|
@@ -1,6 +1,10 @@
|
|
|
package com.jpsoft.smart.modules.base.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.smart.config.OSSConfig;
|
|
|
+import com.jpsoft.smart.modules.common.utils.CheckIdCard;
|
|
|
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.smart.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
@@ -13,6 +17,8 @@ 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.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -31,6 +37,8 @@ import java.util.*;
|
|
|
public class PersonInfoController {
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
@Autowired
|
|
|
private PersonInfoService personInfoService;
|
|
|
@Autowired
|
|
@@ -382,167 +390,154 @@ public class PersonInfoController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
-// @ApiOperation(value="导入企业人员")
|
|
|
-// @PostMapping("importXls")
|
|
|
-// @ApiImplicitParams({
|
|
|
-// @ApiImplicitParam(name = "companyId",value = "企业ID", required = true, paramType = "form",dataType = "String"),
|
|
|
-// @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
-// })
|
|
|
-// public MessageResult<String> importXls(@RequestParam(value="companyId",defaultValue="") String companyId,
|
|
|
-// MultipartFile uploadFile,
|
|
|
-// @RequestAttribute String subject){
|
|
|
-// User user = userService.get(subject);
|
|
|
-//
|
|
|
-// MessageResult<String> msgResult = new MessageResult<>();
|
|
|
-// PersonInfo personInfo = new PersonInfo();
|
|
|
-//
|
|
|
-// try {
|
|
|
-// POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
-// int sheetIndex = 0;
|
|
|
-// Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
-//
|
|
|
-// int affectCount = 0;
|
|
|
-// int failCount = 0;
|
|
|
-// int validateColIndex = 7;
|
|
|
-//
|
|
|
-// for(int rowIndex=1 ; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
-// try {
|
|
|
-// String name = (String)poiUtils.getCellValue(sheetIndex,rowIndex,1);
|
|
|
-// String cardType = (String)poiUtils.getCellValue(sheetIndex,rowIndex,2);
|
|
|
-// String cardNo = (String)poiUtils.getCellValue(sheetIndex,rowIndex,3);
|
|
|
-// String sex = (String)poiUtils.getCellValue(sheetIndex,rowIndex,4);
|
|
|
-//// String age = array[5].toString();
|
|
|
-// String jobName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,5);
|
|
|
-// String healthStatus = (String)poiUtils.getCellValue(sheetIndex,rowIndex,6);
|
|
|
-//
|
|
|
-// if(StringUtils.isEmpty(name)){
|
|
|
-// break;
|
|
|
-// }
|
|
|
-//
|
|
|
-// Map<String, Object> searchParams = new HashMap<>();
|
|
|
-// searchParams.put("companyId", company.getId());
|
|
|
-// searchParams.put("cardNo", cardNo);
|
|
|
-// searchParams.put("delFlag", false);
|
|
|
-//
|
|
|
-// List<Sort> sortList = new ArrayList<>();
|
|
|
-// Page<CompanyMember> page = companyMemberService.pageSearch(searchParams, 1, 100, sortList);
|
|
|
-//
|
|
|
-// if (page.size() > 0) {
|
|
|
-// sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证已导入!");
|
|
|
-// failCount++;
|
|
|
-// continue;
|
|
|
-// } else {
|
|
|
-// companyMember.setId(UUID.randomUUID().toString());
|
|
|
-// if (StringUtils.isNotEmpty(company.getId())) companyMember.setCompanyId(company.getId());
|
|
|
-// if (StringUtils.isNotEmpty(name)) companyMember.setName(name);
|
|
|
-//
|
|
|
-// CheckIdCard cic = null;
|
|
|
-//
|
|
|
-// if(StringUtils.isEmpty(cardNo)){
|
|
|
-// sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证不能为空!");
|
|
|
-// failCount++;
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// cardNo = cardNo.trim().toUpperCase();
|
|
|
-// }
|
|
|
-//
|
|
|
-// for(DataDictionary dd : ddList){
|
|
|
-// if(dd.getName().equals(cardType)) {
|
|
|
-// companyMember.setCardType(dd.getValue());
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (StringUtils.isEmpty(companyMember.getCardType())){
|
|
|
-// sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("证件类型未选择!");
|
|
|
-// failCount++;
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (cardType.contains("身份证")) {
|
|
|
-// cic = new CheckIdCard(cardNo);
|
|
|
-//
|
|
|
-// if (!cic.validate()){
|
|
|
-// sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证验证失败!");
|
|
|
-// failCount++;
|
|
|
-//
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// companyMember.setCardNo(cardNo);
|
|
|
-//
|
|
|
-// List<Jobs> jobsList = jobsService.findByName(jobsName);
|
|
|
-//
|
|
|
-// if (jobsList.size() > 0) {
|
|
|
-// companyMember.setJobsId(jobsList.get(0).getId());
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (StringUtils.isNotEmpty(healthStatus)) companyMember.setHealthStatus(healthStatus);
|
|
|
-//
|
|
|
-// companyMember.setStatus("0");
|
|
|
-// companyMember.setDelFlag(false);
|
|
|
-// companyMember.setCreateBy(principal.getName());
|
|
|
-// companyMember.setCreateTime(new Date());
|
|
|
-//
|
|
|
-// if (companyMemberService.insert(companyMember) > 0) {
|
|
|
-// affectCount++;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// catch(Exception innerEx){
|
|
|
-// logger.error(innerEx.getMessage(),innerEx);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (failCount>0){
|
|
|
-// //有导入失败的记录
|
|
|
-// msgResult.setResult(false);
|
|
|
-// msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
-//
|
|
|
-// //todo 只保留错误数据的sheet
|
|
|
-// int rowIndex = 1;
|
|
|
-//
|
|
|
-// while(rowIndex<= sheet1.getLastRowNum()){
|
|
|
-// Cell cell = sheet1.getRow(rowIndex).getCell(validateColIndex);
|
|
|
-//
|
|
|
-// if (cell==null || StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
-// sheet1.removeRow(sheet1.getRow(rowIndex));
|
|
|
-//
|
|
|
-// if (rowIndex<sheet1.getLastRowNum()) {
|
|
|
-// sheet1.shiftRows(rowIndex + 1, sheet1.getLastRowNum(), -1); //删除后下面行上移,则不需要移动rowIndex
|
|
|
-// }
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// rowIndex++;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// //todo 将wb保存到oss
|
|
|
-// ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
-// poiUtils.getWorkbook().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;
|
|
|
-// }
|
|
|
+ @ApiOperation(value="导入人员(非企业账户需要输入企业ID)")
|
|
|
+ @PostMapping("importXls")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "companyId",value = "企业ID", required = false, paramType = "form",dataType = "String"),
|
|
|
+ @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
+ })
|
|
|
+ public MessageResult<String> importXls(@RequestParam(value="companyId",defaultValue="") String companyId,
|
|
|
+ MultipartFile uploadFile,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ User user = userService.get(subject);
|
|
|
+ if(StringUtils.isEmpty(companyId)){
|
|
|
+ companyId = user.getCompanyId();
|
|
|
+ }
|
|
|
+
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+ PersonInfo personInfo = new PersonInfo();
|
|
|
+
|
|
|
+ try {
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ int sheetIndex = 0;
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 7;
|
|
|
+
|
|
|
+ for(int rowIndex=1 ; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
+ try {
|
|
|
+ String name = (String)poiUtils.getCellValue(sheetIndex,rowIndex,1);
|
|
|
+ String idCard = (String)poiUtils.getCellValue(sheetIndex,rowIndex,2);
|
|
|
+ String phone = (String)poiUtils.getCellValue(sheetIndex,rowIndex,3);
|
|
|
+ String position1 = (String)poiUtils.getCellValue(sheetIndex,rowIndex,4);
|
|
|
+ String position2 = (String)poiUtils.getCellValue(sheetIndex,rowIndex,5);
|
|
|
+ String position3 = (String)poiUtils.getCellValue(sheetIndex,rowIndex,6);
|
|
|
+ String position4 = (String)poiUtils.getCellValue(sheetIndex,rowIndex,7);
|
|
|
+ String position5 = (String)poiUtils.getCellValue(sheetIndex,rowIndex,8);
|
|
|
+ String enabledFace = (String)poiUtils.getCellValue(sheetIndex,rowIndex,9);
|
|
|
+ String enabledCard = (String)poiUtils.getCellValue(sheetIndex,rowIndex,10);
|
|
|
+ String enabledApp = (String)poiUtils.getCellValue(sheetIndex,rowIndex,11);
|
|
|
+ String enabledGuest = (String)poiUtils.getCellValue(sheetIndex,rowIndex,12);
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(name)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
+ searchParams.put("companyId", companyId);
|
|
|
+ searchParams.put("idCard", idCard);
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ Page<PersonInfo> page = personInfoService.pageSearch(searchParams, 1, 1,false, sortList);
|
|
|
+
|
|
|
+ if (page.size() > 0) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证已导入!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ personInfo.setCompanyId(companyId);
|
|
|
+ personInfo.setName(name);
|
|
|
+
|
|
|
+ CheckIdCard cic = null;
|
|
|
+ if(StringUtils.isEmpty(idCard)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证不能为空!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ idCard = idCard.trim().toUpperCase();
|
|
|
+ }
|
|
|
+
|
|
|
+ cic = new CheckIdCard(idCard);
|
|
|
+ if (!cic.validate()){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证验证失败!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ personInfo.setIdCard(idCard);
|
|
|
+ personInfo.setPhone(phone);
|
|
|
+ personInfo.setPosition1(position1);
|
|
|
+ personInfo.setPosition2(position2);
|
|
|
+ personInfo.setPosition3(position3);
|
|
|
+ personInfo.setPosition4(position4);
|
|
|
+ personInfo.setPosition5(position5);
|
|
|
+ personInfo.setFaceEnabled(Boolean.valueOf(enabledFace));
|
|
|
+ personInfo.setCardEnabled(Boolean.valueOf(enabledCard));
|
|
|
+ personInfo.setAppEnabled(Boolean.valueOf(enabledApp));
|
|
|
+ personInfo.setGuestEnabled(Boolean.valueOf(enabledGuest));
|
|
|
+ personInfo.setDelFlag(false);
|
|
|
+ personInfo.setCreateBy(subject);
|
|
|
+ personInfo.setCreateTime(new Date());
|
|
|
+
|
|
|
+ if (personInfoService.insert(personInfo) > 0) {
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception innerEx){
|
|
|
+ logger.error(innerEx.getMessage(),innerEx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (failCount>0){
|
|
|
+ //有导入失败的记录
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
+
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
+ int rowIndex = 1;
|
|
|
+
|
|
|
+ while(rowIndex<= sheet1.getLastRowNum()){
|
|
|
+ Cell cell = sheet1.getRow(rowIndex).getCell(validateColIndex);
|
|
|
+
|
|
|
+ if (cell==null || StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ sheet1.removeRow(sheet1.getRow(rowIndex));
|
|
|
+
|
|
|
+ if (rowIndex<sheet1.getLastRowNum()) {
|
|
|
+ sheet1.shiftRows(rowIndex + 1, sheet1.getLastRowNum(), -1); //删除后下面行上移,则不需要移动rowIndex
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ rowIndex++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ poiUtils.getWorkbook().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;
|
|
|
+ }
|
|
|
}
|