PtlOptionalSchemeServiceImpl.java 16 KB

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