Selaa lähdekoodia

导入企业和导入招聘信息功能

yanliming 2 vuotta sitten
vanhempi
commit
129b313c66

+ 1 - 0
common/src/main/java/com/jpsoft/employment/modules/base/dao/EnterpriseInfoDAO.java

@@ -15,4 +15,5 @@ public interface EnterpriseInfoDAO {
 	int delete(String id);
 	List<EnterpriseInfo> list();
 	List<EnterpriseInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
+	EnterpriseInfo findByName(String name);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/employment/modules/base/service/EnterpriseInfoService.java

@@ -14,4 +14,5 @@ public interface EnterpriseInfoService {
 	int delete(String id);
 	List<EnterpriseInfo> list();
 	Page<EnterpriseInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
+	EnterpriseInfo findByName(String name);
 }

+ 6 - 0
common/src/main/java/com/jpsoft/employment/modules/base/service/impl/EnterpriseInfoServiceImpl.java

@@ -58,6 +58,12 @@ public class EnterpriseInfoServiceImpl implements EnterpriseInfoService {
 		// TODO Auto-generated method stub
 		return enterpriseInfoDAO.list();
 	}
+
+
+	@Override
+	public EnterpriseInfo findByName(String name){
+		return enterpriseInfoDAO.findByName(name);
+	}
 		
 	@Override
 	public Page<EnterpriseInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {

+ 3 - 0
common/src/main/resources/mapper/base/EnterpriseInfo.xml

@@ -89,6 +89,9 @@
 	<select id="list" resultMap="EnterpriseInfoMap">
 		select * from base_enterprise_info where del_flag=false order by name_ asc
 	</select>
+	<select id="findByName" resultMap="EnterpriseInfoMap">
+		select * from base_enterprise_info where del_flag=false and name_=#{0} limit 1
+	</select>
 	<select id="search" parameterType="hashmap" resultMap="EnterpriseInfoMap">
 		<![CDATA[
 			select * from base_enterprise_info

+ 1 - 1
web/src/main/java/com/jpsoft/employment/modules/base/controller/EnterpriseInfoController.java

@@ -324,7 +324,7 @@ public class EnterpriseInfoController {
                     enterpriseInfo.setId(UUID.randomUUID().toString());
                     enterpriseInfo.setName(name);
                     enterpriseInfo.setAddress(address);
-                    enterpriseInfo.setStatus("0");
+                    enterpriseInfo.setStatus("1");
                     enterpriseInfo.setCreateBy(subject);
                     enterpriseInfo.setCreateTime(new Date());
                     enterpriseInfo.setDelFlag(false);

+ 200 - 0
web/src/main/java/com/jpsoft/employment/modules/base/controller/RecruitInformationInfoController.java

@@ -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;
+    }
 }