dengzedong
2024-10-14 558ffc4bcaf7aa5c683e7c9ce01e971feb9e4d95
提交 | 用户 | 时间
5f25e3 1 package com.iailab.module.system.controller.admin.app;
2
3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageParam;
6 import com.iailab.framework.common.pojo.PageResult;
7 import com.iailab.framework.common.util.object.BeanUtils;
8 import com.iailab.framework.excel.core.util.ExcelUtils;
818a01 9 import com.iailab.module.system.api.app.dto.AppMenuRespDTO;
5f25e3 10 import com.iailab.module.system.controller.admin.app.vo.AppPageReqVO;
11 import com.iailab.module.system.controller.admin.app.vo.AppRespVO;
12 import com.iailab.module.system.controller.admin.app.vo.AppSaveReqVO;
13 import com.iailab.module.system.dal.dataobject.app.AppDO;
14 import com.iailab.module.system.service.app.AppService;
15 import io.swagger.v3.oas.annotations.Operation;
16 import io.swagger.v3.oas.annotations.Parameter;
17 import io.swagger.v3.oas.annotations.tags.Tag;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.security.access.prepost.PreAuthorize;
20 import org.springframework.web.bind.annotation.*;
21
22 import javax.servlet.http.HttpServletResponse;
23 import javax.validation.Valid;
24
25 import java.io.IOException;
26 import java.util.List;
27
28 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
29 import static com.iailab.framework.common.pojo.CommonResult.success;
30
31 @Tag(name = "管理后台 - 应用管理")
32 @RestController
33 @RequestMapping("/system/app")
34 public class AppController {
35
36     @Autowired
37     private AppService appService;
38
39     @PostMapping("/create")
40     @Operation(summary = "创建应用")
41     @PreAuthorize("@ss.hasPermission('system:app:create')")
42     public CommonResult<Long> createApp(@Valid @RequestBody AppSaveReqVO createReqVO) {
43         return success(appService.create(createReqVO));
44     }
45
46     @PutMapping("/update")
47     @Operation(summary = "更新应用")
48     @PreAuthorize("@ss.hasPermission('system:app:update')")
49     public CommonResult<Boolean> updateApp(@Valid @RequestBody AppSaveReqVO updateReqVO) {
50         appService.update(updateReqVO);
51         return success(true);
52     }
53
54     @DeleteMapping("/delete")
55     @Operation(summary = "删除应用")
56     @Parameter(name = "id", description = "ID", required = true, example = "1024")
57     @PreAuthorize("@ss.hasPermission('system:app:delete')")
58     public CommonResult<Boolean> deleteApp(@RequestParam("id") Long id) {
59         appService.delete(id);
60         return success(true);
61     }
62
63     @GetMapping("/get")
64     @Operation(summary = "获得应用")
65     @Parameter(name = "id", description = "ID", required = true, example = "1024")
66     @PreAuthorize("@ss.hasPermission('system:app:query')")
67     public CommonResult<AppRespVO> getTenant(@RequestParam("id") Long id) {
68         AppDO data = appService.getInfo(id);
69         return success(BeanUtils.toBean(data, AppRespVO.class));
70     }
71
72     @GetMapping("/page")
256352 73     @Operation(summary = "获得分页")
5f25e3 74     @PreAuthorize("@ss.hasPermission('system:app:query')")
818a01 75     public CommonResult<PageResult<AppRespVO>> getAppPage(@Valid AppPageReqVO pageVO) {
5f25e3 76         PageResult<AppDO> pageResult = appService.getPage(pageVO);
77         return success(BeanUtils.toBean(pageResult, AppRespVO.class));
78     }
79
818a01 80     @GetMapping("/getAppList")
H 81     @Operation(summary = "获得应用列表")
82     @PreAuthorize("@ss.hasPermission('system:app-menu:query')")
83     public CommonResult<List<AppRespVO>> getAppList() {
84         List<AppDO> appDOS = appService.getList();
85         return success(BeanUtils.toBean(appDOS, AppRespVO.class));
86     }
87
88 //    @GetMapping("/getAppMenu")
89 //    @Operation(summary = "获得应用菜单列表")
90 //    @PreAuthorize("@ss.hasPermission('system:app-menu:query')")
91 //    @Parameter(name = "id", description = "ID", required = true, example = "1024")
92 //    public CommonResult<List<AppRespVO>> getAppMenu(@RequestParam("id") Long id) {
93 //        List<AppMenuRespDTO> appDOS = appService.getAppMenu(id);
94 //        return success(BeanUtils.toBean(appDOS, AppRespVO.class));
95 //    }
96
5f25e3 97     @GetMapping("/export-excel")
98     @Operation(summary = "导出租户 Excel")
99     @PreAuthorize("@ss.hasPermission('system:tenant:export')")
100     @ApiAccessLog(operateType = EXPORT)
101     public void exportTenantExcel(@Valid AppPageReqVO exportReqVO,
102                                   HttpServletResponse response) throws IOException {
103         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
104         List<AppDO> list = appService.getPage(exportReqVO).getList();
105         // 导出 Excel
106         ExcelUtils.write(response, "租户.xls", "数据", AppRespVO.class,
107                 BeanUtils.toBean(list, AppRespVO.class));
108     }
109 }