package com.ydtech.modules.order.controller; import com.alibaba.fastjson.JSON; 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.constants.enums.InsuranceRisk; import com.ydtech.constants.enums.dict.agreement.ProductsType; 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.InsOrders; 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.zj.ZjQuoteAccidentVo; import com.ydtech.modules.order.service.*; import com.ydtech.modules.protocol.constants.TaxSourceStatusConstants; import com.ydtech.modules.protocol.dao.PtlTaxSourceNewMapper; import com.ydtech.modules.protocol.entity.constants.PtlApiType; import com.ydtech.modules.protocol.entity.dto.TaxSourceExcludeDto; import com.ydtech.modules.protocol.entity.po.PtlAgreementAttribution; import com.ydtech.modules.protocol.entity.po.PtlTaxSourceNew; 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.stereotype.Controller; 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.LocalDate; 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 YongAnOrderService yongAnOrderService; @Autowired PtlAgreementService ptlAgreementService; @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()); LocalDate currentDate = LocalDate.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("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()); } 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); } } return httpResult; } }