XMTT 8 years ago
parent
commit
eb151019f4

+ 4 - 0
src/main/java/com/ekexiu/console/system/dao/UserDao.java

@ -12,6 +12,7 @@ import org.jfw.util.PageQueryResult;
12 12

13 13
import java.sql.Connection;
14 14
import java.sql.SQLException;
15
import java.util.List;
15 16

16 17
@DAO
17 18
public interface UserDao {
@ -62,6 +63,9 @@ public interface UserDao {
62 63
			@Nullable String email, @Nullable @GtEq @Alias("createTime") String bt, @Nullable @Alias("createTime") @LtEq String et, int pageNo, int pageSize)
63 64
			throws SQLException;
64 65

66
	@SelectList
67
	List<User> queryall(Connection con) throws SQLException;
68

65 69
	@DeleteWith
66 70
	@From(User.class)
67 71
	int delete(Connection con, String id) throws SQLException;

+ 39 - 13
src/main/java/com/ekexiu/console/system/service/UserService.java

@ -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


+ 12 - 11
src/main/java/com/ekexiu/console/util/GlobalInitBean.java

@ -1,20 +1,15 @@
1 1
package com.ekexiu.console.util;
2 2

3
import java.util.LinkedList;
4
import java.util.List;
5
import java.util.ListIterator;
6
import java.util.concurrent.ScheduledExecutorService;
7

8
import javax.sql.DataSource;
9

3
import com.ekexiu.console.system.service.*;
10 4
import org.jfw.util.bean.AfterBeanFactory;
11 5
import org.jfw.util.bean.BeanFactory;
12 6
import org.jfw.util.context.JfwAppContext;
13 7

14
import com.ekexiu.console.system.service.DictService;
15
import com.ekexiu.console.system.service.RightService;
16
import com.ekexiu.console.system.service.RoleService;
17
import com.ekexiu.console.system.service.SysResourceService;
8
import javax.sql.DataSource;
9
import java.util.LinkedList;
10
import java.util.List;
11
import java.util.ListIterator;
12
import java.util.concurrent.ScheduledExecutorService;
18 13

19 14
public class GlobalInitBean implements AfterBeanFactory {
20 15
	private DataSource dataSource;
@ -88,6 +83,12 @@ public class GlobalInitBean implements AfterBeanFactory {
88 83
				getBean(SysResourceService.class).initByDataSource(dataSource);
89 84
			}
90 85
		});
86
		list.add(new Initable() {
87
			@Override
88
			public void init(GlobalInitBean gib) throws Exception {
89
				getBean(UserService.class).initByDataSource(dataSource);
90
			}
91
		});
91 92
		return list;
92 93
	}
93 94
	public <T> T getBean(Class<T> cls){