package com.iailab.module.data.channel.tag.controller.admin;
|
|
import com.iailab.module.data.channel.kio.entity.ChannelKioDeviceEntity;
|
import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity;
|
import com.iailab.module.data.common.enums.DataSourceType;
|
import com.iailab.framework.common.pojo.CommonResult;
|
import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService;
|
import com.iailab.module.data.channel.kio.service.ChannelKioTagService;
|
import com.iailab.module.data.channel.modbus.entity.ChannelModBusDeviceEntity;
|
import com.iailab.module.data.channel.modbus.entity.ChannelModBusTagEntity;
|
import com.iailab.module.data.channel.modbus.service.ChannelModbusDeviceService;
|
import com.iailab.module.data.channel.modbus.service.ChannelModbusTagService;
|
import com.iailab.module.data.channel.opcua.entity.ChannelOPCUADeviceEntity;
|
import com.iailab.module.data.channel.opcua.service.ChannelOPCUADeviceService;
|
import com.iailab.module.data.channel.opcua.service.ChannelOPCUATagService;
|
import com.iailab.module.data.channel.tag.dto.TagOptionDTO;
|
import com.iailab.module.data.channel.http.entity.HttpApiEntity;
|
import com.iailab.module.data.channel.http.entity.HttpTagEntity;
|
import com.iailab.module.data.channel.http.service.HttpApiService;
|
import com.iailab.module.data.channel.opcua.entity.ChannelOPCUATagEntity;
|
import com.iailab.module.data.channel.http.service.HttpTagService;
|
import javax.annotation.Resource;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年05月16日
|
*/
|
@RestController
|
@RequestMapping("/data/channel/tag")
|
public class TagController {
|
|
@Resource
|
private ChannelOPCUADeviceService channelOPCUADeviceService;
|
|
@Resource
|
private ChannelOPCUATagService channelOPCUATagService;
|
|
@Resource
|
private ChannelModbusDeviceService channelModbusDeviceService;
|
|
@Resource
|
private ChannelModbusTagService channelModbusTagService;
|
|
@Resource
|
private ChannelKioDeviceService channelKioDeviceService;
|
|
@Resource
|
private ChannelKioTagService channelKioTagService;
|
|
@Resource
|
private HttpApiService httpApiService;
|
|
@Resource
|
private HttpTagService tagService;
|
|
|
@GetMapping("tree")
|
public CommonResult<List<TagOptionDTO>> tagTree() {
|
List<TagOptionDTO> result = new ArrayList<>();
|
|
TagOptionDTO opcuaData = new TagOptionDTO();
|
opcuaData.setValue(DataSourceType.OPCUA.getCode());
|
opcuaData.setLabel(DataSourceType.OPCUA.getDesc());
|
List<ChannelOPCUADeviceEntity> opcuaDeviceList = channelOPCUADeviceService.list(new HashMap<>());
|
List<TagOptionDTO> opcuaDeviceOp = new ArrayList<>();
|
if (!CollectionUtils.isEmpty(opcuaDeviceList)) {
|
opcuaDeviceList.forEach(item -> {
|
TagOptionDTO op1 = new TagOptionDTO();
|
op1.setValue(item.getId());
|
op1.setLabel(item.getServerName());
|
List<ChannelOPCUATagEntity> tags = channelOPCUATagService.getByDevice(item.getServerName());
|
List<TagOptionDTO> op2 = new ArrayList<>();
|
tags.forEach(item1 -> {
|
TagOptionDTO op3 = new TagOptionDTO();
|
op3.setValue(item1.getTagName());
|
op3.setLabel(item1.getTagName());
|
op2.add(op3);
|
});
|
op1.setChildren(op2);
|
opcuaDeviceOp.add(op1);
|
});
|
}
|
opcuaData.setChildren(opcuaDeviceOp);
|
result.add(opcuaData);
|
|
TagOptionDTO modbusData = new TagOptionDTO();
|
modbusData.setValue(DataSourceType.ModBus.getCode());
|
modbusData.setLabel(DataSourceType.ModBus.getDesc());
|
List<ChannelModBusDeviceEntity> modbusList = channelModbusDeviceService.list(new HashMap<>());
|
List<TagOptionDTO> modbusDeviceOp = new ArrayList<>();
|
if (!CollectionUtils.isEmpty(modbusList)) {
|
modbusList.forEach(item -> {
|
TagOptionDTO op1 = new TagOptionDTO();
|
op1.setValue(item.getId());
|
op1.setLabel(item.getName());
|
List<ChannelModBusTagEntity> tags = channelModbusTagService.getByDevice(item.getName());
|
List<TagOptionDTO> op2 = new ArrayList<>();
|
tags.forEach(item1 -> {
|
TagOptionDTO op3 = new TagOptionDTO();
|
op3.setValue(item1.getTagName());
|
op3.setLabel(item1.getTagName());
|
op2.add(op3);
|
});
|
op1.setChildren(op2);
|
modbusDeviceOp.add(op1);
|
});
|
}
|
modbusData.setChildren(modbusDeviceOp);
|
result.add(modbusData);
|
|
|
TagOptionDTO kioData = new TagOptionDTO();
|
kioData.setValue(DataSourceType.KIO.getCode());
|
kioData.setLabel(DataSourceType.KIO.getDesc());
|
List<ChannelKioDeviceEntity> kioList = channelKioDeviceService.list(new HashMap<>());
|
List<TagOptionDTO> kioDeviceOp = new ArrayList<>();
|
if (!CollectionUtils.isEmpty(kioList)) {
|
kioList.forEach(item -> {
|
TagOptionDTO op1 = new TagOptionDTO();
|
op1.setValue(item.getId());
|
op1.setLabel(item.getInstanceName());
|
List<ChannelKioTagEntity> tags = channelKioTagService.getByDevice(item.getInstanceName());
|
List<TagOptionDTO> op2 = new ArrayList<>();
|
tags.forEach(item1 -> {
|
TagOptionDTO op3 = new TagOptionDTO();
|
op3.setValue(item1.getTagName());
|
op3.setLabel(item1.getTagName());
|
op2.add(op3);
|
});
|
op1.setChildren(op2);
|
kioDeviceOp.add(op1);
|
});
|
}
|
kioData.setChildren(kioDeviceOp);
|
result.add(kioData);
|
|
TagOptionDTO httpApiData = new TagOptionDTO();
|
httpApiData.setValue(DataSourceType.HTTP.getCode());
|
httpApiData.setLabel(DataSourceType.HTTP.getDesc());
|
List<HttpApiEntity> httpApiList = httpApiService.list();
|
List<TagOptionDTO> httpApiOp = new ArrayList<>();
|
if (!CollectionUtils.isEmpty(httpApiList)) {
|
httpApiList.forEach(item -> {
|
TagOptionDTO op1 = new TagOptionDTO();
|
op1.setValue(item.getId());
|
op1.setLabel(item.getName());
|
List<HttpTagEntity> tags = tagService.getApiId(item.getId());
|
List<TagOptionDTO> op2 = new ArrayList<>();
|
tags.forEach(item1 -> {
|
TagOptionDTO op3 = new TagOptionDTO();
|
op3.setValue(item1.getTagName());
|
op3.setLabel(item1.getTagName());
|
op2.add(op3);
|
});
|
op1.setChildren(op2);
|
httpApiOp.add(op1);
|
});
|
}
|
httpApiData.setChildren(httpApiOp);
|
result.add(httpApiData);
|
|
return new CommonResult().setData(result);
|
}
|
}
|