潘志宝
2024-12-25 8a6b19bf5c50ebb54e965645a9366f6cfea02351
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
package com.iailab.module.system.controller.admin.app;
 
import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.pojo.PageParam;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.framework.excel.core.util.ExcelUtils;
import com.iailab.module.system.api.app.dto.AppMenuRespDTO;
import com.iailab.module.system.controller.admin.app.vo.AppPageReqVO;
import com.iailab.module.system.controller.admin.app.vo.AppRespVO;
import com.iailab.module.system.controller.admin.app.vo.AppSaveReqVO;
import com.iailab.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
import com.iailab.module.system.dal.dataobject.app.AppDO;
import com.iailab.module.system.service.app.AppService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
 
import java.io.IOException;
import java.util.List;
 
import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.iailab.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - 应用管理")
@RestController
@RequestMapping("/system/app")
public class AppController {
 
    @Autowired
    private AppService appService;
 
    @PostMapping("/create")
    @Operation(summary = "创建应用")
    @PreAuthorize("@ss.hasPermission('system:app:create')")
    public CommonResult<Long> createApp(@Valid @RequestBody AppSaveReqVO createReqVO) {
        return success(appService.create(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新应用")
    @PreAuthorize("@ss.hasPermission('system:app:update')")
    public CommonResult<Boolean> updateApp(@Valid @RequestBody AppSaveReqVO updateReqVO) {
        appService.update(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除应用")
    @Parameter(name = "id", description = "ID", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:app:delete')")
    public CommonResult<Boolean> deleteApp(@RequestParam("id") Long id) {
        appService.delete(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得应用")
    @Parameter(name = "id", description = "ID", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:app:query')")
    public CommonResult<AppRespVO> getTenant(@RequestParam("id") Long id) {
        AppDO data = appService.getInfo(id);
        return success(BeanUtils.toBean(data, AppRespVO.class));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得分页")
    @PreAuthorize("@ss.hasPermission('system:app:query')")
    public CommonResult<PageResult<AppRespVO>> getAppPage(@Valid AppPageReqVO pageVO) {
        PageResult<AppDO> pageResult = appService.getPage(pageVO);
        return success(BeanUtils.toBean(pageResult, AppRespVO.class));
    }
 
    @GetMapping("/getAppList")
    @Operation(summary = "获得应用列表")
    @PreAuthorize("@ss.hasPermission('system:app-menu:query')")
    public CommonResult<List<AppRespVO>> getAppList() {
        List<AppDO> appDOS = appService.getList();
        return success(BeanUtils.toBean(appDOS, AppRespVO.class));
    }
 
    @GetMapping("/getAppMenu")
    @Operation(summary = "获得应用菜单列表")
    @PreAuthorize("@ss.hasPermission('system:app-menu:query')")
    @Parameter(name = "id", description = "ID", required = true, example = "1024")
    public CommonResult<List<AppRespVO>> getAppMenu(@RequestParam("id") Long id) {
        List<AuthPermissionInfoRespVO.MenuVO> appDOS = appService.getAppMenu(id);
        return success(BeanUtils.toBean(appDOS, AppRespVO.class));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出租户 Excel")
    @PreAuthorize("@ss.hasPermission('system:tenant:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportTenantExcel(@Valid AppPageReqVO exportReqVO,
                                  HttpServletResponse response) throws IOException {
        exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<AppDO> list = appService.getPage(exportReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "租户.xls", "数据", AppRespVO.class,
                BeanUtils.toBean(list, AppRespVO.class));
    }
}