提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.controller.admin.demo; |
H |
2 |
|
|
3 |
import org.springframework.web.bind.annotation.*; |
|
4 |
import javax.annotation.Resource; |
|
5 |
import org.springframework.validation.annotation.Validated; |
|
6 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
7 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
8 |
import io.swagger.v3.oas.annotations.Parameter; |
|
9 |
import io.swagger.v3.oas.annotations.Operation; |
|
10 |
|
|
11 |
import javax.validation.constraints.*; |
|
12 |
import javax.validation.*; |
|
13 |
import javax.servlet.http.*; |
|
14 |
import java.util.*; |
|
15 |
import java.io.IOException; |
|
16 |
|
|
17 |
import com.iailab.framework.common.pojo.PageParam; |
|
18 |
import com.iailab.framework.common.pojo.PageResult; |
|
19 |
import com.iailab.framework.common.pojo.CommonResult; |
|
20 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
21 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
22 |
|
|
23 |
import com.iailab.framework.excel.core.util.ExcelUtils; |
|
24 |
|
|
25 |
import com.iailab.framework.operatelog.core.annotations.OperateLog; |
|
26 |
import static com.iailab.framework.operatelog.core.enums.OperateTypeEnum.*; |
|
27 |
|
|
28 |
import com.iailab.module.infra.controller.admin.demo.vo.*; |
|
29 |
import com.iailab.module.infra.dal.dataobject.demo.InfraCategoryDO; |
|
30 |
import com.iailab.module.infra.service.demo.InfraCategoryService; |
|
31 |
|
|
32 |
@Tag(name = "管理后台 - 分类") |
|
33 |
@RestController |
|
34 |
@RequestMapping("/infra/category") |
|
35 |
@Validated |
|
36 |
public class InfraCategoryController { |
|
37 |
|
|
38 |
@Resource |
|
39 |
private InfraCategoryService categoryService; |
|
40 |
|
|
41 |
@PostMapping("/create") |
|
42 |
@Operation(summary = "创建分类") |
|
43 |
@PreAuthorize("@ss.hasPermission('infra:category:create')") |
|
44 |
public CommonResult<Long> createCategory(@Valid @RequestBody InfraCategorySaveReqVO createReqVO) { |
|
45 |
return success(categoryService.createCategory(createReqVO)); |
|
46 |
} |
|
47 |
|
|
48 |
@PutMapping("/update") |
|
49 |
@Operation(summary = "更新分类") |
|
50 |
@PreAuthorize("@ss.hasPermission('infra:category:update')") |
|
51 |
public CommonResult<Boolean> updateCategory(@Valid @RequestBody InfraCategorySaveReqVO updateReqVO) { |
|
52 |
categoryService.updateCategory(updateReqVO); |
|
53 |
return success(true); |
|
54 |
} |
|
55 |
|
|
56 |
@DeleteMapping("/delete") |
|
57 |
@Operation(summary = "删除分类") |
|
58 |
@Parameter(name = "id", description = "编号", required = true) |
|
59 |
@PreAuthorize("@ss.hasPermission('infra:category:delete')") |
|
60 |
public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) { |
|
61 |
categoryService.deleteCategory(id); |
|
62 |
return success(true); |
|
63 |
} |
|
64 |
|
|
65 |
@GetMapping("/get") |
|
66 |
@Operation(summary = "获得分类") |
|
67 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
68 |
@PreAuthorize("@ss.hasPermission('infra:category:query')") |
|
69 |
public CommonResult<InfraCategoryRespVO> getCategory(@RequestParam("id") Long id) { |
|
70 |
InfraCategoryDO category = categoryService.getCategory(id); |
|
71 |
return success(BeanUtils.toBean(category, InfraCategoryRespVO.class)); |
|
72 |
} |
|
73 |
|
|
74 |
@GetMapping("/list") |
|
75 |
@Operation(summary = "获得分类列表") |
|
76 |
@PreAuthorize("@ss.hasPermission('infra:category:query')") |
|
77 |
public CommonResult<List<InfraCategoryRespVO>> getCategoryList(@Valid InfraCategoryListReqVO listReqVO) { |
|
78 |
List<InfraCategoryDO> list = categoryService.getCategoryList(listReqVO); |
|
79 |
return success(BeanUtils.toBean(list, InfraCategoryRespVO.class)); |
|
80 |
} |
|
81 |
|
|
82 |
@GetMapping("/export-excel") |
|
83 |
@Operation(summary = "导出分类 Excel") |
|
84 |
@PreAuthorize("@ss.hasPermission('infra:category:export')") |
|
85 |
@OperateLog(type = EXPORT) |
|
86 |
public void exportCategoryExcel(@Valid InfraCategoryListReqVO listReqVO, |
|
87 |
HttpServletResponse response) throws IOException { |
|
88 |
List<InfraCategoryDO> list = categoryService.getCategoryList(listReqVO); |
|
89 |
// 导出 Excel |
|
90 |
ExcelUtils.write(response, "分类.xls", "数据", InfraCategoryRespVO.class, |
|
91 |
BeanUtils.toBean(list, InfraCategoryRespVO.class)); |
|
92 |
} |
|
93 |
|
|
94 |
} |