|
@@ -8,9 +8,13 @@ import com.jpsoft.picc.modules.base.entity.Jobs;
|
|
|
import com.jpsoft.picc.modules.base.service.CompanyMemberService;
|
|
|
import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
import com.jpsoft.picc.modules.base.service.JobsService;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsurancePolicy;
|
|
|
+import com.jpsoft.picc.modules.business.service.InsurancePolicyService;
|
|
|
+import com.jpsoft.picc.modules.common.config.OSSConfig;
|
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.picc.modules.common.dto.Sort;
|
|
|
import com.jpsoft.picc.modules.common.utils.CheckIdCard;
|
|
|
+import com.jpsoft.picc.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.picc.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.picc.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.picc.modules.sys.entity.DataDictionary;
|
|
@@ -20,6 +24,7 @@ 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.*;
|
|
|
import org.jasig.cas.client.authentication.AttributePrincipal;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -28,6 +33,8 @@ 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.io.File;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -48,9 +55,15 @@ public class CompanyMemberController {
|
|
|
@Autowired
|
|
|
private JobsService jobsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InsurancePolicyService insurancePolicyService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DataDictionaryService dataDictionaryService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
@ApiOperation(value="读取企业人员列表")
|
|
|
@RequestMapping(value = "list",method = RequestMethod.POST)
|
|
|
public MessageResult<List<CompanyMember>> list(
|
|
@@ -92,7 +105,7 @@ public class CompanyMemberController {
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name = "memberName",value = "人员姓名", required = false, paramType = "form",dataType = "String"),
|
|
|
@ApiImplicitParam(name = "jobsId",value = "岗位编号", required = false, paramType = "form",dataType = "String"),
|
|
|
- @ApiImplicitParam(name = "excludePolicyId",value = "排除投保单中人员", required = false, paramType = "form",dataType = "String"),
|
|
|
+ @ApiImplicitParam(name = "excludePolicyId",value = "要排除投保单", required = false, paramType = "form",dataType = "String"),
|
|
|
})
|
|
|
public MessageResult<Map> pageList(
|
|
|
@RequestParam(value="memberName",defaultValue="") String memberName,
|
|
@@ -124,7 +137,9 @@ public class CompanyMemberController {
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotEmpty(excludePolicyId)) {
|
|
|
- searchParams.put("excludePolicyId", excludePolicyId);
|
|
|
+ //todo 新增和被替换的投保单编号一致
|
|
|
+ InsurancePolicy insurancePolicy = insurancePolicyService.get(excludePolicyId);
|
|
|
+ searchParams.put("excludePolicyNo", insurancePolicy.getPolicyNo());
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotEmpty(memberName)){
|
|
@@ -369,27 +384,27 @@ public class CompanyMemberController {
|
|
|
|
|
|
try {
|
|
|
POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
- List<Object[]> list = poiUtils.getAllData(0);
|
|
|
- list.remove(0);
|
|
|
+ int sheetIndex = 0;
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
|
|
|
int affectCount = 0;
|
|
|
- int existCount = 0;
|
|
|
- List<String> existName = new ArrayList<>();
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 7;
|
|
|
|
|
|
List<DataDictionary> ddList = dataDictionaryService.findByCatalogName("证件类型");
|
|
|
|
|
|
- for(Object[] array : list){
|
|
|
+ for(int rowIndex=1 ; rowIndex<sheet1.getLastRowNum(); rowIndex++){
|
|
|
try {
|
|
|
- String name = array[1].toString();
|
|
|
- String cardType = array[2].toString();
|
|
|
- String cardNo = array[3].toString();
|
|
|
- String sex = array[4].toString();
|
|
|
+ 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 = array[5].toString();
|
|
|
- String healthStatus = array[6].toString();
|
|
|
+ String jobName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,5);
|
|
|
+ String healthStatus = (String)poiUtils.getCellValue(sheetIndex,rowIndex,6);
|
|
|
|
|
|
if(StringUtils.isEmpty(name)){
|
|
|
- continue;
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
Map<String, Object> searchParams = new HashMap<>();
|
|
@@ -401,8 +416,9 @@ public class CompanyMemberController {
|
|
|
Page<CompanyMember> page = companyMemberService.pageSearch(searchParams, 1, 100, sortList);
|
|
|
|
|
|
if (page.size() > 0) {
|
|
|
- existCount++;
|
|
|
- existName.add(page.get(0).getName());
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证已导入!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
} else {
|
|
|
companyMember.setId(UUID.randomUUID().toString());
|
|
|
if (StringUtils.isNotEmpty(company.getId())) companyMember.setCompanyId(company.getId());
|
|
@@ -410,8 +426,13 @@ public class CompanyMemberController {
|
|
|
|
|
|
CheckIdCard cic = null;
|
|
|
|
|
|
- if (cardType.contains("身份证")) {
|
|
|
- cic = new CheckIdCard(cardNo);
|
|
|
+ if(StringUtils.isEmpty(cardNo)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("身份证不能为空!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cardNo = cardNo.trim().toUpperCase();
|
|
|
}
|
|
|
|
|
|
for(DataDictionary dd : ddList){
|
|
@@ -421,6 +442,23 @@ public class CompanyMemberController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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);
|
|
|
|
|
|
if (StringUtils.isNotEmpty(sex)) {
|
|
@@ -433,9 +471,6 @@ public class CompanyMemberController {
|
|
|
companyMember.setSex(cic.isFemal());
|
|
|
}
|
|
|
|
|
|
-// if (StringUtils.isNotEmpty(age)) {
|
|
|
-// companyMember.setAge(Integer.valueOf(age));
|
|
|
-// }
|
|
|
if (cic != null && cic.validate()) {
|
|
|
companyMember.setAge(cic.getAge());
|
|
|
}
|
|
@@ -449,6 +484,12 @@ public class CompanyMemberController {
|
|
|
jobsName = "三类职业";
|
|
|
}
|
|
|
|
|
|
+ if (StringUtils.isEmpty(jobsName)){
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("岗位/工种未选择!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
List<Jobs> jobsList = jobsService.findByName(jobsName);
|
|
|
|
|
|
if (jobsList.size() > 0) {
|
|
@@ -472,23 +513,41 @@ public class CompanyMemberController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (affectCount > 0) {
|
|
|
- msgResult.setResult(true);
|
|
|
- if(existCount > 0) {
|
|
|
- msgResult.setMessage("数据成功导入" + affectCount + "条,有<" + existCount + ">条数据未导入成功,错误数据姓名为<" + String.join(",", existName) + ">,失败原因为<数据重复>。");
|
|
|
- }else{
|
|
|
- msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
- }
|
|
|
- } else {
|
|
|
+ if (failCount>0){
|
|
|
+ //有导入失败的记录
|
|
|
msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
|
|
|
- if(existCount > 0) {
|
|
|
- msgResult.setMessage("您有<" + existCount + ">条数据未导入成功,错误数据姓名为<" + String.join(",", existName) + ">,失败原因为<数据重复>。");
|
|
|
- }
|
|
|
- else {
|
|
|
- msgResult.setMessage("数据导入失败。");
|
|
|
+ //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));
|
|
|
+ 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){
|