Browse Source

fix: 分享功能优化

liaoyitao 1 month ago
parent
commit
94978ba541

+ 2 - 1
src/main/java/com/lqkj/link/module/zone/controller/MaterialInfoController.java

@@ -59,8 +59,9 @@ public class MaterialInfoController {
59
     public MessageBean<Page<MaterialInfo>> pageQueryTemplate(@RequestParam(required = false, defaultValue = "") String name,
59
     public MessageBean<Page<MaterialInfo>> pageQueryTemplate(@RequestParam(required = false, defaultValue = "") String name,
60
                                                              @RequestParam(required = false, defaultValue = "0") Integer page,
60
                                                              @RequestParam(required = false, defaultValue = "0") Integer page,
61
                                                              @RequestParam(required = false) Integer materialType,
61
                                                              @RequestParam(required = false) Integer materialType,
62
+                                                             @RequestParam(required = false) Integer userId,
62
                                                              @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
63
                                                              @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
63
-        return MessageBean.ok(materialInfoService.pageQuery(name, page, pageSize, materialType), "材质分页接口");
64
+        return MessageBean.ok(materialInfoService.pageQuery(name, page, pageSize, materialType, userId), "材质分页接口");
64
 
65
 
65
     }
66
     }
66
 
67
 

+ 4 - 1
src/main/java/com/lqkj/link/module/zone/repository/MaterialInfoRepository.java

@@ -41,8 +41,11 @@ public interface MaterialInfoRepository extends JpaRepository<MaterialInfo, Inte
41
             value = "select * from material_info where " +
41
             value = "select * from material_info where " +
42
                     "(:materialName = '' or material_name like concat('%', :materialName, '%')) " +
42
                     "(:materialName = '' or material_name like concat('%', :materialName, '%')) " +
43
                     "and material_type = :materialType " +
43
                     "and material_type = :materialType " +
44
+                    "and (:userId is null or user_id = :userId) " +
44
                     "order by update_time"
45
                     "order by update_time"
45
     )
46
     )
46
     Page<MaterialInfo> pageQuery(@Param("materialName") String materialName,
47
     Page<MaterialInfo> pageQuery(@Param("materialName") String materialName,
47
-                                 @Param("materialType") Integer materialType,Pageable pageable);
48
+                                 @Param("materialType") Integer materialType,
49
+                                 Pageable pageable,
50
+                                 @Param("userId") Integer userId);
48
 }
51
 }

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

@@ -39,4 +39,10 @@ public interface ShareInfoRepository extends JpaRepository<ShareInfo, Integer> {
39
             value = "DELETE FROM share_info WHERE zone_id = ?1"
39
             value = "DELETE FROM share_info WHERE zone_id = ?1"
40
     )
40
     )
41
     void deleteByZoneId(Integer zoneId);
41
     void deleteByZoneId(Integer zoneId);
42
+
43
+    @Modifying
44
+    @Query(nativeQuery = true,
45
+            value = "UPDATE share_info SET share_time = NOW(), accept_status = null WHERE zone_id = ?1 AND shared_user_id = ?2"
46
+    )
47
+    void updateShareTime(Integer zoneId, Integer userId);
42
 }
48
 }

+ 1 - 1
src/main/java/com/lqkj/link/module/zone/service/MaterialInfoService.java

@@ -30,7 +30,7 @@ public interface MaterialInfoService {
30
      * @param pageSize
30
      * @param pageSize
31
      * @return
31
      * @return
32
      */
32
      */
33
-    Page<MaterialInfo> pageQuery(String name, Integer page, Integer pageSize, Integer materialType);
33
+    Page<MaterialInfo> pageQuery(String name, Integer page, Integer pageSize, Integer materialType, Integer userId);
34
 
34
 
35
 
35
 
36
     /**
36
     /**

+ 14 - 4
src/main/java/com/lqkj/link/module/zone/service/ZoneInfoService.java

@@ -40,6 +40,8 @@ public class ZoneInfoService {
40
     private final GeomInfoRepository geomInfoRepository;
40
     private final GeomInfoRepository geomInfoRepository;
41
     private final ModelInfoRepository modelInfoRepository;
41
     private final ModelInfoRepository modelInfoRepository;
42
 
42
 
43
+    private static final Long ONEDAY = 24 * 60 * 60 * 1000L;
44
+
43
     @Autowired
45
     @Autowired
44
     private LikesInfoRepository likesInfoRepository;
46
     private LikesInfoRepository likesInfoRepository;
45
 
47
 
@@ -290,8 +292,13 @@ public class ZoneInfoService {
290
         UserInfo shareUserInfo = userInfoRepository.findByUserCode(shareUserCode);
292
         UserInfo shareUserInfo = userInfoRepository.findByUserCode(shareUserCode);
291
         if (Objects.isNull(shareUserInfo)) throw new RuntimeException("未能找到与该手机号码相关的账户,请确认号码无误");
293
         if (Objects.isNull(shareUserInfo)) throw new RuntimeException("未能找到与该手机号码相关的账户,请确认号码无误");
292
         String shareCode = UUID.randomUUID().toString();
294
         String shareCode = UUID.randomUUID().toString();
293
-        if (shareInfoRepository.findByZoneIdAndSharedUserId(zoneId, shareUserInfo.getUserId()).size() > 0) throw new RuntimeException("该账户已分享过该作品");
294
-        zoneInfoRepository.share(zoneId, userCode, shareCode, shareUserInfo.getUserId());
295
+        List<ShareInfo> shareInfoList = shareInfoRepository.findByZoneIdAndSharedUserId(zoneId, shareUserInfo.getUserId());
296
+        if (shareInfoList.size() > 0 && (shareTime(shareInfoList.get(0)) > System.currentTimeMillis())) throw new RuntimeException("该账户已分享过该作品");
297
+        else if (shareInfoList.size() > 0 && (shareTime(shareInfoList.get(0)) < System.currentTimeMillis())) {
298
+            shareInfoRepository.updateShareTime(zoneId, shareUserInfo.getUserId());
299
+        }else {
300
+            zoneInfoRepository.share(zoneId, userCode, shareCode, shareUserInfo.getUserId());
301
+        }
295
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
302
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
296
         NoticeInfo noticeInfo = new NoticeInfo();
303
         NoticeInfo noticeInfo = new NoticeInfo();
297
         noticeInfo.setUserId(shareUserInfo.getUserId());
304
         noticeInfo.setUserId(shareUserInfo.getUserId());
@@ -304,6 +311,10 @@ public class ZoneInfoService {
304
         return shareCode;
311
         return shareCode;
305
     }
312
     }
306
 
313
 
314
+    private Long shareTime(ShareInfo shareInfo){
315
+        return shareInfo.getShareTime().getTime() + shareInfo.getCanUse() * ONEDAY;
316
+    }
317
+
307
     @Transactional
318
     @Transactional
308
     public void view(Integer zoneId, String userCode) {
319
     public void view(Integer zoneId, String userCode) {
309
         zoneInfoRepository.view(zoneId, userCode);
320
         zoneInfoRepository.view(zoneId, userCode);
@@ -426,8 +437,7 @@ public class ZoneInfoService {
426
     public boolean checkShareStatus(Integer zoneId, Integer userId) {
437
     public boolean checkShareStatus(Integer zoneId, Integer userId) {
427
         List<ShareInfo> shareInfos = shareInfoRepository.findByZoneIdAndSharedUserId(zoneId, userId);
438
         List<ShareInfo> shareInfos = shareInfoRepository.findByZoneIdAndSharedUserId(zoneId, userId);
428
         if (shareInfos.size() < 1) return false;
439
         if (shareInfos.size() < 1) return false;
429
-        ShareInfo shareInfo = shareInfos.get(0);
430
-        return (shareInfo.getShareTime().getTime() + (shareInfo.getCanUse() * 1000 * 60 * 60)) > System.currentTimeMillis();
440
+        return shareTime(shareInfos.get(0)) > System.currentTimeMillis();
431
     }
441
     }
432
 
442
 
433
 
443
 

+ 2 - 2
src/main/java/com/lqkj/link/module/zone/service/impl/MaterialInfoServiceImpl.java

@@ -50,9 +50,9 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
50
 
50
 
51
 
51
 
52
     @Override
52
     @Override
53
-    public Page<MaterialInfo> pageQuery(String name, Integer page, Integer pageSize, Integer materialType) {
53
+    public Page<MaterialInfo> pageQuery(String name, Integer page, Integer pageSize, Integer materialType, Integer userId) {
54
         Pageable pageable = PageRequest.of(page, pageSize);
54
         Pageable pageable = PageRequest.of(page, pageSize);
55
-        return materialInfoRepository.pageQuery(name, materialType, pageable);
55
+        return materialInfoRepository.pageQuery(name, materialType, pageable, userId);
56
     }
56
     }
57
 
57
 
58
     @Transactional
58
     @Transactional