|
@@ -3,6 +3,7 @@ package com.ruoyi.common.core.controller;
|
3
|
3
|
import java.beans.PropertyEditorSupport;
|
4
|
4
|
import java.util.Date;
|
5
|
5
|
import java.util.List;
|
|
6
|
+
|
6
|
7
|
import org.slf4j.Logger;
|
7
|
8
|
import org.slf4j.LoggerFactory;
|
8
|
9
|
import org.springframework.web.bind.WebDataBinder;
|
|
@@ -23,25 +24,21 @@ import com.ruoyi.common.utils.sql.SqlUtil;
|
23
|
24
|
|
24
|
25
|
/**
|
25
|
26
|
* web层通用数据处理
|
26
|
|
- *
|
|
27
|
+ *
|
27
|
28
|
* @author ruoyi
|
28
|
29
|
*/
|
29
|
|
-public class BaseController
|
30
|
|
-{
|
|
30
|
+public class BaseController {
|
31
|
31
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
32
|
32
|
|
33
|
33
|
/**
|
34
|
34
|
* 将前台传递过来的日期格式的字符串,自动转化为Date类型
|
35
|
35
|
*/
|
36
|
36
|
@InitBinder
|
37
|
|
- public void initBinder(WebDataBinder binder)
|
38
|
|
- {
|
|
37
|
+ public void initBinder(WebDataBinder binder) {
|
39
|
38
|
// Date 类型转换
|
40
|
|
- binder.registerCustomEditor(Date.class, new PropertyEditorSupport()
|
41
|
|
- {
|
|
39
|
+ binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
|
42
|
40
|
@Override
|
43
|
|
- public void setAsText(String text)
|
44
|
|
- {
|
|
41
|
+ public void setAsText(String text) {
|
45
|
42
|
setValue(DateUtils.parseDate(text));
|
46
|
43
|
}
|
47
|
44
|
});
|
|
@@ -50,19 +47,25 @@ public class BaseController
|
50
|
47
|
/**
|
51
|
48
|
* 设置请求分页数据
|
52
|
49
|
*/
|
53
|
|
- protected void startPage()
|
54
|
|
- {
|
|
50
|
+ protected void startPage() {
|
55
|
51
|
PageUtils.startPage();
|
56
|
52
|
}
|
57
|
53
|
|
|
54
|
+ protected void startPage(String isAsc, String orderByColumn) {
|
|
55
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
56
|
+ Integer pageNum = pageDomain.getPageNum();
|
|
57
|
+ Integer pageSize = pageDomain.getPageSize();
|
|
58
|
+ String orderBy = SqlUtil.escapeOrderBySql(orderByColumn + " " + isAsc);
|
|
59
|
+ Boolean reasonable = pageDomain.getReasonable();
|
|
60
|
+ PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
|
|
61
|
+ }
|
|
62
|
+
|
58
|
63
|
/**
|
59
|
64
|
* 设置请求排序数据
|
60
|
65
|
*/
|
61
|
|
- protected void startOrderBy()
|
62
|
|
- {
|
|
66
|
+ protected void startOrderBy() {
|
63
|
67
|
PageDomain pageDomain = TableSupport.buildPageRequest();
|
64
|
|
- if (StringUtils.isNotEmpty(pageDomain.getOrderBy()))
|
65
|
|
- {
|
|
68
|
+ if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) {
|
66
|
69
|
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
67
|
70
|
PageHelper.orderBy(orderBy);
|
68
|
71
|
}
|
|
@@ -71,17 +74,15 @@ public class BaseController
|
71
|
74
|
/**
|
72
|
75
|
* 清理分页的线程变量
|
73
|
76
|
*/
|
74
|
|
- protected void clearPage()
|
75
|
|
- {
|
|
77
|
+ protected void clearPage() {
|
76
|
78
|
PageUtils.clearPage();
|
77
|
79
|
}
|
78
|
80
|
|
79
|
81
|
/**
|
80
|
82
|
* 响应请求分页数据
|
81
|
83
|
*/
|
82
|
|
- @SuppressWarnings({ "rawtypes", "unchecked" })
|
83
|
|
- protected TableDataInfo getDataTable(List<?> list)
|
84
|
|
- {
|
|
84
|
+ @SuppressWarnings({"rawtypes", "unchecked"})
|
|
85
|
+ protected TableDataInfo getDataTable(List<?> list) {
|
85
|
86
|
TableDataInfo rspData = new TableDataInfo();
|
86
|
87
|
rspData.setCode(HttpStatus.SUCCESS);
|
87
|
88
|
rspData.setMsg("查询成功");
|
|
@@ -93,110 +94,97 @@ public class BaseController
|
93
|
94
|
/**
|
94
|
95
|
* 返回成功
|
95
|
96
|
*/
|
96
|
|
- public AjaxResult success()
|
97
|
|
- {
|
|
97
|
+ public AjaxResult success() {
|
98
|
98
|
return AjaxResult.success();
|
99
|
99
|
}
|
100
|
100
|
|
101
|
101
|
/**
|
102
|
102
|
* 返回失败消息
|
103
|
103
|
*/
|
104
|
|
- public AjaxResult error()
|
105
|
|
- {
|
|
104
|
+ public AjaxResult error() {
|
106
|
105
|
return AjaxResult.error();
|
107
|
106
|
}
|
108
|
107
|
|
109
|
108
|
/**
|
110
|
109
|
* 返回成功消息
|
111
|
110
|
*/
|
112
|
|
- public AjaxResult success(String message)
|
113
|
|
- {
|
|
111
|
+ public AjaxResult success(String message) {
|
114
|
112
|
return AjaxResult.success(message);
|
115
|
113
|
}
|
116
|
|
-
|
|
114
|
+
|
117
|
115
|
/**
|
118
|
116
|
* 返回成功消息
|
119
|
117
|
*/
|
120
|
|
- public AjaxResult success(Object data)
|
121
|
|
- {
|
|
118
|
+ public AjaxResult success(Object data) {
|
122
|
119
|
return AjaxResult.success(data);
|
123
|
120
|
}
|
124
|
121
|
|
125
|
122
|
/**
|
126
|
123
|
* 返回失败消息
|
127
|
124
|
*/
|
128
|
|
- public AjaxResult error(String message)
|
129
|
|
- {
|
|
125
|
+ public AjaxResult error(String message) {
|
130
|
126
|
return AjaxResult.error(message);
|
131
|
127
|
}
|
132
|
128
|
|
133
|
129
|
/**
|
134
|
130
|
* 返回警告消息
|
135
|
131
|
*/
|
136
|
|
- public AjaxResult warn(String message)
|
137
|
|
- {
|
|
132
|
+ public AjaxResult warn(String message) {
|
138
|
133
|
return AjaxResult.warn(message);
|
139
|
134
|
}
|
140
|
135
|
|
141
|
136
|
/**
|
142
|
137
|
* 响应返回结果
|
143
|
|
- *
|
|
138
|
+ *
|
144
|
139
|
* @param rows 影响行数
|
145
|
140
|
* @return 操作结果
|
146
|
141
|
*/
|
147
|
|
- protected AjaxResult toAjax(int rows)
|
148
|
|
- {
|
|
142
|
+ protected AjaxResult toAjax(int rows) {
|
149
|
143
|
return rows > 0 ? AjaxResult.success() : AjaxResult.error();
|
150
|
144
|
}
|
151
|
145
|
|
152
|
146
|
/**
|
153
|
147
|
* 响应返回结果
|
154
|
|
- *
|
|
148
|
+ *
|
155
|
149
|
* @param result 结果
|
156
|
150
|
* @return 操作结果
|
157
|
151
|
*/
|
158
|
|
- protected AjaxResult toAjax(boolean result)
|
159
|
|
- {
|
|
152
|
+ protected AjaxResult toAjax(boolean result) {
|
160
|
153
|
return result ? success() : error();
|
161
|
154
|
}
|
162
|
155
|
|
163
|
156
|
/**
|
164
|
157
|
* 页面跳转
|
165
|
158
|
*/
|
166
|
|
- public String redirect(String url)
|
167
|
|
- {
|
|
159
|
+ public String redirect(String url) {
|
168
|
160
|
return StringUtils.format("redirect:{}", url);
|
169
|
161
|
}
|
170
|
162
|
|
171
|
163
|
/**
|
172
|
164
|
* 获取用户缓存信息
|
173
|
165
|
*/
|
174
|
|
- public LoginUser getLoginUser()
|
175
|
|
- {
|
|
166
|
+ public LoginUser getLoginUser() {
|
176
|
167
|
return SecurityUtils.getLoginUser();
|
177
|
168
|
}
|
178
|
169
|
|
179
|
170
|
/**
|
180
|
171
|
* 获取登录用户id
|
181
|
172
|
*/
|
182
|
|
- public Long getUserId()
|
183
|
|
- {
|
|
173
|
+ public Long getUserId() {
|
184
|
174
|
return getLoginUser().getUserId();
|
185
|
175
|
}
|
186
|
176
|
|
187
|
177
|
/**
|
188
|
178
|
* 获取登录部门id
|
189
|
179
|
*/
|
190
|
|
- public Long getDeptId()
|
191
|
|
- {
|
|
180
|
+ public Long getDeptId() {
|
192
|
181
|
return getLoginUser().getDeptId();
|
193
|
182
|
}
|
194
|
183
|
|
195
|
184
|
/**
|
196
|
185
|
* 获取登录用户名
|
197
|
186
|
*/
|
198
|
|
- public String getUsername()
|
199
|
|
- {
|
|
187
|
+ public String getUsername() {
|
200
|
188
|
return getLoginUser().getUsername();
|
201
|
189
|
}
|
202
|
190
|
}
|