|
@@ -53,69 +53,61 @@ public class FhzgElectricalModelSectionServiceImpl extends ServiceImpl<FhzgElect
|
|
|
log.warn("配网电气模型JSON中缺少section_info");
|
|
log.warn("配网电气模型JSON中缺少section_info");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
FhzgElectricalModelSection section = parseSection(sectionJson);
|
|
FhzgElectricalModelSection section = parseSection(sectionJson);
|
|
|
this.save(section);
|
|
this.save(section);
|
|
|
-
|
|
|
|
|
String sectionId = section.getSectionId();
|
|
String sectionId = section.getSectionId();
|
|
|
log.info("配网电气模型断面保存成功, sectionId={}", sectionId);
|
|
log.info("配网电气模型断面保存成功, sectionId={}", sectionId);
|
|
|
-
|
|
|
|
|
// 2. 解析data_objects
|
|
// 2. 解析data_objects
|
|
|
JSONObject dataObjects = root.getJSONObject("data_objects");
|
|
JSONObject dataObjects = root.getJSONObject("data_objects");
|
|
|
if (dataObjects == null) {
|
|
if (dataObjects == null) {
|
|
|
log.warn("配网电气模型JSON中缺少data_objects");
|
|
log.warn("配网电气模型JSON中缺少data_objects");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 3. 保存节点
|
|
// 3. 保存节点
|
|
|
List<FhzgElectricalModelNode> nodes = parseNodes(dataObjects.getJSONArray("nodes"), sectionId);
|
|
List<FhzgElectricalModelNode> nodes = parseNodes(dataObjects.getJSONArray("nodes"), sectionId);
|
|
|
if (CollUtil.isNotEmpty(nodes)) {
|
|
if (CollUtil.isNotEmpty(nodes)) {
|
|
|
nodeService.saveBatch(nodes, 500);
|
|
nodeService.saveBatch(nodes, 500);
|
|
|
log.info("保存节点 {} 条", nodes.size());
|
|
log.info("保存节点 {} 条", nodes.size());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 4. 保存导线段
|
|
// 4. 保存导线段
|
|
|
List<FhzgElectricalModelConductor> conductors = parseConductors(dataObjects.getJSONArray("conductors"), sectionId);
|
|
List<FhzgElectricalModelConductor> conductors = parseConductors(dataObjects.getJSONArray("conductors"), sectionId);
|
|
|
if (CollUtil.isNotEmpty(conductors)) {
|
|
if (CollUtil.isNotEmpty(conductors)) {
|
|
|
conductorService.saveBatch(conductors, 500);
|
|
conductorService.saveBatch(conductors, 500);
|
|
|
log.info("保存导线段 {} 条", conductors.size());
|
|
log.info("保存导线段 {} 条", conductors.size());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 5. 保存配电变压器
|
|
// 5. 保存配电变压器
|
|
|
List<FhzgElectricalModelTransformer> transformers = parseTransformers(dataObjects.getJSONArray("transformers"), sectionId);
|
|
List<FhzgElectricalModelTransformer> transformers = parseTransformers(dataObjects.getJSONArray("transformers"), sectionId);
|
|
|
if (CollUtil.isNotEmpty(transformers)) {
|
|
if (CollUtil.isNotEmpty(transformers)) {
|
|
|
transformerService.saveBatch(transformers, 500);
|
|
transformerService.saveBatch(transformers, 500);
|
|
|
log.info("保存配电变压器 {} 条", transformers.size());
|
|
log.info("保存配电变压器 {} 条", transformers.size());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 6. 保存开关设备
|
|
// 6. 保存开关设备
|
|
|
List<FhzgElectricalModelSwitch> switches = parseSwitches(dataObjects.getJSONArray("switches"), sectionId);
|
|
List<FhzgElectricalModelSwitch> switches = parseSwitches(dataObjects.getJSONArray("switches"), sectionId);
|
|
|
if (CollUtil.isNotEmpty(switches)) {
|
|
if (CollUtil.isNotEmpty(switches)) {
|
|
|
switchService.saveBatch(switches, 500);
|
|
switchService.saveBatch(switches, 500);
|
|
|
log.info("保存开关设备 {} 条", switches.size());
|
|
log.info("保存开关设备 {} 条", switches.size());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 7. 保存注入设备
|
|
// 7. 保存注入设备
|
|
|
List<FhzgElectricalModelInjection> injections = parseInjections(dataObjects.getJSONArray("injection_devices"), sectionId);
|
|
List<FhzgElectricalModelInjection> injections = parseInjections(dataObjects.getJSONArray("injection_devices"), sectionId);
|
|
|
if (CollUtil.isNotEmpty(injections)) {
|
|
if (CollUtil.isNotEmpty(injections)) {
|
|
|
injectionService.saveBatch(injections, 500);
|
|
injectionService.saveBatch(injections, 500);
|
|
|
log.info("保存注入设备 {} 条", injections.size());
|
|
log.info("保存注入设备 {} 条", injections.size());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- log.info("配网电气模型数据保存完成, sectionId={}, 节点={}, 导线={}, 变压器={}, 开关={}, 注入={}",
|
|
|
|
|
- sectionId,
|
|
|
|
|
- CollUtil.size(nodes),
|
|
|
|
|
- CollUtil.size(conductors),
|
|
|
|
|
- CollUtil.size(transformers),
|
|
|
|
|
- CollUtil.size(switches),
|
|
|
|
|
- CollUtil.size(injections));
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// ==================== 手动映射方法 ====================
|
|
// ==================== 手动映射方法 ====================
|
|
|
|
|
|
|
|
private FhzgElectricalModelSection parseSection(JSONObject json) {
|
|
private FhzgElectricalModelSection parseSection(JSONObject json) {
|
|
|
FhzgElectricalModelSection s = new FhzgElectricalModelSection();
|
|
FhzgElectricalModelSection s = new FhzgElectricalModelSection();
|
|
|
s.setSectionId(json.getString("id")); // JSON id → entity sectionId
|
|
s.setSectionId(json.getString("id")); // JSON id → entity sectionId
|
|
|
|
|
+ s.setFeederId(json.getString("feeder_id"));
|
|
|
s.setName(json.getString("name"));
|
|
s.setName(json.getString("name"));
|
|
|
s.setBaseKv(json.getBigDecimal("base_kv"));
|
|
s.setBaseKv(json.getBigDecimal("base_kv"));
|
|
|
s.setBaseKva(json.getBigDecimal("base_kva"));
|
|
s.setBaseKva(json.getBigDecimal("base_kva"));
|
|
@@ -271,60 +263,4 @@ public class FhzgElectricalModelSectionServiceImpl extends ServiceImpl<FhzgElect
|
|
|
private Integer boolToInt(Boolean val) {
|
|
private Integer boolToInt(Boolean val) {
|
|
|
return val != null && val ? 1 : 0;
|
|
return val != null && val ? 1 : 0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // ==================== 本地测试入口 ====================
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 本地测试入口:读取JSON文件,解析并打印统计信息
|
|
|
|
|
- * 用法:直接运行main方法,修改JSON_PATH为你的文件路径
|
|
|
|
|
- */
|
|
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
|
|
- // ========== 修改这里为你的JSON文件路径 ==========
|
|
|
|
|
- String JSON_PATH = "C:/Users/lenovo/Documents/Downloads/standard_model_raw.json";
|
|
|
|
|
- // ================================================
|
|
|
|
|
-
|
|
|
|
|
- if (args.length > 0) {
|
|
|
|
|
- JSON_PATH = args[0];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- System.out.println("读取文件: " + JSON_PATH);
|
|
|
|
|
- String jsonStr = new String(Files.readAllBytes(Paths.get(JSON_PATH)));
|
|
|
|
|
- System.out.println("文件大小: " + jsonStr.length() + " 字符");
|
|
|
|
|
-
|
|
|
|
|
- JSONObject root = JSON.parseObject(jsonStr);
|
|
|
|
|
-
|
|
|
|
|
- // --- 使用与saveFromJson相同的解析逻辑 ---
|
|
|
|
|
- FhzgElectricalModelSectionServiceImpl service = new FhzgElectricalModelSectionServiceImpl();
|
|
|
|
|
-
|
|
|
|
|
- // 解析section_info
|
|
|
|
|
- JSONObject sectionJson = root.getJSONObject("section_info");
|
|
|
|
|
- FhzgElectricalModelSection section = service.parseSection(sectionJson);
|
|
|
|
|
- System.out.println("\n=== 断面信息 ===");
|
|
|
|
|
- System.out.println("sectionId: " + section.getSectionId());
|
|
|
|
|
- System.out.println("name: " + section.getName());
|
|
|
|
|
- System.out.println("baseKv: " + section.getBaseKv());
|
|
|
|
|
- System.out.println("baseKva: " + section.getBaseKva());
|
|
|
|
|
- System.out.println("time: " + section.getTime());
|
|
|
|
|
-
|
|
|
|
|
- // 解析data_objects
|
|
|
|
|
- JSONObject dataObjects = root.getJSONObject("data_objects");
|
|
|
|
|
- String sectionId = section.getSectionId();
|
|
|
|
|
-
|
|
|
|
|
- List<FhzgElectricalModelNode> nodes = service.parseNodes(dataObjects.getJSONArray("nodes"), sectionId);
|
|
|
|
|
- List<FhzgElectricalModelConductor> conductors = service.parseConductors(dataObjects.getJSONArray("conductors"), sectionId);
|
|
|
|
|
- List<FhzgElectricalModelTransformer> transformers = service.parseTransformers(dataObjects.getJSONArray("transformers"), sectionId);
|
|
|
|
|
- List<FhzgElectricalModelSwitch> switches = service.parseSwitches(dataObjects.getJSONArray("switches"), sectionId);
|
|
|
|
|
- List<FhzgElectricalModelInjection> injections = service.parseInjections(dataObjects.getJSONArray("injection_devices"), sectionId);
|
|
|
|
|
-
|
|
|
|
|
- System.out.println("\n=== 数据统计 ===");
|
|
|
|
|
- System.out.println("节点(nodes): " + nodes.size());
|
|
|
|
|
- System.out.println("导线段(conductors): " + conductors.size());
|
|
|
|
|
- System.out.println("配电变压器(transformers): " + transformers.size());
|
|
|
|
|
- System.out.println("开关设备(switches): " + switches.size());
|
|
|
|
|
- System.out.println("注入设备(injection_devices): " + injections.size());
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- System.out.println("\n解析完成,无异常。接入Spring后调用 saveFromJson(jsonStr) 即可入库。");
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|