jiangping
2024-06-20 09da100729793848bc01b51f7b05ca3f1e7ec64f
server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java
@@ -17,6 +17,7 @@
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;
@@ -685,6 +686,7 @@
                            .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());
@@ -703,12 +705,6 @@
                            .set( ApplyChagneDetail::getEndTime, delValidTime)
                            .eq(ApplyChagneDetail::getId,detail.getId())
                    );
//                if(1==1){
//                    throw new BusinessException(ResponseStatus.SERVER_ERROR);
//                }
            }
            member.setApplyId(update.getApplyId());
@@ -881,10 +877,10 @@
            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())
@@ -1002,10 +998,10 @@
            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())
@@ -1042,8 +1038,11 @@
    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)
@@ -1057,7 +1056,6 @@
        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()
@@ -1070,17 +1068,15 @@
        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);
@@ -1104,9 +1100,7 @@
        //减保数据
        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);
@@ -1121,11 +1115,7 @@
            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();
@@ -1222,9 +1212,10 @@
            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());
@@ -1235,6 +1226,8 @@
            //查询减保日期
//            Integer delDays = DateUtil.daysBetweenDates(applyDetail.getEndTime(),endTime);
//            ;
            //查询周期数量
            applyChagneDetail.setFee(
                    Constants.reduceFee(solutions,
                                    Objects.isNull(insuranceApply.getServerCost())?
@@ -1244,6 +1237,11 @@
                                    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);
        }
    }
@@ -2144,10 +2142,10 @@
        }
        //根据批单日期 和 结束日期 计算金额
        //验证批单日期是否在当前日期后 且 在保单结束日期前 申请时间必须处于保单的时间范围内
        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,