package com.iailab.module.data.channel.tag.controller; 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("/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> tagTree() { List result = new ArrayList<>(); TagOptionDTO opcuaData = new TagOptionDTO(); opcuaData.setValue(DataSourceType.OPCUA.getCode()); opcuaData.setLabel(DataSourceType.OPCUA.getDesc()); List opcuaDeviceList = channelOPCUADeviceService.list(new HashMap<>()); List opcuaDeviceOp = new ArrayList<>(); if (!CollectionUtils.isEmpty(opcuaDeviceList)) { opcuaDeviceList.forEach(item -> { TagOptionDTO op1 = new TagOptionDTO(); op1.setValue(item.getId()); op1.setLabel(item.getServerName()); List tags = channelOPCUATagService.getByDevice(item.getServerName()); List 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 modbusList = channelModbusDeviceService.list(new HashMap<>()); List modbusDeviceOp = new ArrayList<>(); if (!CollectionUtils.isEmpty(modbusList)) { modbusList.forEach(item -> { TagOptionDTO op1 = new TagOptionDTO(); op1.setValue(item.getId()); op1.setLabel(item.getName()); List tags = channelModbusTagService.getByDevice(item.getName()); List 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 kioList = channelKioDeviceService.list(new HashMap<>()); List kioDeviceOp = new ArrayList<>(); if (!CollectionUtils.isEmpty(kioList)) { kioList.forEach(item -> { TagOptionDTO op1 = new TagOptionDTO(); op1.setValue(item.getId()); op1.setLabel(item.getInstanceName()); List tags = channelKioTagService.getByDevice(item.getInstanceName()); List 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 httpApiList = httpApiService.list(); List httpApiOp = new ArrayList<>(); if (!CollectionUtils.isEmpty(httpApiList)) { httpApiList.forEach(item -> { TagOptionDTO op1 = new TagOptionDTO(); op1.setValue(item.getId()); op1.setLabel(item.getName()); List tags = tagService.getByCode(item.getCode()); List op2 = new ArrayList<>(); tags.forEach(item1 -> { TagOptionDTO op3 = new TagOptionDTO(); op3.setValue(item1.getTagCode()); op3.setLabel(item1.getTagCode()); op2.add(op3); }); op1.setChildren(op2); httpApiOp.add(op1); }); } httpApiData.setChildren(httpApiOp); result.add(httpApiData); return new CommonResult().setData(result); } }