Browse Source

md5星级回传

dchen 6 days ago
parent
commit
35f385c80b

+ 47 - 0
src/main/java/com/tiangua/star/controller/Md5CallBackController.java

@@ -0,0 +1,47 @@
+package com.tiangua.star.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tiangua.kirin.api.MessageResult;
+import com.tiangua.star.model.XdOrderDto;
+import com.tiangua.star.service.CallBackService;
+import com.tiangua.star.service.XinLuService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+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.util.List;
+import java.util.Map;
+
+/**
+ * @author
+ * @description 本应用 +诚易融 需求开发上线一共两天
+ *              流程:诚易融定时任务扫,将api存在starl的http推送过来
+ *                  本应用使用http请求接受,获取数据,并对应星级,然后返回诚意融,不用mq 没有为什么
+  * @project loan-supermarket-parent
+ * @date 2025/3/21 10:45:49
+ */
+@RestController
+@RequestMapping(value = "/md5/callback")
+@Slf4j
+public class Md5CallBackController {
+
+    @Autowired
+    private CallBackService callBackService;
+
+    @PostMapping("/request")
+    public MessageResult<Integer> request(@RequestBody Map<String,List<XdOrderDto>> map) {
+        log.info("md5GainStarData get begin map{}",map);
+        List<XdOrderDto> data = map.get("data");
+        if (CollectionUtils.isEmpty(data)) {
+            log.info("md5GainStarData 解析回传数据为null");
+            return MessageResult.ok();
+        }
+        callBackService.processInstitutionData(data);
+        log.info("md5GainStarData get end");
+        return MessageResult.ok();
+    }
+}

+ 30 - 0
src/main/java/com/tiangua/star/enmus/CommercialCallBackReadyEnum.java

@@ -0,0 +1,30 @@
+package com.tiangua.star.enmus;
+
+import com.tiangua.kirin.api.StringCodeable;
+import com.tiangua.kirin.utils.EnumUtils;
+
+public enum CommercialCallBackReadyEnum implements StringCodeable {
+
+    Commercial_ONE("11", "www.baidu.com");//六安
+
+    private String code;
+    private String url;
+
+    CommercialCallBackReadyEnum(String code, String url) {
+        this.code = code;
+        this.url = url;
+    }
+
+    public static CommercialCallBackReadyEnum of(String code) {
+        return EnumUtils.stringValueOf(CommercialCallBackReadyEnum.class, code);
+    }
+
+    @Override
+    public String getCode() {
+        return this.code;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+}

+ 62 - 0
src/main/java/com/tiangua/star/model/CustomerFollowup.java

@@ -0,0 +1,62 @@
+package com.tiangua.star.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 客户跟进中间表
+ *
+ * @author zhangyy
+ * @date 2025.03.20 14:14
+ */
+@Data
+public class CustomerFollowup implements Serializable {
+
+    @ApiModelProperty(value = "主键ID")
+    private Integer id;
+
+    @ApiModelProperty(value = "产品商务Id")
+    private Integer productBizId;
+
+    @ApiModelProperty("组织id")
+    private String busiId;
+
+    @ApiModelProperty(value = "客户名称")
+    private String customerName;
+
+    @ApiModelProperty(value = "掩码手机号")
+    private String maskPhone;
+
+    @ApiModelProperty(value = "手机MD5")
+    private String phoneMd5;
+
+    @ApiModelProperty(value = "时间")
+    private Date followTime;
+
+    @ApiModelProperty(value = "星级(可能为小数)")
+    private BigDecimal starLevel;
+
+    @ApiModelProperty(value = "跟进状态")
+    private String followStatus;
+
+    @ApiModelProperty(value = "跟进备注")
+    private String followRemark;
+
+    @ApiModelProperty(value = "来源: 1-(新鹿-h5页面); 2-庆余; 3-其他; 4-excel")
+    private Integer sourceType;
+
+    @ApiModelProperty(value = "orderId")
+    private Integer orderId;
+
+    private Long userId;
+
+}

+ 16 - 0
src/main/java/com/tiangua/star/model/XdOrderDto.java

@@ -0,0 +1,16 @@
+package com.tiangua.star.model;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class XdOrderDto implements Serializable {
+    private String busiId;
+    private String mobileMd5;
+
+    public XdOrderDto(String busiId, String mobileMd5) {
+        this.busiId = busiId;
+        this.mobileMd5 = mobileMd5;
+    }
+}

+ 9 - 0
src/main/java/com/tiangua/star/service/CallBackService.java

@@ -0,0 +1,9 @@
+package com.tiangua.star.service;
+
+import com.tiangua.star.model.XdOrderDto;
+
+import java.util.List;
+
+public interface CallBackService {
+    void processInstitutionData(List<XdOrderDto> xdOrderDtos);
+}

+ 136 - 0
src/main/java/com/tiangua/star/service/impl/CasllBackDataProcessor.java

@@ -0,0 +1,136 @@
+package com.tiangua.star.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.tiangua.star.enmus.CommercialCallBackReadyEnum;
+import com.tiangua.star.model.CustomerFollowup;
+import com.tiangua.star.model.UserStarFollowCallbackParam;
+import com.tiangua.star.model.XdOrderDto;
+import com.tiangua.star.model.XinLuUserStarCallbackParam;
+import com.tiangua.star.service.CallBackService;
+import com.tiangua.star.service.XinLuService;
+import com.tiangua.star.util.HttpClientThreeUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class CasllBackDataProcessor implements CallBackService {
+
+    // HTTP请求工具
+    private static final CloseableHttpClient httpClient = HttpClients.createDefault();
+
+
+    @Value("${md5.callback.url}")
+    private String url;
+
+    /**
+     * 处理机构数据入口
+     */
+    @Override
+    public void processInstitutionData(List<XdOrderDto> xdOrderDtos) {
+        Map<String, List<String>> groupedByBusiId = xdOrderDtos.stream()
+                .collect(Collectors.groupingBy(
+                        XdOrderDto::getBusiId,
+                        Collectors.mapping(XdOrderDto::getMobileMd5, Collectors.toList())
+                ));
+        Map<String, List<String>> callBackMap = groupedByBusiId.entrySet().stream()
+                .filter(entry -> CommercialCallBackReadyEnum.of(entry.getKey()) != null)
+                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+        log.info("已经对接md5星级回传的机构id:{}", callBackMap.keySet());
+
+        for (String busiId : callBackMap.keySet()) {
+            CommercialCallBackReadyEnum commercialCallBackReadyEnum = CommercialCallBackReadyEnum.of(busiId);
+            if (commercialCallBackReadyEnum != null) {
+                switch (commercialCallBackReadyEnum) {
+                    case Commercial_ONE:
+                        log.info("开始处理机构id:{}", busiId);
+                        List<String> md5List = callBackMap.get(busiId);
+                        if (CollectionUtils.isEmpty(md5List)) {
+                            return;
+                        }
+                        sendGetRequest(CommercialCallBackReadyEnum.Commercial_ONE.getCode(),
+                                busiId,commercialCallBackReadyEnum.getUrl(),md5List);
+                        break;
+
+                }
+            }
+        }
+
+
+
+
+    }
+
+    private void sendGetRequest(String productBizId,String busiId,String url,List<String> md5s){
+        List<CustomerFollowup> list = new ArrayList<>();
+        JSONObject map = new JSONObject();
+        JSONObject response = null;
+        for (String md5 : md5s) {
+            map.put("customer_phone", md5);
+            map.put("customer_source", "");
+            String responseStr = HttpClientThreeUtil.post(url, map.toJSONString());
+            response = JSON.parseObject(responseStr);
+            if (response.getInteger("code") == 1) {
+                JSONObject data = response.getJSONObject("data");
+                CustomerFollowup param = new CustomerFollowup();
+
+                JSONArray logList = data.getJSONArray("log_list");
+                if (CollectionUtils.isNotEmpty(logList)) {
+                    StringBuilder result = new StringBuilder();
+                    for (int i = 0; i < logList.size(); i++) {
+                        JSONObject logEntry = logList.getJSONObject(i);
+                        String logTime = logEntry.getString("log_time");
+                        String content = logEntry.getString("content");
+                        result.append(logTime).append("-").append(content);
+                        if (i < logList.size() - 1) {
+                            result.append(";");
+                        }
+                    }
+                    param.setFollowRemark(result.toString());
+                }
+                param.setPhoneMd5(md5);
+                param.setStarLevel(data.getBigDecimal("customer_starlevel"));
+                param.setProductBizId(Integer.getInteger(productBizId));
+                param.setBusiId(busiId);
+                param.setSourceType(3);
+                list.add(param);
+            }
+        }
+        log.info("busiId:{} 处理数据条:{}", busiId, list.size());
+        handleMappedData(list);
+    }
+
+
+
+    private void handleMappedData(List<CustomerFollowup> data) {
+        log.info("【CasllBackDataProcessor】成功处理 {} 条映射数据 明细:{}", data.size(), data);
+        String post = HttpClientThreeUtil.post(url, JSON.toJSONString(data));
+        log.info("【CasllBackDataProcessor】post结果:{}", post);
+    }
+
+
+
+}

+ 63 - 0
src/main/java/com/tiangua/star/util/HttpClientUtil.java

@@ -0,0 +1,63 @@
+package com.tiangua.star.util;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.*;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+
+public class HttpClientUtil {
+
+    /**
+     * 发送 GET 请求
+     *
+     * @param url 请求的 URL
+     * @return 响应内容
+     * @throws IOException 如果发生 I/O 异常
+     */
+    public static String sendGet(String url) throws IOException {
+        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+            HttpGet httpGet = new HttpGet(url);
+            return executeRequest(httpClient, httpGet);
+        }
+    }
+
+    /**
+     * 发送 POST 请求,参数以 JSON 格式发送
+     *
+     * @param url        请求的 URL
+     * @param jsonParams JSON 格式的字符串参数
+     * @return 响应内容
+     * @throws IOException 如果发生 I/O 异常
+     */
+    public static String sendPost(String url, String jsonParams) throws IOException {
+        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+            HttpPost httpPost = new HttpPost(url);
+            if (jsonParams != null) {
+                StringEntity entity = new StringEntity(jsonParams, ContentType.APPLICATION_JSON);
+                httpPost.setEntity(entity);
+            }
+            return executeRequest(httpClient, httpPost);
+        }
+    }
+
+    /**
+     * 执行 HTTP 请求并返回响应内容
+     *
+     * @param httpClient  HttpClient 实例
+     * @param httpRequest HTTP 请求对象
+     * @return 响应内容
+     * @throws IOException 如果发生 I/O 异常
+     */
+    private static String executeRequest(CloseableHttpClient httpClient, HttpUriRequest httpRequest) throws IOException {
+        try (CloseableHttpResponse response = httpClient.execute(httpRequest)) {
+            HttpEntity entity = response.getEntity();
+            return entity != null ? EntityUtils.toString(entity, StandardCharsets.UTF_8) : null;
+        }
+    }
+}

+ 3 - 0
src/main/resources/application-pre.yml

@@ -2,3 +2,6 @@ xinlu:
   callback:
     url: https://loan-web-api2.internal.jiebide.xin/xinlu/callback
 
+md5:
+  callback:
+    url: https://loan-web-api2.internal.jiebide.xin/md5/star/callback

+ 5 - 1
src/main/resources/application-prod.yml

@@ -1,3 +1,7 @@
 xinlu:
   callback:
-    url: https://api.hrshuke.cn/xinlu/callback
+    url: https://api.hrshuke.cn/xinlu/callback
+
+md5:
+  callback:
+    url: https://api.hrshuke.cn/md5/star/callback