jiapeng 8 vuotta sitten
vanhempi
commit
357f060482

+ 5 - 0
src/main/java/com/ekexiu/console/system/dao/UserRoleDao.java

2

2

3
import java.sql.Connection;
3
import java.sql.Connection;
4
import java.sql.SQLException;
4
import java.sql.SQLException;
5
import java.util.List;
5

6

6
import org.jfw.apt.orm.annotation.dao.Batch;
7
import org.jfw.apt.orm.annotation.dao.Batch;
7
import org.jfw.apt.orm.annotation.dao.DAO;
8
import org.jfw.apt.orm.annotation.dao.DAO;
9
import org.jfw.apt.orm.annotation.dao.method.operator.Delete;
10
import org.jfw.apt.orm.annotation.dao.method.operator.Delete;
10
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
11
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
11
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
12
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
13
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
12

14

13
import com.ekexiu.console.system.po.UserRole;
15
import com.ekexiu.console.system.po.UserRole;
14

16

30
	@From(UserRole.class)
32
	@From(UserRole.class)
31
	int deleteByRoleId(Connection con,String roleid)throws SQLException;
33
	int deleteByRoleId(Connection con,String roleid)throws SQLException;
32
	
34
	
35
	@SelectList
36
	List<UserRole> queryByUserId(Connection con, String userid) throws SQLException;
37
	
33
}
38
}

+ 8 - 0
src/main/java/com/ekexiu/console/system/po/Role.java

14
public class Role implements CreateTimeSupported,ModifyTimeSupported,DescpSupported{
14
public class Role implements CreateTimeSupported,ModifyTimeSupported,DescpSupported{
15
	private String id;
15
	private String id;
16
	private String name;
16
	private String name;
17
	private String type;
17
	private String authinfo;
18
	private String authinfo;
18
	private String descp;
19
	private String descp;
19
	private String createTime;
20
	private String createTime;
32
	public void setName(String name) {
33
	public void setName(String name) {
33
		this.name = name;
34
		this.name = name;
34
	}
35
	}
36
	@Column(DE.singleChar)
37
	public String getType() {
38
		return type;
39
	}
40
	public void setType(String type) {
41
		this.type = type;
42
	}
35
	@Column(DE.string_de)
43
	@Column(DE.string_de)
36
	public String getAuthinfo() {
44
	public String getAuthinfo() {
37
		return authinfo;
45
		return authinfo;

+ 4 - 1
src/main/java/com/ekexiu/console/system/service/RoleService.java

69
		r.setId(id);
69
		r.setId(id);
70
		r.setName(role.getName());
70
		r.setName(role.getName());
71
		r.setDescp(role.getDescp());
71
		r.setDescp(role.getDescp());
72
		r.setType(role.getType());
72
		int[] auths = role.getAuths();
73
		int[] auths = role.getAuths();
73
		if (auths == null || auths.length == 0) {
74
		if (auths == null || auths.length == 0) {
74
			r.setAuthinfo(EMPTY_AUTH_STR);
75
			r.setAuthinfo(EMPTY_AUTH_STR);
90
	public void update(@JdbcConn final Connection con, @RequestBody final ConsoleAuthRole role) throws SQLException {
91
	public void update(@JdbcConn final Connection con, @RequestBody final ConsoleAuthRole role) throws SQLException {
91
		final AtomicBoolean ab = new AtomicBoolean(false);
92
		final AtomicBoolean ab = new AtomicBoolean(false);
92
		JdbcUtil.executeAutoCommit(con, new JdbcTask() {
93
		JdbcUtil.executeAutoCommit(con, new JdbcTask() {
93

94
			@Override
94
			@Override
95
			public void exec() throws SQLException {
95
			public void exec() throws SQLException {
96

96

97
				Role r = new Role();
97
				Role r = new Role();
98
				r.setId(role.getId());
99
				r.setType(role.getType());
98
				r.setName(role.getName());
100
				r.setName(role.getName());
99
				r.setDescp(role.getDescp());
101
				r.setDescp(role.getDescp());
100
				int[] auths = role.getAuths();
102
				int[] auths = role.getAuths();
154
		ConsoleAuthRole cr = new ConsoleAuthRole();
156
		ConsoleAuthRole cr = new ConsoleAuthRole();
155
		cr.setDescp(role.getDescp());
157
		cr.setDescp(role.getDescp());
156
		cr.setId(role.getId());
158
		cr.setId(role.getId());
159
		cr.setType(role.getType());
157
		cr.setName(role.getName());
160
		cr.setName(role.getName());
158
		cr.setAuths(AuthUtil.unCompress(AuthUtil.deSerialAuth(role.getAuthinfo())));
161
		cr.setAuths(AuthUtil.unCompress(AuthUtil.deSerialAuth(role.getAuthinfo())));
159
		return cr;
162
		return cr;

+ 12 - 3
src/main/java/com/ekexiu/console/system/service/UserRoleService.java

2

2

3
import java.sql.Connection;
3
import java.sql.Connection;
4
import java.sql.SQLException;
4
import java.sql.SQLException;
5
import java.util.List;
5

6

6
import org.jfw.apt.annotation.Autowrie;
7
import org.jfw.apt.annotation.Autowrie;
7
import org.jfw.apt.web.annotation.Path;
8
import org.jfw.apt.web.annotation.Path;
9
import org.jfw.apt.web.annotation.operate.Get;
10
import org.jfw.apt.web.annotation.operate.Post;
8
import org.jfw.apt.web.annotation.param.JdbcConn;
11
import org.jfw.apt.web.annotation.param.JdbcConn;
12
import org.jfw.apt.web.annotation.param.PathVar;
9

13

10
import com.ekexiu.console.system.dao.UserRoleDao;
14
import com.ekexiu.console.system.dao.UserRoleDao;
11
import com.ekexiu.console.system.po.UserRole;
15
import com.ekexiu.console.system.po.UserRole;
25
	public void setUserRoleDao(UserRoleDao userRoleDao) {
29
	public void setUserRoleDao(UserRoleDao userRoleDao) {
26
		this.userRoleDao = userRoleDao;
30
		this.userRoleDao = userRoleDao;
27
	}
31
	}
28

29

30
	public void insert(@JdbcConn(true) Connection con,String userid,String[] role)throws SQLException{
32
    @Post
33
    @Path()
34
	public void save(@JdbcConn(true) Connection con,String userid,String[] role)throws SQLException{
31
		this.userRoleDao.deleteByUserId(con, userid);
35
		this.userRoleDao.deleteByUserId(con, userid);
32
		UserRole[] urs = new UserRole[role.length];
36
		UserRole[] urs = new UserRole[role.length];
33
		int ind = 0;
37
		int ind = 0;
40
		this.userRoleDao.insert(con, urs);
44
		this.userRoleDao.insert(con, urs);
41
	}
45
	}
42
	
46
	
47
	@Get
48
	@Path("/user/{id}")
49
	public List<UserRole> getRole(@JdbcConn Connection con,@PathVar String id)throws SQLException{
50
		return this.userRoleDao.queryByUserId(con,id);
51
	}
43
}
52
}

+ 8 - 0
src/main/java/com/ekexiu/console/system/vo/ConsoleAuthRole.java

3
public class ConsoleAuthRole {
3
public class ConsoleAuthRole {
4
	private String id;
4
	private String id;
5
	private String name;
5
	private String name;
6
	private String type;
6
	private int[] auths;
7
	private int[] auths;
7
	private String descp;
8
	private String descp;
8
	public String getId() {
9
	public String getId() {
17
	public void setName(String name) {
18
	public void setName(String name) {
18
		this.name = name;
19
		this.name = name;
19
	}
20
	}
21
	
22
	public String getType() {
23
		return type;
24
	}
25
	public void setType(String type) {
26
		this.type = type;
27
	}
20
	public int[] getAuths() {
28
	public int[] getAuths() {
21
		return auths;
29
		return auths;
22
	}
30
	}

+ 20 - 0
src/test/java/com/ekexiu/console/util/JdbcTest.java

1
package com.ekexiu.console.util;
2

3
import java.sql.Connection;
4
import java.sql.DriverManager;
5
import java.sql.PreparedStatement;
6

7
public class JdbcTest {
8
public static void main(String[] args)throws Exception{
9
	//Class.forName(className)
10
	
11
	Connection con = DriverManager.getConnection("jdbc:postgresql://192.168.3.233:5432/console_dev_jp", "postgres","postgres");
12
	
13
	PreparedStatement ps = con.prepareStatement("INSERT INTO TEST (ID,NAME,CODE) SELECT ?,NAME,CODE FROM  TEST WHERE ID=?");
14
	ps.setString(1,"4");
15
	ps.setString(2,"1");
16
	System.out.println(ps.executeUpdate());
17
	ps.close();
18
	con.close();
19
}
20
}