houzhongjian
2024-08-02 d141aee7ec84d3578a19be8c26f10759c1e557b4
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.controller.admin.demo.demo01;
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.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
10 import com.iailab.module.infra.controller.admin.demo.demo01.vo.Demo01ContactRespVO;
11 import com.iailab.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
12 import com.iailab.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
13 import com.iailab.module.infra.service.demo.demo01.Demo01ContactService;
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.validation.annotation.Validated;
19 import org.springframework.web.bind.annotation.*;
20
21 import javax.annotation.Resource;
22 import javax.servlet.http.HttpServletResponse;
23 import javax.validation.Valid;
24 import java.io.IOException;
25 import java.util.List;
26
27 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
28 import static com.iailab.framework.common.pojo.CommonResult.success;
29
30 @Tag(name = "管理后台 - 示例联系人")
31 @RestController
32 @RequestMapping("/infra/demo01-contact")
33 @Validated
34 public class Demo01ContactController {
35
36     @Resource
37     private Demo01ContactService demo01ContactService;
38
39     @PostMapping("/create")
40     @Operation(summary = "创建示例联系人")
41     @PreAuthorize("@ss.hasPermission('infra:demo01-contact:create')")
42     public CommonResult<Long> createDemo01Contact(@Valid @RequestBody Demo01ContactSaveReqVO createReqVO) {
43         return success(demo01ContactService.createDemo01Contact(createReqVO));
44     }
45
46     @PutMapping("/update")
47     @Operation(summary = "更新示例联系人")
48     @PreAuthorize("@ss.hasPermission('infra:demo01-contact:update')")
49     public CommonResult<Boolean> updateDemo01Contact(@Valid @RequestBody Demo01ContactSaveReqVO updateReqVO) {
50         demo01ContactService.updateDemo01Contact(updateReqVO);
51         return success(true);
52     }
53
54     @DeleteMapping("/delete")
55     @Operation(summary = "删除示例联系人")
56     @Parameter(name = "id", description = "编号", required = true)
57     @PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')")
58     public CommonResult<Boolean> deleteDemo01Contact(@RequestParam("id") Long id) {
59         demo01ContactService.deleteDemo01Contact(id);
60         return success(true);
61     }
62
63     @GetMapping("/get")
64     @Operation(summary = "获得示例联系人")
65     @Parameter(name = "id", description = "编号", required = true, example = "1024")
66     @PreAuthorize("@ss.hasPermission('infra:demo01-contact:query')")
67     public CommonResult<Demo01ContactRespVO> getDemo01Contact(@RequestParam("id") Long id) {
68         Demo01ContactDO demo01Contact = demo01ContactService.getDemo01Contact(id);
69         return success(BeanUtils.toBean(demo01Contact, Demo01ContactRespVO.class));
70     }
71
72     @GetMapping("/page")
73     @Operation(summary = "获得示例联系人分页")
74     @PreAuthorize("@ss.hasPermission('infra:demo01-contact:query')")
75     public CommonResult<PageResult<Demo01ContactRespVO>> getDemo01ContactPage(@Valid Demo01ContactPageReqVO pageReqVO) {
76         PageResult<Demo01ContactDO> pageResult = demo01ContactService.getDemo01ContactPage(pageReqVO);
77         return success(BeanUtils.toBean(pageResult, Demo01ContactRespVO.class));
78     }
79
80     @GetMapping("/export-excel")
81     @Operation(summary = "导出示例联系人 Excel")
82     @PreAuthorize("@ss.hasPermission('infra:demo01-contact:export')")
83     @ApiAccessLog(operateType = EXPORT)
84     public void exportDemo01ContactExcel(@Valid Demo01ContactPageReqVO pageReqVO,
85               HttpServletResponse response) throws IOException {
86         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
87         List<Demo01ContactDO> list = demo01ContactService.getDemo01ContactPage(pageReqVO).getList();
88         // 导出 Excel
89         ExcelUtils.write(response, "示例联系人.xls", "数据", Demo01ContactRespVO.class,
90                         BeanUtils.toBean(list, Demo01ContactRespVO.class));
91     }
92
93 }