RoleMapper.java
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.uccc.admin.mapper;
import com.uccc.admin.domain.Role;
import com.uccc.pretty.common.User;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
* Created by bert on 2021-09-13 22:23
*/
public interface RoleMapper {
static final String TABLE_NAME_1 = "user_role";
static final String TABLE_NAME_2 = "roles";
@Insert({
"<script>",
"insert into user_role (",
"role_id, user_id, cts, uts ) values (",
"#{roleId}, #{userId}, now(), now() )",
"</script>",
})
int createUserRole(@Param("userId") Long userId, @Param("roleId") int roleId);
@Delete("delete from " + TABLE_NAME_1 + " where user_id = #{user.id}")
int deleteUserRole(@Param("user") User user);
@Select({
"<script>",
"select count(id) from " + TABLE_NAME_2,
"where name = #{name}",
"</script>"
})
int selectCountByName(@Param("name") String name);
@Insert({
"<script>",
"insert into " + TABLE_NAME_2,
"(",
"name, cts, uts, edit, en_name",
")",
"values",
"(",
"#{role.name}, now(), now(), 1, #{role.enName}",
")",
"</script>"
})
@Options(useGeneratedKeys = true, keyColumn = "id")
int createRole(@Param("role") Role role);
@Select({
"<script>",
"select * from " + TABLE_NAME_2,
"where name = #{name}",
"</script>",
})
Role SelectRoleByName(@Param("name") String name);
@Select({
"<script>",
"select * from " + TABLE_NAME_2,
"<when test='name!=null'>",
"where name like concat('%',#{name},'%')",
"</when>",
"order by cts desc",
"</script>"
})
List<Role> selectRoleList(@Param("name") String name);
@Update({
"<script>",
"UPDATE " + TABLE_NAME_2 + " SET uts = now()",
"<when test='role.name!=null'>",
", name = #{role.name}",
"</when>",
"<when test='role.enName!=null'>",
", en_name = #{role.enName}",
"</when>",
"where id = #{role.id}",
"</script>"
})
int updateRole(@Param("role") Role role);
@Select({
"<script>",
"select DISTINCT on(r.name) r.name,r.id,r.edit,r.en_name,r.cts,r.uts from users u JOIN user_role ur ON ur.user_id = u.id",
"JOIN roles r ON ur.role_id = r.id",
"where u.id = #{userId}",
"</script>"
})
List<com.uccc.pretty.common.Role> selectRoleByUserId(@Param("userId") Long userId);
}