懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
提交 | 用户 | 时间
71e81e 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.system.controller;
17
18 import cn.hutool.core.bean.BeanUtil;
19 import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
20 import cn.stylefeng.guns.base.log.BussinessLog;
21 import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
22 import cn.stylefeng.guns.sys.core.constant.dictmap.DeleteDict;
23 import cn.stylefeng.guns.sys.core.constant.dictmap.NoticeMap;
24 import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory;
25 import cn.stylefeng.guns.sys.core.log.LogObjectHolder;
26 import cn.stylefeng.guns.sys.modular.system.entity.Notice;
27 import cn.stylefeng.guns.sys.modular.system.service.NoticeService;
28 import cn.stylefeng.guns.sys.modular.system.warpper.NoticeWrapper;
29 import cn.stylefeng.roses.core.base.controller.BaseController;
30 import cn.stylefeng.roses.core.util.ToolUtil;
31 import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
32 import cn.stylefeng.roses.kernel.model.response.ResponseData;
33 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Controller;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestParam;
38 import org.springframework.web.bind.annotation.ResponseBody;
39
40 import java.util.Date;
41 import java.util.Map;
42
43 /**
44  * 通知控制器
45  *
46  * @author fengshuonan
47  * @Date 2017-05-09 23:02:21
48  */
49 @Controller
50 @RequestMapping("/notice")
51 public class NoticeController extends BaseController {
52
53     private String PREFIX = "/modular/system/notice/";
54
55     @Autowired
56     private NoticeService noticeService;
57
58     /**
59      * 跳转到通知列表首页
60      *
61      * @author fengshuonan
62      * @Date 2018/12/23 6:06 PM
63      */
64     @RequestMapping("")
65     public String index() {
66         return PREFIX + "notice.html";
67     }
68
69     /**
70      * 跳转到添加通知
71      *
72      * @author fengshuonan
73      * @Date 2018/12/23 6:06 PM
74      */
75     @RequestMapping("/notice_add")
76     public String noticeAdd() {
77         return PREFIX + "notice_add.html";
78     }
79
80     /**
81      * 跳转到修改通知
82      *
83      * @author fengshuonan
84      * @Date 2018/12/23 6:06 PM
85      */
86     @RequestMapping("/notice_update")
87     public String noticeUpdate() {
88         return PREFIX + "notice_edit.html";
89     }
90
91     /**
92      * 获取通知详情
93      *
94      * @author fengshuonan
95      * @Date 2019/8/26 18:14
96      */
97     @RequestMapping("/detail")
98     @ResponseBody
99     public ResponseData noticeDetail(Long noticeId) {
100         Notice notice = this.noticeService.getById(noticeId);
101         Map<String, Object> noticeMap = BeanUtil.beanToMap(notice);
102         return ResponseData.success(noticeMap);
103     }
104
105     /**
106      * 获取通知列表
107      *
108      * @author fengshuonan
109      * @Date 2018/12/23 6:06 PM
110      */
111     @RequestMapping(value = "/list")
112     @ResponseBody
113     public Object list(String condition) {
114         Page<Map<String, Object>> list = this.noticeService.list(condition);
115         Page<Map<String, Object>> wrap = new NoticeWrapper(list).wrap();
116         return LayuiPageFactory.createPageInfo(wrap);
117     }
118
119     /**
120      * 新增通知
121      *
122      * @author fengshuonan
123      * @Date 2018/12/23 6:06 PM
124      */
125     @RequestMapping(value = "/add")
126     @ResponseBody
127     @BussinessLog(value = "新增通知", key = "title", dict = NoticeMap.class)
128     public Object add(Notice notice) {
129         if (ToolUtil.isOneEmpty(notice, notice.getTitle(), notice.getContent())) {
130             throw new RequestEmptyException("通知标题或内容为空");
131         }
132         notice.setCreateUser(LoginContextHolder.getContext().getUserId());
133         notice.setCreateTime(new Date());
134         this.noticeService.save(notice);
135         return SUCCESS_TIP;
136     }
137
138     /**
139      * 删除通知
140      *
141      * @author fengshuonan
142      * @Date 2018/12/23 6:06 PM
143      */
144     @RequestMapping(value = "/delete")
145     @ResponseBody
146     @BussinessLog(value = "删除通知", key = "noticeId", dict = DeleteDict.class)
147     public Object delete(@RequestParam Long noticeId) {
148
149         //缓存通知名称
150         LogObjectHolder.me().set(ConstantFactory.me().getNoticeTitle(noticeId));
151
152         this.noticeService.removeById(noticeId);
153
154         return SUCCESS_TIP;
155     }
156
157     /**
158      * 修改通知
159      *
160      * @author fengshuonan
161      * @Date 2018/12/23 6:06 PM
162      */
163     @RequestMapping(value = "/update")
164     @ResponseBody
165     @BussinessLog(value = "修改通知", key = "title", dict = NoticeMap.class)
166     public Object update(Notice notice) {
167         if (ToolUtil.isOneEmpty(notice, notice.getNoticeId(), notice.getTitle(), notice.getContent())) {
168             throw new RequestEmptyException("通知标题或内容为空");
169         }
170         Notice old = this.noticeService.getById(notice.getNoticeId());
171         old.setTitle(notice.getTitle());
172         old.setContent(notice.getContent());
173         this.noticeService.updateById(old);
174         return SUCCESS_TIP;
175     }
176
177 }