lyh
2025-01-17 ea704e018a27c26ef6deeaea4adc8a28b4d0b27e
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
package org.jeecg.modules.dnc.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.dnc.entity.Button;
import org.jeecg.modules.dnc.request.ButtonRequest;
import org.jeecg.modules.dnc.response.CommonCode;
import org.jeecg.modules.dnc.response.QueryListResponseResult;
import org.jeecg.modules.dnc.response.QueryPageResponseResult;
import org.jeecg.modules.dnc.response.ResponseResult;
import org.jeecg.modules.dnc.service.IButtonService;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.List;
 
@Slf4j
@Api(tags = "按钮管理")
@RestController
@RequestMapping("/ucenter/btn")
public class ButtonController  {
    @Autowired
    private IButtonService buttonService;
 
    @AutoLog(value = "按钮管理-新增按钮对象")
    @ApiOperation(value = "按钮管理-新增按钮对象", notes = "按钮管理-新增按钮对象")
    @PostMapping("/add")
    public ResponseResult addButton(@RequestBody Button button) {
        boolean b = buttonService.addButton(button);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "按钮管理-根据按钮类型查询按钮列表")
    @ApiOperation(value = "按钮管理-根据按钮类型查询按钮列表", notes = "按钮管理-根据按钮类型查询按钮列表")
    @GetMapping("/find/list")
    public QueryListResponseResult<Button> findByButtonType(@RequestParam("buttonType") Integer buttonType) {
        List<Button> list = buttonService.findByButtonType(buttonType);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "按钮管理-分页列表查询")
    @ApiOperation(value = "按钮管理-分页列表查询", notes = "按钮管理-分页列表查询")
    @GetMapping("/find/page/{page}/{size}")
    public QueryPageResponseResult<Button> findByPageList(@PathVariable("page") int page, @PathVariable("size") int size, ButtonRequest buttonRequest) {
        return buttonService.findByPageList(page, size, buttonRequest);
    }
 
    @AutoLog(value = "按钮管理-编辑按钮")
    @ApiOperation(value = "按钮管理-编辑按钮", notes = "按钮管理-编辑按钮")
    @PutMapping("/edit/{id}")
    public ResponseResult editButton(@PathVariable("id") String id,@RequestBody Button button) {
        boolean b = buttonService.editButton(id,button);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "按钮管理-删除按钮")
    @ApiOperation(value = "按钮管理-删除按钮", notes = "按钮管理-删除按钮")
    @DeleteMapping("/delete")
    public ResponseResult deleteButton(@RequestParam("id") String id) {
        boolean b = buttonService.deleteButtonById(id);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @AutoLog(value = "按钮管理-查询角色分配和未分配的系统按钮")
    @ApiOperation(value = "按钮管理-查询角色分配和未分配的系统按钮", notes = "按钮管理-查询角色分配和未分配的系统按钮")
    @GetMapping("/get/role")
    public QueryListResponseResult<Button> findPermsByRoleId(@RequestParam("roleId") String roleId) {
        List<Button> list = buttonService.findPermsByRoleId(roleId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "按钮管理-获取菜单分配的按钮列表 包含未分配按钮")
    @ApiOperation(value = "按钮管理-获取菜单分配的按钮列表 包含未分配按钮", notes = "按钮管理-获取菜单分配的按钮列表 包含未分配按钮")
    @GetMapping("/get/menu")
    public QueryListResponseResult<Button> findByMenuId(@RequestParam("menuId") String menuId) {
        List<Button> list = buttonService.findByMenuId(menuId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "按钮管理-获取对象分配的按钮列表 包含未分配按钮")
    @ApiOperation(value = "按钮管理-获取对象分配的按钮列表 包含未分配按钮", notes = "按钮管理-获取对象分配的按钮列表 包含未分配按钮")
    @GetMapping("/get/object")
    public QueryListResponseResult<Button> findByObjectId(@RequestParam("objectId") String objectId) {
        List<Button> list = buttonService.findByObjectId(objectId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @AutoLog(value = "按钮管理-导出自定义")
    @ApiOperation(value = "按钮管理-导出自定义", notes = "按钮管理-导出自定义")
    @GetMapping("/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        List<Button> list = buttonService.list();
        //mv.addObject(NormalExcelConstants.FILE_NAME,"导出Excel文件名字");
        //注解对象Class
        mv.addObject(NormalExcelConstants.CLASS,Button.class);
        //自定义导出字段
        //mv.addObject(NormalExcelConstants.EXPORT_FIELDS,"name,keyWord,punchTime");
        //自定义表格参数
        mv.addObject(NormalExcelConstants.PARAMS,new ExportParams("自定义导出Excel模板内容标题", "自定义Sheet名字"));
        //导出数据列表
        mv.addObject(NormalExcelConstants.DATA_LIST,list);
        return mv;
    }
}