Jay
2024-10-12 f6a1e4196efbddd6fc4bcf7191a5ccb30ccae946
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.iailab.module.data.ind.item.controller.admin;
 
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.data.common.enums.ItemTypeEnum;
import com.iailab.module.data.ind.category.service.IndItemCategoryService;
import com.iailab.module.data.ind.item.entity.IndItemEntity;
import com.iailab.module.data.ind.item.service.IndItemAtomService;
import com.iailab.module.data.ind.item.service.IndItemCalService;
import com.iailab.module.data.ind.item.service.IndItemDerService;
import com.iailab.module.data.ind.item.service.IndItemService;
import com.iailab.module.data.ind.item.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.List;
 
import static com.iailab.framework.common.pojo.CommonResult.success;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年09月11日
 */
@Tag(name = "数据平台 - 指标项")
@RestController
@RequestMapping("/data/ind-item")
@Validated
public class IndItemController {
    @Autowired
    private IndItemService indItemService;
 
    @Autowired
    private IndItemAtomService indItemAtomService;
 
    @Autowired
    private IndItemDerService indItemDerService;
 
    @Autowired
    private IndItemCalService indItemCalService;
 
    @Autowired
    private IndItemCategoryService indItemCategoryService;
 
    @GetMapping("/page")
    @Operation(summary = "获取指标项列表", description = "用于【指标项】界面")
    @PreAuthorize("@ss.hasPermission('data:ind-item:query')")
    public CommonResult<PageResult<IndItemRespVO>> page(IndItemPageReqVO reqVO) {
        PageResult<IndItemEntity> page = indItemService.page(reqVO);
        PageResult<IndItemRespVO> result = BeanUtils.toBean(page, IndItemRespVO.class);
        for (IndItemRespVO item : result.getList()){
            item.setItemCategoryName(indItemCategoryService.get(item.getItemCategory()) == null ? "" : indItemCategoryService.get(item.getItemCategory()).getLabel());
        }
        return success(result);
    }
 
    @PostMapping("/create")
    @Operation(summary = "创建指标项")
    @PreAuthorize("@ss.hasPermission('data:ind-item:create')")
    public CommonResult<Boolean> create(@Valid @RequestBody IndItemSaveReqVO createReqVO) {
        indItemService.create(createReqVO);
        return success(true);
    }
 
    @PutMapping("/update")
    @Operation(summary = "修改指标项")
    @PreAuthorize("@ss.hasPermission('data:ind-item:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody IndItemSaveReqVO updateReqVO) {
        indItemService.update(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除指标项")
    @Parameter(name = "id", description = "指标项编号", required= true, example = "1024")
    @PreAuthorize("@ss.hasPermission('data:ind-item:delete')")
    public CommonResult<Boolean> delete(@RequestParam("id") String id) {
        indItemService.delete(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获取指标项信息")
    @PreAuthorize("@ss.hasPermission('data:ind-item:query')")
    public CommonResult<IndItemRespVO> get(@RequestParam("id") String id) {
        IndItemEntity entity = indItemService.get(id);
        IndItemRespVO respVO = BeanUtils.toBean(entity, IndItemRespVO.class);
        if (ItemTypeEnum.ATOM.getCode().equals(entity.getItemType())){
            respVO.setAtomItem(indItemAtomService.getByItemId(entity.getId()));
        }else if (ItemTypeEnum.DER.getCode().equals(entity.getItemType())){
            IndItemDerVO derItem = indItemDerService.getByItemId(entity.getId());
            respVO.setDerItem(derItem);
            respVO.setAtomItem(indItemAtomService.getByItemId(derItem.getAtomItemId()));
        }else if (ItemTypeEnum.CAL.getCode().equals(entity.getItemType())){
            respVO.setCalItem(indItemCalService.getByItemId(entity.getId()) == null ? new IndItemCalVO() : indItemCalService.getByItemId(entity.getId()));
        }
        return success(respVO);
    }
 
    @GetMapping("/getList")
    @Operation(summary = "获取指标项列表", description = "用于【指标项】界面")
    @PreAuthorize("@ss.hasPermission('data:ind-item:query')")
    public CommonResult<List<IndItemRespVO>> getList(IndItemPageReqVO reqVO) {
        List<IndItemRespVO> list = indItemService.getList(reqVO);
        return success(list);
    }
}