Explorar o código

定时更新场景viewCount

lyhzzz %!s(int64=2) %!d(string=hai) anos
pai
achega
ec2637205c

+ 1 - 0
src/main/java/com/fdkankan/ucenter/common/RedisKeyUtil.java

@@ -9,6 +9,7 @@ public class RedisKeyUtil {
     public static final String SCENE_UNUSED_NUMS = "4dkankan:scene:nums";
     public static final String SCENE_NUMS_LOADING = "4dkankan:scene:nums:loading";
     public static final String SCENE_VIEW_COUNT = "4dkankan:scene:nums:view_count:";
+    public static final String V4_SCENE_VISIT_CNT = "scene:visit:cnt";
 
     public static final String QRCODE= "4dkankan:qr_code:";
 

+ 4 - 0
src/main/java/com/fdkankan/ucenter/controller/TestController.java

@@ -1,11 +1,14 @@
 package com.fdkankan.ucenter.controller;
 
+import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.HashMap;
+import java.util.Map;
 
 @RestController
 public class TestController {
@@ -13,6 +16,7 @@ public class TestController {
 
     @RequestMapping("/test")
     public Result test() throws Exception {
+
         return Result.success( );
     }
 }

+ 2 - 0
src/main/java/com/fdkankan/ucenter/service/ISceneProService.java

@@ -72,4 +72,6 @@ public interface ISceneProService extends IService<ScenePro> {
     void copyLocalSource(String sceneNum, String newNum) throws Exception ;
 
     String setDataSource(String preDataSource,Integer sceneSource) throws Exception;
+
+    void updateDbViewCount(String num, String count);
 }

+ 16 - 0
src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java

@@ -744,6 +744,22 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
     }
 
     @Override
+    public void updateDbViewCount(String num, String count) {
+        LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(ScenePro::getNum,num);
+        wrapper.set(ScenePro::getViewCount,count);
+        this.update(wrapper);
+
+        ScenePlus plus = scenePlusService.getByNum(num);
+        if(plus !=null){
+            LambdaUpdateWrapper<ScenePlusExt> exWr = new LambdaUpdateWrapper<>();
+            exWr.eq(ScenePlusExt::getPlusId,plus.getId())
+                    .set(ScenePlusExt::getViewCount,count);
+            scenePlusExtService.update(exWr);
+        }
+    }
+
+    @Override
     public ScenePro findByFileId(String fileId) {
         LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
         wrapper.like(ScenePro::getDataSource,fileId);

+ 16 - 1
src/main/java/com/fdkankan/ucenter/task/TaskService.java

@@ -7,7 +7,10 @@ import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.constant.QrCodeFilePath;
 import java.io.File;
 import java.util.Date;
+import java.util.Map;
 import java.util.Objects;
+
+import com.fdkankan.ucenter.service.ISceneProService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -19,11 +22,12 @@ public class TaskService {
 
     @Autowired
     RedisUtil redisUtil;
+    @Autowired
+    ISceneProService sceneProService;
 
     @Scheduled(cron = "0 */10 * * * ?")
     public void delLoginQrCode(){
         long startTime = new Date().getTime();
-        log.info("delLoginQrCode:开始定时清理本地登录二维码" );
         String qrCodePath = QrCodeFilePath.LOGIN_QR_CODE_PATH;
         String aliQrCodePath = QrCodeFilePath.ALI_QRCODE_FOLDER;
         String wxCodePath = QrCodeFilePath.WEIXIN_QRCODE_FOLDER;
@@ -37,6 +41,17 @@ public class TaskService {
         delFile(files1);
         delFile(files2);
         log.info("delLoginQrCode:结束定时清理本地登录二维码:耗时{}秒",(new Date().getTime() - startTime)/1000 );
+        
+        this.updateSceneViewCount();
+    }
+
+    private void updateSceneViewCount() {
+        String redisKey = RedisKeyUtil.V4_SCENE_VISIT_CNT;
+        Map<String,String> hmget = redisUtil.hmget(redisKey);
+        for (String key : hmget.keySet()) {
+            log.info("定时更新场景viewCount--num:{},viewCount:{}",key,hmget.get(key));
+            sceneProService.updateDbViewCount(key,hmget.get(key));
+        }
     }
 
     private void delFile(File[] files){