package com.ydtech.modules.scheme.service.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ydtech.constants.enums.dict.agreement.ProductsType; import com.ydtech.exception.SystemException; import com.ydtech.modules.esm.model.EsmInsCompany; import com.ydtech.modules.ins.model.vo.KindInfoVo; import com.ydtech.modules.order.entity.InsBusinessInsurance; import com.ydtech.modules.order.entity.InsBusinessInsuranceOption; import com.ydtech.modules.order.entity.InsDrivingIntentionInsuranceType; import com.ydtech.modules.order.service.InsBusinessInsuranceService; import com.ydtech.modules.order.service.InsDrivingIntentionInsuranceService; import com.ydtech.modules.order.service.InsDrivingIntentionInsuranceTypeService; import com.ydtech.modules.scheme.dao.PtlOptionalSchemeMapper; import com.ydtech.modules.scheme.dao.PtlSchemeMapper; import com.ydtech.modules.scheme.entity.po.*; import com.ydtech.modules.scheme.entity.vo.*; import com.ydtech.modules.scheme.service.*; import com.ydtech.utils.idgen.IdGenerate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; /** * @description 自选方案 service实现类 * @createDate 2024-7-30 10:18:19 * @Entity */ @Service public class PtlOptionalSchemeServiceImpl extends ServiceImpl implements PtlOptionalSchemeService { @Autowired private PtlOptionalSchemeInsuranceService ptlOptionalSchemeInsuranceService; @Autowired private PtlOptionalSchemeInsuranceDrivingIntentionService ptlOptionalSchemeInsuranceDrivingIntentionService; @Autowired private InsBusinessInsuranceService insBusinessInsuranceService; @Autowired private PtlSchemeInsuranceService ptlSchemeInsuranceService; @Autowired InsDrivingIntentionInsuranceTypeService insDrivingIntentionInsuranceTypeService; @Autowired InsDrivingIntentionInsuranceService insDrivingIntentionInsuranceService; @Override @Transactional public boolean addOptionScheme(OptionalSchemeSaveVo optionalSchemeSaveVo) { PtlOptionalScheme optionalScheme = optionalSchemeSaveVo.getOptionSchemeObject(); this.save(optionalScheme); List optionsSchemeKindsList = optionalSchemeSaveVo.getOptionsSchemeKindsList(optionalScheme.getId()); ptlOptionalSchemeInsuranceService.saveBatch(optionsSchemeKindsList); List optionsSchemeInsruanceDrvingIntentionList = optionalSchemeSaveVo.getOptionsSchemeInsruanceDrvingIntentionList(optionalScheme.getId()); ptlOptionalSchemeInsuranceDrivingIntentionService.saveBatch(optionsSchemeInsruanceDrvingIntentionList); return true; } /** * 更新自选方案 * @param optionalSchemeSaveVo * @return */ @Override public boolean updateOptionScheme(OptionalSchemeSaveVo optionalSchemeSaveVo) { PtlOptionalScheme optionalScheme = optionalSchemeSaveVo.getOptionSchemeObject(); this.updateById(optionalScheme); ptlOptionalSchemeInsuranceService.remove(new LambdaQueryWrapper() .eq(PtlOptionalSchemeInsurance::getSchemeId,optionalScheme.getId())); if(!optionalSchemeSaveVo.getProductId().equals(ProductsType.PT_0330.getCode())) { List optionsSchemeKindsList = optionalSchemeSaveVo.getOptionsSchemeKindsList(optionalScheme.getId()); ptlOptionalSchemeInsuranceService.saveBatch(optionsSchemeKindsList); } ptlOptionalSchemeInsuranceDrivingIntentionService.remove(new LambdaQueryWrapper() .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,optionalScheme.getId())); List optionsSchemeInsruanceDrvingIntentionList = optionalSchemeSaveVo.getOptionsSchemeInsruanceDrvingIntentionList(optionalScheme.getId()); ptlOptionalSchemeInsuranceDrivingIntentionService.saveBatch(optionsSchemeInsruanceDrvingIntentionList); return true; } @Override @Transactional public boolean deleteOptionScheme(String id) { PtlOptionalScheme byId = this.getById(id); if(Objects.isNull(byId)){ throw new SystemException("找不到自选方案"); } this.removeById(id); ptlOptionalSchemeInsuranceService.remove(new LambdaQueryWrapper() .eq(PtlOptionalSchemeInsurance::getSchemeId,id)); ptlOptionalSchemeInsuranceDrivingIntentionService.remove(new LambdaQueryWrapper() .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,id)); return true; } /** * 自选方案详情 * @param companyId * @param productId * @return */ @Override public OptionalSchemeSaveVo optionalSchemeInfo(String companyId, String productId,String carnature, String vehicleType, String energyType) { OptionalSchemeSaveVo optionalSchemeSaveVo = new OptionalSchemeSaveVo(); PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper() .eq(PtlOptionalScheme::getCompanyId,companyId) .eq(PtlOptionalScheme::getProductId,productId) .eq(PtlOptionalScheme::getCarnature,carnature) .eq(PtlOptionalScheme::getVehicleType,vehicleType) .eq(PtlOptionalScheme::getEnergyType,energyType)); optionalSchemeSaveVo.setId(optionalScheme.getId()); optionalSchemeSaveVo.setCompanyId(companyId); optionalSchemeSaveVo.setSchemeName(optionalScheme.getSchemeName()); optionalSchemeSaveVo.setProductName(optionalScheme.getProductName()); optionalSchemeSaveVo.setProductId(optionalScheme.getProductId()); optionalSchemeSaveVo.setDescription(optionalScheme.getDescription()); List kinds = new ArrayList<>(); //遍历全部options List businessInsurance = insBusinessInsuranceService.getBusinessInsurance(); List list = ptlOptionalSchemeInsuranceService.list(new LambdaQueryWrapper() .eq(PtlOptionalSchemeInsurance::getSchemeId, optionalScheme.getId())); businessInsurance.forEach(item->{ item.setAmountDesc("不投保"); OptionalSchemeSaveVo.OptionsSchemeKinds kind = new OptionalSchemeSaveVo.OptionsSchemeKinds(); kind.setId(item.getId()); kind.setKindCode(item.getKindCode()); kind.setKindName(item.getKindName()); List collect = list.stream().filter(x -> x.getInsuranceId().equals(item.getId())).collect(Collectors.toList()); kind.setAmtList(item.getAmtList()); kind.setAmount(list.stream().filter(x->x.getInsuranceId().equals(item.getId())).map(x->x.getOptionId()).collect(Collectors.toList())); if(kind.getKindCode().equals("TY2") || kind.getKindCode().equals("TY3") || kind.getKindCode().equals("TY4")){ if(!collect.isEmpty() && collect.get(0).getMax() != 0){ kind.setMax(collect.get(0).getMax().toString()); } } kinds.add(kind); }); optionalSchemeSaveVo.setKinds(kinds); //驾意险 List drivingIntentions = ptlOptionalSchemeInsuranceDrivingIntentionService.list(new LambdaQueryWrapper() .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,optionalScheme.getId())); List collect = new ArrayList<>(); Map> maps = new HashMap<>(); if(drivingIntentions.size() > 0){ maps = drivingIntentions.stream().collect(Collectors.groupingBy(PtlOptionalSchemeInsuranceDrivingIntention::getSeatNum)); } for (Map.Entry> entry : maps.entrySet()) { String seatNum = entry.getKey(); // 获取 SeatNum List intentions = entry.getValue(); // 获取对应的列表 OptionalSchemeSaveVo.OptionsSchemeInsurance insruance = new OptionalSchemeSaveVo.OptionsSchemeInsurance(); List isOptions = new ArrayList<>(); for (PtlOptionalSchemeInsuranceDrivingIntention x : intentions) { OptionalSchemeSaveVo.OptionsSchemeInsurance.IsOptions isOption = new OptionalSchemeSaveVo.OptionsSchemeInsurance.IsOptions(); isOption.setAlias(x.getAlias()); isOption.setProjectName(x.getAlias()); isOption.setTitle(x.getTitle()); isOption.setId(x.getDrivingIntentionId()); isOption.setMinQuantity(x.getMinQuantity()); isOptions.add(isOption); } insruance.setSeatNum(seatNum); insruance.setIsOptions(isOptions); DrivingIntentionQueryVo drivingIntentionQueryVo = new DrivingIntentionQueryVo(); drivingIntentionQueryVo.setCompanyId(companyId); insruance.setUndrvingList(insDrivingIntentionInsuranceService.getSchemeDrivingIntentionInsurance(drivingIntentionQueryVo)); collect.add(insruance); } optionalSchemeSaveVo.setDrvingList(collect); return optionalSchemeSaveVo; } @Override public List getOptionalSchemeList(SchemeQueryVo schemeQueryVo) { return baseMapper.selectList(new LambdaQueryWrapper() .eq(PtlOptionalScheme::getCompanyId,schemeQueryVo.getCompanyId()) .eq(PtlOptionalScheme::getEnergyType,schemeQueryVo.getEnergyType()) .eq(PtlOptionalScheme::getVehicleType,schemeQueryVo.getVehicleType()) .eq(!Objects.isNull(schemeQueryVo.getCarnature()),PtlOptionalScheme::getCarnature,schemeQueryVo.getCarnature())); } @Override public CompanyOptionalSchemeVo getSchemeInsuranceInfo(SchemeQueryVo schemeQueryVo) { CompanyOptionalSchemeVo companyOptionalSchemeVo = new CompanyOptionalSchemeVo(); List schemeInsuranceInfo = ptlOptionalSchemeInsuranceService.getSchemeInsuranceInfo(schemeQueryVo); schemeInsuranceInfo.sort((o1, o2) -> Integer.compare(Integer.parseInt(o1.getId()), Integer.parseInt(o2.getId()))); PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper() .eq(PtlOptionalScheme::getCompanyId,schemeQueryVo.getCompanyId()) .eq(PtlOptionalScheme::getProductId,schemeQueryVo.getProductId()) .eq(PtlOptionalScheme::getVehicleType, schemeQueryVo.getVehicleType()) .eq(PtlOptionalScheme::getEnergyType, schemeQueryVo.getEnergyType()) .eq(PtlOptionalScheme::getCarnature, schemeQueryVo.getCarnature())); //险种信息 companyOptionalSchemeVo.setIsJq("0"); companyOptionalSchemeVo.setIsSy("0"); if(schemeQueryVo.getProductId().equals(ProductsType.PT_0330.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){ companyOptionalSchemeVo.setIsJq("1"); } if(schemeQueryVo.getProductId().equals(ProductsType.PT_034002.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_034001.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){ companyOptionalSchemeVo.setIsSy("1"); } if(Objects.isNull(optionalScheme)){ throw new SystemException("未找到自选方案"); } schemeInsuranceInfo.forEach(item->{ item.setAmountDesc("不投保"); }); companyOptionalSchemeVo.setSchemeId(optionalScheme.getId()); companyOptionalSchemeVo.setSchemeName(optionalScheme.getSchemeName()); companyOptionalSchemeVo.setKinds(schemeInsuranceInfo); List drivingIntentionInsuranceTypeByCompanyId = insDrivingIntentionInsuranceTypeService.getDrivingIntentionInsuranceTypeByCompanyId(schemeQueryVo.getCompanyId()); companyOptionalSchemeVo.setDrivingList(new ArrayList<>()); companyOptionalSchemeVo.setDrivingTypeList(drivingIntentionInsuranceTypeByCompanyId); return companyOptionalSchemeVo; } @Override public CompanyOptionalSchemeVo getPcSchemeInsuranceInfo(SchemeQueryVo schemeQueryVo) { CompanyOptionalSchemeVo companyOptionalSchemeVo = new CompanyOptionalSchemeVo(); List schemeInsuranceInfo = ptlOptionalSchemeInsuranceService.getSchemeInsuranceInfo(schemeQueryVo); schemeInsuranceInfo.sort((o1, o2) -> Integer.compare(Integer.parseInt(o1.getId()), Integer.parseInt(o2.getId()))); PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper() .eq(PtlOptionalScheme::getCompanyId,schemeQueryVo.getCompanyId()) .eq(PtlOptionalScheme::getProductId,schemeQueryVo.getProductId()) .eq(PtlOptionalScheme::getVehicleType, schemeQueryVo.getVehicleType()) .eq(PtlOptionalScheme::getEnergyType, schemeQueryVo.getEnergyType()) .eq(PtlOptionalScheme::getCarnature, schemeQueryVo.getCarnature())); //险种信息 companyOptionalSchemeVo.setIsJq("0"); companyOptionalSchemeVo.setIsSy("0"); if(schemeQueryVo.getProductId().equals(ProductsType.PT_0330.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){ companyOptionalSchemeVo.setIsJq("1"); } if(schemeQueryVo.getProductId().equals(ProductsType.PT_034002.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_034001.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) || schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){ companyOptionalSchemeVo.setIsSy("1"); } if(Objects.isNull(optionalScheme)){ return null; } schemeInsuranceInfo.forEach(item->{ item.setAmountDesc("不投保"); }); companyOptionalSchemeVo.setSchemeId(optionalScheme.getId()); companyOptionalSchemeVo.setSchemeName(optionalScheme.getSchemeName()); companyOptionalSchemeVo.setKinds(schemeInsuranceInfo); List drivingIntentionInsuranceTypeByCompanyId = insDrivingIntentionInsuranceTypeService.getDrivingIntentionInsuranceTypeByCompanyId(schemeQueryVo.getCompanyId()); companyOptionalSchemeVo.setDrivingList(new ArrayList<>()); companyOptionalSchemeVo.setDrivingTypeList(drivingIntentionInsuranceTypeByCompanyId); return companyOptionalSchemeVo; } /** * 获取保险公司投保指引 * @return */ @Override public String getCompanyInsGuide(String companyId,String productId,String carnature, String vehicleType, String energyType){ PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper() .eq(PtlOptionalScheme::getCompanyId,companyId) .eq(PtlOptionalScheme::getProductId,productId) .eq(PtlOptionalScheme::getVehicleType, vehicleType) .eq(PtlOptionalScheme::getEnergyType, energyType) .eq(PtlOptionalScheme::getCarnature, carnature)); if(Objects.isNull(optionalScheme)){ return ""; } return optionalScheme.getDescription(); } }