Ver código fonte

永诚获取协商价比例

Qchen 1 ano atrás
pai
commit
20cfb8d1cb

+ 7 - 3
src/main/java/com/ydtech/modules/ins/model/yc/ruote/Ruote.java

@@ -156,7 +156,7 @@ public class Ruote {
      * @date: 2023年02月08日 0008
      */
     public static Ruote buildQuoteParam(YaQuoteInfoVo yaQuoteInfoVo, YcConfigureParameters ycConfigureParameters,
-                                        AccidentalDrivingVo adVo,String cQryCdeJQ,String cQryCdeSY) {
+                                        AccidentalDrivingVo adVo,String cQryCdeJQ,String cQryCdeSY,String negotiatedPrice) {
 
         Ruote m = new Ruote();
         Ruote.RequestLabel requestLabel = new Ruote.RequestLabel();
@@ -196,9 +196,13 @@ public class Ruote {
         //折旧价
         String defValue = YcBuildData.getDefValue(new BigDecimal(vhl.getNNewPriceValue()), vhl.getCFstRegYm(), startTime);
         vhl.setNActualValue(defValue);
+        if (negotiatedPrice.equals("0")) {
+            String negotiateThePrice = YcBuildData.getNegotiateThePrice(defValue,  vhl, startTime);
+            vhl.setNNewPurchaseValue(negotiateThePrice);
+        } else {
+            vhl.setNNewPurchaseValue(negotiatedPrice);
+        }
 
-        String negotiateThePrice = YcBuildData.getNegotiateThePrice(defValue,  vhl, startTime);
-        vhl.setNNewPurchaseValue(negotiateThePrice);
         condition.setVhl(vhl);
         /**
          * 车主信息

+ 57 - 0
src/main/java/com/ydtech/modules/order/components/yongcheng/YongchengRequestApiComponents.java

@@ -25,8 +25,10 @@ import com.ydtech.modules.ins.model.yc.ruote.Ruote;
 import com.ydtech.modules.ins.model.yc.ruote.response.RuoteResponse;
 import com.ydtech.modules.order.entity.api.yongcheng.constants.RequestUrl;
 import com.ydtech.modules.order.entity.api.yongcheng.request.AccidentUnderwritingRequest;
+import com.ydtech.modules.order.entity.api.yongcheng.request.PriceDiscountRatioRequest;
 import com.ydtech.modules.order.entity.api.yongcheng.request.ProposalPolicyReturnRequest;
 import com.ydtech.modules.order.entity.api.yongcheng.response.AccidentUnderwritingResponse;
+import com.ydtech.modules.order.entity.api.yongcheng.response.PriceDiscountRatioResponse;
 import com.ydtech.modules.order.utils.InsuranceLog;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.text.StringEscapeUtils;
@@ -89,6 +91,52 @@ public class YongchengRequestApiComponents {
 
         String xmlString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"http://newWS.front" +
                 ".app.echannel.ebiz.alltrust.com/\">";
+//        xmlString += "<soapenv:Header/>";
+
+        xmlString += "<soapenv:Body>";
+
+        xmlString += gainXmlMapper().writeValueAsString(q);
+
+        xmlString += "</soapenv:Body>\n" +
+                "</soapenv:Envelope>";
+
+        InsuranceLog.infoLog(InsuranceEnum.AICS.getPinyin(), "\n\t---------> URl: {} \n---------> 保险公司:{} {}\n---------> 请求参数:{}", url,
+                InsuranceEnum.AICS.getName(), requestUrl.getDesc(), xmlString);
+        HttpEntity<String> httpEntity = new HttpEntity<>(xmlString, httpHeaders);
+
+        ResponseEntity<String> response = restTemplate.postForEntity(url, httpEntity, String.class);
+        String body = response.getBody();
+
+        String responseStringMsg = StringEscapeUtils.unescapeXml(body);
+        InsuranceLog.infoLog(InsuranceEnum.AICS.getPinyin(), "\n\n---------> 响应参数:{}", responseStringMsg);
+
+        String cleanStr = YcBuildData.cleanResponseStr(responseStringMsg);
+        if (!cleanStr.contains("<")) {
+            return (S) cleanStr;
+        }
+
+        S bean = gainXmlMapper().readValue(cleanStr, tClass);
+        if (ObjectUtils.isEmpty(bean)) {
+            throw new SystemException("请求失败");
+        }
+
+        return bean;
+    }
+
+    private <Q, S> S post1(Q q, RequestUrl requestUrl, Class<S> tClass) throws JsonProcessingException {
+
+        String url = apiComponents.getUrl() + requestUrl.getUri();
+
+        HttpHeaders httpHeaders = new HttpHeaders();
+        MediaType mediaType = MediaType.parseMediaType("text/xml;charset=UTF-8");
+        httpHeaders.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 " +
+                "Safari/537.36");
+        httpHeaders.setContentType(mediaType);
+
+        String xmlString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:new=\"http://newWS.front" +
+                ".app.echannel.ebiz.alltrust.com/\">";
+        xmlString += "<soapenv:Header/>";
+
         xmlString += "<soapenv:Body>";
 
         xmlString += gainXmlMapper().writeValueAsString(q);
@@ -222,4 +270,13 @@ public class YongchengRequestApiComponents {
         return post(policy, RequestUrl.API_GUARANTEE_SLIP, PolicyResponse.class);
     }
 
+    /**
+     * 获取协商价折扣比例
+     *
+     * @param priceDiscountRatioRequest 获取协商价折扣比例 入参实体
+     * @return 出参实体
+     */
+    public PriceDiscountRatioResponse priceDiscount(PriceDiscountRatioRequest priceDiscountRatioRequest) throws JsonProcessingException {
+        return post1(priceDiscountRatioRequest, RequestUrl.API_PRICE_DISCOUNT_RATIO, PriceDiscountRatioResponse.class);
+    }
 }

+ 2 - 1
src/main/java/com/ydtech/modules/order/controller/YongChengOrderApiController.java

@@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.text.ParseException;
 import java.time.LocalDate;
 import java.util.List;
 
@@ -47,7 +48,7 @@ public class YongChengOrderApiController {
     @QuoteVerification("报价授权")
     @ApiOperation(value = "永诚API方式 - 报价")
     @PostMapping("/quote")
-    public HttpResult quoteApi(@RequestBody BaseQuoteVo<QuoteAccidentalDrivingVo> quoteVo) throws JsonProcessingException {
+    public HttpResult quoteApi(@RequestBody BaseQuoteVo<QuoteAccidentalDrivingVo> quoteVo) throws JsonProcessingException, ParseException {
         BaseQuoteVo<AccidentalDrivingVo> baseQuoteVo = insOrdersService.convertDriving(quoteVo);
         return yongchengOrderApiService.quoteApi(baseQuoteVo);
     }

+ 2 - 1
src/main/java/com/ydtech/modules/order/entity/api/yongcheng/constants/RequestUrl.java

@@ -17,7 +17,8 @@ public enum RequestUrl {
     API_ORDER_QUERY("payCallback", "补传回调及订单信息查询接口"),
     API_UNDERWRITING_RETURNS("returnAppPolicyWebService", "投保单打回接口"),
     API_ACCIDENT("NewQueryYwCvrgWebService", "意外险"),
-    API_SUBMIT_POLICY("SubmitpolicyWebService", "意外险确保接口");
+    API_SUBMIT_POLICY("SubmitpolicyWebService", "意外险确保接口"),
+    API_PRICE_DISCOUNT_RATIO("PriceDiscountService", "获取协商价浮动比例接口");
 
     private final String uri;
 

+ 117 - 0
src/main/java/com/ydtech/modules/order/entity/api/yongcheng/request/PriceDiscountRatioRequest.java

@@ -0,0 +1,117 @@
+package com.ydtech.modules.order.entity.api.yongcheng.request;
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.ydtech.constants.enums.InsurKind;
+import com.ydtech.modules.ins.model.vo.CarInfoVo;
+import com.ydtech.modules.ins.model.vo.KindInfoVo;
+import com.ydtech.modules.ins.model.yc.YcConfigureParameters;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author quchen
+ * @date 2025/1/9 17:55
+ */
+
+@Data
+@JacksonXmlRootElement(localName = "new:GtePriceDiscountService")
+public class PriceDiscountRatioRequest implements Serializable {
+    @JacksonXmlProperty(localName = "request")
+    private RequestDTO request;
+
+    public PriceDiscountRatioRequest(YcConfigureParameters ycConfigureParameters, CarInfoVo carInfoVo,List<KindInfoVo> kindInfoVoList,String startTime) {
+        this.request = new RequestDTO(ycConfigureParameters.getPassword(),
+                ycConfigureParameters.getUserName(),
+                carInfoVo,
+                kindInfoVoList,
+                startTime,
+                ycConfigureParameters.getDptCde());
+    }
+
+    @Data
+    private static class RequestDTO implements Serializable {
+
+        @JacksonXmlProperty(localName = "authorityData")
+        private AuthorityDataDTO authorityData;
+
+        @JacksonXmlProperty(localName = "body")
+        private BodyDTO body;
+
+        public RequestDTO(String password, String username,CarInfoVo carInfoVo, List<KindInfoVo> kindInfoVoList, String startTime, String CDptCde) {
+            this.authorityData = new AuthorityDataDTO(username,password);
+            this.body = new BodyDTO(carInfoVo, kindInfoVoList, startTime, CDptCde);
+        }
+
+        @Data
+        @AllArgsConstructor
+        private static class AuthorityDataDTO implements Serializable {
+            /**
+             * 用户名
+             */
+            @JacksonXmlProperty(localName = "userName")
+            private String userName;
+            /**
+             * 密码
+             */
+            @JacksonXmlProperty(localName = "password")
+            private String password;
+        }
+
+
+        @Data
+        @AllArgsConstructor
+        private static class BodyDTO implements Serializable {
+            /**
+             * 机构
+             */
+            private String CDptCde;
+            /**
+             * 产品号 0364商业 0326交强
+             */
+            private String CProdNo;
+            /**
+             * 初登日期
+             */
+            private String CFstRegYm;
+            /**
+             * 保险起期
+             */
+            private String TInsrncBgnTm;
+            /**
+             * 是否含车损险
+             */
+            private String IsContainDamage;
+            /**
+             * 车架号
+             */
+            private String CFrmNo;
+            /**
+             * 是否过户车标志
+             */
+            private String CChgOwnerFlag;
+
+            public BodyDTO(CarInfoVo carInfoVo, List<KindInfoVo> kindInfoVoList, String startTime, String CDptCde){
+                this.CDptCde = CDptCde;
+                this.CFstRegYm = carInfoVo.getRegisterDate();
+                this.TInsrncBgnTm = startTime;
+                this.IsContainDamage = "1";
+                if (!kindInfoVoList.isEmpty()) {
+                    this.CProdNo = "0364";
+                    kindInfoVoList.forEach(kindInfoVo -> {
+                            if (kindInfoVo.getKindCode().equals(InsurKind.A.getCode())) {
+                                this.IsContainDamage = "0";
+                            }
+                    });
+                } else {
+                    this.CProdNo = "0326";
+                }
+                this.CFrmNo = carInfoVo.getFrameNo();
+                this.CChgOwnerFlag = carInfoVo.isTransferFlag() ? "1" : "0";
+            }
+        }
+    }
+}

+ 29 - 0
src/main/java/com/ydtech/modules/order/entity/api/yongcheng/response/PriceDiscountRatioResponse.java

@@ -0,0 +1,29 @@
+package com.ydtech.modules.order.entity.api.yongcheng.response;
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import lombok.Data;
+
+/**
+ * @author quchen
+ * @date 2025/1/9 18:06
+ */
+
+@Data
+@JacksonXmlRootElement(localName = "ns2:GtePriceDiscountServiceResponse")
+public class PriceDiscountRatioResponse {
+    /**
+     *  返回消息码  E0001失败  E0000成功
+     */
+    private String code;
+
+    /**
+     *  返回信息
+     */
+    private String msg;
+
+    /**
+     * 协商价折扣比例
+     */
+    private String val;
+
+}

+ 2 - 1
src/main/java/com/ydtech/modules/order/service/YongchengOrderApiService.java

@@ -12,6 +12,7 @@ import com.ydtech.modules.order.entity.vo.AccidentalDrivingVo;
 import com.ydtech.modules.order.entity.vo.BaseQuoteVo;
 import com.ydtech.modules.order.entity.vo.PolicyPrintVo;
 
+import java.text.ParseException;
 import java.util.List;
 
 public interface YongchengOrderApiService {
@@ -20,7 +21,7 @@ public interface YongchengOrderApiService {
     /**
      * 2 报价
      */
-    HttpResult quoteApi(BaseQuoteVo<AccidentalDrivingVo> quoteVo) throws JsonProcessingException;
+    HttpResult quoteApi(BaseQuoteVo<AccidentalDrivingVo> quoteVo) throws JsonProcessingException, ParseException;
 
     /**
      * 3 核保

+ 49 - 6
src/main/java/com/ydtech/modules/order/service/impl/YongchengOrderApiServiceImpl.java

@@ -29,6 +29,7 @@ import com.ydtech.modules.ins.model.dto.CarInsPolicyDto;
 import com.ydtech.modules.ins.model.vo.CarInfoVo;
 import com.ydtech.modules.ins.model.vo.CustomerInfoVo;
 import com.ydtech.modules.ins.model.vo.QuoteRespVo;
+import com.ydtech.modules.ins.model.vo.RiskInfoVo;
 import com.ydtech.modules.ins.model.ya.CarModel_Req;
 import com.ydtech.modules.ins.model.yc.CallBackRequest;
 import com.ydtech.modules.ins.model.yc.YcBuildData;
@@ -65,8 +66,10 @@ import com.ydtech.modules.order.entity.InsAreaCompanyExternalPolicy;
 import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.order.entity.api.yongcheng.constants.MessageStatusCode;
 import com.ydtech.modules.order.entity.api.yongcheng.request.AccidentUnderwritingRequest;
+import com.ydtech.modules.order.entity.api.yongcheng.request.PriceDiscountRatioRequest;
 import com.ydtech.modules.order.entity.api.yongcheng.request.ProposalPolicyReturnRequest;
 import com.ydtech.modules.order.entity.api.yongcheng.response.AccidentUnderwritingResponse;
+import com.ydtech.modules.order.entity.api.yongcheng.response.PriceDiscountRatioResponse;
 import com.ydtech.modules.order.entity.crawler.request.RecognitionRequest;
 import com.ydtech.modules.order.entity.crawler.response.RecognitionResponse;
 import com.ydtech.modules.order.entity.dto.DrivingInsuranceDto;
@@ -98,6 +101,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
@@ -261,7 +266,7 @@ public class YongchengOrderApiServiceImpl implements YongchengOrderApiService {
      * @param quoteVo
      * @return
      */
-    private Ruote builderParams(BaseQuoteVo<AccidentalDrivingVo> quoteVo, BaseQuoteInfoVo yaQuoteInfoVo, CoreModelsVo coreModelsVo) {
+    private Ruote builderParams(BaseQuoteVo<AccidentalDrivingVo> quoteVo, BaseQuoteInfoVo yaQuoteInfoVo, CoreModelsVo coreModelsVo,String negotiatedPrice) {
         // 获取协议配置信息
         YcConfigureParameters ycConfigureParameters = gainYcConfigParams(quoteVo.getAgreementId());
         CarInfoVo carInfo = yaQuoteInfoVo.getCarInfo();
@@ -275,7 +280,7 @@ public class YongchengOrderApiServiceImpl implements YongchengOrderApiService {
         String cQryCdeSY = redisTemplate.opsForValue().get(REDIS_YONGCHENG_QUERY_CODE_SY + yaQuoteInfoVo.getUserId() + carInfo.getVinNo() + carInfo.getLicenseNo());
 
         //组装参数
-        Ruote m = Ruote.buildQuoteParam(yaQuoteInfoVo, ycConfigureParameters, adVo, cQryCdeJQ, cQryCdeSY);
+        Ruote m = Ruote.buildQuoteParam(yaQuoteInfoVo, ycConfigureParameters, adVo, cQryCdeJQ, cQryCdeSY,negotiatedPrice);
         //企业车不构建地区
         String property = carInfo.getProperty();
         if (!"2".equals(property)) {
@@ -470,7 +475,7 @@ public class YongchengOrderApiServiceImpl implements YongchengOrderApiService {
      * 2 报价-
      */
     @Override
-    public HttpResult quoteApi(BaseQuoteVo<AccidentalDrivingVo> quoteVo) throws JsonProcessingException {
+    public HttpResult quoteApi(BaseQuoteVo<AccidentalDrivingVo> quoteVo) throws JsonProcessingException, ParseException {
         Integer maxQuoteNum = quoteVo.getMaxQuoteNum();
 
         List<String> requestInfoList = new ArrayList<>();
@@ -483,10 +488,48 @@ public class YongchengOrderApiServiceImpl implements YongchengOrderApiService {
         //查询订单信息
         InsOrders order = insOrdersService.getById(yaQuoteInfoVo.getOrderNo());
 
-        //build参数
-        Ruote m = this.builderParams(quoteVo, yaQuoteInfoVo, coreModelsVo);
-
         List<SysQuoteRecord> sysQuoteRecords = new ArrayList<>();
+
+        BigDecimal negotiatedPrice = null; // 协商价
+        //接口调用前提条件:
+        //旧车,0326/0364, 10座以下非营业个人客车业务”才调该接口查询协商价浮动比例
+        //协商价 = 折旧价*返回的协商价浮动比例
+        if (yaQuoteInfoVo.getCarInfo().getVehicleUse().equals("05") && Integer.parseInt(yaQuoteInfoVo.getCarInfo().getSeatCount()) <= 10 ) {
+            YcConfigureParameters ycConfigureParameters = gainYcConfigParams(quoteVo.getAgreementId());
+            List<RiskInfoVo> riskList = yaQuoteInfoVo.getRiskList();
+            //交强
+            RiskInfoVo ciRiskInfo = riskList.stream().filter(x -> x.getRiskCode().equals(InsuranceRisk.TRAFFIC.getCode())).findFirst().orElse(null);
+            //商业
+            RiskInfoVo biRiskInfo = riskList.stream().filter(x -> x.getRiskCode().equals(InsuranceRisk.BUSINESS.getCode())).findFirst().orElse(null);
+            String startDate; // 起保日期
+            if (biRiskInfo != null) {
+                startDate = biRiskInfo.getStartDate();
+            } else {
+                startDate = ciRiskInfo.getStartDate();
+            }
+            BigDecimal vehiclePrice = new BigDecimal(yaQuoteInfoVo.getCarInfo().getPurchasePrice()); // 新车购置价
+            String registerDate = yaQuoteInfoVo.getCarInfo().getRegisterDate();  // 初登日期
+            //转换日期格式
+            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date startDateAsDate = inputFormat.parse(startDate);
+            String formattedStartDate = outputFormat.format(startDateAsDate);
+
+            BigDecimal depreciationPrice = new BigDecimal(YcBuildData.getDefValue(vehiclePrice, registerDate, formattedStartDate)); // 折旧价
+            PriceDiscountRatioRequest priceDiscountRatioRequest = new PriceDiscountRatioRequest(ycConfigureParameters, yaQuoteInfoVo.getCarInfo(), quoteVo.getKinds(), startDate);
+            PriceDiscountRatioResponse priceDiscountRatioResponse = yongchengRequestApiComponents.priceDiscount(priceDiscountRatioRequest);
+            if (priceDiscountRatioResponse.getCode().equals("E0000")) {
+                if (priceDiscountRatioResponse.getVal() != null) {
+                    // 协商价 = 折旧价 * 返回的协商价浮动比例
+                    negotiatedPrice = depreciationPrice.multiply(new BigDecimal(priceDiscountRatioResponse.getVal())) ;
+                }
+            } else {
+                negotiatedPrice = BigDecimal.ZERO;
+            }
+        }
+
+        //build参数
+        Ruote m = this.builderParams(quoteVo, yaQuoteInfoVo, coreModelsVo, negotiatedPrice.toString());
         //递归报价
         RuoteResponse rr = this.getResponse(m, yaQuoteInfoVo.getCarInfo().getVinNo(), requestInfoList, yaQuoteInfoVo,quoteVo.getCompanyId(),maxQuoteNum,sysQuoteRecords);