Browse Source

fix:用户修改,api修改

liaoyitao 3 weeks ago
parent
commit
51c7145544

+ 1 - 1
pom.xml

@@ -27,7 +27,7 @@
27 27
         <url/>
28 28
     </scm>
29 29
     <properties>
30
-        <java.version>17</java.version>
30
+        <java.version>21</java.version>
31 31
     </properties>
32 32
     <dependencies>
33 33
         <dependency>

+ 56 - 1
src/main/java/com/lqkj/cmlcp/module/api/controller/ApiInfoController.java

@@ -1,5 +1,6 @@
1 1
 package com.lqkj.cmlcp.module.api.controller;
2 2
 
3
+import com.alibaba.fastjson2.JSONArray;
3 4
 import com.lqkj.cmlcp.message.Result;
4 5
 import com.lqkj.cmlcp.module.api.domain.ApiInfo;
5 6
 import com.lqkj.cmlcp.module.api.service.ApiInfoService;
@@ -33,7 +34,7 @@ public class ApiInfoController {
33 34
     }
34 35
 
35 36
     @PostMapping("/delete")
36
-    public Result delete(@RequestBody List<Integer> ids) {
37
+    public Result delete(@RequestParam List<Integer> ids) {
37 38
         apiInfoService.delete(ids);
38 39
         return Result.ok();
39 40
     }
@@ -54,4 +55,58 @@ public class ApiInfoController {
54 55
         return Result.ok();
55 56
     }
56 57
 
58
+    @PostMapping ("/postTest")
59
+    public Result PostTest(@RequestBody ApiInfo apiInfo) {
60
+        String str = "[{'label': '全彩5456屏','value': 71},{'label': '双基色屏','value': 81},{'label': '简易屏','value': 57},{'label': '条形屏','value': 3}]";
61
+        ApiInfo apiInfo1 = new ApiInfo();
62
+        apiInfo1.setData(JSONArray.parse(str));
63
+        return Result.ok(apiInfo1);
64
+    }
65
+
66
+    @GetMapping("/getTest")
67
+    public Result GetTest(@RequestParam String name) {
68
+        String str = "[{'label': '全彩5456屏','value': 71},{'label': '双基色屏','value': 81},{'label': '简易屏','value': 57},{'label': '条形屏','value': 3}]";
69
+        ApiInfo apiInfo1 = new ApiInfo();
70
+        apiInfo1.setData(JSONArray.parse(str));
71
+        return Result.ok(apiInfo1);
72
+    }
73
+
74
+    @GetMapping("/getTest2")
75
+    public Result GetTest2() {
76
+        String str = "[\n" +
77
+                "\t{\n" +
78
+                "\t\t\"label\": \"测试333\",\n" +
79
+                "\t\t\"value\": 61\n" +
80
+                "\t},\n" +
81
+                "\t{\n" +
82
+                "\t\t\"label\": \"齐\",\n" +
83
+                "\t\t\"value\": 5\n" +
84
+                "\t},\n" +
85
+                "\t{\n" +
86
+                "\t\t\"label\": \"楚\",\n" +
87
+                "\t\t\"value\": 7\n" +
88
+                "\t},\n" +
89
+                "\t{\n" +
90
+                "\t\t\"label\": \"赵\",\n" +
91
+                "\t\t\"value\": 76\n" +
92
+                "\t},\n" +
93
+                "\t{\n" +
94
+                "\t\t\"label\": \"燕\",\n" +
95
+                "\t\t\"value\": 10\n" +
96
+                "\t},\n" +
97
+                "\t{\n" +
98
+                "\t\t\"label\": \"韩\",\n" +
99
+                "\t\t\"value\": 9\n" +
100
+                "\t},\n" +
101
+                "\t{\n" +
102
+                "\t\t\"label\": \"魏\",\n" +
103
+                "\t\t\"value\": 22\n" +
104
+                "\t}\n" +
105
+                "]";
106
+        ApiInfo apiInfo1 = new ApiInfo();
107
+        apiInfo1.setData(JSONArray.parse(str));
108
+        return Result.ok(apiInfo1);
109
+    }
110
+
111
+
57 112
 }

+ 4 - 4
src/main/java/com/lqkj/cmlcp/module/api/service/impl/ApiInfoServiceImpl.java

@@ -1,6 +1,5 @@
1 1
 package com.lqkj.cmlcp.module.api.service.impl;
2 2
 
3
-import cn.afterturn.easypoi.excel.entity.ImportParams;
4 3
 import com.alibaba.excel.EasyExcel;
5 4
 import com.alibaba.fastjson2.JSONArray;
6 5
 import com.alibaba.fastjson2.JSONObject;
@@ -56,9 +55,6 @@ public class ApiInfoServiceImpl implements ApiInfoService {
56 55
     @Override
57 56
     public void importExcel(MultipartFile file) {
58 57
         try {
59
-            ImportParams params = new ImportParams();
60
-            params.setTitleRows(1); // 表示表格的标题行数
61
-            params.setHeadRows(1);  // 表示表头行数
62 58
             List<ApiInfo> apiInfos = EasyExcel.read(file.getInputStream()).head(ApiInfo.class).sheet().doReadSync();
63 59
             apiInfoRepository.saveAll(apiInfos);
64 60
         } catch (Exception e) {
@@ -66,6 +62,10 @@ public class ApiInfoServiceImpl implements ApiInfoService {
66 62
         }
67 63
     }
68 64
 
65
+    /**
66
+     * 封装数据库数据
67
+     * @param apiInfo
68
+     */
69 69
     private void encapsuLationDbData(ApiInfo apiInfo) {
70 70
         if (apiInfo.getData() != null) return;
71 71
         JSONObject params = apiInfo.getParams();

+ 13 - 0
src/main/java/com/lqkj/cmlcp/module/authority/controller/UserInfoController.java

@@ -155,4 +155,17 @@ public class UserInfoController {
155 155
         return Result.ok(null, "更新用户信息");
156 156
     }
157 157
 
158
+    /**
159
+     * 检查是否能登录后台
160
+     */
161
+    @GetMapping("/check")
162
+    public Result<String> check(String userCode) {
163
+        if (userInfoService.check(userCode)){
164
+            return Result.ok("可以登录后台");
165
+        }else{
166
+            return Result.fail("暂无权限,请联系管理员");
167
+        }
168
+
169
+    }
170
+
158 171
 }

+ 7 - 0
src/main/java/com/lqkj/cmlcp/module/authority/service/UserInfoService.java

@@ -75,4 +75,11 @@ public interface UserInfoService{
75 75
     void delete(List<Integer> userIds);
76 76
 
77 77
     void updateInfo(String userCode, String displayName, String headImgPath);
78
+
79
+    /**
80
+     * 检测用户是否可以登录后台
81
+     * @param userCode
82
+     * @return
83
+     */
84
+    boolean check(String userCode);
78 85
 }

+ 17 - 8
src/main/java/com/lqkj/cmlcp/module/authority/service/impl/UserInfoServiceImpl.java

@@ -86,7 +86,7 @@ public class UserInfoServiceImpl implements UserInfoService{
86 86
                 return "账号已被冻结,请稍后重试";
87 87
             }
88 88
             userInfoRepository.save(userInfo);
89
-            return "账号、密码或授权码输入错误," + (4 - loginErrorCount) +"次错误后,账号将会冻结1小时";
89
+            return "账号、密码输入错误," + (4 - loginErrorCount) +"次错误后,账号将会冻结1小时";
90 90
         }
91 91
     }
92 92
 
@@ -184,12 +184,12 @@ public class UserInfoServiceImpl implements UserInfoService{
184 184
         }
185 185
 
186 186
         // 授权码判断,8位数字、大写字母、小写字母
187
-        String auCodeRegex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8}$";
188
-        pattern = Pattern.compile(auCodeRegex);
189
-        matcher = pattern.matcher(userInfo.getAuthorizationCode());
190
-        if (!matcher.find()) {
191
-            return "授权码必须是8位数字、大写字母、小写字母!";
192
-        }
187
+//        String auCodeRegex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8}$";
188
+//        pattern = Pattern.compile(auCodeRegex);
189
+//        matcher = pattern.matcher(userInfo.getAuthorizationCode());
190
+//        if (!matcher.find()) {
191
+//            return "授权码必须是8位数字、大写字母、小写字母!";
192
+//        }
193 193
 
194 194
         if (userInfo.getId() == null) {
195 195
             // 重复判断
@@ -224,7 +224,7 @@ public class UserInfoServiceImpl implements UserInfoService{
224 224
             }
225 225
             oldUser.setDisplayName(userInfo.getDisplayName());
226 226
             oldUser.setHasManage(userInfo.getHasManage());
227
-            oldUser.setAuthorizationCode(userInfo.getAuthorizationCode());
227
+//            oldUser.setAuthorizationCode(userInfo.getAuthorizationCode());
228 228
             oldUser.setUpdateTime(new Date());
229 229
             userInfoRepository.save(oldUser);
230 230
         }
@@ -249,6 +249,15 @@ public class UserInfoServiceImpl implements UserInfoService{
249 249
         userInfoRepository.save(userInfo);
250 250
     }
251 251
 
252
+    @Override
253
+    public boolean check(String userCode) {
254
+        UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
255
+        if (userInfo == null) {
256
+            return false;
257
+        }
258
+        return userInfo.getHasManage();
259
+    }
260
+
252 261
     @PostConstruct
253 262
     @Transactional
254 263
     public void initSuperUser() {

+ 111 - 0
src/main/java/com/lqkj/cmlcp/module/base/controller/ChatController.java

@@ -0,0 +1,111 @@
1
+package com.lqkj.cmlcp.module.base.controller;
2
+
3
+
4
+import org.springframework.http.ResponseEntity;
5
+import org.springframework.web.bind.annotation.*;
6
+import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
7
+
8
+import java.time.LocalDateTime;
9
+import java.util.HashMap;
10
+import java.util.List;
11
+import java.util.Map;
12
+import java.util.concurrent.ConcurrentHashMap;
13
+import java.util.concurrent.CopyOnWriteArrayList;
14
+
15
+@RestController
16
+@RequestMapping("/chat")
17
+public class ChatController {
18
+
19
+    private static final ConcurrentHashMap<String, ResponseBodyEmitter> onlineUsers = new ConcurrentHashMap<>();
20
+    // 存储聊天消息(可替换为数据库)
21
+    private static final List<Map<String, String>> messageHistory = new CopyOnWriteArrayList<>();
22
+
23
+    /**
24
+     * 用户连接聊天通道
25
+     * @param userId 用户唯一标识
26
+     */
27
+    @GetMapping("/connect")
28
+    public ResponseBodyEmitter connect(@RequestParam String userId) {
29
+
30
+        ResponseBodyEmitter emitter = new ResponseBodyEmitter(-1L);
31
+        // 移除旧连接并添加新连接
32
+        onlineUsers.computeIfPresent(userId, (k, v) -> {
33
+            v.complete();
34
+            return emitter;
35
+        });
36
+        onlineUsers.putIfAbsent(userId, emitter);
37
+
38
+        // 发送历史消息(可选)
39
+        sendExistingMessages(emitter);
40
+
41
+        // 设置连接关闭/超时的清理逻辑
42
+        emitter.onCompletion(() -> onlineUsers.remove(userId));
43
+        emitter.onTimeout(() -> onlineUsers.remove(userId));
44
+        emitter.onError((e) -> onlineUsers.remove(userId));
45
+
46
+        return emitter;
47
+
48
+    }
49
+
50
+    /**
51
+     * 发送消息接口
52
+     * @param message 消息体(JSON格式)
53
+     */
54
+    @PostMapping("/send")
55
+    public ResponseEntity<String> sendMessage(@RequestBody Map<String, String> message) {
56
+        String sender = message.get("sender");
57
+        String receiver = message.get("receiver");
58
+        String content = message.get("content");
59
+
60
+        if (sender == null || content == null) {
61
+            return ResponseEntity.badRequest().body("参数缺失");
62
+        }
63
+
64
+        // 构造消息对象
65
+        Map<String, String> msg = new HashMap<>();
66
+        msg.put("sender", sender);
67
+        msg.put("receiver", receiver != null ? receiver : "all"); // 默认群发
68
+        msg.put("content", content);
69
+        msg.put("timestamp", LocalDateTime.now().toString());
70
+
71
+        // 存储消息
72
+        messageHistory.add(msg);
73
+
74
+        // 推送消息
75
+        if (receiver == null) {
76
+            // 群发:遍历所有在线用户
77
+            onlineUsers.forEach((userId, emitter) -> {
78
+                try {
79
+                    emitter.send(msg);
80
+                } catch (Exception e) {
81
+                    emitter.complete();
82
+                    onlineUsers.remove(userId);
83
+                }
84
+            });
85
+        } else {
86
+            // 私聊:查找指定接收者
87
+            ResponseBodyEmitter receiverEmitter = onlineUsers.get(receiver);
88
+            if (receiverEmitter != null) {
89
+                try {
90
+                    receiverEmitter.send(msg);
91
+                } catch (Exception e) {
92
+                    receiverEmitter.complete();
93
+                    onlineUsers.remove(receiver);
94
+                }
95
+            }
96
+        }
97
+
98
+        return ResponseEntity.ok("消息已发送");
99
+    }
100
+
101
+    // 发送历史消息给新连接的用户
102
+    private void sendExistingMessages(ResponseBodyEmitter emitter) {
103
+        try {
104
+            for (Map<String, String> msg : messageHistory) {
105
+                emitter.send(msg);
106
+            }
107
+        } catch (Exception e) {
108
+            emitter.complete();
109
+        }
110
+    }
111
+}

+ 10 - 11
src/main/java/com/lqkj/cmlcp/module/jwt/controller/JwtController.java

@@ -6,6 +6,7 @@ import com.lqkj.cmlcp.module.authority.domain.LoginBody;
6 6
 import com.lqkj.cmlcp.module.authority.domain.UserInfo;
7 7
 import com.lqkj.cmlcp.module.authority.service.UserInfoService;
8 8
 import com.lqkj.cmlcp.module.jwt.service.JwtService;
9
+import com.lqkj.cmlcp.utils.RSAUtils;
9 10
 import io.swagger.v3.oas.annotations.Operation;
10 11
 import io.swagger.v3.oas.annotations.media.Content;
11 12
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -48,13 +49,11 @@ public class JwtController {
48 49
     public Result<String> getToken(@RequestBody LoginBody loginBody){
49 50
         String userCode = loginBody.getUsername();
50 51
         String password = loginBody.getPassword();
51
-        String authCode = loginBody.getAuthCode();
52
-//        if (userCode.length() != 172 || password.length() != 172 || authCode.length() != 172) {
53
-//            return Result.fail("用户名或密码或授权码错误!");
54
-//        }
55
-//        userCode = RSAUtils.decryptBase64(userCode);
56
-//        password = RSAUtils.decryptBase64(password);
57
-//        authCode = RSAUtils.decryptBase64(authCode);
52
+        if (userCode.length() != 172 || password.length() != 172) {
53
+            return Result.fail("用户名或密码错误!");
54
+        }
55
+        userCode = RSAUtils.decryptBase64(userCode);
56
+        password = RSAUtils.decryptBase64(password);
58 57
 
59 58
         UserInfo userInfo = userInfoService.findByUserCode(userCode);
60 59
         if (userInfo == null) {
@@ -66,9 +65,9 @@ public class JwtController {
66 65
         if (!passwordEncoder.matches(password, userInfo.getPassword())) {
67 66
             return Result.fail(userInfoService.lockedUser(userInfo.getUserCode()));
68 67
         }
69
-        if (!authCode.equals(userInfo.getAuthorizationCode())) {
70
-            return Result.fail("授权码错误!");
71
-        }
68
+//        if (!authCode.equals(userInfo.getAuthorizationCode())) {
69
+//            return Result.fail("授权码错误!");
70
+//        }
72 71
         userInfoService.unlockedUser(userInfo.getUserCode());
73 72
 
74 73
         return Result.ok(jwtService.generateToken(userCode));
@@ -92,6 +91,6 @@ public class JwtController {
92 91
     )
93 92
     @PostMapping("/getAdminToken")
94 93
     public Result<String> getAdminToken() {
95
-        return Result.ok(jwtService.generateToken("meta-link"), "获取ADMIN-TOKEN");
94
+        return Result.ok(jwtService.generateToken("admin"), "获取ADMIN-TOKEN");
96 95
     }
97 96
 }

+ 1 - 1
src/main/java/com/lqkj/cmlcp/module/zone/controller/ZoneInfoController.java

@@ -37,7 +37,7 @@ public class ZoneInfoController {
37 37
     }
38 38
 
39 39
     @PostMapping("/delete")
40
-    public Result delete(@RequestBody List<Integer> ids) {
40
+    public Result delete(@RequestParam List<Integer> ids) {
41 41
         zoneInfoService.delete(ids);
42 42
         return Result.ok();
43 43
     }

+ 1 - 0
src/main/java/com/lqkj/cmlcp/module/zone/service/impl/ZoneInfoServiceImpl.java

@@ -47,6 +47,7 @@ public class ZoneInfoServiceImpl implements ZoneInfoService {
47 47
         return zoneInfoRepository.pageQuery(name, pageRequest);
48 48
     }
49 49
 
50
+    @Transactional
50 51
     @Override
51 52
     public void delete(List<Integer> ids) {
52 53
         zoneInfoRepository.deleteAllById(ids);