puzhibing
2023-02-15 2811bab657aab4145b65a45a824fb63e93b58e30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package com.stylefeng.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.modular.system.util.task.base.QuartzManager;
import com.stylefeng.guns.modular.system.util.task.base.TimeJobType;
import com.stylefeng.guns.modular.system.util.task.jobs.AddNotice;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.TNotices;
import com.stylefeng.guns.modular.system.service.ITNoticesService;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 滚动消息设置控制器
 *
 * @author fengshuonan
 * @Date 2020-06-10 15:21:25
 */
@Controller
@RequestMapping("/tNotices")
public class TNoticesController extends BaseController {
 
    private String PREFIX = "/system/tNotices/";
 
    @Autowired
    private ITNoticesService tNoticesService;
 
    /**
     * 跳转到滚动消息设置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tNotices.html";
    }
 
    /**
     * 跳转到系统公告设置首页
     */
    @RequestMapping("/system")
    public String system() {
        return PREFIX + "system.html";
    }
 
    /**
     * 跳转到添加滚动消息设置
     */
    @RequestMapping("/tNotices_add")
    public String tNoticesAdd() {
        return PREFIX + "tNotices_add.html";
    }
 
    /**
     * 跳转到添加系统公告
     */
    @RequestMapping("/system_add")
    public String system_add() {
        return PREFIX + "system_add.html";
    }
 
    /**
     * 跳转到修改滚动消息设置
     */
    @RequestMapping("/tNotices_update/{tNoticesId}")
    public String tNoticesUpdate(@PathVariable Integer tNoticesId, Model model) {
        TNotices tNotices = tNoticesService.selectById(tNoticesId);
        model.addAttribute("item",tNotices);
        LogObjectHolder.me().set(tNotices);
        return PREFIX + "tNotices_edit.html";
    }
 
    /**
     * 跳转到修改系统公告
     */
    @RequestMapping("/system_update/{tNoticesId}")
    public String system_update(@PathVariable Integer tNoticesId, Model model) {
        TNotices tNotices = tNoticesService.selectById(tNoticesId);
        model.addAttribute("item",tNotices);
        LogObjectHolder.me().set(tNotices);
        return PREFIX + "system_update.html";
    }
 
    /**
     * 获取滚动消息设置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,String content) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        if (ShiroKit.getUser().getRoleType() != 1){
            page.setRecords(null);
        }else{
            page.setRecords(tNoticesService.getRollingNoticeList(page,beginTime,endTime,1,content));
        }
        return super.packForBT(page);
    }
 
    /**
     * 获取系统公告设置列表
     */
    @RequestMapping(value = "/listSystem")
    @ResponseBody
    public Object listSystem(String insertTime,String content) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        if (ShiroKit.getUser().getRoleType() != 1){
            page.setRecords(null);
        }else{
            page.setRecords(tNoticesService.getRollingNoticeList(page,beginTime,endTime,2,content));
        }
        return super.packForBT(page);
    }
 
    /**
     * 新增滚动消息设置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TNotices tNotices) {
        tNotices.setIsDelete(1);
        tNotices.setInsertTime(new Date());
        tNotices.setInsertUser(ShiroKit.getUser().getId());
        tNotices.setType(1);
        tNoticesService.insert(tNotices);
        return SUCCESS_TIP;
    }
 
    /**
     * 新增系统公告
     */
    @RequestMapping(value = "/addSystem")
    @ResponseBody
    public Object addSystem(TNotices tNotices) {
        tNotices.setIsDelete(1);
        tNotices.setInsertTime(new Date());
        tNotices.setInsertUser(ShiroKit.getUser().getId());
        tNotices.setType(2);
        tNoticesService.insert(tNotices);
 
        if (tNotices.getIsShow() == 1){  //发布
            //定时1秒后执行
            Map<String,Object> maps=new HashMap<>();
            maps.put("noticeId",tNotices.getId());
            QuartzManager.addJob(AddNotice.class, (AddNotice.name+tNotices.getId()).toUpperCase(), TimeJobType.UNLOCK,DateUtil.getDate_strYMdHms(new Date().getTime() + 1*1000) , maps);
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 发布系统公告
     */
    @RequestMapping(value = "/sendSystem")
    @ResponseBody
    public Object sendSystem(@RequestParam Integer tNoticesId) {
        TNotices tNotices = tNoticesService.selectById(tNoticesId);
        if (tNotices.getIsShow() == 2){
            //定时1秒后执行
            Map<String,Object> maps=new HashMap<>();
            maps.put("noticeId",tNotices.getId());
            QuartzManager.addJob(AddNotice.class, (AddNotice.name+tNotices.getId()).toUpperCase(), TimeJobType.UNLOCK,DateUtil.getDate_strYMdHms(new Date().getTime() + 1*1000) , maps);
        }
        tNotices.setIsShow(1);
        tNotices.setUpdateTime(new Date());
        tNotices.setUpdateUser(ShiroKit.getUser().getId());
        tNoticesService.updateById(tNotices);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tNoticesId) {
        TNotices tNotices = tNoticesService.selectById(tNoticesId);
        tNotices.setIsDelete(2);
        tNotices.setFlag("3");
        tNotices.setUpdateTime(new Date());
        tNotices.setUpdateUser(ShiroKit.getUser().getId());
        tNoticesService.updateById(tNotices);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改滚动消息设置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TNotices tNotices) {
        tNotices.setUpdateUser(ShiroKit.getUser().getId());
        tNotices.setUpdateTime(new Date());
        tNoticesService.updateById(tNotices);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改系统公告
     */
    @RequestMapping(value = "/updateSystem")
    @ResponseBody
    public Object updateSystem(TNotices tNotices) {
        tNotices.setUpdateUser(ShiroKit.getUser().getId());
        tNotices.setUpdateTime(new Date());
        tNoticesService.updateById(tNotices);
 
        if (tNotices.getIsShow() == 1){  //发布
            //定时1秒后执行
            Map<String,Object> maps=new HashMap<>();
            maps.put("noticeId",tNotices.getId());
            QuartzManager.addJob(AddNotice.class, (AddNotice.name+tNotices.getId()).toUpperCase(), TimeJobType.UNLOCK,DateUtil.getDate_strYMdHms(new Date().getTime() + 1*1000) , maps);
        }
        return SUCCESS_TIP;
    }
 
}