|
|
@@ -0,0 +1,1727 @@
|
|
|
+package com.sprivacy.pms.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sprivacy.pms.form.per.PerForm;
|
|
|
+import com.sprivacy.pms.http.HttpResponse;
|
|
|
+import com.sprivacy.pms.http.HttpResponseUtils;
|
|
|
+import com.sprivacy.pms.mapper.PerMapper;
|
|
|
+import com.sprivacy.pms.mapper.TempFileResultMapper;
|
|
|
+import com.sprivacy.pms.model.*;
|
|
|
+import com.sprivacy.pms.properties.PmsProperties;
|
|
|
+import com.sprivacy.pms.service.*;
|
|
|
+import com.sprivacy.pms.util.CleanDateUtil;
|
|
|
+import com.sprivacy.pms.util.DeCompressUtil;
|
|
|
+import com.sprivacy.pms.util.SpecialParseExcel;
|
|
|
+import com.sprivacy.pms.util.ZipUtils;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.lang3.time.DateUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.apache.poi.ooxml.POIXMLDocumentPart;
|
|
|
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author guanhuijuan
|
|
|
+ * @create 2019-02-02 15:51
|
|
|
+ * @desc TestController
|
|
|
+ **/
|
|
|
+@RestController
|
|
|
+// @RequestMapping(value = "/test")
|
|
|
+public class TestController {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(SysUserRoleController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UploadService uploadService;
|
|
|
+
|
|
|
+ private final static int ROW_START = 4;
|
|
|
+ private final static int CELL_END = 30;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PerService perService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PerMapper perMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkRecService workRecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EduRecService eduRecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RewRecService rewRecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WageService wageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SocRelService socRelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FamRelService famRelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TempFileResultMapper tempFileResultMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PmsProperties properties;
|
|
|
+
|
|
|
+ @Value("${pms.common.upload-dir}")
|
|
|
+ private String uploadDir;
|
|
|
+
|
|
|
+ @Value("${pms.common.decompress-dir}")
|
|
|
+ private String deCompressDir;
|
|
|
+
|
|
|
+ @Value("${pms.common.saved-dir}")
|
|
|
+ private String savedDir;
|
|
|
+
|
|
|
+ @Value("${pms.common.base-url}")
|
|
|
+ private String baseUrl;
|
|
|
+
|
|
|
+ @ApiOperation("red info")
|
|
|
+ @GetMapping(value = "/test/red")
|
|
|
+ public HttpResponse uploadImageTest() throws Exception{
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("name", "name");
|
|
|
+ jsonObject.put("sex", "sex");
|
|
|
+ jsonObject.put("nation", "nation");
|
|
|
+ jsonObject.put("birthplace", "birthplace");
|
|
|
+ jsonObject.put("birthday", "birthday");
|
|
|
+ jsonObject.put("workingTime", "workingTime");
|
|
|
+ jsonObject.put("joiningPartyTime", "joiningPartyTime");
|
|
|
+ jsonObject.put("healthStatus", "healthStatus");
|
|
|
+ jsonObject.put("education", "education");
|
|
|
+ jsonObject.put("graTimeSchoolMajor", "graTimeSchoolMajor");
|
|
|
+ jsonObject.put("personnelNature", "personnelNature");
|
|
|
+ jsonObject.put("jobTitle", "jobTitle");
|
|
|
+ jsonObject.put("titleAcqTime", "titleAcqTime");
|
|
|
+ jsonObject.put("currentJob", "currentJob");
|
|
|
+ jsonObject.put("contactPhone", "contactPhone");
|
|
|
+ jsonObject.put("address", "address");
|
|
|
+ jsonObject.put("idNumber", "idNumber");
|
|
|
+ jsonObject.put("eduRecord","eduRecord");
|
|
|
+ jsonObject.put("eduRecord", "eduRecord");
|
|
|
+ jsonObject.put("workRecord","workRecord");
|
|
|
+ jsonObject.put("workRecord", "workRecord");
|
|
|
+ jsonObject.put("famRel", "famRel");
|
|
|
+ jsonObject.put("socRel", "socRel");
|
|
|
+ jsonObject.put("rewRec", "rewRec");
|
|
|
+ return HttpResponseUtils.ok(1,"获取成功",jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("长传图片")
|
|
|
+ @PostMapping(value = "/test/import/img")
|
|
|
+ public HttpResponse uploadImageTest(MultipartFile file) throws Exception {
|
|
|
+ if (null != file){
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ try {
|
|
|
+ // 图片大小单位是Kb
|
|
|
+ Long size = file.getSize() / 1024;
|
|
|
+
|
|
|
+ if (size >= 200) {
|
|
|
+ return HttpResponseUtils.ok(1,"上传失败", file.getOriginalFilename() + ":超过了指定大小");
|
|
|
+ }
|
|
|
+ // 文件保存路径
|
|
|
+ // 图片后缀
|
|
|
+ String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
+ // 图片名称
|
|
|
+ String name = UUID.randomUUID().toString() + suffix;
|
|
|
+ // 图片访问路径
|
|
|
+ String url = properties.getCommon().getFileDir() + name;
|
|
|
+
|
|
|
+ // 转存文件
|
|
|
+ file.transferTo(new File(url));
|
|
|
+ return HttpResponseUtils.ok(1,"上传成功",url);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return HttpResponseUtils.error(0,"您长传的文件为空,请重新上传",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("整批量/单个文件上传人员信息")
|
|
|
+ @PostMapping(value = "/test/import/rarFile")
|
|
|
+ public HttpResponse uploadAllExcelsTest(MultipartFile file) throws Exception {
|
|
|
+ List<PerForm> perForms = new ArrayList<>();
|
|
|
+ String strOriginalFilename = file.getOriginalFilename();
|
|
|
+ String strFileType = StringUtils.substringAfter(strOriginalFilename, ".");
|
|
|
+ log.info("后缀名--->" + strFileType);
|
|
|
+ // 后缀名转换 如:JPG--jpg
|
|
|
+ if (StringUtils.isAllUpperCase(strFileType)) {
|
|
|
+ strFileType = StringUtils.lowerCase(strFileType);
|
|
|
+ log.info("UpperCase后缀名转换-->" + strFileType);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strFileType.equals("xls") || strFileType.equals("xlsx")){
|
|
|
+ // 调用单个excel上传接口
|
|
|
+ log.info("<*******整批次批量上传test*******> <单个>导入接口! START");
|
|
|
+ perForms = importSingleExcel(file);
|
|
|
+ }else {
|
|
|
+ log.info("<*******整批次批量上传*******> <批量>导入接口! START");
|
|
|
+ perForms = uploadService.importAllExcels(file);
|
|
|
+ }
|
|
|
+ if (null != perForms && perForms.size() > 0){
|
|
|
+ log.info("<*******整批次批量上传*******> END responseData{}:"+JSON.toJSONString(perForms));
|
|
|
+ return HttpResponseUtils.ok(1,"上传成功",perForms);
|
|
|
+ }
|
|
|
+
|
|
|
+ return HttpResponseUtils.ok(0,"上传失败",perForms);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<PerForm> importSingleExcel(MultipartFile file) throws Exception {
|
|
|
+ List<PerForm> perForms = new ArrayList<>();
|
|
|
+ Workbook workbook = null;
|
|
|
+ HSSFWorkbook wb;
|
|
|
+ String originalFileName = file.getOriginalFilename();
|
|
|
+ if (StringUtils.endsWithIgnoreCase(originalFileName, "xls")) {
|
|
|
+ log.info("importSingleExcel < .xls>");
|
|
|
+ workbook = new HSSFWorkbook(file.getInputStream());
|
|
|
+ }
|
|
|
+ if (StringUtils.endsWithIgnoreCase(originalFileName, "xlsx")) {
|
|
|
+ log.info("importSingleExcel < .xlsx>");
|
|
|
+ workbook = new XSSFWorkbook(file.getInputStream());
|
|
|
+ }
|
|
|
+ if (null != workbook) {
|
|
|
+ int sheetNum = workbook.getNumberOfSheets();
|
|
|
+ // 文件类型转换
|
|
|
+ File f = null;
|
|
|
+ if (file.equals("") || file.getSize() <= 0) {
|
|
|
+ file = null;
|
|
|
+ } else {
|
|
|
+ // todo 写入rar文件 待处理 0214更正
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
+ FileOutputStream out = new FileOutputStream(deCompressDir.concat(file.getOriginalFilename()));
|
|
|
+ int btsRead = 0;
|
|
|
+ byte[] bf = new byte[8192];
|
|
|
+ while ((btsRead = inputStream.read(bf, 0, 8192)) != -1) {
|
|
|
+ out.write(bf, 0, btsRead);
|
|
|
+ // log.info("importSingleExcel write out>>> "+JSON.toJSONString(out));
|
|
|
+ }
|
|
|
+ out.close();
|
|
|
+
|
|
|
+ InputStream ins = file.getInputStream();
|
|
|
+ f = new File(file.getOriginalFilename());
|
|
|
+ inputStreamToFile(ins, f);
|
|
|
+ }
|
|
|
+ log.info("importSingleExcel START");
|
|
|
+ // TODO GOTO.
|
|
|
+ PerForm form = parseSingleExcel(f, sheetNum, workbook, null);
|
|
|
+ perForms.add(form);
|
|
|
+ log.info("importSingleExcel END data>" + JSON.toJSONString(perForms));
|
|
|
+ }
|
|
|
+ return perForms;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PerForm parseSingleExcel(File file, int sheetNum, Workbook workbook, HSSFWorkbook wb) throws Exception {
|
|
|
+ log.info("parseSingleExcel START");
|
|
|
+ PerForm form = checkSheet(file, sheetNum, workbook, null);
|
|
|
+ log.info("parseSingleExcel END form>>>" + JSON.toJSONString(form));
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PerForm checkSheet(File file, int sheetNum, Workbook workbook, HSSFWorkbook wb) throws Exception {
|
|
|
+ if (null != workbook) {
|
|
|
+ for (int i = 0; i < sheetNum; i++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(i);
|
|
|
+ if (i == 0) {
|
|
|
+ log.info("-------toSheet解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ // 处理照片
|
|
|
+ for (Row row : sheet) {
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+ if (rowNum == 0) {
|
|
|
+ if (row.getCell(0).getStringCellValue().equals("基本情况登记表")) {
|
|
|
+ // TODO GOTO。
|
|
|
+ PerForm form = toSheet(file, sheetNum, workbook);
|
|
|
+ log.info("getPerForms <workbook toSheet> form-->" + JSON.toJSONString(form));
|
|
|
+ return form;
|
|
|
+ } else {
|
|
|
+ // todo 判断文件格式呢。是否为正确的excel文件;
|
|
|
+ log.info("NOT A CORRECT EXCEL FILE!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != wb) {
|
|
|
+ for (int i = 0; i < sheetNum; i++) {
|
|
|
+ Sheet sheet = wb.getSheetAt(i);
|
|
|
+ if (i == 0) {
|
|
|
+ log.info("-------toHSSFSheet解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ // 处理照片
|
|
|
+ for (Row row : sheet) {
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+ if (rowNum == 0) {
|
|
|
+ if (row.getCell(0).getStringCellValue().equals("基本情况登记表")) {
|
|
|
+ // TODO GOTO。
|
|
|
+ PerForm form = toHSSFSheet(file, sheetNum, wb);
|
|
|
+ log.info("getPerForms <wb toHSSFSheet> form-->" + JSON.toJSONString(form));
|
|
|
+ return form;
|
|
|
+ } else {
|
|
|
+ // todo 判断文件格式呢。是否为正确的excel文件;
|
|
|
+ log.info("NOT A CORRECT EXCEL FILE!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("下载文件")
|
|
|
+ @GetMapping("/getUrl/{id}")
|
|
|
+ public void getUrl(List<Long> ids, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
+ // 获取当前真实路径
|
|
|
+ uploadService.download(ids,request,response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取改人员的所有信息
|
|
|
+ * @param id
|
|
|
+ * @return List<PerForm>
|
|
|
+ */
|
|
|
+ public List<PerForm> getPersonnelForm(long id) {
|
|
|
+ List<PerForm> form = new ArrayList<>();
|
|
|
+ PerForm perForm = new PerForm();
|
|
|
+ Per personnel = perMapper.selectById(id);
|
|
|
+ if (null != personnel) {
|
|
|
+ perForm.setPer(personnel);
|
|
|
+ }
|
|
|
+ List<PerEduRec> eduRecords = eduRecService.findByPid(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(eduRecords)) {
|
|
|
+ perForm.setEduRecords(eduRecords);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PerWorkRec> workRecords = workRecService.findByPid(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(workRecords)) {
|
|
|
+ perForm.setWorkRecords(workRecords);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PerFamRel> familyRelations = famRelService.findByPid(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(familyRelations)) {
|
|
|
+ perForm.setFamRelations(familyRelations);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PerSocRel> socialRelations = socRelService.findByPid(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(socialRelations)) {
|
|
|
+
|
|
|
+ perForm.setSocRelations(socialRelations);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PerRewRec> rewards = rewRecService.findByPid(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(rewards)) {
|
|
|
+ perForm.setRewRecords(rewards);
|
|
|
+ }
|
|
|
+ form.add(perForm);
|
|
|
+ log.info(JSON.toJSONString(form));
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("整批量/单个文件上传人员信息")
|
|
|
+ @PostMapping(value = "/import/rarFile")
|
|
|
+ public HttpResponse uploadAllExcels(MultipartFile file) throws Exception {
|
|
|
+ log.info("整批次批量上传 start");
|
|
|
+ List<PerForm> perForms = new ArrayList<>();
|
|
|
+
|
|
|
+ String strOriginalFilename = file.getOriginalFilename();
|
|
|
+ String strFileType = StringUtils.substringAfter(strOriginalFilename, ".");
|
|
|
+ log.info("后缀名--->" + strFileType);
|
|
|
+ // 后缀名转换 如:JPG--jpg
|
|
|
+ if (StringUtils.isAllUpperCase(strFileType)) {
|
|
|
+ strFileType = StringUtils.lowerCase(strFileType);
|
|
|
+ log.info("UpperCase后缀名转换-->" + strFileType);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strFileType.equals("xls") || strFileType.equals("xlsx")){
|
|
|
+ // 调用单个excel上传接口
|
|
|
+ log.info("调用单个导入接口!");
|
|
|
+ perForms = uploadService.importSingleExcel(file);
|
|
|
+ }else {
|
|
|
+ log.info("调用批量导入接口!");
|
|
|
+ // System.err.println("<-size->"+perForms.size());
|
|
|
+ perForms = uploadService.importAllExcels(file);
|
|
|
+ }
|
|
|
+ if (null != perForms && perForms.size() > 0){
|
|
|
+ return HttpResponseUtils.ok(1,"上传成功",perForms);
|
|
|
+ }
|
|
|
+
|
|
|
+ return HttpResponseUtils.ok(0,"上传失败",perForms);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<PerForm> importAllExcels(MultipartFile file) throws Exception {
|
|
|
+
|
|
|
+ File f = null;
|
|
|
+ if (file.equals("") || file.getSize() <= 0) {
|
|
|
+ file = null;
|
|
|
+ } else {
|
|
|
+ // todo 写入rar文件 待处理
|
|
|
+ // File pdfFile = new File();
|
|
|
+
|
|
|
+ // file.transferTo(new File(deCompressDir.concat(file.getOriginalFilename())));
|
|
|
+ InputStream ins = file.getInputStream();
|
|
|
+ f = new File(file.getOriginalFilename());
|
|
|
+ inputStreamToFile(ins, f);
|
|
|
+ }
|
|
|
+ // todo 判断该文件是rar还是zip
|
|
|
+ List<String> unRarAndZipStrs = new ArrayList<>();
|
|
|
+ // List<String> unRarStrs = DeCompressUtil.unRar(f.getPath(),"E:\\mnt\\rar\\");
|
|
|
+ if (!ZipUtils.isArchiveFile(f)) {
|
|
|
+ log.info("to rar DeCompress!");
|
|
|
+ unRarAndZipStrs = DeCompressUtil.unRar(f.getPath(), uploadDir);
|
|
|
+ } else {
|
|
|
+ log.info("to zip DeCompress");
|
|
|
+ // todo 待开发
|
|
|
+ // unRarAndZipStrs = DeCompressUtil.unZip(f.getPath(),uploadDir);
|
|
|
+ }
|
|
|
+ List<PerForm> perForms = new ArrayList<>();
|
|
|
+ for (String unRarStr : unRarAndZipStrs) {
|
|
|
+ // 解析每个excel文件
|
|
|
+ perForms.add(parseAllExcels(unRarStr));
|
|
|
+ }
|
|
|
+ if (perForms.size() > 0) {
|
|
|
+ return perForms;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取所有excels
|
|
|
+ // if (!unRarStr.contains("失败")){
|
|
|
+ // ExcelParseUtil.getAllExcels(str);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void inputStreamToFile(InputStream ins, File file) {
|
|
|
+ try {
|
|
|
+ // FileOutputStream out = new FileOutputStream(deCompressDir);
|
|
|
+ // out.write(data);
|
|
|
+ // out.close();
|
|
|
+ OutputStream os = new FileOutputStream(file);
|
|
|
+ int bytesRead = 0;
|
|
|
+ byte[] buffer = new byte[8192];
|
|
|
+ while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
|
|
|
+ os.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ os.close();
|
|
|
+ ins.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * todo 解析单个excel文件
|
|
|
+ * @param file
|
|
|
+ * @return PerForm
|
|
|
+ */
|
|
|
+ public PerForm parseSingleExcels(File file, int sheetNum, Workbook workbook, HSSFWorkbook wb) throws Exception {
|
|
|
+ PerForm form = getPerForms(file,sheetNum,workbook,null);
|
|
|
+ // System.err.println("single sheetNum-->"+sheetNum);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * todo 解析rar批量excel
|
|
|
+ *
|
|
|
+ * @param strPath
|
|
|
+ */
|
|
|
+ public PerForm parseAllExcels(String strPath) {
|
|
|
+ File file = new File(strPath);
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ for (File fi : files) {
|
|
|
+ // 对文件进行过滤,只读取Excel文件
|
|
|
+ if (fi.getName().indexOf(".xls") > 0) {
|
|
|
+ // parseExcel(fi);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ HSSFWorkbook wb;
|
|
|
+ FileInputStream fs;
|
|
|
+ try {
|
|
|
+ fs = new FileInputStream(file.getAbsolutePath());
|
|
|
+ POIFSFileSystem ps = new POIFSFileSystem(fs);
|
|
|
+ // 使用POI提供的方法得到excel的信息
|
|
|
+ wb = new HSSFWorkbook(ps);
|
|
|
+
|
|
|
+ // ------------------------读取excel-------------------------------------
|
|
|
+ return dealWithAllExcelSheet(file, wb);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ public PerForm dealWithAllExcelSheet(File file, HSSFWorkbook wb) throws Exception {
|
|
|
+ // SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ int sheetNum = wb.getNumberOfSheets();
|
|
|
+ // System.err.println("all sheetNum-->"+sheetNum);
|
|
|
+ PerForm form = getPerForms(file,sheetNum,null,wb);
|
|
|
+ log.info(file.getAbsoluteFile() + "-" + file.getName() + "---initSheet form-->" + JSON.toJSONString(form));
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PerForm getPerForms(File file,int sheetNum,Workbook workbook,HSSFWorkbook wb) throws Exception {
|
|
|
+ if (null != workbook) {
|
|
|
+ PerForm form = toSheet(file,sheetNum,workbook);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+ if (null != wb){
|
|
|
+ PerForm form = toHSSFSheet(file,sheetNum,wb);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PerForm toSheet2(File file, int sheetNum, Workbook workbook) throws Exception {
|
|
|
+ PerForm form = new PerForm();
|
|
|
+ Per personnel = new Per();
|
|
|
+ List<PerEduRec> eduRecords = new ArrayList<>();
|
|
|
+ List<PerWorkRec> workRecords = new ArrayList<>();
|
|
|
+ List<PerFamRel> familyRelations = new ArrayList<>();
|
|
|
+ List<PerSocRel> socialRelations = new ArrayList<>();
|
|
|
+ List<PerRewRec> rewards = new ArrayList<>();
|
|
|
+ List<TempFileResult> tempFileResults = new ArrayList<>();
|
|
|
+ TempFileResult tempFileResult = new TempFileResult();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+
|
|
|
+ String avatar = getAvatar(workbook.getSheetAt(0), workbook);
|
|
|
+ personnel.setAvatar(avatar);
|
|
|
+
|
|
|
+ log.info("toSheet 获取avatar-->" + avatar);
|
|
|
+ int correctFieldNum = 0;
|
|
|
+ int exceptionFieldNum = 0;
|
|
|
+ for (int i = 0; i < sheetNum; i++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(i);
|
|
|
+
|
|
|
+ // todo 遍历取sheet
|
|
|
+ if (i == 0) {
|
|
|
+ log.info("-------toSheet解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ tempFileResult.setFileName(file.getName());
|
|
|
+ // 处理照片
|
|
|
+ for (Row row : sheet) {
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+ if (rowNum == 1) {
|
|
|
+ String tempWorkUnit = row.getCell(0).getStringCellValue();
|
|
|
+ String workUnit = StringUtils.substringAfter(tempWorkUnit, ":");
|
|
|
+ personnel.setWorkUnit(StringUtils.trim(workUnit));
|
|
|
+ }
|
|
|
+ if (rowNum == 2) {
|
|
|
+ String name = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("姓 名")) {
|
|
|
+ name = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ name = "测试name";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("name", name);
|
|
|
+ }
|
|
|
+
|
|
|
+ String sex = "";
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("性 别")) {
|
|
|
+ sex = row.getCell(4).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ sex = "测试sex";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("sex", sex);
|
|
|
+ }
|
|
|
+
|
|
|
+ String nation = "";
|
|
|
+ if (row.getCell(5).getStringCellValue().contains("民 族")) {
|
|
|
+ nation = row.getCell(6).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ nation = "测试nation";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("nation", nation);
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo
|
|
|
+ String birthplace = "";
|
|
|
+ if (row.getCell(7).getStringCellValue().contains("籍 贯")) {
|
|
|
+ birthplace = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ birthplace = "测试birthplace";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("birthplace", birthplace);
|
|
|
+ }
|
|
|
+ personnel.setName(name);
|
|
|
+ personnel.setSex(sex);
|
|
|
+ personnel.setNation(nation);
|
|
|
+ personnel.setBirthplace(birthplace);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 3) {
|
|
|
+ String birthday;
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ if (null != row.getCell(2).getStringCellValue()) {
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("出生年月")) {
|
|
|
+ birthday = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ birthday = "测试birthday";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("birthday", birthday);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ birthday = "";
|
|
|
+ }
|
|
|
+ row.getCell(4).setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ String workingTime;
|
|
|
+ if (null != row.getCell(4).getStringCellValue()) {
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("工作时间")) {
|
|
|
+ workingTime = row.getCell(4).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ workingTime = "测试workingTime";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("workingTime", workingTime);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ workingTime = "";
|
|
|
+ }
|
|
|
+ String joiningPartyTime;
|
|
|
+ row.getCell(6).setCellType(CellType.STRING);
|
|
|
+ if (null != row.getCell(6).getStringCellValue()) {
|
|
|
+ if (row.getCell(5).getStringCellValue().contains("入党时间")) {
|
|
|
+ joiningPartyTime = row.getCell(6).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ joiningPartyTime = "测试joiningPartyTime";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("joiningPartyTime", joiningPartyTime);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ joiningPartyTime = "";
|
|
|
+ }
|
|
|
+ String healthStatus = "";
|
|
|
+ if (row.getCell(7).getStringCellValue().contains("健康状况")) {
|
|
|
+ healthStatus = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ healthStatus = "测试healthStatus";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("healthStatus", healthStatus);
|
|
|
+ }
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(birthday), "-") && CleanDateUtil.cleanDate(birthday).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("birthday", CleanDateUtil.cleanDate(birthday));
|
|
|
+ }
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(workingTime), "-") && CleanDateUtil.cleanDate(workingTime).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("workingTime", CleanDateUtil.cleanDate(workingTime));
|
|
|
+ }
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(joiningPartyTime), "-") && CleanDateUtil.cleanDate(joiningPartyTime).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("joiningPartyTime", CleanDateUtil.cleanDate(joiningPartyTime));
|
|
|
+ }
|
|
|
+ personnel.setBirthday(CleanDateUtil.cleanDate(birthday));
|
|
|
+ personnel.setWorkingTime(CleanDateUtil.cleanDate(workingTime));
|
|
|
+ personnel.setJoiningPartyTime(CleanDateUtil.cleanDate(joiningPartyTime));
|
|
|
+ personnel.setHealthStatus(healthStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 4) {
|
|
|
+
|
|
|
+ String education = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("学 历")) {
|
|
|
+ education = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ education = "测试education";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("education", education);
|
|
|
+ }
|
|
|
+ // todo 毕业院校
|
|
|
+ String graTimeSchoolMajor = "";
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("何年何月毕业于何校何专业")) {
|
|
|
+ graTimeSchoolMajor = row.getCell(6).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ graTimeSchoolMajor = "测试graTimeSchoolMajor";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("graTimeSchoolMajor", graTimeSchoolMajor);
|
|
|
+ }
|
|
|
+ personnel.setEducation(education);
|
|
|
+ personnel.setGraTimeSchoolMajor(graTimeSchoolMajor);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 5) {
|
|
|
+ // todo 后期时需求里无该 “政治面貌” 字段
|
|
|
+ String personnelNature = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("人员性质")) {
|
|
|
+ personnelNature = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ personnelNature = "测试personnelNature";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("personnelNature", personnelNature);
|
|
|
+ }
|
|
|
+ row.getCell(5).setCellType(CellType.STRING);
|
|
|
+ // todo 职称
|
|
|
+ String jobTitle = "";
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("职 称")) {
|
|
|
+ jobTitle = row.getCell(5).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ jobTitle = "测试jobTitle";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("jobTitle", jobTitle);
|
|
|
+ }
|
|
|
+ // todo 是否出错,8
|
|
|
+ String titleAcqTime = "";
|
|
|
+ row.getCell(8).setCellType(CellType.STRING);
|
|
|
+ if (row.getCell(6).getStringCellValue().contains("职称取得时间")) {
|
|
|
+ titleAcqTime = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ titleAcqTime = "测试titleAcqTime";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("titleAcqTime", titleAcqTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(titleAcqTime), "-") && CleanDateUtil.cleanDate(titleAcqTime).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("titleAcqTime", CleanDateUtil.cleanDate(titleAcqTime));
|
|
|
+ }
|
|
|
+ // personnel.setPoliticsStatus(politicsStatus);
|
|
|
+ personnel.setPerNature(personnelNature);
|
|
|
+ personnel.setJobTitle(jobTitle);
|
|
|
+ personnel.setTitleAcqTime(CleanDateUtil.cleanDate(titleAcqTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 6) {
|
|
|
+ // todo 重复 当前模板不再需要在此处获取
|
|
|
+ String currentJob = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("现任职务")) {
|
|
|
+ currentJob = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ currentJob = "测试currentJob";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("currentJob", currentJob);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ row.getCell(8).setCellType(CellType.STRING);
|
|
|
+ row.getCell(7).setCellType(CellType.STRING);
|
|
|
+ String contactPhone = "";
|
|
|
+ if (row.getCell(5).getStringCellValue().contains("联系电话")) {
|
|
|
+ contactPhone = row.getCell(7).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ contactPhone = "测试contactPhone";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("contactPhone", contactPhone);
|
|
|
+ }
|
|
|
+ personnel.setCurrentJob(currentJob);
|
|
|
+ personnel.setContactPhone(contactPhone);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 7) {
|
|
|
+ String address = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("家庭住址")) {
|
|
|
+ address = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ address = "测试address";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("address", address);
|
|
|
+ }
|
|
|
+ String idNumber = "";
|
|
|
+ if (row.getCell(7).getStringCellValue().contains("身份证号码")) {
|
|
|
+ idNumber = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ idNumber = "测试idNumber";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("idNumber", idNumber);
|
|
|
+ }
|
|
|
+ personnel.setAddress(address);
|
|
|
+ personnel.setIdNumber(idNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 8){
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("学习时间") && row.getCell(3).getStringCellValue().contains("学 校") && row.getCell(7).getStringCellValue().contains("专 业")){
|
|
|
+ // System.err.println("8 包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet教育关系 异常字段!!!!");
|
|
|
+ jsonObject.put("eduRecord","eduRecord");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 9 || rowNum == 10 || rowNum == 11 || rowNum == 12) {
|
|
|
+ PerEduRec eduRecord = getEduRecord(row);
|
|
|
+ if (null != eduRecord) {
|
|
|
+ eduRecords.add(eduRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 13){
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("任职时间") && row.getCell(3).getStringCellValue().contains("单 位") && row.getCell(7).getStringCellValue().contains("职 务")){
|
|
|
+ // System.err.println("13 包含");
|
|
|
+ correctFieldNum++;
|
|
|
+
|
|
|
+ }else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet工作简历 异常字段!!!!");
|
|
|
+ jsonObject.put("workRecord","workRecord");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (rowNum == 14 || rowNum == 15 || rowNum == 16 || rowNum == 17 || rowNum == 18 || rowNum == 19 || rowNum == 20 || rowNum == 21 || rowNum == 22) {
|
|
|
+ PerWorkRec workRecord = getWorkRecord(row);
|
|
|
+ if (null != workRecord) {
|
|
|
+ workRecords.add(workRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 13){
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("任职时间") && row.getCell(3).getStringCellValue().contains("单 位") && row.getCell(7).getStringCellValue().contains("职 务")){
|
|
|
+ System.err.println("13任职时间包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ System.err.println("13任职时间 不 包含");
|
|
|
+ if (rowNum == 14){
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("任职时间") && row.getCell(3).getStringCellValue().contains("单 位") && row.getCell(7).getStringCellValue().contains("职 务")) {
|
|
|
+ System.err.println("14任职时间包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ System.err.println("14任职时间 不 包含");
|
|
|
+ if (rowNum == 15){
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("任职时间") && row.getCell(3).getStringCellValue().contains("单 位") && row.getCell(7).getStringCellValue().contains("职 务")) {
|
|
|
+ System.err.println("15任职时间包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ System.err.println("15任职时间 不 包含");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ form.setEduRecords(eduRecords);
|
|
|
+ form.setWorkRecords(workRecords);
|
|
|
+ form.setFamRelations(familyRelations);
|
|
|
+ form.setSocRelations(socialRelations);
|
|
|
+ form.setRewRecords(rewards);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i == 1) {
|
|
|
+ log.info("-------sheet解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ for (Row row : sheet) {
|
|
|
+ // todo sheet 2
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+
|
|
|
+ if (rowNum == 0) {
|
|
|
+
|
|
|
+ if (row.getCell(2).getStringCellValue().contains("姓 名") && row.getCell(3).getStringCellValue().contains("出生年月") && row.getCell(4).getStringCellValue().contains("政治面貌") && row.getCell(5).getStringCellValue().contains("工 作 单 位 及 职 务")) {
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet家庭关系 异常字段!!!!");
|
|
|
+ jsonObject.put("famRel", "famRel");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 1 || rowNum == 3 || rowNum == 4 || rowNum == 5 || rowNum == 6 || rowNum == 7 || rowNum == 8) {
|
|
|
+ PerFamRel relation = getFamRel(rowNum, row);
|
|
|
+ if (null != relation) {
|
|
|
+ familyRelations.add(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (rowNum == 9) {
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("关 系") && row.getCell(2).getStringCellValue().contains("姓 名") && row.getCell(3).getStringCellValue().contains("年 龄") && row.getCell(4).getStringCellValue().contains("政治面貌") && row.getCell(5).getStringCellValue().contains("工 作 单 位 及 职 务")) {
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet社会关系 异常字段!!!!");
|
|
|
+ jsonObject.put("socRel", "socRel");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 10 || rowNum == 11 || rowNum == 12 || rowNum == 13 || rowNum == 14) {
|
|
|
+ PerSocRel relation = getSocRel(row);
|
|
|
+ if (null != relation) {
|
|
|
+ socialRelations.add(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 15) {
|
|
|
+
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ if (row.getCell(2).getStringCellValue().contains("时 间") && row.getCell(4).getStringCellValue().contains("奖 惩 内 容")) {
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet奖惩关系 异常字段!!!!");
|
|
|
+ jsonObject.put("rewRec", "rewRec");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 16 || rowNum == 17 || rowNum == 18 || rowNum == 19 || rowNum == 20) {
|
|
|
+ PerRewRec reward = getReward(row);
|
|
|
+ if (null != reward) {
|
|
|
+ rewards.add(reward);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info(file.getName() + "< toSheet >" + JSON.toJSONString(form));
|
|
|
+
|
|
|
+ tempFileResult.setCorrectFieldNum(String.valueOf(correctFieldNum));
|
|
|
+ tempFileResult.setExceptionFieldNum(String.valueOf(exceptionFieldNum));
|
|
|
+ if (exceptionFieldNum == 0) {
|
|
|
+ tempFileResult.setStatus("ok");
|
|
|
+ } else {
|
|
|
+ tempFileResult.setStatus(String.valueOf(exceptionFieldNum));
|
|
|
+ }
|
|
|
+ tempFileResult.setCheckField(jsonObject.toString());
|
|
|
+ tempFileResultMapper.insert(tempFileResult);
|
|
|
+ tempFileResults.add(tempFileResult);
|
|
|
+ personnel.setFileId(tempFileResult.getId());
|
|
|
+ form.setPer(personnel);
|
|
|
+ form.setTempFileResults(tempFileResults);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PerForm toSheet(File file, int sheetNum, Workbook workbook) throws Exception {
|
|
|
+ PerForm form = new PerForm();
|
|
|
+ Per personnel = new Per();
|
|
|
+ List<PerEduRec> eduRecords = new ArrayList<>();
|
|
|
+ List<PerWorkRec> workRecords = new ArrayList<>();
|
|
|
+ List<PerFamRel> familyRelations = new ArrayList<>();
|
|
|
+ List<PerSocRel> socialRelations = new ArrayList<>();
|
|
|
+ List<PerRewRec> rewards = new ArrayList<>();
|
|
|
+ List<TempFileResult> tempFileResults = new ArrayList<>();
|
|
|
+ TempFileResult tempFileResult = new TempFileResult();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+
|
|
|
+ String avatar = getAvatar(workbook.getSheetAt(0), workbook);
|
|
|
+ personnel.setAvatar(avatar);
|
|
|
+
|
|
|
+ log.info("toSheet 获取avatar-->" + avatar);
|
|
|
+ int correctFieldNum = 0;
|
|
|
+ int exceptionFieldNum = 0;
|
|
|
+ for (int i = 0; i < sheetNum; i++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(i);
|
|
|
+
|
|
|
+ // todo 遍历取sheet
|
|
|
+ if (i == 0) {
|
|
|
+ log.info("-------toSheet解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ tempFileResult.setFileName(file.getName());
|
|
|
+ // 处理照片
|
|
|
+ for (Row row : sheet) {
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+
|
|
|
+
|
|
|
+ if (rowNum == 1) {
|
|
|
+ String tempWorkUnit = row.getCell(0).getStringCellValue();
|
|
|
+ String workUnit = StringUtils.substringAfter(tempWorkUnit, ":");
|
|
|
+ personnel.setWorkUnit(StringUtils.trim(workUnit));
|
|
|
+ }
|
|
|
+ if (rowNum == 2) {
|
|
|
+ String name = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("姓 名")) {
|
|
|
+ name = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ name = "测试name";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("name", name);
|
|
|
+ }
|
|
|
+
|
|
|
+ String sex = "";
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("性 别")) {
|
|
|
+ sex = row.getCell(4).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ sex = "测试sex";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("sex", sex);
|
|
|
+ }
|
|
|
+
|
|
|
+ String nation = "";
|
|
|
+ if (row.getCell(5).getStringCellValue().contains("民 族")) {
|
|
|
+ nation = row.getCell(6).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ nation = "测试nation";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("nation", nation);
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo
|
|
|
+ String birthplace = "";
|
|
|
+ if (row.getCell(7).getStringCellValue().contains("籍 贯")) {
|
|
|
+ birthplace = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ birthplace = "测试birthplace";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("birthplace", birthplace);
|
|
|
+ }
|
|
|
+ personnel.setName(name);
|
|
|
+ personnel.setSex(sex);
|
|
|
+ personnel.setNation(nation);
|
|
|
+ personnel.setBirthplace(birthplace);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 3) {
|
|
|
+ String birthday;
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ if (null != row.getCell(2).getStringCellValue()) {
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("出生年月")) {
|
|
|
+ birthday = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ birthday = "测试birthday";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("birthday", birthday);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ birthday = "";
|
|
|
+ }
|
|
|
+ row.getCell(4).setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ String workingTime;
|
|
|
+ if (null != row.getCell(4).getStringCellValue()) {
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("工作时间")) {
|
|
|
+ workingTime = row.getCell(4).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ workingTime = "测试workingTime";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("workingTime", workingTime);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ workingTime = "";
|
|
|
+ }
|
|
|
+ String joiningPartyTime;
|
|
|
+ row.getCell(6).setCellType(CellType.STRING);
|
|
|
+ if (null != row.getCell(6).getStringCellValue()) {
|
|
|
+ if (row.getCell(5).getStringCellValue().contains("入党时间")) {
|
|
|
+ joiningPartyTime = row.getCell(6).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ joiningPartyTime = "测试joiningPartyTime";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("joiningPartyTime", joiningPartyTime);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ joiningPartyTime = "";
|
|
|
+ }
|
|
|
+ String healthStatus = "";
|
|
|
+ if (row.getCell(7).getStringCellValue().contains("健康状况")) {
|
|
|
+ healthStatus = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ healthStatus = "测试healthStatus";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("healthStatus", healthStatus);
|
|
|
+ }
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(birthday), "-") && CleanDateUtil.cleanDate(birthday).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("birthday", CleanDateUtil.cleanDate(birthday));
|
|
|
+ }
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(workingTime), "-") && CleanDateUtil.cleanDate(workingTime).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("workingTime", CleanDateUtil.cleanDate(workingTime));
|
|
|
+ }
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(joiningPartyTime), "-") && CleanDateUtil.cleanDate(joiningPartyTime).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("joiningPartyTime", CleanDateUtil.cleanDate(joiningPartyTime));
|
|
|
+ }
|
|
|
+ personnel.setBirthday(CleanDateUtil.cleanDate(birthday));
|
|
|
+ personnel.setWorkingTime(CleanDateUtil.cleanDate(workingTime));
|
|
|
+ personnel.setJoiningPartyTime(CleanDateUtil.cleanDate(joiningPartyTime));
|
|
|
+ personnel.setHealthStatus(healthStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 4) {
|
|
|
+
|
|
|
+ String education = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("学 历")) {
|
|
|
+ education = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ education = "测试education";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("education", education);
|
|
|
+ }
|
|
|
+ // todo 毕业院校
|
|
|
+ String graTimeSchoolMajor = "";
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("何年何月毕业于何校何专业")) {
|
|
|
+ graTimeSchoolMajor = row.getCell(6).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ graTimeSchoolMajor = "测试graTimeSchoolMajor";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("graTimeSchoolMajor", graTimeSchoolMajor);
|
|
|
+ }
|
|
|
+ // System.err.println("graTimeSchoolMajor-->" + graTimeSchoolMajor);
|
|
|
+ personnel.setEducation(education);
|
|
|
+ personnel.setGraTimeSchoolMajor(graTimeSchoolMajor);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 5) {
|
|
|
+ // todo 后期时需求里无该 “政治面貌” 字段
|
|
|
+ String personnelNature = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("人员性质")) {
|
|
|
+ personnelNature = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ personnelNature = "测试personnelNature";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("personnelNature", personnelNature);
|
|
|
+ }
|
|
|
+ row.getCell(5).setCellType(CellType.STRING);
|
|
|
+ // todo 职称
|
|
|
+ String jobTitle = "";
|
|
|
+ if (row.getCell(3).getStringCellValue().contains("职 称")) {
|
|
|
+ jobTitle = row.getCell(5).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ jobTitle = "测试jobTitle";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("jobTitle", jobTitle);
|
|
|
+ }
|
|
|
+ // todo 是否出错,8
|
|
|
+ String titleAcqTime = "";
|
|
|
+ row.getCell(8).setCellType(CellType.STRING);
|
|
|
+ if (row.getCell(6).getStringCellValue().contains("职称取得时间")) {
|
|
|
+ titleAcqTime = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ titleAcqTime = "测试titleAcqTime";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("titleAcqTime", titleAcqTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.contains(CleanDateUtil.cleanDate(titleAcqTime), "-") && CleanDateUtil.cleanDate(titleAcqTime).length() > 4) {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("titleAcqTime", CleanDateUtil.cleanDate(titleAcqTime));
|
|
|
+ }
|
|
|
+ // personnel.setPoliticsStatus(politicsStatus);
|
|
|
+ personnel.setPerNature(personnelNature);
|
|
|
+ personnel.setJobTitle(jobTitle);
|
|
|
+ personnel.setTitleAcqTime(CleanDateUtil.cleanDate(titleAcqTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 6) {
|
|
|
+ // todo 重复 当前模板不再需要在此处获取
|
|
|
+ String currentJob = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("现任职务")) {
|
|
|
+ currentJob = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ currentJob = "测试currentJob";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("currentJob", currentJob);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ row.getCell(8).setCellType(CellType.STRING);
|
|
|
+ row.getCell(7).setCellType(CellType.STRING);
|
|
|
+ String contactPhone = "";
|
|
|
+ if (row.getCell(5).getStringCellValue().contains("联系电话")) {
|
|
|
+ contactPhone = row.getCell(7).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ contactPhone = "测试contactPhone";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("contactPhone", contactPhone);
|
|
|
+ }
|
|
|
+ personnel.setCurrentJob(currentJob);
|
|
|
+ personnel.setContactPhone(contactPhone);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 7) {
|
|
|
+ String address = "";
|
|
|
+ if (row.getCell(0).getStringCellValue().contains("家庭住址")) {
|
|
|
+ address = row.getCell(2).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ address = "测试address";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("address", address);
|
|
|
+ }
|
|
|
+ String idNumber = "";
|
|
|
+ if (row.getCell(7).getStringCellValue().contains("身份证号码")) {
|
|
|
+ idNumber = row.getCell(8).getStringCellValue();
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ idNumber = "测试idNumber";
|
|
|
+ exceptionFieldNum++;
|
|
|
+ jsonObject.put("idNumber", idNumber);
|
|
|
+ }
|
|
|
+ personnel.setAddress(address);
|
|
|
+ personnel.setIdNumber(idNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 8){
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("学习时间") && row.getCell(3).getStringCellValue().contains("学 校") && row.getCell(7).getStringCellValue().contains("专 业")){
|
|
|
+ // System.err.println("8 包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet教育关系 异常字段!!!!");
|
|
|
+ jsonObject.put("eduRecord","eduRecord");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 9 || rowNum == 10 || rowNum == 11 || rowNum == 12) {
|
|
|
+ PerEduRec eduRecord = getEduRecord(row);
|
|
|
+ if (null != eduRecord) {
|
|
|
+ eduRecords.add(eduRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 13){
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("任职时间") && row.getCell(3).getStringCellValue().contains("单 位") && row.getCell(7).getStringCellValue().contains("职 务")){
|
|
|
+ System.err.println("13任职时间包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ System.err.println("13任职时间 不 包含");
|
|
|
+ if (rowNum == 14){
|
|
|
+
|
|
|
+ SpecialParseExcel.toCheckForteenRowNum(file,sheetNum,workbook,rowNum);
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("任职时间") && row.getCell(3).getStringCellValue().contains("单 位") && row.getCell(7).getStringCellValue().contains("职 务")) {
|
|
|
+ System.err.println("14任职时间包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ System.err.println("14任职时间 不 包含");
|
|
|
+ if (rowNum == 15){
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("任职时间") && row.getCell(3).getStringCellValue().contains("单 位") && row.getCell(7).getStringCellValue().contains("职 务")) {
|
|
|
+ System.err.println("15任职时间包含");
|
|
|
+ correctFieldNum++;
|
|
|
+ }else {
|
|
|
+ System.err.println("15任职时间 不 包含");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ form.setEduRecords(eduRecords);
|
|
|
+ form.setWorkRecords(workRecords);
|
|
|
+ form.setFamRelations(familyRelations);
|
|
|
+ form.setSocRelations(socialRelations);
|
|
|
+ form.setRewRecords(rewards);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i == 1) {
|
|
|
+ log.info("-------sheet解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ for (Row row : sheet) {
|
|
|
+ // todo sheet 2
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+
|
|
|
+ if (rowNum == 0) {
|
|
|
+
|
|
|
+ if (row.getCell(2).getStringCellValue().contains("姓 名") && row.getCell(3).getStringCellValue().contains("出生年月") && row.getCell(4).getStringCellValue().contains("政治面貌") && row.getCell(5).getStringCellValue().contains("工 作 单 位 及 职 务")) {
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet家庭关系 异常字段!!!!");
|
|
|
+ jsonObject.put("famRel", "famRel");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 1 || rowNum == 3 || rowNum == 4 || rowNum == 5 || rowNum == 6 || rowNum == 7 || rowNum == 8) {
|
|
|
+ PerFamRel relation = getFamRel(rowNum, row);
|
|
|
+ if (null != relation) {
|
|
|
+ familyRelations.add(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (rowNum == 9) {
|
|
|
+
|
|
|
+ if (row.getCell(1).getStringCellValue().contains("关 系") && row.getCell(2).getStringCellValue().contains("姓 名") && row.getCell(3).getStringCellValue().contains("年 龄") && row.getCell(4).getStringCellValue().contains("政治面貌") && row.getCell(5).getStringCellValue().contains("工 作 单 位 及 职 务")) {
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet社会关系 异常字段!!!!");
|
|
|
+ jsonObject.put("socRel", "socRel");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 10 || rowNum == 11 || rowNum == 12 || rowNum == 13 || rowNum == 14) {
|
|
|
+ PerSocRel relation = getSocRel(row);
|
|
|
+ if (null != relation) {
|
|
|
+ socialRelations.add(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 15) {
|
|
|
+
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ if (row.getCell(2).getStringCellValue().contains("时 间") && row.getCell(4).getStringCellValue().contains("奖 惩 内 容")) {
|
|
|
+ correctFieldNum++;
|
|
|
+ } else {
|
|
|
+ exceptionFieldNum++;
|
|
|
+ log.info("sheet奖惩关系 异常字段!!!!");
|
|
|
+ jsonObject.put("rewRec", "rewRec");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rowNum == 16 || rowNum == 17 || rowNum == 18 || rowNum == 19 || rowNum == 20) {
|
|
|
+ PerRewRec reward = getReward(row);
|
|
|
+ if (null != reward) {
|
|
|
+ rewards.add(reward);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info(file.getName() + "< toSheet >" + JSON.toJSONString(form));
|
|
|
+
|
|
|
+ tempFileResult.setCorrectFieldNum(String.valueOf(correctFieldNum));
|
|
|
+ tempFileResult.setExceptionFieldNum(String.valueOf(exceptionFieldNum));
|
|
|
+ if (exceptionFieldNum == 0) {
|
|
|
+ tempFileResult.setStatus("ok");
|
|
|
+ } else {
|
|
|
+ tempFileResult.setStatus(String.valueOf(exceptionFieldNum));
|
|
|
+ }
|
|
|
+ tempFileResult.setCheckField(jsonObject.toString());
|
|
|
+ tempFileResultMapper.insert(tempFileResult);
|
|
|
+ tempFileResults.add(tempFileResult);
|
|
|
+ personnel.setFileId(tempFileResult.getId());
|
|
|
+ form.setPer(personnel);
|
|
|
+ form.setTempFileResults(tempFileResults);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+ public PerForm toHSSFSheet(File file,int sheetNum,HSSFWorkbook wb) throws Exception {
|
|
|
+ PerForm form = new PerForm();
|
|
|
+ Per personnel = new Per();
|
|
|
+ List<PerEduRec> eduRecords = new ArrayList<>();
|
|
|
+ List<PerWorkRec> workRecords = new ArrayList<>();
|
|
|
+ List<PerFamRel> familyRelations = new ArrayList<>();
|
|
|
+ List<PerSocRel> socialRelations = new ArrayList<>();
|
|
|
+ List<PerRewRec> rewards = new ArrayList<>();
|
|
|
+ String avatar = getAvatar(wb.getSheetAt(0), wb);
|
|
|
+ log.info("获取avatar-->" + avatar);
|
|
|
+ personnel.setAvatar(avatar);
|
|
|
+ int nameNum = 0;
|
|
|
+ for (int i = 0; i < sheetNum; i++) {
|
|
|
+
|
|
|
+ HSSFSheet sheet = wb.getSheetAt(i);
|
|
|
+ System.err.println("sheet name-->"+sheet.getSheetName());
|
|
|
+ // System.err.println("toHSSFSheet-->"+sheet);
|
|
|
+ // todo 遍历取sheet
|
|
|
+ if (i == 0) {
|
|
|
+ log.info("-------解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ // 处理照片
|
|
|
+
|
|
|
+ for (Row row : sheet) {
|
|
|
+ // String avatar = getAvatar(sheet, workbook);
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+ if (rowNum == 1){
|
|
|
+ String tempWorkUnit = row.getCell(0).getStringCellValue();
|
|
|
+ String workUnit = StringUtils.substringAfter(tempWorkUnit,":");
|
|
|
+ personnel.setWorkUnit(StringUtils.trim(workUnit));
|
|
|
+ }
|
|
|
+ if (rowNum == 2) {
|
|
|
+ String name ="";
|
|
|
+ if (!row.getCell(1).getStringCellValue().equals("姓名")){
|
|
|
+ name = row.getCell(2).getStringCellValue();
|
|
|
+ }else {
|
|
|
+ nameNum++;
|
|
|
+ }
|
|
|
+
|
|
|
+ String sex = row.getCell(4).getStringCellValue();
|
|
|
+ String nation = row.getCell(6).getStringCellValue();
|
|
|
+ // todo
|
|
|
+ String birthplace = row.getCell(8).getStringCellValue();
|
|
|
+ personnel.setName(name);
|
|
|
+ personnel.setSex(sex);
|
|
|
+ personnel.setNation(nation);
|
|
|
+ personnel.setBirthplace(birthplace);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 3) {
|
|
|
+ String birthday;
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ if (null != row.getCell(2).getStringCellValue()) {
|
|
|
+ // birthday = sdf.format(row.getCell(2).getDateCellValue());
|
|
|
+ birthday = row.getCell(2).getStringCellValue();
|
|
|
+ } else {
|
|
|
+ birthday = "";
|
|
|
+ }
|
|
|
+ row.getCell(4).setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ String workingTime;
|
|
|
+ if (null != row.getCell(4).getStringCellValue()) {
|
|
|
+ // workingTime = sdf.format(row.getCell(4).getDateCellValue());
|
|
|
+ workingTime = row.getCell(4).getStringCellValue();
|
|
|
+ } else {
|
|
|
+ workingTime = "";
|
|
|
+ }
|
|
|
+ String joiningPartyTime;
|
|
|
+ row.getCell(6).setCellType(CellType.STRING);
|
|
|
+ if (null != row.getCell(6).getStringCellValue()) {
|
|
|
+ // joiningPartyTime = sdf.format(row.getCell(6).getDateCellValue());
|
|
|
+ joiningPartyTime = row.getCell(6).getStringCellValue();
|
|
|
+ } else {
|
|
|
+ joiningPartyTime = "";
|
|
|
+ }
|
|
|
+ String healthStatus = row.getCell(8).getStringCellValue();
|
|
|
+ personnel.setBirthday(CleanDateUtil.cleanDate(birthday));
|
|
|
+ personnel.setWorkingTime(CleanDateUtil.cleanDate(workingTime));
|
|
|
+ personnel.setJoiningPartyTime(CleanDateUtil.cleanDate(joiningPartyTime));
|
|
|
+ personnel.setHealthStatus(healthStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 4) {
|
|
|
+
|
|
|
+ String education = row.getCell(2).getStringCellValue();
|
|
|
+ // todo 毕业院校
|
|
|
+ String graTimeSchoolMajor = row.getCell(6).getStringCellValue();
|
|
|
+ personnel.setEducation(education);
|
|
|
+ personnel.setGraTimeSchoolMajor(graTimeSchoolMajor);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 5) {
|
|
|
+ // todo 无该政治面貌字段
|
|
|
+ // String politicsStatus = row.getCell(2).getStringCellValue();
|
|
|
+ String personnelNature = row.getCell(2).getStringCellValue();
|
|
|
+ row.getCell(5).setCellType(CellType.STRING);
|
|
|
+ row.getCell(8).setCellType(CellType.STRING);
|
|
|
+ // todo 职称
|
|
|
+ String jobTitle = row.getCell(5).getStringCellValue();
|
|
|
+ String titleAcqTime = row.getCell(8).getStringCellValue();
|
|
|
+ // personnel.setPoliticsStatus(politicsStatus);
|
|
|
+ personnel.setPerNature(personnelNature);
|
|
|
+ personnel.setJobTitle(jobTitle);
|
|
|
+ personnel.setTitleAcqTime(CleanDateUtil.cleanDate(titleAcqTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 6) {
|
|
|
+ // todo 重复 当前模板不再需要在此处获取
|
|
|
+ // String jobTitle = row.getCell(2).getStringCellValue();
|
|
|
+ String currentJob = row.getCell(2).getStringCellValue();
|
|
|
+
|
|
|
+ row.getCell(8).setCellType(CellType.STRING);
|
|
|
+ row.getCell(7).setCellType(CellType.STRING);
|
|
|
+ String contactPhone = row.getCell(7).getStringCellValue();
|
|
|
+ // personnel.setJobTitle(jobTitle);
|
|
|
+ personnel.setCurrentJob(currentJob);
|
|
|
+ // personnel.setTitleAcqTime(titleAcqTime);
|
|
|
+ personnel.setContactPhone(contactPhone);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 7) {
|
|
|
+ String address = row.getCell(2).getStringCellValue();
|
|
|
+ String idNumber = row.getCell(8).getStringCellValue();
|
|
|
+ personnel.setAddress(address);
|
|
|
+ personnel.setIdNumber(idNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 9 || rowNum == 10 || rowNum == 11 || rowNum == 12) {
|
|
|
+ PerEduRec eduRecord = getEduRecord(row);
|
|
|
+ if (null != eduRecord) {
|
|
|
+ eduRecords.add(eduRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 14 || rowNum == 15 || rowNum == 16 || rowNum == 17 || rowNum == 18 || rowNum == 19 || rowNum == 20 || rowNum == 21 || rowNum == 22) {
|
|
|
+ PerWorkRec workRecord = getWorkRecord(row);
|
|
|
+ if (null != workRecord) {
|
|
|
+ workRecords.add(workRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ form.setPer(personnel);
|
|
|
+ form.setEduRecords(eduRecords);
|
|
|
+ form.setWorkRecords(workRecords);
|
|
|
+ form.setFamRelations(familyRelations);
|
|
|
+ form.setSocRelations(socialRelations);
|
|
|
+ form.setRewRecords(rewards);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (i == 1) {
|
|
|
+ log.info("-------解析-[" + file.getName() + "]-的第>" + i + "个sheet!-------");
|
|
|
+ for (Row row : sheet) {
|
|
|
+ // todo sheet 2
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
+ if (rowNum == 1 || rowNum == 3 || rowNum == 4 || rowNum == 5 || rowNum == 6 || rowNum == 7 || rowNum == 8) {
|
|
|
+ PerFamRel relation = getFamRel(rowNum, row);
|
|
|
+ System.err.println("关系---》"+relation);
|
|
|
+ if (null != relation) {
|
|
|
+ familyRelations.add(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 10 || rowNum == 11 || rowNum == 12 || rowNum == 13 || rowNum == 14) {
|
|
|
+ PerSocRel relation = getSocRel(row);
|
|
|
+ if (null != relation) {
|
|
|
+ socialRelations.add(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowNum == 16 || rowNum == 17 || rowNum == 18 || rowNum == 19 || rowNum == 20) {
|
|
|
+ PerRewRec reward = getReward(row);
|
|
|
+ if (null != reward) {
|
|
|
+ rewards.add(reward);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.err.println("**********************"+nameNum);
|
|
|
+ System.err.println(file.getName() + "< toHSSFSheet >" + JSON.toJSONString(form));
|
|
|
+ return form;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取头像
|
|
|
+ *
|
|
|
+ * @param sheet
|
|
|
+ * @param workbook
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private String getAvatar(Sheet sheet, Workbook workbook) throws Exception {
|
|
|
+ List<PictureData> picList = new ArrayList<>();
|
|
|
+ // System.err.println("sheet-->"+sheet);
|
|
|
+ if (sheet instanceof HSSFSheet) {
|
|
|
+ // System.err.println("sheet instanceof HSSFSheet");
|
|
|
+ List<HSSFPictureData> pictures = ((HSSFWorkbook) workbook).getAllPictures();
|
|
|
+ if (pictures.size() != 0) {
|
|
|
+ for (HSSFShape shape : ((HSSFSheet) sheet).getDrawingPatriarch().getChildren()) {
|
|
|
+ if (shape instanceof HSSFPicture) {
|
|
|
+ HSSFPicture pic = (HSSFPicture) shape;
|
|
|
+ int pictureIndex = pic.getPictureIndex() - 1;
|
|
|
+ HSSFPictureData picData = pictures.get(pictureIndex);
|
|
|
+ picList.add(picData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sheet instanceof XSSFSheet) {
|
|
|
+ // System.err.println("sheet instanceof XSSFSheet");
|
|
|
+ for (POIXMLDocumentPart dr : ((XSSFSheet) sheet).getRelations()) {
|
|
|
+ if (dr instanceof XSSFDrawing) {
|
|
|
+ XSSFDrawing drawing = (XSSFDrawing) dr;
|
|
|
+ List<XSSFShape> shapes = drawing.getShapes();
|
|
|
+ for (XSSFShape shape : shapes) {
|
|
|
+ XSSFPicture pic = (XSSFPicture) shape;
|
|
|
+ picList.add(pic.getPictureData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (picList.size() == 1) {
|
|
|
+ PictureData pic = picList.get(0);
|
|
|
+ // 随机图片名称
|
|
|
+ String picName = UUID.randomUUID().toString() + "." + pic.suggestFileExtension();
|
|
|
+ // System.err.println("picName-->"+picName);
|
|
|
+ // 获取图片二进制流
|
|
|
+ byte[] data = pic.getData();
|
|
|
+ // System.err.println("头像-->"+properties.getCommon().getFileDir());
|
|
|
+ FileOutputStream out = new FileOutputStream(properties.getCommon().getFileDir() + picName);
|
|
|
+ // System.err.println("头像-->"+properties.getCommon().getFileDir() + picName);
|
|
|
+ out.write(data);
|
|
|
+ out.close();
|
|
|
+ log.info("img-->" + properties.getCommon().getBaseUrl() + picName);
|
|
|
+ return properties.getCommon().getBaseUrl() + picName;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ private PerEduRec getEduRecord(Row row) {
|
|
|
+ row.getCell(1).setCellType(CellType.STRING);
|
|
|
+ row.getCell(3).setCellType(CellType.STRING);
|
|
|
+ row.getCell(7).setCellType(CellType.STRING);
|
|
|
+ PerEduRec record = new PerEduRec();
|
|
|
+ String eduRecTime = row.getCell(1).getStringCellValue();
|
|
|
+ String eduRecSchool = row.getCell(3).getStringCellValue();
|
|
|
+ String eduRecMajor = row.getCell(7).getStringCellValue();
|
|
|
+ record.setTime(CleanDateUtil.cleanDate(eduRecTime));
|
|
|
+ record.setSchool(eduRecSchool);
|
|
|
+ record.setMajor(eduRecMajor);
|
|
|
+ if (!record.isEmpty()) {
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PerWorkRec getWorkRecord(Row row) {
|
|
|
+ row.getCell(1).setCellType(CellType.STRING);
|
|
|
+ row.getCell(3).setCellType(CellType.STRING);
|
|
|
+ row.getCell(7).setCellType(CellType.STRING);
|
|
|
+ PerWorkRec record = new PerWorkRec();
|
|
|
+ String workRecTime = row.getCell(1).getStringCellValue();
|
|
|
+ String workRecDept = row.getCell(3).getStringCellValue();
|
|
|
+ String workRecJob = row.getCell(7).getStringCellValue();
|
|
|
+ record.setTime(CleanDateUtil.cleanDate(workRecTime));
|
|
|
+ record.setDepartment(workRecDept);
|
|
|
+ record.setJob(workRecJob);
|
|
|
+ if (!record.isEmpty()) {
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PerFamRel getFamRel(int rowNum, Row row) {
|
|
|
+ row.getCell(1).setCellType(CellType.STRING);
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ row.getCell(3).setCellType(CellType.STRING);
|
|
|
+ row.getCell(4).setCellType(CellType.STRING);
|
|
|
+ row.getCell(5).setCellType(CellType.STRING);
|
|
|
+ PerFamRel relation = new PerFamRel();
|
|
|
+ String famRelRelation;
|
|
|
+ if (rowNum == 27) {
|
|
|
+ famRelRelation = "配偶";
|
|
|
+ } else {
|
|
|
+ famRelRelation = row.getCell(1).getStringCellValue();
|
|
|
+ }
|
|
|
+ String famRelName = row.getCell(2).getStringCellValue();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String tempFamRelBirthday = row.getCell(3).getStringCellValue();
|
|
|
+ System.err.println(famRelName+",tempFamRelBirthday-->"+tempFamRelBirthday);
|
|
|
+ String famRelBirthday = "";
|
|
|
+ String finalFamRelBirthday = "";
|
|
|
+ if (tempFamRelBirthday.length() != 4 && !StringUtils.contains(tempFamRelBirthday,".")){
|
|
|
+ // todo 做时间转换
|
|
|
+ // System.err.println("row3Type-->"+row.getCell(3).getCellType());
|
|
|
+ if (null != tempFamRelBirthday){
|
|
|
+ famRelBirthday = StringUtils.isBlank(tempFamRelBirthday.toString()) ? "" : tempFamRelBirthday.toString().trim();
|
|
|
+ Calendar calendar = new GregorianCalendar(1900,0,-1);
|
|
|
+ Date d = calendar.getTime();
|
|
|
+ if (null == famRelBirthday && "".equals(famRelBirthday)){
|
|
|
+ Date dd = DateUtils.addDays(d,Integer.valueOf(famRelBirthday));
|
|
|
+
|
|
|
+ finalFamRelBirthday = sdf.format(dd);
|
|
|
+ relation.setBirthday(StringUtils.substringBefore(finalFamRelBirthday,"-01"));
|
|
|
+ }else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ relation.setBirthday(CleanDateUtil.cleanDate(tempFamRelBirthday));
|
|
|
+ }
|
|
|
+ String famRelPolSta = row.getCell(4).getStringCellValue();
|
|
|
+ String famRelDeptJob = row.getCell(5).getStringCellValue();
|
|
|
+ relation.setRelation(famRelRelation);
|
|
|
+ relation.setName(famRelName);
|
|
|
+
|
|
|
+ // relation.setBirthday(StringUtils.substringBefore(finalFamRelBirthday,"-01"));
|
|
|
+ relation.setPoliticalStatus(famRelPolSta);
|
|
|
+ relation.setDeptJob(famRelDeptJob);
|
|
|
+ if (!relation.isEmpty()) {
|
|
|
+ return relation;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PerSocRel getSocRel(Row row) {
|
|
|
+ row.getCell(1).setCellType(CellType.STRING);
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ row.getCell(3).setCellType(CellType.STRING);
|
|
|
+ row.getCell(4).setCellType(CellType.STRING);
|
|
|
+ row.getCell(5).setCellType(CellType.STRING);
|
|
|
+ PerSocRel relation = new PerSocRel();
|
|
|
+ String socRelRelation = row.getCell(1).getStringCellValue();
|
|
|
+ String socRelName = row.getCell(2).getStringCellValue();
|
|
|
+ String socRelAge = row.getCell(3).getStringCellValue();
|
|
|
+ String socRelPolSta = row.getCell(4).getStringCellValue();
|
|
|
+ String socRelDeptJob = row.getCell(5).getStringCellValue();
|
|
|
+ relation.setRelation(socRelRelation);
|
|
|
+ relation.setName(socRelName);
|
|
|
+ relation.setAge(socRelAge);
|
|
|
+ relation.setPoliticalStatus(socRelPolSta);
|
|
|
+ relation.setDeptJob(socRelDeptJob);
|
|
|
+ if (!relation.isEmpty()) {
|
|
|
+ return relation;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PerRewRec getReward(Row row) {
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ row.getCell(4).setCellType(CellType.STRING);
|
|
|
+ PerRewRec reward = new PerRewRec();
|
|
|
+ String rewTime = row.getCell(2).getStringCellValue();
|
|
|
+ String rewContent = row.getCell(4).getStringCellValue();
|
|
|
+ reward.setTime(CleanDateUtil.cleanDate(rewTime));
|
|
|
+ reward.setContent(rewContent);
|
|
|
+ if (!reward.isEmpty()) {
|
|
|
+ return reward;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|