dchen 1 сар өмнө
parent
commit
030ebf1b40

+ 44 - 0
src/main/java/com/tiangua/star/controller/ThirdCallBackController.java

@@ -0,0 +1,44 @@
+package com.tiangua.star.controller;
+
+import com.tiangua.kirin.api.MessageResult;
+import com.tiangua.star.model.ThirdStarDto;
+import com.tiangua.star.model.XdOrderDto;
+import com.tiangua.star.service.CallBackService;
+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
+
+  * @project loan-supermarket-parent
+ * @date 2025/3/21 10:45:49
+ */
+@RestController
+@RequestMapping(value = "/third/callback")
+@Slf4j
+public class ThirdCallBackController {
+
+    @Autowired
+    private CallBackService callBackService;
+
+    @PostMapping("/request")
+    public MessageResult<Integer> request(@RequestBody Map<String, List<ThirdStarDto>> map) {
+        log.info("thirdGainStarData get begin map{}",map);
+        List<ThirdStarDto> data = map.get("data");
+        if (CollectionUtils.isEmpty(data)) {
+            log.info("md5GainStarData 解析回传数据为null");
+            return MessageResult.ok();
+        }
+        callBackService.thirdProcessInstitutionData(data);
+        log.info("thirdGainStarData get end");
+        return MessageResult.ok();
+    }
+}

+ 2 - 1
src/main/java/com/tiangua/star/enmus/CommercialCallBackReadyEnum.java

@@ -12,7 +12,8 @@ public enum CommercialCallBackReadyEnum implements StringCodeable {
     Commercial_CHONGQINGZC("4181", "e955dd0c3177250225021000business", "https://api.zhudaicms.com/api/stars_back.html?brand=1263&orgid=41812&d=1696580106;https://api.zhudaicms.com/api/stars_back.html?brand=1263&orgid=4181&d=1696580106"),//4181重庆众诚 两个星级
     Commercial_BJQN("3781", "1059819706ac240813041124business", "https://api.zhudaicms.com/api/stars_back.html?brand=1556&orgid=%E6%83%A0%E8%9E%8D%E9%92%B1%E5%8C%85&d=1721903031"),//北京签牛企业管理咨询有限公司
     Commercial_NBHX("4303", "a3c7888a1d91250313094409business", "https://api.zhudaicms.com/api/stars_back.html?brand=1280&orgid=4303&d=1700188876"),//宁波垣信信息科技有限公司
-    Commercial_HZ("4212", "496f0859cfe3250228102712business", "https://api.zhudaicms.com/api/stars_back.html?brand=1663&orgid=4212&d=1736049235");//杭州聚壹融商务信息咨询有限公司
+    Commercial_HZ("4212", "496f0859cfe3250228102712business", "https://api.zhudaicms.com/api/stars_back.html?brand=1663&orgid=4212&d=1736049235"),//杭州聚壹融商务信息咨询有限公司
+    Commercial_DAQN("4381", "445982746008128business", "http://47.113.122.223:8001/api/xiaoan/queryByUniqueId");//大连青柠
 
     private String code;
     private String busid;

+ 25 - 0
src/main/java/com/tiangua/star/model/ThirdStarDto.java

@@ -0,0 +1,25 @@
+package com.tiangua.star.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+@Data
+@AllArgsConstructor
+public class ThirdStarDto implements Serializable {
+    private String busiId;
+    private String productBizId;
+    private String phoneMd5;
+    private String uniqueIdentify;
+
+    public ThirdStarDto(String productBizId, String phoneMd5) {
+        this.productBizId = productBizId;
+        this.phoneMd5 = phoneMd5;
+    }
+
+    public ThirdStarDto() {
+    }
+
+}

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

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

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

@@ -5,6 +5,7 @@ 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.ThirdStarDto;
 import com.tiangua.star.model.XdOrderDto;
 import com.tiangua.star.service.CallBackService;
 import com.tiangua.star.util.HttpClientThreeUtil;
@@ -19,11 +20,15 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -137,6 +142,15 @@ public class CasllBackDataProcessor implements CallBackService {
                                     commercialCallBackReadyEnum.getBusid(),urlTemp,"重庆众诚");
                         }
                         break;
+                    case Commercial_DAQN:
+                        List<String> md5ListDAQN = callBackMap.get(productBizId);
+                        log.info("开始处理机构id:{},大连青柠 当日订单数:{},条数:{}", productBizId,md5ListDAQN,md5ListDAQN.size());
+                        if (CollectionUtils.isEmpty(md5ListDAQN)) {
+                            return;
+                        }
+//                        sendGetRequestHz(commercialCallBackReadyEnum.getCode(),
+//                                commercialCallBackReadyEnum.getBusid(),urlTemp,"大连青柠");
+                        break;
 //                    case Commercial_Test:
 //                        log.info("开始处理机构id:{}", busiId);
 //                        List<String> md5List2 = callBackMap.get(busiId);
@@ -155,6 +169,45 @@ public class CasllBackDataProcessor implements CallBackService {
 
     }
 
+    @Override
+    public void thirdProcessInstitutionData(List<ThirdStarDto> thirdStarDtos) {
+        if (CollectionUtils.isEmpty(thirdStarDtos)) {
+            log.info("thirdStarDtos 解析回传数据为null");
+            return;
+        }
+
+        Map<String, List<String>> groupedByBusiId = thirdStarDtos.stream()
+                .collect(Collectors.groupingBy(
+                        ThirdStarDto::getProductBizId,
+                        Collectors.mapping(ThirdStarDto::getPhoneMd5, 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("已经对接third星级回传的机构id:{}", callBackMap.keySet());
+        if (CollectionUtils.isEmpty(callBackMap.keySet())) {
+            log.info("third 无需要处理的星级回传:{}", callBackMap.keySet());
+            return;
+        }
+
+        for (String productBizId : callBackMap.keySet()) {
+            CommercialCallBackReadyEnum commercialCallBackReadyEnum = CommercialCallBackReadyEnum.of(productBizId);
+            if (commercialCallBackReadyEnum != null) {
+                switch (commercialCallBackReadyEnum) {
+                    case Commercial_DAQN:
+                        if (CollectionUtils.isEmpty(thirdStarDtos)) {
+                            return;
+                        }
+                        sendDalian(commercialCallBackReadyEnum.getCode(),
+                                commercialCallBackReadyEnum.getBusid(),
+                                commercialCallBackReadyEnum.getUrl(),thirdStarDtos);
+                        break;
+
+                }
+            }
+        }
+    }
+
 
     private void sendGetRequestSXRKX(String productBizId,String busiId,String url){
         JSONObject param = SignUtil.generateSign(81, 43, "730969D3F673BA42432C574378B9A8F1");
@@ -283,6 +336,103 @@ public class CasllBackDataProcessor implements CallBackService {
 
     }
 
+    private void sendDalian(String productBizId,String busiId,String url,List<ThirdStarDto> thirdStarDtos){
+        if (CollectionUtils.isEmpty(thirdStarDtos)) {
+            return;
+        }
+        List<CustomerFollowup> list = new ArrayList<>();
+        Map<String, String> map = new HashMap();
+        JSONObject response = null;
+        String joined = thirdStarDtos.stream()
+                .map(ThirdStarDto::getUniqueIdentify)
+                .collect(Collectors.joining(","));
+
+        map.put("app_id", "45");
+        map.put("timestamp", String.valueOf(System.currentTimeMillis()/1000));
+        map.put("unique_id", joined);
+        String sign = makeSign(map, "THITVXdSPQRQzArVwtssyD4uMdQIUxEY");
+        map.put("sign", sign);
+        log.info("【大连青宁】请求前参数:{}",map);
+        String responseStr = HttpClientThreeUtil.post(url, JSON.toJSONString(map));
+        response = JSON.parseObject(responseStr);
+        log.info("【大连青宁】响应数据:{}",response);
+        if (response.getInteger("code") == 200) {
+            JSONArray data = response.getJSONArray("data");
+
+            Map<String, ThirdStarDto> dtoMap = thirdStarDtos.stream()
+                    .collect(Collectors.toMap(ThirdStarDto::getUniqueIdentify, Function.identity(), (a, b) -> a));
+
+            for (int i = 0; i < data.size(); i++) {
+                JSONObject obj = data.getJSONObject(i);
+                String uniqueId = obj.getString("unique_id");
+                Integer star = obj.getInteger("star");
+
+                ThirdStarDto dto = dtoMap.get(uniqueId);
+                if (dto != null) {
+                    CustomerFollowup followup = new CustomerFollowup();
+                    followup.setStarLevel(new BigDecimal(star));
+                    followup.setPhoneMd5(dto.getPhoneMd5());
+                    followup.setBusiId(busiId);
+                    followup.setProductBizId(Integer.parseInt(productBizId));
+                    followup.setFollowTime(new Date());
+                    followup.setSourceType(3);
+                    list.add(followup);
+                } else {
+                    log.warn("未匹配到 unique_id={} 对应的 ThirdStarDto", uniqueId);
+                }
+            }
+        }
+        log.info("busiId:{} 处理数据条:{}", busiId, list.size());
+        handleMappedData(busiId,list);
+    }
+
+    public static void main(String[] args) {
+        Map<String, String> map = new HashMap();
+        map.put("app_id", "45");
+        map.put("timestamp", String.valueOf(System.currentTimeMillis()/1000));
+        map.put("unique_id", "hryk1744092978");
+        String sign = makeSign(map, "THITVXdSPQRQzArVwtssyD4uMdQIUxEY");
+        map.put("sign", sign);
+        System.out.println(map);
+    }
+    public static String makeSign(Map<String, String> args, String token) {
+        if (args == null || token == null) {
+            return "";
+        }
+
+        Map<String, String> sortedArgs = new TreeMap<>(args);
+
+        StringBuilder signStr = new StringBuilder();
+        for (Map.Entry<String, String> entry : sortedArgs.entrySet()) {
+            String key = entry.getKey();
+            String value = entry.getValue();
+            if (value != null && !value.isEmpty()) {
+                signStr.append(key).append(value);
+            }
+        }
+
+        System.out.println(signStr.toString());
+
+        return md5(md5(signStr.toString()) + token).toUpperCase();
+    }
+
+    private static String md5(String str) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            md.update(str.getBytes());
+            byte[] digest = md.digest();
+
+            StringBuilder sb = new StringBuilder();
+            for (byte b : digest) {
+                sb.append(String.format("%02x", b & 0xff));
+            }
+
+            return sb.toString();
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+            return "";
+        }
+    }
 
     private void sendGetRequest(String productBizId,String busiId,String url,List<String> md5s){
         List<CustomerFollowup> list = new ArrayList<>();

+ 305 - 0
src/main/java/com/tiangua/star/util/RedisUtil.java

@@ -0,0 +1,305 @@
+package com.tiangua.star.util;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ValueOperations;
+import org.springframework.data.redis.core.script.DefaultRedisScript;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * redicache 工具类
+ */
+@SuppressWarnings("unchecked")
+@Component
+public class RedisUtil {
+    @SuppressWarnings("rawtypes")
+    @Autowired
+    public RedisTemplate redisTemplate;
+
+    @Autowired(required = false)
+    public void setRedisTemplate(RedisTemplate redisTemplate) {
+        RedisSerializer stringSerializer = new StringRedisSerializer();
+        redisTemplate.setKeySerializer(stringSerializer);
+        redisTemplate.setValueSerializer(stringSerializer);
+        redisTemplate.setHashKeySerializer(stringSerializer);
+        redisTemplate.setHashValueSerializer(stringSerializer);
+        this.redisTemplate = redisTemplate;
+    }
+
+    /**
+     * 批量删除对应的value
+     *
+     * @param keys
+     */
+    public void remove(final String... keys) {
+        for (String key : keys) {
+            remove(key);
+        }
+    }
+
+    /**
+     * 批量删除key
+     *
+     * @param pattern
+     */
+    public void removePattern(final String pattern) {
+        Set<Serializable> keys = redisTemplate.keys(pattern + "*");
+        if (keys.size() > 0)
+            redisTemplate.delete(keys);
+    }
+
+    /**
+     * 删除对应的value
+     *
+     * @param key
+     */
+    public void remove(final String key) {
+        if (exists(key)) {
+            redisTemplate.delete(key);
+        }
+    }
+
+    /**
+     * 判断缓存中是否有对应的value
+     *
+     * @param key
+     * @return
+     */
+    public boolean exists(final String key) {
+        return redisTemplate.hasKey(key);
+    }
+
+    /**
+     * 读取缓存
+     *
+     * @param key
+     * @return
+     */
+    public String get(final String key) {
+        Object result = null;
+        redisTemplate.setValueSerializer(new StringRedisSerializer());
+        ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
+        result = operations.get(key);
+        if (result == null) {
+            return null;
+        }
+        return result.toString();
+    }
+
+    /**
+     * @param key
+     * @return
+     */
+    public Map<Integer, Integer> keysForLimit(String key) {
+        Set valueSet = redisTemplate.keys(key);
+        Map<Integer, Integer> resultMap = new HashMap<>();
+        if (valueSet.isEmpty()) {
+            return resultMap;
+        } else {
+            for (Object redisKey : valueSet) {
+                Object value = redisTemplate.opsForValue().get(redisKey);
+                String productId = redisKey.toString().split(":")[1];
+                resultMap.put(Integer.valueOf(productId), Integer.valueOf(value.toString()));
+            }
+            return resultMap;
+        }
+    }
+
+    public Map<Integer, Integer> getCacheProduct(String key) {
+        Map<Integer, Integer> map = new HashMap<>();
+        Map entries = redisTemplate.opsForHash().entries(key);
+        for (Object entryKey : entries.keySet()) {
+            Object value = entries.get(entryKey);
+            map.put(Integer.valueOf(entryKey.toString()), Integer.valueOf(value.toString()));
+        }
+        return map;
+    }
+
+    /**
+     * 写入缓存
+     *
+     * @param key
+     * @param value
+     * @return
+     */
+    public boolean set(final String key, Object value) {
+        boolean result = false;
+        try {
+            ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
+            operations.set(key, value);
+            result = true;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    /**
+     * 写入缓存
+     *
+     * @param key
+     * @param value
+     * @param expireTime 分钟
+     * @return
+     */
+    public boolean set(final String key, Object value, Long expireTime) {
+        boolean result = false;
+        try {
+            ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
+            operations.set(key, value);
+            redisTemplate.expire(key, expireTime, TimeUnit.MINUTES);
+            result = true;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    /**
+     * 设置Key 过期时间
+     *
+     * @param key
+     * @param expireTime 分钟
+     */
+    public void expire(final String key, Long expireTime) {
+        if (redisTemplate.hasKey(key)) {
+            redisTemplate.expire(key, expireTime, TimeUnit.MINUTES);
+        }
+    }
+
+    public void expireSECONDS(final String key, Long expireTime) {
+        if (redisTemplate.hasKey(key)) {
+            redisTemplate.expire(key, expireTime, TimeUnit.SECONDS);
+        }
+    }
+
+    public boolean hmset(String key, Map<String, String> value) {
+        boolean result = false;
+        try {
+            redisTemplate.opsForHash().putAll(key, value);
+            result = true;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public Map<String, String> hmget(String key) {
+        Map<String, String> result = null;
+        try {
+            result = redisTemplate.opsForHash().entries(key);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+
+    public boolean hmSetOne(String key, String code, String value) {
+        boolean result = false;
+        try {
+            redisTemplate.opsForHash().put(key, code, value);
+            result = true;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public Object hmGet(String key, String code) {
+        return redisTemplate.opsForHash().get(key, code);
+    }
+
+    public Map hashEntries(String key){
+        Map entries = redisTemplate.opsForHash().entries(key);
+        return entries;
+    }
+
+    public void hmdel(String key, String removeKey) {
+        try {
+            redisTemplate.opsForHash().delete(key, removeKey);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public Long sadd(String key, Object... objects) {
+        return redisTemplate.opsForSet().add(key, objects);
+    }
+
+    public Set smembers(String key) {
+        return redisTemplate.opsForSet().members(key);
+    }
+
+    public void srem(String key, Object... value) {
+        redisTemplate.opsForSet().remove(key, value);
+    }
+
+    /**
+     * value类型key对应的值自增1
+     *
+     * @param key
+     */
+    public void incrementForValue(String key) {
+        redisTemplate.opsForValue().increment(key);
+    }
+
+
+    public Boolean hasKey(String key) {
+        return redisTemplate.hasKey(key);
+    }
+
+    public boolean hset(String key, Object item, Object value, long time) {
+        try {
+            redisTemplate.opsForHash().put(key, item, value);
+            if (time > 0) {
+                expireSECONDS(key, time);
+            }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    public boolean hSetIfAbsent(String key, Object item, Object value, long time) {
+        try {
+            redisTemplate.opsForHash().putIfAbsent(key, item, value);
+            if (time > 0) {
+                expireSECONDS(key, time);
+            }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    public void setKeyCurrDayValid(String redisKey, Object value) {
+        LocalDateTime tomorrow = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
+        long seconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), tomorrow);
+        redisTemplate.opsForValue().set(redisKey, value, seconds);
+    }
+
+    public Boolean hashHasKey(String redisKey, String key) {
+      return  redisTemplate.opsForHash().hasKey(redisKey,key);
+    }
+
+
+    public String incrementWithExpiry(String key, long expireSeconds, String luaScript) {
+        DefaultRedisScript<Long> script = new DefaultRedisScript<>(luaScript, Long.class);
+        return (String) redisTemplate.execute(script, redisTemplate.getStringSerializer(), redisTemplate.getValueSerializer(), Collections.singletonList(key), String.valueOf(expireSeconds));
+    }
+
+}