Jay
2024-11-25 ee9f604388a3e77d3f4654e326f3976552e7f532
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.data.channel.kio.controller.admin;
H 2
03e8ac 3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
a6de49 4 import com.iailab.framework.common.pojo.CommonResult;
03e8ac 5 import com.iailab.framework.common.pojo.PageParam;
aecc49 6 import com.iailab.framework.common.pojo.PageResult;
L 7 import com.iailab.framework.common.util.object.BeanUtils;
03e8ac 8 import com.iailab.framework.common.util.object.ConvertUtils;
J 9 import com.iailab.framework.excel.core.util.ExcelUtils;
e8ad66 10 import com.iailab.module.data.channel.kio.collector.KingIOCollector;
aecc49 11 import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity;
a6de49 12 import com.iailab.module.data.channel.kio.service.ChannelKioTagService;
aecc49 13 import com.iailab.module.data.channel.kio.vo.KioTagPageReqVO;
L 14 import com.iailab.module.data.channel.kio.vo.KioTagRespVO;
03e8ac 15 import com.iailab.module.data.channel.tag.vo.TagExportExcelVO;
J 16 import com.iailab.module.data.channel.tag.vo.TagImportExcelVO;
17 import com.iailab.module.data.channel.tag.vo.TagImportRespVO;
2f03e2 18 import com.iailab.module.data.common.enums.DataQualityEnum;
f21253 19 import com.iailab.module.data.common.enums.IsEnableEnum;
a6de49 20 import io.swagger.v3.oas.annotations.Operation;
03e8ac 21 import io.swagger.v3.oas.annotations.Parameter;
J 22 import io.swagger.v3.oas.annotations.Parameters;
a477ef 23 import org.springframework.security.access.prepost.PreAuthorize;
03e8ac 24 import org.springframework.validation.annotation.Validated;
a6de49 25 import org.springframework.web.bind.annotation.*;
03e8ac 26 import org.springframework.web.multipart.MultipartFile;
a6de49 27
aecc49 28 import javax.annotation.Resource;
03e8ac 29 import javax.servlet.http.HttpServletResponse;
aecc49 30 import javax.validation.Valid;
03e8ac 31 import java.io.IOException;
J 32 import java.util.Collections;
aecc49 33 import java.util.Date;
03e8ac 34 import java.util.List;
a6de49 35 import java.util.UUID;
H 36
03e8ac 37 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
aecc49 38 import static com.iailab.framework.common.pojo.CommonResult.success;
L 39
a6de49 40 /**
c7f709 41
a6de49 42  */
H 43 @RestController
44 @RequestMapping("/data/channel/kio/tag")
45 public class ChannelKioTagController {
46     @Resource
47     private ChannelKioTagService channelKioTagService;
48
e8ad66 49     @Resource
D 50     private KingIOCollector kingIOCollector;
51
a6de49 52     /**
H 53      * 分页查询tag
54      * */
a477ef 55     @PreAuthorize("@ss.hasPermission('data:channel-kio:query')")
a6de49 56     @GetMapping("page")
aecc49 57     public CommonResult<PageResult<KioTagRespVO>> page(@Valid KioTagPageReqVO reqVO){
L 58         PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO);
2f03e2 59         PageResult<KioTagRespVO> pageResult = BeanUtils.toBean(page, KioTagRespVO.class);
60         pageResult.getList().forEach(item -> {
61             item.setDataValue(kingIOCollector.getTagValue(item.getDevice(), item.getTagName()));
62             item.setDataTime(new Date());
63             item.setDataQuality(DataQualityEnum.getEumByValue(item.getDataValue()).getDesc());
64         });
65         return success(pageResult);
a6de49 66     }
H 67
a477ef 68     @PreAuthorize("@ss.hasPermission('data:channel-kio:query')")
aecc49 69     @GetMapping("/info/{id}")
a6de49 70     @Operation(summary = "信息")
aecc49 71     public CommonResult<ChannelKioTagEntity> info(@PathVariable("id") String id) {
L 72         ChannelKioTagEntity info = channelKioTagService.info(id);
73         return success(info);
a6de49 74     }
H 75
a477ef 76     @PreAuthorize("@ss.hasPermission('data:channel-kio:create')")
77     @PostMapping("/create")
78     public CommonResult<Boolean> create(@RequestBody ChannelKioTagEntity channelKioTagEntity) {
aecc49 79         String id = UUID.randomUUID().toString();
L 80         channelKioTagEntity.setId(id);
81         channelKioTagEntity.setCreateTime(new Date());
82         channelKioTagService.add(channelKioTagEntity);
83         return success(true);
a6de49 84     }
H 85
a477ef 86     @PreAuthorize("@ss.hasPermission('data:channel-kio:update')")
aecc49 87     @PutMapping("/update")
L 88     public CommonResult<Boolean> update(@RequestBody ChannelKioTagEntity channelKioTagEntity) {
89         channelKioTagEntity.setUpdateTime(new Date());
90         channelKioTagService.update(channelKioTagEntity);
91         return success(true);
a6de49 92     }
H 93
a477ef 94     @PreAuthorize("@ss.hasPermission('data:channel-kio:delete')")
aecc49 95     @DeleteMapping("/delete")
L 96     public CommonResult<Boolean> delete(@RequestParam("id") String id) {
97         channelKioTagService.delete(id);
98         return success(true);
a6de49 99     }
H 100
03e8ac 101     @GetMapping("/export")
J 102     @Operation(summary = "导出modbus tag列表")
103     @PreAuthorize("@ss.hasPermission('data:channel-kio-tag:export')")
104     @ApiAccessLog(operateType = EXPORT)
105     public void exportPointList(@Validated KioTagPageReqVO reqVO, HttpServletResponse response) throws IOException {
106         reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
107         PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO);
108         List<TagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), TagExportExcelVO.class);
109         ExcelUtils.write(response, "tag列表.xls", "数据", TagExportExcelVO.class, list, true);
110     }
5b634f 111
03e8ac 112     @GetMapping("/get-import-template")
J 113     @Operation(summary = "获得tag导入模板")
114     public void importTemplate(HttpServletResponse response) throws IOException {
115         // 手动创建导出 demo
116         List<TagImportExcelVO> list = Collections.singletonList(
f21253 117                 TagImportExcelVO.builder().tagName("Tag名称").tagDesc("Tag描述").dataType("String").enabled(IsEnableEnum.ENABLE.getCode())
03e8ac 118                         .build()
J 119         );
120         // 输出
121         ExcelUtils.write(response, "tag导入模板.xls", "tag列表", TagImportExcelVO.class, list,true);
122     }
123
124     @PostMapping("/import")
125     @Operation(summary = "导入tag")
126     @Parameters({
127             @Parameter(name = "file", description = "Excel 文件", required = true),
128             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
129     })
130     @PreAuthorize("@ss.hasPermission('data:channel-kio-tag:import')")
131     public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
132                                                      @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport,
133                                                      @RequestParam("device") String device) throws Exception {
134         List<TagImportExcelVO> list = ExcelUtils.read(file, TagImportExcelVO.class);
135         return success(channelKioTagService.importKioTagList(list, updateSupport, device));
136     }
a6de49 137 }