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