Merge branch 'develop-business-css' of http://121.37.111.42:3000/ThbTech/JavaProjectRepo into develop-business-css
This commit is contained in:
commit
47761dd242
@ -8,38 +8,38 @@ import java.util.Map;
|
|||||||
@RequestMapping("/sim")
|
@RequestMapping("/sim")
|
||||||
public class SimController {
|
public class SimController {
|
||||||
|
|
||||||
private final ProjectRepository projectRepo;
|
// private final ProjectRepository projectRepo;
|
||||||
private final EventRepository eventRepo;
|
// private final EventRepository eventRepo;
|
||||||
private final InfluenceRepository influenceRepo;
|
// private final InfluenceRepository influenceRepo;
|
||||||
private final SimService simService;
|
// private final SimService simService;
|
||||||
|
|
||||||
public SimController(ProjectRepository projectRepo,
|
// public SimController(ProjectRepository projectRepo,
|
||||||
EventRepository eventRepo,
|
// EventRepository eventRepo,
|
||||||
InfluenceRepository influenceRepo,
|
// InfluenceRepository influenceRepo,
|
||||||
SimService simService) {
|
// SimService simService) {
|
||||||
this.projectRepo = projectRepo;
|
// this.projectRepo = projectRepo;
|
||||||
this.eventRepo = eventRepo;
|
// this.eventRepo = eventRepo;
|
||||||
this.influenceRepo = influenceRepo;
|
// this.influenceRepo = influenceRepo;
|
||||||
this.simService = simService;
|
// this.simService = simService;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@PostMapping("/run")
|
// @PostMapping("/run")
|
||||||
public Map<String,Object> runSimulation(@RequestParam String projectId,
|
// public Map<String,Object> runSimulation(@RequestParam String projectId,
|
||||||
@RequestParam String scenarioId,
|
// @RequestParam String scenarioId,
|
||||||
@RequestParam int steps) {
|
// @RequestParam int steps) {
|
||||||
|
|
||||||
List<Map<String, String>> topoRows = projectRepo.loadTopo(projectId);
|
// List<Map<String, String>> topoRows = projectRepo.loadTopo(projectId);
|
||||||
List<Map<String, Object>> attrChanges = eventRepo.loadAttrChanges(projectId, scenarioId);
|
// List<Map<String, Object>> attrChanges = eventRepo.loadAttrChanges(projectId, scenarioId);
|
||||||
List<Map<String, Object>> influenceRows = influenceRepo.loadInfluences(projectId);
|
// List<Map<String, Object>> influenceRows = influenceRepo.loadInfluences(projectId);
|
||||||
|
|
||||||
List<SimUnit> units = SimBuilder.buildUnits(topoRows);
|
// List<SimUnit> units = SimBuilder.buildUnits(topoRows);
|
||||||
List<SimEvent> events = SimBuilder.buildEvents(attrChanges);
|
// List<SimEvent> events = SimBuilder.buildEvents(attrChanges);
|
||||||
List<SimInfluenceNode> nodes = SimBuilder.buildInfluenceNodes(influenceRows);
|
// List<SimInfluenceNode> nodes = SimBuilder.buildInfluenceNodes(influenceRows);
|
||||||
|
|
||||||
SimContext ctx = simService.runSimulation(units, events, nodes, steps);
|
// SimContext ctx = simService.runSimulation(units, events, nodes, steps);
|
||||||
|
|
||||||
// 转换成推理接口 JSON
|
// // 转换成推理接口 JSON
|
||||||
return InferenceConverter.toInferenceInput(ctx, units, projectId, scenarioId);
|
// return InferenceConverter.toInferenceInput(ctx, units, projectId, scenarioId);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1353,105 +1353,105 @@ public class ProjectServiceImpl
|
|||||||
//加载项目的影响关系节点
|
//加载项目的影响关系节点
|
||||||
/*拓扑 → influence node 是一次性构建 *
|
/*拓扑 → influence node 是一次性构建 *
|
||||||
*/
|
*/
|
||||||
@Override
|
// @Override
|
||||||
public List<SimInfluenceNode> loadSimInfluenceNodes(String projectId)
|
// public List<SimInfluenceNode> loadSimInfluenceNodes(String projectId)
|
||||||
{
|
// {
|
||||||
//1. 校验项目是否存在
|
// //1. 校验项目是否存在
|
||||||
Project project = this.getOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectId, projectId));
|
// Project project = this.getOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectId, projectId));
|
||||||
if (project == null || project.getTopology() == null) {
|
// if (project == null || project.getTopology() == null) {
|
||||||
return List.of();
|
// return List.of();
|
||||||
}
|
// }
|
||||||
List<SimInfluenceNode> nodes = new ArrayList<>();
|
// List<SimInfluenceNode> nodes = new ArrayList<>();
|
||||||
//2. 解析拓扑图,提取节点
|
// //2. 解析拓扑图,提取节点
|
||||||
try {
|
// try {
|
||||||
JsonNode root = objectMapper.readTree(project.getTopology());
|
// JsonNode root = objectMapper.readTree(project.getTopology());
|
||||||
|
|
||||||
JsonNode devices = root.path("devices");
|
// JsonNode devices = root.path("devices");
|
||||||
if (!devices.isArray()) return nodes;
|
// if (!devices.isArray()) return nodes;
|
||||||
|
|
||||||
for (JsonNode deviceNode : devices) {
|
// for (JsonNode deviceNode : devices) {
|
||||||
String deviceId = deviceNode.path("deviceId").asText();
|
// String deviceId = deviceNode.path("deviceId").asText();
|
||||||
|
|
||||||
// ---------- device.properties ----------
|
// // ---------- device.properties ----------
|
||||||
buildInfluenceNodes(
|
// buildInfluenceNodes(
|
||||||
"DEVICE",
|
// "DEVICE",
|
||||||
deviceId,
|
// deviceId,
|
||||||
deviceNode.path("properties"),
|
// deviceNode.path("properties"),
|
||||||
nodes
|
// nodes
|
||||||
);
|
// );
|
||||||
|
|
||||||
// ---------- device.material ----------
|
// // ---------- device.material ----------
|
||||||
JsonNode materialNode = deviceNode.path("material");
|
// JsonNode materialNode = deviceNode.path("material");
|
||||||
if (!materialNode.isMissingNode()) {
|
// if (!materialNode.isMissingNode()) {
|
||||||
String materialId = materialNode.path("materialId").asText();
|
// String materialId = materialNode.path("materialId").asText();
|
||||||
buildInfluenceNodes(
|
// buildInfluenceNodes(
|
||||||
"MATERIAL",
|
// "MATERIAL",
|
||||||
materialId,
|
// materialId,
|
||||||
materialNode.path("properties"),
|
// materialNode.path("properties"),
|
||||||
nodes
|
// nodes
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new IllegalStateException("Failed to parse topology JSON", e);
|
// throw new IllegalStateException("Failed to parse topology JSON", e);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return nodes;
|
// return nodes;
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*
|
// /*
|
||||||
* 核心构建方法
|
// * 核心构建方法
|
||||||
*/
|
// */
|
||||||
private void buildInfluenceNodes(String entityType,
|
// private void buildInfluenceNodes(String entityType,
|
||||||
String entityId,
|
// String entityId,
|
||||||
JsonNode propertiesNode,
|
// JsonNode propertiesNode,
|
||||||
List<SimInfluenceNode> result) {
|
// List<SimInfluenceNode> result) {
|
||||||
|
|
||||||
if (!propertiesNode.isObject()) return;
|
// if (!propertiesNode.isObject()) return;
|
||||||
|
|
||||||
propertiesNode.fields().forEachRemaining(entry -> {
|
// propertiesNode.fields().forEachRemaining(entry -> {
|
||||||
String propertyName = entry.getKey();
|
// String propertyName = entry.getKey();
|
||||||
JsonNode propNode = entry.getValue();
|
// JsonNode propNode = entry.getValue();
|
||||||
|
|
||||||
if (!"influence".equals(propNode.path("type").asText())) {
|
// if (!"influence".equals(propNode.path("type").asText())) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
SimInfluenceNode node = new SimInfluenceNode();
|
// SimInfluenceNode node = new SimInfluenceNode();
|
||||||
node.setTargetEntityType(entityType);
|
// node.setTargetEntityType(entityType);
|
||||||
node.setTargetEntityId(entityId);
|
// node.setTargetEntityId(entityId);
|
||||||
node.setTargetProperty(propertyName);
|
// node.setTargetProperty(propertyName);
|
||||||
node.setBase(propNode.path("base").asDouble(0));
|
// node.setBase(propNode.path("base").asDouble(0));
|
||||||
node.setBias(propNode.path("bias").asDouble(0));
|
// node.setBias(propNode.path("bias").asDouble(0));
|
||||||
|
|
||||||
// sources
|
// // sources
|
||||||
List<SimInfluenceSource> sources = new ArrayList<>();
|
// List<SimInfluenceSource> sources = new ArrayList<>();
|
||||||
JsonNode srcArray = propNode.path("sources");
|
// JsonNode srcArray = propNode.path("sources");
|
||||||
if (srcArray.isArray()) {
|
// if (srcArray.isArray()) {
|
||||||
for (JsonNode src : srcArray) {
|
// for (JsonNode src : srcArray) {
|
||||||
SimInfluenceSource s = new SimInfluenceSource();
|
// SimInfluenceSource s = new SimInfluenceSource();
|
||||||
s.setSourceEntityType(src.path("entityType").asText().toUpperCase());
|
// s.setSourceEntityType(src.path("entityType").asText().toUpperCase());
|
||||||
s.setSourceEntityId(src.path("entityId").asText());
|
// s.setSourceEntityId(src.path("entityId").asText());
|
||||||
s.setSourceProperty(src.path("property").asText());
|
// s.setSourceProperty(src.path("property").asText());
|
||||||
s.setCoefficient(src.path("coefficient").asDouble(1.0));
|
// s.setCoefficient(src.path("coefficient").asDouble(1.0));
|
||||||
|
|
||||||
JsonNode delay = src.path("delay");
|
// JsonNode delay = src.path("delay");
|
||||||
if (delay.path("enabled").asBoolean(false)) {
|
// if (delay.path("enabled").asBoolean(false)) {
|
||||||
s.setDelay(delay.path("time").asInt(0));
|
// s.setDelay(delay.path("time").asInt(0));
|
||||||
} else {
|
// } else {
|
||||||
s.setDelay(0);
|
// s.setDelay(0);
|
||||||
}
|
// }
|
||||||
|
|
||||||
sources.add(s);
|
// sources.add(s);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
node.setSources(sources);
|
// node.setSources(sources);
|
||||||
result.add(node);
|
// result.add(node);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user