Commit c562be17 authored by 李灿灿's avatar 李灿灿

表内数据校验重复

parent 1f69b220
......@@ -270,7 +270,37 @@ public class LocalDateUtil {
return dif;
}
/**
* 判断两个时间段是否有交集
*
* 思路:将有交集的情况列出,若不符合有交集的情况,则无交集
* 有交集的两种情况
* 1.第一个时间段的开始时间在第二个时间段的开始时间和结束时间当中
* 2.第二个时间段的开始时间在第一个时间段的开始时间和结束时间当中
*
* @author licancan
* @param leftStartDate 第一个时间段的开始时间
* @param leftEndDate 第一个时间段的结束时间
* @param rightStartDate 第二个时间段的开始时间
* @param rightEndDate 第二个时间段的结束时间
* @return {@link boolean} 若有交集, 返回true, 否则返回false
*/
public static boolean hasOverlap(LocalDate leftStartDate, LocalDate leftEndDate, LocalDate rightStartDate, LocalDate rightEndDate) {
return ((leftStartDate.equals(rightStartDate) || leftStartDate.isAfter(rightStartDate))
&& leftStartDate.isBefore(rightEndDate))
||
(leftStartDate.isAfter(rightStartDate)
&& (leftStartDate.equals(rightEndDate) || leftStartDate.isBefore(rightEndDate)))
||
((rightStartDate.equals(leftStartDate) || rightStartDate.isAfter(leftStartDate))
&& rightStartDate.isBefore(leftEndDate))
||
(rightStartDate.isAfter(leftStartDate)
&& (rightStartDate.equals(leftEndDate) || rightStartDate.isBefore(leftEndDate)));
}
public static void main(String[] args) {
System.out.println(betweenMonth("2022-10-03","2022-08-03"));
boolean hasOverlap = hasOverlap(parseLocalDate("2022-08-03"), parseLocalDate("2022-08-04"), parseLocalDate("2022-08-03"), parseLocalDate("2022-08-04"));
System.out.println(hasOverlap);
}
}
......@@ -945,7 +945,11 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
Map<String,List<InsuranceAddParam>> map = new HashMap<>();
List<InsuranceAddParam> listResult = new ArrayList<>();
List<InsuranceAddParam> listSuccess = new ArrayList<>();
for (InsuranceAddParam param : paramList.stream().distinct().collect(Collectors.toList())) {
List<InsuranceAddParam> distinctList = paramList.stream().distinct().collect(Collectors.toList());
//定义外层循环标识,方便去重的时候跳出
outer:
for (int i = 0; i < distinctList.size(); i++) {
InsuranceAddParam param = distinctList.get(i);
// 必填校验
if (StringUtils.isBlank(param.getEmpName())){
param.setErrorMessage(InsurancesConstants.EMP_NAME_NOT_EMPTY);
......@@ -1043,6 +1047,44 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
listResult.add(param);
continue;
}
// 保单开始日期 > 当前派单日期
if(!LocalDateUtil.isDate(param.getPolicyStart(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_START_PARSE_ERROR);
listResult.add(param);
continue;
}
if(!LocalDateUtil.isDate(param.getPolicyEnd(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_END_PARSE_ERROR);
listResult.add(param);
continue;
}
if(!LocalDateUtil.isFutureDate(param.getPolicyStart())){
param.setErrorMessage(InsurancesConstants.POLICY_START_SHOULD_IS_FUTURE);
listResult.add(param);
continue;
}
if (!LocalDateUtil.compareDate(param.getPolicyStart(),param.getPolicyEnd())){
param.setErrorMessage(InsurancesConstants.POLICY_START_SHOULD_LESS_THAN_POLICY_END);
listResult.add(param);
continue;
}
//表内数据重复 员工姓名、员工身份证号码、保险公司、险种、起止时间(有交叉)
for (int j = 0; j < distinctList.size(); j++) {
InsuranceAddParam repeat = distinctList.get(j);
if (param.getEmpName().equals(repeat.getEmpName())
&& param.getEmpIdcardNo().equals(repeat.getEmpIdcardNo())
&& param.getInsuranceCompanyName().equals(repeat.getInsuranceCompanyName())
&& param.getInsuranceTypeName().equals(repeat.getInsuranceTypeName())
&& LocalDateUtil.hasOverlap(LocalDateUtil.parseLocalDate(param.getPolicyStart()),LocalDateUtil.parseLocalDate(param.getPolicyEnd()),LocalDateUtil.parseLocalDate(repeat.getPolicyStart()),LocalDateUtil.parseLocalDate(repeat.getPolicyEnd()))
&& i != j){
param.setErrorMessage(InsurancesConstants.DUPLICATE_DATA_ERROR);
listResult.add(param);
continue outer;
}
}
//校验身份合法
/*TCheckIdCard checkIdCard = new TCheckIdCard();
checkIdCard.setName(param.getEmpName());
......@@ -1119,28 +1161,6 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
param.setInsuranceHandleCity(Integer.parseInt(redisHandleCityName));
}
// 保单开始日期 > 当前派单日期
if(!LocalDateUtil.isDate(param.getPolicyStart(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_START_PARSE_ERROR);
listResult.add(param);
continue;
}
if(!LocalDateUtil.isDate(param.getPolicyEnd(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_END_PARSE_ERROR);
listResult.add(param);
continue;
}
if(!LocalDateUtil.isFutureDate(param.getPolicyStart())){
param.setErrorMessage(InsurancesConstants.POLICY_START_SHOULD_IS_FUTURE);
listResult.add(param);
continue;
}
if (!LocalDateUtil.compareDate(param.getPolicyStart(),param.getPolicyEnd())){
param.setErrorMessage(InsurancesConstants.POLICY_START_SHOULD_LESS_THAN_POLICY_END);
listResult.add(param);
continue;
}
// 保险公司-险种-购买标准 是否存在
TInsuranceCompany insuranceCompany = tInsuranceCompanyService.getOne(Wrappers.<TInsuranceCompany>query().lambda()
.eq(TInsuranceCompany::getCompanyName, param.getInsuranceCompanyName())
......@@ -1297,7 +1317,11 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
Map<String,List<InsuranceBatchParam>> map = new HashMap<>();
List<InsuranceBatchParam> listResult = new ArrayList<>();
List<InsuranceBatchParam> listSuccess = new ArrayList<>();
for (InsuranceBatchParam param : paramList.stream().distinct().collect(Collectors.toList())) {
List<InsuranceBatchParam> distinctList = paramList.stream().distinct().collect(Collectors.toList());
//定义外层循环标识,方便去重的时候跳出
outer:
for (int i = 0; i < distinctList.size(); i++) {
InsuranceBatchParam param = distinctList.get(i);
// 必填校验
if (StringUtils.isBlank(param.getDeptNo())){
param.setErrorMessage(InsurancesConstants.DEPT_NO_NOT_EMPTY);
......@@ -1388,6 +1412,21 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
continue;
}
//表内数据重复 员工姓名、员工身份证号码、保险公司、险种、保单号
for (int j = 0; j < distinctList.size(); j++) {
InsuranceBatchParam repeat = distinctList.get(j);
if (param.getEmpName().equals(repeat.getEmpName())
&& param.getEmpIdcardNo().equals(repeat.getEmpIdcardNo())
&& param.getInsuranceCompanyName().equals(repeat.getInsuranceCompanyName())
&& param.getInsuranceTypeName().equals(repeat.getInsuranceTypeName())
&& param.getPolicyNo().equals(repeat.getPolicyNo())
&& i != j){
param.setErrorMessage(InsurancesConstants.DUPLICATE_DATA_ERROR);
listResult.add(param);
continue outer;
}
}
//校验身份合法
/*TCheckIdCard checkIdCard = new TCheckIdCard();
checkIdCard.setName(param.getEmpName());
......@@ -1625,7 +1664,11 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
Map<String,List<InsuranceReplaceParam>> map = new HashMap<>();
List<InsuranceReplaceParam> listResult = new ArrayList<>();
List<InsuranceReplaceParam> listSuccess = new ArrayList<>();
for (InsuranceReplaceParam param : paramList.stream().distinct().collect(Collectors.toList())) {
List<InsuranceReplaceParam> distinctList = paramList.stream().distinct().collect(Collectors.toList());
//定义外层循环标识,方便去重的时候跳出
outer:
for (int i = 0; i < distinctList.size(); i++) {
InsuranceReplaceParam param = distinctList.get(i);
// 必填校验
if (StringUtils.isBlank(param.getEmpName())){
param.setErrorMessage(InsurancesConstants.EMP_NAME_NOT_EMPTY);
......@@ -1700,6 +1743,38 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
listResult.add(param);
continue;
}
if(!LocalDateUtil.isDate(param.getPolicyStart(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_START_PARSE_ERROR);
listResult.add(param);
continue;
}
if(!LocalDateUtil.isDate(param.getPolicyEnd(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_END_PARSE_ERROR);
listResult.add(param);
continue;
}
if (!LocalDateUtil.compareDate(param.getPolicyStart(),param.getPolicyEnd())){
param.setErrorMessage(InsurancesConstants.POLICY_START_SHOULD_LESS_THAN_POLICY_END);
listResult.add(param);
continue;
}
//表内数据重复 员工姓名、员工身份证号码、保险公司、险种、起止时间(有交叉)
for (int j = 0; j < distinctList.size(); j++) {
InsuranceReplaceParam repeat = distinctList.get(j);
if (((param.getEmpName().equals(repeat.getEmpName()) && param.getEmpIdcardNo().equals(repeat.getEmpIdcardNo()))
||(param.getReplaceEmpName().equals(repeat.getReplaceEmpName()) && param.getReplaceEmpIdcardNo().equals(repeat.getReplaceEmpIdcardNo())))
&& param.getInsuranceCompanyName().equals(repeat.getInsuranceCompanyName())
&& param.getInsuranceTypeName().equals(repeat.getInsuranceTypeName())
&& LocalDateUtil.hasOverlap(LocalDateUtil.parseLocalDate(param.getPolicyStart()),LocalDateUtil.parseLocalDate(param.getPolicyEnd()),LocalDateUtil.parseLocalDate(repeat.getPolicyStart()),LocalDateUtil.parseLocalDate(repeat.getPolicyEnd()))
&& i != j){
param.setErrorMessage(InsurancesConstants.DUPLICATE_DATA_ERROR);
listResult.add(param);
continue outer;
}
}
//校验身份合法
/*TCheckIdCard checkIdCard = new TCheckIdCard();
checkIdCard.setName(param.getReplaceEmpName());
......@@ -1738,17 +1813,6 @@ public class TInsuranceDetailServiceImpl extends ServiceImpl<TInsuranceDetailMap
}
}
if(!LocalDateUtil.isDate(param.getPolicyStart(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_START_PARSE_ERROR);
listResult.add(param);
continue;
}
if(!LocalDateUtil.isDate(param.getPolicyEnd(),LocalDateUtil.NORM_DATE_PATTERN)){
param.setErrorMessage(InsurancesConstants.POLICY_END_PARSE_ERROR);
listResult.add(param);
continue;
}
//原数据查重校验:姓名 + 身份证号 + 项目编码 + 保险公司 + 险种名称 + 保单开始时间 + 保单结束时间
TInsuranceDetail detail = this.baseMapper.selectOne(Wrappers.<TInsuranceDetail>query().lambda()
.eq(TInsuranceDetail::getEmpName, param.getEmpName())
......
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