| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private ApplyDetailJoinMapper applyDetailJoinMapper; |
| | | |
| | | @Autowired |
| | | private MemberInsuranceJoinMapper memberInsuranceJoinMapper; |
| | | |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | |
| | | ApplyLog log = new ApplyLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update)); |
| | | applyLogMapper.insert(log); |
| | | |
| | | |
| | | return 1; |
| | | |
| | | } |
| | |
| | | .selectAll(ApplyChagneDetail.class) |
| | | .selectAs(Solutions::getTimeUnit,ApplyChagneDetail::getSolutionTimeUnit) |
| | | .selectAs(Solutions::getPrice,ApplyChagneDetail::getSolutionPrice) |
| | | .selectAs(Worktype::getName,ApplyChagneDetail::getWorkTypeName) |
| | | .selectAs(DispatchUnit::getName,ApplyChagneDetail::getDuName) |
| | | .leftJoin(ApplyChange.class, ApplyChange::getId, ApplyChagneDetail::getApplyChangeId) |
| | | .leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyChange::getApplyId) |
| | | .leftJoin(Solutions.class, Solutions::getId, InsuranceApply::getSolutionId) |
| | | .leftJoin(Solutions.class, Solutions::getId, ApplyChange::getSolutionsId) |
| | | .leftJoin(Worktype.class,Worktype::getId,ApplyChagneDetail::getWorktypeId) |
| | | .leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyChagneDetail::getDuId) |
| | | .eq(ApplyChagneDetail::getApplyChangeId,update.getId()) |
| | | .eq(ApplyChagneDetail::getIsdeleted,Constants.ZERO) ); |
| | | if(detailList ==null || detailList.size()==0){ |
| | |
| | | if(oldModel == null ){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,用户【"+detail.getMemberName()+"】原保单信息有误,当前申请不支持减保处理!"); |
| | | } |
| | | Date endDate = oldModel.getEndTime(); |
| | | //当前日期大于批单日期 需要回滚数据实际数据 |
| | | Boolean flag = DateUtil.getMontageDate(new Date(),2).compareTo(DateUtil.getMontageDate(update.getStartTime(),2))>0; |
| | | //换厂后历史记录的费用 fee |
| | | Integer days = DateUtil.daysBetweenDates(DateUtil.getMontageDate(update.getStartTime(),2),DateUtil.getMontageDate(oldModel.getStartTime(),1)) + 1; |
| | | BigDecimal oldFee = this.getApplyPrice(update.getApplyId(),days); |
| | | BigDecimal fee = oldModel.getFee(); |
| | | BigDecimal oldCurrentFee = oldModel.getCurrentFee(); |
| | | applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda() |
| | | .set(ApplyDetail::getEditor,update.getEditor()) |
| | | .set(ApplyDetail::getWorktypeId,detail.getWorktypeId()) |
| | | .set(ApplyDetail::getDuId,detail.getDuId()) |
| | | .set(ApplyDetail::getEditDate,update.getEditDate()) |
| | | .set(ApplyDetail::getEndTime,DateUtil.getMontageDate(update.getStartTime(),2)) |
| | | .set(ApplyDetail::getFee,oldFee) |
| | | .set(flag,ApplyDetail::getCurrentFee,oldFee) |
| | | .eq(ApplyDetail::getId,oldModel.getApplyId()) |
| | | ); |
| | | |
| | | //修改 员工投保明细记录 历史数据 |
| | | memberInsuranceJoinMapper.update(null,new UpdateWrapper<MemberInsurance>().lambda() |
| | | .set(MemberInsurance::getEndTime,update.getApplyStartTime()) |
| | | .set(MemberInsurance::getFee,oldFee) |
| | | .eq(MemberInsurance::getRelationId,oldModel.getId()) |
| | | ); |
| | | |
| | | ApplyDetail applyDetail = new ApplyDetail(); |
| | | applyDetail.setApplyId(oldModel.getApplyId()); |
| | | applyDetail.setCreateDate(new Date()); |
| | | applyDetail.setCreator(update.getEditor()); |
| | | applyDetail.setMemberId(oldModel.getMemberId()); |
| | | applyDetail.setStartTime(DateUtil.getMontageDate(update.getApplyStartTime(),1)); |
| | | applyDetail.setEndTime(endDate); |
| | | applyDetail.setDuId(detail.getDuId()); |
| | | applyDetail.setWorktypeId(detail.getWorktypeId()); |
| | | applyDetail.setIdcardNo(oldModel.getIdcardNo()); |
| | | applyDetail.setFee(fee.subtract(oldFee)); |
| | | if(flag){ |
| | | applyDetail.setCurrentFee(oldCurrentFee.multiply(oldFee)); |
| | | }else{ |
| | | applyDetail.setCurrentFee(BigDecimal.ZERO); |
| | | } |
| | | applyDetail.setSex(oldModel.getSex()); |
| | | applyDetail.setMemberName(oldModel.getMemberName()); |
| | | applyDetail.setFromId(detail.getId()); |
| | | applyDetailJoinMapper.insert(applyDetail); |
| | | |
| | | MemberInsurance memberInsurance = new MemberInsurance(applyDetail,update.getId()); |
| | | memberInsuranceJoinMapper.insert(memberInsurance); |
| | | } |
| | | } |
| | | /** |
| | | * 处理加减保明细数据 |
| | | * @param update |
| | | */ |
| | | private void dealDetailsValidTime(ApplyChange update ) { |
| | | private void dealDetailsValidTime(ApplyChange update) { |
| | | List<ApplyChagneDetail> detailList = applyChagneDetailJoinMapper.selectJoinList(ApplyChagneDetail.class, |
| | | new MPJLambdaWrapper<ApplyChagneDetail>() |
| | | .selectAll(ApplyChagneDetail.class) |
| | | .selectAs(Solutions::getTimeUnit,ApplyChagneDetail::getSolutionTimeUnit) |
| | | .selectAs(Solutions::getPrice,ApplyChagneDetail::getSolutionPrice) |
| | | .leftJoin(ApplyChange.class, ApplyChange::getId, ApplyChagneDetail::getApplyChangeId) |
| | | .leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyChange::getApplyId) |
| | | .leftJoin(Solutions.class, Solutions::getId, InsuranceApply::getSolutionId) |
| | | .eq(ApplyChagneDetail::getApplyChangeId,update.getId()) |
| | | .eq(ApplyChagneDetail::getIsdeleted,Constants.ZERO) ); |
| | | if(detailList ==null || detailList.size()==0){ |
| | | .selectAs(Solutions::getTimeUnit, ApplyChagneDetail::getSolutionTimeUnit) |
| | | .selectAs(Solutions::getPrice, ApplyChagneDetail::getSolutionPrice) |
| | | .selectAs(Worktype::getName, ApplyChagneDetail::getWorkTypeName) |
| | | .selectAs(DispatchUnit::getName, ApplyChagneDetail::getDuName) |
| | | .leftJoin(ApplyChange.class, ApplyChange::getId, ApplyChagneDetail::getApplyChangeId) |
| | | .leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyChange::getApplyId) |
| | | .leftJoin(Solutions.class, Solutions::getId, InsuranceApply::getSolutionId) |
| | | .leftJoin(Solutions.class, Solutions::getId, ApplyChange::getSolutionsId) |
| | | .leftJoin(Worktype.class, Worktype::getId, ApplyChagneDetail::getWorktypeId) |
| | | .leftJoin(DispatchUnit.class, DispatchUnit::getId, ApplyChagneDetail::getDuId) |
| | | .eq(ApplyChagneDetail::getApplyChangeId, update.getId()) |
| | | .eq(ApplyChagneDetail::getIsdeleted, Constants.ZERO)); |
| | | if (detailList == null || detailList.size() == 0) { |
| | | return; |
| | | } |
| | | List<ApplyDetail> addList = new ArrayList<>(); |
| | | List<Integer> reduceMembers = new ArrayList<>(); |
| | | BigDecimal totalFee = new BigDecimal(0); |
| | | BigDecimal currentFee = new BigDecimal(0); |
| | | //投保记录 加保数据加入新数据 减保数据 修改老数据 |
| | | List<MemberInsurance> memberInsuranceList = new ArrayList<>(); |
| | | |
| | | for(ApplyChagneDetail detail : detailList){ |
| | | if(Constants.equalsInteger(detail.getType(),Constants.ZERO)){ |
| | | |
| | | //加保业务 使用的加保金额 |
| | | ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO_add = new ApplyChangeCyclePriceDTO(); |
| | | applyChangeCyclePriceDTO_add.setApplyId(update.getApplyId()); |
| | | applyChangeCyclePriceDTO_add.setValidTime(DateUtil.getMontageDate(update.getStartTime(), 1)); |
| | | //加保 添加的金额 |
| | | CountCyclePriceVO countCyclePriceVO_add = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO_add); |
| | | |
| | | |
| | | //减保业务 使用的减保金额 |
| | | ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO_reduce = new ApplyChangeCyclePriceDTO(); |
| | | applyChangeCyclePriceDTO_reduce.setApplyId(update.getApplyId()); |
| | | applyChangeCyclePriceDTO_reduce.setValidTime(DateUtil.getMontageDate(update.getStartTime(), 3)); |
| | | //减保 需要减少的金额 |
| | | CountCyclePriceVO countCyclePriceVO_reduce = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO_reduce); |
| | | |
| | | |
| | | for (ApplyChagneDetail detail : detailList) { |
| | | if (Constants.equalsInteger(detail.getType(), Constants.ZERO)) { |
| | | //加保 |
| | | ApplyDetail add = new ApplyDetail(); |
| | | add.setApplyId(update.getApplyId()); |
| | |
| | | add.setEndTime(detail.getEndTime()); |
| | | add.setFee(new BigDecimal(0)); |
| | | // add.setFee(Constants.countDetailFee(detail.getSolutionTimeUnit(),detail.getSolutionPrice(), add.getStartTime(),add.getEndTime())); |
| | | if(DateUtil.daysBetweenDates(add.getStartTime(),new Date() )>=0){ |
| | | //如果已产生费用,计算已产生费用 |
| | | add.setCurrentFee(Constants.countDetailFee(detail.getSolutionTimeUnit(),detail.getSolutionPrice(), add.getStartTime(),new Date())); |
| | | if (DateUtil.daysBetweenDates(add.getStartTime(), new Date()) >= 0) { |
| | | add.setStartTime(DateUtil.getMontageDate(update.getApplyStartTime(), 1)); |
| | | add.setEndTime(DateUtil.getMontageDate(detail.getEndTime(), 2)); |
| | | |
| | | add.setFee(countCyclePriceVO_add.getCyclePrice()); |
| | | if (DateUtil.daysBetweenDates(DateUtil.getMontageDate(add.getStartTime(), 2), new Date()) >= 0) { |
| | | Integer days = DateUtil.daysBetweenDates(new Date(), DateUtil.getMontageDate(add.getStartTime(), 2)) + 1; |
| | | //如果已产生费用,计算已产生费用 |
| | | add.setCurrentFee(this.getApplyPrice(update.getApplyId(), days)); |
| | | } |
| | | // addList.add(add); |
| | | applyDetailJoinMapper.insert(add); |
| | | totalFee.add(add.getFee()); |
| | | currentFee.add(add.getCurrentFee()); |
| | | |
| | | MemberInsurance memberInsurance = new MemberInsurance(detail, update, update.getEditor(), add.getId()); |
| | | memberInsuranceList.add(memberInsurance); |
| | | } else { |
| | | //减保操作 |
| | | //查询员工是在主单下 是否存在生效中的数据 |
| | | ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda() |
| | | .eq(ApplyDetail::getApplyId, update.getApplyId()) |
| | | .eq(ApplyDetail::getMemberId, detail.getMemberId()) |
| | | .orderByDesc(ApplyDetail::getCreateDate) |
| | | .last("limit 1")); |
| | | if (oldModel == null || oldModel.getStartTime() == null || oldModel.getStartTime().getTime() > update.getApplyStartTime().getTime()) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,用户【" + detail.getMemberName() + "】原保单信息有误,当前申请不支持减保处理!"); |
| | | } |
| | | //退保需要退回的费用 |
| | | BigDecimal updateFee = countCyclePriceVO_reduce.getCyclePrice().multiply(new BigDecimal(-1)); |
| | | BigDecimal updateCurrentFee = oldModel.getFee().subtract(updateFee); |
| | | |
| | | // BigDecimal updateCurrentFee = new BigDecimal(0); |
| | | // if(DateUtil.daysBetweenDates(update.getApplyStartTime(),new Date() )>0){ |
| | | // //如果生效时间 是今天之前,退回已产生费用,计算已产生费用(总费用-已产生费用) |
| | | // updateCurrentFee = updateFee.subtract(oldModel.getCurrentFee()); |
| | | // } |
| | | |
| | | // BigDecimal updateFee = (Constants.countDetailFee(detail.getSolutionTimeUnit(), detail.getSolutionPrice(), oldModel.getStartTime(), update.getApplyStartTime())); |
| | | // BigDecimal updateCurrentFee = new BigDecimal(0); |
| | | if (DateUtil.daysBetweenDates(update.getApplyStartTime(), new Date()) > 0) { |
| | | //如果生效时间 是今天之前,退回已产生费用,计算已产生费用(总费用-已产生费用) |
| | | updateCurrentFee = updateFee.subtract(Constants.formatBigdecimal(oldModel.getCurrentFee())); |
| | | } |
| | | applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda() |
| | | .setSql(" fee = ifnull(fee,0)+" + updateFee) |
| | | .setSql(" current_fee = " + updateCurrentFee) |
| | | .set(ApplyDetail::getEndTime, update.getApplyStartTime()) |
| | | .set(ApplyDetail::getEditor, update.getEditor()) |
| | | .set(ApplyDetail::getEditDate, update.getEditDate()) |
| | | .eq(ApplyDetail::getId, oldModel.getApplyId()) |
| | | ); |
| | | totalFee.add(updateFee); |
| | | currentFee.add(updateCurrentFee); |
| | | |
| | | //修改 员工投保明细记录 历史数据 |
| | | memberInsuranceJoinMapper.update(null, new UpdateWrapper<MemberInsurance>().lambda() |
| | | .setSql(" fee = ifnull(fee,0)+" + updateFee) |
| | | .set(MemberInsurance::getEndTime, update.getApplyStartTime()) |
| | | .eq(MemberInsurance::getRelationId, oldModel.getId()) |
| | | ); |
| | | |
| | | } |
| | | addList.add(add); |
| | | totalFee.add(add.getFee()); |
| | | currentFee.add(add.getCurrentFee()); |
| | | }else{ |
| | | //减保操作 |
| | | //查询员工是在主单下 是否存在生效中的数据 |
| | | ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda() |
| | | .eq(ApplyDetail::getApplyId, update.getApplyId()) |
| | | .eq(ApplyDetail::getMemberId, detail.getMemberId()) |
| | | .orderByDesc(ApplyDetail::getCreateDate) |
| | | .last("limit 1")); |
| | | if(oldModel == null || oldModel.getStartTime()==null || oldModel.getStartTime().getTime() > update.getApplyStartTime().getTime()){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,用户【"+detail.getMemberName()+"】原保单信息有误,当前申请不支持减保处理!"); |
| | | } |
| | | BigDecimal updateFee = (Constants.countDetailFee(detail.getSolutionTimeUnit(),detail.getSolutionPrice(), oldModel.getStartTime(),update.getApplyStartTime())); |
| | | BigDecimal updateCurrentFee = new BigDecimal(0); |
| | | if(DateUtil.daysBetweenDates(update.getApplyStartTime(),new Date() )>0){ |
| | | //如果生效时间 是今天之前,退回已产生费用,计算已产生费用(总费用-已产生费用) |
| | | updateCurrentFee = updateFee.subtract(Constants.formatBigdecimal(oldModel.getCurrentFee())); |
| | | } |
| | | applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda() |
| | | .setSql(" fee = ifnull(fee,0)+"+updateFee) |
| | | .setSql(" current_fee = "+updateFee) |
| | | .set(ApplyDetail::getEditor,update.getEditor()) |
| | | .set(ApplyDetail::getEditDate,update.getEditDate()) |
| | | .eq(ApplyDetail::getId,oldModel.getApplyId()) |
| | | } |
| | | |
| | | if (memberInsuranceList != null && memberInsuranceList.size() > 0) { |
| | | // applyDetailJoinMapper.insertBatchSomeColumn(addList); |
| | | memberInsuranceJoinMapper.insertBatchSomeColumn(memberInsuranceList); |
| | | } |
| | | if (totalFee.compareTo(new BigDecimal(0)) != 0) { |
| | | //如果保单金额发生编码,更新总保单金额 |
| | | insuranceApplyMapper.update(null, new UpdateWrapper<InsuranceApply>().lambda() |
| | | .setSql(" fee = ifnull(fee,0)+" + totalFee) |
| | | .setSql(" current_fee = ifnull(current_fee,0)+" + currentFee) |
| | | .set(InsuranceApply::getEditor, update.getEditor()) |
| | | .set(InsuranceApply::getEditDate, update.getEditDate()) |
| | | .eq(InsuranceApply::getId, update.getApplyId()) |
| | | ); |
| | | totalFee.add(updateFee); |
| | | currentFee.add(updateCurrentFee); |
| | | |
| | | } |
| | | } |
| | | if(addList!=null && addList.size()>0){ |
| | | applyDetailJoinMapper.insertBatchSomeColumn(addList); |
| | | } |
| | | if(totalFee.compareTo(new BigDecimal(0)) != 0){ |
| | | //如果保单金额发生编码,更新总保单金额 |
| | | insuranceApplyMapper.update(null, new UpdateWrapper<InsuranceApply>().lambda() |
| | | .setSql(" fee = ifnull(fee,0)+"+totalFee) |
| | | .setSql(" current_fee = ifnull(current_fee,0)+"+currentFee) |
| | | .set(InsuranceApply::getEditor,update.getEditor()) |
| | | .set(InsuranceApply::getEditDate,update.getEditDate()) |
| | | .eq(InsuranceApply::getId,update.getApplyId()) |
| | | ); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); |
| | | } |
| | | |
| | | |
| | | applyChange.setEditDate(new Date()); |
| | | applyChange.setEditor(loginUserInfo.getId()); |
| | | applyChange.setStatus(Constants.ZERO); |
| | | BigDecimal fee = BigDecimal.ZERO; |
| | | //删除历史数据 |
| | | applyChagneDetailJoinMapper.delete(new QueryWrapper<ApplyChagneDetail>().lambda().eq(ApplyChagneDetail::getApplyChangeId,applyChange.getId())); |
| | | |
| | | this.dealApplyChangeData(applyChange,insuranceApply,companySolution,solutions,loginUserInfo,fee); |
| | | applyChange.setFee(fee); |
| | | applyChangeMapper.updateById(applyChange); |
| | |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "数据异常:保险方案下未查询到工种信息"); |
| | | } |
| | | |
| | | ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO = new ApplyChangeCyclePriceDTO(); |
| | | applyChangeCyclePriceDTO.setApplyId(insuranceApply.getId()); |
| | | //加保数据 |
| | | List<ApplyChagneDetail> addDetailList = applyChange.getAddDetailList(); |
| | | if (CollectionUtils.isNotEmpty(addDetailList)) { |
| | | if(companySolution.getCanAdd().equals(Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "该企业分配保险方案无法进行加保"); |
| | | } |
| | | this.addChangeDetail(applyChange,addDetailList,duWorktypeList,duSolutionList,insuranceApply,solutions,loginUserInfo); |
| | | //加保明细数据 计算金额 根据批单时间 计算 |
| | | applyChangeCyclePriceDTO.setValidTime(DateUtil.getMontageDate(insuranceApply.getStartTime(),1)); |
| | | CountCyclePriceVO countCyclePriceVO = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO); |
| | | BigDecimal detailFee = countCyclePriceVO.getCyclePrice(); |
| | | |
| | | this.addChangeDetail(applyChange,addDetailList,duWorktypeList,duSolutionList,insuranceApply,solutions,loginUserInfo,detailFee); |
| | | |
| | | fee = addDetailList.stream().map(ApplyChagneDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | } |
| | |
| | | if(companySolution.getCanReduce().equals(Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "该企业分配保险方案无法进行减保"); |
| | | } |
| | | this.delChangeDetail(applyChange,delDetailList,insuranceApply,solutions,loginUserInfo); |
| | | //减保明细数据 计算金额 根据批单时间 前一天 计算 |
| | | applyChangeCyclePriceDTO.setValidTime(DateUtil.getMontageDate(insuranceApply.getStartTime(),3)); |
| | | CountCyclePriceVO countCyclePriceVO = this.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO); |
| | | BigDecimal detailFee = countCyclePriceVO.getCyclePrice(); |
| | | this.delChangeDetail(applyChange,delDetailList,insuranceApply,solutions,loginUserInfo,detailFee); |
| | | fee = fee.add(delDetailList.stream().map(ApplyChagneDetail::getFee).reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | } |
| | | |
| | |
| | | * @param delDetailList |
| | | * @param loginUserInfo |
| | | */ |
| | | public void delChangeDetail(ApplyChange applyChange ,List<ApplyChagneDetail> delDetailList,InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo){ |
| | | public void delChangeDetail(ApplyChange applyChange ,List<ApplyChagneDetail> delDetailList,InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal detailFee){ |
| | | for (ApplyChagneDetail applyChagneDetail : delDetailList) { |
| | | if (Objects.isNull(applyChagneDetail.getMemberId())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "减保人员【" + applyChagneDetail.getMemberName() + "】必填项缺失"); |
| | |
| | | applyChagneDetail.setApplyChangeId(applyChange.getId()); |
| | | applyChagneDetail.setType(Constants.ONE); |
| | | |
| | | System.out.println(DateUtil.dateToString(applyDetail.getEndTime(),"yyyy-MM-dd")); |
| | | System.out.println(DateUtil.dateToString(applyDetail.getStartTime(),"yyyy-MM-dd")); |
| | | System.out.println(DateUtil.dateToString(applyChange.getValidTime(),"yyyy-MM-dd")); |
| | | applyChagneDetail.setStartTime(DateUtil.getMontageDate(applyDetail.getStartTime(),1)); |
| | | applyChagneDetail.setEndTime(DateUtil.getMontageDate(applyChange.getStartTime(),3)); |
| | | |
| | | BigDecimal sumFee = Constants.countDetailFee(solutions, applyDetail.getEndTime(),applyDetail.getStartTime()); |
| | | BigDecimal useFee = Constants.countDetailFee(solutions, applyChange.getValidTime(),applyDetail.getStartTime()); |
| | | |
| | | applyChagneDetail.setFee( |
| | | Constants.countDetailFee(solutions, applyDetail.getEndTime(),applyDetail.getStartTime()) |
| | | .subtract(Constants.countDetailFee(solutions,applyChange.getValidTime(), applyDetail.getStartTime())).multiply(new BigDecimal(-1)) |
| | | ); |
| | | applyChagneDetail.setFee( detailFee.multiply(new BigDecimal(-1))); |
| | | applyChagneDetailJoinMapper.insert(applyChagneDetail); |
| | | } |
| | | } |
| | |
| | | * @param duSolutionList |
| | | * @param loginUserInfo |
| | | */ |
| | | public void addChangeDetail(ApplyChange applyChange ,List<ApplyChagneDetail> addDetailList,List<DuWorktype> duWorktypeList,List<DuSolution> duSolutionList,InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo){ |
| | | public void addChangeDetail(ApplyChange applyChange ,List<ApplyChagneDetail> addDetailList,List<DuWorktype> duWorktypeList,List<DuSolution> duSolutionList,InsuranceApply insuranceApply,Solutions solutions,LoginUserInfo loginUserInfo,BigDecimal detailFee){ |
| | | for (ApplyChagneDetail applyChagneDetail : addDetailList) { |
| | | if ( Objects.isNull(applyChagneDetail.getDuId()) |
| | | || Objects.isNull(applyChagneDetail.getWorktypeId()) |
| | |
| | | ) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "加保人员【" + applyChagneDetail.getMemberName() + "】必填项缺失"); |
| | | } |
| | | |
| | | |
| | | Member member = new Member(); |
| | | if(Objects.isNull(applyChagneDetail.getMemberId())){ |
| | |
| | | applyChagneDetail.setCreator(loginUserInfo.getId()); |
| | | applyChagneDetail.setIsdeleted(Constants.ZERO); |
| | | applyChagneDetail.setApplyChangeId(applyChange.getId()); |
| | | applyChagneDetail.setStartTime(DateUtil.getMontageDate(applyChange.getStartTime(),1)); |
| | | applyChagneDetail.setEndTime(DateUtil.getMontageDate(insuranceApply.getEndTime(),2)); |
| | | applyChagneDetail.setType(Constants.ZERO); |
| | | applyChagneDetail.setFee( |
| | | Constants.countDetailFee(solutions,insuranceApply.getEndTime(),applyChange.getValidTime()) |
| | | ); |
| | | applyChagneDetail.setFee(detailFee); |
| | | applyChagneDetailJoinMapper.insert(applyChagneDetail); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 加减保申请时 查询加减金额 |
| | | * @param applyChangeCyclePriceDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public CountCyclePriceVO getChangeCountCyclePriceVO(ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO){ |
| | | if(Objects.isNull(applyChangeCyclePriceDTO) |
| | |
| | | || Objects.isNull(applyChangeCyclePriceDTO.getValidTime())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | InsuranceApply insuranceApply = insuranceApplyMapper.selectById(applyChangeCyclePriceDTO.getApplyId()); |
| | | if(Objects.isNull(insuranceApply)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到保单"); |
| | |
| | | if(Objects.isNull(solutions)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息"); |
| | | } |
| | | CountCyclePriceVO countCyclePriceVO = new CountCyclePriceVO(); |
| | | countCyclePriceVO.setCyclePrice(Constants.countDetailFee(solutions,insuranceApply.getEndTime(),applyChangeCyclePriceDTO.getValidTime())); |
| | | return countCyclePriceVO; |
| | | //根据批单日期 和 结束日期 计算金额 |
| | | //验证批单日期是否在当前日期后 且 在保单结束日期前 申请时间必须处于保单的时间范围内 |
| | | if (!(DateUtil.compareDate( insuranceApply.getStartTime(),applyChangeCyclePriceDTO.getValidTime()) >= Constants.ZERO |
| | | && DateUtil.compareDate( applyChangeCyclePriceDTO.getValidTime(),insuranceApply.getEndTime()) >= Constants.ZERO)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "申请日期未处于保单日期内,无法进行该操作"); |
| | | } |
| | | //总天数 |
| | | Integer sumDays = DateUtil.daysBetweenDates(insuranceApply.getEndTime(),insuranceApply.getStartTime()) + 1; |
| | | //加减保 到结束的天数 |
| | | Integer optDays = DateUtil.daysBetweenDates(insuranceApply.getEndTime(),applyChangeCyclePriceDTO.getValidTime()) + 1; |
| | | |
| | | CountCyclePriceVO countCyclePriceVO = Constants.countPriceVO(insuranceApply.getStartTime(),solutions); |
| | | //总金额 |
| | | BigDecimal sumPrice = countCyclePriceVO.getCyclePrice(); |
| | | CountCyclePriceVO returnCountCyclePriceVO = new CountCyclePriceVO(); |
| | | //加减保金额 |
| | | returnCountCyclePriceVO.setCyclePrice(sumPrice.divide(new BigDecimal(sumDays),2, RoundingMode.HALF_UP).multiply(new BigDecimal(optDays))); |
| | | return returnCountCyclePriceVO; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 计算保单下 X天 多少费用 |
| | | * @param applyId |
| | | * @param optDays |
| | | * @return |
| | | */ |
| | | public BigDecimal getApplyPrice(Integer applyId,Integer optDays){ |
| | | InsuranceApply insuranceApply = insuranceApplyMapper.selectById(applyId); |
| | | if(Objects.isNull(insuranceApply)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到保单"); |
| | | } |
| | | Solutions solutions = solutionsMapper.selectById(insuranceApply.getSolutionId()); |
| | | if(Objects.isNull(solutions)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息"); |
| | | } |
| | | //总天数 |
| | | Integer sumDays = DateUtil.daysBetweenDates(insuranceApply.getEndTime(),insuranceApply.getStartTime()) + 1; |
| | | CountCyclePriceVO countCyclePriceVO = Constants.countPriceVO(insuranceApply.getStartTime(),solutions); |
| | | //总金额 |
| | | BigDecimal sumPrice = countCyclePriceVO.getCyclePrice();; |
| | | return sumPrice.divide(new BigDecimal(sumDays),2, RoundingMode.HALF_UP).multiply(new BigDecimal(optDays)); |
| | | } |
| | | |
| | | } |