Commit 8337630f5f0b434705476b963589cee46e92e905
1 parent
94d6edc9
Exists in
dev
定时修改全部用户密码
Showing
3 changed files
with
73 additions
and
0 deletions
Show diff stats
zr-cloud/zr-modules/zr-job/src/main/java/com/chinagas/modules/job/mapper/SysJobMapper.java
@@ -3,6 +3,7 @@ package com.chinagas.modules.job.mapper; | @@ -3,6 +3,7 @@ package com.chinagas.modules.job.mapper; | ||
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
4 | import com.chinagas.modules.job.entity.SysJob; | 4 | import com.chinagas.modules.job.entity.SysJob; |
5 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
6 | +import org.apache.ibatis.annotations.Param; | ||
6 | 7 | ||
7 | import java.util.List; | 8 | import java.util.List; |
8 | 9 | ||
@@ -70,4 +71,8 @@ public interface SysJobMapper extends BaseMapper<SysJob> { | @@ -70,4 +71,8 @@ public interface SysJobMapper extends BaseMapper<SysJob> { | ||
70 | * @return 结果 | 71 | * @return 结果 |
71 | */ | 72 | */ |
72 | public int insertJob(SysJob job); | 73 | public int insertJob(SysJob job); |
74 | + | ||
75 | + void updateUserPassword(@Param("password") String password); | ||
76 | + | ||
77 | + | ||
73 | } | 78 | } |
zr-cloud/zr-modules/zr-job/src/main/java/com/chinagas/modules/job/task/ZrTask.java
@@ -5,11 +5,14 @@ import com.chinagas.api.mcsb.RemoteMcsbService; | @@ -5,11 +5,14 @@ import com.chinagas.api.mcsb.RemoteMcsbService; | ||
5 | import com.chinagas.api.system.RemoteDataSyncService; | 5 | import com.chinagas.api.system.RemoteDataSyncService; |
6 | import com.chinagas.common.core.constants.Constants; | 6 | import com.chinagas.common.core.constants.Constants; |
7 | import com.chinagas.common.core.domain.R; | 7 | import com.chinagas.common.core.domain.R; |
8 | +import com.chinagas.common.security.utils.SecurityUtils; | ||
9 | +import com.chinagas.modules.job.mapper.SysJobMapper; | ||
8 | import org.quartz.JobExecutionException; | 10 | import org.quartz.JobExecutionException; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
10 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
11 | 13 | ||
12 | import java.io.IOException; | 14 | import java.io.IOException; |
15 | +import java.util.Random; | ||
13 | 16 | ||
14 | /** | 17 | /** |
15 | * @ClassName ZrTask | 18 | * @ClassName ZrTask |
@@ -29,6 +32,9 @@ public class ZrTask { | @@ -29,6 +32,9 @@ public class ZrTask { | ||
29 | @Autowired | 32 | @Autowired |
30 | private RemoteFksbService fksbService; | 33 | private RemoteFksbService fksbService; |
31 | 34 | ||
35 | + @Autowired | ||
36 | + private SysJobMapper sysJobMapper; | ||
37 | + | ||
32 | 38 | ||
33 | public void syncOrgData(String ifacecode) throws JobExecutionException, IOException { | 39 | public void syncOrgData(String ifacecode) throws JobExecutionException, IOException { |
34 | R<Integer> res = dataSyncService.dataSync(ifacecode); | 40 | R<Integer> res = dataSyncService.dataSync(ifacecode); |
@@ -37,6 +43,64 @@ public class ZrTask { | @@ -37,6 +43,64 @@ public class ZrTask { | ||
37 | } | 43 | } |
38 | } | 44 | } |
39 | 45 | ||
46 | + /** | ||
47 | + * 定时修改密码 | ||
48 | + */ | ||
49 | + public void syncUpdatePassword(){ | ||
50 | + String randomString = generateRandomString(12); | ||
51 | + sysJobMapper.updateUserPassword(SecurityUtils.encryptPassword(randomString)); | ||
52 | + } | ||
53 | + | ||
54 | + private static final String LOWER_CASE = "abcdefghijklmnopqrstuvwxyz"; | ||
55 | + private static final String UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
56 | + private static final String DIGITS = "0123456789"; | ||
57 | + private static final String SPECIAL_CHARACTERS = "!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?"; | ||
58 | + | ||
59 | + public static String generateRandomString(int length) { | ||
60 | + StringBuilder sb = new StringBuilder(length); | ||
61 | + Random random = new Random(); | ||
62 | + | ||
63 | + // 确保至少包含一个小写字母、大写字母、数字和特殊字符 | ||
64 | + sb.append(getRandomChar(LOWER_CASE, random)); | ||
65 | + sb.append(getRandomChar(UPPER_CASE, random)); | ||
66 | + sb.append(getRandomChar(DIGITS, random)); | ||
67 | + sb.append(getRandomChar(SPECIAL_CHARACTERS, random)); | ||
68 | + | ||
69 | + // 填充剩余的字符 | ||
70 | + for (int i = 4; i < length; i++) { | ||
71 | + String charSet = LOWER_CASE + UPPER_CASE + DIGITS + SPECIAL_CHARACTERS; | ||
72 | + char nextChar = getRandomChar(charSet, random); | ||
73 | + // 避免连续的字符 | ||
74 | + if (i > 0 && sb.charAt(i - 1) == nextChar) { | ||
75 | + do { | ||
76 | + nextChar = getRandomChar(charSet, random); | ||
77 | + } while (sb.charAt(i - 1) == nextChar); | ||
78 | + } | ||
79 | + sb.append(nextChar); | ||
80 | + } | ||
81 | + | ||
82 | + // 打乱顺序以避免连续的字符 | ||
83 | + shuffle(sb, random); | ||
84 | + | ||
85 | + return sb.toString(); | ||
86 | + } | ||
87 | + | ||
88 | + private static char getRandomChar(String charSet, Random random) { | ||
89 | + int index = random.nextInt(charSet.length()); | ||
90 | + return charSet.charAt(index); | ||
91 | + } | ||
92 | + | ||
93 | + private static void shuffle(StringBuilder sb, Random random) { | ||
94 | + for (int i = sb.length() - 1; i > 0; i--) { | ||
95 | + int j = random.nextInt(i + 1); | ||
96 | + char temp = sb.charAt(i); | ||
97 | + sb.setCharAt(i, sb.charAt(j)); | ||
98 | + sb.setCharAt(j, temp); | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + | ||
103 | + | ||
40 | // //读取财务报表excel文件 | 104 | // //读取财务报表excel文件 |
41 | // public void readMcsbExcel() throws JobExecutionException { | 105 | // public void readMcsbExcel() throws JobExecutionException { |
42 | // R<Integer> res = mcsbService.readMcsbExcel(); | 106 | // R<Integer> res = mcsbService.readMcsbExcel(); |
zr-cloud/zr-modules/zr-job/src/main/resources/mapper/SysJobMapper.xml