jinpengyong
2021-06-24 06b00a178d194d33370e44410c4f04a4164f86c7
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
package com.moral.api.controller;
 
import com.alibaba.fastjson.JSON;
import com.moral.api.entity.ManageRole;
import com.moral.api.service.ManageRoleMenuService;
import com.moral.api.service.ManageRoleService;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
import static org.springframework.web.util.WebUtils.getParametersStartingWith;
 
@Slf4j
@Api(tags = {"角色"})
@RestController
@RequestMapping("/manageRole")
public class ManageRoleController {
 
    @Autowired
    private ManageRoleService manageRoleService;
 
    @Autowired
    private ManageRoleMenuService manageRoleMenuService;
 
    @Autowired
    private RedisTemplate redisTemplate;
 
    @ApiOperation(value = "获取所有角色", notes = "获取所有角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页数量", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "getAllManageRole", method = RequestMethod.GET)
    public ResultMessage getAllManageRole(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Map<String,Object> re = manageRoleService.getAllWithPagingQuery(parameters);
        return ResultMessage.ok(re);
    }
 
    @ApiOperation(value = "新增角色", notes = "新增角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "desc", value = "备注", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "menuIds", value = "菜单集合", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "insertOneManageRole", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage insertOneManageRole(@RequestBody Map<String, Object> parameters,HttpServletRequest request) {
        List list = new ArrayList();
        if (parameters.get("menuIds") != null){
            String menuIdsStr = parameters.get("menuIds").toString();
            menuIdsStr = menuIdsStr.replace(" ","");
            if (menuIdsStr.length() > 2){
                menuIdsStr = menuIdsStr.substring(1,menuIdsStr.length()-1);
                String[] menuIdsArray = menuIdsStr.split(",");
                list = Arrays.asList(menuIdsArray);
            }
            parameters.remove("menuIds");
        }
        ManageRole manageRole = JSON.parseObject(JSON.toJSONString(parameters), ManageRole.class);
        Map<String,Object> resultMap = manageRoleService.insertOne(manageRole,list);
        String msg = resultMap.get("msg").toString();
        int code = Integer.parseInt(resultMap.get("code").toString());
        if (code == 0){
            return ResultMessage.ok(msg);
        }
        return ResultMessage.fail(msg);
        //return null;
    }
 
    @ApiOperation(value = "更新角色", notes = "更新角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "desc", value = "备注", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "updateManageRole", method = RequestMethod.POST)
    public ResultMessage updateManageRole(@RequestBody Map<String, Object> parameters) {
        Map<String,Object> resultMap = manageRoleService.updateManageRole(parameters);
        String msg = resultMap.get("msg").toString();
        int code = Integer.parseInt(resultMap.get("code").toString());
        if (code == 0){
            return ResultMessage.ok(msg);
        }
        return ResultMessage.fail(msg);
    }
 
    @ApiOperation(value = "删除角色", notes = "删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "deleteManageRole", method = RequestMethod.POST)
    public ResultMessage deleteManageRole(@RequestBody Map<String, Object> parameters) {
        Map<String,Object> resultMap = manageRoleService.deleteManageRole(parameters);
        String msg = resultMap.get("msg").toString();
        int code = Integer.parseInt(resultMap.get("code").toString());
        if (code == 0){
            return ResultMessage.ok(msg);
        }
        return ResultMessage.fail(msg);
    }
 
    @ApiOperation(value = "角色模糊查询", notes = "角色模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页数量", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "getManageRoleByNameFuzzy", method = RequestMethod.GET)
    public ResultMessage getManageRoleByNameFuzzy(HttpServletRequest request) {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        Map<String,Object> re = manageRoleService.getManageRoleByNameFuzzy(parameters);
        return ResultMessage.ok(re);
    }
 
    @ApiOperation(value = "更新角色菜单", notes = "更新角色菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "updateRoleMenu", method = RequestMethod.POST)
    public ResultMessage updateRoleMenu(@RequestBody Map<String, Object> parameters) {
        List list = new ArrayList();
        if (parameters.get("menuIds") != null){
            String menuIdsStr = parameters.get("menuIds").toString();
            menuIdsStr = menuIdsStr.replace(" ","");
            if (menuIdsStr.length() > 2){
                menuIdsStr = menuIdsStr.substring(1,menuIdsStr.length()-1);
                String[] menuIdsArray = menuIdsStr.split(",");
                list = Arrays.asList(menuIdsArray);
            }
            parameters.remove("menuIds");
        }
        int id = Integer.parseInt(parameters.get("id").toString());
        Map<String,Object> re = manageRoleMenuService.updateRoleMenu(list,id);
        return ResultMessage.ok(re);
    }
}