Commit 35cbe3c8 by 翁国栋

8小时后台--

导入替换人员异常
parent db3ad21f
...@@ -370,7 +370,7 @@ public class InsureContorll { ...@@ -370,7 +370,7 @@ public class InsureContorll {
insureUser.setApplicantEmployeeList(url); insureUser.setApplicantEmployeeList(url);
insureUser.setTricycleFrameNumber(p.getTricycleFrameNumber()); insureUser.setTricycleFrameNumber(p.getTricycleFrameNumber());
insureUser.setPolicyDateStart(dtf3.parse(insureDto.getPolicyDateStart())); insureUser.setPolicyDateStart(dtf3.parse(insureDto.getPolicyDateStart()));
insureUser.setPolicyDateEnd(dtf3.parse(insureDto.getPolicyDateEnd())); insureUser.setPolicyDateEnd(dtf3.parse(DateUtil.getStringFormat(DateUtil.getLastDayOfMonth(insureDto.getPolicyDateStart()))+" 23:59:59"));
insureUser.setApplyType(2);//投保类型 insureUser.setApplyType(2);//投保类型
insureUser.setPolicyId(insurePolicy.getId()); insureUser.setPolicyId(insurePolicy.getId());
insureUser.setCreateTime(new Date()); insureUser.setCreateTime(new Date());
...@@ -628,7 +628,6 @@ public class InsureContorll { ...@@ -628,7 +628,6 @@ public class InsureContorll {
.orgCode(y.getOrgCode()) .orgCode(y.getOrgCode())
.benefitOccupationCategory(insureDto.getBenefitOccupationCategory()) .benefitOccupationCategory(insureDto.getBenefitOccupationCategory())
.insuredMobile(y.getPhone()) .insuredMobile(y.getPhone())
.benefitOccupationCategory(insureDto.getBenefitOccupationCategory())
.insuredNo(y.getZjNum()) .insuredNo(y.getZjNum())
.tricycleFrameNumber(insureDto.getTricycleFrameNumber()) .tricycleFrameNumber(insureDto.getTricycleFrameNumber())
.insuredEContact(y.getName()) .insuredEContact(y.getName())
...@@ -1704,21 +1703,21 @@ public class InsureContorll { ...@@ -1704,21 +1703,21 @@ public class InsureContorll {
@PostMapping(value = "/replaceUserPolicy") @PostMapping(value = "/replaceUserPolicy")
@ApiOperation(value = "18.导入替换人员", httpMethod = "POST", notes = "导入用户") @ApiOperation(value = "18.导入替换人员", httpMethod = "POST", notes = "导入用户")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<Object> replaceUserPolicy(@RequestParam("file") MultipartFile file, @RequestParam("policyId") Integer policyId){ public Result<Object> replaceUserPolicy(@RequestParam("file") MultipartFile file, @RequestParam("policyId") Integer policyId,@RequestParam("planId") String planId,@RequestParam("categoryId") String categoryId){
InsurePolicy insurePolicy = InsurePolicy.builder().id(policyId).build().selectById(); InsurePolicy insurePolicy = InsurePolicy.builder().id(policyId).build().selectById();
ByteArrayOutputStream bos = null; ByteArrayOutputStream bos = new ByteArrayOutputStream();
XSSFWorkbook xw=null; XSSFWorkbook xw=null;
try { try {
xw = new XSSFWorkbook(file.getInputStream()); xw = new XSSFWorkbook(file.getInputStream());
XSSFSheet sheetAt = xw.getSheetAt(0); XSSFSheet sheetAt = xw.getSheetAt(0);
//默认第一行为标题行,i = 0 //默认第一行为标题行,i = 13
XSSFRow titleRow = sheetAt.getRow(0); XSSFRow titleRow = sheetAt.getRow(13);
InsureUser originalUser; InsureUser originalUser;
InsureUser replaceUser; InsureUser replaceUser;
/*原被保人集合*/ /*原被保人集合*/
List<InsureUser> originalList=Lists.newArrayList(); List<InsureUser> originalList=Lists.newArrayList();
// 循环获取每一行数据 // 循环获取每一行数据
for (int i = 1; i < sheetAt.getPhysicalNumberOfRows(); i++) { for (int i = 14; i < sheetAt.getPhysicalNumberOfRows(); i++) {
XSSFRow row = sheetAt.getRow(i); XSSFRow row = sheetAt.getRow(i);
originalUser=InsureUser.builder().build(); originalUser=InsureUser.builder().build();
replaceUser=InsureUser.builder().build(); replaceUser=InsureUser.builder().build();
...@@ -1758,6 +1757,7 @@ public class InsureContorll { ...@@ -1758,6 +1757,7 @@ public class InsureContorll {
if (StringUtils.isNullOrEmpty(ExcelUtils.getString(cell))) { if (StringUtils.isNullOrEmpty(ExcelUtils.getString(cell))) {
return ResultUtil.error("第" + i + "行第" + index + "列批改生效日不能为空"); return ResultUtil.error("第" + i + "行第" + index + "列批改生效日不能为空");
} }
replaceUser.setPolicyDateStart(dtf3.parse(ExcelUtils.getString(cell)+" 00:00:00"));
break; break;
case "replace_name": case "replace_name":
if (StringUtils.isNullOrEmpty(ExcelUtils.getString(cell))) { if (StringUtils.isNullOrEmpty(ExcelUtils.getString(cell))) {
...@@ -1776,26 +1776,14 @@ public class InsureContorll { ...@@ -1776,26 +1776,14 @@ public class InsureContorll {
} }
replaceUser.setInsuredNo(ExcelUtils.getString(cell)); replaceUser.setInsuredNo(ExcelUtils.getString(cell));
break; break;
case "Date_of_birth":
break;
case "insured_type":
break;
case "insured_relationship":
break;
case "cert_type_related_insured":
break;
case "insured_relationship_id":
break;
case "Branch":
break;
case "Tricycle_frame_number": case "Tricycle_frame_number":
replaceUser.setTricycleFrameNumber(ExcelUtils.getString(cell)); replaceUser.setTricycleFrameNumber(ExcelUtils.getString(cell));
break; break;
case "insured_number":
break;
case "benefit_occupation_category": case "benefit_occupation_category":
replaceUser.setBenefitOccupationCategory(ExcelUtils.getString(cell)); replaceUser.setBenefitOccupationCategory(ExcelUtils.getString(cell));
break; break;
default:
continue;
} }
originalUser.setReplaceUser(replaceUser); originalUser.setReplaceUser(replaceUser);
...@@ -1803,12 +1791,14 @@ public class InsureContorll { ...@@ -1803,12 +1791,14 @@ public class InsureContorll {
} }
} }
/*验证表格信息*/ /*验证表格信息*/
List<String> userIdList=Lists.newArrayList();
for (InsureUser insureUser : originalList) { for (InsureUser insureUser : originalList) {
InsureUser getInsureUser = InsureUser.builder().build().selectOne(new QueryWrapper<InsureUser>().lambda() InsureUser getInsureUser = InsureUser.builder().build().selectOne(new QueryWrapper<InsureUser>().lambda()
.eq(InsureUser::getInsuredEContact,insureUser.getInsuredEContact()).eq(InsureUser::getInsuredNo,insureUser.getInsuredNo()) .eq(InsureUser::getInsuredEContact,insureUser.getInsuredEContact()).eq(InsureUser::getInsuredNo,insureUser.getInsuredNo())
.eq(InsureUser::getInsureStatus,1).eq(InsureUser::getStatus,1).eq(InsureUser::getPolicyId,policyId)); .eq(InsureUser::getInsureStatus,1).eq(InsureUser::getStatus,1).eq(InsureUser::getPolicyId,policyId).eq(InsureUser::getBenefitBasicPlan,planId)
.eq(InsureUser::getBenefitOccupationCategory,categoryId));
if(getInsureUser==null){ if(getInsureUser==null){
return ResultUtil.error(insureUser.getInsuredName()+"未投保"); return ResultUtil.error(insureUser.getInsuredEContact()+"未投保");
} }
YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda() YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda()
.eq(YgglMainEmp::getName,insureUser.getReplaceUser().getInsuredName()) .eq(YgglMainEmp::getName,insureUser.getReplaceUser().getInsuredName())
...@@ -1825,9 +1815,11 @@ public class InsureContorll { ...@@ -1825,9 +1815,11 @@ public class InsureContorll {
ygglMainEmp.setIsInsure(0); ygglMainEmp.setIsInsure(0);
ygglMainEmp.insert(); ygglMainEmp.insert();
} }
userIdList.add(String.valueOf(ygglMainEmp.getId()));
} }
/*上传替换文件到保司服务器*/ /*上传替换文件到保司服务器*/
bos = new ByteArrayOutputStream();
/*保司返回地址*/ /*保司返回地址*/
String url = ""; String url = "";
xw.write(bos); xw.write(bos);
...@@ -1845,26 +1837,96 @@ public class InsureContorll { ...@@ -1845,26 +1837,96 @@ public class InsureContorll {
Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(o)); Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(o));
url = map.get("file_url").toString(); url = map.get("file_url").toString();
if(StringUtils.isNullOrEmpty(url)||url=="error"){ if(StringUtils.isNullOrEmpty(url)||url=="error"){
return ResultUtil.error("上传文件路径异常"); throw new CustomException("上传文件路径异常");
} }
} }
InsureLog.builder().requestParam(JSONObject.toJSONString(setParams(JSONObject.toJSONString(bodyMap), appidq, secretq))).type(6) InsureLog.builder().requestParam(JSONObject.toJSONString(setParams(JSONObject.toJSONString(bodyMap), appidq, secretq))).type(6)
.requestData(JSONObject.toJSONString(bodyMap)).createTime(new Date()).requestType(1).returnBody(data).requestPath(uploadUrl2) .requestData(JSONObject.toJSONString(bodyMap)).createTime(new Date()).requestType(1).returnBody(data).requestPath(uploadUrl2)
.returnCode(dataMap.get("errcode").toString()).returnMsg(dataMap.get("errmsg").toString()).fileUrl(url).build().insert(); .returnCode(dataMap.get("errcode").toString()).returnMsg(dataMap.get("errmsg").toString()).fileUrl(url).build().insert();
List<InsureUser> oldInsureUserList = insureUserMapper.selectListByIds(originalList.stream().map(InsureUser::getId).toArray(String[]::new),insurePolicy.getId(),null);
String[] oldUser = new String[oldInsureUserList.size()];
for (int i = 0; i < oldInsureUserList.size(); i++) {
oldUser[i] = oldInsureUserList.get(i).getUserId().toString();
}
Integer price = getPrice(planId, categoryId);
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
bodyMap.put("contract_no", insurePolicy.getPolicyNo());
bodyMap.put("order_status", "3");
bodyMap.put("callback_plan", "");
bodyMap.put("file_url", url);
bodyMap.put("from_source", "API");
bodyMap.put("import_review_callback", "");
bodyMap.put("import_callback", base_api_url + "/callBack/policy/CallBack");
bodyMap.put("third_uuid", "RP_" + insurePolicy.getOrgCode() + "_" + dtf2.format(now));
String responData = HttpUtils.sendPost(batchUrl, setParams(JSONObject.toJSONString(bodyMap), appidq, secretq), bodyMap);
Map<String, Object> batchDataMap = JSONObject.parseObject(responData);
InsureLog.builder().requestParam(JSONObject.toJSONString(setParams(JSONObject.toJSONString(bodyMap), appid, secret))).type(3)
.requestData(JSONObject.toJSONString(bodyMap)).createTime(new Date()).requestType(1).returnBody(responData).requestPath(batchUrl)
.returnCode(batchDataMap.get("errcode").toString()).returnMsg(batchDataMap.get("errmsg").toString()).policyId(insurePolicy.getId()).fileUrl(url).build().insert();
if (batchDataMap.get("errcode").toString().equals("suc")) {
Map<String, Object> batchData = JSONObject.parseObject(JSONObject.toJSONString(batchDataMap.get("data")));
Map<String, Object> orderImportInfo = JSONObject.parseObject(JSONObject.toJSONString(batchData.get("order_import_info")));
String status = orderImportInfo.get("status").toString();
if (status.equals("5") || status.equals("6") || status.equals("7")) {
InsureLog.builder().requestParam(JSONObject.toJSONString(setParams(JSONObject.toJSONString(bodyMap), appid, secret))).type(2)
.requestData(JSONObject.toJSONString(bodyMap)).createTime(new Date()).requestType(1).returnBody(responData).requestPath(batchUrl)
.returnCode(batchDataMap.get("errcode").toString()).returnMsg(batchDataMap.get("errmsg").toString()).policyId(insurePolicy.getId()).transId("RP_" + insurePolicy.getOrgCode() + "_" + dtf2.format(now)).fileUrl(batchData.get("file_url").toString()).build().insert();
//TODO 写入日志
return ResultUtil.error("信息填写错误,请查看日志");
} else {
List<YgglMainEmp> ygglMainEmpList = ygglMainEmpMapper.selectListByIds(userIdList.stream().toArray(String[]::new));
QyzxEntInfoM qyzxEntInfoM = QyzxEntInfoM.builder().id(insurePolicy.getOrgCode()).build().selectById();
ygglMainEmpList.forEach(y -> {
InsureUser.builder()
.transId("RP_" + insurePolicy.getOrgCode() + "_" + dtf2.format(now))
.insuredName(qyzxEntInfoM.getName())
.price(price.toString())/*前端获取的保费*/
.premium(String.valueOf(price * ygglMainEmpList.size()))
.batchNo(batchDataMap.get("import_uuid").toString())
.benefitBasicPlan(planId)
.policyNo(orderImportInfo.get("contract_no").toString())
.userId(y.getId())
.orgCode(y.getOrgCode())
.benefitOccupationCategory(categoryId)
.insuredMobile(y.getPhone())
.insuredNo(y.getZjNum())
.tricycleFrameNumber(oldInsureUserList.get(0).getTricycleFrameNumber())
.insuredEContact(y.getName())
.applicantEmployeeList(batchDataMap.get("file_url").toString())
.policyDateStart(oldInsureUserList.get(0).getPolicyDateStart())
.policyDateEnd(oldInsureUserList.get(0).getPolicyDateEnd())
.applyType(3)
.createTime(new Date())
.status("1").insureStatus(3).policyId(insurePolicy.getId()).build().insert();
y.setIsInsure(1);
y.insertOrUpdate();
});
oldInsureUserList.forEach(o -> {
o.setReplaceTransId(batchDataMap.get("import_uuid").toString());
o.updateById();
});
return ResultUtil.data("核保成功,等待系统更新");
}
}
return ResultUtil.error("导入失败");
}catch (Exception e){ }catch (Exception e){
throw new CustomException("导入异常"); throw new CustomException("导入异常");
}finally { }finally {
try { try {
xw.close(); bos.close();
} catch (IOException e) { } catch (IOException e) {
throw new CustomException("XSSFWorkbook流关闭异常"); throw new CustomException("ByteArrayOutputStream流关闭异常");
} }
try { try {
bos.close(); xw.close();
} catch (IOException e) { } catch (IOException e) {
throw new CustomException("ByteArrayOutputStream流关闭异常"); throw new CustomException("XSSFWorkbook流关闭异常");
} }
} }
return ResultUtil.success();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment