|
@ -23,17 +23,21 @@ import org.jfw.util.PageQueryResult;
|
23
|
23
|
import org.jfw.util.StringUtil;
|
24
|
24
|
import org.jfw.util.auth.AuthUtil;
|
25
|
25
|
import org.jfw.util.exception.JfwBaseException;
|
|
26
|
import org.jfw.util.jdbc.JdbcTask;
|
|
27
|
import org.jfw.util.jdbc.JdbcUtil;
|
26
|
28
|
import org.jfw.util.web.fileupload.UploadItemIterator;
|
27
|
29
|
|
|
30
|
import javax.sql.DataSource;
|
28
|
31
|
import java.io.IOException;
|
29
|
32
|
import java.sql.Connection;
|
30
|
33
|
import java.sql.SQLException;
|
31
|
|
import java.util.ArrayList;
|
32
|
|
import java.util.List;
|
|
34
|
import java.util.*;
|
|
35
|
import java.util.concurrent.atomic.AtomicReference;
|
33
|
36
|
|
34
|
37
|
@Path("/sys/user")
|
35
|
38
|
public class UserService extends Upload {
|
36
|
|
public static final String DEFAULT_AUTH_STR = AuthUtil.serialAuth(new int[] { 0 });
|
|
39
|
private AtomicReference<Map<String, User>> cache = new AtomicReference<Map<String, User>>();
|
|
40
|
public static final String DEFAULT_AUTH_STR = AuthUtil.serialAuth(new int[]{0});
|
37
|
41
|
public static final String DEFAULT_PW_STR = StringUtil.md5("12345678");
|
38
|
42
|
|
39
|
43
|
@Autowrie
|
|
@ -103,13 +107,13 @@ public class UserService extends Upload {
|
103
|
107
|
}
|
104
|
108
|
|
105
|
109
|
public static void main(String[] args) throws Exception {
|
106
|
|
System.out.println(AuthUtil.serialAuth(new int[] { 0 }));
|
|
110
|
System.out.println(AuthUtil.serialAuth(new int[]{0}));
|
107
|
111
|
}
|
108
|
112
|
|
109
|
113
|
@Get
|
110
|
114
|
@Path("/pq")
|
111
|
115
|
public PageQueryResult<User> pageQuery(@JdbcConn Connection con, @Nullable String name, @Nullable Boolean actived, @Nullable String mobile,
|
112
|
|
@Nullable String email, @Nullable String bt, @Nullable String et, @DefaultValue("1") int pageNo, @DefaultValue("10") int pageSize)
|
|
116
|
@Nullable String email, @Nullable String bt, @Nullable String et, @DefaultValue("1") int pageNo, @DefaultValue("10") int pageSize)
|
113
|
117
|
throws SQLException {
|
114
|
118
|
if (bt != null)
|
115
|
119
|
bt = bt + "000000";
|
|
@ -126,11 +130,11 @@ public class UserService extends Upload {
|
126
|
130
|
@Post
|
127
|
131
|
@Path
|
128
|
132
|
public void insert(@JdbcConn(true) Connection con,
|
129
|
|
@RequestParam(fields = { @FieldParam(value = "name", valueClass = String.class, required = true),
|
130
|
|
@FieldParam(value = "email", valueClass = String.class, required = true),
|
131
|
|
@FieldParam(value = "mobile", valueClass = String.class, required = false),
|
132
|
|
@FieldParam(value = "descp", valueClass = String.class, required = false),
|
133
|
|
@FieldParam(value = "head", valueClass = String.class, required = false) }) User user)
|
|
133
|
@RequestParam(fields = {@FieldParam(value = "name", valueClass = String.class, required = true),
|
|
134
|
@FieldParam(value = "email", valueClass = String.class, required = true),
|
|
135
|
@FieldParam(value = "mobile", valueClass = String.class, required = false),
|
|
136
|
@FieldParam(value = "descp", valueClass = String.class, required = false),
|
|
137
|
@FieldParam(value = "head", valueClass = String.class, required = false)}) User user)
|
134
|
138
|
throws SQLException {
|
135
|
139
|
String id = StringUtil.buildUUID();
|
136
|
140
|
user.setId(id);
|
|
@ -140,6 +144,27 @@ public class UserService extends Upload {
|
140
|
144
|
this.userDao.insert(con, user);
|
141
|
145
|
}
|
142
|
146
|
|
|
147
|
@Get
|
|
148
|
@Path("/all")
|
|
149
|
public Collection<User> queryall(@JdbcConn Connection con) throws SQLException {
|
|
150
|
return this.cache.get().values();
|
|
151
|
}
|
|
152
|
|
|
153
|
public void initByDataSource(DataSource ds) throws SQLException {
|
|
154
|
final Connection con = ds.getConnection();
|
|
155
|
JdbcUtil.executeAutoClose(con, new JdbcTask() {
|
|
156
|
@Override
|
|
157
|
public void exec() throws SQLException {
|
|
158
|
List<User> list = userDao.queryall(con);
|
|
159
|
Map<String, User> map = new HashMap<String, User>();
|
|
160
|
for (User res : list) {
|
|
161
|
map.put(res.getId(), res);
|
|
162
|
}
|
|
163
|
cache.set(map);
|
|
164
|
}
|
|
165
|
}, false);
|
|
166
|
}
|
|
167
|
|
143
|
168
|
@Put
|
144
|
169
|
@Path
|
145
|
170
|
public void update(@JdbcConn(true) Connection con, @RequestBody User user) throws SQLException {
|
|
@ -172,9 +197,10 @@ public class UserService extends Upload {
|
172
|
197
|
}
|
173
|
198
|
return null;
|
174
|
199
|
}
|
|
200
|
|
175
|
201
|
@Post
|
176
|
202
|
@Path("/right")
|
177
|
|
public void updateRights(@JdbcConn(true) Connection con, String userid,int[] right)throws SQLException{
|
|
203
|
public void updateRights(@JdbcConn(true) Connection con, String userid, int[] right) throws SQLException {
|
178
|
204
|
this.userDao.update(con, userid, AuthUtil.serialAuth(AuthUtil.compress(right)));
|
179
|
205
|
}
|
180
|
206
|
|
|
@ -186,13 +212,13 @@ public class UserService extends Upload {
|
186
|
212
|
|
187
|
213
|
@Post
|
188
|
214
|
@Path("/del")
|
189
|
|
public void delete(@JdbcConn(true)Connection con,String[] ids)throws SQLException {
|
|
215
|
public void delete(@JdbcConn(true) Connection con, String[] ids) throws SQLException {
|
190
|
216
|
this.userDao.delete(con, ids);
|
191
|
217
|
}
|
192
|
218
|
|
193
|
219
|
@Get
|
194
|
220
|
@Path("/id/{id}")
|
195
|
|
public User query(@JdbcConn Connection con, @PathVar String id)throws SQLException {
|
|
221
|
public User query(@JdbcConn Connection con, @PathVar String id) throws SQLException {
|
196
|
222
|
return this.userDao.queryById(con, id);
|
197
|
223
|
}
|
198
|
224
|
|