|  |  |  | 
|---|
|  |  |  | .selectAs(Solutions::getSpecialAgreement,UnionApply::getSpecialAgreement) | 
|---|
|  |  |  | .selectAs(Solutions::getSpecialInfo,UnionApply::getSpecialInfo); | 
|---|
|  |  |  | queryWrapper.select("(select count(distinct(b.MEMBER_ID)) from apply_detail b where b.isdeleted=0 and b.union_apply_id=t.id) as insureNum "); | 
|---|
|  |  |  | queryWrapper.select(" ( select count(DISTINCT(b.MEMBER_ID)) from apply_detail b inner join insurance_apply a on b.apply_id = a.id  and a.status in ( 5 , 27 )  where b.union_apply_id=t.id and b.END_TIME > now() ) as guaranteeNum"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(pageWrap.getModel().getQueryFlag() == 1){ | 
|---|
|  |  |  | queryWrapper.select("(select count(1) from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id=t.id " + | 
|---|
|  |  |  | "and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 0  ) as addApplyNum "); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else  if(pageWrap.getModel().getQueryFlag() ==2){ | 
|---|
|  |  |  | queryWrapper.select("(select count(1) from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id=t.id " + | 
|---|
|  |  |  | "and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 1  ) as changeApplyNum "); | 
|---|
|  |  |  | 
|---|
|  |  |  | if(Constants.equalsInteger(user.getType(),Constants.TWO)){ | 
|---|
|  |  |  | queryWrapper.eq(UnionApply::getCompanyId, user.getCompanyId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(UnionApply::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getSolutionId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(UnionApply::getSolutionId, pageWrap.getModel().getSolutionId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getHasApplying() != null) { | 
|---|
|  |  |  | if(Constants.equalsInteger(pageWrap.getModel().getHasApplying() ,Constants.ONE)){ | 
|---|
|  |  |  | queryWrapper.exists( | 
|---|
|  |  |  | " ( select 1  from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id= t.id " + | 
|---|
|  |  |  | "        and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 0  ) " | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }else if(Constants.equalsInteger(pageWrap.getModel().getHasApplying() ,Constants.TWO)){ | 
|---|
|  |  |  | queryWrapper.exists( | 
|---|
|  |  |  | " ( select 1  from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id= t.id " + | 
|---|
|  |  |  | "        and a.status = "+Constants.ApplyChangeStatus.CHECHED_PASSED.getKey()+" and a.type = 1   ) " | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreator() != null) { | 
|---|
|  |  |  | queryWrapper.eq(UnionApply::getCreator, pageWrap.getModel().getCreator()); | 
|---|
|  |  |  | 
|---|
|  |  |  | new MPJLambdaWrapper<UnionApply>() | 
|---|
|  |  |  | .selectAll(UnionApply.class) | 
|---|
|  |  |  | .selectAs(Solutions::getName,UnionApply::getSolutionName) | 
|---|
|  |  |  | .selectAs(Solutions::getDelOnlyReplace,UnionApply::getDelOnlyReplace) | 
|---|
|  |  |  | .selectAs(Company::getName,UnionApply::getCompanyName) | 
|---|
|  |  |  | .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.UNION_APPLY_ID = t.id ) as insureNum") | 
|---|
|  |  |  | .select(" ( select count(DISTINCT(b.MEMBER_ID)) from apply_detail b inner join insurance_apply a on b.apply_id = a.id  and a.status in ( 5 , 27 )  where b.union_apply_id=t.id and b.END_TIME > now() ) as guaranteeNum") | 
|---|
|  |  |  | .select(" ( select group_concat(DISTINCT(cd.name)) from insurance_apply ad left join company cd on ad.company_id = cd.id where ad.UNION_APPLY_ID = t.id ) as companyNames") | 
|---|
|  |  |  | .leftJoin(Solutions.class,Solutions::getId,UnionApply::getSolutionId) | 
|---|
|  |  |  | .leftJoin(Company.class,Company::getId,UnionApply::getCompanyId) | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer maxDays = DateUtil.calculateBetween(saveUnionApplyDTO.getStartDate(),saveUnionApplyDTO.getEndDate(),0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda() | 
|---|
|  |  |  | List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,new MPJLambdaWrapper<ApplyDetail>() | 
|---|
|  |  |  | .select(ApplyDetail::getId,ApplyDetail::getPrice,ApplyDetail::getStartTime,ApplyDetail::getEndTime,ApplyDetail::getFee) | 
|---|
|  |  |  | .selectAs(Member::getIdcardNo,ApplyDetail::getIdcardNo) | 
|---|
|  |  |  | .selectAs(Member::getName,ApplyDetail::getMemberName) | 
|---|
|  |  |  | .leftJoin(Member.class,Member::getId,ApplyDetail::getMemberId) | 
|---|
|  |  |  | .in(ApplyDetail::getApplyId,saveUnionApplyDTO.getApplyIds()) | 
|---|
|  |  |  | .eq(ApplyDetail::getIsdeleted,Constants.ZERO)); | 
|---|
|  |  |  | if(applyDetailList.size()==0){ | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BigDecimal fee = BigDecimal.ZERO; | 
|---|
|  |  |  | for (ApplyDetail applyDetail:applyDetailList) { | 
|---|
|  |  |  | //查询人员信息是否存在相同的方案下是否存在 冲突数据 | 
|---|
|  |  |  | InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getBaseId(), | 
|---|
|  |  |  | applyDetail.getIdcardNo(),applyDetail.getMemberName(),unionApply.getStartTime(),unionApply.getEndTime(), | 
|---|
|  |  |  | applyDetailJoinMapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | fee =fee.add( | 
|---|
|  |  |  | Constants.reduceFee(solutions,solutions.getPrice(),applyDetail.getStartTime(),applyDetail.getEndTime(),saveUnionApplyDTO.getStartDate(),saveUnionApplyDTO.getEndDate()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | unionApply.setFee(fee); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        unionApply.setFee(applyDetailList.stream() | 
|---|
|  |  |  | //                .map(i->Constants.formatBigdecimal(i.getPrice()).multiply(new BigDecimal(maxDays))).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | unionApplyMapper.insert(unionApply); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | List<MemberInsurance> memberInsuranceList = new ArrayList<>(); | 
|---|
|  |  |  | for (ApplyDetail applyDetail:applyDetailList.stream() | 
|---|
|  |  |  | .filter(m->Constants.equalsInteger(m.getApplyId(),(insuranceApply.getId()))).collect(Collectors.toList())) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询人员信息是否存在相同的方案下是否存在 冲突数据 | 
|---|
|  |  |  | InsuranceApplyServiceImpl.checkStaticMemberSolution(solutions.getBaseId(), | 
|---|
|  |  |  | applyDetail.getIdcardNo(),applyDetail.getMemberName(),unionApply.getStartTime(),unionApply.getEndTime(), | 
|---|
|  |  |  | applyDetailJoinMapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | applyDetail.setPrice(price); | 
|---|
|  |  |  | applyDetail.setFee(price.multiply(new BigDecimal(maxDays)).add(serverCost)); | 
|---|
|  |  |  | applyDetail.setStartTime(unionApplyBXDDTO.getStartTime()); | 
|---|
|  |  |  | applyDetail.setEndTime(unionApplyBXDDTO.getEndTime()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MemberInsurance memberInsurance = new MemberInsurance(applyDetail,user.getId()); | 
|---|
|  |  |  | memberInsurance.setBdCode(unionApplyBXDDTO.getCode()); | 
|---|
|  |  |  | memberInsurance.setRelationType(Constants.ZERO); | 
|---|