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