沙钢智慧能源系统后端代码
houzhongjian
2024-10-09 97edd72e5e6dbb134cedae4b72c95be8c948c5ec
提交 | 用户 | 时间
97edd7 1 package com.iailab.module.shasteel.controller.admin.demo;
H 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;
9 import com.iailab.module.shasteel.controller.admin.demo.vo.DemoPageReqVO;
10 import com.iailab.module.shasteel.controller.admin.demo.vo.DemoRespVO;
11 import com.iailab.module.shasteel.controller.admin.demo.vo.DemoSaveReqVO;
12 import com.iailab.module.shasteel.dal.dataobject.demo.DemoDO;
13 import com.iailab.module.shasteel.service.demo.DemoService;
14 import io.swagger.v3.oas.annotations.Operation;
15 import io.swagger.v3.oas.annotations.Parameter;
16 import io.swagger.v3.oas.annotations.tags.Tag;
17 import org.springframework.security.access.prepost.PreAuthorize;
18 import org.springframework.web.bind.annotation.*;
19
20 import javax.annotation.Resource;
21 import javax.servlet.http.HttpServletResponse;
22 import javax.validation.Valid;
23 import java.io.IOException;
24 import java.util.List;
25
26 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
27 import static com.iailab.framework.common.pojo.CommonResult.success;
28
29 @Tag(name = "管理后台 - 演示管理")
30 @RestController
31 @RequestMapping("/shasteel/demo")
32 public class DemoController {
33
34     @Resource
35     private DemoService demoService;
36
37     @PostMapping("/create")
38     @Operation(summary = "创建演示")
39     @PreAuthorize("@ss.hasPermission('shasteel:demo:create')")
40     public CommonResult<Long> createDemo(@Valid @RequestBody DemoSaveReqVO createReqVO) {
41         return success(demoService.create(createReqVO));
42     }
43
44     @PutMapping("/update")
45     @Operation(summary = "更新演示")
46     @PreAuthorize("@ss.hasPermission('shasteel:demo:update')")
47     public CommonResult<Boolean> updateDemo(@Valid @RequestBody DemoSaveReqVO updateReqVO) {
48         demoService.update(updateReqVO);
49         return success(true);
50     }
51
52     @DeleteMapping("/delete")
53     @Operation(summary = "删除演示")
54     @Parameter(name = "id", description = "ID", required = true, example = "1024")
55     @PreAuthorize("@ss.hasPermission('shasteel:demo:delete')")
56     public CommonResult<Boolean> deleteDemo(@RequestParam("id") Long id) {
57         demoService.delete(id);
58         return success(true);
59     }
60
61     @GetMapping("/get")
62     @Operation(summary = "获得演示")
63     @Parameter(name = "id", description = "ID", required = true, example = "1024")
64     @PreAuthorize("@ss.hasPermission('shasteel:demo:query')")
65     public CommonResult<DemoRespVO> getTenant(@RequestParam("id") Long id) {
66         DemoDO data = demoService.getInfo(id);
67         return success(BeanUtils.toBean(data, DemoRespVO.class));
68     }
69
70     @GetMapping("/page")
71     @Operation(summary = "获得分页")
72     @PreAuthorize("@ss.hasPermission('shasteel:demo:query')")
73     public CommonResult<PageResult<DemoRespVO>> getTenantPage(@Valid DemoPageReqVO pageVO) {
74         PageResult<DemoDO> pageResult = demoService.getPage(pageVO);
75         return success(BeanUtils.toBean(pageResult, DemoRespVO.class));
76     }
77
78     @GetMapping("/export-excel")
79     @Operation(summary = "导出租户 Excel")
80     @PreAuthorize("@ss.hasPermission('system:tenant:export')")
81     @ApiAccessLog(operateType = EXPORT)
82     public void exportTenantExcel(@Valid DemoPageReqVO exportReqVO,
83                                   HttpServletResponse response) throws IOException {
84         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
85         List<DemoDO> list = demoService.getPage(exportReqVO).getList();
86         // 导出 Excel
87         ExcelUtils.write(response, "租户.xls", "数据", DemoRespVO.class,
88                 BeanUtils.toBean(list, DemoRespVO.class));
89     }
90 }