commit | author | age
|
9bcb19
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.sys.modular.notice.service.impl; |
|
26 |
|
|
27 |
import cn.hutool.core.bean.BeanUtil; |
|
28 |
import cn.hutool.core.collection.CollectionUtil; |
|
29 |
import cn.hutool.core.lang.Dict; |
|
30 |
import cn.hutool.core.util.ObjectUtil; |
|
31 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
32 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
33 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
34 |
import org.springframework.stereotype.Service; |
|
35 |
import org.springframework.transaction.annotation.Transactional; |
|
36 |
import vip.xiaonuo.core.context.login.LoginContextHolder; |
|
37 |
import vip.xiaonuo.core.exception.ServiceException; |
|
38 |
import vip.xiaonuo.core.factory.PageFactory; |
|
39 |
import vip.xiaonuo.core.pojo.login.SysLoginUser; |
|
40 |
import vip.xiaonuo.core.pojo.page.PageResult; |
|
41 |
import vip.xiaonuo.sys.core.enums.NoticeStatusEnum; |
|
42 |
import vip.xiaonuo.sys.core.enums.NoticeUserStatusEnum; |
|
43 |
import vip.xiaonuo.sys.modular.notice.entity.SysNotice; |
|
44 |
import vip.xiaonuo.sys.modular.notice.entity.SysNoticeUser; |
|
45 |
import vip.xiaonuo.sys.modular.notice.enums.SysNoticeExceptionEnum; |
|
46 |
import vip.xiaonuo.sys.modular.notice.mapper.SysNoticeMapper; |
|
47 |
import vip.xiaonuo.sys.modular.notice.param.SysNoticeParam; |
|
48 |
import vip.xiaonuo.sys.modular.notice.result.SysNoticeDetailResult; |
|
49 |
import vip.xiaonuo.sys.modular.notice.result.SysNoticeReceiveResult; |
|
50 |
import vip.xiaonuo.sys.modular.notice.service.SysNoticeService; |
|
51 |
import vip.xiaonuo.sys.modular.notice.service.SysNoticeUserService; |
|
52 |
import vip.xiaonuo.sys.modular.user.service.SysUserService; |
|
53 |
|
|
54 |
import javax.annotation.Resource; |
|
55 |
import java.util.Date; |
|
56 |
import java.util.List; |
|
57 |
|
|
58 |
/** |
|
59 |
* 系统通知公告service接口实现类 |
|
60 |
* |
|
61 |
* @author xuyuxiang |
|
62 |
* @date 2020/6/28 17:20 |
|
63 |
*/ |
|
64 |
@Service |
|
65 |
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements SysNoticeService { |
|
66 |
|
|
67 |
@Resource |
|
68 |
private SysNoticeUserService sysNoticeUserService; |
|
69 |
|
|
70 |
@Resource |
|
71 |
private SysUserService sysUserService; |
|
72 |
|
|
73 |
@Override |
|
74 |
public PageResult<SysNotice> page(SysNoticeParam sysNoticeParam) { |
|
75 |
LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>(); |
|
76 |
if (ObjectUtil.isNotNull(sysNoticeParam)) { |
|
77 |
//根据标题或内容模糊查询 |
|
78 |
if (ObjectUtil.isNotEmpty(sysNoticeParam.getSearchValue())) { |
|
79 |
queryWrapper.and(q -> q.like(SysNotice::getTitle, sysNoticeParam.getSearchValue()) |
|
80 |
.or().like(SysNotice::getContent, sysNoticeParam.getSearchValue())); |
|
81 |
} |
|
82 |
//根据类型查询 |
|
83 |
if (ObjectUtil.isNotEmpty(sysNoticeParam.getType())) { |
|
84 |
queryWrapper.eq(SysNotice::getType, sysNoticeParam.getType()); |
|
85 |
} |
|
86 |
} |
|
87 |
//查询未删除的 |
|
88 |
queryWrapper.ne(SysNotice::getStatus, NoticeStatusEnum.DELETED.getCode()); |
|
89 |
return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper)); |
|
90 |
} |
|
91 |
|
|
92 |
@Transactional(rollbackFor = Exception.class) |
|
93 |
@Override |
|
94 |
public void add(SysNoticeParam sysNoticeParam) { |
|
95 |
//校验参数,检查状态是否正确 |
|
96 |
checkParam(sysNoticeParam, true); |
|
97 |
SysNotice sysNotice = new SysNotice(); |
|
98 |
BeanUtil.copyProperties(sysNoticeParam, sysNotice); |
|
99 |
SysLoginUser sysLoginUser = LoginContextHolder.me().getSysLoginUser(); |
|
100 |
sysNotice.setPublicUserId(sysLoginUser.getId()); |
|
101 |
sysNotice.setPublicUserName(sysLoginUser.getName()); |
|
102 |
sysNotice.setPublicOrgId(sysLoginUser.getLoginEmpInfo().getOrgId()); |
|
103 |
sysNotice.setPublicOrgName(sysLoginUser.getLoginEmpInfo().getOrgName()); |
|
104 |
//如果是发布,则设置发布时间 |
|
105 |
if (NoticeStatusEnum.PUBLIC.getCode().equals(sysNotice.getStatus())) { |
|
106 |
sysNotice.setPublicTime(new Date()); |
|
107 |
} |
|
108 |
this.save(sysNotice); |
|
109 |
//通知到的人 |
|
110 |
List<Long> noticeUserIdList = sysNoticeParam.getNoticeUserIdList(); |
|
111 |
Integer noticeUserStatus = NoticeUserStatusEnum.UNREAD.getCode(); |
|
112 |
sysNoticeUserService.add(sysNotice.getId(), noticeUserIdList, noticeUserStatus); |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public void delete(SysNoticeParam sysNoticeParam) { |
|
117 |
SysNotice sysNotice = this.querySysNotice(sysNoticeParam); |
|
118 |
Integer status = sysNotice.getStatus(); |
|
119 |
if (!NoticeStatusEnum.DRAFT.getCode().equals(status) && !NoticeStatusEnum.CANCEL.getCode().equals(status)) { |
|
120 |
throw new ServiceException(SysNoticeExceptionEnum.NOTICE_CANNOT_DELETE); |
|
121 |
} |
|
122 |
sysNotice.setStatus(NoticeStatusEnum.DELETED.getCode()); |
|
123 |
this.updateById(sysNotice); |
|
124 |
} |
|
125 |
|
|
126 |
@Transactional(rollbackFor = Exception.class) |
|
127 |
@Override |
|
128 |
public void edit(SysNoticeParam sysNoticeParam) { |
|
129 |
SysNotice sysNotice = this.querySysNotice(sysNoticeParam); |
|
130 |
//校验参数,检查状态是否正确 |
|
131 |
checkParam(sysNoticeParam, true); |
|
132 |
//非草稿状态 |
|
133 |
Integer status = sysNotice.getStatus(); |
|
134 |
if (!NoticeStatusEnum.DRAFT.getCode().equals(status)) { |
|
135 |
throw new ServiceException(SysNoticeExceptionEnum.NOTICE_CANNOT_EDIT); |
|
136 |
} |
|
137 |
BeanUtil.copyProperties(sysNoticeParam, sysNotice); |
|
138 |
//如果是发布,则设置发布时间 |
|
139 |
if (NoticeStatusEnum.PUBLIC.getCode().equals(sysNotice.getStatus())) { |
|
140 |
sysNotice.setPublicTime(new Date()); |
|
141 |
} |
|
142 |
this.updateById(sysNotice); |
|
143 |
//通知到的人 |
|
144 |
List<Long> noticeUserIdList = sysNoticeParam.getNoticeUserIdList(); |
|
145 |
Integer noticeUserStatus = NoticeUserStatusEnum.UNREAD.getCode(); |
|
146 |
sysNoticeUserService.edit(sysNotice.getId(), noticeUserIdList, noticeUserStatus); |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public SysNoticeDetailResult detail(SysNoticeParam sysNoticeParam) { |
|
151 |
SysNotice sysNotice = this.querySysNotice(sysNoticeParam); |
|
152 |
Long id = sysNotice.getId(); |
|
153 |
//获取通知到的用户 |
|
154 |
List<SysNoticeUser> sysNoticeUserList = sysNoticeUserService.getSysNoticeUserListByNoticeId(id); |
|
155 |
List<Long> noticeUserIdList = CollectionUtil.newArrayList(); |
|
156 |
List<Dict> noticeUserReadInfoList = CollectionUtil.newArrayList(); |
|
157 |
SysNoticeDetailResult sysNoticeResult = new SysNoticeDetailResult(); |
|
158 |
BeanUtil.copyProperties(sysNotice, sysNoticeResult); |
|
159 |
if (ObjectUtil.isNotEmpty(sysNoticeUserList)) { |
|
160 |
sysNoticeUserList.forEach(sysNoticeUser -> { |
|
161 |
//遍历通知到的用户,并构造 |
|
162 |
noticeUserIdList.add(sysNoticeUser.getUserId()); |
|
163 |
Dict dict = Dict.create(); |
|
164 |
dict.put("userId", sysNoticeUser.getUserId()); |
|
165 |
dict.put("userName", sysUserService.getNameByUserId(sysNoticeUser.getUserId())); |
|
166 |
dict.put("readStatus", sysNoticeUser.getStatus()); |
|
167 |
dict.put("readTime", sysNoticeUser.getReadTime()); |
|
168 |
noticeUserReadInfoList.add(dict); |
|
169 |
}); |
|
170 |
} |
|
171 |
sysNoticeResult.setNoticeUserIdList(noticeUserIdList); |
|
172 |
sysNoticeResult.setNoticeUserReadInfoList(noticeUserReadInfoList); |
|
173 |
//如果该条通知公告为已发布,则将当前用户的该条通知公告设置为已读 |
|
174 |
if (sysNotice.getStatus().equals(NoticeStatusEnum.PUBLIC.getCode())) { |
|
175 |
sysNoticeUserService.read(sysNotice.getId(), |
|
176 |
LoginContextHolder.me().getSysLoginUserId(), NoticeUserStatusEnum.READ.getCode()); |
|
177 |
} |
|
178 |
return sysNoticeResult; |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public void changeStatus(SysNoticeParam sysNoticeParam) { |
|
183 |
SysNotice sysNotice = this.querySysNotice(sysNoticeParam); |
|
184 |
//校验参数,检查状态是否正确 |
|
185 |
checkParam(sysNoticeParam, false); |
|
186 |
sysNotice.setStatus(sysNoticeParam.getStatus()); |
|
187 |
//如果是撤回,则设置撤回时间 |
|
188 |
if (NoticeStatusEnum.CANCEL.getCode().equals(sysNotice.getStatus())) { |
|
189 |
sysNotice.setCancelTime(new Date()); |
|
190 |
} else if (NoticeStatusEnum.PUBLIC.getCode().equals(sysNotice.getStatus())) { |
|
191 |
//如果是发布,则设置发布时间 |
|
192 |
sysNotice.setPublicTime(new Date()); |
|
193 |
} |
|
194 |
this.updateById(sysNotice); |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public PageResult<SysNoticeReceiveResult> received(SysNoticeParam sysNoticeParam) { |
|
199 |
QueryWrapper<SysNoticeReceiveResult> queryWrapper = new QueryWrapper<>(); |
|
200 |
//查询当前用户的 |
|
201 |
queryWrapper.eq("sys_notice_user.user_id", LoginContextHolder.me().getSysLoginUserId()); |
|
202 |
if (ObjectUtil.isNotNull(sysNoticeParam)) { |
|
203 |
//根据标题或内容模糊查询 |
|
204 |
if (ObjectUtil.isNotEmpty(sysNoticeParam.getSearchValue())) { |
|
205 |
queryWrapper.and(q -> q.like("sys_notice.title", sysNoticeParam.getSearchValue()) |
|
206 |
.or().like("sys_notice.content", sysNoticeParam.getSearchValue())); |
|
207 |
} |
|
208 |
//根据类型查询 |
|
209 |
if (ObjectUtil.isNotEmpty(sysNoticeParam.getType())) { |
|
210 |
queryWrapper.eq("sys_notice.type", sysNoticeParam.getType()); |
|
211 |
} |
|
212 |
} |
|
213 |
//查询未删除的 |
|
214 |
queryWrapper.ne("sys_notice.status", NoticeStatusEnum.DELETED.getCode()); |
|
215 |
return new PageResult<>(this.baseMapper.page(PageFactory.defaultPage(), queryWrapper)); |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* 校验参数,判断状态是否正确 |
|
220 |
* |
|
221 |
* @author xuyuxiang |
|
222 |
* @date 2020/6/29 10:06 |
|
223 |
*/ |
|
224 |
private void checkParam(SysNoticeParam sysNoticeParam, boolean isAddOrEdit) { |
|
225 |
//保存或编辑时,传递的状态参数应为草稿,或发布 |
|
226 |
Integer status = sysNoticeParam.getStatus(); |
|
227 |
if (isAddOrEdit) { |
|
228 |
if (!NoticeStatusEnum.DRAFT.getCode().equals(status) && |
|
229 |
!NoticeStatusEnum.PUBLIC.getCode().equals(status)) { |
|
230 |
throw new ServiceException(SysNoticeExceptionEnum.NOTICE_STATUS_ERROR); |
|
231 |
} |
|
232 |
} else { |
|
233 |
//修改状态时,传递的状态参数应为撤回或删除或发布 |
|
234 |
if (!NoticeStatusEnum.CANCEL.getCode().equals(status) && |
|
235 |
!NoticeStatusEnum.DELETED.getCode().equals(status) && |
|
236 |
!NoticeStatusEnum.PUBLIC.getCode().equals(status)) { |
|
237 |
throw new ServiceException(SysNoticeExceptionEnum.NOTICE_STATUS_ERROR); |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* 获取系统通知公告 |
|
245 |
* |
|
246 |
* @author xuyuxiang |
|
247 |
* @date 2020/6/29 9:58 |
|
248 |
*/ |
|
249 |
private SysNotice querySysNotice(SysNoticeParam sysNoticeParam) { |
|
250 |
SysNotice sysNotice = this.getById(sysNoticeParam.getId()); |
|
251 |
if (ObjectUtil.isNull(sysNotice)) { |
|
252 |
throw new ServiceException(SysNoticeExceptionEnum.NOTICE_NOT_EXIST); |
|
253 |
} |
|
254 |
return sysNotice; |
|
255 |
} |
|
256 |
|
|
257 |
} |