Browse Source

账号添加过期设置

lyhzzz 1 year ago
parent
commit
d1427a526e

+ 3 - 0
src/main/java/com/fdkankan/manage/entity/RtkAccount.java

@@ -63,6 +63,9 @@ public class RtkAccount implements Serializable {
     @TableField("status")
     private Integer status;
 
+    @TableField("failure_time")
+    private Date failureTime;
+
     @TableField("rec_status")
     @TableLogic(value = "A",delval = "I")
     private String recStatus;

+ 4 - 0
src/main/java/com/fdkankan/manage/service/IRtkAccountService.java

@@ -4,6 +4,8 @@ import com.fdkankan.manage.entity.RtkAccount;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.manage.vo.request.RtkInfoParam;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -27,4 +29,6 @@ public interface IRtkAccountService extends IService<RtkAccount> {
     void del(RtkAccount param);
 
     RtkAccount getByUserName(String userName);
+
+    List<RtkAccount> getByNotFailure();
 }

+ 28 - 11
src/main/java/com/fdkankan/manage/service/impl/RtkAccountServiceImpl.java

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fdkankan.dingtalk.DingTalkSendUtils;
 import com.fdkankan.manage.common.PageInfo;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.entity.*;
@@ -77,8 +76,14 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
         }
         if(redisUtil.hasKey(redisKey)){
             String jsonStr = redisUtil.get(redisKey);
-            redisUtil.expire(redisKey,time);
-            return JSONObject.parseObject(jsonStr, RtkAccount.class);
+            RtkAccount rtkAccount = JSONObject.parseObject(jsonStr, RtkAccount.class);
+            Boolean flag = checkAccountFailureTime(rtkAccount.getId());
+            if(flag){
+                redisUtil.expire(redisKey,time);
+                return rtkAccount;
+            }else {
+                redisUtil.del(redisKey);
+            }
         }
 
         LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
@@ -110,6 +115,17 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
         return rtkAccount;
     }
 
+    private Boolean checkAccountFailureTime(Integer accountId) {
+        RtkAccount dbRtkAccount = this.getById(accountId);
+        if(dbRtkAccount == null || dbRtkAccount.getStatus() == 3){
+            return false;
+        }
+        if(dbRtkAccount.getFailureTime() != null &&  dbRtkAccount.getFailureTime().getTime() <= new Date().getTime() ){
+            return false;
+        }
+        return true;
+    }
+
     @Override
     public void updateAccountStatus(Integer id, int status) {
         LambdaUpdateWrapper<RtkAccount> wrapper1 = new LambdaUpdateWrapper<>();
@@ -129,14 +145,6 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
         }
     }
 
-
-
-
-
-
-
-
-
     @Override
     public Object pageList(RtkInfoParam param) {
         LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
@@ -205,4 +213,13 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
         wrapper.eq(RtkAccount::getUserName,userName);
         return this.getOne(wrapper);
     }
+
+    @Override
+    public List<RtkAccount> getByNotFailure() {
+        LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
+        wrapper.ne(RtkAccount::getStatus,3);
+        wrapper.isNotNull(RtkAccount::getFailureTime);
+        wrapper.le(RtkAccount::getFailureTime,new Date());
+        return this.list(wrapper);
+    }
 }

+ 13 - 3
src/main/java/com/fdkankan/manage/task/TaskService.java

@@ -3,7 +3,6 @@ package com.fdkankan.manage.task;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.fdkankan.dingtalk.DingTalkSendUtils;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.entity.RtkAccount;
 import com.fdkankan.manage.exception.BusinessException;
@@ -15,9 +14,11 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -53,14 +54,14 @@ public class TaskService {
      * 检查账号
      */
     public void checkAccount() {
-        HashMap<String, RtkAccount> map = new HashMap<>();
+        HashMap<String, String> map = new HashMap<>();
         String redisKey = "4dkankan:rtk:snCode:*";
         Set<String> keys = redisUtil.keys(redisKey);
         if(keys!= null && !keys.isEmpty()){
             for (String key : keys) {
                 String jsonStr = redisUtil.get(key);
                 RtkAccount rtkAccount = JSONObject.parseObject(jsonStr, RtkAccount.class);
-                map.put(rtkAccount.getUserName(),rtkAccount);
+                map.put(rtkAccount.getUserName(),key);
             }
         }
         LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
@@ -73,6 +74,15 @@ public class TaskService {
             rtkAccountService.updateAccountStatus(rtkAccount.getId(),1);
         }
 
+        List<RtkAccount> rtkAccounts = rtkAccountService.getByNotFailure();
+        for (RtkAccount rtkAccount : rtkAccounts) {
+            rtkAccount.setStatus(3);
+            rtkAccountService.updateAccountStatus(rtkAccount.getId(),3);
+            if(map.containsKey(rtkAccount.getUserName())){
+                redisUtil.del(map.get(rtkAccount.getUserName()));
+            }
+        }
+
     }