jiangping
2024-12-27 5506edbe54883b31db3cc8e4a1d9d0795a18a3c9
server/service/src/main/java/com/doumee/service/business/impl/MemberServiceImpl.java
@@ -21,6 +21,7 @@
import com.doumee.dao.business.join.ApplyDetailJoinMapper;
import com.doumee.dao.business.join.DispatchUnitJoinMapper;
import com.doumee.dao.business.join.MemberJoinMapper;
import com.doumee.dao.business.join.SolutionWorktypeJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.MemberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -67,6 +68,8 @@
    private SolutionsMapper solutionsMapper;
    @Autowired
    private InsuranceApplyMapper insuranceApplyMapper;
    @Autowired
    private SolutionWorktypeJoinMapper solutionWorktypeJoinMapper;
    @Override
    public Integer create(Member member) {
@@ -356,8 +359,10 @@
//                Date  reduceEndTime = DateUtil.getMontageDate(new Date(),3);
                for (Member member:memberList) {
                    //如果当前日期 小于 人员保单明细记录的开始时间 则使用开始日期  开始日期 = 结束日期  且 费用全部退回
                    if(System.currentTimeMillis()<=member.getStartTime().getTime()){
                        member.setFee(solutions.getPrice().multiply(new BigDecimal(-1)));
//                    if(System.currentTimeMillis()<=member.getStartTime().getTime()){
//                        member.setFee(solutions.getPrice().multiply(new BigDecimal(-1)));
                    if(System.currentTimeMillis()<=member.getDetailStartTime().getTime()){
                            member.setFee(member.getFee().multiply(new BigDecimal(-1)));
                    }else{
                        Date  reduceEndTime = DateUtil.getMontageDate(
                            DateUtil.afterDateByType(new Date(),0,solutions.getDelValidDays()),3);
@@ -501,6 +506,13 @@
        if(!loginUserInfo.getType().equals(Constants.ONE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非企业人员无法进行该操作");
        }
        if(Objects.isNull(solutionId)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"参数错误 - 方案信息");
        }
        Solutions solutions = solutionsMapper.selectById(solutionId);
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到方案信息");
        }
        ExcelImporter ie = null;
        List<MemberImport> dataList =null;
        try {
@@ -516,13 +528,16 @@
        Map<String,String> idCardMap = new HashMap<>();
        for(MemberImport model : dataList){
            //校验参数是否合法
            validImportParam(model,idCardMap,dataList,index,solutionId);
            validImportParam(model,idCardMap,dataList,index,solutions);
            index += 1;
        }
        List<DispatchUnit> dispatchUnitList    = dispatchUnitJoinMapper.selectJoinList(DispatchUnit.class,
        List<DispatchUnit> dispatchUnitList = new ArrayList<>();
        List<SolutionWorktype> solutionWorktypeList = new ArrayList<>();
        //2024年11月6日15:39:10 加入 根据方案是否有保险方案进行判断
        if(Constants.equalsInteger(solutions.getHasDispatchUnit(),Constants.ZERO)){
            dispatchUnitList    = dispatchUnitJoinMapper.selectJoinList(DispatchUnit.class,
                    new MPJLambdaWrapper<DispatchUnit>()
                            .selectAll(DispatchUnit.class)
//                            .select("(select b.id from du_solution b where b.isdeleted=0 and b.dispatch_unit_id=t.id and b.solution_id="+solutionId+" limit 1) as du_solution_id" )
                            .select("(select b.id from du_solution b where b.isdeleted=0 and b.dispatch_unit_id=t.id and b.solution_id="+solutionId+"  order by b.CHECK_DATE desc  limit 1) as du_solution_id" )
                            .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
                            .eq(DispatchUnit::getStatus,Constants.ZERO)
@@ -542,28 +557,34 @@
                dispatchUnit.setWorktypeList(worktypeList);
            }
        }
        }else{
            //方案不选择派遣单位情况下的业务
            solutionWorktypeList = solutionWorktypeJoinMapper.selectJoinList(SolutionWorktype.class,
                    new MPJLambdaWrapper<SolutionWorktype>()
                            .selectAll(SolutionWorktype.class)
                            .selectAs(Worktype::getName,SolutionWorktype::getWorktypeName)
                            .leftJoin(Worktype.class,Worktype::getId,SolutionWorktype::getWorktypeId)
                            .eq(SolutionWorktype::getSolutionId,solutions.getId())
            );
            if(CollectionUtils.isEmpty(solutionWorktypeList)){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,保险方案下未查询到工种信息");
            }
        }
        index = Constants.TWO;
        for(MemberImport model : dataList){
            //校验人员是否已经在参保中
            isMemberValidForSolution(model,index,solutionId);
            //检查派遣单位和工种有效性
            dealDuAndWorktype(model,index,dispatchUnitList);
            dealDuAndWorktype(model,index,dispatchUnitList,solutions,solutionWorktypeList);
            index += 1;
            model.setSex(Constants.getSexByIdCard(model.getIdCard()));
        }
        return dataList;
    }
    private void isMemberValidForSolution(MemberImport model, int index, Integer solutionId) {
       /* ApplyDetail detail = applyDetailJoinMapper.selectJoinOne(ApplyDetail.class,new MPJLambdaWrapper<ApplyDetail>()
                .last("limit 1"));
        if(detail!=null){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行身份证为【"+model.getIdCard()+"】人员已经在该方案下存在投保记录!");
        }*/
    }
    private void dealDuAndWorktype(MemberImport model, int index, List<DispatchUnit> dispatchUnitList  ) {
    private void dealDuAndWorktype(MemberImport model, int index, List<DispatchUnit> dispatchUnitList , Solutions  solutions,List<SolutionWorktype> solutionWorktypeList) {
        //2024年11月6日15:39:10 加入 根据方案是否有保险方案进行判断
        if(Constants.equalsInteger(solutions.getHasDispatchUnit(),Constants.ZERO)){
        if(CollectionUtils.isNotEmpty(dispatchUnitList)){
            Optional<DispatchUnit>  dispatchUnitOptional= dispatchUnitList.stream().filter(m->m.getName().equals(model.getDuName())).findFirst();
            if(dispatchUnitOptional.isPresent()){
@@ -581,21 +602,32 @@
        if(Objects.isNull(model.getDuId())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据派遣单位【"+model.getDuName()+"】不正确!");
        }
        }else{
            Optional<SolutionWorktype>  worktypeOptional= solutionWorktypeList.stream().filter(m->m.getWorktypeName().replaceAll(" ","")
                    .equals(model.getWorkTypeName().replaceAll(" ",""))).findFirst();
            if(worktypeOptional.isPresent()){
                SolutionWorktype worktype = worktypeOptional.get();
                model.setWorktypeId(worktype.getId());
            }
        }
        if(Objects.isNull(model.getWorktypeId())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据工种【"+model.getWorkTypeName()+"】不正确!");
        }
    }
    private void validImportParam(MemberImport model, Map<String, String> idCardMap, List<MemberImport> dataList,int index,Integer solutionId) {
    private void validImportParam(MemberImport model, Map<String, String> idCardMap, List<MemberImport> dataList,int index,Solutions solutions) {
        if(StringUtils.isBlank(model.getName())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据姓名不能为空!");
        }
        if(StringUtils.isBlank(model.getIdCard())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据身份证号不能为空!");
        }
        //2024年11月6日15:39:10 加入 根据方案是否有保险方案进行判断
        if(Constants.equalsInteger(solutions.getHasDispatchUnit(),Constants.ZERO)){
        if(StringUtils.isBlank(model.getDuName())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据派遣单位不能为空!");
        }
        }
        if(StringUtils.isBlank(model.getWorkTypeName())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+index+"行数据工种不能为空!");
        }