Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/test' into test

zhaoxian 2 anni fa
parent
commit
e1f4431782

+ 49 - 5
ruixuan-common/src/main/java/com/ruixuan/common/core/redis/RedisCache.java

@@ -1,16 +1,17 @@
 package com.ruixuan.common.core.redis;
 
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
+
+import com.ruixuan.common.utils.DateUtils;
+import com.ruixuan.common.utils.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.BoundSetOperations;
 import org.springframework.data.redis.core.HashOperations;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ValueOperations;
+import org.springframework.data.redis.support.atomic.RedisAtomicLong;
 import org.springframework.stereotype.Component;
 
 /**
@@ -243,4 +244,47 @@ public class RedisCache
     {
         return redisTemplate.keys(pattern);
     }
+
+
+    /**
+     * 获取 自增流水
+     * @return
+     */
+    public String getFlowCode(){
+        String currentDate = DateUtils.formatDate(new Date(), DateUtils.YYYYMMDD);
+        Long num = getIncrementNum("salesLeads:robotTask:str"+currentDate);
+        String flowCode = getSequence(num);
+        //System.out.println("taskId------->>>>"+currentDate+flowCode);
+        return flowCode;
+    }
+
+    public Long getIncrementNum(String key){
+        // 不存在准备创建 键值对
+        RedisAtomicLong entityIdCounter = new RedisAtomicLong(key,redisTemplate.getConnectionFactory());
+        Long counter = entityIdCounter.incrementAndGet();
+        if ((null == counter || counter.longValue() == 1)) {// 初始设置过期时间
+            //过期时间为1天
+            entityIdCounter.expire(1, TimeUnit.DAYS);// 单位天
+        }
+        return counter;
+    }
+
+    static final int DEFAULT_LENGTH = 8;
+
+    public String getSequence(long seq) {
+        String str = String.valueOf(seq);
+        int len = str.length();
+        if (len >= DEFAULT_LENGTH) {// 取决于业务规模,应该不会到达8
+            return str;
+        }
+        int rest = DEFAULT_LENGTH - len;
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < rest; i++) {
+            sb.append('0');
+        }
+        sb.append(str);
+        return sb.toString();
+    }
+
+
 }

+ 2 - 2
ruixuan-salesLeads/src/main/java/com.ruixuan.salesLeads/controller/SaleClueInfoController.java

@@ -261,10 +261,10 @@ public class SaleClueInfoController extends BaseController {
 
 
     @ApiOperation(value = "外呼机器人-导入号码",notes = "外呼机器人-导入号码")
-    @RateLimiter(count = 1)
+    //@RateLimiter(count = 1)
     @PostMapping(value = "/importRobotTelephone")
     public ResultResponse importRobotTelephone(@ApiParam(value = "卖家ids") @RequestParam(value = "sellerIds") List<Long> sellerIds,
-                                               @ApiParam(value = "用户id") @RequestParam(value = "userId") String userId){
+                                               @ApiParam(value = "用户id") @RequestParam(value = "userId") String userId) throws Exception {
         if (sellerIds.size() > 5000){
             return ResultResponse.error("单次最大导入号码数量不能超过5000条!");
         }

+ 1 - 1
ruixuan-salesLeads/src/main/java/com.ruixuan.salesLeads/mapper/SaleClueCallRecordMapper.java

@@ -21,6 +21,6 @@ public interface SaleClueCallRecordMapper {
 
     List<SaleClueCallRecordPojo> getSaleClueCallRecordInfo();
 
-    void updateCallRecordUser(String userId);
+    void updateCallRecordUser(@Param("userId") String userId,@Param("taskId") String taskId);
 
 }

+ 1 - 1
ruixuan-salesLeads/src/main/java/com.ruixuan.salesLeads/service/ITelephoneRobotService.java

@@ -21,7 +21,7 @@ public interface ITelephoneRobotService {
 
     JSONObject getTelephoneRobotToken();
 
-    ResultResponse importRobotTelephone(List<Long> sellerIds,String userId);
+    ResultResponse importRobotTelephone(List<Long> sellerIds,String userId) throws Exception;
 
     ResultResponse getRobotTelephoneRecordList();
 

+ 18 - 16
ruixuan-salesLeads/src/main/java/com.ruixuan.salesLeads/service/impl/TelephoneRobotServiceImpl.java

@@ -32,10 +32,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -108,21 +105,23 @@ public class TelephoneRobotServiceImpl implements ITelephoneRobotService {
      * @author: zianY
      */
     @Override
-    public ResultResponse importRobotTelephone(List<Long> sellerIds,String userId){
+    public ResultResponse importRobotTelephone(List<Long> sellerIds,String userId) throws Exception{
         Map<String,String> headers = new HashMap<>();
         Map<String,Object> result = new HashMap<>();
-        result.put("taskId",123);
-        result.put("batchId",123);
+        //日期8位数 自增
+        String flowCode = redisCache.getFlowCode();
+        log.info("task------>>>>{}",flowCode);
+        result.put("taskId",flowCode);
+        result.put("batchId",flowCode);
         result.put("callBackUrl",RobotConstant.CALL_BACK_URL);
         result.put("canCover",true);
-
         List customerList = new ArrayList();
         for (Long sellerId : sellerIds) {
             SaleRecordVo saleInfo = saleClueInfoMapper.selectSaleClueInfoBySellerId(sellerId);
             Map<String,Object> param = new HashMap<>();
-            param.put("id",saleInfo.getSellerId());
-            param.put("name",saleInfo.getSellerName());
-            param.put("companyName","");
+            param.put("id",saleInfo.getSellerId().intValue());
+            param.put("name",saleInfo.getSellerId());
+            param.put("companyName",saleInfo.getSellerName());
             param.put("phone","17778037644");
             param.put("website","");
             customerList.add(param);
@@ -145,11 +144,14 @@ public class TelephoneRobotServiceImpl implements ITelephoneRobotService {
             return ResultResponse.error("第三方接口异常,请稍候再试");
         }
 
-        //更新记录 用户
-        saleClueCallRecordMapper.updateCallRecordUser(userId);
-        JSONArray success = jsonObject.getJSONArray("success");
-        JSONArray error = jsonObject.getJSONArray("error");
-        return ResultResponse.successMsg("本次导入记录,成功"+success.size()+"条;失败"+error.size()+"条。",null);
+        Thread.sleep(500);
+        //更新最新的记录 用户信息
+        //1分钟只能调取导入接口一次 所以可以保证最新的记录就是刚通过回调接口回来的数据信息
+        saleClueCallRecordMapper.updateCallRecordUser(userId,flowCode);
+        log.info("------>>>>>>修改用户信息");
+        //JSONArray success = jsonObject.getJSONArray("success");
+        //JSONArray error = jsonObject.getJSONArray("error");
+        return ResultResponse.successMsg("导入记录成功"+customerList.size()+"条",null);
     }
 
 

+ 2 - 1
ruixuan-salesLeads/src/main/resources/mapper/salesLeads/SaleClueCallRecordMapper.xml

@@ -33,7 +33,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<!-- 修改用户id -->
 	<update id="updateCallRecordUser">
 		UPDATE sale_clue_call_record
-		SET create_user_id = #{userId}
+		SET create_user_id = #{userId},
+		    task_id = #{taskId}
 			ORDER BY
 		create_time DESC
 		LIMIT 1