소스 검색

fix: 客户端分享等功能

liaoyitao 9 달 전
부모
커밋
2b095963c3

+ 1 - 1
src/main/java/com/lqkj/link/GlobalExceptionHandler.java

@@ -20,6 +20,6 @@ public class GlobalExceptionHandler {
20 20
     public MessageBean<String> resolveException(Exception e) {
21 21
         logger.error("收到异常", e);
22 22
 
23
-        return MessageBean.error(e.toString());
23
+        return MessageBean.error(e.getMessage());
24 24
     }
25 25
 }

+ 3 - 0
src/main/java/com/lqkj/link/module/authority/domain/LoginBody.java

@@ -13,4 +13,7 @@ public class LoginBody {
13 13
     private String password;
14 14
     @Schema(description = "授权码,RSA加密")
15 15
     private String authCode;
16
+
17
+    @Schema(description = "登录类型:1后台登录, 2前台登录")
18
+    private int loginType;
16 19
 }

+ 3 - 2
src/main/java/com/lqkj/link/module/authority/service/UserInfoService.java

@@ -48,6 +48,7 @@ public class UserInfoService {
48 48
         guestUser.setHasManage(false);
49 49
         guestUser.setLocking(false);
50 50
         guestUser.setRefreshResource(false);
51
+        guestUser.setUpdateTime(new Date());
51 52
         register(guestUser, true, null);
52 53
         return guestUser.getUserCode();
53 54
     }
@@ -257,10 +258,10 @@ public class UserInfoService {
257 258
         if (userInfoRepository.hasSameUserCode(userCode)) {
258 259
             throw new RuntimeException("该手机号已被注册!");
259 260
         }
260
-        if (userCode.matches("^1[3-9]\\\\d{9}$")){
261
+        if (!userCode.matches("^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$")){
261 262
             throw new RuntimeException("请输入正确的手机号!");
262 263
         }
263
-        if (password.matches("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,16}$")){
264
+        if (!password.matches("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,16}$")){
264 265
             throw new RuntimeException("密码必须是8-16位数字、大写字母、小写字母!");
265 266
         }
266 267
 

+ 9 - 1
src/main/java/com/lqkj/link/module/bulletin/domain/NoticeInfo.java

@@ -43,6 +43,14 @@ public class NoticeInfo {
43 43
     @Schema(description = "查看时间")
44 44
     private Date viewTime;
45 45
     @Column(name = "type")
46
-    @Schema(description = "信息类型,1更新日志,2系统公告,3审核通知")
46
+    @Schema(description = "信息类型,1更新日志,2系统公告,3审核通知,4分享通知")
47 47
     private Integer type;
48
+
49
+    @Column(name = "zone_id")
50
+    @Schema(description = "作品id")
51
+    private Integer zoneId;
52
+
53
+    @Transient
54
+    private Integer authStatus;
55
+
48 56
 }

+ 14 - 1
src/main/java/com/lqkj/link/module/bulletin/service/NoticeInfoService.java

@@ -2,6 +2,9 @@ package com.lqkj.link.module.bulletin.service;
2 2
 
3 3
 import com.lqkj.link.module.bulletin.domain.NoticeInfo;
4 4
 import com.lqkj.link.module.bulletin.repository.NoticeInfoRepository;
5
+import com.lqkj.link.module.zone.domain.ZoneInfo;
6
+import com.lqkj.link.module.zone.repository.ZoneInfoRepository;
7
+import org.springframework.beans.factory.annotation.Autowired;
5 8
 import org.springframework.transaction.annotation.Transactional;
6 9
 import org.springframework.stereotype.Service;
7 10
 
@@ -11,12 +14,22 @@ import java.util.List;
11 14
 public class NoticeInfoService {
12 15
     private final NoticeInfoRepository noticeInfoRepository;
13 16
 
17
+    @Autowired
18
+    private ZoneInfoRepository zoneInfoRepository;
19
+
14 20
     public NoticeInfoService(NoticeInfoRepository noticeInfoRepository) {
15 21
         this.noticeInfoRepository = noticeInfoRepository;
16 22
     }
17 23
 
18 24
     public List<NoticeInfo> queryList(String userCode) {
19
-        return noticeInfoRepository.queryWithUserCode(userCode);
25
+        List<NoticeInfo> noticeInfos = noticeInfoRepository.queryWithUserCode(userCode);
26
+        noticeInfos.stream().forEach(noticeInfo -> {
27
+            if (noticeInfo.getType() == 4) {
28
+                ZoneInfo zoneInfo = zoneInfoRepository.findById(noticeInfo.getZoneId()).get();
29
+                noticeInfo.setAuthStatus(zoneInfo.getAuthStatus());
30
+            }
31
+        });
32
+        return noticeInfos;
20 33
     }
21 34
 
22 35
     @Transactional

+ 6 - 4
src/main/java/com/lqkj/link/module/jwt/controller/JwtController.java

@@ -18,6 +18,8 @@ import org.springframework.context.annotation.Lazy;
18 18
 import org.springframework.security.crypto.password.PasswordEncoder;
19 19
 import org.springframework.web.bind.annotation.*;
20 20
 
21
+import java.util.Objects;
22
+
21 23
 @RestController
22 24
 @RequestMapping("/jwt")
23 25
 @Tag(name = "授权服务", description = "授权服务")
@@ -53,13 +55,12 @@ public class JwtController {
53 55
         String userCode = loginBody.getUsername();
54 56
         String password = loginBody.getPassword();
55 57
         String authCode = loginBody.getAuthCode();
56
-        if (userCode.length() != 172 || password.length() != 172 || authCode.length() != 172) {
58
+        if (userCode.length() != 172 || password.length() != 172) {
57 59
             return MessageBean.error("用户名或密码或授权码错误!");
58 60
         }
59 61
         userCode = RSAUtils.decryptBase64(userCode);
60 62
         password = RSAUtils.decryptBase64(password);
61
-        authCode = RSAUtils.decryptBase64(authCode);
62
-
63
+        if (Objects.nonNull(authCode)) authCode = RSAUtils.decryptBase64(authCode);
63 64
         UserInfo userInfo = userDetailService.findByUserCode(userCode);
64 65
         if (userInfo == null) {
65 66
             return MessageBean.error("账号不存在!");
@@ -70,7 +71,8 @@ public class JwtController {
70 71
         if (!passwordEncoder.matches(password, userInfo.getPassword())) {
71 72
             return MessageBean.error(userDetailService.lockedUser(userInfo.getUserCode()));
72 73
         }
73
-        if (!authCode.equals(userInfo.getAuthorizationCode())) {
74
+        if (loginBody.getLoginType() == 0) return MessageBean.error("参数错误请重试!");
75
+        if (loginBody.getLoginType() == 1 && !authCode.equals(userInfo.getAuthorizationCode())) {
74 76
             return MessageBean.error("授权码错误!");
75 77
         }
76 78
         userDetailService.unlockedUser(userInfo.getUserCode());

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

@@ -232,10 +232,11 @@ public class ZoneInfoController {
232 232
     )
233 233
     @PostMapping("/" + VERSION_V1 + "/share")
234 234
     public MessageBean<String> share(@RequestParam Integer zoneId,
235
+                                     @RequestParam("shareUserCode") String shareUserCode,
235 236
                                      HttpServletRequest request) {
236 237
         String authHeader = request.getHeader("Authorization");
237 238
         String userCode = jwtService.decryptUsernameWithHeader(authHeader);
238
-        return MessageBean.ok(zoneInfoService.share(zoneId, userCode), "分享");
239
+        return MessageBean.ok(zoneInfoService.share(zoneId, userCode, shareUserCode), "分享");
239 240
     }
240 241
 
241 242
     @Operation(
@@ -338,4 +339,20 @@ public class ZoneInfoController {
338 339
     public MessageBean<JSONObject> loadTrans(@RequestParam Integer zoneId) {
339 340
         return MessageBean.ok(zoneInfoService.readTrans(zoneId), "获取变换接口");
340 341
     }
342
+
343
+
344
+    /**
345
+     * 检查分享状态
346
+     *
347
+     * @param zoneId
348
+     * @param userId
349
+     * @return
350
+     */
351
+    @PostMapping("/checkShareStatus")
352
+    public MessageBean save(@Parameter(name = "zoneId", description = "作品ID") Integer zoneId,
353
+                            @Parameter(name = "userId", description = "用户ID") Integer userId) {
354
+        boolean result = zoneInfoService.checkShareStatus(zoneId, userId);
355
+        return MessageBean.ok(result, "检查分享状态");
356
+    }
357
+
341 358
 }

+ 4 - 0
src/main/java/com/lqkj/link/module/zone/domain/LikesInfo.java

@@ -10,6 +10,10 @@ import lombok.Setter;
10 10
 
11 11
 import java.util.Date;
12 12
 
13
+/**
14
+ * 点赞信息
15
+ */
16
+
13 17
 @Entity
14 18
 @Table(name = "likes")
15 19
 @Getter

+ 56 - 0
src/main/java/com/lqkj/link/module/zone/domain/ShareInfo.java

@@ -0,0 +1,56 @@
1
+package com.lqkj.link.module.zone.domain;
2
+
3
+import com.fasterxml.jackson.annotation.JsonFormat;
4
+import io.swagger.v3.oas.annotations.media.Schema;
5
+import jakarta.persistence.*;
6
+import lombok.AllArgsConstructor;
7
+import lombok.Getter;
8
+import lombok.NoArgsConstructor;
9
+import lombok.Setter;
10
+
11
+import java.util.Date;
12
+
13
+/**
14
+ * 分享信息
15
+ */
16
+
17
+@Entity
18
+@Table(name = "share_info")
19
+@Getter
20
+@Setter
21
+@NoArgsConstructor
22
+@AllArgsConstructor
23
+public class ShareInfo {
24
+
25
+    @Id
26
+    @Column(name = "record_id")
27
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
28
+    @Schema(description = "记录ID")
29
+    private Integer recordId;
30
+
31
+    @Column(name = "user_id")
32
+    @Schema(description = "分享人ID")
33
+    private Integer userId;
34
+
35
+    @Column(name = "shared_user_id")
36
+    @Schema(description = "被分享人ID")
37
+    private Integer sharedUserId;
38
+
39
+    @Column(name = "zone_id")
40
+    @Schema(description = "区域/作品id")
41
+    private Integer zoneId;
42
+
43
+    @Column(name = "share_code")
44
+    @Schema(description = "随机序号")
45
+    private String shareCode;
46
+
47
+    @Column(name = "can_use")
48
+    @Schema(description = "有效期(天)")
49
+    private Integer canUse;
50
+
51
+    @Column(name = "share_time")
52
+    @JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
53
+    @Schema(description = "添加时间")
54
+    private Date shareTime;
55
+
56
+}

+ 25 - 0
src/main/java/com/lqkj/link/module/zone/repository/ShareInfoRepository.java

@@ -0,0 +1,25 @@
1
+package com.lqkj.link.module.zone.repository;
2
+
3
+import com.lqkj.link.module.zone.domain.ShareInfo;
4
+import com.lqkj.link.module.zone.domain.ZoneInfo;
5
+import org.springframework.data.jpa.repository.JpaRepository;
6
+import org.springframework.data.jpa.repository.Query;
7
+import org.springframework.stereotype.Repository;
8
+
9
+import java.util.List;
10
+
11
+@Repository
12
+public interface ShareInfoRepository extends JpaRepository<ShareInfo, Integer> {
13
+
14
+
15
+    /**
16
+     * 根据zoneId和sharedUserId查询
17
+     * @param zoneId
18
+     * @param userId
19
+     * @return
20
+     */
21
+    @Query(nativeQuery = true,
22
+            value = "SELECT * FROM share_info WHERE zone_id = ?1 AND shared_user_id = ?2"
23
+    )
24
+    List<ShareInfo> findByZoneIdAndSharedUserId(Integer zoneId, Integer userId);
25
+}

+ 4 - 3
src/main/java/com/lqkj/link/module/zone/repository/ZoneInfoRepository.java

@@ -85,13 +85,14 @@ public interface ZoneInfoRepository extends JpaRepository<ZoneInfo, Integer> {
85 85
     @Modifying
86 86
     @Query(nativeQuery = true,
87 87
         value = "with t1 as (update zone_info set share_count = coalesce(share_count, 0) + 1 where zone_id = :zoneId)" +
88
-                "insert into share_info(record_id, zone_id, user_id, share_code, share_time, can_use) " +
89
-                "select nextval('share_info_record_id_seq'), :zoneId, user_id, :shareCode, now(), 7 " +
88
+                "insert into share_info(record_id, zone_id, user_id, share_code, share_time, can_use, shared_user_id) " +
89
+                "select nextval('share_info_record_id_seq'), :zoneId, user_id, :shareCode, now(), 7 , :sharedUserId" +
90 90
                 "from user_info where user_code = :userCode"
91 91
     )
92 92
     void share(@Param("zoneId") Integer zoneId,
93 93
                @Param("userCode") String userCode,
94
-               @Param("shareCode") String shareCode);
94
+               @Param("shareCode") String shareCode,
95
+               @Param("sharedUserId") Integer sharedUserId);
95 96
 
96 97
     @Modifying
97 98
     @Query(nativeQuery = true,

+ 35 - 6
src/main/java/com/lqkj/link/module/zone/service/ZoneInfoService.java

@@ -4,15 +4,15 @@ import com.alibaba.fastjson2.JSON;
4 4
 import com.alibaba.fastjson2.JSONObject;
5 5
 import com.lqkj.link.module.authority.domain.UserInfo;
6 6
 import com.lqkj.link.module.authority.repository.UserInfoRepository;
7
+import com.lqkj.link.module.bulletin.domain.NoticeInfo;
8
+import com.lqkj.link.module.bulletin.repository.NoticeInfoRepository;
7 9
 import com.lqkj.link.module.zone.domain.*;
8
-import com.lqkj.link.module.zone.repository.GeomInfoRepository;
9
-import com.lqkj.link.module.zone.repository.LikesInfoRepository;
10
-import com.lqkj.link.module.zone.repository.ModelInfoRepository;
11
-import com.lqkj.link.module.zone.repository.ZoneInfoRepository;
10
+import com.lqkj.link.module.zone.repository.*;
12 11
 import com.lqkj.link.util.Unzipper;
13 12
 import org.apache.commons.lang3.StringUtils;
14 13
 import org.apache.commons.lang3.SystemUtils;
15 14
 import org.aspectj.weaver.ast.Var;
15
+import org.checkerframework.checker.units.qual.A;
16 16
 import org.locationtech.jts.geom.Coordinate;
17 17
 import org.locationtech.jts.geom.GeometryFactory;
18 18
 import org.springframework.beans.BeanUtils;
@@ -40,6 +40,12 @@ public class ZoneInfoService {
40 40
     @Autowired
41 41
     private LikesInfoRepository likesInfoRepository;
42 42
 
43
+    @Autowired
44
+    private NoticeInfoRepository noticeInfoRepository;
45
+
46
+    @Autowired
47
+    private ShareInfoRepository shareInfoRepository;
48
+
43 49
     public ZoneInfoService(ZoneInfoRepository zoneInfoRepository, UserInfoRepository userInfoRepository,
44 50
                            GeomInfoRepository geomInfoRepository, ModelInfoRepository modelInfoRepository) {
45 51
         this.zoneInfoRepository = zoneInfoRepository;
@@ -277,9 +283,20 @@ public class ZoneInfoService {
277 283
     }
278 284
 
279 285
     @Transactional
280
-    public String share(Integer zoneId, String userCode) {
286
+    public String share(Integer zoneId, String userCode, String shareUserCode) {
287
+        UserInfo shareUserInfo = userInfoRepository.findByUserCode(shareUserCode);
288
+        if (Objects.isNull(shareUserInfo)) throw new RuntimeException("分享用户不存在!请核验手机号");
281 289
         String shareCode = UUID.randomUUID().toString();
282
-        zoneInfoRepository.share(zoneId, userCode, shareCode);
290
+        zoneInfoRepository.share(zoneId, userCode, shareCode, shareUserInfo.getUserId());
291
+        UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
292
+        NoticeInfo noticeInfo = new NoticeInfo();
293
+        noticeInfo.setUserId(shareUserInfo.getUserId());
294
+        noticeInfo.setType(4);
295
+        noticeInfo.setContent(userInfo.getUserCode().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2") + "邀请你参加作品协作,与他(她)共建场景。");
296
+        noticeInfo.setHasView(true);
297
+        noticeInfo.setCreateTime(new Date());
298
+        noticeInfo.setZoneId(zoneId);
299
+        noticeInfoRepository.save(noticeInfo);
283 300
         return shareCode;
284 301
     }
285 302
 
@@ -371,4 +388,16 @@ public class ZoneInfoService {
371 388
         return zoneInfoRepository.findById(zoneId).get().getInitLocation();
372 389
     }
373 390
 
391
+    /**
392
+     * 检查分享状态
393
+     * @param zoneId
394
+     * @param userId
395
+     * @return
396
+     */
397
+    public boolean checkShareStatus(Integer zoneId, Integer userId) {
398
+        List<ShareInfo> shareInfos = shareInfoRepository.findByZoneIdAndSharedUserId(zoneId, userId);
399
+        if (shareInfos.size() < 1) return false;
400
+        ShareInfo shareInfo = shareInfos.get(0);
401
+        return (shareInfo.getShareTime().getTime() + (shareInfo.getCanUse() * 1000 * 60 * 60)) > System.currentTimeMillis();
402
+    }
374 403
 }

+ 2 - 1
src/main/java/com/lqkj/link/util/AESUtils.java

@@ -12,6 +12,7 @@ import java.nio.charset.StandardCharsets;
12 12
 import java.security.Security;
13 13
 import java.util.Base64;
14 14
 import java.util.Date;
15
+import java.util.Objects;
15 16
 import java.util.Random;
16 17
 
17 18
 
@@ -74,7 +75,7 @@ public class AESUtils {
74 75
         }
75 76
         UserInfo encryptUser = JSON.parseObject(JSON.toJSONString(object), UserInfo.class);
76 77
         encryptUser.setUserCode(encrypt(encryptUser.getUserCode(), key));
77
-        encryptUser.setAuthorizationCode(encrypt(encryptUser.getAuthorizationCode(), key));
78
+        if (Objects.nonNull(encryptUser.getAuthorizationCode())) encryptUser.setAuthorizationCode(encrypt(encryptUser.getAuthorizationCode(), key));
78 79
         encryptUser.setUpdateTime(updateTime);
79 80
         encryptUser.setLockTime(lockTime);
80 81
         return encryptUser;

+ 7 - 0
src/main/resources/db/migration/V4__2.0.1.sql

@@ -0,0 +1,7 @@
1
+alter table share_info add column shared_user_id INT4;
2
+comment on column share_info.shared_user_id is
3
+'被分享人id: shared_user_id';
4
+
5
+alter table notice_info add column zone_id INT4;
6
+comment on column notice_info.zone_id is
7
+'作品id: zone_id';