| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- 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.constants.enums.dict.insurance.EnergyType;
- 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<PtlOptionalSchemeMapper, PtlOptionalScheme>
- 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<PtlOptionalSchemeInsurance> optionsSchemeKindsList = optionalSchemeSaveVo.getOptionsSchemeKindsList(optionalScheme.getId());
- ptlOptionalSchemeInsuranceService.saveBatch(optionsSchemeKindsList);
- List<PtlOptionalSchemeInsuranceDrivingIntention> 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<PtlOptionalSchemeInsurance>()
- .eq(PtlOptionalSchemeInsurance::getSchemeId,optionalScheme.getId()));
- if(!optionalSchemeSaveVo.getProductId().equals(ProductsType.PT_0330.getCode())) {
- List<PtlOptionalSchemeInsurance> optionsSchemeKindsList = optionalSchemeSaveVo.getOptionsSchemeKindsList(optionalScheme.getId());
- ptlOptionalSchemeInsuranceService.saveBatch(optionsSchemeKindsList);
- }
- ptlOptionalSchemeInsuranceDrivingIntentionService.remove(new LambdaQueryWrapper<PtlOptionalSchemeInsuranceDrivingIntention>()
- .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,optionalScheme.getId()));
- List<PtlOptionalSchemeInsuranceDrivingIntention> 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<PtlOptionalSchemeInsurance>()
- .eq(PtlOptionalSchemeInsurance::getSchemeId,id));
- ptlOptionalSchemeInsuranceDrivingIntentionService.remove(new LambdaQueryWrapper<PtlOptionalSchemeInsuranceDrivingIntention>()
- .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<PtlOptionalScheme>()
- .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<OptionalSchemeSaveVo.OptionsSchemeKinds> kinds = new ArrayList<>();
- //遍历全部options
- List<InsBusinessInsurance> businessInsurance = insBusinessInsuranceService.getBusinessInsurance();
- List<PtlOptionalSchemeInsurance> list = ptlOptionalSchemeInsuranceService.list(new LambdaQueryWrapper<PtlOptionalSchemeInsurance>()
- .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<PtlOptionalSchemeInsurance> 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()));
- kinds.add(kind);
- });
- optionalSchemeSaveVo.setKinds(kinds);
- //驾意险
- List<PtlOptionalSchemeInsuranceDrivingIntention> drivingIntentions = ptlOptionalSchemeInsuranceDrivingIntentionService.list(new LambdaQueryWrapper<PtlOptionalSchemeInsuranceDrivingIntention>()
- .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,optionalScheme.getId()));
- List<OptionalSchemeSaveVo.OptionsSchemeInsurance> collect = new ArrayList<>();
- Map<String, List<PtlOptionalSchemeInsuranceDrivingIntention>> maps = new HashMap<>();
- if(drivingIntentions.size() > 0){
- maps = drivingIntentions.stream().collect(Collectors.groupingBy(PtlOptionalSchemeInsuranceDrivingIntention::getSeatNum));
- }
- for (Map.Entry<String, List<PtlOptionalSchemeInsuranceDrivingIntention>> entry : maps.entrySet()) {
- String seatNum = entry.getKey(); // 获取 SeatNum
- List<PtlOptionalSchemeInsuranceDrivingIntention> intentions = entry.getValue(); // 获取对应的列表
- OptionalSchemeSaveVo.OptionsSchemeInsurance insruance = new OptionalSchemeSaveVo.OptionsSchemeInsurance();
- List<OptionalSchemeSaveVo.OptionsSchemeInsurance.IsOptions> 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<PtlOptionalScheme> getOptionalSchemeList(SchemeQueryVo schemeQueryVo) {
- return baseMapper.selectList(new LambdaQueryWrapper<PtlOptionalScheme>()
- .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<SchemeKindInfoVo> schemeInsuranceInfo = ptlOptionalSchemeInsuranceService.getSchemeInsuranceInfo(schemeQueryVo);
- schemeInsuranceInfo.sort((o1, o2) -> Integer.compare(Integer.parseInt(o1.getId()), Integer.parseInt(o2.getId())));
- PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper<PtlOptionalScheme>()
- .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<InsDrivingIntentionInsuranceType> drivingIntentionInsuranceTypeByCompanyId = insDrivingIntentionInsuranceTypeService.getDrivingIntentionInsuranceTypeByCompanyId(schemeQueryVo.getCompanyId());
- companyOptionalSchemeVo.setDrivingList(new ArrayList<>());
- companyOptionalSchemeVo.setDrivingTypeList(drivingIntentionInsuranceTypeByCompanyId);
- return companyOptionalSchemeVo;
- }
- @Override
- public CompanyOptionalSchemeVo getPcSchemeInsuranceInfo(SchemeQueryVo schemeQueryVo) {
- CompanyOptionalSchemeVo companyOptionalSchemeVo = new CompanyOptionalSchemeVo();
- //处理新能源
- schemeQueryVo.setEnergyType(EnergyType.isNewEnergy(schemeQueryVo.getEnergyType()) ? "1" : "0");
- List<SchemeKindInfoVo> schemeInsuranceInfo = ptlOptionalSchemeInsuranceService.getSchemeInsuranceInfo(schemeQueryVo);
- schemeInsuranceInfo.sort((o1, o2) -> Integer.compare(Integer.parseInt(o1.getId()), Integer.parseInt(o2.getId())));
- PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper<PtlOptionalScheme>()
- .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<InsDrivingIntentionInsuranceType> 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<PtlOptionalScheme>()
- .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();
- }
- }
|