Commit c8e66a0a68eab665e56337dff8661e3fe744e577
Merge branch 'localhost-cxy' into 'master'
fix: 修改通知删除,相应的我的通知消息也一并删除 See merge request huang/thingsboard3.3.2!19
Showing
8 changed files
with
51 additions
and
21 deletions
@@ -34,7 +34,7 @@ public class SysNoticeDTO extends TenantDTO { | @@ -34,7 +34,7 @@ public class SysNoticeDTO extends TenantDTO { | ||
34 | private String receiverType; | 34 | private String receiverType; |
35 | 35 | ||
36 | @ApiModelProperty(value = "根据receiverType不同变化,0:传null,1:组织id,2:部门id,3:用户id",required = true) | 36 | @ApiModelProperty(value = "根据receiverType不同变化,0:传null,1:组织id,2:部门id,3:用户id",required = true) |
37 | - private List<String> pointId; | 37 | + private String pointId; |
38 | 38 | ||
39 | @ApiModelProperty(value = "发送状态(字典值draft_status) 0:草稿 1:已发布") | 39 | @ApiModelProperty(value = "发送状态(字典值draft_status) 0:草稿 1:已发布") |
40 | private String status; | 40 | private String status; |
@@ -7,6 +7,7 @@ import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | @@ -7,6 +7,7 @@ import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | ||
7 | import org.thingsboard.server.common.data.yunteng.enums.SysNoticeTypeEnum; | 7 | import org.thingsboard.server.common.data.yunteng.enums.SysNoticeTypeEnum; |
8 | 8 | ||
9 | import java.time.LocalDateTime; | 9 | import java.time.LocalDateTime; |
10 | +import java.util.List; | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * @author: 徐浩然 | 13 | * @author: 徐浩然 |
@@ -25,12 +26,14 @@ public class SysNotice extends TenantBaseEntity { | @@ -25,12 +26,14 @@ public class SysNotice extends TenantBaseEntity { | ||
25 | private String title; | 26 | private String title; |
26 | /** 内容 */ | 27 | /** 内容 */ |
27 | private String content; | 28 | private String content; |
28 | - /** 接收者(字典值receiver_type) 0:全部 1:组织 2:部门 3:个人 */ | 29 | + /** 接收者(字典值receiver_type) 0:全部 1:组织 2:部门 3:个人 */ |
29 | private String receiverType; | 30 | private String receiverType; |
30 | - /** 发送状态(字典值draft_status) 0:草稿 1:已发布 */ | 31 | + /** 发送状态(字典值draft_status) 0:草稿 1:已发布 */ |
31 | private String status; | 32 | private String status; |
32 | /** 发送者 */ | 33 | /** 发送者 */ |
33 | private String senderName; | 34 | private String senderName; |
34 | /** 发送时间 */ | 35 | /** 发送时间 */ |
35 | private LocalDateTime senderDate; | 36 | private LocalDateTime senderDate; |
37 | + /** 组织id */ | ||
38 | + private String pointId; | ||
36 | } | 39 | } |
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
4 | import com.baomidou.mybatisplus.core.metadata.IPage; | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | import lombok.RequiredArgsConstructor; | 5 | import lombok.RequiredArgsConstructor; |
6 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
7 | +import org.apache.commons.lang3.StringUtils; | ||
7 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
8 | import org.springframework.transaction.annotation.Transactional; | 9 | import org.springframework.transaction.annotation.Transactional; |
9 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 10 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
@@ -22,9 +23,7 @@ import org.thingsboard.server.dao.yunteng.service.SysNoticeUserService; | @@ -22,9 +23,7 @@ import org.thingsboard.server.dao.yunteng.service.SysNoticeUserService; | ||
22 | import org.thingsboard.server.dao.yunteng.service.UserOrganizationMappingService; | 23 | import org.thingsboard.server.dao.yunteng.service.UserOrganizationMappingService; |
23 | 24 | ||
24 | import java.time.LocalDateTime; | 25 | import java.time.LocalDateTime; |
25 | -import java.util.List; | ||
26 | -import java.util.Map; | ||
27 | -import java.util.Set; | 26 | +import java.util.*; |
28 | import java.util.stream.Collectors; | 27 | import java.util.stream.Collectors; |
29 | 28 | ||
30 | /** | 29 | /** |
@@ -56,7 +55,10 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | @@ -56,7 +55,10 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | ||
56 | } | 55 | } |
57 | 56 | ||
58 | @Override | 57 | @Override |
58 | + @Transactional | ||
59 | public boolean delete(Set<String> ids, String tenantId) { | 59 | public boolean delete(Set<String> ids, String tenantId) { |
60 | + //删除前先删除通知用户 | ||
61 | + sysNoticeUserService.deleteNoticUserByNoticeId(new ArrayList<>(ids)); | ||
60 | return baseMapper.delete( | 62 | return baseMapper.delete( |
61 | new LambdaQueryWrapper<SysNotice>() | 63 | new LambdaQueryWrapper<SysNotice>() |
62 | .in(SysNotice::getId, ids) | 64 | .in(SysNotice::getId, ids) |
@@ -65,16 +67,17 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | @@ -65,16 +67,17 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | ||
65 | } | 67 | } |
66 | 68 | ||
67 | @Override | 69 | @Override |
70 | + @Transactional | ||
68 | public SysNoticeDTO save(SysNoticeDTO sysNoticeDTO, String tenantId) { | 71 | public SysNoticeDTO save(SysNoticeDTO sysNoticeDTO, String tenantId) { |
69 | SysNotice sysNotice = sysNoticeDTO.getEntity(SysNotice.class); | 72 | SysNotice sysNotice = sysNoticeDTO.getEntity(SysNotice.class); |
70 | // 设置为草稿 | 73 | // 设置为草稿 |
71 | sysNotice.setTenantId(tenantId); | 74 | sysNotice.setTenantId(tenantId); |
75 | + // 接收者字典值判断 | ||
72 | if (sysNoticeDTO.getReceiverType() == null | 76 | if (sysNoticeDTO.getReceiverType() == null |
73 | || (!sysNoticeDTO.getReceiverType().equals(FastIotConstants.ReceiverType.ALL) | 77 | || (!sysNoticeDTO.getReceiverType().equals(FastIotConstants.ReceiverType.ALL) |
74 | - && sysNoticeDTO.getPointId() == null)) { | 78 | + && StringUtils.isEmpty(sysNoticeDTO.getPointId()))) { |
75 | throw new EntityCreationException(ErrorMessage.SEND_DESTINATION_NOT_FOUND.name()); | 79 | throw new EntityCreationException(ErrorMessage.SEND_DESTINATION_NOT_FOUND.name()); |
76 | } | 80 | } |
77 | - | ||
78 | List<String> userList; | 81 | List<String> userList; |
79 | switch (sysNotice.getReceiverType()) { | 82 | switch (sysNotice.getReceiverType()) { |
80 | case FastIotConstants.ReceiverType.ALL: | 83 | case FastIotConstants.ReceiverType.ALL: |
@@ -90,13 +93,14 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | @@ -90,13 +93,14 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | ||
90 | break; | 93 | break; |
91 | case FastIotConstants.ReceiverType.ORGANIZATION: | 94 | case FastIotConstants.ReceiverType.ORGANIZATION: |
92 | // 判断传入的集合id是否为空 | 95 | // 判断传入的集合id是否为空 |
93 | - if (sysNoticeDTO.getPointId() == null || sysNoticeDTO.getPointId().size() == 0) { | 96 | + if (StringUtils.isEmpty(sysNoticeDTO.getPointId())) { |
94 | throw new EntityCreationException(ErrorMessage.GET_CURRENT_USER_EXCEPTION.name()); | 97 | throw new EntityCreationException(ErrorMessage.GET_CURRENT_USER_EXCEPTION.name()); |
95 | } | 98 | } |
96 | // 获取当前组织下的所有用户 | 99 | // 获取当前组织下的所有用户 |
100 | + //把拿到的数据用,分割成数组 | ||
97 | userList = | 101 | userList = |
98 | userOrganizationMappingService.getUserIdByOrganizationIds( | 102 | userOrganizationMappingService.getUserIdByOrganizationIds( |
99 | - tenantId, sysNoticeDTO.getPointId().toArray(String[]::new)); | 103 | + tenantId, sysNoticeDTO.getPointId().split(",")); |
100 | break; | 104 | break; |
101 | default: | 105 | default: |
102 | throw new EntityCreationException(ErrorMessage.SEND_DESTINATION_NOT_FOUND.name()); | 106 | throw new EntityCreationException(ErrorMessage.SEND_DESTINATION_NOT_FOUND.name()); |
@@ -104,6 +108,7 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | @@ -104,6 +108,7 @@ public class SysNoticeServiceImpl extends AbstractBaseService<SysNoticeMapper, S | ||
104 | if (userList.isEmpty()) { | 108 | if (userList.isEmpty()) { |
105 | throw new EntityCreationException(ErrorMessage.SEND_DESTINATION_NOT_FOUND.name()); | 109 | throw new EntityCreationException(ErrorMessage.SEND_DESTINATION_NOT_FOUND.name()); |
106 | } | 110 | } |
111 | + //sysNotice.setPointId(String.join(",", sysNoticeDTO.getPointId())); | ||
107 | // 如果为空,则新增 | 112 | // 如果为空,则新增 |
108 | if (sysNotice.getId() == null) { | 113 | if (sysNotice.getId() == null) { |
109 | baseMapper.insert(sysNotice); | 114 | baseMapper.insert(sysNotice); |
@@ -71,16 +71,17 @@ public class SysNoticeUserServiceImpl | @@ -71,16 +71,17 @@ public class SysNoticeUserServiceImpl | ||
71 | public void saveSysNoticeUser( | 71 | public void saveSysNoticeUser( |
72 | List<String> userIds, String tenantId, String noticeId, String status) { | 72 | List<String> userIds, String tenantId, String noticeId, String status) { |
73 | List<SysNoticeUser> sysNoticeUserList = new ArrayList<>(); | 73 | List<SysNoticeUser> sysNoticeUserList = new ArrayList<>(); |
74 | - userIds.forEach(userId ->{ | ||
75 | - SysNoticeUser sysNoticeUser = new SysNoticeUser(); | ||
76 | - sysNoticeUser.setNoticeId(noticeId); | ||
77 | - sysNoticeUser.setStatus(status); | ||
78 | - sysNoticeUser.setTenantId(tenantId); | ||
79 | - sysNoticeUser.setReadStatus(FastIotConstants.ReadState.UNREAD); | ||
80 | - sysNoticeUser.setReceiverId(userId); | ||
81 | - sysNoticeUserList.add(sysNoticeUser); | ||
82 | - }); | ||
83 | - insertBatch(sysNoticeUserList,sysNoticeUserList.size()); | 74 | + userIds.forEach( |
75 | + userId -> { | ||
76 | + SysNoticeUser sysNoticeUser = new SysNoticeUser(); | ||
77 | + sysNoticeUser.setNoticeId(noticeId); | ||
78 | + sysNoticeUser.setStatus(status); | ||
79 | + sysNoticeUser.setTenantId(tenantId); | ||
80 | + sysNoticeUser.setReadStatus(FastIotConstants.ReadState.UNREAD); | ||
81 | + sysNoticeUser.setReceiverId(userId); | ||
82 | + sysNoticeUserList.add(sysNoticeUser); | ||
83 | + }); | ||
84 | + insertBatch(sysNoticeUserList, sysNoticeUserList.size()); | ||
84 | } | 85 | } |
85 | 86 | ||
86 | @Override | 87 | @Override |
@@ -104,6 +105,14 @@ public class SysNoticeUserServiceImpl | @@ -104,6 +105,14 @@ public class SysNoticeUserServiceImpl | ||
104 | return baseMapper.updateSysNoticeUsersStatusByNoticeId(id, status); | 105 | return baseMapper.updateSysNoticeUsersStatusByNoticeId(id, status); |
105 | } | 106 | } |
106 | 107 | ||
108 | + @Override | ||
109 | + public boolean deleteNoticUserByNoticeId(List<String> noticeId) { | ||
110 | + | ||
111 | + return baseMapper.delete( | ||
112 | + new LambdaQueryWrapper<SysNoticeUser>().in(SysNoticeUser::getNoticeId, noticeId)) | ||
113 | + > 0; | ||
114 | + } | ||
115 | + | ||
107 | private YtPageData<SysNoticeUserDTO> getPage(Map<String, Object> queryMap) { | 116 | private YtPageData<SysNoticeUserDTO> getPage(Map<String, Object> queryMap) { |
108 | IPage<SysNoticeUser> page = getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, true); | 117 | IPage<SysNoticeUser> page = getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, true); |
109 | IPage<SysNoticeUserDTO> pageDto = baseMapper.page(page, queryMap); | 118 | IPage<SysNoticeUserDTO> pageDto = baseMapper.page(page, queryMap); |
@@ -4,10 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; | @@ -4,10 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
4 | import com.baomidou.mybatisplus.core.metadata.IPage; | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
6 | import org.apache.ibatis.annotations.Param; | 6 | import org.apache.ibatis.annotations.Param; |
7 | +import org.springframework.validation.annotation.Validated; | ||
8 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
7 | import org.thingsboard.server.common.data.yunteng.dto.SysNoticeDTO; | 9 | import org.thingsboard.server.common.data.yunteng.dto.SysNoticeDTO; |
8 | import org.thingsboard.server.dao.yunteng.entities.SysNotice; | 10 | import org.thingsboard.server.dao.yunteng.entities.SysNotice; |
9 | 11 | ||
10 | import java.util.Map; | 12 | import java.util.Map; |
13 | +import java.util.Set; | ||
11 | 14 | ||
12 | /** | 15 | /** |
13 | * @author: 徐浩然 | 16 | * @author: 徐浩然 |
@@ -28,4 +31,7 @@ public interface SysNoticeMapper extends BaseMapper<SysNotice> { | @@ -28,4 +31,7 @@ public interface SysNoticeMapper extends BaseMapper<SysNotice> { | ||
28 | * @return 消息详情 | 31 | * @return 消息详情 |
29 | */ | 32 | */ |
30 | SysNoticeDTO get(@Param("id") String id, @Param("tenantId") String tenantId); | 33 | SysNoticeDTO get(@Param("id") String id, @Param("tenantId") String tenantId); |
34 | + | ||
35 | + | ||
36 | + | ||
31 | } | 37 | } |
@@ -31,4 +31,6 @@ public interface SysNoticeUserMapper extends BaseMapper<SysNoticeUser> { | @@ -31,4 +31,6 @@ public interface SysNoticeUserMapper extends BaseMapper<SysNoticeUser> { | ||
31 | SysNoticeUserDTO get(@Param("id") String id, @Param("tenantId") String tenantId); | 31 | SysNoticeUserDTO get(@Param("id") String id, @Param("tenantId") String tenantId); |
32 | 32 | ||
33 | boolean updateSysNoticeUsersStatusByNoticeId(@Param("noticeId")String noticeId, @Param("status")String status); | 33 | boolean updateSysNoticeUsersStatusByNoticeId(@Param("noticeId")String noticeId, @Param("status")String status); |
34 | + | ||
35 | + | ||
34 | } | 36 | } |
@@ -25,4 +25,6 @@ public interface SysNoticeUserService { | @@ -25,4 +25,6 @@ public interface SysNoticeUserService { | ||
25 | List<String> getSysNoticeUserIdsByNoticeId(String noticeId); | 25 | List<String> getSysNoticeUserIdsByNoticeId(String noticeId); |
26 | 26 | ||
27 | boolean updateSysNoticeUsersStatusByNoticeId(String noticeId, String status); | 27 | boolean updateSysNoticeUsersStatusByNoticeId(String noticeId, String status); |
28 | + | ||
29 | + boolean deleteNoticUserByNoticeId(List<String> noticeId); | ||
28 | } | 30 | } |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | <result property="createTime" column="create_time"/> | 16 | <result property="createTime" column="create_time"/> |
17 | <result property="updateTime" column="update_time"/> | 17 | <result property="updateTime" column="update_time"/> |
18 | <result property="tenantId" column="tenant_id"/> | 18 | <result property="tenantId" column="tenant_id"/> |
19 | + <result property="pointId" column="point_id"/> | ||
19 | </resultMap> | 20 | </resultMap> |
20 | 21 | ||
21 | <sql id="dict"> | 22 | <sql id="dict"> |
@@ -45,7 +46,8 @@ | @@ -45,7 +46,8 @@ | ||
45 | sn.updater updater, | 46 | sn.updater updater, |
46 | sn.create_time create_time, | 47 | sn.create_time create_time, |
47 | sn.update_time update_time, | 48 | sn.update_time update_time, |
48 | - sn.tenant_id tenant_id | 49 | + sn.tenant_id tenant_id, |
50 | + sn.point_id point_id | ||
49 | FROM sys_notice sn | 51 | FROM sys_notice sn |
50 | </sql> | 52 | </sql> |
51 | <select id="page" resultMap="sysNotice"> | 53 | <select id="page" resultMap="sysNotice"> |
@@ -62,4 +64,5 @@ | @@ -62,4 +64,5 @@ | ||
62 | sn.tenant_id = #{tenantId} | 64 | sn.tenant_id = #{tenantId} |
63 | AND sn.id = #{id} | 65 | AND sn.id = #{id} |
64 | </select> | 66 | </select> |
67 | + | ||
65 | </mapper> | 68 | </mapper> |