提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.service.notice; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.pojo.PageResult; |
|
4 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
5 |
import com.iailab.module.system.controller.admin.notice.vo.NoticePageReqVO; |
|
6 |
import com.iailab.module.system.controller.admin.notice.vo.NoticeSaveReqVO; |
|
7 |
import com.iailab.module.system.dal.dataobject.notice.NoticeDO; |
|
8 |
import com.iailab.module.system.dal.mysql.notice.NoticeMapper; |
|
9 |
import com.google.common.annotations.VisibleForTesting; |
|
10 |
import org.springframework.stereotype.Service; |
|
11 |
|
|
12 |
import javax.annotation.Resource; |
|
13 |
|
|
14 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
15 |
import static com.iailab.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; |
|
16 |
|
|
17 |
/** |
|
18 |
* 通知公告 Service 实现类 |
|
19 |
* |
|
20 |
* @author iailab |
|
21 |
*/ |
|
22 |
@Service |
|
23 |
public class NoticeServiceImpl implements NoticeService { |
|
24 |
|
|
25 |
@Resource |
|
26 |
private NoticeMapper noticeMapper; |
|
27 |
|
|
28 |
@Override |
|
29 |
public Long createNotice(NoticeSaveReqVO createReqVO) { |
|
30 |
NoticeDO notice = BeanUtils.toBean(createReqVO, NoticeDO.class); |
|
31 |
noticeMapper.insert(notice); |
|
32 |
return notice.getId(); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public void updateNotice(NoticeSaveReqVO updateReqVO) { |
|
37 |
// 校验是否存在 |
|
38 |
validateNoticeExists(updateReqVO.getId()); |
|
39 |
// 更新通知公告 |
|
40 |
NoticeDO updateObj = BeanUtils.toBean(updateReqVO, NoticeDO.class); |
|
41 |
noticeMapper.updateById(updateObj); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void deleteNotice(Long id) { |
|
46 |
// 校验是否存在 |
|
47 |
validateNoticeExists(id); |
|
48 |
// 删除通知公告 |
|
49 |
noticeMapper.deleteById(id); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) { |
|
54 |
return noticeMapper.selectPage(reqVO); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public NoticeDO getNotice(Long id) { |
|
59 |
return noticeMapper.selectById(id); |
|
60 |
} |
|
61 |
|
|
62 |
@VisibleForTesting |
|
63 |
public void validateNoticeExists(Long id) { |
|
64 |
if (id == null) { |
|
65 |
return; |
|
66 |
} |
|
67 |
NoticeDO notice = noticeMapper.selectById(id); |
|
68 |
if (notice == null) { |
|
69 |
throw exception(NOTICE_NOT_FOUND); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
} |