jiapeng 8 years ago
parent
commit
357f060482

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

@ -2,6 +2,7 @@ package com.ekexiu.console.system.dao;
2 2

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

6 7
import org.jfw.apt.orm.annotation.dao.Batch;
7 8
import org.jfw.apt.orm.annotation.dao.DAO;
@ -9,6 +10,7 @@ import org.jfw.apt.orm.annotation.dao.method.From;
9 10
import org.jfw.apt.orm.annotation.dao.method.operator.Delete;
10 11
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
11 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 15
import com.ekexiu.console.system.po.UserRole;
14 16

@ -30,4 +32,7 @@ public interface UserRoleDao {
30 32
	@From(UserRole.class)
31 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,6 +14,7 @@ import com.ekexiu.console.basepo.ModifyTimeSupported;
14 14
public class Role implements CreateTimeSupported,ModifyTimeSupported,DescpSupported{
15 15
	private String id;
16 16
	private String name;
17
	private String type;
17 18
	private String authinfo;
18 19
	private String descp;
19 20
	private String createTime;
@ -32,6 +33,13 @@ public class Role implements CreateTimeSupported,ModifyTimeSupported,DescpSuppor
32 33
	public void setName(String name) {
33 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 43
	@Column(DE.string_de)
36 44
	public String getAuthinfo() {
37 45
		return authinfo;

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

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

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

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

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

@ -2,10 +2,14 @@ package com.ekexiu.console.system.service;
2 2

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

6 7
import org.jfw.apt.annotation.Autowrie;
7 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 11
import org.jfw.apt.web.annotation.param.JdbcConn;
12
import org.jfw.apt.web.annotation.param.PathVar;
9 13

10 14
import com.ekexiu.console.system.dao.UserRoleDao;
11 15
import com.ekexiu.console.system.po.UserRole;
@ -25,9 +29,9 @@ public class UserRoleService {
25 29
	public void setUserRoleDao(UserRoleDao userRoleDao) {
26 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 35
		this.userRoleDao.deleteByUserId(con, userid);
32 36
		UserRole[] urs = new UserRole[role.length];
33 37
		int ind = 0;
@ -40,4 +44,9 @@ public class UserRoleService {
40 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,6 +3,7 @@ package com.ekexiu.console.system.vo;
3 3
public class ConsoleAuthRole {
4 4
	private String id;
5 5
	private String name;
6
	private String type;
6 7
	private int[] auths;
7 8
	private String descp;
8 9
	public String getId() {
@ -17,6 +18,13 @@ public class ConsoleAuthRole {
17 18
	public void setName(String name) {
18 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 28
	public int[] getAuths() {
21 29
		return auths;
22 30
	}

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

@ -0,0 +1,20 @@
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
}