提交 | 用户 | 时间
|
2070c0
|
1 |
package com.iailab.module.data.channel.tag.controller.admin; |
a6de49
|
2 |
|
aecc49
|
3 |
import com.iailab.module.data.channel.kio.entity.ChannelKioDeviceEntity; |
L |
4 |
import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity; |
a6de49
|
5 |
import com.iailab.module.data.common.enums.DataSourceType; |
H |
6 |
import com.iailab.framework.common.pojo.CommonResult; |
|
7 |
import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService; |
|
8 |
import com.iailab.module.data.channel.kio.service.ChannelKioTagService; |
|
9 |
import com.iailab.module.data.channel.modbus.entity.ChannelModBusDeviceEntity; |
|
10 |
import com.iailab.module.data.channel.modbus.entity.ChannelModBusTagEntity; |
|
11 |
import com.iailab.module.data.channel.modbus.service.ChannelModbusDeviceService; |
|
12 |
import com.iailab.module.data.channel.modbus.service.ChannelModbusTagService; |
|
13 |
import com.iailab.module.data.channel.opcua.entity.ChannelOPCUADeviceEntity; |
|
14 |
import com.iailab.module.data.channel.opcua.service.ChannelOPCUADeviceService; |
|
15 |
import com.iailab.module.data.channel.opcua.service.ChannelOPCUATagService; |
|
16 |
import com.iailab.module.data.channel.tag.dto.TagOptionDTO; |
c7f709
|
17 |
import com.iailab.module.data.channel.http.entity.HttpApiEntity; |
L |
18 |
import com.iailab.module.data.channel.http.entity.HttpTagEntity; |
|
19 |
import com.iailab.module.data.channel.http.service.HttpApiService; |
a6de49
|
20 |
import com.iailab.module.data.channel.opcua.entity.ChannelOPCUATagEntity; |
c7f709
|
21 |
import com.iailab.module.data.channel.http.service.HttpTagService; |
a6de49
|
22 |
import javax.annotation.Resource; |
H |
23 |
import org.springframework.util.CollectionUtils; |
|
24 |
import org.springframework.web.bind.annotation.GetMapping; |
|
25 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
26 |
import org.springframework.web.bind.annotation.RestController; |
|
27 |
|
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author PanZhibao |
|
34 |
* @Description |
|
35 |
* @createTime 2024年05月16日 |
|
36 |
*/ |
|
37 |
@RestController |
2070c0
|
38 |
@RequestMapping("/data/channel/tag") |
a6de49
|
39 |
public class TagController { |
H |
40 |
|
|
41 |
@Resource |
|
42 |
private ChannelOPCUADeviceService channelOPCUADeviceService; |
|
43 |
|
|
44 |
@Resource |
|
45 |
private ChannelOPCUATagService channelOPCUATagService; |
|
46 |
|
|
47 |
@Resource |
|
48 |
private ChannelModbusDeviceService channelModbusDeviceService; |
|
49 |
|
|
50 |
@Resource |
|
51 |
private ChannelModbusTagService channelModbusTagService; |
|
52 |
|
|
53 |
@Resource |
|
54 |
private ChannelKioDeviceService channelKioDeviceService; |
|
55 |
|
|
56 |
@Resource |
|
57 |
private ChannelKioTagService channelKioTagService; |
|
58 |
|
|
59 |
@Resource |
|
60 |
private HttpApiService httpApiService; |
|
61 |
|
|
62 |
@Resource |
|
63 |
private HttpTagService tagService; |
|
64 |
|
|
65 |
|
|
66 |
@GetMapping("tree") |
|
67 |
public CommonResult<List<TagOptionDTO>> tagTree() { |
|
68 |
List<TagOptionDTO> result = new ArrayList<>(); |
|
69 |
|
|
70 |
TagOptionDTO opcuaData = new TagOptionDTO(); |
|
71 |
opcuaData.setValue(DataSourceType.OPCUA.getCode()); |
|
72 |
opcuaData.setLabel(DataSourceType.OPCUA.getDesc()); |
|
73 |
List<ChannelOPCUADeviceEntity> opcuaDeviceList = channelOPCUADeviceService.list(new HashMap<>()); |
|
74 |
List<TagOptionDTO> opcuaDeviceOp = new ArrayList<>(); |
|
75 |
if (!CollectionUtils.isEmpty(opcuaDeviceList)) { |
|
76 |
opcuaDeviceList.forEach(item -> { |
|
77 |
TagOptionDTO op1 = new TagOptionDTO(); |
|
78 |
op1.setValue(item.getId()); |
|
79 |
op1.setLabel(item.getServerName()); |
|
80 |
List<ChannelOPCUATagEntity> tags = channelOPCUATagService.getByDevice(item.getServerName()); |
|
81 |
List<TagOptionDTO> op2 = new ArrayList<>(); |
|
82 |
tags.forEach(item1 -> { |
|
83 |
TagOptionDTO op3 = new TagOptionDTO(); |
|
84 |
op3.setValue(item1.getTagName()); |
|
85 |
op3.setLabel(item1.getTagName()); |
|
86 |
op2.add(op3); |
|
87 |
}); |
|
88 |
op1.setChildren(op2); |
|
89 |
opcuaDeviceOp.add(op1); |
|
90 |
}); |
|
91 |
} |
|
92 |
opcuaData.setChildren(opcuaDeviceOp); |
|
93 |
result.add(opcuaData); |
|
94 |
|
|
95 |
TagOptionDTO modbusData = new TagOptionDTO(); |
|
96 |
modbusData.setValue(DataSourceType.ModBus.getCode()); |
|
97 |
modbusData.setLabel(DataSourceType.ModBus.getDesc()); |
|
98 |
List<ChannelModBusDeviceEntity> modbusList = channelModbusDeviceService.list(new HashMap<>()); |
|
99 |
List<TagOptionDTO> modbusDeviceOp = new ArrayList<>(); |
|
100 |
if (!CollectionUtils.isEmpty(modbusList)) { |
|
101 |
modbusList.forEach(item -> { |
|
102 |
TagOptionDTO op1 = new TagOptionDTO(); |
|
103 |
op1.setValue(item.getId()); |
|
104 |
op1.setLabel(item.getName()); |
|
105 |
List<ChannelModBusTagEntity> tags = channelModbusTagService.getByDevice(item.getName()); |
|
106 |
List<TagOptionDTO> op2 = new ArrayList<>(); |
|
107 |
tags.forEach(item1 -> { |
|
108 |
TagOptionDTO op3 = new TagOptionDTO(); |
|
109 |
op3.setValue(item1.getTagName()); |
|
110 |
op3.setLabel(item1.getTagName()); |
|
111 |
op2.add(op3); |
|
112 |
}); |
|
113 |
op1.setChildren(op2); |
|
114 |
modbusDeviceOp.add(op1); |
|
115 |
}); |
|
116 |
} |
|
117 |
modbusData.setChildren(modbusDeviceOp); |
|
118 |
result.add(modbusData); |
|
119 |
|
|
120 |
|
|
121 |
TagOptionDTO kioData = new TagOptionDTO(); |
|
122 |
kioData.setValue(DataSourceType.KIO.getCode()); |
|
123 |
kioData.setLabel(DataSourceType.KIO.getDesc()); |
aecc49
|
124 |
List<ChannelKioDeviceEntity> kioList = channelKioDeviceService.list(new HashMap<>()); |
a6de49
|
125 |
List<TagOptionDTO> kioDeviceOp = new ArrayList<>(); |
H |
126 |
if (!CollectionUtils.isEmpty(kioList)) { |
|
127 |
kioList.forEach(item -> { |
|
128 |
TagOptionDTO op1 = new TagOptionDTO(); |
|
129 |
op1.setValue(item.getId()); |
|
130 |
op1.setLabel(item.getInstanceName()); |
aecc49
|
131 |
List<ChannelKioTagEntity> tags = channelKioTagService.getByDevice(item.getInstanceName()); |
a6de49
|
132 |
List<TagOptionDTO> op2 = new ArrayList<>(); |
H |
133 |
tags.forEach(item1 -> { |
|
134 |
TagOptionDTO op3 = new TagOptionDTO(); |
|
135 |
op3.setValue(item1.getTagName()); |
|
136 |
op3.setLabel(item1.getTagName()); |
|
137 |
op2.add(op3); |
|
138 |
}); |
|
139 |
op1.setChildren(op2); |
|
140 |
kioDeviceOp.add(op1); |
|
141 |
}); |
|
142 |
} |
|
143 |
kioData.setChildren(kioDeviceOp); |
|
144 |
result.add(kioData); |
|
145 |
|
|
146 |
TagOptionDTO httpApiData = new TagOptionDTO(); |
|
147 |
httpApiData.setValue(DataSourceType.HTTP.getCode()); |
|
148 |
httpApiData.setLabel(DataSourceType.HTTP.getDesc()); |
|
149 |
List<HttpApiEntity> httpApiList = httpApiService.list(); |
|
150 |
List<TagOptionDTO> httpApiOp = new ArrayList<>(); |
|
151 |
if (!CollectionUtils.isEmpty(httpApiList)) { |
|
152 |
httpApiList.forEach(item -> { |
|
153 |
TagOptionDTO op1 = new TagOptionDTO(); |
|
154 |
op1.setValue(item.getId()); |
|
155 |
op1.setLabel(item.getName()); |
86145e
|
156 |
List<HttpTagEntity> tags = tagService.getApiId(item.getId()); |
a6de49
|
157 |
List<TagOptionDTO> op2 = new ArrayList<>(); |
H |
158 |
tags.forEach(item1 -> { |
|
159 |
TagOptionDTO op3 = new TagOptionDTO(); |
336bd2
|
160 |
op3.setValue(item1.getTagName()); |
潘 |
161 |
op3.setLabel(item1.getTagName()); |
a6de49
|
162 |
op2.add(op3); |
H |
163 |
}); |
|
164 |
op1.setChildren(op2); |
|
165 |
httpApiOp.add(op1); |
|
166 |
}); |
|
167 |
} |
|
168 |
httpApiData.setChildren(httpApiOp); |
|
169 |
result.add(httpApiData); |
|
170 |
|
|
171 |
return new CommonResult().setData(result); |
|
172 |
} |
|
173 |
} |