From d9181897757187467dba49db34ace33667370022 Mon Sep 17 00:00:00 2001 From: sh Date: Tue, 10 Mar 2026 20:37:47 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=B2=97=E4=BD=8D=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=B7=BB=E5=8A=A0=E7=A4=BE=E4=BC=9A=E4=BF=A1=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=202.=E4=BF=AE=E6=94=B9es=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=B8=8D=E6=94=BE=E9=80=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=BA=E7=B2=BE=E5=87=86=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cms/controller/cms/CmsJobController.java | 33 +++++++--- .../com/ruoyi/cms/domain/vo/JobExcelVo.java | 23 ++++--- .../com/ruoyi/cms/mapper/CompanyMapper.java | 2 + .../cms/service/impl/ESJobSearchImpl.java | 25 +++++--- .../cms/service/impl/JobServiceImpl.java | 8 +-- .../cms/util/excel/JobExcelListener.java | 64 +++++++++++++++++++ .../resources/mapper/app/CompanyMapper.xml | 8 +++ 7 files changed, 132 insertions(+), 31 deletions(-) create mode 100644 ruoyi-bussiness/src/main/java/com/ruoyi/cms/util/excel/JobExcelListener.java diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CmsJobController.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CmsJobController.java index 8ff71c6..6ad938d 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CmsJobController.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/controller/cms/CmsJobController.java @@ -1,5 +1,6 @@ package com.ruoyi.cms.controller.cms; +import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSON; import com.ruoyi.cms.domain.*; import com.ruoyi.cms.domain.query.ESJobSearch; @@ -7,9 +8,9 @@ import com.ruoyi.cms.domain.vo.CandidateVO; import com.ruoyi.cms.domain.vo.CompanyVo; import com.ruoyi.cms.domain.vo.JobExcelVo; import com.ruoyi.cms.service.*; -import com.ruoyi.cms.util.EasyExcelUtils; import com.ruoyi.cms.util.RoleUtils; import com.ruoyi.cms.util.StringUtil; +import com.ruoyi.cms.util.excel.JobExcelListener; import com.ruoyi.cms.util.sensitiveWord.SensitiveWordChecker; import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.annotation.Log; @@ -40,6 +41,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * 岗位Controller @@ -390,14 +392,29 @@ public class CmsJobController extends BaseController } try (InputStream inputStream = file.getInputStream()){ - List allExcelVoList = new ArrayList<>(); - EasyExcelUtils.readExcelByBatch(inputStream, JobExcelVo.class, 100, list -> { - allExcelVoList.addAll(list); - }); - if (CollectionUtils.isEmpty(allExcelVoList)) { - throw new Exception("Excel文件中无有效数据"); + JobExcelListener listener = new JobExcelListener(); + EasyExcel.read(inputStream, JobExcelVo.class, listener).sheet().headRowNumber(1).doRead(); + + if (listener.hasColumnError()) { + return AjaxResult.error(listener.getColumnErrorMsg()); } - jobService.uploadFileJob(allExcelVoList); + + List emptyRowNumbers = listener.getEmptyRowNumbers(); + List validDataList = listener.getValidDataList(); + int emptyCount = emptyRowNumbers.size(); + + if (emptyCount > 0) { + String rowNumStr = emptyRowNumbers.stream() + .map(String::valueOf) + .collect(Collectors.joining("、")); + return AjaxResult.error(String.format("检测到第%s行社会信用代码为空,本次上传终止,未插入任何数据!", rowNumStr)); + } + + if (CollectionUtils.isEmpty(validDataList)) { + return AjaxResult.error("Excel文件中无有效数据!"); + } + + jobService.uploadFileJob(validDataList); return AjaxResult.success("已上传!"); } catch (Exception e) { e.printStackTrace(); diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/vo/JobExcelVo.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/vo/JobExcelVo.java index 7bdeefe..1134727 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/vo/JobExcelVo.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/domain/vo/JobExcelVo.java @@ -44,41 +44,46 @@ public class JobExcelVo @ApiModelProperty("用人单位名称") private String companyName; - @ExcelProperty(value = "职位名称", index = 6,converter = LongConverter.class) + @ExcelProperty(value = "社会信用代码", index = 6) + @Excel(name = "社会信用代码") + @ApiModelProperty("社会信用代码") + private String code; + + @ExcelProperty(value = "职位名称", index = 7,converter = LongConverter.class) @Excel(name = "招聘人数") @ApiModelProperty("招聘人数") private Long vacancies; - @ExcelProperty(value = "职位名称", index = 7) + @ExcelProperty(value = "职位名称", index = 8) @ApiModelProperty("岗位描述") private String description; - @ExcelProperty(value = "职位名称", index = 8) + @ExcelProperty(value = "职位名称", index = 9) @ApiModelProperty("岗位分类") private String jobCategory; - @ExcelProperty(value = "职位名称", index = 9) + @ExcelProperty(value = "职位名称", index = 10) @ApiModelProperty("岗位类型 0疆内 1疆外") private String jobType; - @ExcelProperty(value = "职位名称", index = 10) + @ExcelProperty(value = "职位名称", index = 11) @ApiModelProperty("类型 0常规岗位 1就业见习岗位 2实习实训岗位 3社区实践岗位 4零工 对应字段字典position_type") private String type; - @ExcelProperty(value = "职位名称", index = 11) + @ExcelProperty(value = "职位名称", index = 12) @ApiModelProperty("工作地点") private String jobAddress; - @ExcelProperty(value = "职位名称", index = 12) + @ExcelProperty(value = "职位名称", index = 13) @Excel(name = "岗位区划") @ApiModelProperty("岗位区划") private String jobLocation; - @ExcelProperty(value = "联系人", index = 13) + @ExcelProperty(value = "联系人", index = 14) @ApiModelProperty("联系人") private String contactPerson; - @ExcelProperty(value = "联系人电话", index = 14) + @ExcelProperty(value = "联系人电话", index = 15) @ApiModelProperty("联系人电话") private String contactPersonPhone; diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/mapper/CompanyMapper.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/mapper/CompanyMapper.java index 9a8c087..b17d0f9 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/mapper/CompanyMapper.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/mapper/CompanyMapper.java @@ -33,4 +33,6 @@ public interface CompanyMapper extends BaseMapper List selectByNames(List list); public Company selectByCode(@Param("code") String code); + + List selectBycodes(List list); } diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java index 3b60eb4..0573c44 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java @@ -247,7 +247,7 @@ public class ESJobSearchImpl implements IESJobSearchService List esJobDocuments = esJobDocumentMapper.selectList(wrapper); - if (!isCompanyUser &&esJobDocuments.size() < esJobSearch.getPageSize()) { + /*if (!isCompanyUser &&esJobDocuments.size() < esJobSearch.getPageSize()) { // 定义要逐步放宽的搜索条件字段 List relaxConditions = new ArrayList<>(); relaxConditions.add(() -> newSearch.setArea(null)); @@ -290,7 +290,7 @@ public class ESJobSearchImpl implements IESJobSearchService } else { esJobDocuments = allDocuments; } - } + }*/ return esJobDocuments; } @@ -489,7 +489,8 @@ public class ESJobSearchImpl implements IESJobSearchService } if(!StringUtil.isEmptyOrNull(esJobSearch.getEducation())){ Integer maxValue = StringUtil.findMaxValue(esJobSearch.getEducation()); - wrapper.and(x->x.le(ESJobDocument::getEducation_int,maxValue)); + //wrapper.and(x->x.le(ESJobDocument::getEducation_int,maxValue));//模糊查询 + wrapper.and(x->x.eq(ESJobDocument::getEducation_int,maxValue));//精准查询 } if(Objects.nonNull(esJobSearch.getMaxSalary())){ wrapper.and(x->x.le(ESJobDocument::getMaxSalary,esJobSearch.getMaxSalary())); @@ -499,7 +500,8 @@ public class ESJobSearchImpl implements IESJobSearchService } if(!StringUtil.isEmptyOrNull(esJobSearch.getExperience())){ Integer maxValue = StringUtil.findMaxValue(esJobSearch.getExperience()); - wrapper.and(x->x.le(ESJobDocument::getExperience_int,maxValue)); + //wrapper.and(x->x.le(ESJobDocument::getExperience_int,maxValue)); + wrapper.and(x->x.eq(ESJobDocument::getExperience_int,maxValue));//精准查询 } if(!StringUtil.isEmptyOrNull(esJobSearch.getJobCategory())){ //wrapper.and(x->x.eq(ESJobDocument::getJobCategory,esJobSearch.getJobCategory())); @@ -510,7 +512,8 @@ public class ESJobSearchImpl implements IESJobSearchService } if(!StringUtil.isEmptyOrNull(esJobSearch.getScale())){ Integer maxValue = StringUtil.findMaxValue(esJobSearch.getScale()); - wrapper.and(x->x.le(ESJobDocument::getScale,maxValue)); + //wrapper.and(x->x.le(ESJobDocument::getScale,maxValue)); + wrapper.and(x->x.eq(ESJobDocument::getScale,maxValue));//精准查询 } if(!StringUtil.isEmptyOrNull(esJobSearch.getArea())){ List integers = StringUtil.convertStringToIntegerList(esJobSearch.getArea()); @@ -544,7 +547,7 @@ public class ESJobSearchImpl implements IESJobSearchService wrapper.and(x->x.like(ESJobDocument::getRegionCode,esJobSearch.getRegionCode())); } if(!StringUtil.isEmptyOrNull(esJobSearch.getStaffType())){ - wrapper.and(x->x.like(ESJobDocument::getStaffType,esJobSearch.getStaffType())); + wrapper.and(x->x.eq(ESJobDocument::getStaffType,esJobSearch.getStaffType())); } if(!StringUtil.isEmptyOrNull(esJobSearch.getJobStatus())){ wrapper.and(x->x.eq(ESJobDocument::getJobStatus,esJobSearch.getJobStatus())); @@ -587,14 +590,16 @@ public class ESJobSearchImpl implements IESJobSearchService .match(ESJobDocument::getDescription,jobQuery.getJobTitle(),1.0f)); } if(!StringUtil.isEmptyOrNull(jobQuery.getEducation())){ - wrapper.and(a->a.le(ESJobDocument::getEducation,jobQuery.getEducation())); + //wrapper.and(a->a.le(ESJobDocument::getEducation,jobQuery.getEducation())); + wrapper.and(a->a.eq(ESJobDocument::getEducation,jobQuery.getEducation())); } if(!StringUtil.isEmptyOrNull(jobQuery.getArea())){ List integers = StringUtil.convertStringToIntegerList(jobQuery.getArea()); wrapper.and(x->x.in(ESJobDocument::getJobLocationAreaCode,integers)); } if(!StringUtil.isEmptyOrNull(jobQuery.getExperience())){ - wrapper.and(a->a.le(ESJobDocument::getExperience,jobQuery.getExperience())); + //wrapper.and(a->a.le(ESJobDocument::getExperience,jobQuery.getExperience())); + wrapper.and(a->a.eq(ESJobDocument::getExperience,jobQuery.getExperience())); } if(Objects.nonNull(jobQuery.getMaxSalary())){ wrapper.and(x->x.le(ESJobDocument::getMaxSalary,jobQuery.getMaxSalary())); @@ -811,7 +816,7 @@ public class ESJobSearchImpl implements IESJobSearchService wrapper.limit(esJobSearch.getPageSize()); List esJobDocuments = esJobDocumentMapper.selectList(wrapper); - if (esJobDocuments.size() < esJobSearch.getPageSize()) { + /*if (esJobDocuments.size() < esJobSearch.getPageSize()) { // 定义要逐步放宽的搜索条件字段 List relaxConditions = new ArrayList<>(); relaxConditions.add(() -> newSearch.setArea(null)); @@ -854,7 +859,7 @@ public class ESJobSearchImpl implements IESJobSearchService } else { esJobDocuments = allDocuments; } - } + }*/ return esJobDocuments; } diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java index 2f6bf56..0961db1 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/JobServiceImpl.java @@ -1175,7 +1175,7 @@ public class JobServiceImpl extends ServiceImpl implements IJobSe */ private Map companyNameToIdMap(List allExcelVoList) { Set companyNameSet = allExcelVoList.stream() - .map(JobExcelVo::getCompanyName) + .map(JobExcelVo::getCode) .filter(StringUtils::hasText) .collect(Collectors.toSet()); @@ -1183,13 +1183,13 @@ public class JobServiceImpl extends ServiceImpl implements IJobSe return Collections.emptyMap(); } - List companies = companyMapper.selectByNames(new ArrayList<>(companyNameSet)); + List companies = companyMapper.selectBycodes(new ArrayList<>(companyNameSet)); if (CollectionUtils.isEmpty(companies)) { return Collections.emptyMap(); } return companies.stream() .collect(Collectors.toMap( - Company::getName, + Company::getCode, Company::getCompanyId, (v1, v2) -> v1 )); @@ -1225,7 +1225,7 @@ public class JobServiceImpl extends ServiceImpl implements IJobSe String companyName = it.getCompanyName(); job.setCompanyName(companyName); - job.setCompanyId(companyNameToIdMap.getOrDefault(companyName, null)); + job.setCompanyId(companyNameToIdMap.getOrDefault(it.getCode(), null)); return job; }).collect(Collectors.toList()); diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/util/excel/JobExcelListener.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/util/excel/JobExcelListener.java new file mode 100644 index 0000000..c7076ce --- /dev/null +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/util/excel/JobExcelListener.java @@ -0,0 +1,64 @@ +package com.ruoyi.cms.util.excel; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.ruoyi.cms.domain.vo.JobExcelVo; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 企业岗位excel监听 + */ +@Getter +public class JobExcelListener extends AnalysisEventListener { + + private final List validDataList = new ArrayList<>(); + private final List emptyRowNumbers = new ArrayList<>(); + private boolean isHeadChecked = false; + private String columnErrorMsg; + + @Override + public void invokeHead(Map> headMap, AnalysisContext context) { + if (!isHeadChecked) { + ReadCellData cellData = headMap.get(6); + String seventhColumnTitle = null; + if (cellData != null) { + seventhColumnTitle = cellData.getStringValue(); + } + if (StringUtils.isBlank(seventhColumnTitle) || !seventhColumnTitle.trim().equals("社会信用代码")) { + columnErrorMsg = "Excel模板格式错误:第7列标题应为「社会信用代码」,请下载标准模板后重新上传!"; + } + + isHeadChecked = true; + } + } + + + @Override + public void invoke(JobExcelVo jobExcelVo, AnalysisContext analysisContext) { + int currentRowNum = analysisContext.readRowHolder().getRowIndex() + 1; + String creditCode = jobExcelVo.getCode(); + + if (creditCode != null) { + creditCode = creditCode.trim(); + jobExcelVo.setCode(creditCode.toUpperCase()); + } + + if (StringUtils.isBlank(creditCode)) { + emptyRowNumbers.add(currentRowNum); + } else { + validDataList.add(jobExcelVo); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) {} + + public boolean hasColumnError() { + return StringUtils.isNotBlank(columnErrorMsg); + } +} \ No newline at end of file diff --git a/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml b/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml index 7dd79bf..3c84f48 100644 --- a/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml +++ b/ruoyi-bussiness/src/main/resources/mapper/app/CompanyMapper.xml @@ -129,4 +129,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by create_time desc limit 1 + + \ No newline at end of file