提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.workflow.modular.controller; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.sys.modular.system.entity.Role; |
|
4 |
import cn.stylefeng.guns.sys.modular.system.mapper.RoleMapper; |
|
5 |
import cn.stylefeng.guns.sys.modular.system.mapper.UserMapper; |
|
6 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
7 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
8 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.stereotype.Controller; |
|
11 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
12 |
import org.springframework.web.bind.annotation.RequestParam; |
|
13 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
14 |
|
|
15 |
import java.util.Arrays; |
|
16 |
import java.util.HashMap; |
|
17 |
import java.util.List; |
|
18 |
import java.util.Map; |
|
19 |
|
|
20 |
/** |
|
21 |
* Act通用Controller |
|
22 |
* |
|
23 |
* @author stylefeng |
|
24 |
* @date 2019/8/27 - 17:34 |
|
25 |
*/ |
|
26 |
@Controller |
|
27 |
@RequestMapping("/common") |
|
28 |
public class ActCommonController { |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private UserMapper userMapper; |
|
32 |
|
|
33 |
@Autowired |
|
34 |
private RoleMapper roleMapper; |
|
35 |
|
|
36 |
/** |
|
37 |
* 设置用户页面 |
|
38 |
* |
|
39 |
* @author yaopu |
|
40 |
* @date 2019/8/30 - 09:34 |
|
41 |
*/ |
|
42 |
@RequestMapping(value = "/toSetUserPage") |
|
43 |
public String toSetUserPage() { |
|
44 |
return "/modular/act/model/user.html"; |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* 设置角色页面 |
|
49 |
* |
|
50 |
* @author yaopu |
|
51 |
* @date 2019/8/30 - 09:34 |
|
52 |
*/ |
|
53 |
@RequestMapping(value = "/toSetRolePage") |
|
54 |
public String toSetRolePage() { |
|
55 |
return "/modular/act/model/role.html"; |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* 显示用户列表(弹窗选择用) |
|
60 |
* |
|
61 |
* @author stylefeng |
|
62 |
* @date 2019/8/27 - 17:34 |
|
63 |
*/ |
|
64 |
@RequestMapping(value = "/listUsersForWindow") |
|
65 |
@ResponseBody |
|
66 |
public Object listUsersForWindow(@RequestParam("currentPage") Integer currentPage, |
|
67 |
@RequestParam("showCount") Integer showCount, |
|
68 |
@RequestParam(value = "KEYWORDS", required = false) String keywords, |
|
69 |
@RequestParam("ROLE_ID") String roleId, |
|
70 |
@RequestParam(value = "STRARTTIME", required = false) String strarttime) { |
|
71 |
|
|
72 |
Page page = new Page(); |
|
73 |
page.setCurrent(currentPage); |
|
74 |
if (showCount == -1) { |
|
75 |
showCount = 10; |
|
76 |
} |
|
77 |
page.setSize(showCount); |
|
78 |
|
|
79 |
//查询人员列表信息 |
|
80 |
Page<Map<String, Object>> mapPage = userMapper.selectUsersByRole(page, keywords, strarttime, null, roleId); |
|
81 |
List<Map<String, Object>> records = mapPage.getRecords(); |
|
82 |
|
|
83 |
//查询角色信息 |
|
84 |
Page rolePage = new Page(); |
|
85 |
rolePage.setSize(9999); |
|
86 |
IPage<Map<String, Object>> listRole = roleMapper.listRole(rolePage, null); |
|
87 |
List<Map<String, Object>> roleList = listRole.getRecords(); |
|
88 |
|
|
89 |
//设置前端所需参数 |
|
90 |
if (ToolUtil.isNotEmpty(records) && records.size() > 0) { |
|
91 |
for (int i = 0; i < records.size(); i++) { |
|
92 |
records.get(i).put("USERNAME", records.get(i).get("account")); |
|
93 |
records.get(i).put("NAME", records.get(i).get("name")); |
|
94 |
|
|
95 |
String roleIdItem = (String) records.get(i).get("roleId"); |
|
96 |
String[] split = roleIdItem.split(","); |
|
97 |
List<Role> roles = roleMapper.selectBatchIds(Arrays.asList(split)); |
|
98 |
StringBuilder roleNameString = new StringBuilder(""); |
|
99 |
for (int j = 0; j < roles.size(); j++) { |
|
100 |
if (j == roles.size() - 1) { |
|
101 |
roleNameString.append(roles.get(j).getName()); |
|
102 |
break; |
|
103 |
} |
|
104 |
roleNameString.append(roles.get(j).getName()).append(","); |
|
105 |
} |
|
106 |
records.get(i).put("ROLE_NAME", roleNameString); |
|
107 |
} |
|
108 |
} |
|
109 |
if (ToolUtil.isNotEmpty(roleList) && roleList.size() > 0) { |
|
110 |
for (int i = 0; i < roleList.size(); i++) { |
|
111 |
roleList.get(i).put("role_NAME", roleList.get(i).get("name")); |
|
112 |
roleList.get(i).put("role_ID", roleList.get(i).get("id")); |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
//分页信息 |
|
117 |
int totalResult = (int) page.getTotal(); |
|
118 |
int totalPage = (int) page.getPages(); |
|
119 |
int currentResult = (currentPage - 1) * showCount; |
|
120 |
if (currentResult < 0) { |
|
121 |
currentResult = 0; |
|
122 |
} |
|
123 |
|
|
124 |
Map<String, Object> pageInfo = new HashMap<>(); |
|
125 |
pageInfo.put("showCount", showCount); |
|
126 |
pageInfo.put("totalPage", totalPage); |
|
127 |
pageInfo.put("totalResult", totalResult); |
|
128 |
pageInfo.put("currentPage", currentPage); |
|
129 |
pageInfo.put("currentResult", currentResult); |
|
130 |
pageInfo.put("entityOrField", true); |
|
131 |
pageInfo.put("pageStr", getPageStr(totalResult, currentPage, totalPage, showCount)); |
|
132 |
pageInfo.put("pageStrSimplify", getPageStrSimplify(totalResult, currentPage, totalPage)); |
|
133 |
pageInfo.put("pageStrSimplify2", getPageStrSimplify2(totalResult, currentPage, totalPage)); |
|
134 |
|
|
135 |
//返回结果 |
|
136 |
Map<String, Object> resultMap = new HashMap<>(); |
|
137 |
resultMap.put("userList", records); |
|
138 |
resultMap.put("result", "success"); |
|
139 |
resultMap.put("roleList", roleList); |
|
140 |
resultMap.put("page", pageInfo); |
|
141 |
resultMap.put("pd", ""); |
|
142 |
return resultMap; |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* 选择角色(弹窗选择用) |
|
147 |
* |
|
148 |
* @author stylefeng |
|
149 |
* @date 2019/8/28 - 13:10 |
|
150 |
*/ |
|
151 |
@RequestMapping(value = "/roleListWindow") |
|
152 |
@ResponseBody |
|
153 |
public Object roleListWindow(@RequestParam("currentPage") Integer currentPage, |
|
154 |
@RequestParam("showCount") Integer showCount, |
|
155 |
@RequestParam("KEYWORDS") String keywords) { |
|
156 |
|
|
157 |
Page page = new Page(); |
|
158 |
page.setCurrent(currentPage); |
|
159 |
if (showCount == -1) { |
|
160 |
showCount = 10; |
|
161 |
} |
|
162 |
page.setSize(showCount); |
|
163 |
|
|
164 |
//查询角色列表信息 |
|
165 |
Page<Map<String, Object>> mapPage = roleMapper.selectRoles(page, keywords); |
|
166 |
List<Map<String, Object>> records = mapPage.getRecords(); |
|
167 |
|
|
168 |
//设置前端所需参数 |
|
169 |
if (ToolUtil.isNotEmpty(records) && records.size() > 0) { |
|
170 |
for (int i = 0; i < records.size(); i++) { |
|
171 |
records.get(i).put("RNUMBER", records.get(i).get("roleId")); |
|
172 |
records.get(i).put("ROLE_NAME", records.get(i).get("name")); |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
//分页信息 |
|
177 |
int totalResult = (int) page.getTotal(); |
|
178 |
int totalPage = (int) page.getPages(); |
|
179 |
int currentResult = (currentPage - 1) * showCount; |
|
180 |
if (currentResult < 0) { |
|
181 |
currentResult = 0; |
|
182 |
} |
|
183 |
|
|
184 |
Map<String, Object> pageInfo = new HashMap<>(); |
|
185 |
pageInfo.put("showCount", showCount); |
|
186 |
pageInfo.put("totalPage", totalPage); |
|
187 |
pageInfo.put("totalResult", totalResult); |
|
188 |
pageInfo.put("currentPage", currentPage); |
|
189 |
pageInfo.put("currentResult", currentResult); |
|
190 |
pageInfo.put("entityOrField", true); |
|
191 |
pageInfo.put("pageStr", getPageStr(totalResult, currentPage, totalPage, showCount)); |
|
192 |
pageInfo.put("pageStrSimplify", getPageStrSimplify(totalResult, currentPage, totalPage)); |
|
193 |
pageInfo.put("pageStrSimplify2", getPageStrSimplify2(totalResult, currentPage, totalPage)); |
|
194 |
|
|
195 |
//返回结果 |
|
196 |
Map<String, Object> resultMap = new HashMap<>(); |
|
197 |
resultMap.put("roleList", records); |
|
198 |
resultMap.put("result", "success"); |
|
199 |
resultMap.put("page", pageInfo); |
|
200 |
return resultMap; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* 拼接分页 页面及JS函数 |
|
205 |
* |
|
206 |
* @author fengshuonan |
|
207 |
* @Date 2019-08-29 14:10 |
|
208 |
*/ |
|
209 |
private String getPageStr(int totalResult, int currentPage, int totalPage, int showCount) { |
|
210 |
StringBuffer sb = new StringBuffer(); |
|
211 |
if (totalResult > 0) { |
|
212 |
sb.append(" <ul class=\"pagination pull-right no-margin\">\n"); |
|
213 |
if (currentPage == 1) { |
|
214 |
sb.append(" <li style=\"padding-top:10px;\"><a>共").append(totalResult).append("条 </a></li>\n"); |
|
215 |
sb.append(" <li><input type=\"number\" value=\"\" id=\"toGoPage\" style=\"width:36px;padding-top:5px;border-left-width:0px;border-top-width:0px;border-right-width:0px;border-bottom: 1px solid #dbdbdb\" /></li>\n"); |
|
216 |
sb.append(" <li style=\"cursor:pointer;padding-top:10px;\"><a onclick=\"vm.toTZ();\" > 跳转 </a></li>\n"); |
|
217 |
sb.append(" <li style=\"padding-top:10px;\"><a> 首页 </a></li>\n"); |
|
218 |
sb.append(" <li style=\"padding-top:10px;\"><a> 上页 </a></li>\n"); |
|
219 |
} else { |
|
220 |
sb.append(" <li style=\"padding-top:10px;\"><a> 共").append(totalResult).append("条 </a></li>\n"); |
|
221 |
sb.append(" <li><input type=\"number\" value=\"\" id=\"toGoPage\" style=\"width:36px;padding-top:5px;border-left-width:0px;border-top-width:0px;border-right-width:0px;border-bottom: 1px solid #dbdbdb\" /></li>\n"); |
|
222 |
sb.append(" <li style=\"cursor:pointer;padding-top:10px;\"><a onclick=\"vm.toTZ();\" > 跳转 </a></li>\n"); |
|
223 |
sb.append(" <li style=\"cursor:pointer;padding-top:10px;\"><a onclick=\"vm.nextPage(1)\"> 首页 </a></li>\n"); |
|
224 |
sb.append(" <li style=\"cursor:pointer;padding-top:10px;\"><a onclick=\"vm.nextPage(").append(currentPage - 1).append(")\"> 上页 </a></li>\n"); |
|
225 |
} |
|
226 |
|
|
227 |
//分页标签显示数量 |
|
228 |
int showTag = 5; |
|
229 |
int startTag = 1; |
|
230 |
if (currentPage > showTag) { |
|
231 |
startTag = currentPage - 1; |
|
232 |
} |
|
233 |
int endTag = startTag + showTag - 1; |
|
234 |
for (int i = startTag; i <= totalPage && i <= endTag; i++) { |
|
235 |
if (currentPage == i) { |
|
236 |
sb.append("<li style=\"padding-top:10px;\" class=\"active\"><a><font color=\"#3F4D67\"> <b>").append(i).append("</b></font></a></li>\n"); |
|
237 |
|
|
238 |
} else { |
|
239 |
sb.append(" <li style=\"padding-top:10px;\" style=\"cursor:pointer;\"><a style=\"cursor:pointer;\" onclick=\"vm.nextPage(").append(i).append(")\"> ").append(i).append("</a></li>\n"); |
|
240 |
} |
|
241 |
|
|
242 |
} |
|
243 |
if (currentPage == totalPage) { |
|
244 |
sb.append(" <li style=\"padding-top:10px;\"><a> 下页 </a></li>\n"); |
|
245 |
sb.append(" <li style=\"padding-top:10px;\"><a> 尾页 </a></li>\n"); |
|
246 |
} else { |
|
247 |
sb.append(" <li style=\"cursor:pointer;padding-top:10px;\"><a onclick=\"vm.nextPage(").append(currentPage + 1).append(")\"> 下页 </a></li>\n"); |
|
248 |
sb.append(" <li style=\"cursor:pointer;padding-top:10px;\"><a onclick=\"vm.nextPage(").append(totalPage).append(")\"> 尾页 </a></li>\n"); |
|
249 |
} |
|
250 |
sb.append(" <li style=\"padding-top:10px;\"><a> 共").append(totalPage).append("页 </a></li>\n"); |
|
251 |
sb.append(" <li style=\"padding-top:10px;\"><select title='显示条数' style=\"cursor:pointer;width:39px;float:left;margin-top:0px;border:none;background-color: rgba(255,255,255,0.6);\" onchange=\"vm.changeCount(this.value)\">\n"); |
|
252 |
sb.append(" <option value='").append(showCount).append("'>").append(showCount).append("</option>\n"); |
|
253 |
if (10 != showCount) { |
|
254 |
sb.append(" <option value='10'>10</option>\n"); |
|
255 |
} |
|
256 |
sb.append(" <option value='20'>20</option>\n"); |
|
257 |
sb.append(" <option value='30'>30</option>\n"); |
|
258 |
sb.append(" <option value='40'>40</option>\n"); |
|
259 |
sb.append(" <option value='50'>50</option>\n"); |
|
260 |
sb.append(" <option value='60'>60</option>\n"); |
|
261 |
sb.append(" <option value='70'>70</option>\n"); |
|
262 |
sb.append(" <option value='80'>80</option>\n"); |
|
263 |
sb.append(" <option value='90'>90</option>\n"); |
|
264 |
sb.append(" <option value='99'>99</option>\n"); |
|
265 |
sb.append(" </select>\n"); |
|
266 |
sb.append(" </li>\n"); |
|
267 |
sb.append("</ul>\n"); |
|
268 |
} |
|
269 |
return sb.toString(); |
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* 拼接分页 页面及JS函数 |
|
274 |
* |
|
275 |
* @author fengshuonan |
|
276 |
* @Date 2019-08-29 14:10 |
|
277 |
*/ |
|
278 |
private String getPageStrSimplify(int totalResult, int currentPage, int totalPage) { |
|
279 |
StringBuilder buffer = new StringBuilder(); |
|
280 |
if (totalResult > 0) { |
|
281 |
buffer.append(" <ul class=\"pagination pull-right no-margin\">\n"); |
|
282 |
if (currentPage == 1) { |
|
283 |
buffer.append(" <li><a>共").append(totalResult).append("条 </a></li>\n"); |
|
284 |
buffer.append(" <li><a> 首页 </a></li>\n"); |
|
285 |
buffer.append(" <li><a> 上页 </a></li>\n"); |
|
286 |
} else { |
|
287 |
buffer.append(" <li><a> 共").append(totalResult).append("条 </a></li>\n"); |
|
288 |
buffer.append(" <li style=\"cursor:pointer;\"><a onclick=\"vm.nextPage(1)\"> 首页 </a></li>\n"); |
|
289 |
buffer.append(" <li style=\"cursor:pointer;\"><a onclick=\"vm.nextPage(").append(currentPage - 1).append(")\"> 上页 </a></li>\n"); |
|
290 |
} |
|
291 |
|
|
292 |
//分页标签显示数量 |
|
293 |
int showTag = 2; |
|
294 |
int startTag = 1; |
|
295 |
if (currentPage > showTag) { |
|
296 |
startTag = currentPage - 1; |
|
297 |
} |
|
298 |
int endTag = startTag + showTag - 1; |
|
299 |
for (int i = startTag; i <= totalPage && i <= endTag; i++) { |
|
300 |
if (currentPage == i) { |
|
301 |
buffer.append("<li class=\"active\"><a><font color=\"#3F4D67\"> <b>").append(i).append("</b></font></a></li>\n"); |
|
302 |
} else { |
|
303 |
buffer.append(" <li style=\"cursor:pointer;\"><a style=\"cursor:pointer;\" onclick=\"vm.nextPage(").append(i).append(")\"> ").append(i).append("</a></li>\n"); |
|
304 |
} |
|
305 |
} |
|
306 |
if (currentPage == totalPage) { |
|
307 |
buffer.append(" <li><a> 下页 </a></li>\n"); |
|
308 |
buffer.append(" <li><a> 尾页 </a></li>\n"); |
|
309 |
} else { |
|
310 |
buffer.append(" <li style=\"cursor:pointer;\"><a onclick=\"vm.nextPage(").append(currentPage + 1).append(")\"> 下页 </a></li>\n"); |
|
311 |
buffer.append(" <li style=\"cursor:pointer;\"><a onclick=\"vm.nextPage(").append(totalPage).append(")\"> 尾页 </a></li>\n"); |
|
312 |
} |
|
313 |
buffer.append(" <li><a> 共").append(totalPage).append("页 </a></li>\n"); |
|
314 |
buffer.append("</ul>\n"); |
|
315 |
} |
|
316 |
return buffer.toString(); |
|
317 |
} |
|
318 |
|
|
319 |
/** |
|
320 |
* 拼接分页 页面及JS函数 |
|
321 |
* |
|
322 |
* @author fengshuonan |
|
323 |
* @Date 2019-08-29 14:11 |
|
324 |
*/ |
|
325 |
public String getPageStrSimplify2(int totalResult, int currentPage, int totalPage) { |
|
326 |
StringBuilder sb = new StringBuilder(); |
|
327 |
if (totalResult > 0) { |
|
328 |
sb.append(" <ul class=\"pagination pull-right no-margin\">\n"); |
|
329 |
if (currentPage == 1) { |
|
330 |
sb.append(" <li><a>共").append(totalResult).append("条 </a></li>\n"); |
|
331 |
sb.append(" <li><a> 首页 </a></li>\n"); |
|
332 |
sb.append(" <li><a> 上页 </a></li>\n"); |
|
333 |
} else { |
|
334 |
sb.append(" <li><a> 共").append(totalResult).append("条 </a></li>\n"); |
|
335 |
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage(1)\"> 首页 </a></li>\n"); |
|
336 |
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage(").append(currentPage - 1).append(")\"> 上页 </a></li>\n"); |
|
337 |
} |
|
338 |
|
|
339 |
//分页标签显示数量 |
|
340 |
int showTag = 2; |
|
341 |
int startTag = 1; |
|
342 |
if (currentPage > showTag) { |
|
343 |
startTag = currentPage - 1; |
|
344 |
} |
|
345 |
int endTag = startTag + showTag - 1; |
|
346 |
for (int i = startTag; i <= totalPage && i <= endTag; i++) { |
|
347 |
if (currentPage == i) { |
|
348 |
sb.append("<li class=\"active\"><a><font color=\"#3F4D67\"> <b>").append(i).append("</b></font></a></li>\n"); |
|
349 |
} else { |
|
350 |
sb.append(" <li style=\"cursor:pointer;\"><a style=\"cursor:pointer;\" onclick=\"nextPage(").append(i).append(")\"> ").append(i).append("</a></li>\n"); |
|
351 |
|
|
352 |
} |
|
353 |
} |
|
354 |
if (currentPage == totalPage) { |
|
355 |
sb.append(" <li><a> 下页 </a></li>\n"); |
|
356 |
sb.append(" <li><a> 尾页 </a></li>\n"); |
|
357 |
} else { |
|
358 |
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage(").append(currentPage + 1).append(")\"> 下页 </a></li>\n"); |
|
359 |
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage(").append(totalPage).append(")\"> 尾页 </a></li>\n"); |
|
360 |
} |
|
361 |
sb.append(" <li><a> 共").append(totalPage).append("页 </a></li>\n"); |
|
362 |
sb.append("</ul>\n"); |
|
363 |
} |
|
364 |
return sb.toString(); |
|
365 |
} |
|
366 |
} |