Merge branch 'develop-business-css' of http://121.37.111.42:3000/ThbTech/JavaProjectRepo into develop-business-css

This commit is contained in:
limengnan 2026-01-21 13:40:08 +08:00
commit 47761dd242
3 changed files with 111 additions and 111 deletions

View File

@ -8,38 +8,38 @@ import java.util.Map;
@RequestMapping("/sim")
public class SimController {
private final ProjectRepository projectRepo;
private final EventRepository eventRepo;
private final InfluenceRepository influenceRepo;
private final SimService simService;
// private final ProjectRepository projectRepo;
// private final EventRepository eventRepo;
// private final InfluenceRepository influenceRepo;
// private final SimService simService;
public SimController(ProjectRepository projectRepo,
EventRepository eventRepo,
InfluenceRepository influenceRepo,
SimService simService) {
this.projectRepo = projectRepo;
this.eventRepo = eventRepo;
this.influenceRepo = influenceRepo;
this.simService = simService;
}
@PostMapping("/run")
public Map<String,Object> runSimulation(@RequestParam String projectId,
@RequestParam String scenarioId,
@RequestParam int steps) {
List<Map<String, String>> topoRows = projectRepo.loadTopo(projectId);
List<Map<String, Object>> attrChanges = eventRepo.loadAttrChanges(projectId, scenarioId);
List<Map<String, Object>> influenceRows = influenceRepo.loadInfluences(projectId);
List<SimUnit> units = SimBuilder.buildUnits(topoRows);
List<SimEvent> events = SimBuilder.buildEvents(attrChanges);
List<SimInfluenceNode> nodes = SimBuilder.buildInfluenceNodes(influenceRows);
SimContext ctx = simService.runSimulation(units, events, nodes, steps);
// 转换成推理接口 JSON
return InferenceConverter.toInferenceInput(ctx, units, projectId, scenarioId);
}
// public SimController(ProjectRepository projectRepo,
// EventRepository eventRepo,
// InfluenceRepository influenceRepo,
// SimService simService) {
// this.projectRepo = projectRepo;
// this.eventRepo = eventRepo;
// this.influenceRepo = influenceRepo;
// this.simService = simService;
// }
// @PostMapping("/run")
// public Map<String,Object> runSimulation(@RequestParam String projectId,
// @RequestParam String scenarioId,
// @RequestParam int steps) {
// List<Map<String, String>> topoRows = projectRepo.loadTopo(projectId);
// List<Map<String, Object>> attrChanges = eventRepo.loadAttrChanges(projectId, scenarioId);
// List<Map<String, Object>> influenceRows = influenceRepo.loadInfluences(projectId);
// List<SimUnit> units = SimBuilder.buildUnits(topoRows);
// List<SimEvent> events = SimBuilder.buildEvents(attrChanges);
// List<SimInfluenceNode> nodes = SimBuilder.buildInfluenceNodes(influenceRows);
// SimContext ctx = simService.runSimulation(units, events, nodes, steps);
// // 转换成推理接口 JSON
// return InferenceConverter.toInferenceInput(ctx, units, projectId, scenarioId);
// }
}

View File

@ -47,6 +47,6 @@ public interface ProjectService extends IService<Project> {
*/
java.util.Map<String, Object> runSimulation(String projectId, String scenarioId, java.util.Map<String, Object> params);
List<SimInfluenceNode> loadSimInfluenceNodes(String projectId);
// List<SimInfluenceNode> loadSimInfluenceNodes(String projectId);
}

View File

@ -1353,105 +1353,105 @@ public class ProjectServiceImpl
//加载项目的影响关系节点
/*拓扑 influence node 是一次性构建 *
*/
@Override
public List<SimInfluenceNode> loadSimInfluenceNodes(String projectId)
{
//1. 校验项目是否存在
Project project = this.getOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectId, projectId));
if (project == null || project.getTopology() == null) {
return List.of();
}
List<SimInfluenceNode> nodes = new ArrayList<>();
//2. 解析拓扑图提取节点
try {
JsonNode root = objectMapper.readTree(project.getTopology());
// @Override
// public List<SimInfluenceNode> loadSimInfluenceNodes(String projectId)
// {
// //1. 校验项目是否存在
// Project project = this.getOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectId, projectId));
// if (project == null || project.getTopology() == null) {
// return List.of();
// }
// List<SimInfluenceNode> nodes = new ArrayList<>();
// //2. 解析拓扑图提取节点
// try {
// JsonNode root = objectMapper.readTree(project.getTopology());
JsonNode devices = root.path("devices");
if (!devices.isArray()) return nodes;
// JsonNode devices = root.path("devices");
// if (!devices.isArray()) return nodes;
for (JsonNode deviceNode : devices) {
String deviceId = deviceNode.path("deviceId").asText();
// for (JsonNode deviceNode : devices) {
// String deviceId = deviceNode.path("deviceId").asText();
// ---------- device.properties ----------
buildInfluenceNodes(
"DEVICE",
deviceId,
deviceNode.path("properties"),
nodes
);
// // ---------- device.properties ----------
// buildInfluenceNodes(
// "DEVICE",
// deviceId,
// deviceNode.path("properties"),
// nodes
// );
// ---------- device.material ----------
JsonNode materialNode = deviceNode.path("material");
if (!materialNode.isMissingNode()) {
String materialId = materialNode.path("materialId").asText();
buildInfluenceNodes(
"MATERIAL",
materialId,
materialNode.path("properties"),
nodes
);
}
}
// // ---------- device.material ----------
// JsonNode materialNode = deviceNode.path("material");
// if (!materialNode.isMissingNode()) {
// String materialId = materialNode.path("materialId").asText();
// buildInfluenceNodes(
// "MATERIAL",
// materialId,
// materialNode.path("properties"),
// nodes
// );
// }
// }
} catch (Exception e) {
throw new IllegalStateException("Failed to parse topology JSON", e);
}
// } catch (Exception e) {
// throw new IllegalStateException("Failed to parse topology JSON", e);
// }
return nodes;
}
/*
* 核心构建方法
*/
private void buildInfluenceNodes(String entityType,
String entityId,
JsonNode propertiesNode,
List<SimInfluenceNode> result) {
if (!propertiesNode.isObject()) return;
propertiesNode.fields().forEachRemaining(entry -> {
String propertyName = entry.getKey();
JsonNode propNode = entry.getValue();
if (!"influence".equals(propNode.path("type").asText())) {
return;
}
SimInfluenceNode node = new SimInfluenceNode();
node.setTargetEntityType(entityType);
node.setTargetEntityId(entityId);
node.setTargetProperty(propertyName);
node.setBase(propNode.path("base").asDouble(0));
node.setBias(propNode.path("bias").asDouble(0));
// sources
List<SimInfluenceSource> sources = new ArrayList<>();
JsonNode srcArray = propNode.path("sources");
if (srcArray.isArray()) {
for (JsonNode src : srcArray) {
SimInfluenceSource s = new SimInfluenceSource();
s.setSourceEntityType(src.path("entityType").asText().toUpperCase());
s.setSourceEntityId(src.path("entityId").asText());
s.setSourceProperty(src.path("property").asText());
s.setCoefficient(src.path("coefficient").asDouble(1.0));
JsonNode delay = src.path("delay");
if (delay.path("enabled").asBoolean(false)) {
s.setDelay(delay.path("time").asInt(0));
} else {
s.setDelay(0);
}
sources.add(s);
}
}
node.setSources(sources);
result.add(node);
});
}
// return nodes;
// }
// /*
// * 核心构建方法
// */
// private void buildInfluenceNodes(String entityType,
// String entityId,
// JsonNode propertiesNode,
// List<SimInfluenceNode> result) {
// if (!propertiesNode.isObject()) return;
// propertiesNode.fields().forEachRemaining(entry -> {
// String propertyName = entry.getKey();
// JsonNode propNode = entry.getValue();
// if (!"influence".equals(propNode.path("type").asText())) {
// return;
// }
// SimInfluenceNode node = new SimInfluenceNode();
// node.setTargetEntityType(entityType);
// node.setTargetEntityId(entityId);
// node.setTargetProperty(propertyName);
// node.setBase(propNode.path("base").asDouble(0));
// node.setBias(propNode.path("bias").asDouble(0));
// // sources
// List<SimInfluenceSource> sources = new ArrayList<>();
// JsonNode srcArray = propNode.path("sources");
// if (srcArray.isArray()) {
// for (JsonNode src : srcArray) {
// SimInfluenceSource s = new SimInfluenceSource();
// s.setSourceEntityType(src.path("entityType").asText().toUpperCase());
// s.setSourceEntityId(src.path("entityId").asText());
// s.setSourceProperty(src.path("property").asText());
// s.setCoefficient(src.path("coefficient").asDouble(1.0));
// JsonNode delay = src.path("delay");
// if (delay.path("enabled").asBoolean(false)) {
// s.setDelay(delay.path("time").asInt(0));
// } else {
// s.setDelay(0);
// }
// sources.add(s);
// }
// }
// node.setSources(sources);
// result.add(node);
// });
// }
}