XMTT 8 vuotta sitten
vanhempi
commit
eb151019f4

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

12

12

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

16

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

65

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

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

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

23
import org.jfw.util.StringUtil;
23
import org.jfw.util.StringUtil;
24
import org.jfw.util.auth.AuthUtil;
24
import org.jfw.util.auth.AuthUtil;
25
import org.jfw.util.exception.JfwBaseException;
25
import org.jfw.util.exception.JfwBaseException;
26
import org.jfw.util.jdbc.JdbcTask;
27
import org.jfw.util.jdbc.JdbcUtil;
26
import org.jfw.util.web.fileupload.UploadItemIterator;
28
import org.jfw.util.web.fileupload.UploadItemIterator;
27

29

30
import javax.sql.DataSource;
28
import java.io.IOException;
31
import java.io.IOException;
29
import java.sql.Connection;
32
import java.sql.Connection;
30
import java.sql.SQLException;
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
@Path("/sys/user")
37
@Path("/sys/user")
35
public class UserService extends Upload {
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
	public static final String DEFAULT_PW_STR = StringUtil.md5("12345678");
41
	public static final String DEFAULT_PW_STR = StringUtil.md5("12345678");
38

42

39
	@Autowrie
43
	@Autowrie
103
	}
107
	}
104

108

105
	public static void main(String[] args) throws Exception {
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
	@Get
113
	@Get
110
	@Path("/pq")
114
	@Path("/pq")
111
	public PageQueryResult<User> pageQuery(@JdbcConn Connection con, @Nullable String name, @Nullable Boolean actived, @Nullable String mobile,
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
			throws SQLException {
117
			throws SQLException {
114
		if (bt != null)
118
		if (bt != null)
115
			bt = bt + "000000";
119
			bt = bt + "000000";
126
	@Post
130
	@Post
127
	@Path
131
	@Path
128
	public void insert(@JdbcConn(true) Connection con,
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
			throws SQLException {
138
			throws SQLException {
135
		String id = StringUtil.buildUUID();
139
		String id = StringUtil.buildUUID();
136
		user.setId(id);
140
		user.setId(id);
140
		this.userDao.insert(con, user);
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
	@Put
168
	@Put
144
	@Path
169
	@Path
145
	public void update(@JdbcConn(true) Connection con, @RequestBody User user) throws SQLException {
170
	public void update(@JdbcConn(true) Connection con, @RequestBody User user) throws SQLException {
172
		}
197
		}
173
		return null;
198
		return null;
174
	}
199
	}
200

175
	@Post
201
	@Post
176
	@Path("/right")
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
		this.userDao.update(con, userid, AuthUtil.serialAuth(AuthUtil.compress(right)));
204
		this.userDao.update(con, userid, AuthUtil.serialAuth(AuthUtil.compress(right)));
179
	}
205
	}
180

206

186

212

187
	@Post
213
	@Post
188
	@Path("/del")
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
		this.userDao.delete(con, ids);
216
		this.userDao.delete(con, ids);
191
	}
217
	}
192

218

193
	@Get
219
	@Get
194
	@Path("/id/{id}")
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
		return this.userDao.queryById(con, id);
222
		return this.userDao.queryById(con, id);
197
	}
223
	}
198

224


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

1
package com.ekexiu.console.util;
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
import org.jfw.util.bean.AfterBeanFactory;
4
import org.jfw.util.bean.AfterBeanFactory;
11
import org.jfw.util.bean.BeanFactory;
5
import org.jfw.util.bean.BeanFactory;
12
import org.jfw.util.context.JfwAppContext;
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
public class GlobalInitBean implements AfterBeanFactory {
14
public class GlobalInitBean implements AfterBeanFactory {
20
	private DataSource dataSource;
15
	private DataSource dataSource;
88
				getBean(SysResourceService.class).initByDataSource(dataSource);
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
		return list;
92
		return list;
92
	}
93
	}
93
	public <T> T getBean(Class<T> cls){
94
	public <T> T getBean(Class<T> cls){