|
|
@@ -1,8 +1,6 @@
|
|
1
|
1
|
package com.zjt.web;
|
|
2
|
2
|
|
|
3
|
3
|
import com.alibaba.fastjson.JSON;
|
|
4
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
5
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
6
|
4
|
import com.google.gson.JsonArray;
|
|
7
|
5
|
import com.google.gson.JsonObject;
|
|
8
|
6
|
import com.zjt.entity.*;
|
|
|
@@ -19,12 +17,11 @@ import org.springframework.ui.Model;
|
|
19
|
17
|
import org.springframework.validation.BindingResult;
|
|
20
|
18
|
import org.springframework.web.bind.annotation.*;
|
|
21
|
19
|
import tk.mybatis.mapper.entity.Example;
|
|
|
20
|
+import javax.servlet.http.HttpSession;
|
|
22
|
21
|
|
|
23
|
22
|
import javax.annotation.Resource;
|
|
24
|
23
|
import javax.servlet.http.HttpSession;
|
|
25
|
24
|
import javax.validation.Valid;
|
|
26
|
|
-import javax.validation.constraints.Size;
|
|
27
|
|
-import java.net.URLEncoder;
|
|
28
|
25
|
import java.text.SimpleDateFormat;
|
|
29
|
26
|
import java.util.Date;
|
|
30
|
27
|
import java.util.HashMap;
|
|
|
@@ -34,249 +31,188 @@ import java.util.function.Consumer;
|
|
34
|
31
|
import java.util.function.Predicate;
|
|
35
|
32
|
import java.util.stream.Collectors;
|
|
36
|
33
|
|
|
37
|
|
-import static org.apache.commons.lang3.StringUtils.length;
|
|
38
|
|
-
|
|
39
|
|
-/**
|
|
40
|
|
-* @Description: 当前登录用户控制器
|
|
41
|
|
-* @Date: Created in 2018/2/8 19:28
|
|
42
|
|
-* @param
|
|
43
|
|
-*/
|
|
44
|
34
|
@Controller
|
|
45
|
35
|
@RequestMapping("/user")
|
|
46
|
36
|
public class UserController {
|
|
47
|
37
|
|
|
|
38
|
+ private static final String ADMIN_ROLE = "admin";
|
|
|
39
|
+ private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
|
|
40
|
+ private static final String ID_PREFIX = "S";
|
|
|
41
|
+
|
|
48
|
42
|
@Resource
|
|
49
|
|
- private com.zjt.service.MaterialType MaterialType;
|
|
|
43
|
+ private MaterialType materialType;
|
|
50
|
44
|
|
|
51
|
45
|
@Resource
|
|
52
|
46
|
private TroleService troleService;
|
|
53
|
|
-
|
|
|
47
|
+
|
|
54
|
48
|
@Resource
|
|
55
|
49
|
private TuserService tuserService;
|
|
56
|
|
-
|
|
|
50
|
+
|
|
57
|
51
|
@Resource
|
|
58
|
52
|
private TmenuService tmenuService;
|
|
59
|
53
|
|
|
60
|
|
- /*@Resource
|
|
61
|
|
- private LogService logService;*/
|
|
62
|
54
|
@RequestMapping("list")
|
|
63
|
|
- public String select(String id,String storeCode, String createtime,String receive, HttpSession session, Model model){
|
|
64
|
|
- Tuser users= (Tuser) session.getAttribute("currentUser");
|
|
|
55
|
+ public String select(String id, String storeCode, String createtime, String receive, Model model, HttpSession session) {
|
|
|
56
|
+ Tuser users = (Tuser) session.getAttribute("currentUser");
|
|
65
|
57
|
List<cgmaterial> collect1;
|
|
66
|
|
- String id1="";
|
|
67
|
|
- if(!"".equals(id)){
|
|
68
|
|
- id1=id.substring(1);
|
|
|
58
|
+ String id1 = "";
|
|
|
59
|
+
|
|
|
60
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
61
|
+ id1 = id.substring(1);
|
|
69
|
62
|
}
|
|
70
|
|
- if(!"".equals(createtime)){
|
|
|
63
|
+
|
|
|
64
|
+ SimpleDateFormat sdf1 = new SimpleDateFormat(DATE_FORMAT);
|
|
|
65
|
+ if (StringUtils.isNotEmpty(createtime)) {
|
|
71
|
66
|
String[] split1 = createtime.split(" - ");
|
|
72
|
|
- String strDateFormat1 = "yyyy-MM-dd HH:mm:ss";
|
|
73
|
|
- SimpleDateFormat sdf1 = new SimpleDateFormat(strDateFormat1);
|
|
74
|
|
- if(!"".equals(storeCode)){
|
|
75
|
|
- if("admin".equals(users.getTrueName())){
|
|
76
|
|
- collect1=MaterialType.selectDataBy(id1,storeCode,split1[0],split1[1],receive);
|
|
77
|
|
- }else{
|
|
78
|
|
- collect1=MaterialType.selectDataBy(id1,users.getUserName(),split1[0],split1[1],receive);
|
|
|
67
|
+ if (StringUtils.isNotEmpty(storeCode)) {
|
|
|
68
|
+ if (ADMIN_ROLE.equals(users.getTrueName())) {
|
|
|
69
|
+ collect1 = materialType.selectDataBy(id1, storeCode, split1[0], split1[1], receive);
|
|
|
70
|
+ } else {
|
|
|
71
|
+ collect1 = materialType.selectDataBy(id1, users.getUserName(), split1[0], split1[1], receive);
|
|
79
|
72
|
}
|
|
80
|
|
- }else{
|
|
81
|
|
- if("admin".equals(users.getTrueName())){
|
|
82
|
|
- collect1=MaterialType.selectDataBy(id1,"",split1[0],split1[1],receive);
|
|
83
|
|
- }else{
|
|
84
|
|
- collect1=MaterialType.selectDataBy(id1,users.getUserName(),split1[0],split1[1],receive);
|
|
|
73
|
+ } else {
|
|
|
74
|
+ if (ADMIN_ROLE.equals(users.getTrueName())) {
|
|
|
75
|
+ collect1 = materialType.selectDataBy(id1, "", split1[0], split1[1], receive);
|
|
|
76
|
+ } else {
|
|
|
77
|
+ collect1 = materialType.selectDataBy(id1, users.getUserName(), split1[0], split1[1], receive);
|
|
85
|
78
|
}
|
|
86
|
79
|
}
|
|
87
|
|
- }else{
|
|
88
|
|
- if(!"".equals(storeCode)){
|
|
89
|
|
- if("admin".equals(users.getTrueName())){
|
|
90
|
|
- collect1=MaterialType.selectDataBy(id1,storeCode,"","",receive);
|
|
91
|
|
- }else{
|
|
92
|
|
- collect1=MaterialType.selectDataBy(id1,users.getUserName(),"","",receive);
|
|
|
80
|
+ } else {
|
|
|
81
|
+ if (StringUtils.isNotEmpty(storeCode)) {
|
|
|
82
|
+ if (ADMIN_ROLE.equals(users.getTrueName())) {
|
|
|
83
|
+ collect1 = materialType.selectDataBy(id1, storeCode, "", "", receive);
|
|
|
84
|
+ } else {
|
|
|
85
|
+ collect1 = materialType.selectDataBy(id1, users.getUserName(), "", "", receive);
|
|
93
|
86
|
}
|
|
94
|
|
- }else{
|
|
95
|
|
- if("admin".equals(users.getTrueName())){
|
|
96
|
|
- collect1=MaterialType.selectDataBy(id1,"","","",receive);
|
|
97
|
|
- }else {
|
|
98
|
|
- collect1 = MaterialType.selectDataBy(id1, users.getUserName(), "", "", receive);
|
|
|
87
|
+ } else {
|
|
|
88
|
+ if (ADMIN_ROLE.equals(users.getTrueName())) {
|
|
|
89
|
+ collect1 = materialType.selectDataBy(id1, "", "", "", receive);
|
|
|
90
|
+ } else {
|
|
|
91
|
+ collect1 = materialType.selectDataBy(id1, users.getUserName(), "", "", receive);
|
|
99
|
92
|
}
|
|
100
|
93
|
}
|
|
101
|
94
|
}
|
|
102
|
|
- model.addAttribute("listcg",collect1);
|
|
|
95
|
+ model.addAttribute("listcg", collect1);
|
|
103
|
96
|
|
|
104
|
|
- //List<cgmaterial> collect1 = MaterialType.selectDataBy(id,storeCode,split1[0],split1[1],receive);
|
|
105
|
|
-
|
|
106
|
|
- Predicate<cgmaterial> predicate = a->{
|
|
107
|
|
- if(!"admin".equals(users.getTrueName())){
|
|
108
|
|
- if(a.getUsername().equals(users.getTrueName())){
|
|
109
|
|
- return true;
|
|
110
|
|
- }else{
|
|
111
|
|
- return false;
|
|
112
|
|
- }
|
|
113
|
|
- }else {
|
|
114
|
|
- return true;
|
|
|
97
|
+ Predicate<cgmaterial> predicate = a -> {
|
|
|
98
|
+ if (!ADMIN_ROLE.equals(users.getTrueName())) {
|
|
|
99
|
+ return a.getUsername().equals(users.getTrueName());
|
|
115
|
100
|
}
|
|
|
101
|
+ return true;
|
|
116
|
102
|
};
|
|
117
|
|
- Predicate<cgmaterial> predicate2=a->{
|
|
118
|
|
- if(createtime.length()>0){
|
|
|
103
|
+
|
|
|
104
|
+ Predicate<cgmaterial> predicate2 = a -> {
|
|
|
105
|
+ if (StringUtils.isNotEmpty(createtime)) {
|
|
119
|
106
|
String[] split = createtime.split(" - ");
|
|
120
|
|
- String strDateFormat = "yyyy-MM-dd HH:mm:ss";
|
|
121
|
|
- SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
|
|
122
|
|
- if(sdf.format(a.getCreatetime()).compareTo(split[0])>0&&sdf.format(a.getCreatetime()).compareTo(split[1])<0){
|
|
123
|
|
- return true;
|
|
124
|
|
- }else{
|
|
125
|
|
- return false;
|
|
126
|
|
- }
|
|
127
|
|
- }else{
|
|
128
|
|
- return true;
|
|
|
107
|
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
|
|
|
108
|
+ String createTimeStr = sdf.format(a.getCreatetime());
|
|
|
109
|
+ return createTimeStr.compareTo(split[0]) > 0 && createTimeStr.compareTo(split[1]) < 0;
|
|
129
|
110
|
}
|
|
|
111
|
+ return true;
|
|
130
|
112
|
};
|
|
131
|
|
-/* Predicate<cgmaterial> predicate3=a->{
|
|
132
|
|
- if(receive.length()>0){
|
|
133
|
|
- if(a.getLy().equals(receive)){
|
|
134
|
|
- return true;
|
|
135
|
|
- }else{
|
|
136
|
|
- return false;
|
|
137
|
|
- }
|
|
138
|
|
- }else {
|
|
139
|
|
- return true;
|
|
140
|
|
- }
|
|
141
|
113
|
|
|
142
|
|
- };*/
|
|
143
|
|
- Predicate<cgmaterial> predicate4=a->{
|
|
144
|
|
- if(storeCode.length()>0){
|
|
145
|
|
- if(a.getStore().equals(storeCode)){
|
|
146
|
|
- return true;
|
|
147
|
|
- }else{
|
|
148
|
|
- return false;
|
|
149
|
|
- }
|
|
150
|
|
- }else {
|
|
151
|
|
- return true;
|
|
152
|
|
- }
|
|
153
|
|
- };
|
|
154
|
|
- Predicate<cgmaterial> predicate5=a->{
|
|
155
|
|
- if(id.length()>0){
|
|
156
|
|
- String replace = id.replace(",", "");
|
|
157
|
|
- if(("S"+a.getId()).equals(replace)){
|
|
158
|
|
- return true;
|
|
159
|
|
- }else{
|
|
160
|
|
- return false;
|
|
161
|
|
- }
|
|
162
|
|
- }else {
|
|
163
|
|
- return true;
|
|
164
|
|
- }
|
|
165
|
|
- };
|
|
|
114
|
+ Predicate<cgmaterial> predicate4 = a -> StringUtils.isEmpty(storeCode) || a.getStore().equals(storeCode);
|
|
|
115
|
+ Predicate<cgmaterial> predicate5 = a -> StringUtils.isEmpty(id) || (ID_PREFIX + a.getId()).equals(id.replace(",", ""));
|
|
166
|
116
|
|
|
167
|
|
-/* List<cgmaterial> collect = MaterialType.selectData().stream()
|
|
|
117
|
+ // 合并所有过滤条件
|
|
|
118
|
+ List<cgmaterial> collect = collect1.stream()
|
|
168
|
119
|
.filter(predicate)
|
|
169
|
120
|
.filter(predicate2)
|
|
170
|
|
- .filter(predicate3)
|
|
171
|
121
|
.filter(predicate4)
|
|
172
|
122
|
.filter(predicate5)
|
|
173
|
|
- .collect(Collectors.toList());*/
|
|
|
123
|
+ .collect(Collectors.toList());
|
|
174
|
124
|
|
|
175
|
125
|
return "mypackage/selectcg";
|
|
176
|
126
|
}
|
|
177
|
127
|
|
|
178
|
128
|
@RequestMapping("input")
|
|
179
|
|
- public String input(){
|
|
|
129
|
+ public String input() {
|
|
180
|
130
|
return "mypackage/input";
|
|
181
|
131
|
}
|
|
182
|
132
|
|
|
183
|
133
|
@RequestMapping("test")
|
|
184
|
|
- public String test(){
|
|
|
134
|
+ public String test() {
|
|
185
|
135
|
return "mypackage/test";
|
|
186
|
136
|
}
|
|
187
|
|
- @RequestMapping("insert")
|
|
188
|
|
- public String insert(@RequestParam("list")String userList,HttpSession session){
|
|
189
|
|
- //List<requestDate> requestDates = JSON.parseArray(userList, requestDate.class);
|
|
190
|
|
- List<cgmaterial> cgmaterial = JSON.parseArray(userList, cgmaterial.class);
|
|
191
|
|
- Tuser user= (Tuser) session.getAttribute("currentUser");
|
|
192
|
|
- SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
|
|
193
|
|
- String s=user.getId()+""+df.format(new Date());
|
|
194
|
|
- Consumer<cgmaterial> consumer= a->MaterialType.insertCg(a);
|
|
195
|
|
- Predicate<cgmaterial> predicate=a->{
|
|
196
|
|
- if(a.getMaterialcode()!= null&&a.getWz()!=null&&a.getLy()!=null){
|
|
197
|
|
- return true;
|
|
198
|
|
- }else{
|
|
199
|
|
- return false;
|
|
200
|
|
- }
|
|
201
|
|
- };
|
|
202
|
|
-
|
|
203
|
|
- cgmaterial.stream().filter(a->a.getMaterialcode()!= null&&a.getWz()!=null&&a.getLy()!=null).map(
|
|
204
|
|
- a->{
|
|
205
|
|
- a.setId(Long.parseLong(s));
|
|
206
|
|
- a.setUsername(user.getTrueName());
|
|
207
|
|
- a.setCreatetime(new Date());
|
|
208
|
|
- a.setStore(user.getUserName());
|
|
|
137
|
+
|
|
|
138
|
+ @RequestMapping("insert")
|
|
|
139
|
+ public String insert(@RequestParam("list") String userList, HttpSession session) {
|
|
|
140
|
+ List<cgmaterial> cgmaterials = JSON.parseArray(userList, cgmaterial.class);
|
|
|
141
|
+ Tuser user = (Tuser) session.getAttribute("currentUser");
|
|
|
142
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
143
|
+ String s = user.getId() + "" + df.format(new Date());
|
|
|
144
|
+
|
|
|
145
|
+ Consumer<cgmaterial> consumer = materialType::insertCg;
|
|
|
146
|
+
|
|
|
147
|
+ cgmaterials.stream()
|
|
|
148
|
+ .filter(a -> a.getMaterialcode() != null && a.getWz() != null && a.getLy() != null)
|
|
|
149
|
+ .map(a -> {
|
|
|
150
|
+ a.setId(Long.parseLong(s));
|
|
|
151
|
+ a.setUsername(user.getTrueName());
|
|
|
152
|
+ a.setCreatetime(new Date());
|
|
|
153
|
+ a.setStore(user.getUserName());
|
|
209
|
154
|
return a;
|
|
210
|
|
- }
|
|
211
|
|
- ).collect(Collectors.toList()).forEach(consumer);
|
|
212
|
|
- return "mypackage/test";
|
|
|
155
|
+ })
|
|
|
156
|
+ .forEach(consumer);
|
|
|
157
|
+
|
|
|
158
|
+ return "mypackage/test";
|
|
|
159
|
+ }
|
|
|
160
|
+
|
|
|
161
|
+ @ResponseBody
|
|
|
162
|
+ @PostMapping("/login")
|
|
|
163
|
+ public Map<String, Object> login(String imageCode, @Valid Tuser user, BindingResult bindingResult, HttpSession session) {
|
|
|
164
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
165
|
+ if (StringUtils.isEmpty(imageCode)) {
|
|
|
166
|
+ map.put("success", false);
|
|
|
167
|
+ map.put("errorInfo", "请输入验证码!");
|
|
|
168
|
+ return map;
|
|
|
169
|
+ }
|
|
|
170
|
+ if (!session.getAttribute("checkcode").equals(imageCode)) {
|
|
|
171
|
+ map.put("success", false);
|
|
|
172
|
+ map.put("errorInfo", "验证码输入错误!");
|
|
|
173
|
+ return map;
|
|
213
|
174
|
}
|
|
|
175
|
+ if (bindingResult.hasErrors()) {
|
|
|
176
|
+ map.put("success", false);
|
|
|
177
|
+ map.put("errorInfo", bindingResult.getFieldError().getDefaultMessage());
|
|
|
178
|
+ return map;
|
|
|
179
|
+ }
|
|
|
180
|
+
|
|
|
181
|
+ Subject subject = SecurityUtils.getSubject();
|
|
|
182
|
+ UsernamePasswordToken token = new UsernamePasswordToken(user.getUserName(), user.getPassword());
|
|
|
183
|
+ try {
|
|
|
184
|
+ subject.login(token);
|
|
|
185
|
+ if (!subject.isAuthenticated()) {
|
|
|
186
|
+ map.put("success", false);
|
|
|
187
|
+ map.put("errorInfo", "认证失败!");
|
|
|
188
|
+ return map;
|
|
|
189
|
+ }
|
|
214
|
190
|
|
|
215
|
|
-
|
|
216
|
|
- /**
|
|
217
|
|
- * 用户登录请求
|
|
218
|
|
- * @param user
|
|
219
|
|
- * @return
|
|
220
|
|
- */
|
|
221
|
|
- @ResponseBody
|
|
222
|
|
- @PostMapping("/login")
|
|
223
|
|
- public Map<String,Object> login(String imageCode, @Valid Tuser user, BindingResult bindingResult, HttpSession session){
|
|
224
|
|
- Map<String,Object> map=new HashMap<String,Object>();
|
|
225
|
|
- if(StringUtils.isEmpty(imageCode)){
|
|
226
|
|
- map.put("success", false);
|
|
227
|
|
- map.put("errorInfo", "请输入验证码!");
|
|
228
|
|
- return map;
|
|
229
|
|
- }
|
|
230
|
|
- if(!session.getAttribute("checkcode").equals(imageCode)){
|
|
231
|
|
- map.put("success", false);
|
|
232
|
|
- map.put("errorInfo", "验证码输入错误!");
|
|
233
|
|
- return map;
|
|
234
|
|
- }
|
|
235
|
|
- if(bindingResult.hasErrors()){
|
|
236
|
|
- map.put("success", false);
|
|
237
|
|
- map.put("errorInfo", bindingResult.getFieldError().getDefaultMessage());
|
|
238
|
|
- return map;
|
|
239
|
|
- }
|
|
240
|
|
- Subject subject=SecurityUtils.getSubject();
|
|
241
|
|
- UsernamePasswordToken token=new UsernamePasswordToken(user.getUserName(), user.getPassword());
|
|
242
|
|
- try{
|
|
243
|
|
- subject.login(token); // 登录认证
|
|
244
|
|
- String userName=(String) SecurityUtils.getSubject().getPrincipal();
|
|
245
|
|
- //Tuser currentUser=tuserService.findByUserName(userName);
|
|
246
|
|
- Example tuserExample=new Example(Tuser.class);
|
|
247
|
|
- tuserExample.or().andEqualTo("userName",userName);
|
|
248
|
|
- Tuser currentUser=tuserService.selectByExample(tuserExample).get(0);
|
|
|
191
|
+ String userName = (String) SecurityUtils.getSubject().getPrincipal();
|
|
|
192
|
+ Example tuserExample = new Example(Tuser.class);
|
|
|
193
|
+ tuserExample.or().andEqualTo("userName", userName);
|
|
|
194
|
+ Tuser currentUser = tuserService.selectByExample(tuserExample).get(0);
|
|
249
|
195
|
session.setAttribute("currentUser", currentUser);
|
|
250
|
|
- //List<Trole> roleList=troleService.findByUserId(currentUser.getId());
|
|
251
|
|
- List<Trole> roleList=troleService.selectRolesByUserId(currentUser.getId());
|
|
|
196
|
+
|
|
|
197
|
+ List<Trole> roleList = troleService.selectRolesByUserId(currentUser.getId());
|
|
252
|
198
|
map.put("roleList", roleList);
|
|
253
|
199
|
map.put("roleSize", roleList.size());
|
|
254
|
200
|
map.put("success", true);
|
|
255
|
|
- //logService.save(new Log(Log.LOGIN_ACTION,"用户登录")); // 写入日志
|
|
256
|
201
|
return map;
|
|
257
|
|
- }catch(Exception e){
|
|
|
202
|
+ } catch (Exception e) {
|
|
258
|
203
|
e.printStackTrace();
|
|
259
|
204
|
map.put("success", false);
|
|
260
|
205
|
map.put("errorInfo", "用户名或者密码错误!");
|
|
261
|
206
|
return map;
|
|
262
|
207
|
}
|
|
263
|
|
- }
|
|
264
|
|
-
|
|
265
|
|
-
|
|
|
208
|
+ }
|
|
266
|
209
|
|
|
267
|
|
- /**
|
|
268
|
|
- * 保存角色信息
|
|
269
|
|
- * @param roleId
|
|
270
|
|
- * @param session
|
|
271
|
|
- * @return
|
|
272
|
|
- * @throws Exception
|
|
273
|
|
- */
|
|
274
|
210
|
@ResponseBody
|
|
275
|
211
|
@PostMapping("/saveRole")
|
|
276
|
|
- public Map<String,Object> saveRole(Integer roleId,HttpSession session)throws Exception{
|
|
277
|
|
- Map<String,Object> map=new HashMap<String,Object>();
|
|
278
|
|
- Trole currentRole=troleService.selectByKey(roleId);
|
|
279
|
|
- session.setAttribute("currentRole", currentRole); // 保存当前角色信息
|
|
|
212
|
+ public Map<String, Object> saveRole(Integer roleId, HttpSession session) {
|
|
|
213
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
214
|
+ Trole currentRole = troleService.selectByKey(roleId);
|
|
|
215
|
+ session.setAttribute("currentRole", currentRole);
|
|
280
|
216
|
|
|
281
|
217
|
putTmenuOneClassListIntoSession(session);
|
|
282
|
218
|
|
|
|
@@ -284,138 +220,82 @@ public class UserController {
|
|
284
|
220
|
return map;
|
|
285
|
221
|
}
|
|
286
|
222
|
|
|
287
|
|
-
|
|
288
|
|
- /**
|
|
289
|
|
- * 安全退出
|
|
290
|
|
- *
|
|
291
|
|
- * @return
|
|
292
|
|
- * @throws Exception
|
|
293
|
|
- */
|
|
294
|
223
|
@GetMapping("/logout")
|
|
295
|
|
- public String logout() throws Exception {
|
|
296
|
|
-// logService.save(new Log(Log.LOGOUT_ACTION,"用户注销"));
|
|
|
224
|
+ public String logout() {
|
|
297
|
225
|
SecurityUtils.getSubject().logout();
|
|
298
|
226
|
return "redirect:/tologin";
|
|
299
|
227
|
}
|
|
300
|
228
|
|
|
301
|
|
-
|
|
302
|
|
- /**
|
|
303
|
|
- * 加载权限菜单
|
|
304
|
|
- * @param session
|
|
305
|
|
- * @return
|
|
306
|
|
- * @throws Exception
|
|
307
|
|
- * 这里传入的parentId是1
|
|
308
|
|
- */
|
|
309
|
229
|
@ResponseBody
|
|
310
|
230
|
@GetMapping("/loadMenuInfo")
|
|
311
|
|
- public String loadMenuInfo(HttpSession session, Integer parentId)throws Exception{
|
|
312
|
|
-
|
|
|
231
|
+ public String loadMenuInfo(HttpSession session, Integer parentId) {
|
|
313
|
232
|
putTmenuOneClassListIntoSession(session);
|
|
314
|
233
|
|
|
315
|
|
- Trole currentRole=(Trole) session.getAttribute("currentRole");
|
|
316
|
|
- //根据当前用户的角色id和父节点id查询所有菜单及子集json
|
|
317
|
|
- String json=getAllMenuByParentId(parentId,currentRole.getId()).toString();
|
|
318
|
|
- //System.out.println(json);
|
|
|
234
|
+ Trole currentRole = (Trole) session.getAttribute("currentRole");
|
|
|
235
|
+ String json = getAllMenuByParentId(parentId, currentRole.getId()).toString();
|
|
319
|
236
|
return json;
|
|
320
|
237
|
}
|
|
321
|
238
|
|
|
322
|
|
- /**
|
|
323
|
|
- * 获取根频道所有菜单信息
|
|
324
|
|
- * @param parentId
|
|
325
|
|
- * @param roleId
|
|
326
|
|
- * @return
|
|
327
|
|
- */
|
|
328
|
|
- private JsonObject getAllMenuByParentId(Integer parentId,Integer roleId){
|
|
329
|
|
- JsonObject resultObject=new JsonObject();
|
|
330
|
|
- JsonArray jsonArray=this.getMenuByParentId(parentId, roleId);//得到所有一级菜单
|
|
331
|
|
- for(int i=0;i<jsonArray.size();i++){
|
|
332
|
|
- JsonObject jsonObject=(JsonObject) jsonArray.get(i);
|
|
333
|
|
- //判断该节点下时候还有子节点
|
|
334
|
|
- Example example=new Example(Tmenu.class);
|
|
335
|
|
- example.or().andEqualTo("pId",jsonObject.get("id").getAsString());
|
|
336
|
|
- //if("true".equals(jsonObject.get("spread").getAsString())){
|
|
337
|
|
- if (tmenuService.selectCountByExample(example)==0) {
|
|
|
239
|
+ private JsonObject getAllMenuByParentId(Integer parentId, Integer roleId) {
|
|
|
240
|
+ JsonObject resultObject = new JsonObject();
|
|
|
241
|
+ JsonArray jsonArray = getMenuByParentId(parentId, roleId);
|
|
|
242
|
+
|
|
|
243
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
244
|
+ JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
|
|
|
245
|
+ Example example = new Example(Tmenu.class);
|
|
|
246
|
+ example.or().andEqualTo("pId", jsonObject.get("id").getAsString());
|
|
|
247
|
+
|
|
|
248
|
+ if (tmenuService.selectCountByExample(example) == 0) {
|
|
338
|
249
|
continue;
|
|
339
|
|
- }else{
|
|
340
|
|
- //由于后台模板的规定,一级菜单以title最为json的key
|
|
341
|
|
- resultObject.add(jsonObject.get("title").getAsString(), getAllMenuJsonArrayByParentId(jsonObject.get("id").getAsInt(),roleId));
|
|
|
250
|
+ } else {
|
|
|
251
|
+ resultObject.add(jsonObject.get("title").getAsString(), getAllMenuJsonArrayByParentId(jsonObject.get("id").getAsInt(), roleId));
|
|
342
|
252
|
}
|
|
343
|
253
|
}
|
|
344
|
254
|
return resultObject;
|
|
345
|
255
|
}
|
|
346
|
256
|
|
|
|
257
|
+ private JsonArray getAllMenuJsonArrayByParentId(Integer parentId, Integer roleId) {
|
|
|
258
|
+ JsonArray jsonArray = getMenuByParentId(parentId, roleId);
|
|
347
|
259
|
|
|
|
260
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
261
|
+ JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
|
|
|
262
|
+ Example example = new Example(Tmenu.class);
|
|
|
263
|
+ example.or().andEqualTo("pId", jsonObject.get("id").getAsString());
|
|
348
|
264
|
|
|
349
|
|
- //获取根频道下子频道菜单列表集合
|
|
350
|
|
- private JsonArray getAllMenuJsonArrayByParentId(Integer parentId,Integer roleId){
|
|
351
|
|
- JsonArray jsonArray=this.getMenuByParentId(parentId, roleId);
|
|
352
|
|
- for(int i=0;i<jsonArray.size();i++){
|
|
353
|
|
- JsonObject jsonObject=(JsonObject) jsonArray.get(i);
|
|
354
|
|
- //判断该节点下是否还有子节点
|
|
355
|
|
- Example example=new Example(Tmenu.class);
|
|
356
|
|
- example.or().andEqualTo("pId",jsonObject.get("id").getAsString());
|
|
357
|
|
- //if("true".equals(jsonObject.get("spread").getAsString())){
|
|
358
|
|
- if (tmenuService.selectCountByExample(example)==0) {
|
|
|
265
|
+ if (tmenuService.selectCountByExample(example) == 0) {
|
|
359
|
266
|
continue;
|
|
360
|
|
- }else{
|
|
361
|
|
- //二级或三级菜单
|
|
362
|
|
- jsonObject.add("children", getAllMenuJsonArrayByParentId(jsonObject.get("id").getAsInt(),roleId));
|
|
|
267
|
+ } else {
|
|
|
268
|
+ jsonObject.add("children", getAllMenuJsonArrayByParentId(jsonObject.get("id").getAsInt(), roleId));
|
|
363
|
269
|
}
|
|
364
|
270
|
}
|
|
365
|
271
|
return jsonArray;
|
|
366
|
272
|
}
|
|
367
|
273
|
|
|
368
|
|
-
|
|
369
|
|
-
|
|
370
|
|
-
|
|
371
|
|
- /**
|
|
372
|
|
- * 根据父节点和用户角色id查询菜单
|
|
373
|
|
- * @param parentId
|
|
374
|
|
- * @param roleId
|
|
375
|
|
- * @return
|
|
376
|
|
- */
|
|
377
|
|
- private JsonArray getMenuByParentId(Integer parentId,Integer roleId){
|
|
378
|
|
- //List<Menu> menuList=menuService.findByParentIdAndRoleId(parentId, roleId);
|
|
379
|
|
- HashMap<String,Object> paraMap=new HashMap<String,Object>();
|
|
380
|
|
- paraMap.put("pid",parentId);
|
|
381
|
|
- paraMap.put("roleid",roleId);
|
|
382
|
|
- List<Tmenu> menuList=tmenuService.selectByParentIdAndRoleId(paraMap);
|
|
383
|
|
- JsonArray jsonArray=new JsonArray();
|
|
384
|
|
- for(Tmenu menu:menuList){
|
|
385
|
|
- JsonObject jsonObject=new JsonObject();
|
|
386
|
|
- jsonObject.addProperty("id", menu.getId()); // 节点id
|
|
387
|
|
- jsonObject.addProperty("title", menu.getName()); // 节点名称
|
|
388
|
|
- jsonObject.addProperty("spread", false); // 不展开
|
|
|
274
|
+ private JsonArray getMenuByParentId(Integer parentId, Integer roleId) {
|
|
|
275
|
+ HashMap<String, Object> paraMap = new HashMap<>();
|
|
|
276
|
+ paraMap.put("pid", parentId);
|
|
|
277
|
+ paraMap.put("roleid", roleId);
|
|
|
278
|
+ List<Tmenu> menuList = tmenuService.selectByParentIdAndRoleId(paraMap);
|
|
|
279
|
+
|
|
|
280
|
+ JsonArray jsonArray = new JsonArray();
|
|
|
281
|
+ for (Tmenu menu : menuList) {
|
|
|
282
|
+ JsonObject jsonObject = new JsonObject();
|
|
|
283
|
+ jsonObject.addProperty("id", menu.getId());
|
|
|
284
|
+ jsonObject.addProperty("title", menu.getName());
|
|
|
285
|
+ jsonObject.addProperty("spread", false);
|
|
389
|
286
|
jsonObject.addProperty("icon", menu.getIcon());
|
|
390
|
|
- if(StringUtils.isNotEmpty(menu.getUrl())){
|
|
391
|
|
- jsonObject.addProperty("href", menu.getUrl()); // 菜单请求地址
|
|
|
287
|
+ if (StringUtils.isNotEmpty(menu.getUrl())) {
|
|
|
288
|
+ jsonObject.addProperty("href", menu.getUrl());
|
|
392
|
289
|
}
|
|
393
|
290
|
jsonArray.add(jsonObject);
|
|
394
|
|
-
|
|
395
|
291
|
}
|
|
396
|
292
|
return jsonArray;
|
|
397
|
293
|
}
|
|
398
|
294
|
|
|
399
|
|
-
|
|
400
|
|
-
|
|
401
|
|
-
|
|
402
|
|
-public void putTmenuOneClassListIntoSession(HttpSession session){
|
|
403
|
|
- //用来在welcome.ftl中获取主菜单列表
|
|
404
|
|
- Example example=new Example(Tmenu.class);
|
|
405
|
|
- example.or().andEqualTo("pId",1);
|
|
406
|
|
- List<Tmenu> tmenuOneClassList=tmenuService.selectByExample(example);
|
|
407
|
|
- session.setAttribute("tmenuOneClassList", tmenuOneClassList);
|
|
408
|
|
-}
|
|
409
|
|
-
|
|
410
|
|
-
|
|
411
|
|
-
|
|
412
|
|
-
|
|
413
|
|
-
|
|
414
|
|
-
|
|
415
|
|
-
|
|
416
|
|
-
|
|
417
|
|
-
|
|
418
|
|
-
|
|
419
|
|
-
|
|
420
|
|
-
|
|
|
295
|
+ public void putTmenuOneClassListIntoSession(HttpSession session) {
|
|
|
296
|
+ Example example = new Example(Tmenu.class);
|
|
|
297
|
+ example.or().andEqualTo("pId", 1);
|
|
|
298
|
+ List<Tmenu> tmenuOneClassList = tmenuService.selectByExample(example);
|
|
|
299
|
+ session.setAttribute("tmenuOneClassList", tmenuOneClassList);
|
|
|
300
|
+ }
|
|
421
|
301
|
}
|