提交 | 用户 | 时间
|
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.auth.model.LoginUser; |
|
21 |
import cn.stylefeng.guns.base.oshi.SystemHardwareInfo; |
|
22 |
import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory; |
|
23 |
import cn.stylefeng.guns.sys.core.log.LogObjectHolder; |
|
24 |
import cn.stylefeng.guns.sys.core.util.DefaultImages; |
|
25 |
import cn.stylefeng.guns.sys.modular.system.entity.Notice; |
|
26 |
import cn.stylefeng.guns.sys.modular.system.entity.User; |
|
27 |
import cn.stylefeng.guns.sys.modular.system.model.UploadResult; |
|
28 |
import cn.stylefeng.guns.sys.modular.system.service.FileInfoService; |
|
29 |
import cn.stylefeng.guns.sys.modular.system.service.NoticeService; |
|
30 |
import cn.stylefeng.guns.sys.modular.system.service.UserService; |
|
31 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
32 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
33 |
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException; |
|
34 |
import cn.stylefeng.roses.kernel.model.exception.ServiceException; |
|
35 |
import cn.stylefeng.roses.kernel.model.exception.enums.CoreExceptionEnum; |
|
36 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
37 |
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData; |
|
38 |
import lombok.extern.slf4j.Slf4j; |
|
39 |
import org.springframework.beans.factory.annotation.Autowired; |
|
40 |
import org.springframework.stereotype.Controller; |
|
41 |
import org.springframework.ui.Model; |
|
42 |
import org.springframework.web.bind.annotation.*; |
|
43 |
import org.springframework.web.multipart.MultipartFile; |
|
44 |
|
|
45 |
import javax.servlet.http.HttpServletResponse; |
|
46 |
import java.io.IOException; |
|
47 |
import java.io.UnsupportedEncodingException; |
|
48 |
import java.net.URLDecoder; |
|
49 |
import java.util.HashMap; |
|
50 |
import java.util.List; |
|
51 |
|
|
52 |
/** |
|
53 |
* 通用控制器 |
|
54 |
* |
|
55 |
* @author fengshuonan |
|
56 |
* @Date 2017年2月17日20:27:22 |
|
57 |
*/ |
|
58 |
@Controller |
|
59 |
@RequestMapping("/system") |
|
60 |
@Slf4j |
|
61 |
public class SystemController extends BaseController { |
|
62 |
|
|
63 |
@Autowired |
|
64 |
private UserService userService; |
|
65 |
|
|
66 |
@Autowired |
|
67 |
private FileInfoService fileInfoService; |
|
68 |
|
|
69 |
@Autowired |
|
70 |
private NoticeService noticeService; |
|
71 |
|
|
72 |
/** |
|
73 |
* 控制台页面 |
|
74 |
* |
|
75 |
* @author fengshuonan |
|
76 |
* @Date 2018/12/24 22:43 |
|
77 |
*/ |
|
78 |
@RequestMapping("/console") |
|
79 |
public String console() { |
|
80 |
return "/modular/frame/console.html"; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* 分析页面 |
|
85 |
* |
|
86 |
* @author fengshuonan |
|
87 |
* @Date 2018/12/24 22:43 |
|
88 |
*/ |
|
89 |
@RequestMapping("/console2") |
|
90 |
public String console2() { |
|
91 |
return "/modular/frame/console2.html"; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* 系统硬件信息页面 |
|
96 |
* |
|
97 |
* @author fengshuonan |
|
98 |
* @Date 2018/12/24 22:43 |
|
99 |
*/ |
|
100 |
@RequestMapping("/systemInfo") |
|
101 |
public String systemInfo(Model model) { |
|
102 |
|
|
103 |
SystemHardwareInfo systemHardwareInfo = new SystemHardwareInfo(); |
|
104 |
systemHardwareInfo.copyTo(); |
|
105 |
|
|
106 |
model.addAttribute("server", systemHardwareInfo); |
|
107 |
|
|
108 |
return "/modular/frame/systemInfo.html"; |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* 跳转到首页通知 |
|
113 |
* |
|
114 |
* @author fengshuonan |
|
115 |
* @Date 2018/12/23 6:06 PM |
|
116 |
*/ |
|
117 |
@RequestMapping("/notice") |
|
118 |
public String hello() { |
|
119 |
List<Notice> notices = noticeService.list(); |
|
120 |
super.setAttr("noticeList", notices); |
|
121 |
return "/modular/frame/notice.html"; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* 主页面 |
|
126 |
* |
|
127 |
* @author fengshuonan |
|
128 |
* @Date 2019/1/24 3:38 PM |
|
129 |
*/ |
|
130 |
@RequestMapping("/welcome") |
|
131 |
public String welcome() { |
|
132 |
return "/modular/frame/welcome.html"; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* 主题页面 |
|
137 |
* |
|
138 |
* @author fengshuonan |
|
139 |
* @Date 2019/1/24 3:38 PM |
|
140 |
*/ |
|
141 |
@RequestMapping("/theme") |
|
142 |
public String theme() { |
|
143 |
return "/modular/frame/theme.html"; |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* 锁屏界面 |
|
148 |
* |
|
149 |
* @author fengshuonan |
|
150 |
* @Date 2020/3/8 17:19 |
|
151 |
*/ |
|
152 |
@RequestMapping("/lock") |
|
153 |
public String lock() { |
|
154 |
return "/modular/frame/lock-screen.html"; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* 跳转到修改密码界面 |
|
159 |
* |
|
160 |
* @author fengshuonan |
|
161 |
* @Date 2018/12/24 22:43 |
|
162 |
*/ |
|
163 |
@RequestMapping("/user_chpwd") |
|
164 |
public String chPwd() { |
|
165 |
return "/modular/frame/password.html"; |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* 个人消息列表 |
|
170 |
* |
|
171 |
* @author fengshuonan |
|
172 |
* @Date 2018/12/24 22:43 |
|
173 |
*/ |
|
174 |
@RequestMapping("/message") |
|
175 |
public String message() { |
|
176 |
return "/modular/frame/message.html"; |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* 跳转到查看用户详情页面 |
|
181 |
* |
|
182 |
* @author fengshuonan |
|
183 |
* @Date 2018/12/24 22:43 |
|
184 |
*/ |
|
185 |
@RequestMapping("/user_info") |
|
186 |
public String userInfo(Model model) { |
|
187 |
Long userId = LoginContextHolder.getContext().getUserId(); |
|
188 |
User user = this.userService.getById(userId); |
|
189 |
|
|
190 |
model.addAllAttributes(BeanUtil.beanToMap(user)); |
|
191 |
model.addAttribute("roleName", ConstantFactory.me().getRoleName(user.getRoleId())); |
|
192 |
model.addAttribute("deptName", ConstantFactory.me().getDeptName(user.getDeptId())); |
|
193 |
model.addAttribute("avatar", DefaultImages.defaultAvatarUrl()); |
|
194 |
LogObjectHolder.me().set(user); |
|
195 |
|
|
196 |
return "/modular/frame/user_info.html"; |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* 通用的树列表选择器 |
|
201 |
* |
|
202 |
* @author fengshuonan |
|
203 |
* @Date 2018/12/23 6:59 PM |
|
204 |
*/ |
|
205 |
@RequestMapping("/commonTree") |
|
206 |
public String deptTreeList(@RequestParam("formName") String formName, |
|
207 |
@RequestParam("formId") String formId, |
|
208 |
@RequestParam("treeUrl") String treeUrl, Model model) { |
|
209 |
|
|
210 |
if (ToolUtil.isOneEmpty(formName, formId, treeUrl)) { |
|
211 |
throw new RequestEmptyException("请求数据不完整!"); |
|
212 |
} |
|
213 |
|
|
214 |
try { |
|
215 |
model.addAttribute("formName", URLDecoder.decode(formName, "UTF-8")); |
|
216 |
model.addAttribute("formId", URLDecoder.decode(formId, "UTF-8")); |
|
217 |
model.addAttribute("treeUrl", URLDecoder.decode(treeUrl, "UTF-8")); |
|
218 |
} catch (UnsupportedEncodingException e) { |
|
219 |
throw new RequestEmptyException("请求数据不完整!"); |
|
220 |
} |
|
221 |
|
|
222 |
return "/common/tree_dlg.html"; |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* 更新头像 |
|
227 |
* |
|
228 |
* @author fengshuonan |
|
229 |
* @Date 2018/11/9 12:45 PM |
|
230 |
*/ |
|
231 |
@RequestMapping("/updateAvatar") |
|
232 |
@ResponseBody |
|
233 |
public Object uploadAvatar(@RequestParam("fileId") String fileId) { |
|
234 |
|
|
235 |
if (ToolUtil.isEmpty(fileId)) { |
|
236 |
throw new RequestEmptyException("请求头像为空"); |
|
237 |
} |
|
238 |
|
|
239 |
fileInfoService.updateAvatar(fileId); |
|
240 |
|
|
241 |
return SUCCESS_TIP; |
|
242 |
} |
|
243 |
|
|
244 |
/** |
|
245 |
* 预览头像 |
|
246 |
* |
|
247 |
* @author fengshuonan |
|
248 |
* @Date 2018/11/9 12:45 PM |
|
249 |
*/ |
|
250 |
@RequestMapping("/previewAvatar") |
|
251 |
@ResponseBody |
|
252 |
public Object previewAvatar(HttpServletResponse response) { |
|
253 |
|
|
254 |
//输出图片的文件流 |
|
255 |
try { |
|
256 |
response.setContentType("image/jpeg"); |
|
257 |
byte[] decode = this.fileInfoService.previewAvatar(); |
|
258 |
response.getOutputStream().write(decode); |
|
259 |
} catch (IOException e) { |
|
260 |
throw new ServiceException(CoreExceptionEnum.SERVICE_ERROR); |
|
261 |
} |
|
262 |
|
|
263 |
return null; |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* 获取当前用户详情 |
|
268 |
* |
|
269 |
* @author fengshuonan |
|
270 |
* @Date 2018/12/23 6:59 PM |
|
271 |
*/ |
|
272 |
@RequestMapping("/currentUserInfo") |
|
273 |
@ResponseBody |
|
274 |
public ResponseData getUserInfo() { |
|
275 |
|
|
276 |
LoginUser currentUser = LoginContextHolder.getContext().getUser(); |
|
277 |
if (currentUser == null) { |
|
278 |
throw new ServiceException(CoreExceptionEnum.NO_CURRENT_USER); |
|
279 |
} |
|
280 |
|
|
281 |
return new SuccessResponseData(userService.getUserInfo(currentUser.getId())); |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* layui上传组件 通用文件上传接口 |
|
286 |
* |
|
287 |
* @author fengshuonan |
|
288 |
* @Date 2019-2-23 10:48:29 |
|
289 |
*/ |
|
290 |
@RequestMapping(method = RequestMethod.POST, path = "/upload") |
|
291 |
@ResponseBody |
|
292 |
public ResponseData layuiUpload(@RequestPart("file") MultipartFile file) { |
|
293 |
|
|
294 |
UploadResult uploadResult = this.fileInfoService.uploadFile(file); |
|
295 |
String fileId = uploadResult.getFileId(); |
|
296 |
|
|
297 |
HashMap<String, Object> map = new HashMap<>(); |
|
298 |
map.put("fileId", fileId); |
|
299 |
|
|
300 |
return ResponseData.success(0, "上传成功", map); |
|
301 |
} |
|
302 |
|
|
303 |
|
|
304 |
} |