package com.ydtech.modules.order.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fasterxml.jackson.core.JsonProcessingException; import com.ydtech.aop.request.RequestSingleParam; import com.ydtech.core.page.HttpResult; import com.ydtech.exception.SystemException; import com.ydtech.modules.base.controller.BaseController; import com.ydtech.modules.ins.model.vo.KindInfoVo; import com.ydtech.modules.ins.model.vo.QuoteRespVo; import com.ydtech.modules.order.aop.QuoteVerification; import com.ydtech.modules.order.components.InsOrdersComponents; import com.ydtech.modules.order.entity.InsAreaCompany; import com.ydtech.modules.order.entity.InsDrivingIntentionInsurance; import com.ydtech.modules.order.entity.vo.AccidentalDrivingVo; import com.ydtech.modules.order.entity.vo.BaseQuoteInfoVo; import com.ydtech.modules.order.entity.vo.BaseQuoteVo; import com.ydtech.modules.order.entity.vo.QuoteAccidentalDrivingVo; import com.ydtech.modules.order.entity.vo.bohai.BoHaiQuoteAccidentVo; import com.ydtech.modules.order.entity.vo.guoren.GuoRenQuoteVo; import com.ydtech.modules.order.entity.vo.guoren.GuorenAccidentalDrivingVo; import com.ydtech.modules.order.entity.vo.yangguang.YgQuoteAccidentVo; import com.ydtech.modules.order.entity.vo.zj.ZjQuoteAccidentVo; import com.ydtech.modules.order.service.*; import com.ydtech.modules.protocol.dao.PtlTaxSourceNewMapper; import com.ydtech.modules.protocol.entity.constants.PtlApiType; import com.ydtech.modules.protocol.entity.po.PtlAgreementAttribution; import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo; import com.ydtech.modules.protocol.service.PtlAgreementAttributionService; import com.ydtech.modules.protocol.service.PtlAgreementService; import com.ydtech.modules.protocol.service.PtlTaxSourceNewService; import com.ydtech.modules.protocol.service.impl.TaxSourceExcludeServiceImpl; import com.ydtech.utils.StringUtils; import io.swagger.annotations.Api; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.Objects; @Api(tags = "报价") @RestController @RequestMapping(value = "/quote") public class QuoteController extends BaseController { @Autowired TaxSourceExcludeServiceImpl taxSourceExcludeService; @Autowired PtlTaxSourceNewService ptlTaxSourceNewService; @Autowired PtlTaxSourceNewMapper ptlTaxSourceNewMapper; @Autowired InsOrdersComponents insOrdersComponents; @Autowired PtlAgreementAttributionService ptlAgreementAttributionService; @Autowired InsCrawlerOrderService insCrawlerOrderService; @Autowired ZhongMeiOrderApiService zhongMeiOrderApiService; @Autowired ZijinOrderApiService zijinOrderApiService; @Autowired YongchengOrderApiService yongchengOrderApiService; @Autowired HuaTaiOrderApiService huaTaiOrderApiService; @Autowired GuorenOrderApiService guorenOrderApiService; @Autowired DaJiaOrderService daJiaOrderService; @Autowired BoHaiOrderApiService boHaiOrderApiService; @Autowired PingAnOrderApiService pingAnOrderApiService; @Autowired InsOrdersService insOrdersService; @Autowired InsAreaCompanyService insAreaCompanyService; @Autowired ChengTaiOrderApiService chengTaiOrderApiService; @Autowired YongAnOrderService yongAnOrderService; @Autowired YangGuangOrderApiService yangGuangOrderApiService; @Autowired PtlAgreementService ptlAgreementService; @Autowired InsDrivingIntentionInsuranceService insDrivingIntentionInsuranceService; @QuoteVerification("报价授权") @PostMapping(value = "/quote") public HttpResult quote(@RequestBody BaseQuoteVo quoteVo) throws Exception { //处理商业险 为空的去掉 List kinds = quoteVo.getKinds(); kinds.removeIf(item->Double.compare(item.getAmount(),0) == 0 && Double.compare(item.getUnitAmount(),0) == 0 && item.getServiceTimes() == 0); BaseQuoteInfoVo quoteInfo = insOrdersComponents.getQuoteInfo(quoteVo.getOrderNo(), quoteVo.getAgreementId(),quoteVo.getKinds()); quoteInfo.setKindList(kinds); //设置座位数 驾意险需要传 quoteVo.setSeatNum(quoteInfo.getCarInfo().getSeatCount()); HttpResult respVo = null; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); HttpResult byAgreementId = ptlAgreementService.getByAgreementId(quoteVo.getAgreementId()); LocalDateTime currentDate = LocalDateTime.now(); if(byAgreementId.getData().getAgreement().getIsValid().equals("0") //是否有效 || byAgreementId.getData().getAgreement().getValidStatus().equals("0") //是否有效 || !(currentDate.isAfter(byAgreementId.getData().getAgreement().getStartDate()) && currentDate.isBefore(byAgreementId.getData().getAgreement().getEndDate()))){ throw new SystemException("协议失效,请检查调度"); } PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.getById(quoteVo.getAgreementId()); if (PtlApiType.PTL_API_2.getCode() == ptlAgreementAttribution.getApiType()) { BaseQuoteVo quoteVo1 = new BaseQuoteVo<>(); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); QuoteAccidentalDrivingVo javaObject = jsonObject.toJavaObject(QuoteAccidentalDrivingVo.class); BeanUtils.copyProperties(quoteVo, quoteVo1); quoteVo1.setAccidentalDrivingVo(javaObject); quoteVo1.setSeatNum(quoteInfo.getCarInfo().getSeatCount()); BaseQuoteVo baseQuoteVo = insOrdersService.convertDriving(quoteVo1); respVo = insCrawlerOrderService.quote(quoteInfo, baseQuoteVo); } if("ZMBX1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ BaseQuoteVo quoteVo1 = new BaseQuoteVo<>(); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); BeanUtils.copyProperties(quoteVo, quoteVo1); if(jsonObject.size() > 0) { AccidentalDrivingVo javaObject = jsonObject.toJavaObject(AccidentalDrivingVo.class); quoteVo1.setAccidentalDrivingVo(javaObject); }else{ quoteVo1.setAccidentalDrivingVo(null); } respVo = zhongMeiOrderApiService.quote(quoteInfo, quoteVo1); } if("AICS1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ BaseQuoteVo quoteVo1 = new BaseQuoteVo<>(); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); QuoteAccidentalDrivingVo javaObject = jsonObject.toJavaObject(QuoteAccidentalDrivingVo.class); BeanUtils.copyProperties(quoteVo, quoteVo1); quoteVo1.setAccidentalDrivingVo(javaObject); //转换类型 BaseQuoteVo baseQuoteVo = insOrdersService.convertDriving(quoteVo1); respVo = yongchengOrderApiService.quoteApi(baseQuoteVo); } if("YAIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ } if("ZKIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ BaseQuoteVo> quoteVo1 = new BaseQuoteVo<>(); JSONArray jsonObject = JSONArray.parseArray(JSONArray.toJSONString(quoteVo.getAccidentalDrivingVo())); List javaObject = jsonObject.toJavaList(ZjQuoteAccidentVo.class); BeanUtils.copyProperties(quoteVo, quoteVo1); quoteVo1.setAccidentalDrivingVo(javaObject); respVo = zijinOrderApiService.quote(quoteInfo, quoteVo1); } if("XDCX1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ GuoRenQuoteVo quoteVo1 = new GuoRenQuoteVo<>(); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); QuoteAccidentalDrivingVo javaObject = jsonObject.toJavaObject(QuoteAccidentalDrivingVo.class); BeanUtils.copyProperties(quoteVo, quoteVo1); quoteVo1.setAccidentalDrivingVo(javaObject); // quoteVo1.setSeatNum(); BaseQuoteVo baseQuoteVo = insOrdersService.convertDriving(quoteVo1); GuoRenQuoteVo guoRenQuoteVo = new GuoRenQuoteVo(); BeanUtils.copyProperties(baseQuoteVo, guoRenQuoteVo); guoRenQuoteVo.setGuoRenSpecialAgreementVo(baseQuoteVo.getGuoRenSpecialAgreementVo()); respVo = guorenOrderApiService.quoteApi(guoRenQuoteVo); } if("HTIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ BaseQuoteVo quoteVo1 = new BaseQuoteVo<>(); AccidentalDrivingVo javaObject = new AccidentalDrivingVo(); if(!Objects.isNull(quoteVo.getAccidentalDrivingVo())) { JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); javaObject= jsonObject.toJavaObject(AccidentalDrivingVo.class); } BeanUtils.copyProperties(quoteVo,quoteVo1); quoteVo1.setAccidentalDrivingVo(javaObject); respVo = huaTaiOrderApiService.quote(quoteInfo, quoteVo1); } if("DJPC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ respVo = daJiaOrderService.quote(quoteInfo, quoteVo); } if("BPIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ BaseQuoteVo> quoteVo1 = new BaseQuoteVo<>(); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); BeanUtils.copyProperties(quoteVo, quoteVo1); if(jsonObject.size() > 0) { BoHaiQuoteAccidentVo javaObject = new BoHaiQuoteAccidentVo(); javaObject.setPackageCode(jsonObject.getString("projectCode")); javaObject.setProductCode(jsonObject.getString("riskCode")); javaObject.setCopies(jsonObject.getString("quantity")); List javaObjectList = new ArrayList<>(); javaObjectList.add(javaObject); quoteVo1.setAccidentalDrivingVo(javaObjectList); }else{ quoteVo1.setAccidentalDrivingVo(new ArrayList<>()); } respVo = boHaiOrderApiService.quote(quoteInfo, quoteVo1); } if("CHAC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ BaseQuoteVo quoteVo1 = new BaseQuoteVo<>(); InsDrivingIntentionInsurance javaObject = new InsDrivingIntentionInsurance(); if(!Objects.isNull(quoteVo.getAccidentalDrivingVo())) { JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); javaObject = jsonObject.toJavaObject(InsDrivingIntentionInsurance.class); BeanUtils.copyProperties(quoteVo,quoteVo1); if(StringUtils.isNotBlank(javaObject.getProjectCode())){ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(InsDrivingIntentionInsurance::getProjectCode,javaObject.getProjectCode()); InsDrivingIntentionInsurance insDrivingIntentionInsurance = insDrivingIntentionInsuranceService.getOne(wrapper); if (StringUtils.isNotBlank(insDrivingIntentionInsurance.getRelateCode())){ javaObject.setProjectCode(insDrivingIntentionInsurance.getRelateCode()); quoteVo1.setAccidentalDrivingVo(javaObject); }else{ throw new SystemException("驾意险失效,请检查方案配置"); } }else{ quoteVo1.setAccidentalDrivingVo(javaObject); } } respVo = chengTaiOrderApiService.quoteApi(quoteInfo, quoteVo1); } if ("YGBX1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)) { BaseQuoteVo> quoteVo1 = new BaseQuoteVo<>(); JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); BeanUtils.copyProperties(quoteVo, quoteVo1); if(jsonObject.size() > 0) { YgQuoteAccidentVo ygQuoteAccidentVo = new YgQuoteAccidentVo(); ygQuoteAccidentVo.setProductCode(jsonObject.getString("projectCode")); ygQuoteAccidentVo.setQuantityCasualty(jsonObject.getString("quantity")); List javaObjectList = new ArrayList<>(); javaObjectList.add(ygQuoteAccidentVo); quoteVo1.setAccidentalDrivingVo(javaObjectList); } else { quoteVo1.setAccidentalDrivingVo(new ArrayList<>()); } respVo = yangGuangOrderApiService.quote(quoteInfo, quoteVo1); } if("PAIC1000000".equals(ptlAgreementAttribution.getInsCompanyId()) && Objects.isNull(respVo)){ // BaseQuoteVo quoteVo1 = new BaseQuoteVo<>(); // JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(quoteVo.getAccidentalDrivingVo())); // AccidentalDrivingVo javaObject = jsonObject.toJavaObject(AccidentalDrivingVo.class); // BeanUtils.copyProperties(quoteVo,quoteVo1); // quoteVo1.setAccidentalDrivingVo(javaObject); // return pingAnOrderApiService.quote(quoteInfo, quoteVo1); } PtlAgreementAttribution byId = ptlAgreementAttributionService.getById(quoteVo.getAgreementId()); if( respVo != null && !ObjectUtils.isEmpty( respVo.getData() )){ respVo.getData().setApiType(byId.getApiType()); respVo.getData().setOrderstatus("0"); } return respVo; } @PostMapping(value = "submitImage") public HttpResult submitImage(@RequestSingleParam(value = "companyId") String companyId) throws Exception { InsAreaCompany insAreaCompany = insAreaCompanyService.getById(companyId); PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.getById(insAreaCompany.getAgreementId()); if(Objects.isNull(ptlAgreementAttribution) || Objects.isNull(ptlAgreementAttribution.getApiType())){ throw new SystemException("协议数据出错,请联系管理员"); } HttpResult httpResult = null; //判断是否是爬虫 if(ptlAgreementAttribution.getApiType() == 2){ httpResult = insCrawlerOrderService.submitImage(companyId); }else if(ptlAgreementAttribution.getApiType() == 1){ //渤海 if(insAreaCompany.getCompanyId().equals("BPIC1000000")){ httpResult = boHaiOrderApiService.submitImage(companyId); } //大家 if(insAreaCompany.getCompanyId().equals("DJPC1000000")){ httpResult = daJiaOrderService.submitImage(companyId); } //国任 if(insAreaCompany.getCompanyId().equals("XDCX1000000")){ httpResult = guorenOrderApiService.uploadImageApi(companyId); } //华泰 if(insAreaCompany.getCompanyId().equals("HTIC1000000")){ httpResult = huaTaiOrderApiService.submitImage(companyId); } //永安 if(insAreaCompany.getCompanyId().equals("YAIC1000000")){ httpResult = yongAnOrderService.submitImage(companyId); } //永诚 if(insAreaCompany.getCompanyId().equals("AICS1000000")){ httpResult = yongchengOrderApiService.uploadImageApi(companyId); } //中煤 if(insAreaCompany.getCompanyId().equals("ZMBX1000000")){ httpResult = zhongMeiOrderApiService.submitImage(companyId); } //紫金 if(insAreaCompany.getCompanyId().equals("ZKIC1000000")){ httpResult = zijinOrderApiService.submitImage(companyId); } //诚泰 if(insAreaCompany.getCompanyId().equals("CHAC1000000")){ httpResult = chengTaiOrderApiService.submitImages(companyId); } //阳光 if (insAreaCompany.getCompanyId().equals("YGBX1000000")) { httpResult = yangGuangOrderApiService.upload(companyId); } } return httpResult; } @PostMapping(value = "batchOrderStatus") public HttpResult batchOrderStatus(@RequestSingleParam("orderNos") List orderNos) throws Exception { List list = insAreaCompanyService.list(new LambdaQueryWrapper() .in(InsAreaCompany::getId, orderNos)); list.forEach(item -> { //如果是爬虫的 先调用爬虫的查询订单状态 if (Objects.isNull(item.getApiType()) || item.getApiType() == 2) { try { insCrawlerOrderService.verifyPayment(item.getId()); }catch (Exception e){ } } if (item.getCompanyId().equals("AICS1000000") && item.getApiType() == 1) { try { yongchengOrderApiService.callbackAnOrder(item.getId()); }catch (Exception e){ } } else if (item.getCompanyId().equals("ZMBX1000000") && item.getApiType() == 1) { try { zhongMeiOrderApiService.paymentEnquiry(item.getId()); }catch (Exception e){} } else if (item.getCompanyId().equals("ZKIC1000000")) { try { zijinOrderApiService.auditStatusQuery(item.getId()); }catch (Exception e){} } else if (item.getCompanyId().equals("XDCX1000000")) { try { guorenOrderApiService.pay(item.getId()); }catch (Exception e){} } else if (item.getCompanyId().equals("YGBX1000000")) { try { yangGuangOrderApiService.paymentCallback(item.getId()); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } else if (item.getCompanyId().equals("HTIC1000000")) { try { huaTaiOrderApiService.paymentEnquiry(item.getId()); }catch (Exception e){} } else if (item.getCompanyId().equals("DJPC1000000")) { try { daJiaOrderService.verifyPayment(item.getId()); }catch (Exception e){} } else if (item.getCompanyId().equals("CHAC1000000")) { try { chengTaiOrderApiService.getPayUrl(item.getId()); } catch (Exception e) { throw new RuntimeException(e); } } else if (item.getCompanyId().equals("BPIC1000000")) { try { boHaiOrderApiService.auditStatusQuery(item.getId()); } catch (Exception e) { throw new RuntimeException(e); } } }); return HttpResult.ok("查询成功"); } }