dengzedong
2024-11-06 db184afd0c5bf3359b44eb0251fa5b07386eb3ff
提交 | 用户 | 时间
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;
849c3b 8 import com.iailab.framework.common.util.object.ConvertUtils;
D 9 import com.iailab.framework.excel.core.util.ExcelUtils;
e8ad66 10 import com.iailab.module.data.channel.kio.collector.KingIOCollector;
03e8ac 11 import com.iailab.framework.common.util.object.ConvertUtils;
J 12 import com.iailab.framework.excel.core.util.ExcelUtils;
aecc49 13 import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity;
a6de49 14 import com.iailab.module.data.channel.kio.service.ChannelKioTagService;
aecc49 15 import com.iailab.module.data.channel.kio.vo.KioTagPageReqVO;
L 16 import com.iailab.module.data.channel.kio.vo.KioTagRespVO;
03e8ac 17 import com.iailab.module.data.channel.tag.vo.TagExportExcelVO;
J 18 import com.iailab.module.data.channel.tag.vo.TagImportExcelVO;
19 import com.iailab.module.data.channel.tag.vo.TagImportRespVO;
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;
e8ad66 34 import java.util.List;
a6de49 35 import java.util.UUID;
e8ad66 36 import java.util.stream.Collectors;
a6de49 37
03e8ac 38 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
aecc49 39 import static com.iailab.framework.common.pojo.CommonResult.success;
L 40
a6de49 41 /**
c7f709 42
a6de49 43  */
H 44 @RestController
45 @RequestMapping("/data/channel/kio/tag")
46 public class ChannelKioTagController {
47     @Resource
48     private ChannelKioTagService channelKioTagService;
49
e8ad66 50     @Resource
D 51     private KingIOCollector kingIOCollector;
52
a6de49 53     /**
H 54      * 分页查询tag
55      * */
a477ef 56     @PreAuthorize("@ss.hasPermission('data:channel-kio:query')")
a6de49 57     @GetMapping("page")
aecc49 58     public CommonResult<PageResult<KioTagRespVO>> page(@Valid KioTagPageReqVO reqVO){
e8ad66 59
aecc49 60         PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO);
e8ad66 61         PageResult<KioTagRespVO> pageResultVO = new PageResult<>();
D 62         pageResultVO.setTotal(page.getTotal());
63
64         List<KioTagRespVO> vos = page.getList().stream().map(entity -> {
65
66             KioTagRespVO vo = BeanUtils.toBean(entity,KioTagRespVO.class);
67             try {
68                 vo.setDataValue(Double.parseDouble(kingIOCollector.getTagValue(reqVO.getDeviceId(), entity.getTagName())));
69             }catch (Exception e){
70                 e.printStackTrace();
71             }
72             return vo;
73         }).collect(Collectors.toList());
74
75         pageResultVO.setList(vos);
76
77         return success(pageResultVO);
a6de49 78     }
H 79
a477ef 80     @PreAuthorize("@ss.hasPermission('data:channel-kio:query')")
aecc49 81     @GetMapping("/info/{id}")
a6de49 82     @Operation(summary = "信息")
aecc49 83     public CommonResult<ChannelKioTagEntity> info(@PathVariable("id") String id) {
L 84         ChannelKioTagEntity info = channelKioTagService.info(id);
85         return success(info);
a6de49 86     }
H 87
a477ef 88     @PreAuthorize("@ss.hasPermission('data:channel-kio:create')")
89     @PostMapping("/create")
90     public CommonResult<Boolean> create(@RequestBody ChannelKioTagEntity channelKioTagEntity) {
aecc49 91         String id = UUID.randomUUID().toString();
L 92         channelKioTagEntity.setId(id);
93         channelKioTagEntity.setCreateTime(new Date());
94         channelKioTagService.add(channelKioTagEntity);
95         return success(true);
a6de49 96     }
H 97
a477ef 98     @PreAuthorize("@ss.hasPermission('data:channel-kio:update')")
aecc49 99     @PutMapping("/update")
L 100     public CommonResult<Boolean> update(@RequestBody ChannelKioTagEntity channelKioTagEntity) {
101         channelKioTagEntity.setUpdateTime(new Date());
102         channelKioTagService.update(channelKioTagEntity);
103         return success(true);
a6de49 104     }
H 105
a477ef 106     @PreAuthorize("@ss.hasPermission('data:channel-kio:delete')")
aecc49 107     @DeleteMapping("/delete")
L 108     public CommonResult<Boolean> delete(@RequestParam("id") String id) {
109         channelKioTagService.delete(id);
110         return success(true);
a6de49 111     }
H 112
03e8ac 113     @GetMapping("/export")
J 114     @Operation(summary = "导出modbus tag列表")
115     @PreAuthorize("@ss.hasPermission('data:channel-kio-tag:export')")
116     @ApiAccessLog(operateType = EXPORT)
117     public void exportPointList(@Validated KioTagPageReqVO reqVO, HttpServletResponse response) throws IOException {
118         reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
119         PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO);
120         List<TagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), TagExportExcelVO.class);
121         ExcelUtils.write(response, "tag列表.xls", "数据", TagExportExcelVO.class, list, true);
122     }
5b634f 123
03e8ac 124     @GetMapping("/get-import-template")
J 125     @Operation(summary = "获得tag导入模板")
126     public void importTemplate(HttpServletResponse response) throws IOException {
127         // 手动创建导出 demo
128         List<TagImportExcelVO> list = Collections.singletonList(
129                 TagImportExcelVO.builder().tagName("Tag名称").tagDesc("Tag描述").dataType("String").enabled(1)
130                         .build()
131         );
132         // 输出
133         ExcelUtils.write(response, "tag导入模板.xls", "tag列表", TagImportExcelVO.class, list,true);
134     }
135
136     @PostMapping("/import")
137     @Operation(summary = "导入tag")
138     @Parameters({
139             @Parameter(name = "file", description = "Excel 文件", required = true),
140             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
141     })
142     @PreAuthorize("@ss.hasPermission('data:channel-kio-tag:import')")
143     public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
144                                                      @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport,
145                                                      @RequestParam("device") String device) throws Exception {
146         List<TagImportExcelVO> list = ExcelUtils.read(file, TagImportExcelVO.class);
147         return success(channelKioTagService.importKioTagList(list, updateSupport, device));
148     }
a6de49 149 }