潘志宝
2024-12-16 df99e46312fdd5ee830f1451e478f6658e09f9ed
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.system.controller.admin.dict;
H 2
3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
4 import com.iailab.framework.common.enums.CommonStatusEnum;
5 import com.iailab.framework.common.pojo.CommonResult;
6 import com.iailab.framework.common.pojo.PageParam;
7 import com.iailab.framework.common.pojo.PageResult;
8 import com.iailab.framework.common.util.object.BeanUtils;
9 import com.iailab.framework.excel.core.util.ExcelUtils;
10 import com.iailab.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
11 import com.iailab.module.system.controller.admin.dict.vo.data.DictDataRespVO;
12 import com.iailab.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
13 import com.iailab.module.system.controller.admin.dict.vo.data.DictDataSimpleRespVO;
14 import com.iailab.module.system.dal.dataobject.dict.DictDataDO;
15 import com.iailab.module.system.service.dict.DictDataService;
16 import io.swagger.v3.oas.annotations.Operation;
17 import io.swagger.v3.oas.annotations.Parameter;
18 import io.swagger.v3.oas.annotations.tags.Tag;
19 import org.springframework.security.access.prepost.PreAuthorize;
20 import org.springframework.validation.annotation.Validated;
21 import org.springframework.web.bind.annotation.*;
22
23 import javax.annotation.Resource;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.validation.Valid;
26 import java.io.IOException;
27 import java.util.List;
28
29 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
30 import static com.iailab.framework.common.pojo.CommonResult.success;
31
32 @Tag(name = "管理后台 - 字典数据")
33 @RestController
34 @RequestMapping("/system/dict-data")
35 @Validated
36 public class DictDataController {
37
38     @Resource
39     private DictDataService dictDataService;
40
41     @PostMapping("/create")
42     @Operation(summary = "新增字典数据")
43     @PreAuthorize("@ss.hasPermission('system:dict:create')")
44     public CommonResult<Long> createDictData(@Valid @RequestBody DictDataSaveReqVO createReqVO) {
45         Long dictDataId = dictDataService.createDictData(createReqVO);
46         return success(dictDataId);
47     }
48
49     @PutMapping("/update")
50     @Operation(summary = "修改字典数据")
51     @PreAuthorize("@ss.hasPermission('system:dict:update')")
52     public CommonResult<Boolean> updateDictData(@Valid @RequestBody DictDataSaveReqVO updateReqVO) {
53         dictDataService.updateDictData(updateReqVO);
54         return success(true);
55     }
56
57     @DeleteMapping("/delete")
58     @Operation(summary = "删除字典数据")
59     @Parameter(name = "id", description = "编号", required = true, example = "1024")
60     @PreAuthorize("@ss.hasPermission('system:dict:delete')")
61     public CommonResult<Boolean> deleteDictData(Long id) {
62         dictDataService.deleteDictData(id);
63         return success(true);
64     }
65
66     @GetMapping(value = {"/list-all-simple", "simple-list"})
67     @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地")
68     // 无需添加权限认证,因为前端全局都需要
69     public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() {
70         List<DictDataDO> list = dictDataService.getDictDataList(
71                 CommonStatusEnum.ENABLE.getStatus(), null);
72         return success(BeanUtils.toBean(list, DictDataSimpleRespVO.class));
73     }
74
75     @GetMapping("/page")
76     @Operation(summary = "/获得字典类型的分页列表")
77     @PreAuthorize("@ss.hasPermission('system:dict:query')")
78     public CommonResult<PageResult<DictDataRespVO>> getDictTypePage(@Valid DictDataPageReqVO pageReqVO) {
79         PageResult<DictDataDO> pageResult = dictDataService.getDictDataPage(pageReqVO);
80         return success(BeanUtils.toBean(pageResult, DictDataRespVO.class));
81     }
82
83     @GetMapping(value = "/get")
84     @Operation(summary = "/查询字典数据详细")
85     @Parameter(name = "id", description = "编号", required = true, example = "1024")
86     @PreAuthorize("@ss.hasPermission('system:dict:query')")
87     public CommonResult<DictDataRespVO> getDictData(@RequestParam("id") Long id) {
88         DictDataDO dictData = dictDataService.getDictData(id);
89         return success(BeanUtils.toBean(dictData, DictDataRespVO.class));
90     }
91
92     @GetMapping("/export")
93     @Operation(summary = "导出字典数据")
94     @PreAuthorize("@ss.hasPermission('system:dict:export')")
95     @ApiAccessLog(operateType = EXPORT)
96     public void export(HttpServletResponse response, @Valid DictDataPageReqVO exportReqVO) throws IOException {
97         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
98         List<DictDataDO> list = dictDataService.getDictDataPage(exportReqVO).getList();
99         // 输出
100         ExcelUtils.write(response, "字典数据.xls", "数据", DictDataRespVO.class,
101                 BeanUtils.toBean(list, DictDataRespVO.class));
102     }
103
104 }