|
|
|
@ -11,6 +11,9 @@ import java.util.Set; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.inspect.agg.entity.AggBasedataArea; |
|
|
|
import com.inspect.agg.entity.AggBasedataEqpbook; |
|
|
|
import com.inspect.agg.entity.AggBasedataEqpbookChannel; |
|
|
|
@ -19,10 +22,12 @@ import com.inspect.agg.mapper.AggBasedataEqpbookChannelMapper; |
|
|
|
import com.inspect.agg.mapper.AggBasedataEqpbookMapper; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
/** |
|
|
|
* 使用汇聚区域、台账和通道数据构建通道树。 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class EqpbookTreeService { |
|
|
|
@ -30,11 +35,13 @@ public class EqpbookTreeService { |
|
|
|
private final AggBasedataAreaMapper areaMapper; |
|
|
|
private final AggBasedataEqpbookMapper eqpbookMapper; |
|
|
|
private final AggBasedataEqpbookChannelMapper channelMapper; |
|
|
|
private final ObjectMapper objectMapper; |
|
|
|
|
|
|
|
public List<Map<String, Object>> buildFilterTree(String stationCode, |
|
|
|
String patrolDeviceName, |
|
|
|
String onlineStatus, |
|
|
|
String patrolDeviceTypeFlag) { |
|
|
|
String patrolDeviceTypeFlag, |
|
|
|
String deviceSource) { |
|
|
|
List<AggBasedataArea> areas = areaMapper.listForTree(stationCode); |
|
|
|
List<AggBasedataEqpbook> eqpbooks = eqpbookMapper.list(stationCode, 0); |
|
|
|
List<AggBasedataEqpbookChannel> channels = channelMapper.list(stationCode, 0); |
|
|
|
@ -46,6 +53,9 @@ public class EqpbookTreeService { |
|
|
|
|
|
|
|
Map<String, List<AggBasedataEqpbookChannel>> channelIndex = new HashMap<>(); |
|
|
|
for (AggBasedataEqpbookChannel channel : channels) { |
|
|
|
if (!matchesDeviceSource(channel, deviceSource)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
channelIndex.computeIfAbsent(eqpbookKey(channel.getStationCode(), channel.getEqpbookId()), |
|
|
|
key -> new ArrayList<>()).add(channel); |
|
|
|
} |
|
|
|
@ -81,9 +91,9 @@ public class EqpbookTreeService { |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Map<String, Object>> areaNodes = new LinkedHashMap<>(); |
|
|
|
for (String key : selectedAreaKeys) { |
|
|
|
AggBasedataArea area = areaIndex.get(key); |
|
|
|
if (area == null) continue; |
|
|
|
for (AggBasedataArea area : areas) { |
|
|
|
String key = areaKey(area.getStationCode(), area.getAreaId()); |
|
|
|
if (!selectedAreaKeys.contains(key)) continue; |
|
|
|
Map<String, Object> node = new LinkedHashMap<>(); |
|
|
|
node.put("id", key); |
|
|
|
String parentKey = area.getParentId() == null ? null : areaKey(area.getStationCode(), area.getParentId()); |
|
|
|
@ -147,6 +157,8 @@ public class EqpbookTreeService { |
|
|
|
channelNode.put("channelName", channel.getChannelName()); |
|
|
|
channelNode.put("channelFlag", "Yes"); |
|
|
|
channelNode.put("channelType", channel.getChannelType()); |
|
|
|
channelNode.put("deviceSource", channel.getDeviceSource()); |
|
|
|
channelNode.put("capabilities", parseCapabilities(channel.getCapabilities())); |
|
|
|
channelNode.put("host", channel.getHost()); |
|
|
|
channelNode.put("port", channel.getPort()); |
|
|
|
channelNode.put("stationCode", channel.getStationCode()); |
|
|
|
@ -171,6 +183,28 @@ public class EqpbookTreeService { |
|
|
|
return roots; |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, Object> parseCapabilities(String value) { |
|
|
|
if (!StringUtils.hasText(value)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
try { |
|
|
|
JsonNode node = objectMapper.readTree(value); |
|
|
|
if (node == null || !node.isObject()) { |
|
|
|
log.warn("通道 capabilities 不是 JSON 对象,已忽略: {}", abbrev(value)); |
|
|
|
return null; |
|
|
|
} |
|
|
|
return objectMapper.convertValue(node, new TypeReference<Map<String, Object>>() { |
|
|
|
}); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("通道 capabilities 解析失败,已忽略: {}", abbrev(value)); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static String abbrev(String value) { |
|
|
|
return value.length() <= 120 ? value : value.substring(0, 120); |
|
|
|
} |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
private static List<Map<String, Object>> children(Map<String, Object> node) { |
|
|
|
return (List<Map<String, Object>>) node.get("children"); |
|
|
|
@ -196,6 +230,19 @@ public class EqpbookTreeService { |
|
|
|
&& eqpbook.getPatrolDeviceName().contains(value)); |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean matchesDeviceSource(AggBasedataEqpbookChannel channel, String deviceSource) { |
|
|
|
if (!StringUtils.hasText(deviceSource)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
String expected = deviceSource.trim(); |
|
|
|
String value = channel.getDeviceSource(); |
|
|
|
String actual = value == null ? "" : value.trim(); |
|
|
|
if ("其他".equals(expected)) { |
|
|
|
return actual.isEmpty() || "其他".equals(actual); |
|
|
|
} |
|
|
|
return expected.equals(actual); |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean matchesType(AggBasedataEqpbook eqpbook, String flag) { |
|
|
|
if (!StringUtils.hasText(flag)) return true; |
|
|
|
String type = eqpbook.getDeviceType(); |
|
|
|
|