提交 | 用户 | 时间
|
1ac2bc
|
1 |
/** |
懒 |
2 |
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng) |
|
3 |
* <p> |
|
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 |
* <p> |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* <p> |
|
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 |
package cn.stylefeng.guns.sys.modular.rest.controller; |
|
17 |
|
|
18 |
import cn.stylefeng.guns.base.auth.context.LoginContextHolder; |
|
19 |
import cn.stylefeng.guns.base.log.BussinessLog; |
|
20 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; |
|
21 |
import cn.stylefeng.guns.sys.core.constant.dictmap.DeleteDict; |
|
22 |
import cn.stylefeng.guns.sys.core.constant.dictmap.NoticeMap; |
|
23 |
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum; |
|
24 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestNotice; |
|
25 |
import cn.stylefeng.guns.sys.modular.rest.service.RestNoticeService; |
|
26 |
import cn.stylefeng.guns.sys.modular.system.entity.Notice; |
|
27 |
import cn.stylefeng.guns.sys.modular.system.warpper.NoticeWrapper; |
|
28 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
29 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
30 |
import cn.stylefeng.roses.kernel.model.exception.ServiceException; |
|
31 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
32 |
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData; |
|
33 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
34 |
import org.springframework.beans.factory.annotation.Autowired; |
|
35 |
import org.springframework.web.bind.annotation.*; |
|
36 |
|
|
37 |
import java.util.Date; |
|
38 |
import java.util.Map; |
|
39 |
|
|
40 |
/** |
|
41 |
* 通知控制器 |
|
42 |
* |
|
43 |
* @author fengshuonan |
|
44 |
* @Date 2017-05-09 23:02:21 |
|
45 |
*/ |
|
46 |
@RestController |
|
47 |
@RequestMapping("/rest/notice") |
|
48 |
public class RestNoticeController extends BaseController { |
|
49 |
|
|
50 |
@Autowired |
|
51 |
private RestNoticeService restNoticeService; |
|
52 |
|
|
53 |
/** |
|
54 |
* 获取通知详情 |
|
55 |
* |
|
56 |
* @author fengshuonan |
|
57 |
* @Date 2018/12/23 6:06 PM |
|
58 |
*/ |
|
59 |
@RequestMapping("/detail/{noticeId}") |
|
60 |
public ResponseData noticeUpdate(@PathVariable Long noticeId) { |
|
61 |
RestNotice notice = this.restNoticeService.getById(noticeId); |
|
62 |
return new SuccessResponseData(notice); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* 获取通知列表 |
|
67 |
* |
|
68 |
* @author fengshuonan |
|
69 |
* @Date 2018/12/23 6:06 PM |
|
70 |
*/ |
|
71 |
@RequestMapping(value = "/list") |
|
72 |
public Object list(String condition) { |
|
73 |
Page<Map<String, Object>> list = this.restNoticeService.list(condition); |
|
74 |
Page<Map<String, Object>> wrap = new NoticeWrapper(list).wrap(); |
|
75 |
return LayuiPageFactory.createPageInfo(wrap); |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* 新增通知 |
|
80 |
* |
|
81 |
* @author fengshuonan |
|
82 |
* @Date 2018/12/23 6:06 PM |
|
83 |
*/ |
|
84 |
@RequestMapping(value = "/add") |
|
85 |
@BussinessLog(value = "新增通知", key = "title", dict = NoticeMap.class) |
|
86 |
public Object add(@RequestBody RestNotice restNotice) { |
|
87 |
if (ToolUtil.isOneEmpty(restNotice, restNotice.getTitle(), restNotice.getContent())) { |
|
88 |
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); |
|
89 |
} |
|
90 |
restNotice.setCreateUser(LoginContextHolder.getContext().getUser().getId()); |
|
91 |
restNotice.setCreateTime(new Date()); |
|
92 |
this.restNoticeService.save(restNotice); |
|
93 |
return SUCCESS_TIP; |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* 删除通知 |
|
98 |
* |
|
99 |
* @author fengshuonan |
|
100 |
* @Date 2018/12/23 6:06 PM |
|
101 |
*/ |
|
102 |
@RequestMapping(value = "/delete") |
|
103 |
@BussinessLog(value = "删除通知", key = "noticeId", dict = DeleteDict.class) |
|
104 |
public Object delete(@RequestParam Long noticeId) { |
|
105 |
|
|
106 |
this.restNoticeService.removeById(noticeId); |
|
107 |
|
|
108 |
return SUCCESS_TIP; |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* 修改通知 |
|
113 |
* |
|
114 |
* @author fengshuonan |
|
115 |
* @Date 2018/12/23 6:06 PM |
|
116 |
*/ |
|
117 |
@RequestMapping(value = "/update") |
|
118 |
@BussinessLog(value = "修改通知", key = "title", dict = NoticeMap.class) |
|
119 |
public Object update(@RequestBody Notice notice) { |
|
120 |
if (ToolUtil.isOneEmpty(notice, notice.getNoticeId(), notice.getTitle(), notice.getContent())) { |
|
121 |
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); |
|
122 |
} |
|
123 |
RestNotice old = this.restNoticeService.getById(notice.getNoticeId()); |
|
124 |
old.setTitle(notice.getTitle()); |
|
125 |
old.setContent(notice.getContent()); |
|
126 |
this.restNoticeService.updateById(old); |
|
127 |
return SUCCESS_TIP; |
|
128 |
} |
|
129 |
|
|
130 |
} |