leon 5 lat temu
rodzic
commit
4c574fd4c7

+ 6 - 0
src/main/java/com/mokamrp/privates/controller/pangu/PromoteQrcodePoolController.java

@@ -147,6 +147,11 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
             stringRedisTemplate.opsForZSet().add(RedisKey.PanCustServiceIdView + promoteId, Integer.toString(custserviceId), score);
             stringRedisTemplate.opsForZSet().add(RedisKey.PanCustServiceIdView + promoteId, Integer.toString(custserviceId), score);
             return true;
             return true;
         }
         }
+        Long indexDay = stringRedisTemplate.opsForZSet().rank(RedisKey.PanCustServiceIdDayView + promoteId, Integer.toString(custserviceId));
+        if (indexDay == null) {
+            stringRedisTemplate.opsForZSet().add(RedisKey.PanCustServiceIdDayView + promoteId, Integer.toString(custserviceId), score);
+            return true;
+        }
         return false;
         return false;
     }
     }
 
 
@@ -157,6 +162,7 @@ public class PromoteQrcodePoolController extends BaseController<PromoteQrcodePoo
         }
         }
         for (PromoteQrcodePool promoteQrcodePool : res) {
         for (PromoteQrcodePool promoteQrcodePool : res) {
             stringRedisTemplate.opsForZSet().remove(RedisKey.PanCustServiceIdView + Integer.toString(promoteQrcodePool.getPromoteId()), Integer.toString(promoteQrcodePool.getCustserviceId()));
             stringRedisTemplate.opsForZSet().remove(RedisKey.PanCustServiceIdView + Integer.toString(promoteQrcodePool.getPromoteId()), Integer.toString(promoteQrcodePool.getCustserviceId()));
+            stringRedisTemplate.opsForZSet().remove(RedisKey.PanCustServiceIdDayView + Integer.toString(promoteQrcodePool.getPromoteId()), Integer.toString(promoteQrcodePool.getCustserviceId()));
         }
         }
         return true;
         return true;
     }
     }

+ 19 - 3
src/main/java/com/mokamrp/privates/tast/pangu/ResetCustserviceDayViewTask.java

@@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mokamrp.privates.constant.RedisKey;
 import com.mokamrp.privates.constant.RedisKey;
 import com.mokamrp.privates.mapper.pangu.pojo.Playbill;
 import com.mokamrp.privates.mapper.pangu.pojo.Playbill;
 import com.mokamrp.privates.mapper.pangu.pojo.PromoteCode;
 import com.mokamrp.privates.mapper.pangu.pojo.PromoteCode;
+import com.mokamrp.privates.mapper.pangu.pojo.PromoteQrcodePool;
 import com.mokamrp.privates.service.pangu.PlaybillService;
 import com.mokamrp.privates.service.pangu.PlaybillService;
 import com.mokamrp.privates.service.pangu.PromoteCodeService;
 import com.mokamrp.privates.service.pangu.PromoteCodeService;
+import com.mokamrp.privates.service.pangu.PromoteQrcodePoolService;
 import com.mokamrp.privates.utils.http.HttpUtils;
 import com.mokamrp.privates.utils.http.HttpUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.data.redis.core.StringRedisTemplate;
@@ -29,6 +31,9 @@ public class ResetCustserviceDayViewTask {
     public PromoteCodeService promoteCodeService;
     public PromoteCodeService promoteCodeService;
 
 
     @Autowired
     @Autowired
+    public PromoteQrcodePoolService promoteQrcodePoolService;
+
+    @Autowired
     public StringRedisTemplate stringRedisTemplate;
     public StringRedisTemplate stringRedisTemplate;
 
 
     @Scheduled(cron = "0 0 0 * * ?") //.每天0点重置每日个微客服访问量
     @Scheduled(cron = "0 0 0 * * ?") //.每天0点重置每日个微客服访问量
@@ -36,10 +41,21 @@ public class ResetCustserviceDayViewTask {
         System.out.println("[cronjob]:盘古活码个微每日访问量清空");
         System.out.println("[cronjob]:盘古活码个微每日访问量清空");
         List<PromoteCode> promoteCodeList = promoteCodeService.list();
         List<PromoteCode> promoteCodeList = promoteCodeService.list();
         for (PromoteCode promoteCode : promoteCodeList) {
         for (PromoteCode promoteCode : promoteCodeList) {
-            Set<String> members = stringRedisTemplate.opsForZSet().range(RedisKey.PanCustServiceIdDayView+Integer.toString(promoteCode.getId()),0,-1);
-            for (String member : members){
-                stringRedisTemplate.opsForZSet().add(RedisKey.PanCustServiceIdDayView+Integer.toString(promoteCode.getId()), member, 0);
+            List<PromoteQrcodePool> promoteQrcodePoolList = promoteQrcodePoolService.list(new QueryWrapper<PromoteQrcodePool>().eq("promote_id", promoteCode.getId()));
+            for (PromoteQrcodePool promoteQrcodePool : promoteQrcodePoolList){
+                this.addRedis(promoteCode.getId(),promoteQrcodePool.getCustserviceId(),promoteQrcodePool.getWeight());
             }
             }
         }
         }
     }
     }
+
+    private Boolean addRedis(Integer promoteId, Integer custserviceId, Integer weight) {
+        Float score = weight.floatValue() / 10000;
+        Long index = stringRedisTemplate.opsForZSet().rank(RedisKey.PanCustServiceIdDayView + promoteId, Integer.toString(custserviceId));
+        //.redis存在记录时才做更新
+        if (index != null) {
+            stringRedisTemplate.opsForZSet().add(RedisKey.PanCustServiceIdDayView + promoteId, Integer.toString(custserviceId), score);
+            return true;
+        }
+        return false;
+    }
 }
 }

+ 1 - 1
src/main/java/com/mokamrp/privates/tast/pangu/ResetCustserviceViewTask.java

@@ -27,7 +27,7 @@ public class ResetCustserviceViewTask {
     @Autowired
     @Autowired
     public StringRedisTemplate stringRedisTemplate;
     public StringRedisTemplate stringRedisTemplate;
 
 
-    @Scheduled(cron = "0 */1 * * * ?") //.每小时重置个微客户访问量
+    @Scheduled(cron = "0 0 */1 * * ?") //.每小时重置个微客户访问量
     public void execute() {
     public void execute() {
         System.out.println("[cronjob]:盘古活码个微每小时访问量清空");
         System.out.println("[cronjob]:盘古活码个微每小时访问量清空");
         List<PromoteCode> promoteCodeList = promoteCodeService.list();
         List<PromoteCode> promoteCodeList = promoteCodeService.list();