NotifyController.java
4.87 KB
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
package com.bootdo.oa.controller;
import com.bootdo.common.config.Constant;
import com.bootdo.common.controller.BaseController;
import com.bootdo.common.domain.DictDO;
import com.bootdo.common.service.DictService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.oa.domain.NotifyDO;
import com.bootdo.oa.domain.NotifyRecordDO;
import com.bootdo.oa.service.NotifyRecordService;
import com.bootdo.oa.service.NotifyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.security.Principal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 通知通告
*
* @author chglee
* @email 1992lcg@163.com
* @date 2017-10-05 17:11:16
*/
@Controller
@RequestMapping("/oa/notify")
public class NotifyController extends BaseController {
@Autowired
private NotifyService notifyService;
@Autowired
private NotifyRecordService notifyRecordService;
@Autowired
private DictService dictService;
@GetMapping()
@RequiresPermissions("oa:notify:notify")
String oaNotify() {
return "oa/notify/notify";
}
@ResponseBody
@GetMapping("/list")
@RequiresPermissions("oa:notify:notify")
public PageUtils list(@RequestParam Map<String, Object> params) {
// 查询列表数据
Query query = new Query(params);
List<NotifyDO> notifyList = notifyService.list(query);
int total = notifyService.count(query);
PageUtils pageUtils = new PageUtils(notifyList, total);
return pageUtils;
}
@GetMapping("/add")
@RequiresPermissions("oa:notify:add")
String add() {
return "oa/notify/add";
}
@GetMapping("/edit/{id}")
@RequiresPermissions("oa:notify:edit")
String edit(@PathVariable("id") Long id, Model model) {
NotifyDO notify = notifyService.get(id);
List<DictDO> dictDOS = dictService.listByType("oa_notify_type");
String type = notify.getType();
for (DictDO dictDO:dictDOS){
if(type.equals(dictDO.getValue())){
dictDO.setRemarks("checked");
}
}
model.addAttribute("oaNotifyTypes",dictDOS);
model.addAttribute("notify", notify);
return "oa/notify/edit";
}
/**
* 保存
*/
@ResponseBody
@PostMapping("/save")
@RequiresPermissions("oa:notify:add")
public R save(NotifyDO notify) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
notify.setCreateBy(getUserId());
if (notifyService.save(notify) > 0) {
return R.ok();
}
return R.error();
}
/**
* 修改
*/
@ResponseBody
@RequestMapping("/update")
@RequiresPermissions("oa:notify:edit")
public R update(NotifyDO notify) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
notifyService.update(notify);
return R.ok();
}
/**
* 删除
*/
@PostMapping("/remove")
@ResponseBody
@RequiresPermissions("oa:notify:remove")
public R remove(Long id) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (notifyService.remove(id) > 0) {
return R.ok();
}
return R.error();
}
/**
* 删除
*/
@PostMapping("/batchRemove")
@ResponseBody
@RequiresPermissions("oa:notify:batchRemove")
public R remove(@RequestParam("ids[]") Long[] ids) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
notifyService.batchRemove(ids);
return R.ok();
}
@ResponseBody
@GetMapping("/message")
PageUtils message() {
Map<String, Object> params = new HashMap<>(16);
params.put("offset", 0);
params.put("limit", 3);
Query query = new Query(params);
query.put("userId", getUserId());
query.put("isRead",Constant.OA_NOTIFY_READ_NO);
return notifyService.selfList(query);
}
@GetMapping("/selfNotify")
String selefNotify() {
return "oa/notify/selfNotify";
}
@ResponseBody
@GetMapping("/selfList")
PageUtils selfList(@RequestParam Map<String, Object> params) {
Query query = new Query(params);
query.put("userId", getUserId());
return notifyService.selfList(query);
}
@GetMapping("/read/{id}")
@RequiresPermissions("oa:notify:edit")
String read(@PathVariable("id") Long id, Model model) {
NotifyDO notify = notifyService.get(id);
//更改阅读状态
NotifyRecordDO notifyRecordDO = new NotifyRecordDO();
notifyRecordDO.setNotifyId(id);
notifyRecordDO.setUserId(getUserId());
notifyRecordDO.setReadDate(new Date());
notifyRecordDO.setIsRead(Constant.OA_NOTIFY_READ_YES);
notifyRecordService.changeRead(notifyRecordDO);
model.addAttribute("notify", notify);
return "oa/notify/read";
}
}