package com.hz.employmentsite.services.impl.companyService; 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.LabelCQuery; import com.hz.employmentsite.mapper.cquery.PostCQuery; import com.hz.employmentsite.mapper.cquery.RecommendMgtCQuery; import com.hz.employmentsite.model.*; import com.hz.employmentsite.services.service.companyService.PostService; import com.hz.employmentsite.services.service.system.DictionaryService; import com.hz.employmentsite.util.RegexUtils; import com.hz.employmentsite.util.StringUtils; import com.hz.employmentsite.vo.companyService.PostVo; import com.hz.employmentsite.vo.companyService.RecommendPostVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; @Service("PostService") public class PostServiceImpl implements PostService { @Autowired private PostCQuery postCQuery; @Autowired private StringUtils stringUtils; @Autowired private RegexUtils regexUtils; @Autowired private PcPostMapper pcPostMapper; @Autowired private PcRecommendMapper pcRecommendMapper; @Autowired private PcRecommendMgtMapper pcRecommendMgtMapper; @Autowired private PcProfessionMapper pcProfessionMapper; @Autowired private PcCompanyMapper companyMapper; @Autowired private PcSiteUserMapper pcSiteUserMapper; @Autowired private DictionaryService dictionaryService; @Autowired private PcLabelPostMapper pcLabelPostMapper; @Autowired private LabelCQuery labelCQuery; @Autowired private PcWorkcategoryMapper pcWorkcategoryMapper; @Override public PageInfo getList(Integer page, Integer rows, List postIDList, String professionName, Integer minCount, Integer maxCount, String companyName, String recordStatus, String companyID, String loginUserID, String siteID, Date startDate, Date endDate) { List curLoginUserSiteCompanyIDs = new ArrayList<>(); if (!stringUtils.IsNullOrEmpty(loginUserID)) { PcSiteUserExample siteUserExp = new PcSiteUserExample(); siteUserExp.or().andUserIDEqualTo(loginUserID); var curLoginUserSiteID = pcSiteUserMapper.selectByExample(siteUserExp).get(0).getSiteID(); PcCompanyExample companyExp = new PcCompanyExample(); companyExp.or().andSiteIDEqualTo(curLoginUserSiteID); var curLoginUserSiteCompanyList = companyMapper.selectByExample(companyExp).stream().toList(); for (PcCompany curLoginUserSiteCompany : curLoginUserSiteCompanyList) { curLoginUserSiteCompanyIDs.add(curLoginUserSiteCompany.getCompanyID()); } } PageHelper.startPage(page, rows); List list = postCQuery.selectPostList(stringUtils.ListToInSql(postIDList), professionName, minCount, maxCount, companyName, recordStatus, companyID, stringUtils.ListToInSql(curLoginUserSiteCompanyIDs), siteID, startDate, endDate,false); if(list != null && list.size()>0){ for(PostVo curPost : list){ curPost.listLabel = labelCQuery.getPostLabelList(curPost.getPostID()); var curPcPost = pcPostMapper.selectByPrimaryKey(curPost.getPostID()); if (!stringUtils.IsNullOrEmpty(curPost.professionID)&&stringUtils.IsNullOrEmpty(curPost.postName)){ PcProfessionExample professionExp = new PcProfessionExample(); professionExp.or().andProfessionIDEqualTo(curPost.professionID); var curProfession = pcProfessionMapper.selectByExample(professionExp).stream().findFirst().orElse(null); if( curProfession!=null){ curPcPost.setPostName(curProfession.getProfessionName()); pcPostMapper.updateByPrimaryKey(curPcPost); } } if (!stringUtils.IsNullOrEmpty(curPost.workCode)&&stringUtils.IsNullOrEmpty(curPost.workName)){ PcWorkcategoryExample workCategoryExp = new PcWorkcategoryExample(); workCategoryExp.or().andWorkCategoryIDEqualTo(curPost.workCode); var curWorkCategory = pcWorkcategoryMapper.selectByExample(workCategoryExp).stream().findFirst().orElse(null); if( curWorkCategory!=null){ curPcPost.setWorkName(curWorkCategory.getWorkCategoryName()); pcPostMapper.updateByPrimaryKey(curPcPost); } } if (curPost.endTime != null && curPost.endTime.before(new Date()) && curPost.recordStatus.equals(1)) { curPcPost.setRecordStatus(0); pcPostMapper.updateByPrimaryKey(curPcPost); } } } PageInfo result = new PageInfo(list); return result; } @Override public PageInfo getCommendPostList(Integer page, Integer rows, String jobUserID) { PageHelper.startPage(page, rows); List list = postCQuery.selectRecommendPostList(jobUserID); PageInfo result = new PageInfo(list); return result; } @Override public Integer saveCommendPost(RecommendPostVo data, String userId) { int result = 0; PcRecommend dbData = null; if (data.recommendID != null) { PcRecommendExample exp = new PcRecommendExample(); PcRecommendExample.Criteria cro = exp.createCriteria(); cro.andPostIDEqualTo(data.recommendID); dbData = pcRecommendMapper.selectByExample(exp).stream().findFirst().orElse(null); } Boolean isExist = dbData != null; if (!isExist) { dbData = new PcRecommend(); dbData.setRecommendID(UUID.randomUUID().toString()); dbData.setJobuserID(data.jobUserID); dbData.setPostID(data.postID); dbData.setIsRead(data.isRead == null ? false : true); dbData.setIsSendnotes(data.isSendNotes == null ? false : true); dbData.setCreateTime(new Date()); dbData.setCreateUserID(userId); result = pcRecommendMapper.insert(dbData); } else { dbData.setJobuserID(data.jobUserID); dbData.setPostID(data.postID); dbData.setIsRead(data.isRead == null ? false : true); dbData.setIsSendnotes(data.isSendNotes == null ? false : true); dbData.setModifyTime(new Date()); dbData.setModifyUserID(userId); result = pcRecommendMapper.updateByPrimaryKeySelective(dbData); } return result; } @Override public int updatePostStatus(String postID, Integer status) { PcPost post = pcPostMapper.selectByPrimaryKey(postID); if(status.equals(1)&&post.getEndTime().before(new Date())){ throw new BaseException("","该岗位招聘日期已结束,不能启用!"); } post.setRecordStatus(status); return pcPostMapper.updateByPrimaryKey(post); } @Override public int save(PostVo data, String userId) { int result = 0; PcPost dbData = null; Boolean isExist = data.getPostID() != null; PcPostExample exp = new PcPostExample(); PcPostExample.Criteria cro = exp.createCriteria(); if (isExist) { cro.andPostIDEqualTo(data.getPostID()); dbData = pcPostMapper.selectByExample(exp).stream().findFirst().orElse(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 (dbData == null) { dbData = new PcPost(); dbData.setPostID(UUID.randomUUID().toString()); dbData.setProfessionID(data.getProfessionID()); dbData.setWorkCode(data.getWorkCode()); dbData.setWorkName(data.getWorkName()); dbData.setValidTime(data.getValidTime()); dbData.setRecruitCount(data.getRecruitCount()); dbData.setCompanyID(data.getCompanyID()); dbData.setPostName(data.getPostName()); dbData.setRecordStatus(data.getRecordStatus()); dbData.setWorkNature(data.getWorkNature()); dbData.setValidDay(data.getValidDay()); dbData.setWorkYear(data.getWorkYear()); dbData.setWorkNature(data.getWorkNature()); dbData.setCultureRank(data.getCultureRank()); dbData.setPostDesc(data.getPostDesc()); dbData.setMaxSalary(data.getMaxSalary()); dbData.setMinSalary(data.getMinSalary()); dbData.setWelfare(data.getWelfare()); dbData.setUserName(data.getUserName()); dbData.setUserMobile(data.getUserMobile()); dbData.setPostEmail(data.getPostEmail()); dbData.setWorkTime(data.getWorkTime()); dbData.setIsTrail(data.getIsTrail()); dbData.setTrailMonths(data.getTrailMonths()); dbData.setTrailMaxSalary(data.getTrailMaxSalary()); dbData.setTrailMinSalary(data.getTrailMinSalary()); dbData.setCreateTime(new Date()); dbData.setCreateUserID(userId); dbData.setJobPlace(data.getJobPlace()); dbData.setStartTime(data.getStartTime()); dbData.setEndTime(data.getEndTime()); dbData.setContactName(data.getContactName()); dbData.setContactMobile(data.getContactMobile()); dbData.setContactEmail(data.getContactEmail()); dbData.setWorkNatureID(data.getWorkNatureID()); // dbData.setTagID(data.getTagID()); result = pcPostMapper.insert(dbData); } else { dbData.setProfessionID(data.getProfessionID()); dbData.setWorkCode(data.getWorkCode()); dbData.setValidTime(data.getValidTime()); dbData.setWorkName(data.getWorkName()); dbData.setRecruitCount(data.getRecruitCount()); dbData.setCompanyID(data.getCompanyID()); dbData.setPostName(data.getPostName()); dbData.setRecordStatus(data.getRecordStatus()); dbData.setWorkNature(data.getWorkNature()); dbData.setValidDay(data.getValidDay()); dbData.setWorkYear(data.getWorkYear()); dbData.setWorkNature(data.getWorkNature()); dbData.setCultureRank(data.getCultureRank()); dbData.setPostDesc(data.getPostDesc()); dbData.setMaxSalary(data.getMaxSalary()); dbData.setMinSalary(data.getMinSalary()); dbData.setWelfare(data.getWelfare()); dbData.setUserName(data.getUserName()); dbData.setUserMobile(data.getUserMobile()); dbData.setPostEmail(data.getPostEmail()); dbData.setWorkTime(data.getWorkTime()); dbData.setIsTrail(data.getIsTrail()); dbData.setTrailMonths(data.getTrailMonths()); dbData.setTrailMaxSalary(data.getTrailMaxSalary()); dbData.setTrailMinSalary(data.getTrailMinSalary()); dbData.setModifyTime(new Date()); dbData.setModifyUserID(userId); dbData.setJobPlace(data.getJobPlace()); dbData.setStartTime(data.getStartTime()); dbData.setEndTime(data.getEndTime()); dbData.setContactName(data.getContactName()); dbData.setContactMobile(data.getContactMobile()); dbData.setContactEmail(data.getContactEmail()); dbData.setWorkNatureID(data.getWorkNatureID()); // dbData.setTagID(data.getTagID()); result = pcPostMapper.updateByPrimaryKeyWithBLOBs(dbData); } PcLabelPostExample labelEmp = new PcLabelPostExample(); labelEmp.or().andPostIDEqualTo(data.getPostID()); pcLabelPostMapper.deleteByExample(labelEmp); if (data.listLabel != null && data.listLabel.size() > 0) { data.listLabel.forEach(x -> { PcLabelPost labelModel = new PcLabelPost(); labelModel.setPostID(data.getPostID()); labelModel.setLabelID(x.getLabelID()); pcLabelPostMapper.insert(labelModel); }); } return result; } @Override public int delete(List idList) { int result = 0; PcRecommendMgtExample recommendMgtExp = new PcRecommendMgtExample(); recommendMgtExp.or().andPostIDIn(idList); List resultList = pcRecommendMgtMapper.selectByExample(recommendMgtExp).stream().toList(); if( resultList.size() > 0 ) { throw new BaseException("10004","已存在该岗位的推荐数据,删除失败!"); } PcPostExample postExp = new PcPostExample(); postExp.or().andPostIDIn(idList); result = pcPostMapper.deleteByExample(postExp); if (result > 0) { PcLabelPostExample labelEmp = new PcLabelPostExample(); labelEmp.or().andPostIDIn(idList); pcLabelPostMapper.deleteByExample(labelEmp); } return result; } @Override public int deletePostAndRecommendMgt(String id) { try { PcRecommendMgtExample exp = new PcRecommendMgtExample(); PcRecommendMgtExample.Criteria cro = exp.or(); cro.andPostIDEqualTo(id); pcRecommendMgtMapper.deleteByExample(exp); PcLabelPostExample labelEmp = new PcLabelPostExample(); labelEmp.or().andPostIDEqualTo(id); pcLabelPostMapper.deleteByExample(labelEmp); return pcPostMapper.deleteByPrimaryKey(id); } catch (Exception e) { e.printStackTrace(); return 0; } } @Override public PostVo getDataById(String id,boolean isAllPost) { if (stringUtils.IsNullOrEmpty(id)) { return null; } PostVo data = postCQuery.selectPostList(stringUtils.ListToInSql(Arrays.asList(id)), null, null, null, null, null, null, null, null, null, null,isAllPost).stream().findFirst().orElse(null); if (data != null) { data.listLabel = labelCQuery.getPostLabelList(id); } return data; } @Override public List getDataListByCompanyID(String companyId) { List resultList = new ArrayList<>(); PcPostExample postExp = new PcPostExample(); postExp.or().andCompanyIDEqualTo(companyId); var postList = pcPostMapper.selectByExample(postExp); for (PcPost curPost : postList) { PostVo item = new PostVo(); item.setPostID(curPost.getPostID()); item.setProfessionID(curPost.getProfessionID()); PcProfessionExample professionExp = new PcProfessionExample(); professionExp.or().andProfessionIDEqualTo(curPost.getProfessionID()); var curProfession = pcProfessionMapper.selectByExample(professionExp).get(0); item.setProfessionName(curProfession.getProfessionName()); item.setCompanyID(curPost.getCompanyID()); item.setRecruitCount(curPost.getRecruitCount()); item.setStartTime(curPost.getStartTime()); item.setEndTime(curPost.getEndTime()); resultList.add(item); } return resultList; } public static boolean isPositiveInteger(String str) { try { // 尝试将字符串转换为整数 int num = Integer.parseInt(str); // 如果转换后的整数小于等于0,则为false return num > 0; } catch (NumberFormatException e) { // 字符串无法转换为整数,则为false return false; } } @Override public List importPost(List dataList, String userID) { if (dataList.size() <= 0) throw new BaseException("", "请添加导入数据!"); //所属企业 PcCompanyExample companyExp = new PcCompanyExample(); companyExp.or().andRecordStatusEqualTo(1); List companyList = companyMapper.selectByExample(companyExp); //岗位信息 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 WorkCategoryList = new ArrayList<>(); // 获取第一级工种 PcWorkcategoryExample workCategoryExample = new PcWorkcategoryExample(); workCategoryExample.or().andParentWorkCategoryIDEqualTo("").andStatusEqualTo(1); List firstLevelWorkCategoryList = pcWorkcategoryMapper.selectByExample(workCategoryExample); for (PcWorkcategory pcWorkcategory : firstLevelWorkCategoryList) { // 获取第二级工种 workCategoryExample = new PcWorkcategoryExample(); workCategoryExample.or().andParentWorkCategoryIDEqualTo(pcWorkcategory.getWorkCategoryID()).andStatusEqualTo(1); List secondLevelWorkCategoryList = pcWorkcategoryMapper.selectByExample(workCategoryExample); for (PcWorkcategory workCategory : secondLevelWorkCategoryList) { // 获取第三级工种 workCategoryExample = new PcWorkcategoryExample(); workCategoryExample.or().andParentWorkCategoryIDEqualTo(workCategory.getWorkCategoryID()).andStatusEqualTo(1); List thirdLevelWorkCategoryList = pcWorkcategoryMapper.selectByExample(workCategoryExample); for (PcWorkcategory pcWorkCategory1 : thirdLevelWorkCategoryList) { SysDictionaryItem item = new SysDictionaryItem(); item.setCode(pcWorkCategory1.getWorkCategoryID()); item.setName(pcWorkCategory1.getWorkCategoryName()); WorkCategoryList.add(item); } } } //文化程度 List dicCultureDataList = dictionaryService.getDictionaryItemList("CultureLevel"); // 工作年限 List dicWorkYearDataList = dictionaryService.getDictionaryItemList("WorkYearType"); // 最终处理数据 List resultList = new ArrayList<>(); // 岗位 List pcProfessionList = new ArrayList<>(); // 岗位字典 // 获取二级的“其他”岗位 PcProfessionExample proEmp = new PcProfessionExample(); PcProfessionExample.Criteria proCia = proEmp.or(); proCia.andParentProfessionIDNotEqualTo(""); proCia.andProfessionNameEqualTo("其他"); PcProfession proOther = pcProfessionMapper.selectByExample(proEmp).stream().findFirst().orElse(null); proEmp = new PcProfessionExample(); proEmp.or().andParentProfessionIDEqualTo(proOther.getProfessionID()).andProfessionNameIsNotNull(); //查询已存在的三级“其他”岗位 List proOtherSonList = pcProfessionMapper.selectByExample(proEmp); dataList.forEach(item -> { String errorInfo = ""; item.setPostID(UUID.randomUUID().toString()); item.setRecordStatus(1); if (stringUtils.IsNullOrEmpty(item.companyName)) errorInfo += "请填写企业名称!"; else { item.companyID = companyList.stream().filter(it -> it.getCompanyName().equals(item.getCompanyName().trim())) .findFirst().orElse(new PcCompany()).getCompanyID(); if (item.companyID == null) errorInfo += "企业不存在!"; } if (stringUtils.IsNullOrEmpty(item.professionName)) errorInfo += "请填写岗位名称!"; else { item.professionID = thirdLevelProfessionList.stream().filter(it -> it.getName() != null && it.getName().equals(item.getProfessionName().trim())) .findFirst().orElse(new SysDictionaryItem()).getCode(); if (item.professionID == null || item.professionID == "") { // 如果岗位不存在,则在“其他”下添加一个 if (proOther != null) { item.setProfessionID(UUID.randomUUID().toString()); PcProfession proModel = new PcProfession(); proModel.setProfessionID(item.getProfessionID()); proModel.setParentProfessionID(proOther.getProfessionID()); proModel.setProfessionName(item.getProfessionName()); proModel.setStatus(Integer.parseInt("1")); proModel.setOrderNo(proOtherSonList.size() + 1); pcProfessionList.add(proModel); // 先将该岗位临时存储在第三级数据中,防止在最终添加之前,向pcProfessionList生成多个相同名称的岗位字典数据 SysDictionaryItem dictionaryItem = new SysDictionaryItem(); dictionaryItem.setCode(item.getProfessionID()); dictionaryItem.setName(item.getProfessionName()); thirdLevelProfessionList.add(dictionaryItem); } } } if (stringUtils.IsNullOrEmpty(item.getWorkCategoryName())) { errorInfo += "请填写工种名称"; } else { item.workCode = WorkCategoryList.stream().filter(it -> it.getName() != null && it.getName().equals(item.getWorkCategoryName().trim())) .findFirst().orElse(new SysDictionaryItem()).getCode(); if (item.workCode == null || item.workCode == "") { errorInfo += "工种不存在!"; }else{ item.workName = item.getWorkCategoryName(); } } if (stringUtils.IsNullOrEmpty(String.valueOf(item.recruitCountStr))) errorInfo += "请填写招聘人数!"; else{ if(!isPositiveInteger(item.recruitCountStr)){ errorInfo += "招聘人数必须为一个正整数!"; }else{ item.setRecruitCount(Integer.valueOf(item.recruitCountStr)); } } if (stringUtils.IsNullOrEmpty(String.valueOf(item.startTime)) || item.startTime == null) errorInfo += "请填写开始日期!"; if (stringUtils.IsNullOrEmpty(String.valueOf(item.startTime)) || item.startTime == null) errorInfo += "请填写结束日期!"; if (stringUtils.IsNullOrEmpty(item.jobPlace)) errorInfo += "请填写工作地点!"; if (!stringUtils.IsNullOrEmpty(item.getWorkYearName())) { item.workYear = dicWorkYearDataList.stream().filter(it -> it.getName() != null && it.getName().equals(item.getWorkYearName().trim())) .findFirst().orElse(new SysDictionaryItem()).getValue(); if (item.workYear == null) errorInfo += "工作年限不存在!"; } if (item.isTrailName.trim().equals("是")) item.isTrail = true; else if (item.isTrailName.trim().equals("否")) item.isTrail = false; if (!stringUtils.IsNullOrEmpty(item.cultureLevelName)) { item.cultureRank = dicCultureDataList.stream().filter(it -> it.getName() != null && it.getName().equals(item.cultureLevelName.trim())) .findFirst().orElse(new SysDictionaryItem()).getValue(); if (item.cultureRank == null || item.cultureRank == 0) errorInfo += "输入的学历要求不存在!"; } if (!stringUtils.IsNullOrEmpty(item.getContactMobile())) { if (!regexUtils.theMobileIsValid( item.contactMobile,true)) { errorInfo += "输入的联系人电话格式不正确"; } } if (!stringUtils.IsNullOrEmpty(item.getCompanyEmail())) { if (!regexUtils.theEmailIsValid(item.contactEmail)) { errorInfo += "输入的邮箱格式不正确"; } } 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); }); // 添加岗位名称字典 pcProfessionList.forEach(item -> { pcProfessionMapper.insert(item); }); return null; } /** * 企业数据可视化地图页面获取岗位 * * @param companyID 企业ID * @return 岗位信息 */ @Override public PageInfo selectCompanyMapPostList(int pageIndex, int pageSize, String companyID) { PageHelper.startPage(pageIndex, pageSize); List postVos = postCQuery.selectCompanyMapPostList(companyID); PageInfo result = new PageInfo(postVos); return result; } }