Browse Source

fix 防重复提交

he2802 3 years ago
parent
commit
7bbb91e3eb

+ 14 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/base/ProfileTpController.java

@@ -3,6 +3,7 @@ package com.zhongzheng.controller.base;
 import com.zhongzheng.common.core.controller.BaseController;
 import com.zhongzheng.common.core.domain.AjaxResult;
 import com.zhongzheng.common.core.page.TableDataInfo;
+import com.zhongzheng.common.core.redis.RedisCache;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.framework.web.service.WxTokenService;
 import com.zhongzheng.modules.base.bo.*;
@@ -19,6 +20,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 资料模板Controller
@@ -39,6 +41,8 @@ public class ProfileTpController extends BaseController {
 
     private final IUserProfileService iUserProfileService;
 
+    private final RedisCache redisCache;
+
     /**
      * 查询资料模板列表
      */
@@ -69,7 +73,16 @@ public class ProfileTpController extends BaseController {
     public AjaxResult<Void> add(@RequestBody UserProfileAddBo bo) {
         ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
         bo.setUserId(loginUser.getUser().getUserId());
-        return toAjax(iUserProfileService.insertByAddBo(bo) ? 1 : 0);
+        String key = "PROFILE_"+loginUser.getUser().getUserId();
+        Long value = redisCache.getCacheObject(key);
+        if(value!=null){
+            return toAjax(1);
+        }
+        if(iUserProfileService.insertByAddBo(bo)){
+            redisCache.setCacheObject(key,1L,10, TimeUnit.SECONDS);//10秒
+            return toAjax(1);
+        }
+        return toAjax(0);
     }
 
     /**

+ 14 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/base/UserProfileStampController.java

@@ -4,6 +4,7 @@ import com.zhongzheng.common.annotation.Log;
 import com.zhongzheng.common.core.controller.BaseController;
 import com.zhongzheng.common.core.domain.AjaxResult;
 import com.zhongzheng.common.core.page.TableDataInfo;
+import com.zhongzheng.common.core.redis.RedisCache;
 import com.zhongzheng.common.enums.BusinessType;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.framework.web.service.WxTokenService;
@@ -24,6 +25,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 填写资料审核Controller
@@ -41,6 +43,8 @@ public class UserProfileStampController extends BaseController {
 
     private final WxTokenService wxTokenService;
 
+    private final RedisCache redisCache;
+
     /**
      * 新增填写资料审核
      */
@@ -50,7 +54,16 @@ public class UserProfileStampController extends BaseController {
         ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
         bo.setUserId(loginUser.getUser().getUserId());
         bo.setTypeStatus(2);
-        return toAjax(iUserProfileService.insertByAddBo(bo) ? 1 : 0);
+        String key = "PRSTAMP_"+loginUser.getUser().getUserId();
+        Long value = redisCache.getCacheObject(key);
+        if(value!=null){
+            return toAjax(1);
+        }
+        if(iUserProfileService.insertByAddBo(bo)){
+            redisCache.setCacheObject(key,1L,10, TimeUnit.SECONDS);//10秒
+            return toAjax(1);
+        }
+        return toAjax(0);
     }
 
     /**

+ 1 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/cmmon/CommonController.java

@@ -101,7 +101,7 @@ public class CommonController extends BaseController {
         map.put("hide",false);
         if(Validator.isNotEmpty(bo.getVersion())){
             if(bo.getVersion().equals("4.1")){
-                map.put("hide",true);
+                map.put("hide",false);
             }
         }
         return AjaxResult.success(map);