Prechádzať zdrojové kódy

Merge branch 'master' of http://192.168.0.115:3000/lyhzzz/4dkankan-center-user

lyhzzz 2 rokov pred
rodič
commit
243c07a488

+ 11 - 2
src/main/java/com/fdkankan/ucenter/controller/SceneController.java

@@ -5,10 +5,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.dtflys.forest.annotation.Get;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.JwtUtil;
+import com.fdkankan.ucenter.common.BaseController;
+import com.fdkankan.ucenter.common.DownloadStatusEnum;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.constant.LoginConstant;
+import com.fdkankan.ucenter.entity.User;
 import com.fdkankan.ucenter.service.*;
 import com.fdkankan.ucenter.vo.request.SceneParam;
+import com.fdkankan.ucenter.vo.response.DownloadProcessVo;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -31,7 +35,7 @@ import java.util.List;
  */
 @RestController
 @RequestMapping("/user/scene")
-public class SceneController {
+public class SceneController extends BaseController {
 
     @Autowired
     ISceneProService sceneProService;
@@ -98,7 +102,12 @@ public class SceneController {
      */
     @PostMapping("/downloadProcess")
     public Result downloadProcess(@RequestBody SceneParam param) throws Exception{
-        return Result.success(downService.downloadProcess(param.getSceneNum()));
+        User user = userService.getByUserName(JwtUtil.getUsername(this.getToken()));
+        DownloadProcessVo downloadProcessVo = downService.downloadProcess(user.getId(), param.getSceneNum());
+        if(downloadProcessVo.getStatus() == DownloadStatusEnum.DOWNLOAD_FAILED_CODE){
+            return Result.failure("下载失败!");
+        }
+        return Result.success(downloadProcessVo);
     }
 
     /**

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/IDownService.java

@@ -10,5 +10,5 @@ public interface IDownService {
 
     DownVo down(String sceneNum,String userName);
 
-    DownloadProcessVo downloadProcess(String num);
+    DownloadProcessVo downloadProcess(Long userId, String num);
 }

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

@@ -56,4 +56,6 @@ public interface IUserService extends IService<User> {
     User getByToken(String token);
 
     Object findCameraDetailByChildName(String token, String childName);
+
+    void updateDownloadNum(long userId, int num);
 }

+ 12 - 4
src/main/java/com/fdkankan/ucenter/service/impl/DownService.java

@@ -121,14 +121,21 @@ public class DownService implements IDownService {
         Map<String,String> params = new HashMap<>(2);
         params.put("type","local");
         params.put("sceneNum",sceneNum);
-        String redisKey = RedisKey.DOWNLOAD_TASK;
+        String progressKey = String.format(RedisKey.PREFIX_DOWNLOAD_PROGRESS, sceneNum);
+        String downloadTaskKey = RedisKey.DOWNLOAD_TASK;
         String sysVersion = "v3";
         if(scenePro == null){
             params.put("num",sceneNum);
-            redisKey = RedisKey.SCENE_DOWNLOADS_TASK_V4;
+            progressKey = String.format(RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4, sceneNum);
+            downloadTaskKey = RedisKey.SCENE_DOWNLOADS_TASK_V4;
             sysVersion = "v4";
         }
-        redisUtil.lRightPush(redisKey, JSONObject.toJSONString(params));
+        //先删除之前的下载进度
+        redisUtil.del(progressKey);
+        //入队
+        redisUtil.lRightPush(downloadTaskKey, JSONObject.toJSONString(params));
+
+        //修改用户的下载次数
         user.setDownloadNum(user.getDownloadNum() + 1);
         userService.updateById(user);
 
@@ -145,7 +152,7 @@ public class DownService implements IDownService {
     }
 
     @Override
-    public DownloadProcessVo downloadProcess(String sceneNum) {
+    public DownloadProcessVo downloadProcess(Long userId, String sceneNum) {
         if (StringUtils.isEmpty(sceneNum)) {
             throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
         }
@@ -180,6 +187,7 @@ public class DownService implements IDownService {
                 }
             case DownloadStatusEnum.DOWNLOAD_FAILED_CODE:
                 sceneDownloadLog.setStatus(-1);
+                userService.updateDownloadNum(userId, -1);
                 break;
         }
         sceneDownloadLogService.updateById(sceneDownloadLog);

+ 5 - 0
src/main/java/com/fdkankan/ucenter/service/impl/UserServiceImpl.java

@@ -327,4 +327,9 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
         }
         return cameraVo;
     }
+
+    @Override
+    public void updateDownloadNum(long userId, int num) {
+        this.update(new LambdaUpdateWrapper<User>().setSql("download_num = download_num + " + num).eq(User::getId, userId));
+    }
 }