houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
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
package com.iailab.module.infra.controller.admin.demo;
 
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
 
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
 
import com.iailab.framework.common.pojo.PageParam;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.util.object.BeanUtils;
import static com.iailab.framework.common.pojo.CommonResult.success;
 
import com.iailab.framework.excel.core.util.ExcelUtils;
 
import com.iailab.framework.operatelog.core.annotations.OperateLog;
import static com.iailab.framework.operatelog.core.enums.OperateTypeEnum.*;
 
import com.iailab.module.infra.controller.admin.demo.vo.*;
import com.iailab.module.infra.dal.dataobject.demo.InfraCategoryDO;
import com.iailab.module.infra.service.demo.InfraCategoryService;
 
@Tag(name = "管理后台 - 分类")
@RestController
@RequestMapping("/infra/category")
@Validated
public class InfraCategoryController {
 
    @Resource
    private InfraCategoryService categoryService;
 
    @PostMapping("/create")
    @Operation(summary = "创建分类")
    @PreAuthorize("@ss.hasPermission('infra:category:create')")
    public CommonResult<Long> createCategory(@Valid @RequestBody InfraCategorySaveReqVO createReqVO) {
        return success(categoryService.createCategory(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新分类")
    @PreAuthorize("@ss.hasPermission('infra:category:update')")
    public CommonResult<Boolean> updateCategory(@Valid @RequestBody InfraCategorySaveReqVO updateReqVO) {
        categoryService.updateCategory(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除分类")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('infra:category:delete')")
    public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) {
        categoryService.deleteCategory(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得分类")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('infra:category:query')")
    public CommonResult<InfraCategoryRespVO> getCategory(@RequestParam("id") Long id) {
        InfraCategoryDO category = categoryService.getCategory(id);
        return success(BeanUtils.toBean(category, InfraCategoryRespVO.class));
    }
 
    @GetMapping("/list")
    @Operation(summary = "获得分类列表")
    @PreAuthorize("@ss.hasPermission('infra:category:query')")
    public CommonResult<List<InfraCategoryRespVO>> getCategoryList(@Valid InfraCategoryListReqVO listReqVO) {
        List<InfraCategoryDO> list = categoryService.getCategoryList(listReqVO);
        return success(BeanUtils.toBean(list, InfraCategoryRespVO.class));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出分类 Excel")
    @PreAuthorize("@ss.hasPermission('infra:category:export')")
    @OperateLog(type = EXPORT)
    public void exportCategoryExcel(@Valid InfraCategoryListReqVO listReqVO,
              HttpServletResponse response) throws IOException {
        List<InfraCategoryDO> list = categoryService.getCategoryList(listReqVO);
        // 导出 Excel
        ExcelUtils.write(response, "分类.xls", "数据", InfraCategoryRespVO.class,
                        BeanUtils.toBean(list, InfraCategoryRespVO.class));
    }
 
}