package com.hz.employmentsite.services.impl.jobUserManager; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hz.employmentsite.filter.exception.BaseException; import com.hz.employmentsite.mapper.*; import com.hz.employmentsite.mapper.cquery.JobHuntCQuery; import com.hz.employmentsite.model.*; import com.hz.employmentsite.services.service.AccountService; import com.hz.employmentsite.services.service.jobUserManager.JobHuntService; import com.hz.employmentsite.services.service.system.DictionaryService; import com.hz.employmentsite.util.StringUtils; import com.hz.employmentsite.util.ip.IpUtils; import com.hz.employmentsite.vo.jobUserManager.JobHuntVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; @Service("JobHuntService") public class JobHuntServiceImpl implements JobHuntService { @Autowired private JobHuntCQuery jobhuntCQuery; @Autowired private PcJobhuntMapper pcJobhuntMapper; @Autowired private PcJobuserMapper pcJobuserMapper; @Autowired private PcProfessionMapper pcProfessionMapper; @Autowired private PcRecommendMgtMapper pcRecommendMgtMapper; @Autowired private PcSiteUserMapper pcSiteUserMapper; @Autowired private DictionaryService dictionaryService; @Autowired private StringUtils stringUtils; @Autowired private AccountService accountService; @Autowired private SysLogMapper sysLogMapper; @Override public PageInfo getList(Integer pageIndex, Integer pageSize, List jobHuntIDList, String jobUserID, String jobUserName, String professionName, BigDecimal minWorkYear, BigDecimal maxWorkYear, Integer jobHuntTypeID, Integer jobUserTypeID, BigDecimal minSalary, BigDecimal maxSalary, Integer isAccomplish, String loginUserID, String siteID, String regionCode, Date startDate, Date endDate,boolean isAllJobHunt, String createUserName, Integer dataSource) { List curLoginUserSiteJobUserIDs = new ArrayList<>(); if (!stringUtils.IsNullOrEmpty(loginUserID)) { PcSiteUserExample siteUserExp = new PcSiteUserExample(); siteUserExp.or().andUserIDEqualTo(loginUserID); var curLoginUserSiteID = pcSiteUserMapper.selectByExample(siteUserExp).get(0).getSiteID(); PcJobuserExample jobUserExp = new PcJobuserExample(); jobUserExp.or().andSiteIDEqualTo(curLoginUserSiteID); var curLoginUserSiteJobUserList = pcJobuserMapper.selectByExample(jobUserExp).stream().toList(); for (PcJobuser curLoginUserSiteJobUser : curLoginUserSiteJobUserList) { curLoginUserSiteJobUserIDs.add(curLoginUserSiteJobUser.getJobuserID()); } } PageHelper.startPage(pageIndex, pageSize); List list; if (!stringUtils.IsNullOrEmpty(loginUserID) && curLoginUserSiteJobUserIDs.isEmpty()) { // APP查询时,当前驿站没有录入求职人员,返回空,防止curLoginUserSiteJobUserIDs为空字符,查询语句不能触发 list = new ArrayList<>(); } else { list = jobhuntCQuery.getJobHuntList(stringUtils.ListToInSql(jobHuntIDList), jobUserID, jobUserName, professionName, minWorkYear, maxWorkYear, jobHuntTypeID, jobUserTypeID, minSalary, maxSalary, isAccomplish, stringUtils.ListToInSql(curLoginUserSiteJobUserIDs), siteID, regionCode, startDate, endDate, isAllJobHunt, createUserName, dataSource); } PageInfo result = new PageInfo(list); return result; } @Override public JobHuntVo get(String jobHuntId) { List ids = new ArrayList<>(); if (stringUtils.IsNullOrEmpty(jobHuntId)) { return null; }else{ ids.add(jobHuntId); } JobHuntVo model = jobhuntCQuery.getJobHuntList(stringUtils.ListToInSql(ids), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,true, null, null).stream().findFirst().orElse(null); return model; } @Override public Integer delete(HttpServletRequest request, List idList, String loginUserID){ PcRecommendMgtExample recommendMgtExp = new PcRecommendMgtExample(); recommendMgtExp.or().andJobHuntIDIn(idList); List resultList = pcRecommendMgtMapper.selectByExample(recommendMgtExp).stream().toList(); if( resultList.size() > 0 ) { throw new BaseException("10004","已存在该意向的推荐数据,删除失败!"); } // 查询数据 List jobHuntList = jobhuntCQuery.getJobHuntList(stringUtils.ListToInSql(idList), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, null, null); String delInfo = "删除求职意向:"; for (JobHuntVo item : jobHuntList) { delInfo += item.getJobUserName() + "("+item.getProfessionName() + "),"; } PcJobhuntExample contactExample = new PcJobhuntExample(); contactExample.or().andJobHuntIDIn(idList); int result = pcJobhuntMapper.deleteByExample(contactExample); if (result > 0) { SysLog sysLog = new SysLog(); sysLog.setLogID(UUID.randomUUID().toString()); sysLog.setPageName("求职意向信息管理"); sysLog.setPageUrl("/jobusermgr/jobhunt/delete"); sysLog.setActionName("删除求职意向"); sysLog.setUserID(loginUserID); sysLog.setLogTime(new Date()); sysLog.setIPAddress(IpUtils.getIpAddr(request)); sysLog.setOperationData(delInfo.substring(0, delInfo.length() - 1)); // 注意移除最后一个, sysLogMapper.insert(sysLog); } return result; } @Override public Integer deleteJobHuntAndRecommendMgt(HttpServletRequest request, String id, String loginUserID){ try{ PcRecommendMgtExample emp = new PcRecommendMgtExample(); emp.or().andJobHuntIDEqualTo(id); pcRecommendMgtMapper.deleteByExample(emp); // 求职意向相关数据 List jobHuntList = jobhuntCQuery.getJobHuntList(stringUtils.ListToInSql(Arrays.asList(id)), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false,null, null); // 删除求职意向 int result = pcJobhuntMapper.deleteByPrimaryKey(id); if (result > 0) { // 保存日志信息 String delInfo = "删除求职意向:"; for (JobHuntVo item : jobHuntList) { delInfo += item.getJobUserName() + "("+item.getProfessionName() + ")"; } SysLog sysLog = new SysLog(); sysLog.setLogID(UUID.randomUUID().toString()); sysLog.setPageName("求职意向信息管理"); sysLog.setPageUrl("/jobusermgr/jobhunt/delete"); sysLog.setActionName("删除求职意向"); sysLog.setUserID(loginUserID); sysLog.setLogTime(new Date()); sysLog.setIPAddress(IpUtils.getIpAddr(request)); sysLog.setOperationData(delInfo); sysLogMapper.insert(sysLog); } return result; }catch (Exception e){ e.printStackTrace(); return 0; } } @Override public Integer save(JobHuntVo data, String userId) { int result = 0; JobHuntVo record = get(data.jobHuntID); PcJobhunt dbData = record == null ? null : pcJobhuntMapper.selectByPrimaryKey(record.jobHuntID); if (dbData == null && !stringUtils.IsNullOrEmpty(data.getOracleTableID())) { PcJobhuntExample example = new PcJobhuntExample(); example.createCriteria().andOracleTableIDEqualTo(data.getOracleTableID()); List jobhuntList = pcJobhuntMapper.selectByExample(example); if (!jobhuntList.isEmpty()) { // 已入库的不进行重复同步 return 0; } } Boolean isExist = dbData != null; //判断岗位id是否为空 if (stringUtils.IsNullOrEmpty(data.getProfessionID())) { PcProfessionExample proEmp = new PcProfessionExample(); PcProfessionExample.Criteria proCia = proEmp.or(); proCia.andParentProfessionIDNotEqualTo(""); proCia.andProfessionNameEqualTo("其他"); //获取二级其他信息 PcProfession proOther = pcProfessionMapper.selectByExample(proEmp).stream().findFirst().orElse(null); if (proOther != null) { proEmp = new PcProfessionExample(); proEmp.or().andParentProfessionIDEqualTo(proOther.getProfessionID()).andProfessionNameIsNotNull(); // proCia.andProfessionNameEqualTo(data.getProfessionName()); //查询其他岗位 List proOtherSonList = pcProfessionMapper.selectByExample(proEmp); PcProfession proOtherSon = proOtherSonList.stream() .filter(x -> x.getProfessionName().equals(data.getProfessionName())).findFirst().orElse(null); if (proOtherSon != null) { data.setProfessionID(proOtherSon.getProfessionID()); } else { data.setProfessionID(UUID.randomUUID().toString()); PcProfession proModel = new PcProfession(); proModel.setProfessionID(data.getProfessionID()); proModel.setParentProfessionID(proOther.getProfessionID()); proModel.setProfessionName(data.getProfessionName()); proModel.setStatus(Integer.parseInt("1")); proModel.setOrderNo(proOtherSonList.size() + 1); pcProfessionMapper.insert(proModel); } } } if (!isExist) { //添加 dbData = new PcJobhunt(); dbData.setJobHuntID(data.getJobHuntID()); dbData.setJobUserID(data.getJobUserID()); dbData.setProfessionID(data.getProfessionID()); dbData.setWorkCode(data.getWorkCode()); dbData.setWorkName(data.getWorkName()); dbData.setAreaWork(data.getAreaWork()); dbData.setInDate(data.getInDate()); dbData.setWorkYear(data.getWorkYear()); dbData.setJobHuntType(data.getJobHuntType()); dbData.setJobUserType(data.getJobUserType()); dbData.setMinSalary(data.getMinSalary()); dbData.setMaxSalary(data.getMaxSalary()); dbData.setOtherDemand(data.getOtherDemand()); dbData.setCreateUserID(userId); dbData.setCreateTime(data.getCreateTime() == null ? new Date() : data.getCreateTime()); // 三目运算防止oracle同步数据的创建日期被重置 dbData.setOracleTableID(data.getOracleTableID()); result = pcJobhuntMapper.insert(dbData); } else { //修改 dbData.setJobHuntID(data.jobHuntID); dbData.setJobUserID(data.jobUserID); dbData.setProfessionID(data.professionID); dbData.setWorkCode(data.workCode); dbData.setWorkName(data.workName); dbData.setAreaWork(data.areaWork); dbData.setInDate(data.inDate); dbData.setWorkYear(data.workYear); dbData.setJobHuntType(data.jobHuntType); dbData.setJobUserType(data.jobUserType); dbData.setMinSalary(data.minSalary); dbData.setMaxSalary(data.maxSalary); dbData.setOtherDemand(data.otherDemand); dbData.setModifyUserID(userId); dbData.setModifyTime(new Date()); dbData.setOracleTableID(data.getOracleTableID()); result = pcJobhuntMapper.updateByPrimaryKey(dbData); } return result; } @Override public List importJobHunt(List dataList, String userID) { if (dataList.size() <= 0) throw new BaseException("", "请添加导入数据!"); //求职人员 PcSiteUserExample siteUserExp = new PcSiteUserExample(); siteUserExp.or().andUserIDEqualTo(userID); PcSiteUser curLoginSiteUser = pcSiteUserMapper.selectByExample(siteUserExp).stream().findFirst().orElse(null); List jobUserList = new ArrayList<>(); if(curLoginSiteUser==null){ throw new BaseException("", "未能查询到当前登录人的驿站信息!"); }else{ PcJobuserExample jobuserExample = new PcJobuserExample(); jobuserExample.or().andNameIsNotNull().andSiteIDEqualTo(curLoginSiteUser.getSiteID()); jobUserList = pcJobuserMapper.selectByExample(jobuserExample); } //岗位 List thirdLevelProfessionList = new ArrayList<>(); PcProfessionExample professionExp = new PcProfessionExample(); professionExp.or().andParentProfessionIDEqualTo("").andStatusEqualTo(1); var firstLevelData = pcProfessionMapper.selectByExample(professionExp); for (PcProfession curProfession : firstLevelData) { professionExp = new PcProfessionExample(); professionExp.or().andParentProfessionIDEqualTo(curProfession.getProfessionID()).andStatusEqualTo(1); var secondLevelData = pcProfessionMapper.selectByExample(professionExp); for (PcProfession curParentProfession : secondLevelData) { professionExp = new PcProfessionExample(); professionExp.or().andParentProfessionIDEqualTo(curParentProfession.getProfessionID()).andStatusEqualTo(1).andProfessionNameIsNotNull(); var thirdLevelData = pcProfessionMapper.selectByExample(professionExp); for (PcProfession curItem : thirdLevelData) { SysDictionaryItem item = new SysDictionaryItem(); item.setCode(curItem.getProfessionID()); item.setName(curItem.getProfessionName()); thirdLevelProfessionList.add(item); } } } //求职类型 List dicHuntTypeList = dictionaryService.getDictionaryItemList("JobHuntType"); //人才类型 List dicUserTypeList = dictionaryService.getDictionaryItemList("JobUserType"); List resultList = new ArrayList<>(); List finalJobUserList = jobUserList; dataList.forEach(item -> { String errorInfo = ""; item.setJobHuntID(UUID.randomUUID().toString()); if (stringUtils.IsNullOrEmpty(item.jobUserName)) errorInfo += "请填写姓名!"; else { item.jobUserID = finalJobUserList.stream().filter(it -> it.getName().equals(item.getJobUserName().trim())) .findFirst().orElse(new PcJobuser()).getJobuserID(); if (item.jobUserID == null) errorInfo += "求职人员不存在!"; } if (stringUtils.IsNullOrEmpty(item.jobHuntTypeStr)) errorInfo += "请填写求职类型!"; else { item.jobHuntType = dicHuntTypeList.stream().filter(it -> it.getName().equals(item.jobHuntTypeStr.trim())) .findFirst().orElse(new SysDictionaryItem()).getValue(); if (item.jobHuntType == null || item.jobHuntType == 0) errorInfo += "输入求职类型不存在!"; } if (stringUtils.IsNullOrEmpty(item.jobUserTypeStr)) errorInfo += "请填写人才类型!"; else { item.jobUserType = dicUserTypeList.stream().filter(it -> it.getName().equals(item.jobUserTypeStr.trim())) .findFirst().orElse(new SysDictionaryItem()).getValue(); if (item.jobUserType == null || item.jobUserType == 0) errorInfo += "输入人才类型不存在!"; } if (stringUtils.IsNullOrEmpty(String.valueOf(item.minSalary)) || item.minSalary == null) errorInfo += "请填写最低薪酬!"; if (stringUtils.IsNullOrEmpty(String.valueOf(item.maxSalary)) || item.maxSalary == null) errorInfo += "请填写最高薪酬!"; if (stringUtils.IsNullOrEmpty(item.professionName)) errorInfo += "请填写求职岗位!"; else { item.professionID = thirdLevelProfessionList.stream().filter(it -> it.getName().equals(item.getProfessionName().trim())) .findFirst().orElse(new SysDictionaryItem()).getCode(); //if (item.professionID == null) // errorInfo += "求职岗位不存在!"; } if (stringUtils.IsNullOrEmpty(item.areaWork)) errorInfo += "请填写希望工作地区!"; if (stringUtils.IsNullOrEmpty(String.valueOf(item.inDate)) || item.inDate == null) errorInfo += "请填写可到职日期!"; if (stringUtils.IsNullOrEmpty(String.valueOf(item.workYear))||String.valueOf(item.workYear).equals("null")) item.setWorkYear(new BigDecimal(0)); if (stringUtils.IsNullOrEmpty(errorInfo)) { resultList.add(item); } else { item.setErrorMessage(errorInfo); } }); if (dataList.stream().filter(it -> !stringUtils.IsNullOrEmpty(it.errorMessage)).collect(Collectors.toList()).size() > 0) return dataList; resultList.forEach(item -> { save(item, userID); }); return null; } }