#
18516761980
2022-07-25 2c37b04bc0e5e2eae772166f514ff67113668f17
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package com.slcf.controller;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.slcf.pojo.RoleBean;
import com.slcf.pojo.SysLogBean;
import com.slcf.pojo.UserBean;
import com.slcf.service.RoleService;
import com.slcf.service.SysLogService;
import com.slcf.util.ViewTree;
 
@Controller
@RequestMapping("/role")
public class RoleController {
 
    @Autowired
    RoleService roleService;
    
    @Autowired
    SysLogService sysLogService;
    
    /**
     * 验证角色名称是否唯一
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkRole.action")
    public Map<String,Object> checkRoleName(
            @RequestParam("roleName")String name,
            @RequestParam(value="rid",defaultValue="0",required=false)int rid
            ){    
        Map<String,Object>map=new HashMap<String, Object>();
        try {
            boolean flag = roleService.checkRoleName(name, rid);
            if (flag) {
                map.put("msg", "名称可用");
            } else {
                map.put("msg", "名称已被占可用");
            }
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 查询所有角色
     * @return
     */
    @ResponseBody
    @RequestMapping("/roleList.action")
    public List<RoleBean> getRoleList(){
        try {
            return roleService.getRoleList();
        }catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 分页查询
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/rolePages.action")
    public Map<String,Object> getRoleListByPage(
            @RequestParam(value="pageNumber",defaultValue="0",required=false)int pageNumber,
            @RequestParam("pageSize")int pageSize){
//        Map<String,Object>map=roleService.getRoleListByPage((pageNumber-1)*pageSize, pageNumber*pageSize);
        try {
            Map<String,Object>map=roleService.getRoleListByPage((pageNumber-1)*pageSize, pageSize);
            return map;
        }catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 添加角色
     * @param role
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/saveRole.action")
    public int saveRole(RoleBean role,HttpServletRequest request){
        int i=0;
        try{
            i=roleService.saveRole(role, request);
            if(i>0) {
                // 插入日志
                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("saveRole.action");
                sysLog.setTts_keyname("添加角色:" + role.getRole_name());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return i;
    }
    
    /**
     * 根据id删除角色
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/delRole.action")
    public int delRole(@RequestParam("rid")int id,HttpServletRequest request){
        int i = 0;
        try {
            i = roleService.delRole(id);
            
            if(i>0) {
                // 插入日志
                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("delRole.action");
                sysLog.setTts_keyname("删除角色,ID" + id);
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return i;
    }
    
    /**
     * 根据id查找
     * @param rid
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryRole.action")
    public Map<String,Object> queryRoleById(@RequestParam("rid")int rid){
        Map<String,Object>map=new HashMap<String, Object>();
        try {
            List<RoleBean>rlist=roleService.getRoleList();
            RoleBean role=roleService.queryRoleById(rid);
            map.put("role", role);
            map.put("rlist", rlist);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 更新角色
     * @param role
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/upRole.action")
    public int upRole(RoleBean role,HttpServletRequest request){
//        System.out.println(role.getRole_id()+"==========");
        int i = 0;
        try {
            i = roleService.upRole(role, request);
            if(i>0) {
                // 插入日志
                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("upRole.action");
                sysLog.setTts_keyname("修改角色:" + role.getRole_name());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return i;
    }
    
    /**
     * 查找菜单
     * @param rid
     * @return
     */
    @ResponseBody
    @RequestMapping("/viewTree.action")
    public List<ViewTree> getRoleTree(@RequestParam("rid")int rid){
        try {
            return roleService.getViewTree(rid);
        }catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 保存角色权限
     * @param rid
     * @param mid
     * @return
     */
    @ResponseBody
    @RequestMapping("/saveRoleMenu.action")
    public boolean saveRoleMenu(@RequestParam("rid")int rid,@RequestParam("mid")int []mid,
            @RequestParam("auths")int []auths, HttpServletRequest request){
        boolean flag=false;
        try {
            flag=roleService.saveRoleMenu(rid, mid, auths);
            if(flag) {
                // 插入日志
                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("saveRoleMenu.action");
                sysLog.setTts_keyname("保存角色权限,ID:" + rid);
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return flag;
    }
}