Jay
2024-11-08 f21253fe4bdd742acf546472fddf99d2fa06fecb
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.data.channel.opcua.controller.admin;
H 2
03e8ac 3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
aecc49 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;
a6de49 10 import com.iailab.module.data.channel.opcua.entity.ChannelOPCUATagEntity;
H 11 import com.iailab.module.data.channel.opcua.service.ChannelOPCUATagService;
03e8ac 12 import com.iailab.module.data.channel.opcua.vo.OpcUaTagExportExcelVO;
J 13 import com.iailab.module.data.channel.opcua.vo.OpcUaTagImportExcelVO;
aecc49 14 import com.iailab.module.data.channel.opcua.vo.OpcUaTagPageReqVO;
L 15 import com.iailab.module.data.channel.opcua.vo.OpcUaTagRespVO;
03e8ac 16 import com.iailab.module.data.channel.tag.vo.TagImportRespVO;
f21253 17 import com.iailab.module.data.common.enums.IsEnableEnum;
03e8ac 18 import io.swagger.v3.oas.annotations.Operation;
J 19 import io.swagger.v3.oas.annotations.Parameter;
20 import io.swagger.v3.oas.annotations.Parameters;
a477ef 21 import org.springframework.security.access.prepost.PreAuthorize;
03e8ac 22 import org.springframework.validation.annotation.Validated;
a6de49 23 import org.springframework.web.bind.annotation.*;
03e8ac 24 import org.springframework.web.multipart.MultipartFile;
a6de49 25
aecc49 26 import javax.annotation.Resource;
03e8ac 27 import javax.servlet.http.HttpServletResponse;
aecc49 28 import javax.validation.Valid;
03e8ac 29 import java.io.IOException;
J 30 import java.util.Collections;
aecc49 31 import java.util.Date;
03e8ac 32 import java.util.List;
a6de49 33 import java.util.UUID;
aecc49 34
03e8ac 35 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
aecc49 36 import static com.iailab.framework.common.pojo.CommonResult.success;
a6de49 37
H 38 /**
39  * 操作opcua tag配置
aecc49 40  * @author lirm
L 41  * @Description
42  * @createTime 2024年08月26日
a6de49 43  */
H 44 @RestController
45 @RequestMapping("/data/channel/opcua/tag")
46 public class ChannelOPCUATagController {
47     @Resource
48     private ChannelOPCUATagService channelOpcuaTagService;
49
a477ef 50     @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')")
aecc49 51     @GetMapping("page")
L 52     public CommonResult<PageResult<OpcUaTagRespVO>> list(@Valid OpcUaTagPageReqVO reqVO) {
53         PageResult<ChannelOPCUATagEntity> page = channelOpcuaTagService.queryPage(reqVO);
54         return success(BeanUtils.toBean(page, OpcUaTagRespVO.class));
a6de49 55     }
aecc49 56
a477ef 57     @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')")
a6de49 58     @GetMapping("/info/{id}")
aecc49 59     public CommonResult<ChannelOPCUATagEntity> info(@PathVariable("id") String id) {
L 60         ChannelOPCUATagEntity info = channelOpcuaTagService.info(id);
61         return success(info);
a6de49 62     }
aecc49 63
a477ef 64     @PreAuthorize("@ss.hasPermission('data:channel-opcua:create')")
65     @PostMapping("/create")
66     public CommonResult<Boolean> create(@RequestBody ChannelOPCUATagEntity channelOPCUATagEntity) {
aecc49 67         String id = UUID.randomUUID().toString();
L 68         channelOPCUATagEntity.setId(id);
69         channelOPCUATagEntity.setCreateTime(new Date());
70         channelOpcuaTagService.add(channelOPCUATagEntity);
71         return success(true);
a6de49 72     }
H 73
a477ef 74     @PreAuthorize("@ss.hasPermission('data:channel-opcua:update')")
aecc49 75     @PutMapping("/update")
L 76     public CommonResult<Boolean> update(@RequestBody ChannelOPCUATagEntity channelOPCUATagEntity) {
77         channelOPCUATagEntity.setUpdateTime(new Date());
a6de49 78         channelOpcuaTagService.update(channelOPCUATagEntity);
aecc49 79         return success(true);
a6de49 80     }
H 81
a477ef 82     @PreAuthorize("@ss.hasPermission('data:channel-opcua:delete')")
aecc49 83     @DeleteMapping("/delete")
L 84     public CommonResult<Boolean> delete(@RequestParam("id") String id) {
a6de49 85         channelOpcuaTagService.delete(id);
aecc49 86         return success(true);
a6de49 87     }
H 88
03e8ac 89     @GetMapping("/export")
J 90     @Operation(summary = "导出modbus tag列表")
91     @PreAuthorize("@ss.hasPermission('data:channel-opcua-tag:export')")
92     @ApiAccessLog(operateType = EXPORT)
93     public void exportPointList(@Validated OpcUaTagPageReqVO reqVO, HttpServletResponse response) throws IOException {
94         reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
95         PageResult<ChannelOPCUATagEntity> page = channelOpcuaTagService.queryPage(reqVO);
96         List<OpcUaTagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), OpcUaTagExportExcelVO.class);
97         ExcelUtils.write(response, "tag列表.xls", "数据", OpcUaTagExportExcelVO.class, list, true);
98     }
99
100     @GetMapping("/get-import-template")
101     @Operation(summary = "获得tag导入模板")
102     public void importTemplate(HttpServletResponse response) throws IOException {
103         // 手动创建导出 demo
104         List<OpcUaTagImportExcelVO> list = Collections.singletonList(
f21253 105                 OpcUaTagImportExcelVO.builder().tagName("Tag名称").dataType("String").address("123").samplingRate(1000).enabled(IsEnableEnum.ENABLE.getCode())
03e8ac 106                         .build()
J 107         );
108         // 输出
109         ExcelUtils.write(response, "tag导入模板.xls", "tag列表", OpcUaTagImportExcelVO.class, list,true);
110     }
111
112     @PostMapping("/import")
113     @Operation(summary = "导入tag")
114     @Parameters({
115             @Parameter(name = "file", description = "Excel 文件", required = true),
116             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
117     })
118     @PreAuthorize("@ss.hasPermission('data:channel-opcua-tag:import')")
119     public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
120                                                      @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport,
121                                                      @RequestParam("device") String device) throws Exception {
122         List<OpcUaTagImportExcelVO> list = ExcelUtils.read(file, OpcUaTagImportExcelVO.class);
123         return success(channelOpcuaTagService.importOpcUaTagList(list, updateSupport,device));
124     }
a6de49 125 }