Jay
2024-10-12 f6a1e4196efbddd6fc4bcf7191a5ccb30ccae946
提交 | 用户 | 时间
68413a 1 package com.iailab.module.data.ind.item.controller.admin;
J 2
3 import com.iailab.framework.common.pojo.CommonResult;
4 import com.iailab.framework.common.pojo.PageResult;
5 import com.iailab.framework.common.util.object.BeanUtils;
6 import com.iailab.module.data.common.enums.ItemTypeEnum;
7 import com.iailab.module.data.ind.category.service.IndItemCategoryService;
8 import com.iailab.module.data.ind.item.entity.IndItemEntity;
9 import com.iailab.module.data.ind.item.service.IndItemAtomService;
10 import com.iailab.module.data.ind.item.service.IndItemCalService;
11 import com.iailab.module.data.ind.item.service.IndItemDerService;
12 import com.iailab.module.data.ind.item.service.IndItemService;
13 import com.iailab.module.data.ind.item.vo.*;
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.beans.factory.annotation.Autowired;
18 import org.springframework.security.access.prepost.PreAuthorize;
19 import org.springframework.validation.annotation.Validated;
20 import org.springframework.web.bind.annotation.*;
21
22 import javax.validation.Valid;
23 import java.util.List;
24
25 import static com.iailab.framework.common.pojo.CommonResult.success;
26
27 /**
28  * @author PanZhibao
29  * @Description
30  * @createTime 2024年09月11日
31  */
32 @Tag(name = "数据平台 - 指标项")
33 @RestController
34 @RequestMapping("/data/ind-item")
35 @Validated
36 public class IndItemController {
37     @Autowired
38     private IndItemService indItemService;
39
40     @Autowired
41     private IndItemAtomService indItemAtomService;
42
43     @Autowired
44     private IndItemDerService indItemDerService;
45
46     @Autowired
47     private IndItemCalService indItemCalService;
48
49     @Autowired
50     private IndItemCategoryService indItemCategoryService;
51
52     @GetMapping("/page")
53     @Operation(summary = "获取指标项列表", description = "用于【指标项】界面")
54     @PreAuthorize("@ss.hasPermission('data:ind-item:query')")
55     public CommonResult<PageResult<IndItemRespVO>> page(IndItemPageReqVO reqVO) {
56         PageResult<IndItemEntity> page = indItemService.page(reqVO);
57         PageResult<IndItemRespVO> result = BeanUtils.toBean(page, IndItemRespVO.class);
58         for (IndItemRespVO item : result.getList()){
59             item.setItemCategoryName(indItemCategoryService.get(item.getItemCategory()) == null ? "" : indItemCategoryService.get(item.getItemCategory()).getLabel());
60         }
61         return success(result);
62     }
63
64     @PostMapping("/create")
65     @Operation(summary = "创建指标项")
66     @PreAuthorize("@ss.hasPermission('data:ind-item:create')")
67     public CommonResult<Boolean> create(@Valid @RequestBody IndItemSaveReqVO createReqVO) {
68         indItemService.create(createReqVO);
69         return success(true);
70     }
71
72     @PutMapping("/update")
73     @Operation(summary = "修改指标项")
74     @PreAuthorize("@ss.hasPermission('data:ind-item:update')")
75     public CommonResult<Boolean> update(@Valid @RequestBody IndItemSaveReqVO updateReqVO) {
76         indItemService.update(updateReqVO);
77         return success(true);
78     }
79
80     @DeleteMapping("/delete")
81     @Operation(summary = "删除指标项")
82     @Parameter(name = "id", description = "指标项编号", required= true, example = "1024")
83     @PreAuthorize("@ss.hasPermission('data:ind-item:delete')")
84     public CommonResult<Boolean> delete(@RequestParam("id") String id) {
85         indItemService.delete(id);
86         return success(true);
87     }
88
89     @GetMapping("/get")
90     @Operation(summary = "获取指标项信息")
91     @PreAuthorize("@ss.hasPermission('data:ind-item:query')")
92     public CommonResult<IndItemRespVO> get(@RequestParam("id") String id) {
93         IndItemEntity entity = indItemService.get(id);
94         IndItemRespVO respVO = BeanUtils.toBean(entity, IndItemRespVO.class);
95         if (ItemTypeEnum.ATOM.getCode().equals(entity.getItemType())){
96             respVO.setAtomItem(indItemAtomService.getByItemId(entity.getId()));
97         }else if (ItemTypeEnum.DER.getCode().equals(entity.getItemType())){
cf757d 98             IndItemDerVO derItem = indItemDerService.getByItemId(entity.getId());
68413a 99             respVO.setDerItem(derItem);
f6a1e4 100             respVO.setAtomItem(indItemAtomService.getByItemId(derItem.getAtomItemId()));
68413a 101         }else if (ItemTypeEnum.CAL.getCode().equals(entity.getItemType())){
cf757d 102             respVO.setCalItem(indItemCalService.getByItemId(entity.getId()) == null ? new IndItemCalVO() : indItemCalService.getByItemId(entity.getId()));
68413a 103         }
J 104         return success(respVO);
105     }
106
107     @GetMapping("/getList")
108     @Operation(summary = "获取指标项列表", description = "用于【指标项】界面")
109     @PreAuthorize("@ss.hasPermission('data:ind-item:query')")
110     public CommonResult<List<IndItemRespVO>> getList(IndItemPageReqVO reqVO) {
111         List<IndItemRespVO> list = indItemService.getList(reqVO);
112         return success(list);
113     }
114 }