kaiyu
2021-09-26 d6428820434c9a54eb4063b74ece253924708ede
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
package com.moral.api.controller;
 
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 java.util.List;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import com.moral.api.entity.Menu;
import com.moral.api.service.GroupMenuService;
import com.moral.api.service.MenuService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.TokenUtils;
 
@Slf4j
@Api(tags = {"菜单管理"})
@RestController
@RequestMapping("/menu")
public class MenuController {
 
    @Autowired
    private GroupMenuService groupMenuService;
 
    @Autowired
    private MenuService menuService;
 
    @ApiOperation(value = "组分配菜单", notes = "组分配菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "allot", method = RequestMethod.POST)
    public ResultMessage allot(@RequestBody Map<String, Object> parameters) {
        if (!parameters.containsKey("groupId")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        groupMenuService.allotMenus(parameters);
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "菜单列表", notes = "菜单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
    })
    @RequestMapping(value = "menu-list", method = RequestMethod.POST)
    public ResultMessage selectMenus() {
        Map<String, Object> currentUserInfo = (Map<String, Object>)TokenUtils.getUserInfo();
        Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization");
        List<Menu> menus = menuService.getMenuList((Integer) orgInfo.get("id"));
        return ResultMessage.ok(menus);
    }
 
    @ApiOperation(value = "层级菜单", notes = "层级菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
    })
    @RequestMapping(value = "select", method = RequestMethod.GET)
    public ResultMessage select() {
        Map<String, Object> currentUserInfo = (Map<String, Object>)TokenUtils.getUserInfo();
        Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization");
        Map<String, Object> result = menuService.selectMenusByOrgId((Integer) orgInfo.get("id"));
        return ResultMessage.ok(result);
    }
 
    @ApiOperation(value = "获取组菜单ids", notes = "获取组菜单ids")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "getMenuIds", method = RequestMethod.GET)
    public ResultMessage getMenuIds(Integer groupId) {
        List<Integer> menusIds = groupMenuService.getMenusIds(groupId);
        return ResultMessage.ok(menusIds);
    }
}