|  |  | 
 |  |  | import com.doumee.dao.business.dto.*; | 
 |  |  | import com.doumee.dao.business.join.*; | 
 |  |  | import com.doumee.dao.business.model.*; | 
 |  |  | import com.doumee.dao.business.vo.ChangeDealTypeVO; | 
 |  |  | import com.doumee.dao.business.vo.CountCyclePriceVO; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | import com.doumee.service.business.ApplyChangeService; | 
 |  |  | 
 |  |  |                             .set(ApplyDetail::getEndTime, delValidTime) | 
 |  |  |                             .set(ApplyDetail::getEditor, update.getEditor()) | 
 |  |  |                             .set(ApplyDetail::getEditDate, update.getEditDate()) | 
 |  |  |  | 
 |  |  |                             .eq(ApplyDetail::getId, oldModel.getId()) | 
 |  |  |                     ); | 
 |  |  |                     totalFee = totalFee.add(updateFee).subtract(oldModel.getFee()); | 
 |  |  | 
 |  |  |                             .set( ApplyChagneDetail::getEndTime, delValidTime) | 
 |  |  |                             .eq(ApplyChagneDetail::getId,detail.getId()) | 
 |  |  |                     ); | 
 |  |  |  | 
 |  |  | //                if(1==1){ | 
 |  |  | //                    throw new BusinessException(ResponseStatus.SERVER_ERROR); | 
 |  |  | //                } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             member.setApplyId(update.getApplyId()); | 
 |  |  | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到企业分配保险方案信息"); | 
 |  |  |         } | 
 |  |  |         //申请时间必须处于保单的时间范围内 | 
 |  |  |         if (!(DateUtil.compareDate( insuranceApply.getStartTime(),applyChange.getValidTime()) >= Constants.ZERO | 
 |  |  |                 && DateUtil.compareDate( applyChange.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) { | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); | 
 |  |  |         } | 
 |  |  | //        if (!(DateUtil.compareDate( insuranceApply.getStartTime(),applyChange.getValidTime()) >= Constants.ZERO | 
 |  |  | //                && DateUtil.compareDate( applyChange.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) { | 
 |  |  | //            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); | 
 |  |  | //        } | 
 |  |  |         //查询保单下是否存在进行中的加减保/换厂单据 | 
 |  |  |         if(applyChangeMapper.selectCount(new QueryWrapper<ApplyChange>().lambda() | 
 |  |  |                 .eq(ApplyChange::getApplyId,insuranceApply.getId()) | 
 |  |  | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到企业分配保险方案信息"); | 
 |  |  |         } | 
 |  |  |         //申请时间必须处于保单的时间范围内 | 
 |  |  |         if (!(DateUtil.compareDate( insuranceApply.getStartTime(),applyChange.getValidTime()) >= Constants.ZERO | 
 |  |  |                 && DateUtil.compareDate( applyChange.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) { | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); | 
 |  |  |         } | 
 |  |  | //        if (!(DateUtil.compareDate( insuranceApply.getStartTime(),applyChange.getValidTime()) >= Constants.ZERO | 
 |  |  | //                && DateUtil.compareDate( applyChange.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) { | 
 |  |  | //            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); | 
 |  |  | //        } | 
 |  |  |         //查询保单下是否存在进行中的加减保/换厂单据 | 
 |  |  |         if(applyChangeMapper.selectCount(new QueryWrapper<ApplyChange>().lambda() | 
 |  |  |                 .eq(ApplyChange::getApplyId,insuranceApply.getId()) | 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     public BigDecimal dealApplyChangeData(ApplyChange applyChange,InsuranceApply insuranceApply,CompanySolution companySolution,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal fee){ | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         if(Objects.nonNull(solutions.getDelOnlyReplace())&& solutions.getDelOnlyReplace().equals(Constants.ONE)){ | 
 |  |  |             if(applyChange.getDelDetailList().size() > applyChange.getAddDetailList().size()){ | 
 |  |  |                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "该保险方案仅支持替换(减保人数不得大于加保人数)"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         //查询保险方案下的所有派遣单位 | 
 |  |  |         List<DuSolution>  duSolutionList = duSolutionJoinMapper.selectJoinList(DuSolution.class,new MPJLambdaWrapper<DuSolution>() | 
 |  |  |                 .selectAll(DuSolution.class) | 
 |  |  | 
 |  |  |         if(!CollectionUtils.isNotEmpty(duSolutionList)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"数据异常:保险方案下未查询到派遣单位"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //查询所有派遣单位下的工种 | 
 |  |  |         List<Integer> duSolutionIdList = duSolutionList.stream().map(i->i.getId()).collect(Collectors.toList()); | 
 |  |  |         List<DuWorktype> duWorktypeList = duWorktypeMapper.selectList(new QueryWrapper<DuWorktype>().lambda() | 
 |  |  | 
 |  |  |  | 
 |  |  |         ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO = new ApplyChangeCyclePriceDTO(); | 
 |  |  |         applyChangeCyclePriceDTO.setApplyId(insuranceApply.getId()); | 
 |  |  |  | 
 |  |  |          | 
 |  |  |         //加保数据 | 
 |  |  |         List<ApplyChagneDetail> addDetailList = applyChange.getAddDetailList(); | 
 |  |  |         Integer addDetailSize  = 0 ; | 
 |  |  |  | 
 |  |  |         if (CollectionUtils.isNotEmpty(addDetailList)) { | 
 |  |  |             addDetailSize = addDetailList.size(); | 
 |  |  |             if(Objects.isNull(solutions.getCanAdd()) || solutions.getCanAdd().equals(Constants.ZERO)){ | 
 |  |  |                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "该保险方案无法进行加保"); | 
 |  |  |             } | 
 |  |  | //            if(companySolution.getCanAdd().equals(Constants.ZERO)){ | 
 |  |  | //                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "该企业分配保险方案无法进行加保"); | 
 |  |  | //            } | 
 |  |  |             //验证是否存在重复数据 | 
 |  |  |             List<String> idcarNo = addDetailList.stream().map(m->m.getIdcardNo()).collect(Collectors.toList()); | 
 |  |  |             Set<String> set = new HashSet<>(idcarNo); | 
 |  |  | 
 |  |  |  | 
 |  |  |         //减保数据 | 
 |  |  |         List<ApplyChagneDetail> delDetailList = applyChange.getDelDetailList(); | 
 |  |  |         Integer delDetailSize  = 0 ; | 
 |  |  |         if (CollectionUtils.isNotEmpty(delDetailList)) { | 
 |  |  |             delDetailSize  = delDetailList.size() ; | 
 |  |  |             //验证是否存在重复数据 | 
 |  |  |             List<String> idcarNo = delDetailList.stream().map(m->m.getIdcardNo()).collect(Collectors.toList()); | 
 |  |  |             Set<String> set = new HashSet<>(idcarNo); | 
 |  |  | 
 |  |  |             fee = fee.add(delDetailList.stream().map(ApplyChagneDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if(Objects.nonNull(solutions.getDelOnlyReplace())&& solutions.getDelOnlyReplace().equals(Constants.ONE)){ | 
 |  |  |             if(delDetailSize > addDetailSize){ | 
 |  |  |                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "该保险方案仅支持替换(减保人数不得大于加保人数)"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         | 
 |  |  |  | 
 |  |  |         //换厂业务 | 
 |  |  |         List<ApplyChagneDetail> changeDetailList = applyChange.getChangeDetailList(); | 
 |  |  | 
 |  |  |             applyChagneDetail.setIsdeleted(Constants.ZERO); | 
 |  |  |             applyChagneDetail.setApplyChangeId(applyChange.getId()); | 
 |  |  |             applyChagneDetail.setType(Constants.ONE); | 
 |  |  |  | 
 |  |  |             applyChagneDetail.setApplyDetailId(applyDetail.getId()); | 
 |  |  |             applyChagneDetail.setStartTime(applyDetail.getStartTime()); | 
 |  |  |             applyChagneDetail.setEndTime(endTime); | 
 |  |  |             applyChagneDetail.setReduceMoney(BigDecimal.ZERO); | 
 |  |  |  | 
 |  |  |             member.setApplyId(insuranceApply.getId()); | 
 |  |  |             member.setDuId(applyChagneDetail.getDuId()); | 
 |  |  | 
 |  |  |             //查询减保日期 | 
 |  |  | //            Integer delDays = DateUtil.daysBetweenDates(applyDetail.getEndTime(),endTime); | 
 |  |  | //            ; | 
 |  |  |  | 
 |  |  |             //查询周期数量 | 
 |  |  |             applyChagneDetail.setFee( | 
 |  |  |                     Constants.reduceFee(solutions, | 
 |  |  |                                     Objects.isNull(insuranceApply.getServerCost())? | 
 |  |  | 
 |  |  |                                     applyDetail.getStartTime(),endTime) | 
 |  |  |                             .subtract(applyDetail.getFee() | 
 |  |  |             )); | 
 |  |  |             //如果是减保业务为仅替换 且 方案的扣费周期和总周期相等 则处理减保费用 | 
 |  |  |             if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE) | 
 |  |  |              && Constants.equalsInteger(solutions.getTimeUnit(),solutions.getInsureCycleUnit())){ | 
 |  |  |                 applyChagneDetail.setReduceMoney(solutions.getPrice().multiply(new BigDecimal(-1))); | 
 |  |  |             } | 
 |  |  |             applyChagneDetailJoinMapper.insert(applyChagneDetail); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | 
 |  |  |         } | 
 |  |  |         //根据批单日期 和 结束日期 计算金额 | 
 |  |  |         //验证批单日期是否在当前日期后 且 在保单结束日期前 申请时间必须处于保单的时间范围内 | 
 |  |  |         if (!(DateUtil.compareDate( insuranceApply.getStartTime(),applyChangeCyclePriceDTO.getValidTime()) >= Constants.ZERO | 
 |  |  |                 && DateUtil.compareDate( applyChangeCyclePriceDTO.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) { | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); | 
 |  |  |         } | 
 |  |  | //        if (!(DateUtil.compareDate( insuranceApply.getStartTime(),applyChangeCyclePriceDTO.getValidTime()) >= Constants.ZERO | 
 |  |  | //                && DateUtil.compareDate( applyChangeCyclePriceDTO.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) { | 
 |  |  | //            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); | 
 |  |  | //        } | 
 |  |  |         BigDecimal sumPrice = Objects.isNull(insuranceApply.getServerCost())?solutions.getPrice():solutions.getPrice().add(insuranceApply.getServerCost()); | 
 |  |  |         CountCyclePriceVO returnCountCyclePriceVO = new CountCyclePriceVO(); | 
 |  |  |         returnCountCyclePriceVO.setCyclePrice(Constants.addFee(solutions, |