Forráskód Böngészése

白名单过期后,未能正常

dzx 2 hónapja
szülő
commit
75261d69c6

+ 2 - 0
src/main/java/com/xjrsoft/module/base/mapper/WhitelistManagementMapper.java

@@ -41,5 +41,7 @@ public interface WhitelistManagementMapper extends MPJBaseMapper<WhitelistManage
 
     @Select("SELECT id, name FROM base_class WHERE grade_id = #{gradeId}")
     List<WhiteBaseClass> getClassesByGradeId(@Param("gradeId") String gradeId);
+
+    List<WhitelistManagement> getCachesList();
 }
 

+ 2 - 0
src/main/java/com/xjrsoft/module/base/service/IWhitelistManagementService.java

@@ -40,4 +40,6 @@ public interface IWhitelistManagementService extends MPJBaseService<WhitelistMan
     List<Map<Integer, Object>> importData(List<Map<Integer, Object>> savedDataList);
 
     List<Map<Integer, Object>> activateImport(List<Map<Integer, Object>> savedDataList);
+
+    List<WhitelistManagement> getCachesList();
 }

+ 17 - 11
src/main/java/com/xjrsoft/module/base/service/impl/WhitelistManagementServiceImpl.java

@@ -2,6 +2,7 @@ package com.xjrsoft.module.base.service.impl;
 
 import cn.dev33.satoken.secure.BCrypt;
 import cn.hutool.core.util.IdUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -43,11 +44,11 @@ import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
+import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
 /**
@@ -60,7 +61,7 @@ import java.util.stream.Collectors;
 @Service
 @AllArgsConstructor
 public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<WhitelistManagementMapper, WhitelistManagement> implements IWhitelistManagementService {
-    private final WhitelistManagementMapper whitelistManagementMapper;
+    private final WhitelistManagementMapper managementMapper;
 
     private RedisUtil redisUtil;
 
@@ -72,37 +73,37 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
     private final IUserRoleRelationService roleRelationService;
     @Override
     public Page<WhitelistManagementPageVo> getPage(Page<Object> objectPage, WhitelistManagementPageDto dto) {
-        return whitelistManagementMapper.getPage(objectPage, dto);
+        return managementMapper.getPage(objectPage, dto);
     }
 
     @Override
     public String GetName(String name) {
-        return whitelistManagementMapper.getName(name);
+        return managementMapper.getName(name);
     }
 
     @Override
     public String GetCredentialNumber(String credentialNumber) {
-        return whitelistManagementMapper.getCredentialNumber(credentialNumber);
+        return managementMapper.getCredentialNumber(credentialNumber);
     }
 
     @Override
     public String GetPhone(String phone) {
-        return whitelistManagementMapper.getPhone(phone);
+        return managementMapper.getPhone(phone);
     }
 
     @Override
     public Long getUserId(String credentialNumber) {
-        return whitelistManagementMapper.getUserId(credentialNumber);
+        return managementMapper.getUserId(credentialNumber);
     }
 
     @Override
     public boolean checkExist(String credentialNumber) {
-        return whitelistManagementMapper.checkExits(credentialNumber);
+        return managementMapper.checkExits(credentialNumber);
     }
 
     @Override
     public List<TreeNode> getTreeStructure() {
-        List<WhiteBaseGrade> grades = whitelistManagementMapper.getAllGrades();
+        List<WhiteBaseGrade> grades = managementMapper.getAllGrades();
         List<TreeNode> treeNodes = new ArrayList<>();
 
         for (WhiteBaseGrade grade : grades) {
@@ -110,7 +111,7 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
             gradeNode.setId(grade.getId());
             gradeNode.setName(grade.getName());
 
-            List<WhiteBaseClass> classes = whitelistManagementMapper.getClassesByGradeId(grade.getId());
+            List<WhiteBaseClass> classes = managementMapper.getClassesByGradeId(grade.getId());
             List<TreeNode> classNodes = new ArrayList<>();
 
             for (WhiteBaseClass clazz : classes) {
@@ -133,7 +134,7 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
     @Async
     public void loadCaches() {
         log.info("XJRSOFT: 加载所有学生电信开卡用户缓存开始");
-        List<WhitelistManagement> list = whitelistManagementMapper.selectList(Wrappers.<WhitelistManagement>query().lambda().select(WhitelistManagement::getUserId));
+        List<WhitelistManagement> list = managementMapper.getCachesList();
 
         Map<Long, Long> map = list.stream().collect(Collectors.toMap(WhitelistManagement::getUserId, WhitelistManagement::getUserId));
         redisUtil.set(GlobalConstant.WHITE_MANAGEMENT_CACHE_KEY, map);
@@ -373,4 +374,9 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
 
         return errorList;
     }
+
+    @Override
+    public List<WhitelistManagement> getCachesList() {
+        return this.baseMapper.getCachesList();
+    }
 }

+ 46 - 0
src/main/java/com/xjrsoft/module/job/WhitelistTask.java

@@ -0,0 +1,46 @@
+package com.xjrsoft.module.job;
+
+import com.xjrsoft.common.constant.GlobalConstant;
+import com.xjrsoft.common.utils.RedisUtil;
+import com.xjrsoft.module.base.entity.WhitelistManagement;
+import com.xjrsoft.module.base.service.IWhitelistManagementService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author dzx
+ * @date 2024/9/2
+ */
+@Component
+@Slf4j
+public class WhitelistTask {
+
+    @Autowired
+    private IWhitelistManagementService whitelistService;
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Scheduled(cron = "0 */15 * * * ?")
+    public void execute() {
+        doExecute();
+    }
+
+    public void doExecute(){
+        List<WhitelistManagement> list = whitelistService.getCachesList();
+
+        Map map = redisUtil.get(GlobalConstant.WHITE_MANAGEMENT_CACHE_KEY, Map.class);
+        if(map.size() != list.size()){
+            Map<Long, Long> newMap = list.stream().collect(Collectors.toMap(WhitelistManagement::getUserId, WhitelistManagement::getUserId));
+            redisUtil.set(GlobalConstant.WHITE_MANAGEMENT_CACHE_KEY, newMap);
+        }
+    }
+
+}
+

+ 2 - 2
src/main/java/com/xjrsoft/module/material/controller/MaterialTaskController.java

@@ -274,7 +274,7 @@ public class MaterialTaskController {
         return RT.fileStream(bot.toByteArray(), "MaterialFormData" + ExcelTypeEnum.XLSX.getValue());
     }
 
-    @PostMapping("/download-file-export")
+    @PostMapping("/download-file-export-query")
     @ApiOperation(value = "下载附件(zip压缩包)")
     public ResponseEntity<byte[]> downloadFile(@Valid @RequestBody MaterialTaskAssignListDto dto) {
         MaterialTask materialTask = materialTaskService.getById(dto.getMaterialTaskId());
@@ -282,6 +282,6 @@ public class MaterialTaskController {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
 
         byte[] bytes = materialTaskService.downloadFile(dto);
-        return RT.fileStream(bytes, materialTask.getName() + "【" + LocalDate.now().format(formatter) + "】" + ".zip");
+        return RT.fileStream(bytes, "download-file-export.zip");
     }
 }

+ 4 - 0
src/main/resources/mapper/base/WhitelistManagement.xml

@@ -82,4 +82,8 @@
         </if>
     </select>
 
+    <select id="getCachesList" resultType="com.xjrsoft.module.base.entity.WhitelistManagement">
+        SELECT * FROM whitelist_management WHERE delete_mark = 0
+        AND (is_temporary = 0 OR (is_temporary = 1 AND end_time > NOW()))
+    </select>
 </mapper>