QuoteController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package com.ydtech.modules.order.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.fasterxml.jackson.core.JsonProcessingException;
  7. import com.ydtech.constants.enums.InsuranceRisk;
  8. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  9. import com.ydtech.core.page.HttpResult;
  10. import com.ydtech.exception.SystemException;
  11. import com.ydtech.modules.base.controller.BaseController;
  12. import com.ydtech.modules.ins.model.vo.QuoteRespVo;
  13. import com.ydtech.modules.order.aop.QuoteVerification;
  14. import com.ydtech.modules.order.components.InsOrdersComponents;
  15. import com.ydtech.modules.order.entity.vo.AccidentalDrivingVo;
  16. import com.ydtech.modules.order.entity.vo.BaseQuoteInfoVo;
  17. import com.ydtech.modules.order.entity.vo.BaseQuoteVo;
  18. import com.ydtech.modules.order.entity.vo.QuoteAccidentalDrivingVo;
  19. import com.ydtech.modules.order.entity.vo.bohai.BoHaiQuoteAccidentVo;
  20. import com.ydtech.modules.order.entity.vo.guoren.GuoRenQuoteVo;
  21. import com.ydtech.modules.order.entity.vo.guoren.GuorenAccidentalDrivingVo;
  22. import com.ydtech.modules.order.entity.vo.zj.ZjQuoteAccidentVo;
  23. import com.ydtech.modules.order.service.*;
  24. import com.ydtech.modules.protocol.constants.TaxSourceStatusConstants;
  25. import com.ydtech.modules.protocol.dao.PtlTaxSourceNewMapper;
  26. import com.ydtech.modules.protocol.entity.constants.PtlApiType;
  27. import com.ydtech.modules.protocol.entity.dto.TaxSourceExcludeDto;
  28. import com.ydtech.modules.protocol.entity.po.PtlAgreementAttribution;
  29. import com.ydtech.modules.protocol.entity.po.PtlTaxSourceNew;
  30. import com.ydtech.modules.protocol.service.PtlAgreementAttributionService;
  31. import com.ydtech.modules.protocol.service.PtlTaxSourceNewService;
  32. import com.ydtech.modules.protocol.service.impl.TaxSourceExcludeServiceImpl;
  33. import com.ydtech.utils.StringUtils;
  34. import io.swagger.annotations.Api;
  35. import org.springframework.beans.BeanUtils;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.stereotype.Controller;
  38. import org.springframework.util.ObjectUtils;
  39. import org.springframework.web.bind.annotation.PostMapping;
  40. import org.springframework.web.bind.annotation.RequestBody;
  41. import org.springframework.web.bind.annotation.RequestMapping;
  42. import org.springframework.web.bind.annotation.RestController;
  43. import java.util.ArrayList;
  44. import java.util.List;
  45. import java.util.Objects;
  46. @Api(tags = "报价")
  47. @RestController
  48. @RequestMapping(value = "/quote")
  49. public class QuoteController extends BaseController {
  50. @Autowired
  51. TaxSourceExcludeServiceImpl taxSourceExcludeService;
  52. @Autowired
  53. PtlTaxSourceNewService ptlTaxSourceNewService;
  54. @Autowired
  55. PtlTaxSourceNewMapper ptlTaxSourceNewMapper;
  56. @Autowired
  57. InsOrdersComponents insOrdersComponents;
  58. @Autowired
  59. PtlAgreementAttributionService ptlAgreementAttributionService;
  60. @Autowired
  61. InsCrawlerOrderService insCrawlerOrderService;
  62. @Autowired
  63. ZhongMeiOrderApiService zhongMeiOrderApiService;
  64. @Autowired
  65. ZijinOrderApiService zijinOrderApiService;
  66. @Autowired
  67. YongchengOrderApiService yongchengOrderApiService;
  68. @Autowired
  69. HuaTaiOrderApiService huaTaiOrderApiService;
  70. @Autowired
  71. GuorenOrderApiService guorenOrderApiService;
  72. @Autowired
  73. DaJiaOrderService daJiaOrderService;
  74. @Autowired
  75. BoHaiOrderApiService boHaiOrderApiService;
  76. @Autowired
  77. PingAnOrderApiService pingAnOrderApiService;
  78. @Autowired
  79. InsOrdersService insOrdersService;
  80. @QuoteVerification("报价授权")
  81. @PostMapping(value = "/quote")
  82. public HttpResult<QuoteRespVo> quote(@RequestBody BaseQuoteVo<Object> quoteVo) throws Exception {
  83. String isTaxSource = quoteVo.getIsTaxSource();
  84. boolean isExclude = true;
  85. //排除的部门信息
  86. List<TaxSourceExcludeDto> excludeDepts =
  87. taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>()
  88. .eq(TaxSourceExcludeDto::getExcludeInfo, getDeptId())
  89. .eq(TaxSourceExcludeDto::getInsCompanyId, quoteVo.getCompanyId())
  90. .eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
  91. BaseQuoteInfoVo quoteInfo = insOrdersComponents.getQuoteInfo(quoteVo.getOrderNo(), quoteVo.getAgreementId(),quoteVo.getKinds());
  92. //部门排除
  93. String finalDeptId = getDeptId();
  94. if (excludeDepts.stream().anyMatch(taxSourceDto -> taxSourceDto.getExcludeInfo().equals(finalDeptId))) {
  95. isExclude = false;
  96. }
  97. if(Objects.isNull(quoteVo.getKinds())){
  98. quoteVo.setKinds(new ArrayList<>());
  99. }
  100. ProductsType insuranceRisk = InsuranceRisk.determineInsuranceInformation(quoteVo.getKinds(), quoteVo.getRisks());
  101. //默认协议走逻辑判断 且不在排除部门中走默认判断逻辑
  102. if(StringUtils.isNotBlank(isTaxSource) && "1".equals(isTaxSource) && isExclude){
  103. String taxAgreementId = ptlTaxSourceNewService.getAgreementId(getDeptId(), getUserId(), quoteVo.getCompanyId(), quoteInfo,insuranceRisk.getCode(),quoteVo.getOrderNo());
  104. quoteVo.setAgreementId(taxAgreementId);
  105. // log.info("======================订单号"+orderno+"走默认协议判断逻辑!匹配协议为:"+taxAgreementId+"=======================");
  106. //throw new SystemException("订单号"+orderno+"走默认协议判断逻辑!匹配协议为:"+taxAgreementId);
  107. }else{
  108. //不在排除部门内进行默认判断
  109. if(isExclude){
  110. //走正常协议判断是错误的 判断是否有默认配置,如果有不可能进来,前台报错
  111. List<PtlTaxSourceNew> taxSourceDtoList = ptlTaxSourceNewMapper.selectList(new LambdaQueryWrapper<PtlTaxSourceNew>()
  112. .eq(PtlTaxSourceNew::getInsCompanyId, quoteVo.getCompanyId())
  113. .eq(PtlTaxSourceNew::getDefaultFlag,"1"));
  114. if(taxSourceDtoList!=null && !taxSourceDtoList.isEmpty()){
  115. //throw new SystemException("配置默认协议且部门未排除应走默认逻辑,操作错误,请联系管理员!!");
  116. //强制走默认状态
  117. String taxAgreementId = ptlTaxSourceNewService.getAgreementId(getDeptId(), getUserId(), quoteVo.getCompanyId(), quoteInfo,insuranceRisk.getCode(),quoteVo.getOrderNo());
  118. quoteVo.setAgreementId(taxAgreementId);
  119. }
  120. }
  121. }
  122. HttpResult<QuoteRespVo> respVo = null;
  123. PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.getById(quoteVo.getAgreementId());
  124. if (PtlApiType.PTL_API_2.getCode() == ptlAgreementAttribution.getApiType()) {
  125. BaseQuoteVo<QuoteAccidentalDrivingVo> quoteVo1 = new BaseQuoteVo<>();
  126. JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo()));
  127. QuoteAccidentalDrivingVo javaObject = jsonObject.toJavaObject(QuoteAccidentalDrivingVo.class);
  128. BeanUtils.copyProperties(quoteVo, quoteVo1);
  129. quoteVo1.setAccidentalDrivingVo(javaObject);
  130. BaseQuoteVo baseQuoteVo = insOrdersService.convertDriving(quoteVo1);
  131. respVo = insCrawlerOrderService.quote(quoteInfo, baseQuoteVo);
  132. }
  133. if("ZMBX1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  134. BaseQuoteVo<AccidentalDrivingVo> quoteVo1 = new BaseQuoteVo<>();
  135. JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo()));
  136. BeanUtils.copyProperties(quoteVo, quoteVo1);
  137. if(jsonObject.size() > 0) {
  138. AccidentalDrivingVo javaObject = jsonObject.toJavaObject(AccidentalDrivingVo.class);
  139. quoteVo1.setAccidentalDrivingVo(javaObject);
  140. }else{
  141. quoteVo1.setAccidentalDrivingVo(null);
  142. }
  143. respVo = zhongMeiOrderApiService.quote(quoteInfo, quoteVo1);
  144. }
  145. if("AICS1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  146. BaseQuoteVo<QuoteAccidentalDrivingVo> quoteVo1 = new BaseQuoteVo<>();
  147. JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo()));
  148. QuoteAccidentalDrivingVo javaObject = jsonObject.toJavaObject(QuoteAccidentalDrivingVo.class);
  149. BeanUtils.copyProperties(quoteVo, quoteVo1);
  150. quoteVo1.setAccidentalDrivingVo(javaObject);
  151. //转换类型
  152. BaseQuoteVo<AccidentalDrivingVo> baseQuoteVo = insOrdersService.convertDriving(quoteVo1);
  153. respVo = yongchengOrderApiService.quoteApi(baseQuoteVo);
  154. }
  155. if("YAIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  156. }
  157. if("ZKIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  158. BaseQuoteVo<List<ZjQuoteAccidentVo>> quoteVo1 = new BaseQuoteVo<>();
  159. JSONArray jsonObject = JSONArray.parseArray(JSONArray.toJSONString(quoteVo.getAccidentalDrivingVo()));
  160. List<ZjQuoteAccidentVo> javaObject = jsonObject.toJavaList(ZjQuoteAccidentVo.class);
  161. BeanUtils.copyProperties(quoteVo, quoteVo1);
  162. quoteVo1.setAccidentalDrivingVo(javaObject);
  163. respVo = zijinOrderApiService.quote(quoteInfo, quoteVo1);
  164. }
  165. if("XDCX1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  166. GuoRenQuoteVo<QuoteAccidentalDrivingVo> quoteVo1 = new GuoRenQuoteVo<>();
  167. JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo()));
  168. QuoteAccidentalDrivingVo javaObject = jsonObject.toJavaObject(QuoteAccidentalDrivingVo.class);
  169. BeanUtils.copyProperties(quoteVo, quoteVo1);
  170. quoteVo1.setAccidentalDrivingVo(javaObject);
  171. BaseQuoteVo<GuorenAccidentalDrivingVo> baseQuoteVo = insOrdersService.convertDriving(quoteVo1);
  172. GuoRenQuoteVo guoRenQuoteVo = new GuoRenQuoteVo();
  173. BeanUtils.copyProperties(baseQuoteVo, guoRenQuoteVo);
  174. guoRenQuoteVo.setGuoRenSpecialAgreementVo(baseQuoteVo.getGuoRenSpecialAgreementVo());
  175. respVo = guorenOrderApiService.quoteApi(guoRenQuoteVo);
  176. }
  177. if("HTIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  178. BaseQuoteVo<AccidentalDrivingVo> quoteVo1 = new BaseQuoteVo<>();
  179. AccidentalDrivingVo javaObject = new AccidentalDrivingVo();
  180. if(!Objects.isNull(quoteVo.getAccidentalDrivingVo())) {
  181. JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo()));
  182. javaObject= jsonObject.toJavaObject(AccidentalDrivingVo.class);
  183. }
  184. BeanUtils.copyProperties(quoteVo,quoteVo1);
  185. quoteVo1.setAccidentalDrivingVo(javaObject);
  186. respVo = huaTaiOrderApiService.quote(quoteInfo, quoteVo1);
  187. }
  188. if("DJPC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  189. respVo = daJiaOrderService.quote(quoteInfo, quoteVo);
  190. }
  191. if("BPIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  192. BaseQuoteVo<List<BoHaiQuoteAccidentVo>> quoteVo1 = new BaseQuoteVo<>();
  193. JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo()));
  194. BeanUtils.copyProperties(quoteVo, quoteVo1);
  195. if(jsonObject.size() > 0) {
  196. BoHaiQuoteAccidentVo javaObject = new BoHaiQuoteAccidentVo();
  197. javaObject.setPackageCode(jsonObject.getString("projectCode"));
  198. javaObject.setProductCode(jsonObject.getString("riskCode"));
  199. javaObject.setCopies(jsonObject.getString("quantity"));
  200. List<BoHaiQuoteAccidentVo> javaObjectList = new ArrayList<>();
  201. javaObjectList.add(javaObject);
  202. quoteVo1.setAccidentalDrivingVo(javaObjectList);
  203. }else{
  204. quoteVo1.setAccidentalDrivingVo(new ArrayList<>());
  205. }
  206. respVo = boHaiOrderApiService.quote(quoteInfo, quoteVo1);
  207. }
  208. if("PAIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){
  209. // BaseQuoteVo<AccidentalDrivingVo> quoteVo1 = new BaseQuoteVo<>();
  210. // JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo()));
  211. // AccidentalDrivingVo javaObject = jsonObject.toJavaObject(AccidentalDrivingVo.class);
  212. // BeanUtils.copyProperties(quoteVo,quoteVo1);
  213. // quoteVo1.setAccidentalDrivingVo(javaObject);
  214. // return pingAnOrderApiService.quote(quoteInfo, quoteVo1);
  215. }
  216. PtlAgreementAttribution byId = ptlAgreementAttributionService.getById(quoteVo.getAgreementId());
  217. if( respVo != null && !ObjectUtils.isEmpty( respVo.getData() )){
  218. respVo.getData().setApiType(byId.getApiType());
  219. }
  220. return respVo;
  221. }
  222. }