|
|
@@ -1,22 +1,32 @@
|
|
|
package com.jpsoft.employment.modules.base.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.employment.config.OSSConfig;
|
|
|
import com.jpsoft.employment.modules.base.entity.EnterpriseInfo;
|
|
|
import com.jpsoft.employment.modules.base.service.EnterpriseInfoService;
|
|
|
import com.jpsoft.employment.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.employment.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.employment.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.employment.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.employment.modules.common.dto.Sort;
|
|
|
import com.jpsoft.employment.modules.base.entity.RecruitInformationInfo;
|
|
|
import com.jpsoft.employment.modules.base.service.RecruitInformationInfoService;
|
|
|
import com.jpsoft.employment.modules.sys.service.DataDictionaryService;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -33,6 +43,9 @@ public class RecruitInformationInfoController {
|
|
|
|
|
|
@Autowired
|
|
|
private DataDictionaryService dataDictionaryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
|
|
|
|
|
@ApiOperation(value="创建空记录")
|
|
|
@@ -307,4 +320,191 @@ public class RecruitInformationInfoController {
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "导入招聘信息")
|
|
|
+ @PostMapping("importXls")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "uploadFile", value = "上传文件", required = true, paramType = "form", dataType = "__file")
|
|
|
+ })
|
|
|
+ public MessageResult<String> importXls(MultipartFile uploadFile, @RequestAttribute String subject) {
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ int sheetIndex = 0;
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 11;
|
|
|
+
|
|
|
+ int count = sheet1.getLastRowNum();
|
|
|
+
|
|
|
+ for (int rowIndex = 1; rowIndex <= count; rowIndex++) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ String enterpriseName = poiUtils.getCellValue(sheetIndex, rowIndex, 0).toString().replace(" ", "");
|
|
|
+ String industry = poiUtils.getCellValue(sheetIndex, rowIndex, 1).toString().replace(" ", "");
|
|
|
+ String positionName = poiUtils.getCellValue(sheetIndex, rowIndex, 2).toString().replace(" ", "");
|
|
|
+ String settlementMethod = poiUtils.getCellValue(sheetIndex, rowIndex, 3).toString().replace(" ", "");
|
|
|
+ String salary = poiUtils.getCellValue(sheetIndex, rowIndex, 4).toString().replace(" ", "");
|
|
|
+ String recruitingNumbers = poiUtils.getCellValue(sheetIndex, rowIndex, 5).toString().replace(" ", "");
|
|
|
+ String desc = poiUtils.getCellValue(sheetIndex, rowIndex, 6).toString().replace(" ", "");
|
|
|
+ String contacts = poiUtils.getCellValue(sheetIndex, rowIndex, 7).toString().replace(" ", "");
|
|
|
+ String contactsPhone = poiUtils.getCellValue(sheetIndex, rowIndex, 8).toString().replace(" ", "");
|
|
|
+ String workArea = poiUtils.getCellValue(sheetIndex, rowIndex, 9).toString().replace(" ", "");
|
|
|
+ String address = poiUtils.getCellValue(sheetIndex, rowIndex, 10).toString().replace(" ", "");
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(enterpriseName)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写企业名称!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(industry)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写行业!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(positionName)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写职位名称!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(settlementMethod)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写结算方式!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(salary)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写薪资待遇!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(recruitingNumbers)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写招聘人数!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(desc)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写工作描述!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(contacts)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写联系人!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(contactsPhone)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写联系电话!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(workArea)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写工作地区!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(address)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写详细地址!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ EnterpriseInfo enterpriseInfo = enterpriseInfoService.findByName(enterpriseName);
|
|
|
+ if(enterpriseInfo==null){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("填写的企业名称在系统中不存在,请检查企业名称!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String industryValue = dataDictionaryService.findValueByCatalogNameAndName("意向行业",industry);
|
|
|
+ if(StringUtils.isEmpty(industryValue)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("填写的行业在系统中不存在,请检查行业!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String settlementMethodValue = dataDictionaryService.findValueByCatalogNameAndName("结算方式",settlementMethod);
|
|
|
+ if(StringUtils.isEmpty(settlementMethodValue)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("填写的结算方式在系统中不存在,请检查结算方式!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //企业
|
|
|
+ RecruitInformationInfo recruitInformationInfo = new RecruitInformationInfo();
|
|
|
+ recruitInformationInfo.setId(UUID.randomUUID().toString());
|
|
|
+ recruitInformationInfo.setDelFlag(false);
|
|
|
+ recruitInformationInfo.setCreateBy(subject);
|
|
|
+ recruitInformationInfo.setCreateTime(new Date());
|
|
|
+ recruitInformationInfo.setStatus("1");
|
|
|
+ recruitInformationInfo.setBrowseNumber(0);
|
|
|
+ recruitInformationInfo.setEnterpriseId(enterpriseInfo.getId());
|
|
|
+ recruitInformationInfo.setIndustry(industryValue);
|
|
|
+ recruitInformationInfo.setPositionName(positionName);
|
|
|
+ recruitInformationInfo.setSettlementMethod(settlementMethodValue);
|
|
|
+ recruitInformationInfo.setSalary(salary);
|
|
|
+ recruitInformationInfo.setRecruitingNumbers(recruitingNumbers);
|
|
|
+ recruitInformationInfo.setDesc(desc);
|
|
|
+ recruitInformationInfo.setContacts(contacts);
|
|
|
+ recruitInformationInfo.setContactsPhone(contactsPhone);
|
|
|
+ recruitInformationInfo.setWorkArea(workArea);
|
|
|
+ recruitInformationInfo.setAddress(address);
|
|
|
+
|
|
|
+
|
|
|
+ //保存新企业
|
|
|
+ recruitInformationInfoService.insert(recruitInformationInfo);
|
|
|
+ affectCount++;
|
|
|
+ } catch (Exception innerEx) {
|
|
|
+ logger.error(innerEx.getMessage(), innerEx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (failCount > 0) {
|
|
|
+ //有导入失败的记录
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
+
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(sheetIndex, validateColIndex, 1 + affectCount + failCount);
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig, "import", "error.xls", input);
|
|
|
+
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|