Ver código fonte

fix: 删除作品,通知等功能调整

liaoyitao 8 meses atrás
pai
commit
75d86f6b58

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

@@ -43,7 +43,7 @@ public class NoticeInfo {
43 43
     @Schema(description = "查看时间")
44 44
     private Date viewTime;
45 45
     @Column(name = "type")
46
-    @Schema(description = "信息类型,1更新日志,2系统公告,3审核通知,4分享通知")
46
+    @Schema(description = "信息类型,1更新日志,2系统公告,3审核通知,4分享通知, 5协作拒绝通知, 删除作品通知")
47 47
     private Integer type;
48 48
 
49 49
     @Column(name = "zone_id")
@@ -53,4 +53,7 @@ public class NoticeInfo {
53 53
     @Transient
54 54
     private Integer authStatus;
55 55
 
56
+    @Transient
57
+    private Boolean acceptStatus;
58
+
56 59
 }

+ 8 - 2
src/main/java/com/lqkj/link/module/bulletin/service/NoticeInfoService.java

@@ -2,13 +2,16 @@ 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.ShareInfo;
5 6
 import com.lqkj.link.module.zone.domain.ZoneInfo;
7
+import com.lqkj.link.module.zone.repository.ShareInfoRepository;
6 8
 import com.lqkj.link.module.zone.repository.ZoneInfoRepository;
7 9
 import org.springframework.beans.factory.annotation.Autowired;
8 10
 import org.springframework.transaction.annotation.Transactional;
9 11
 import org.springframework.stereotype.Service;
10 12
 
11 13
 import java.util.List;
14
+import java.util.Objects;
12 15
 
13 16
 @Service
14 17
 public class NoticeInfoService {
@@ -17,6 +20,9 @@ public class NoticeInfoService {
17 20
     @Autowired
18 21
     private ZoneInfoRepository zoneInfoRepository;
19 22
 
23
+    @Autowired
24
+    private ShareInfoRepository shareInfoRepository;
25
+
20 26
     public NoticeInfoService(NoticeInfoRepository noticeInfoRepository) {
21 27
         this.noticeInfoRepository = noticeInfoRepository;
22 28
     }
@@ -25,8 +31,8 @@ public class NoticeInfoService {
25 31
         List<NoticeInfo> noticeInfos = noticeInfoRepository.queryWithUserCode(userCode);
26 32
         noticeInfos.stream().forEach(noticeInfo -> {
27 33
             if (noticeInfo.getType() == 4) {
28
-                ZoneInfo zoneInfo = zoneInfoRepository.findById(noticeInfo.getZoneId()).get();
29
-                noticeInfo.setAuthStatus(zoneInfo.getAuthStatus());
34
+                ShareInfo shareInfo = shareInfoRepository.findByZoneIdAndSharedUserId(noticeInfo.getZoneId(), noticeInfo.getUserId()).get(0);
35
+                noticeInfo.setAcceptStatus(Objects.isNull(shareInfo) ? false : shareInfo.getAcceptStatus());
30 36
             }
31 37
         });
32 38
         return noticeInfos;

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

@@ -365,9 +365,9 @@ public class ZoneInfoController {
365 365
      */
366 366
     @PostMapping("/getShareCenter")
367 367
     public MessageBean<Page<Map<String, Object>>> getShareCenter(@RequestParam(required = false, defaultValue = "") String name,
368
-                                                                     @RequestParam(required = false) Integer userId,
369
-                                                                     @RequestParam(required = false, defaultValue = "0") Integer page,
370
-                                                                     @RequestParam(required = false, defaultValue = "10") Integer pageSize){
368
+                                                                 @RequestParam() Integer userId,
369
+                                                                 @RequestParam(required = false, defaultValue = "0") Integer page,
370
+                                                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize){
371 371
         return MessageBean.ok(zoneInfoService.shareCenter(name, userId, page, pageSize), "获取分享中心");
372 372
 
373 373
     }

+ 1 - 1
src/main/java/com/lqkj/link/module/zone/domain/MaterialInfo.java

@@ -41,7 +41,7 @@ public class MaterialInfo {
41 41
     private String materialIcon;
42 42
 
43 43
     @Column(name = "json_file_name")
44
-    @Schema(description = "材质图标")
44
+    @Schema(description = "json文件名")
45 45
     private String compressFileName;
46 46
 
47 47
     @Column(name = "material_type")

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

@@ -53,4 +53,8 @@ public class ShareInfo {
53 53
     @Schema(description = "添加时间")
54 54
     private Date shareTime;
55 55
 
56
+    @Column(name = "accept_status")
57
+    @Schema(description = "接受状态")
58
+    private Boolean acceptStatus;
59
+
56 60
 }

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

@@ -3,6 +3,7 @@ package com.lqkj.link.module.zone.repository;
3 3
 import com.lqkj.link.module.zone.domain.ShareInfo;
4 4
 import com.lqkj.link.module.zone.domain.ZoneInfo;
5 5
 import org.springframework.data.jpa.repository.JpaRepository;
6
+import org.springframework.data.jpa.repository.Modifying;
6 7
 import org.springframework.data.jpa.repository.Query;
7 8
 import org.springframework.stereotype.Repository;
8 9
 
@@ -22,4 +23,20 @@ public interface ShareInfoRepository extends JpaRepository<ShareInfo, Integer> {
22 23
             value = "SELECT * FROM share_info WHERE zone_id = ?1 AND shared_user_id = ?2"
23 24
     )
24 25
     List<ShareInfo> findByZoneIdAndSharedUserId(Integer zoneId, Integer userId);
26
+
27
+    /**
28
+     * 根据zoneId查询
29
+     * @param zoneId
30
+     * @return
31
+     */
32
+    @Query(nativeQuery = true,
33
+            value = "SELECT * FROM share_info WHERE zone_id = ?1"
34
+    )
35
+    List<ShareInfo> findByZoneId(Integer zoneId);
36
+
37
+    @Modifying
38
+    @Query(nativeQuery = true,
39
+            value = "DELETE FROM share_info WHERE zone_id = ?1"
40
+    )
41
+    void deleteByZoneId(Integer zoneId);
25 42
 }

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

@@ -86,7 +86,7 @@ public interface ZoneInfoRepository extends JpaRepository<ZoneInfo, Integer> {
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 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" +
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,
@@ -194,9 +194,11 @@ public interface ZoneInfoRepository extends JpaRepository<ZoneInfo, Integer> {
194 194
                                           @Param("zoneId") Integer zoneId);
195 195
 
196 196
     @Query(nativeQuery = true,
197
-            value = "select zi.* from zone_info zi, share_info si " +
197
+            value = "select zi.*, ui.display_name from zone_info zi, share_info si, user_info ui " +
198 198
                     "where zi.zone_id = si.zone_id and si.shared_user_id = :userId " +
199
+                    "and si.accept_status = true " +
199 200
                     "and zi.zone_name like concat('%', :name, '%') " +
201
+                    "and ui.user_id = zi.user_id " +
200 202
                     "order by zi.update_time desc"
201 203
     )
202 204
     Page<Map<String, Object>> pageQueryshareCenter(@Param("name") String name,
@@ -205,7 +207,8 @@ public interface ZoneInfoRepository extends JpaRepository<ZoneInfo, Integer> {
205 207
 
206 208
     @Query(nativeQuery = true,
207 209
             value = "select distinct(zone_name) as \"name\" from zone_info zi, share_info si " +
208
-                    "where where zi.zone_id = si.zone_id and si.shared_user_id = :userId and zone_name like concat('%', :keyword, '%') " +
210
+                    "where zi.zone_id = si.zone_id and si.shared_user_id = :userId and si.accept_status = true " +
211
+                    "and zone_name like concat('%', :keyword, '%') " +
209 212
                     "order by zone_name"
210 213
     )
211 214
     List<String> autoCompleteShare(@Param("keyword") String keyword,

+ 53 - 3
src/main/java/com/lqkj/link/module/zone/service/ZoneInfoService.java

@@ -8,6 +8,7 @@ import com.lqkj.link.module.bulletin.domain.NoticeInfo;
8 8
 import com.lqkj.link.module.bulletin.repository.NoticeInfoRepository;
9 9
 import com.lqkj.link.module.zone.domain.*;
10 10
 import com.lqkj.link.module.zone.repository.*;
11
+import com.lqkj.link.util.PhoneUtils;
11 12
 import com.lqkj.link.util.Unzipper;
12 13
 import org.apache.commons.lang3.StringUtils;
13 14
 import org.apache.commons.lang3.SystemUtils;
@@ -27,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
27 28
 import java.io.File;
28 29
 import java.nio.file.Files;
29 30
 import java.nio.file.Paths;
31
+import java.sql.Timestamp;
32
+import java.text.SimpleDateFormat;
30 33
 import java.util.*;
31 34
 import java.util.stream.Collectors;
32 35
 
@@ -293,8 +296,8 @@ public class ZoneInfoService {
293 296
         NoticeInfo noticeInfo = new NoticeInfo();
294 297
         noticeInfo.setUserId(shareUserInfo.getUserId());
295 298
         noticeInfo.setType(4);
296
-        noticeInfo.setContent(userInfo.getUserCode().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2") + "邀请你参加作品协作,与他(她)共建场景。");
297
-        noticeInfo.setHasView(true);
299
+        noticeInfo.setContent(PhoneUtils.encryptPhoneNumber(userInfo.getUserCode()) + "邀请你参加作品协作,与他(她)共建场景。");
300
+        noticeInfo.setHasView(false);
298 301
         noticeInfo.setCreateTime(new Date());
299 302
         noticeInfo.setZoneId(zoneId);
300 303
         noticeInfoRepository.save(noticeInfo);
@@ -315,6 +318,7 @@ public class ZoneInfoService {
315 318
         return null;
316 319
     }
317 320
 
321
+    @Transactional
318 322
     public String deleteWork(Integer zoneId, String userCode) {
319 323
         if(!zoneInfoRepository.existsById(zoneId)){
320 324
             return "该作品不存在!";
@@ -325,10 +329,33 @@ public class ZoneInfoService {
325 329
         if (!zoneInfoRepository.canBeDeleteWithAuthStatus(zoneId)) {
326 330
             return "不能删除正在审核的作品!";
327 331
         }
332
+        notifySharer(zoneId);
333
+        shareInfoRepository.deleteByZoneId(zoneId);
328 334
         zoneInfoRepository.deleteById(zoneId);
329 335
         return null;
330 336
     }
331 337
 
338
+
339
+
340
+    /**
341
+     * 通知分享者
342
+     * @param zoneId
343
+     */
344
+    private void notifySharer(Integer zoneId) {
345
+        List<NoticeInfo>  noticeInfos = new ArrayList<>();
346
+        shareInfoRepository.findByZoneId(zoneId).forEach(shareInfo -> {
347
+            NoticeInfo noticeInfo = new NoticeInfo();
348
+            noticeInfo.setUserId(shareInfo.getSharedUserId());
349
+            noticeInfo.setType(6);
350
+            noticeInfo.setContent("经决定对团队进行调整。很遗憾地通知您,您将不再作为该项目的协作者。我们感谢您到目前为止的贡献。");
351
+            noticeInfo.setHasView(false);
352
+            noticeInfo.setCreateTime(new Date());
353
+            noticeInfo.setZoneId(zoneId);
354
+            noticeInfos.add(noticeInfo);
355
+        });
356
+        noticeInfoRepository.saveAll(noticeInfos);
357
+    }
358
+
332 359
     @Transactional
333 360
     public Map<String, Object> create(String name, Integer templateId, String userCode) {
334 361
         Map<String, Object> result = new HashMap<>();
@@ -413,7 +440,15 @@ public class ZoneInfoService {
413 440
      */
414 441
     public Page<Map<String, Object>> shareCenter(String name, Integer userId, Integer page, Integer pageSize) {
415 442
         Pageable pageable = PageRequest.of(page, pageSize);
416
-        return zoneInfoRepository.pageQueryshareCenter(name, userId, pageable);
443
+        Page<Map<String, Object>> maps = zoneInfoRepository.pageQueryshareCenter(name, userId, pageable);
444
+        List<Map<String, Object>> result = new ArrayList<>();
445
+        maps.getContent().forEach(map -> {
446
+            String update_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(map.get("update_time"));
447
+            HashMap<String, Object> resultMap = new HashMap<>(map);
448
+            resultMap.put("update_time", update_time);
449
+            result.add(resultMap);
450
+        });
451
+        return new PageImpl<>(result, PageRequest.of(page, pageSize), maps.getTotalElements());
417 452
     }
418 453
 
419 454
 
@@ -435,5 +470,20 @@ public class ZoneInfoService {
435 470
     @Transactional
436 471
     public void acceptShare(Integer zoneId, Integer userId, Boolean acceptStatus) {
437 472
         zoneInfoRepository.acceptShare(zoneId, userId, acceptStatus);
473
+        if (!acceptStatus) {
474
+            UserInfo userInfo = userInfoRepository.findById(userId).get();
475
+            ShareInfo shareInfo = shareInfoRepository.findByZoneIdAndSharedUserId(zoneId, userId).get(0);
476
+            NoticeInfo noticeInfo = new NoticeInfo();
477
+            noticeInfo.setAcceptStatus(false);
478
+            noticeInfo.setCreateTime(new Date());
479
+            noticeInfo.setHasView(false);
480
+            noticeInfo.setUserId(shareInfo.getUserId());
481
+            noticeInfo.setType(5);
482
+            noticeInfo.setContent("手机号为" + PhoneUtils.encryptPhoneNumber(userInfo.getUserCode()) + "的用户拒绝参加您的作品协作!");
483
+            noticeInfo.setZoneId(zoneId);
484
+            noticeInfoRepository.save(noticeInfo);
485
+        }
486
+
487
+
438 488
     }
439 489
 }

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

@@ -1,23 +1,18 @@
1 1
 package com.lqkj.link.module.zone.service.impl;
2 2
 
3 3
 import cn.hutool.core.util.RandomUtil;
4
-import com.lqkj.link.message.MessageBean;
5 4
 import com.lqkj.link.module.authority.repository.UserInfoRepository;
6 5
 import com.lqkj.link.module.zone.domain.MaterialInfo;
7
-import com.lqkj.link.module.zone.domain.ModelCategory;
8
-import com.lqkj.link.module.zone.domain.ModelInfo;
9 6
 import com.lqkj.link.module.zone.repository.MaterialInfoRepository;
10 7
 import com.lqkj.link.module.zone.service.MaterialInfoService;
11 8
 import com.lqkj.link.util.Unzipper;
12
-import org.checkerframework.checker.units.qual.A;
9
+import org.apache.commons.lang3.StringUtils;
13 10
 import org.springframework.beans.factory.annotation.Autowired;
14 11
 import org.springframework.data.domain.Page;
15 12
 import org.springframework.data.domain.PageRequest;
16 13
 import org.springframework.data.domain.Pageable;
17 14
 import org.springframework.stereotype.Service;
18 15
 import org.springframework.transaction.annotation.Transactional;
19
-import org.springframework.web.multipart.MultipartFile;
20
-
21 16
 import java.io.File;
22 17
 import java.io.IOException;
23 18
 import java.util.*;
@@ -35,6 +30,7 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
35 30
     @Transactional
36 31
     @Override
37 32
     public void sava(MaterialInfo materialInfo) {
33
+        materialInfo.setMaterialName(StringUtils.split(materialInfo.getCompressFileName(), ".")[0]);
38 34
         if ((Objects.nonNull(materialInfo.getMaterialId()) && materialInfoRepository.hasSameNameWithoutOne(materialInfo.getMaterialId(), materialInfo.getMaterialName()))
39 35
             || (Objects.isNull(materialInfo.getMaterialId()) && materialInfoRepository.hasSameName(materialInfo.getMaterialName()))) {
40 36
             throw new RuntimeException("材质名称不能重复!");

+ 30 - 0
src/main/java/com/lqkj/link/util/PhoneUtils.java

@@ -0,0 +1,30 @@
1
+package com.lqkj.link.util;
2
+
3
+public class PhoneUtils {
4
+
5
+    /**
6
+     * 加密手机号中间四位为*
7
+     * @param phoneNumber 原始手机号码
8
+     * @return 加密后的手机号码
9
+     * @throws IllegalArgumentException 如果手机号长度不等于11位
10
+     */
11
+    public static String encryptPhoneNumber(String phoneNumber) {
12
+        // 检查手机号长度是否为11位i
13
+        if ("meta-link".equals(phoneNumber)) return phoneNumber;
14
+        if (phoneNumber == null || phoneNumber.length() != 11) {
15
+            throw new IllegalArgumentException("手机号长度不正确");
16
+        }
17
+
18
+        // 将手机号分为前三位、中间四位、后四位
19
+        String prefix = phoneNumber.substring(0, 3);
20
+        String middle = phoneNumber.substring(3, 7); // 中间四位
21
+        String suffix = phoneNumber.substring(7);
22
+
23
+        // 中间四位加密为*
24
+        middle = "****";
25
+
26
+        // 拼接加密后的手机号
27
+        String encryptedNumber = prefix + middle + suffix;
28
+        return encryptedNumber;
29
+    }
30
+}