#
18516761980
2022-07-28 65fa066e222f6472badf7323c3b301417b674fdb
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.slcf.dao;
 
import java.util.List;
 
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
 
import com.slcf.pojo.MenuBean;
import com.slcf.pojo.RoleBean;
import com.slcf.pojo.RoleMenu;
 
@Repository
public interface RoleDao {
 
    /**
     * 根据角色名称查询
     * @param name
     * @return
     */
    @Select("select * from tb_role where role_name =#{name}")
    public RoleBean queryRoleByName(String name);
    
    /**
     * 查询所有
     * @return
     */
    @Select("select * from tb_role order by role_id")
    public List<RoleBean> getRoleList();
    
    /**
     * 分页查询
     * @param spage
     * @param epage
     * @return
     */
//    @Select("select * from tb_role r  order by r.role_id desc limit #{spage},#{epage}")
    @Select("select top (#{epage}) * from tb_role where role_id not in "
            + "(select top (#{spage}) role_id from tb_role order by role_id desc) order by role_id desc")
    public List<RoleBean> getRoleListByPage(@Param("spage")int spage,@Param("epage")int epage);
    
    /**
     * 统计数量
     * @return
     */
    @Select("select count(*) from tb_role")
    public int getCount();
    
    /**
     * 添加角色操作表
     * @param name
     * @param type
     * @param rid
     * @return
     */
    @Insert("insert into tb_role_opt(r_id,ropt_name,ropt_type,ropt_time) values(#{rid},#{name},#{type},getdate())")
    public int saveRoleOpt(@Param("name")String name,@Param("type")String type,@Param("rid")int rid);
    
    /**
     * 添加角色表
     * @param role
     * @return
     */
    @Insert("insert into tb_role(role_name,role_desc,pid) values(#{role_name},#{role_desc},#{pid})")
    public int saveRole(RoleBean role);
    
    /**
     * 删除角色操作记录表
     * @param rid
     * @return
     */
    @Delete("delete from tb_role_opt where r_id=#{rid}")
    public int delRoleOpt(int rid);
    
    /**
     * 删除角色表
     * @param rid
     * @return
     */
    @Delete("delete from tb_role where role_id=#{rid}")
    public int delRole(int rid);
    
    /**
     * 根据id查找
     * @param rid
     * @return
     */
    @Select("select * from tb_role where role_id=#{rid}")
    public RoleBean queryRoleById(int rid);
    
    /**
     * 跟新角色
     * @param role
     * @return
     */
    @Update("update tb_role set role_name=#{role_name},role_desc=#{role_desc},pid=#{pid} where role_id=#{role_id}")
    public int upRole(RoleBean role);
    
    /**
     * 查询所有启用父级菜单
     * @return
     */
    @Select("select * from tb_menu where parentID=0 and statu='0' ORDER BY menu_id")
    public List<MenuBean> getParentMenuList();
    
    /**
     * 查询父级菜单下的所有启用子菜单
     * @param pid
     * @return
     */
    @Select("select * from tb_menu where parentID=#{pid} and statu='0' ORDER BY menu_id")
    public List<MenuBean> queryChildMenuByPid(int pid);
    
    /**
     * 根据角色id查询此角色用有的菜单权限
     * @param rid
     * @return
     */
    @Select("select menu_id from tb_role_menu  where role_id=#{rid} ")
    public List<Integer> queryMenuByRoleId(int rid);
    
    /**
     * 添加角色菜单表
     * @param rid
     * @param mid
     * @return
     */
    @Insert("insert into tb_role_menu (menu_id,role_id,auth_code) values(#{mid},#{rid},#{auth_code})")
    public int saveRoleMenu(@Param("rid")int rid,@Param("mid")int mid,@Param("auth_code")String auth_code);
    
    /**
     * 删除角色菜单表
     * @param rid
     * @return
     */
    @Delete("delete from tb_role_menu where role_id=#{rid}")
    public int delRoleMenu(int rid);
    
    /**
     * 根据角色id查询
     * @param rid
     * @return
     */
    @Select("select * from tb_role_menu where role_id=#{rid}")
    public List<RoleMenu> queryRoleMenu(int rid);
    
    /**
     * 根据角色id、菜单id查询用户按钮权限
     * @param rid
     * @return
     */
    @Select("select auth_code from tb_role_menu  where role_id=#{rid} and menu_id=#{menu_id}")
    public String queryAuthStrsByRoleMenu(@Param("rid")int rid, @Param("menu_id")int menu_id);
}