13693261870
7 天以前 b8d62de41ff7e1e0549061308aa11f68cf881ed9
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
package com.terra.system.controller.sys;
 
import com.terra.system.annotation.SysLog;
import com.terra.system.controller.all.BaseController;
import com.terra.system.entity.all.ResponseMsg;
import com.terra.system.entity.sys.MenuEntity;
import com.terra.system.entity.sys.UserEntity;
import com.terra.system.helper.StringHelper;
import com.terra.system.service.all.PermsService;
import com.terra.system.service.sys.MenuService;
import com.terra.system.service.sys.TokenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import javax.annotation.Resource;
 
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
/**
 * 菜单
 * @author sws
 * @date   2022-09-23
 */
@Tag(name= "运维管理\\菜单管理")
@RestController
@RequestMapping("/menu")
public class MenuController extends BaseController {
    @Resource
    MenuService menuService;
 
    @Resource
    TokenService tokenService;
 
    @Resource
    PermsService permsService;
 
    @SysLog()
    @Operation(summary = "插入一条")
    @Parameters({
            @Parameter(name = "entity", description = "实体类", example = "")
    })
    @PostMapping(value = "/insertMenu", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertMenu(@RequestBody MenuEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            }
 
            int count = menuService.insertMenu(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @Operation(summary = "插入多条")
    @Parameters({
            @Parameter(name = "list", description = "实体类集合", example = "")
    })
    @PostMapping(value = "/insertMenus", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertMenus(@RequestBody List<MenuEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (MenuEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
 
            int count = menuService.insertMenus(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @Operation(summary = "删除一条")
    @Parameters({
            @Parameter(name = "id", description = "ID", in = ParameterIn.QUERY, example = "1")
    })
    @GetMapping(value = "/deleteMenu")
    public ResponseMsg<Integer> deleteMenu(int id) {
        try {
            int count = menuService.deleteMenu(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @Operation(summary = "删除多条")
    @Parameters({
            @Parameter(name = "ids", description = "ID数组", schema = @Schema(type = "array"), in = ParameterIn.QUERY, example = "1,2")
    })
    @GetMapping(value = "/deleteMenus")
    public ResponseMsg<Integer> deleteMenus(@RequestParam List<Integer> ids) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
 
            int count = menuService.deleteMenus(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @Operation(summary = "更新一条")
    @Parameters({
            @Parameter(name = "entity", description = "实体类", example = "")
    })
    @ResponseBody
    @PostMapping(value = "/updateMenu", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updateMenu(@RequestBody MenuEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
 
            int count = menuService.updateMenu(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @Operation(summary = "更新多条")
    @Parameters({
            @Parameter(name = "list", description = "实体类集合", example = "")
    })
    @ResponseBody
    @PostMapping(value = "/updateMenus", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updateMenus(@RequestBody List<MenuEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (MenuEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
 
            int count = menuService.updateMenus(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
 
    @SysLog()
    @Operation(summary = "根据ID查询")
    @Parameters({
            @Parameter(name = "id", description = "ID", in = ParameterIn.QUERY, example = "1")
    })
    @GetMapping(value = "/selectMenu")
    public ResponseMsg<MenuEntity> selectMenu(int id) {
        try {
            MenuEntity menuEntity = menuService.selectMenu(id);
 
            return success(menuEntity);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询所有")
    @GetMapping(value = "/selectMenuAll")
    public ResponseMsg<List<MenuEntity>> selectMenuAll() {
        try {
            List<MenuEntity> list = menuService.selectMenuAll();
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "递归查询")
    @Parameters({
            @Parameter(name = "name", description = "菜单名称", in = ParameterIn.QUERY, required = false, example = "管道基础大数据平台")
    })
    @GetMapping(value = "/selectMenuRecursive")
    public ResponseMsg<Object> selectMenuRecursive(String name) {
        try {
            if (StringHelper.isEmpty(name)) {
                name = "管道基础大数据平台";
            }
            List<MenuEntity> list = menuService.selectMenuRecursive(name);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
}