PtlOptionalSchemeServiceImpl.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. package com.ydtech.modules.scheme.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  8. import com.ydtech.constants.enums.dict.insurance.EnergyType;
  9. import com.ydtech.exception.SystemException;
  10. import com.ydtech.modules.esm.model.EsmInsCompany;
  11. import com.ydtech.modules.ins.model.vo.KindInfoVo;
  12. import com.ydtech.modules.order.entity.InsBusinessInsurance;
  13. import com.ydtech.modules.order.entity.InsBusinessInsuranceOption;
  14. import com.ydtech.modules.order.entity.InsDrivingIntentionInsuranceType;
  15. import com.ydtech.modules.order.service.InsBusinessInsuranceService;
  16. import com.ydtech.modules.order.service.InsDrivingIntentionInsuranceService;
  17. import com.ydtech.modules.order.service.InsDrivingIntentionInsuranceTypeService;
  18. import com.ydtech.modules.scheme.dao.PtlOptionalSchemeMapper;
  19. import com.ydtech.modules.scheme.dao.PtlSchemeMapper;
  20. import com.ydtech.modules.scheme.entity.po.*;
  21. import com.ydtech.modules.scheme.entity.vo.*;
  22. import com.ydtech.modules.scheme.service.*;
  23. import com.ydtech.utils.idgen.IdGenerate;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import org.springframework.transaction.annotation.Transactional;
  27. import java.util.*;
  28. import java.util.stream.Collectors;
  29. /**
  30. * @description 自选方案 service实现类
  31. * @createDate 2024-7-30 10:18:19
  32. * @Entity
  33. */
  34. @Service
  35. public class PtlOptionalSchemeServiceImpl extends ServiceImpl<PtlOptionalSchemeMapper, PtlOptionalScheme>
  36. implements PtlOptionalSchemeService {
  37. @Autowired
  38. private PtlOptionalSchemeInsuranceService ptlOptionalSchemeInsuranceService;
  39. @Autowired
  40. private PtlOptionalSchemeInsuranceDrivingIntentionService ptlOptionalSchemeInsuranceDrivingIntentionService;
  41. @Autowired
  42. private InsBusinessInsuranceService insBusinessInsuranceService;
  43. @Autowired
  44. private PtlSchemeInsuranceService ptlSchemeInsuranceService;
  45. @Autowired
  46. InsDrivingIntentionInsuranceTypeService insDrivingIntentionInsuranceTypeService;
  47. @Autowired
  48. InsDrivingIntentionInsuranceService insDrivingIntentionInsuranceService;
  49. @Override
  50. @Transactional
  51. public boolean addOptionScheme(OptionalSchemeSaveVo optionalSchemeSaveVo) {
  52. PtlOptionalScheme optionalScheme = optionalSchemeSaveVo.getOptionSchemeObject();
  53. this.save(optionalScheme);
  54. List<PtlOptionalSchemeInsurance> optionsSchemeKindsList = optionalSchemeSaveVo.getOptionsSchemeKindsList(optionalScheme.getId());
  55. ptlOptionalSchemeInsuranceService.saveBatch(optionsSchemeKindsList);
  56. List<PtlOptionalSchemeInsuranceDrivingIntention> optionsSchemeInsruanceDrvingIntentionList = optionalSchemeSaveVo.getOptionsSchemeInsruanceDrvingIntentionList(optionalScheme.getId());
  57. ptlOptionalSchemeInsuranceDrivingIntentionService.saveBatch(optionsSchemeInsruanceDrvingIntentionList);
  58. return true;
  59. }
  60. /**
  61. * 更新自选方案
  62. * @param optionalSchemeSaveVo
  63. * @return
  64. */
  65. @Override
  66. public boolean updateOptionScheme(OptionalSchemeSaveVo optionalSchemeSaveVo) {
  67. PtlOptionalScheme optionalScheme = optionalSchemeSaveVo.getOptionSchemeObject();
  68. this.updateById(optionalScheme);
  69. ptlOptionalSchemeInsuranceService.remove(new LambdaQueryWrapper<PtlOptionalSchemeInsurance>()
  70. .eq(PtlOptionalSchemeInsurance::getSchemeId,optionalScheme.getId()));
  71. if(!optionalSchemeSaveVo.getProductId().equals(ProductsType.PT_0330.getCode())) {
  72. List<PtlOptionalSchemeInsurance> optionsSchemeKindsList = optionalSchemeSaveVo.getOptionsSchemeKindsList(optionalScheme.getId());
  73. ptlOptionalSchemeInsuranceService.saveBatch(optionsSchemeKindsList);
  74. }
  75. ptlOptionalSchemeInsuranceDrivingIntentionService.remove(new LambdaQueryWrapper<PtlOptionalSchemeInsuranceDrivingIntention>()
  76. .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,optionalScheme.getId()));
  77. List<PtlOptionalSchemeInsuranceDrivingIntention> optionsSchemeInsruanceDrvingIntentionList = optionalSchemeSaveVo.getOptionsSchemeInsruanceDrvingIntentionList(optionalScheme.getId());
  78. ptlOptionalSchemeInsuranceDrivingIntentionService.saveBatch(optionsSchemeInsruanceDrvingIntentionList);
  79. return true;
  80. }
  81. @Override
  82. @Transactional
  83. public boolean deleteOptionScheme(String id) {
  84. PtlOptionalScheme byId = this.getById(id);
  85. if(Objects.isNull(byId)){
  86. throw new SystemException("找不到自选方案");
  87. }
  88. this.removeById(id);
  89. ptlOptionalSchemeInsuranceService.remove(new LambdaQueryWrapper<PtlOptionalSchemeInsurance>()
  90. .eq(PtlOptionalSchemeInsurance::getSchemeId,id));
  91. ptlOptionalSchemeInsuranceDrivingIntentionService.remove(new LambdaQueryWrapper<PtlOptionalSchemeInsuranceDrivingIntention>()
  92. .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,id));
  93. return true;
  94. }
  95. /**
  96. * 自选方案详情
  97. * @param companyId
  98. * @param productId
  99. * @return
  100. */
  101. @Override
  102. public OptionalSchemeSaveVo optionalSchemeInfo(String companyId, String productId,String carnature, String vehicleType, String energyType) {
  103. OptionalSchemeSaveVo optionalSchemeSaveVo = new OptionalSchemeSaveVo();
  104. PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper<PtlOptionalScheme>()
  105. .eq(PtlOptionalScheme::getCompanyId,companyId)
  106. .eq(PtlOptionalScheme::getProductId,productId)
  107. .eq(PtlOptionalScheme::getCarnature,carnature)
  108. .eq(PtlOptionalScheme::getVehicleType,vehicleType)
  109. .eq(PtlOptionalScheme::getEnergyType,energyType));
  110. optionalSchemeSaveVo.setId(optionalScheme.getId());
  111. optionalSchemeSaveVo.setCompanyId(companyId);
  112. optionalSchemeSaveVo.setSchemeName(optionalScheme.getSchemeName());
  113. optionalSchemeSaveVo.setProductName(optionalScheme.getProductName());
  114. optionalSchemeSaveVo.setProductId(optionalScheme.getProductId());
  115. optionalSchemeSaveVo.setDescription(optionalScheme.getDescription());
  116. List<OptionalSchemeSaveVo.OptionsSchemeKinds> kinds = new ArrayList<>();
  117. //遍历全部options
  118. List<InsBusinessInsurance> businessInsurance = insBusinessInsuranceService.getBusinessInsurance();
  119. List<PtlOptionalSchemeInsurance> list = ptlOptionalSchemeInsuranceService.list(new LambdaQueryWrapper<PtlOptionalSchemeInsurance>()
  120. .eq(PtlOptionalSchemeInsurance::getSchemeId, optionalScheme.getId()));
  121. businessInsurance.forEach(item->{
  122. item.setAmountDesc("不投保");
  123. OptionalSchemeSaveVo.OptionsSchemeKinds kind = new OptionalSchemeSaveVo.OptionsSchemeKinds();
  124. kind.setId(item.getId());
  125. kind.setKindCode(item.getKindCode());
  126. kind.setKindName(item.getKindName());
  127. List<PtlOptionalSchemeInsurance> collect = list.stream().filter(x -> x.getInsuranceId().equals(item.getId())).collect(Collectors.toList());
  128. kind.setAmtList(item.getAmtList());
  129. kind.setAmount(list.stream().filter(x->x.getInsuranceId().equals(item.getId())).map(x->x.getOptionId()).collect(Collectors.toList()));
  130. if(kind.getKindCode().equals("TY2") || kind.getKindCode().equals("TY3") || kind.getKindCode().equals("TY4")){
  131. if(!collect.isEmpty() && collect.get(0).getMax() != 0){
  132. kind.setMax(collect.get(0).getMax().toString());
  133. }
  134. }
  135. kinds.add(kind);
  136. });
  137. optionalSchemeSaveVo.setKinds(kinds);
  138. //驾意险
  139. List<PtlOptionalSchemeInsuranceDrivingIntention> drivingIntentions = ptlOptionalSchemeInsuranceDrivingIntentionService.list(new LambdaQueryWrapper<PtlOptionalSchemeInsuranceDrivingIntention>()
  140. .eq(PtlOptionalSchemeInsuranceDrivingIntention::getSchemeId,optionalScheme.getId()));
  141. List<OptionalSchemeSaveVo.OptionsSchemeInsurance> collect = new ArrayList<>();
  142. Map<String, List<PtlOptionalSchemeInsuranceDrivingIntention>> maps = new HashMap<>();
  143. if(drivingIntentions.size() > 0){
  144. maps = drivingIntentions.stream().collect(Collectors.groupingBy(PtlOptionalSchemeInsuranceDrivingIntention::getSeatNum));
  145. }
  146. for (Map.Entry<String, List<PtlOptionalSchemeInsuranceDrivingIntention>> entry : maps.entrySet()) {
  147. String seatNum = entry.getKey(); // 获取 SeatNum
  148. List<PtlOptionalSchemeInsuranceDrivingIntention> intentions = entry.getValue(); // 获取对应的列表
  149. OptionalSchemeSaveVo.OptionsSchemeInsurance insruance = new OptionalSchemeSaveVo.OptionsSchemeInsurance();
  150. List<OptionalSchemeSaveVo.OptionsSchemeInsurance.IsOptions> isOptions = new ArrayList<>();
  151. for (PtlOptionalSchemeInsuranceDrivingIntention x : intentions) {
  152. OptionalSchemeSaveVo.OptionsSchemeInsurance.IsOptions isOption = new OptionalSchemeSaveVo.OptionsSchemeInsurance.IsOptions();
  153. isOption.setAlias(x.getAlias());
  154. isOption.setProjectName(x.getAlias());
  155. isOption.setTitle(x.getTitle());
  156. isOption.setId(x.getDrivingIntentionId());
  157. isOption.setMinQuantity(x.getMinQuantity());
  158. isOptions.add(isOption);
  159. }
  160. insruance.setSeatNum(seatNum);
  161. insruance.setIsOptions(isOptions);
  162. DrivingIntentionQueryVo drivingIntentionQueryVo = new DrivingIntentionQueryVo();
  163. drivingIntentionQueryVo.setCompanyId(companyId);
  164. insruance.setUndrvingList(insDrivingIntentionInsuranceService.getSchemeDrivingIntentionInsurance(drivingIntentionQueryVo));
  165. collect.add(insruance);
  166. }
  167. optionalSchemeSaveVo.setDrvingList(collect);
  168. return optionalSchemeSaveVo;
  169. }
  170. @Override
  171. public List<PtlOptionalScheme> getOptionalSchemeList(SchemeQueryVo schemeQueryVo) {
  172. return baseMapper.selectList(new LambdaQueryWrapper<PtlOptionalScheme>()
  173. .eq(PtlOptionalScheme::getCompanyId,schemeQueryVo.getCompanyId())
  174. .eq(PtlOptionalScheme::getEnergyType,schemeQueryVo.getEnergyType())
  175. .eq(PtlOptionalScheme::getVehicleType,schemeQueryVo.getVehicleType())
  176. .eq(!Objects.isNull(schemeQueryVo.getCarnature()),PtlOptionalScheme::getCarnature,schemeQueryVo.getCarnature()));
  177. }
  178. @Override
  179. public CompanyOptionalSchemeVo getSchemeInsuranceInfo(SchemeQueryVo schemeQueryVo) {
  180. CompanyOptionalSchemeVo companyOptionalSchemeVo = new CompanyOptionalSchemeVo();
  181. List<SchemeKindInfoVo> schemeInsuranceInfo = ptlOptionalSchemeInsuranceService.getSchemeInsuranceInfo(schemeQueryVo);
  182. schemeInsuranceInfo.sort((o1, o2) -> Integer.compare(Integer.parseInt(o1.getId()), Integer.parseInt(o2.getId())));
  183. PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper<PtlOptionalScheme>()
  184. .eq(PtlOptionalScheme::getCompanyId,schemeQueryVo.getCompanyId())
  185. .eq(PtlOptionalScheme::getProductId,schemeQueryVo.getProductId())
  186. .eq(PtlOptionalScheme::getVehicleType, schemeQueryVo.getVehicleType())
  187. .eq(PtlOptionalScheme::getEnergyType, schemeQueryVo.getEnergyType())
  188. .eq(PtlOptionalScheme::getCarnature, schemeQueryVo.getCarnature()));
  189. //险种信息
  190. companyOptionalSchemeVo.setIsJq("0");
  191. companyOptionalSchemeVo.setIsSy("0");
  192. if(schemeQueryVo.getProductId().equals(ProductsType.PT_0330.getCode()) ||
  193. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) ||
  194. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){
  195. companyOptionalSchemeVo.setIsJq("1");
  196. }
  197. if(schemeQueryVo.getProductId().equals(ProductsType.PT_034002.getCode()) ||
  198. schemeQueryVo.getProductId().equals(ProductsType.PT_034001.getCode()) ||
  199. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) ||
  200. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){
  201. companyOptionalSchemeVo.setIsSy("1");
  202. }
  203. if(Objects.isNull(optionalScheme)){
  204. throw new SystemException("未找到自选方案");
  205. }
  206. schemeInsuranceInfo.forEach(item->{
  207. item.setAmountDesc("不投保");
  208. });
  209. companyOptionalSchemeVo.setSchemeId(optionalScheme.getId());
  210. companyOptionalSchemeVo.setSchemeName(optionalScheme.getSchemeName());
  211. companyOptionalSchemeVo.setKinds(schemeInsuranceInfo);
  212. List<InsDrivingIntentionInsuranceType> drivingIntentionInsuranceTypeByCompanyId = insDrivingIntentionInsuranceTypeService.getDrivingIntentionInsuranceTypeByCompanyId(schemeQueryVo.getCompanyId());
  213. companyOptionalSchemeVo.setDrivingList(new ArrayList<>());
  214. companyOptionalSchemeVo.setDrivingTypeList(drivingIntentionInsuranceTypeByCompanyId);
  215. return companyOptionalSchemeVo;
  216. }
  217. @Override
  218. public CompanyOptionalSchemeVo getPcSchemeInsuranceInfo(SchemeQueryVo schemeQueryVo) {
  219. CompanyOptionalSchemeVo companyOptionalSchemeVo = new CompanyOptionalSchemeVo();
  220. //处理新能源
  221. schemeQueryVo.setEnergyType(EnergyType.isNewEnergy(schemeQueryVo.getEnergyType()) ? "1" : "0");
  222. List<SchemeKindInfoVo> schemeInsuranceInfo = ptlOptionalSchemeInsuranceService.getSchemeInsuranceInfo(schemeQueryVo);
  223. schemeInsuranceInfo.sort((o1, o2) -> Integer.compare(Integer.parseInt(o1.getId()), Integer.parseInt(o2.getId())));
  224. PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper<PtlOptionalScheme>()
  225. .eq(PtlOptionalScheme::getCompanyId,schemeQueryVo.getCompanyId())
  226. .eq(PtlOptionalScheme::getProductId,schemeQueryVo.getProductId())
  227. .eq(PtlOptionalScheme::getVehicleType, schemeQueryVo.getVehicleType())
  228. .eq(PtlOptionalScheme::getEnergyType, schemeQueryVo.getEnergyType())
  229. .eq(PtlOptionalScheme::getCarnature, schemeQueryVo.getCarnature()));
  230. //险种信息
  231. companyOptionalSchemeVo.setIsJq("0");
  232. companyOptionalSchemeVo.setIsSy("0");
  233. if(schemeQueryVo.getProductId().equals(ProductsType.PT_0330.getCode()) ||
  234. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) ||
  235. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){
  236. companyOptionalSchemeVo.setIsJq("1");
  237. }
  238. if(schemeQueryVo.getProductId().equals(ProductsType.PT_034002.getCode()) ||
  239. schemeQueryVo.getProductId().equals(ProductsType.PT_034001.getCode()) ||
  240. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034001.getCode()) ||
  241. schemeQueryVo.getProductId().equals(ProductsType.PT_0330034002.getCode())){
  242. companyOptionalSchemeVo.setIsSy("1");
  243. }
  244. if(Objects.isNull(optionalScheme)){
  245. return null;
  246. }
  247. schemeInsuranceInfo.forEach(item->{
  248. item.setAmountDesc("不投保");
  249. });
  250. companyOptionalSchemeVo.setSchemeId(optionalScheme.getId());
  251. companyOptionalSchemeVo.setSchemeName(optionalScheme.getSchemeName());
  252. companyOptionalSchemeVo.setKinds(schemeInsuranceInfo);
  253. List<InsDrivingIntentionInsuranceType> drivingIntentionInsuranceTypeByCompanyId = insDrivingIntentionInsuranceTypeService.getDrivingIntentionInsuranceTypeByCompanyId(schemeQueryVo.getCompanyId());
  254. companyOptionalSchemeVo.setDrivingList(new ArrayList<>());
  255. companyOptionalSchemeVo.setDrivingTypeList(drivingIntentionInsuranceTypeByCompanyId);
  256. return companyOptionalSchemeVo;
  257. }
  258. /**
  259. * 获取保险公司投保指引
  260. * @return
  261. */
  262. @Override
  263. public String getCompanyInsGuide(String companyId,String productId,String carnature, String vehicleType, String energyType){
  264. PtlOptionalScheme optionalScheme = this.getOne(new LambdaQueryWrapper<PtlOptionalScheme>()
  265. .eq(PtlOptionalScheme::getCompanyId,companyId)
  266. .eq(PtlOptionalScheme::getProductId,productId)
  267. .eq(PtlOptionalScheme::getVehicleType, vehicleType)
  268. .eq(PtlOptionalScheme::getEnergyType, energyType)
  269. .eq(PtlOptionalScheme::getCarnature, carnature));
  270. if(Objects.isNull(optionalScheme)){
  271. return "";
  272. }
  273. return optionalScheme.getDescription();
  274. }
  275. }