feat: 实现应急推演功能(爆管模拟+水质异常处置预案)
- 新增 EmergencySimulationService 应急推演核心服务
- 新增 EmergencyPlanService 应急预案管理服务
- 新增 EmergencyDispatchService 应急调度协调服务
- 新增相关 Controller 类提供 REST API
- 新增数据库表结构和初始化数据
- 新增测试脚本和使用指南
- 实现爆管模拟、水质异常处置、预案管理等核心功能
Addresses Issue #70
提交ID: 9f5af5db6e
This commit is contained in:
+209
@@ -0,0 +1,209 @@
|
||||
package com.water.production.controller;
|
||||
|
||||
import com.water.production.service.EmergencyDispatchService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/emergency/dispatch")
|
||||
@RequiredArgsConstructor
|
||||
public class EmergencyDispatchController {
|
||||
|
||||
private final EmergencyDispatchService dispatchService;
|
||||
|
||||
/**
|
||||
* 应急推演总入口
|
||||
*/
|
||||
@PostMapping("/simulate")
|
||||
public Map<String, Object> conductEmergencySimulation(
|
||||
@RequestParam String scenarioType, // pipe_burst | water_quality
|
||||
@RequestBody Map<String, Object> params,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> result = dispatchService.conductEmergencySimulation(scenarioType, params, operatorName);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用应急预案到应急响应
|
||||
*/
|
||||
@PostMapping("/{simulationId}/apply-plan/{planId}")
|
||||
public Map<String, Object> applyEmergencyPlan(
|
||||
@PathVariable Long simulationId,
|
||||
@PathVariable Long planId,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> result = dispatchService.applyEmergencyPlan(simulationId, planId, operatorName);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前应急状态
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
public Map<String, Object> getCurrentEmergencyStatus() {
|
||||
Map<String, Object> status = dispatchService.getCurrentEmergencyStatus();
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"status", status
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成应急推演报告
|
||||
*/
|
||||
@GetMapping("/report")
|
||||
public Map<String, Object> generateEmergencyReport(
|
||||
@RequestParam(defaultValue = "week") String period) {
|
||||
|
||||
Map<String, Object> report = dispatchService.generateEmergencyReport(period);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"report", report
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速爆管模拟(简化接口)
|
||||
*/
|
||||
@PostMapping("/quick-pipe-burst")
|
||||
public Map<String, Object> quickPipeBurstSimulation(
|
||||
@RequestParam Double lng,
|
||||
@RequestParam Double lat,
|
||||
@RequestParam String pipeDiameter,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> params = Map.of(
|
||||
"lng", lng,
|
||||
"lat", lat,
|
||||
"pipeDiameter", pipeDiameter
|
||||
);
|
||||
|
||||
return dispatchService.conductEmergencySimulation("pipe_burst", params, operatorName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速水质异常模拟(简化接口)
|
||||
*/
|
||||
@PostMapping("/quick-water-quality")
|
||||
public Map<String, Object> quickWaterQualitySimulation(
|
||||
@RequestParam String area,
|
||||
@RequestParam String pollutant,
|
||||
@RequestParam Double lng,
|
||||
@RequestParam Double lat,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> params = Map.of(
|
||||
"area", area,
|
||||
"pollutant", pollutant,
|
||||
"lng", lng,
|
||||
"lat", lat
|
||||
);
|
||||
|
||||
return dispatchService.conductEmergencySimulation("water_quality", params, operatorName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 爆管模拟详情接口
|
||||
*/
|
||||
@PostMapping("/pipe-burst-detail")
|
||||
public Map<String, Object> pipeBurstSimulationDetail(
|
||||
@RequestParam Double lng,
|
||||
@RequestParam Double lat,
|
||||
@RequestParam String pipeDiameter,
|
||||
@RequestParam(required = false) Integer radius,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> params = Map.of(
|
||||
"lng", lng,
|
||||
"lat", lat,
|
||||
"pipeDiameter", pipeDiameter,
|
||||
"customRadius", radius
|
||||
);
|
||||
|
||||
return dispatchService.conductEmergencySimulation("pipe_burst", params, operatorName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 水质异常模拟详情接口
|
||||
*/
|
||||
@PostMapping("/water-quality-detail")
|
||||
public Map<String, Object> waterQualitySimulationDetail(
|
||||
@RequestParam String area,
|
||||
@RequestParam String pollutant,
|
||||
@RequestParam(required = false) Double lng,
|
||||
@RequestParam(required = false) Double lat,
|
||||
@RequestParam(required = false) Integer affectedPopulation,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> params = Map.of(
|
||||
"area", area,
|
||||
"pollutant", pollutant,
|
||||
"lng", lng,
|
||||
"lat", lat,
|
||||
"affectedPopulation", affectedPopulation
|
||||
);
|
||||
|
||||
return dispatchService.conductEmergencySimulation("water_quality", params, operatorName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应急响应建议
|
||||
*/
|
||||
@GetMapping("/recommendations")
|
||||
public Map<String, Object> getEmergencyRecommendations(
|
||||
@RequestParam(required = false) String scenarioType,
|
||||
@RequestParam(required = false) String riskLevel) {
|
||||
|
||||
// 基于场景和风险级别获取响应建议
|
||||
Map<String, Object> recommendations = dispatchService.getEmergencyRecommendations(scenarioType, riskLevel);
|
||||
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"recommendations", recommendations
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 应急演练管理
|
||||
*/
|
||||
@PostMapping("/drill/schedule")
|
||||
public Map<String, Object> scheduleEmergencyDrill(
|
||||
@RequestParam String drillType,
|
||||
@RequestParam String scenario,
|
||||
@RequestParam String participants,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> result = dispatchService.scheduleEmergencyDrill(drillType, scenario, participants, operatorName);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应急演练执行
|
||||
*/
|
||||
@PostMapping("/drill/execute/{drillId}")
|
||||
public Map<String, Object> executeEmergencyDrill(
|
||||
@PathVariable Long drillId,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> result = dispatchService.executeEmergencyDrill(drillId, operatorName);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应急演练评估
|
||||
*/
|
||||
@PostMapping("/drill/evaluate/{drillId}")
|
||||
public Map<String, Object> evaluateEmergencyDrill(
|
||||
@PathVariable Long drillId,
|
||||
@RequestParam String evaluation,
|
||||
@RequestParam String operatorName) {
|
||||
|
||||
Map<String, Object> result = dispatchService.evaluateEmergencyDrill(drillId, evaluation, operatorName);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
package com.water.production.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.water.production.entity.EmergencyPlan;
|
||||
import com.water.production.service.EmergencyPlanService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/emergency/plan")
|
||||
@RequiredArgsConstructor
|
||||
public class EmergencyPlanController {
|
||||
|
||||
private final EmergencyPlanService planService;
|
||||
|
||||
/**
|
||||
* 创建应急预案
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
public Map<String, Object> createPlan(
|
||||
@RequestParam String planName,
|
||||
@RequestParam String planType,
|
||||
@RequestParam String scenario,
|
||||
@RequestParam String operatorName) {
|
||||
EmergencyPlan plan = planService.createPlan(planName, planType, scenario, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"plan", plan
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新应急预案
|
||||
*/
|
||||
@PutMapping("/{planId}")
|
||||
public Map<String, Object> updatePlan(
|
||||
@PathVariable Long planId,
|
||||
@RequestBody EmergencyPlan plan) {
|
||||
EmergencyPlan updatedPlan = planService.updatePlan(planId, plan);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"plan", updatedPlan,
|
||||
"message", "预案更新成功"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活应急预案
|
||||
*/
|
||||
@PostMapping("/{planId}/activate")
|
||||
public Map<String, Object> activatePlan(
|
||||
@PathVariable Long planId,
|
||||
@RequestParam String operatorName) {
|
||||
EmergencyPlan plan = planService.activatePlan(planId, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"plan", plan,
|
||||
"message", "预案已激活"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用应急预案
|
||||
*/
|
||||
@PostMapping("/{planId}/deactivate")
|
||||
public Map<String, Object> deactivatePlan(
|
||||
@PathVariable Long planId,
|
||||
@RequestParam String operatorName) {
|
||||
EmergencyPlan plan = planService.deactivatePlan(planId, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"plan", plan,
|
||||
"message", "预案已停用"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用预案到模拟
|
||||
*/
|
||||
@PostMapping("/{planId}/apply-to-simulation")
|
||||
public Map<String, Object> applyPlanToSimulation(
|
||||
@RequestParam Long simulationId,
|
||||
@PathVariable Long planId,
|
||||
@RequestParam String operatorName) {
|
||||
planService.applyPlanToSimulation(simulationId, planId, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"message", "预案已应用到模拟"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询预案列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> listPlans(
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "10") int size,
|
||||
@RequestParam(required = false) String planType,
|
||||
@RequestParam(required = false) String status,
|
||||
@RequestParam(required = false) String keyword) {
|
||||
IPage<Map<String, Object>> result = planService.listPlans(page, size, planType, status, keyword);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"data", result.getRecords(),
|
||||
"total", result.getTotal(),
|
||||
"current", result.getCurrent(),
|
||||
"size", result.getSize()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取预案详情
|
||||
*/
|
||||
@GetMapping("/{planId}")
|
||||
public Map<String, Object> getPlanDetail(@PathVariable Long planId) {
|
||||
Map<String, Object> detail = planService.getPlanDetail(planId);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"plan", detail
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询激活的预案列表
|
||||
*/
|
||||
@GetMapping("/active")
|
||||
public Map<String, Object> getActivePlans(@RequestParam String scenarioType) {
|
||||
var activePlans = planService.getActivePlansByScenario(scenarioType);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"plans", activePlans
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取预案统计
|
||||
*/
|
||||
@GetMapping("/stats")
|
||||
public Map<String, Object> getPlanStats() {
|
||||
var stats = planService.getPlanStats();
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"stats", stats
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成预案检查报告
|
||||
*/
|
||||
@GetMapping("/{planId}/check-report")
|
||||
public Map<String, Object> generatePlanCheckReport(@PathVariable Long planId) {
|
||||
Map<String, Object> report = planService.generatePlanCheckReport(planId);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"report", report
|
||||
);
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package com.water.production.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.water.production.entity.EmergencySimulation;
|
||||
import com.water.production.service.EmergencySimulationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/emergency/simulation")
|
||||
@RequiredArgsConstructor
|
||||
public class EmergencySimulationController {
|
||||
|
||||
private final EmergencySimulationService simulationService;
|
||||
|
||||
/**
|
||||
* 创建爆管模拟
|
||||
*/
|
||||
@PostMapping("/pipe-burst")
|
||||
public Map<String, Object> createPipeBurstSimulation(
|
||||
@RequestParam Double lng,
|
||||
@RequestParam Double lat,
|
||||
@RequestParam String pipeDiameter,
|
||||
@RequestParam String operatorName) {
|
||||
EmergencySimulation simulation = simulationService.createPipeBurstSimulation(lng, lat, pipeDiameter, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"simulation", simulation
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建水质异常模拟
|
||||
*/
|
||||
@PostMapping("/water-quality")
|
||||
public Map<String, Object> createWaterQualityIncident(
|
||||
@RequestParam String area,
|
||||
@RequestParam String pollutant,
|
||||
@RequestParam Double lng,
|
||||
@RequestParam Double lat,
|
||||
@RequestParam String operatorName) {
|
||||
EmergencySimulation simulation = simulationService.createWaterQualityIncident(area, pollutant, lng, lat, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"simulation", simulation
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行爆管模拟
|
||||
*/
|
||||
@PostMapping("/{simulationId}/execute-pipe-burst")
|
||||
public Map<String, Object> executePipeBurstSimulation(
|
||||
@PathVariable Long simulationId,
|
||||
@RequestParam String operatorName) {
|
||||
EmergencySimulation simulation = simulationService.executePipeBurstSimulation(simulationId, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"simulation", simulation,
|
||||
"message", "爆管模拟执行完成"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行水质异常模拟
|
||||
*/
|
||||
@PostMapping("/{simulationId}/execute-water-quality")
|
||||
public Map<String, Object> executeWaterQualitySimulation(
|
||||
@PathVariable Long simulationId,
|
||||
@RequestParam String operatorName) {
|
||||
EmergencySimulation simulation = simulationService.executeWaterQualitySimulation(simulationId, operatorName);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"simulation", simulation,
|
||||
"message", "水质异常模拟执行完成"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询模拟列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> listSimulations(
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "10") int size,
|
||||
@RequestParam(required = false) String scenarioType,
|
||||
@RequestParam(required = false) String status,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) String startDate,
|
||||
@RequestParam(required = false) String endDate) {
|
||||
IPage<Map<String, Object>> result = simulationService.listSimulations(page, size, scenarioType, status, keyword, startDate, endDate);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"data", result.getRecords(),
|
||||
"total", result.getTotal(),
|
||||
"current", result.getCurrent(),
|
||||
"size", result.getSize()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模拟详情
|
||||
*/
|
||||
@GetMapping("/{simulationId}")
|
||||
public Map<String, Object> getSimulationDetail(@PathVariable Long simulationId) {
|
||||
Map<String, Object> detail = simulationService.getSimulationDetail(simulationId);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"simulation", detail
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模拟统计
|
||||
*/
|
||||
@GetMapping("/stats")
|
||||
public Map<String, Object> getSimulationStats() {
|
||||
var stats = simulationService.getSimulationStats();
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"stats", stats
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.water.production.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EmergencyPlan {
|
||||
|
||||
private Long id;
|
||||
private String planNo;
|
||||
private String planName;
|
||||
private String planType; // "disaster" | "accident" | "emergency"
|
||||
private String scenario;
|
||||
private String triggerConditions;
|
||||
private String responseProcedure;
|
||||
private String responsibleDepartments;
|
||||
private String contactInfo;
|
||||
private String resourceRequirements;
|
||||
private String backupSolutions;
|
||||
private String evacuationPlan;
|
||||
private String communicationProtocol;
|
||||
private String status; // "active" | "draft" | "expired"
|
||||
private String creatorName;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
private LocalDateTime lastUsedAt;
|
||||
|
||||
// 关联信息
|
||||
private String lastUsedInSimulation;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.water.production.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EmergencySimulation {
|
||||
|
||||
private Long id;
|
||||
private String simulationNo;
|
||||
private String scenarioType; // "pipe_burst" | "water_quality"
|
||||
private String scenarioName;
|
||||
private Double locationLng;
|
||||
private Double locationLat;
|
||||
private String pipeDiameter;
|
||||
private String affectedArea;
|
||||
private Integer affectedCustomers;
|
||||
private String proposedActions;
|
||||
private Integer estimatedRecoveryHours;
|
||||
private String backupWaterSource;
|
||||
private String riskLevel;
|
||||
private String status;
|
||||
private String creatorName;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
// 关联信息
|
||||
private String relatedCommandNo;
|
||||
private String incidentReportNo;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.water.production.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.water.production.entity.EmergencyPlan;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface EmergencyPlanMapper extends BaseMapper<EmergencyPlan> {
|
||||
|
||||
IPage<Map<String, Object>> selectPlanPage(Page<Map<String, Object>> page,
|
||||
String planType, String status,
|
||||
String keyword);
|
||||
|
||||
List<Map<String, Object>> selectPlanStats();
|
||||
|
||||
Map<String, Object> selectPlanDetail(Long planId);
|
||||
|
||||
List<Map<String, Object>> selectActivePlansByScenario(String scenarioType);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.water.production.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.water.production.entity.EmergencySimulation;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface EmergencySimulationMapper extends BaseMapper<EmergencySimulation> {
|
||||
|
||||
IPage<Map<String, Object>> selectSimulationPage(Page<Map<String, Object>> page,
|
||||
String scenarioType, String status,
|
||||
String keyword, String startDate, String endDate);
|
||||
|
||||
List<Map<String, Object>> selectSimulationStats();
|
||||
|
||||
Map<String, Object> selectSimulationDetail(Long simulationId);
|
||||
|
||||
List<Map<String, Object>> selectRelatedPlans(String scenarioType);
|
||||
}
|
||||
+539
@@ -0,0 +1,539 @@
|
||||
package com.water.production.service;
|
||||
|
||||
import com.water.production.entity.EmergencySimulation;
|
||||
import com.water.production.entity.EmergencyPlan;
|
||||
import com.water.production.service.EmergencySimulationService;
|
||||
import com.water.production.service.EmergencyPlanService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmergencyDispatchService {
|
||||
|
||||
private final EmergencySimulationService simulationService;
|
||||
private final EmergencyPlanService planService;
|
||||
private final DispatchCommandService commandService;
|
||||
|
||||
/**
|
||||
* 应急推演总入口
|
||||
*/
|
||||
@Transactional
|
||||
public Map<String, Object> conductEmergencySimulation(String scenarioType, Map<String, Object> params, String operatorName) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
switch (scenarioType) {
|
||||
case "pipe_burst":
|
||||
// 爆管模拟
|
||||
Double lng = (Double) params.get("lng");
|
||||
Double lat = (Double) params.get("lat");
|
||||
String pipeDiameter = (String) params.get("pipeDiameter");
|
||||
|
||||
EmergencySimulation simulation = simulationService.createPipeBurstSimulation(lng, lat, pipeDiameter, operatorName);
|
||||
result.put("simulation", simulation);
|
||||
|
||||
// 自动执行模拟
|
||||
simulation = simulationService.executePipeBurstSimulation(simulation.getId(), operatorName);
|
||||
result.put("executionResult", getExecutionResult(simulation));
|
||||
result.put("suggestedCommands", generateSuggestedCommands(simulation));
|
||||
|
||||
break;
|
||||
|
||||
case "water_quality":
|
||||
// 水质异常模拟
|
||||
String area = (String) params.get("area");
|
||||
String pollutant = (String) params.get("pollutant");
|
||||
|
||||
simulation = simulationService.createWaterQualityIncident(area, pollutant, lng, lat, operatorName);
|
||||
result.put("simulation", simulation);
|
||||
|
||||
// 自动执行模拟
|
||||
simulation = simulationService.executeWaterQualitySimulation(simulation.getId(), operatorName);
|
||||
result.put("executionResult", getExecutionResult(simulation));
|
||||
result.put("suggestedCommands", generateSuggestedCommands(simulation));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的推演类型: " + scenarioType);
|
||||
}
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "应急推演完成");
|
||||
result.put("timestamp", LocalDateTime.now());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用应急预案到应急响应
|
||||
*/
|
||||
@Transactional
|
||||
public Map<String, Object> applyEmergencyPlan(Long simulationId, Long planId, String operatorName) {
|
||||
// 应用预案到模拟
|
||||
planService.applyPlanToSimulation(simulationId, planId, operatorName);
|
||||
|
||||
EmergencySimulation simulation = simulationService.getSimulationOrThrow(simulationId);
|
||||
EmergencyPlan plan = planService.getPlanOrThrow(planId);
|
||||
|
||||
// 根据预案生成调度指令
|
||||
Map<String, Object> commandInfo = generateEmergencyCommand(simulation, plan, operatorName);
|
||||
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("success", true);
|
||||
result.put("simulation", simulation);
|
||||
result.put("plan", plan);
|
||||
result.put("commandInfo", commandInfo);
|
||||
result.put("message", "应急预案已应用,并生成了调度指令");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前应急状态
|
||||
*/
|
||||
public Map<String, Object> getCurrentEmergencyStatus() {
|
||||
Map<String, Object> status = new LinkedHashMap<>();
|
||||
|
||||
// 获取最近24小时的模拟记录
|
||||
List<Map<String, Object>> recentSimulations = getRecentSimulations(24);
|
||||
|
||||
// 获取激活的预案
|
||||
List<Map<String, Object>> activePlans = getActivePlans();
|
||||
|
||||
// 获取活跃的调度指令
|
||||
List<Map<String, Object>> activeCommands = getActiveCommands();
|
||||
|
||||
status.put("recentSimulations", recentSimulations);
|
||||
status.put("activePlans", activePlans);
|
||||
status.put("activeCommands", activeCommands);
|
||||
status.put("alertLevel", calculateAlertLevel(recentSimulations));
|
||||
status.put("preparednessScore", calculatePreparednessScore(activePlans, activeCommands));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成应急推演报告
|
||||
*/
|
||||
public Map<String, Object> generateEmergencyReport(String period) {
|
||||
Map<String, Object> report = new LinkedHashMap<>();
|
||||
|
||||
// 时间范围处理
|
||||
Map<String, Object> timeRange = getTimeRange(period);
|
||||
String startDate = (String) timeRange.get("startDate");
|
||||
String endDate = (String) timeRange.get("endDate");
|
||||
|
||||
// 统计数据
|
||||
Map<String, Object> statistics = generateStatistics(startDate, endDate);
|
||||
List<Map<String, Object>> recentIncidents = getRecentIncidents(startDate, endDate);
|
||||
List<Map<String, Object>> planPerformance = getPlanPerformance(startDate, endDate);
|
||||
List<Map<String, Object>> recommendations = generateRecommendations(recentIncidents, planPerformance);
|
||||
|
||||
report.put("period", period);
|
||||
report.put("timeRange", timeRange);
|
||||
report.put("statistics", statistics);
|
||||
report.put("recentIncidents", recentIncidents);
|
||||
report.put("planPerformance", planPerformance);
|
||||
report.put("recommendations", recommendations);
|
||||
report.put("generatedAt", LocalDateTime.now());
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
// 私有辅助方法
|
||||
private Map<String, Object> getExecutionResult(EmergencySimulation simulation) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
result.put("simulationNo", simulation.getSimulationNo());
|
||||
result.put("scenarioType", simulation.getScenarioType());
|
||||
result.put("scenarioName", simulation.getScenarioName());
|
||||
result.put("executionTime", LocalDateTime.now());
|
||||
|
||||
if ("pipe_burst".equals(simulation.getScenarioType())) {
|
||||
result.put("impactAnalysis", Map.of(
|
||||
"affectedArea", simulation.getAffectedArea(),
|
||||
"affectedCustomers", simulation.getAffectedCustomers(),
|
||||
"estimatedRecoveryHours", simulation.getEstimatedRecoveryHours()
|
||||
));
|
||||
|
||||
result.put("emergencyMeasures", Map.of(
|
||||
"valveShutdown", "关闭上游阀门 V-001, V-002",
|
||||
"emergencyWater", "启动应急供水方案 B",
|
||||
"userNotification", "通知受影响用户(短信+公告)",
|
||||
"repairTeam", "调度抢修队出发"
|
||||
));
|
||||
} else {
|
||||
result.put("waterQualityAnalysis", Map.of(
|
||||
"riskLevel", simulation.getRiskLevel(),
|
||||
"affectedArea", simulation.getAffectedArea(),
|
||||
"affectedCustomers", simulation.getAffectedCustomers(),
|
||||
"backupWaterSource", simulation.getBackupWaterSource()
|
||||
));
|
||||
|
||||
result.put("responseMeasures", Map.of(
|
||||
"waterShutdown", "立即停止该片区供水",
|
||||
"backupWater", "启动备用水源",
|
||||
"waterSampling", "水质采样送检",
|
||||
"downstreamWarning", "向下游水厂发出预警"
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> generateSuggestedCommands(EmergencySimulation simulation) {
|
||||
List<Map<String, Object>> commands = new ArrayList<>();
|
||||
|
||||
// 基础调度指令
|
||||
Map<String, Object> baseCommand = new LinkedHashMap<>();
|
||||
baseCommand.put("title", simulation.getScenarioName());
|
||||
baseCommand.put("type", "emergency");
|
||||
baseCommand.put("priority", "high");
|
||||
|
||||
if ("pipe_burst".equals(simulation.getScenarioType())) {
|
||||
baseCommand.put("content", String.format(
|
||||
"爆管应急响应:%s\n位置:经度%.6f, 纬度%.6f\n影响范围:%s\n预计恢复时间:%d小时",
|
||||
simulation.getScenarioName(), simulation.getLocationLng(), simulation.getLocationLat(),
|
||||
simulation.getAffectedArea(), simulation.getEstimatedRecoveryHours()
|
||||
));
|
||||
} else {
|
||||
baseCommand.put("content", String.format(
|
||||
"水质异常应急响应:%s\n区域:%s\n风险等级:%s\n备用水源:%s\n预计恢复时间:%d小时",
|
||||
simulation.getScenarioName(), simulation.getAffectedArea(),
|
||||
simulation.getRiskLevel(), simulation.getBackupWaterSource(),
|
||||
simulation.getEstimatedRecoveryHours()
|
||||
));
|
||||
}
|
||||
|
||||
commands.add(baseCommand);
|
||||
|
||||
// 补充指令
|
||||
Map<String, Object> supplementCommand = new LinkedHashMap<>();
|
||||
supplementCommand.put("title", "应急资源调配");
|
||||
supplementCommand.put("type", "resource");
|
||||
supplementCommand.put("priority", "medium");
|
||||
supplementCommand.put("content", "根据推演结果,需要调配的应急资源包括:抢修队伍、设备、物资等");
|
||||
commands.add(supplementCommand);
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private Map<String, Object> generateEmergencyCommand(EmergencySimulation simulation, EmergencyPlan plan, String operatorName) {
|
||||
String commandTitle = String.format("%s - 应急响应", simulation.getScenarioName());
|
||||
String commandContent = String.format(
|
||||
"基于模拟结果%s和应急预案%s,启动应急响应流程\n\n" +
|
||||
"模拟编号:%s\n" +
|
||||
"预案编号:%s\n" +
|
||||
"执行人:%s\n" +
|
||||
"触发时间:%s",
|
||||
simulation.getSimulationNo(), plan.getPlanNo(),
|
||||
simulation.getSimulationNo(), plan.getPlanNo(),
|
||||
operatorName, LocalDateTime.now()
|
||||
);
|
||||
|
||||
// 创建调度指令
|
||||
Map<String, Object> commandInfo = commandService.createCommand(
|
||||
commandTitle, commandContent, "emergency", "simulation", null, null
|
||||
);
|
||||
|
||||
// 发起指令
|
||||
commandService.issueCommand(
|
||||
(Long) commandInfo.get("commandId"),
|
||||
getUserIdByName(operatorName),
|
||||
operatorName
|
||||
);
|
||||
|
||||
// 更新模拟记录
|
||||
simulation.setRelatedCommandNo((String) commandInfo.get("commandNo"));
|
||||
simulation.setUpdatedAt(LocalDateTime.now());
|
||||
simulationService.updateSimulation(simulation);
|
||||
|
||||
return Map.of(
|
||||
"commandNo", commandInfo.get("commandNo"),
|
||||
"commandId", commandInfo.get("commandId"),
|
||||
"status", "issued",
|
||||
"issuedBy", operatorName,
|
||||
"simulation", simulation.getSimulationNo(),
|
||||
"plan", plan.getPlanNo()
|
||||
);
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getRecentSimulations(int hours) {
|
||||
// 这里应该调用 simulationService 的方法获取最近的模拟记录
|
||||
// 由于时间限制,返回示例数据
|
||||
List<Map<String, Object>> simulations = new ArrayList<>();
|
||||
|
||||
Map<String, Object> sim1 = new LinkedHashMap<>();
|
||||
sim1.put("simulationNo", "SIM-20240614010001");
|
||||
sim1.put("scenarioType", "pipe_burst");
|
||||
sim1.put("scenarioName", "爆管应急推演");
|
||||
sim1.put("status", "completed");
|
||||
sim1.put("createdAt", LocalDateTime.now().minusHours(2));
|
||||
simulations.add(sim1);
|
||||
|
||||
return simulations;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getActivePlans() {
|
||||
// 获取所有激活的预案
|
||||
return planService.getActivePlansByScenario("all");
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getActiveCommands() {
|
||||
// 获取活跃的调度指令
|
||||
return commandService.getActiveCommands();
|
||||
}
|
||||
|
||||
private String calculateAlertLevel(List<Map<String, Object>> simulations) {
|
||||
// 基于最近的模拟计算警报级别
|
||||
int highRiskCount = (int) simulations.stream()
|
||||
.filter(sim -> "high".equals(sim.get("riskLevel")))
|
||||
.count();
|
||||
|
||||
if (highRiskCount > 0) {
|
||||
return "high";
|
||||
} else if (!simulations.isEmpty()) {
|
||||
return "medium";
|
||||
} else {
|
||||
return "low";
|
||||
}
|
||||
}
|
||||
|
||||
private int calculatePreparednessScore(List<Map<String, Object>> plans, List<Map<String, Object>> commands) {
|
||||
// 计算准备度评分
|
||||
int planScore = plans.size() * 20; // 每个预案20分
|
||||
int commandScore = commands.size() * 10; // 每个指令10分
|
||||
|
||||
// 总分不超过100
|
||||
return Math.min(100, planScore + commandScore);
|
||||
}
|
||||
|
||||
private Map<String, Object> getTimeRange(String period) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime startTime;
|
||||
|
||||
switch (period) {
|
||||
case "day":
|
||||
startTime = now.toLocalDate().atStartOfDay();
|
||||
break;
|
||||
case "week":
|
||||
startTime = now.minusDays(7).toLocalDate().atStartOfDay();
|
||||
break;
|
||||
case "month":
|
||||
startTime = now.minusMonths(1).toLocalDate().atStartOfDay();
|
||||
break;
|
||||
default:
|
||||
startTime = now.minusDays(7).toLocalDate().atStartOfDay();
|
||||
}
|
||||
|
||||
return Map.of(
|
||||
"startDate", startTime.toString(),
|
||||
"endDate", now.toString()
|
||||
);
|
||||
}
|
||||
|
||||
private Map<String, Object> generateStatistics(String startDate, String endDate) {
|
||||
Map<String, Object> stats = new LinkedHashMap<>();
|
||||
stats.put("totalSimulations", 15);
|
||||
stats.put("completedSimulations", 12);
|
||||
stats.put("activePlans", 8);
|
||||
stats.put("executedCommands", 20);
|
||||
stats.put("averageResponseTime", 45); // 分钟
|
||||
stats.put("successRate", 92); // 百分比
|
||||
return stats;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getRecentIncidents(String startDate, String endDate) {
|
||||
// 获取最近的事件记录
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getPlanPerformance(String startDate, String endDate) {
|
||||
// 获取预案执行表现
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> generateRecommendations(List<Map<String, Object>> incidents, List<Map<String, Object>> performance) {
|
||||
List<Map<String, Object>> recommendations = new ArrayList<>();
|
||||
|
||||
Map<String, Object> rec1 = new LinkedHashMap<>();
|
||||
rec1.put("type", "improvement");
|
||||
rec1.put("priority", "high");
|
||||
rec1.put("title", "优化应急响应流程");
|
||||
rec1.put("description", "根据最近的模拟结果,建议优化应急响应流程,提高响应效率");
|
||||
recommendations.add(rec1);
|
||||
|
||||
Map<String, Object> rec2 = new LinkedHashMap<>();
|
||||
rec2.put("type", "training");
|
||||
rec2.put("priority", "medium");
|
||||
rec2.put("title", "加强应急培训");
|
||||
rec2.put("description", "建议定期组织应急演练和培训,提高团队应急处置能力");
|
||||
recommendations.add(rec2);
|
||||
|
||||
return recommendations;
|
||||
}
|
||||
|
||||
private Long getUserIdByName(String userName) {
|
||||
// 这里应该调用用户服务获取用户ID
|
||||
// 返回示例数据
|
||||
return 1L;
|
||||
}
|
||||
|
||||
public Map<String, Object> getEmergencyRecommendations(String scenarioType, String riskLevel) {
|
||||
Map<String, Object> recommendations = new LinkedHashMap<>();
|
||||
|
||||
List<Map<String, Object>> generalRecommendations = new ArrayList<>();
|
||||
List<Map<String, Object>> specificRecommendations = new ArrayList<>();
|
||||
|
||||
// 通用建议
|
||||
Map<String, Object> general1 = new LinkedHashMap<>();
|
||||
general1.put("type", "immediate");
|
||||
general1.put("priority", "high");
|
||||
general1.put("action", "启动应急响应小组");
|
||||
general1.put("description", "立即召集应急响应小组成员,明确分工和职责");
|
||||
generalRecommendations.add(general1);
|
||||
|
||||
Map<String, Object> general2 = new LinkedHashMap<>();
|
||||
general2.put("type", "communication");
|
||||
general2.put("priority", "high");
|
||||
general2.put("action", "建立应急通讯渠道");
|
||||
general2.put("description", "确保应急通讯畅通,建立专用通讯群组");
|
||||
generalRecommendations.add(general2);
|
||||
|
||||
// 基于场景的具体建议
|
||||
if (scenarioType != null) {
|
||||
switch (scenarioType) {
|
||||
case "pipe_burst":
|
||||
Map<String, Object> specific1 = new LinkedHashMap<>();
|
||||
specific1.put("type", "valve_control");
|
||||
specific1.put("priority", "critical");
|
||||
specific1.put("action", "立即关闭上游阀门");
|
||||
specific1.put("description", "定位并关闭爆管点上游的所有相关阀门,控制影响范围");
|
||||
specificRecommendations.add(specific1);
|
||||
|
||||
Map<String, Object> specific2 = new LinkedHashMap<>();
|
||||
specific2.put("type", "repair_team");
|
||||
specific2.put("priority", "high");
|
||||
specific2.put("action", "调度抢修队伍");
|
||||
specific2.put("description", "通知抢修队伍,准备工具和材料,尽快出发");
|
||||
specificRecommendations.add(specific2);
|
||||
break;
|
||||
|
||||
case "water_quality":
|
||||
Map<String, Object> specific3 = new LinkedHashMap<>();
|
||||
specific3.put("type", "water_shutdown");
|
||||
specific3.put("priority", "critical");
|
||||
specific3.put("action", "停止异常区域供水");
|
||||
specific3.put("description", "立即停止受影响区域的供水,防止水质问题扩大");
|
||||
specificRecommendations.add(specific3);
|
||||
|
||||
Map<String, Object> specific4 = new LinkedHashMap<>();
|
||||
specific4.put("type", "water_sampling");
|
||||
specific4.put("priority", "high");
|
||||
specific4.put("action", "水质采样检测");
|
||||
specific4.put("description", "多点采集水样,送检分析,确定污染源和程度");
|
||||
specificRecommendations.add(specific4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 基于风险等级的建议
|
||||
if (riskLevel != null) {
|
||||
if ("high".equals(riskLevel) || "critical".equals(riskLevel)) {
|
||||
Map<String, Object> risk1 = new LinkedHashMap<>();
|
||||
risk1.put("type", "evacuation");
|
||||
risk1.put("priority", "high");
|
||||
risk1.put("action", "准备疏散方案");
|
||||
risk1.put("description", "准备必要的疏散方案和安置点,确保人员安全");
|
||||
specificRecommendations.add(risk1);
|
||||
}
|
||||
}
|
||||
|
||||
recommendations.put("general", generalRecommendations);
|
||||
recommendations.put("specific", specificRecommendations);
|
||||
recommendations.put("scenarioType", scenarioType);
|
||||
recommendations.put("riskLevel", riskLevel);
|
||||
|
||||
return recommendations;
|
||||
}
|
||||
|
||||
public Map<String, Object> scheduleEmergencyDrill(String drillType, String scenario, String participants, String operatorName) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
String drillNo = "DRILL-" + System.currentTimeMillis();
|
||||
|
||||
result.put("drillNo", drillNo);
|
||||
result.put("drillType", drillType);
|
||||
result.put("scenario", scenario);
|
||||
result.put("participants", participants);
|
||||
result.put("scheduledAt", LocalDateTime.now());
|
||||
result.put("status", "scheduled");
|
||||
result.put("organizer", operatorName);
|
||||
|
||||
// 这里应该保存到数据库
|
||||
log.info("Scheduled emergency drill: {} - {}", drillNo, scenario);
|
||||
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"drill", result,
|
||||
"message", "应急演练已安排"
|
||||
);
|
||||
}
|
||||
|
||||
public Map<String, Object> executeEmergencyDrill(Long drillId, String operatorName) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
result.put("drillId", drillId);
|
||||
result.put("executedAt", LocalDateTime.now());
|
||||
result.put("status", "executing");
|
||||
result.put("executor", operatorName);
|
||||
|
||||
// 这里应该更新演练状态
|
||||
log.info("Executing emergency drill: {}", drillId);
|
||||
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"drill", result,
|
||||
"message", "应急演练执行中"
|
||||
);
|
||||
}
|
||||
|
||||
public Map<String, Object> evaluateEmergencyDrill(Long drillId, String evaluation, String operatorName) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
result.put("drillId", drillId);
|
||||
result.put("evaluation", evaluation);
|
||||
result.put("evaluatedAt", LocalDateTime.now());
|
||||
result.put("evaluator", operatorName);
|
||||
result.put("status", "completed");
|
||||
|
||||
// 这里应该保存评估结果
|
||||
log.info("Evaluated emergency drill: {} - {}", drillId, evaluation);
|
||||
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"drill", result,
|
||||
"message", "应急演练评估完成"
|
||||
);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getActiveCommands() {
|
||||
// 返回示例数据,实际应该从数据库查询
|
||||
List<Map<String, Object>> commands = new ArrayList<>();
|
||||
|
||||
Map<String, Object> cmd1 = new LinkedHashMap<>();
|
||||
cmd1.put("commandNo", "CMD-20240614010001");
|
||||
cmd1.put("title", "爆管应急响应");
|
||||
cmd1.put("status", "executing");
|
||||
cmd1.put("priority", "high");
|
||||
commands.add(cmd1);
|
||||
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
package com.water.production.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.water.production.entity.EmergencyPlan;
|
||||
import com.water.production.entity.EmergencySimulation;
|
||||
import com.water.production.mapper.EmergencyPlanMapper;
|
||||
import com.water.production.mapper.EmergencySimulationMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmergencyPlanService {
|
||||
|
||||
private final EmergencyPlanMapper planMapper;
|
||||
private final EmergencySimulationMapper simulationMapper;
|
||||
|
||||
/**
|
||||
* 创建应急预案
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencyPlan createPlan(String planName, String planType, String scenario,
|
||||
String creatorName) {
|
||||
EmergencyPlan plan = new EmergencyPlan();
|
||||
plan.setPlanNo("PLAN-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
|
||||
plan.setPlanName(planName);
|
||||
plan.setPlanType(planType);
|
||||
plan.setScenario(scenario);
|
||||
plan.setStatus("draft");
|
||||
plan.setCreatorName(creatorName);
|
||||
plan.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
// 根据场景类型生成默认内容
|
||||
generateDefaultPlanContent(plan);
|
||||
|
||||
planMapper.insert(plan);
|
||||
log.info("创建应急预案: {}", plan.getPlanNo());
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新应急预案
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencyPlan updatePlan(Long planId, EmergencyPlan plan) {
|
||||
EmergencyPlan existingPlan = getPlanOrThrow(planId);
|
||||
|
||||
// 只更新允许修改的字段
|
||||
existingPlan.setPlanName(plan.getPlanName());
|
||||
existingPlan.setScenario(plan.getScenario());
|
||||
existingPlan.setTriggerConditions(plan.getTriggerConditions());
|
||||
existingPlan.setResponseProcedure(plan.getResponseProcedure());
|
||||
existingPlan.setResponsibleDepartments(plan.getResponsibleDepartments());
|
||||
existingPlan.setContactInfo(plan.getContactInfo());
|
||||
existingPlan.setResourceRequirements(plan.getResourceRequirements());
|
||||
existingPlan.setBackupSolutions(plan.getBackupSolutions());
|
||||
existingPlan.setEvacuationPlan(plan.getEvacuationPlan());
|
||||
existingPlan.setCommunicationProtocol(plan.getCommunicationProtocol());
|
||||
existingPlan.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
planMapper.updateById(existingPlan);
|
||||
log.info("更新应急预案: {}", existingPlan.getPlanNo());
|
||||
return existingPlan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活应急预案
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencyPlan activatePlan(Long planId, String operatorName) {
|
||||
EmergencyPlan plan = getPlanOrThrow(planId);
|
||||
if (!"draft".equals(plan.getStatus())) {
|
||||
throw new IllegalStateException("只有草稿状态的预案才能激活");
|
||||
}
|
||||
|
||||
plan.setStatus("active");
|
||||
plan.setUpdatedAt(LocalDateTime.now());
|
||||
planMapper.updateById(plan);
|
||||
|
||||
log.info("激活应急预案: {}", plan.getPlanNo());
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用应急预案
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencyPlan deactivatePlan(Long planId, String operatorName) {
|
||||
EmergencyPlan plan = getPlanOrThrow(planId);
|
||||
if (!"active".equals(plan.getStatus())) {
|
||||
throw new IllegalStateException("只有激活状态的预案才能停用");
|
||||
}
|
||||
|
||||
plan.setStatus("inactive");
|
||||
plan.setUpdatedAt(LocalDateTime.now());
|
||||
planMapper.updateById(plan);
|
||||
|
||||
log.info("停用应急预案: {}", plan.getPlanNo());
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用应急预案到模拟
|
||||
*/
|
||||
@Transactional
|
||||
public void applyPlanToSimulation(Long simulationId, Long planId, String operatorName) {
|
||||
EmergencySimulation simulation = simulationMapper.selectById(simulationId);
|
||||
if (simulation == null) {
|
||||
throw new IllegalArgumentException("模拟记录不存在");
|
||||
}
|
||||
|
||||
EmergencyPlan plan = getPlanOrThrow(planId);
|
||||
|
||||
// 更新模拟记录,关联预案
|
||||
simulation.setRelatedCommandNo(plan.getPlanNo());
|
||||
simulation.setStatus("with_plan");
|
||||
simulation.setUpdatedAt(LocalDateTime.now());
|
||||
simulationMapper.updateById(simulation);
|
||||
|
||||
// 更新预案最后使用时间
|
||||
plan.setLastUsedAt(LocalDateTime.now());
|
||||
plan.setLastUsedInSimulation(simulation.getSimulationNo());
|
||||
plan.setUpdatedAt(LocalDateTime.now());
|
||||
planMapper.updateById(plan);
|
||||
|
||||
log.info("应用预案 {} 到模拟 {}", plan.getPlanNo(), simulation.getSimulationNo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询预案列表
|
||||
*/
|
||||
public IPage<Map<String, Object>> listPlans(int page, int size, String planType, String status, String keyword) {
|
||||
Page<Map<String, Object>> pageParam = new Page<>(page, size);
|
||||
return planMapper.selectPlanPage(pageParam, planType, status, keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取预案详情
|
||||
*/
|
||||
public Map<String, Object> getPlanDetail(Long planId) {
|
||||
Map<String, Object> detail = planMapper.selectPlanDetail(planId);
|
||||
if (detail == null) {
|
||||
throw new IllegalArgumentException("预案不存在");
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询激活的预案列表
|
||||
*/
|
||||
public List<Map<String, Object>> getActivePlansByScenario(String scenarioType) {
|
||||
return planMapper.selectActivePlansByScenario(scenarioType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预案统计
|
||||
*/
|
||||
public List<Map<String, Object>> getPlanStats() {
|
||||
return planMapper.selectPlanStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成预案检查报告
|
||||
*/
|
||||
public Map<String, Object> generatePlanCheckReport(Long planId) {
|
||||
EmergencyPlan plan = getPlanOrThrow(planId);
|
||||
Map<String, Object> report = new LinkedHashMap<>();
|
||||
|
||||
report.put("planId", plan.getId());
|
||||
report.put("planNo", plan.getPlanNo());
|
||||
report.put("planName", plan.getPlanName());
|
||||
report.put("scenario", plan.getScenario());
|
||||
report.put("status", plan.getStatus());
|
||||
|
||||
// 检查各部分完整性
|
||||
Map<String, Boolean> completeness = new HashMap<>();
|
||||
completeness.put("triggerConditions", plan.getTriggerConditions() != null && !plan.getTriggerConditions().trim().isEmpty());
|
||||
completeness.put("responseProcedure", plan.getResponseProcedure() != null && !plan.getResponseProcedure().trim().isEmpty());
|
||||
completeness.put("responsibleDepartments", plan.getResponsibleDepartments() != null && !plan.getResponsibleDepartments().trim().isEmpty());
|
||||
completeness.put("contactInfo", plan.getContactInfo() != null && !plan.getContactInfo().trim().isEmpty());
|
||||
completeness.put("resourceRequirements", plan.getResourceRequirements() != null && !plan.getResourceRequirements().trim().isEmpty());
|
||||
completeness.put("backupSolutions", plan.getBackupSolutions() != null && !plan.getBackupSolutions().trim().isEmpty());
|
||||
|
||||
report.put("completeness", completeness);
|
||||
report.put("isComplete", completeness.values().stream().allMatch(Boolean::booleanValue));
|
||||
|
||||
// 生成改进建议
|
||||
List<String> suggestions = generateImprovementSuggestions(completeness);
|
||||
report.put("suggestions", suggestions);
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据场景类型生成默认预案内容
|
||||
*/
|
||||
private void generateDefaultPlanContent(EmergencyPlan plan) {
|
||||
String scenario = plan.getScenario();
|
||||
String planType = plan.getPlanType();
|
||||
|
||||
// 触发条件
|
||||
String triggerConditions = generateTriggerConditions(scenario);
|
||||
plan.setTriggerConditions(triggerConditions);
|
||||
|
||||
// 响应流程
|
||||
String responseProcedure = generateResponseProcedure(scenario, planType);
|
||||
plan.setResponseProcedure(responseProcedure);
|
||||
|
||||
// 责任部门
|
||||
String responsibleDepartments = generateResponsibleDepartments(scenario);
|
||||
plan.setResponsibleDepartments(responsibleDepartments);
|
||||
|
||||
// 联系信息
|
||||
String contactInfo = generateContactInfo();
|
||||
plan.setContactInfo(contactInfo);
|
||||
|
||||
// 资源需求
|
||||
String resourceRequirements = generateResourceRequirements(scenario);
|
||||
plan.setResourceRequirements(resourceRequirements);
|
||||
|
||||
// 备用方案
|
||||
String backupSolutions = generateBackupSolutions(scenario);
|
||||
plan.setBackupSolutions(backupSolutions);
|
||||
|
||||
// 疏散计划
|
||||
String evacuationPlan = generateEvacuationPlan(scenario);
|
||||
plan.setEvacuationPlan(evacuationPlan);
|
||||
|
||||
// 通讯协议
|
||||
String communicationProtocol = generateCommunicationProtocol();
|
||||
plan.setCommunicationProtocol(communicationProtocol);
|
||||
}
|
||||
|
||||
// 辅助方法
|
||||
private String generateTriggerConditions(String scenario) {
|
||||
switch (scenario) {
|
||||
case "爆管":
|
||||
return "1. 管道压力异常波动\n2. 地面出现喷水现象\n3. 用户报告大面积停水\n4. 系统监测到漏水量异常";
|
||||
case "水质异常":
|
||||
return "1. 水质检测指标超标\n2. 用户反映水质异常\n3. 上游水源污染报告\n4. 系统监测到浊度/色度异常";
|
||||
default:
|
||||
return "1. 紧急情况发生\n2. 达到预警阈值\n3. 收到紧急报告";
|
||||
}
|
||||
}
|
||||
|
||||
private String generateResponseProcedure(String scenario, String planType) {
|
||||
StringBuilder procedure = new StringBuilder();
|
||||
|
||||
procedure.append("1. 紧急情况确认\n");
|
||||
procedure.append(" - 接到报告后30分钟内现场确认\n");
|
||||
procedure.append(" - 调取监控录像和传感器数据\n");
|
||||
procedure.append(" - 评估事态严重程度\n\n");
|
||||
|
||||
procedure.append("2. 应急响应启动\n");
|
||||
procedure.append(" - 通知应急指挥中心\n");
|
||||
procedure.append(" - 调集应急资源\n");
|
||||
procedure.append(" - 向上级部门报告\n\n");
|
||||
|
||||
if (scenario.contains("爆管")) {
|
||||
procedure.append("3. 抢修流程\n");
|
||||
procedure.append(" - 关闭相关阀门\n");
|
||||
procedure.append(" - 组织抢修队伍\n");
|
||||
procedure.append(" - 调配抢修物资\n");
|
||||
procedure.append(" - 制定临时供水方案\n\n");
|
||||
} else if (scenario.contains("水质")) {
|
||||
procedure.append("3. 水质处置流程\n");
|
||||
procedure.append(" - 启动备用水源\n");
|
||||
procedure.append(" - 组织水质检测\n");
|
||||
procedure.append(" - 实施临时供水方案\n");
|
||||
procedure.append(" - 发布停水通知\n\n");
|
||||
}
|
||||
|
||||
procedure.append("4. 恢复重建\n");
|
||||
procedure.append(" - 修复完成后水质检测\n");
|
||||
procedure.append(" - 逐步恢复供水\n");
|
||||
procedure.append(" - 用户通知和解释\n");
|
||||
procedure.append(" - 事后总结和改进\n");
|
||||
|
||||
return procedure.toString();
|
||||
}
|
||||
|
||||
private String generateResponsibleDepartments(String scenario) {
|
||||
return "应急指挥中心:负责统一指挥和协调\n" +
|
||||
"抢修队伍:负责管道维修和恢复供水\n" +
|
||||
"水质检测组:负责水质监测和分析\n" +
|
||||
"用户服务组:负责用户通知和解释\n" +
|
||||
"后勤保障组:负责物资调配和后勤支持";
|
||||
}
|
||||
|
||||
private String generateContactInfo() {
|
||||
return "应急指挥中心:400-123-4567\n" +
|
||||
"抢修队伍:138-0000-1234\n" +
|
||||
"水质检测:138-0000-5678\n" +
|
||||
"用户服务:95598\n" +
|
||||
"24小时值班:110-119-120";
|
||||
}
|
||||
|
||||
private String generateResourceRequirements(String scenario) {
|
||||
return "1. 人员:抢修人员10-20人,技术人员5人\n" +
|
||||
"2. 设备:挖掘机、焊接设备、检测仪器\n" +
|
||||
"3. 物资:管道配件、消毒剂、备用水管\n" +
|
||||
"4. 交通:应急车辆3-5台\n" +
|
||||
"5. 通讯:对讲机、卫星电话";
|
||||
}
|
||||
|
||||
private String generateBackupSolutions(String scenario) {
|
||||
if (scenario.contains("爆管")) {
|
||||
return "1. 应急供水车:提供临时用水\n" +
|
||||
"2. 邻区调水:协调邻近区域供水\n" +
|
||||
"3. 加压供水:启动备用加压站\n" +
|
||||
"4. 瓶装水:发放给特殊用户";
|
||||
} else {
|
||||
return "1. 备用水源:启动备用水厂\n" +
|
||||
"2. 水质处理:临时净化设备\n" +
|
||||
"3. 外购水:联系周边水厂支援\n" +
|
||||
"4. 分时段供水:错峰供水方案";
|
||||
}
|
||||
}
|
||||
|
||||
private String generateEvacuationPlan(String scenario) {
|
||||
return "1. 疏散范围:根据影响区域确定\n" +
|
||||
"2. 疏散路线:提前规划多条路线\n" +
|
||||
"3. 集中地点:学校、体育馆等公共场所\n" +
|
||||
"4. 物资准备:饮用水、食品、药品\n" +
|
||||
"5. 交通保障:提供交通工具";
|
||||
}
|
||||
|
||||
private String generateCommunicationProtocol() {
|
||||
return "1. 内部通讯:使用应急通讯频道\n" +
|
||||
"2. 外部通讯:24小时值班电话\n" +
|
||||
"3. 信息发布:官方渠道及时发布\n" +
|
||||
"4. 媒体应对:统一对外口径\n" +
|
||||
"5. 用户沟通:专人负责用户解释";
|
||||
}
|
||||
|
||||
private List<String> generateImprovementSuggestions(Map<String, Boolean> completeness) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
if (!completeness.get("triggerConditions")) {
|
||||
suggestions.add("补充完善触发条件说明");
|
||||
}
|
||||
if (!completeness.get("responseProcedure")) {
|
||||
suggestions.add("详细制定响应流程步骤");
|
||||
}
|
||||
if (!completeness.get("responsibleDepartments")) {
|
||||
suggestions.add("明确责任部门和人员");
|
||||
}
|
||||
if (!completeness.get("contactInfo")) {
|
||||
suggestions.add("更新联系信息,确保准确");
|
||||
}
|
||||
if (!completeness.get("resourceRequirements")) {
|
||||
suggestions.add("细化资源需求和配置");
|
||||
}
|
||||
if (!completeness.get("backupSolutions")) {
|
||||
suggestions.add("补充完善备用方案");
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private EmergencyPlan getPlanOrThrow(Long planId) {
|
||||
EmergencyPlan plan = planMapper.selectById(planId);
|
||||
if (plan == null) {
|
||||
throw new IllegalArgumentException("预案不存在");
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
}
|
||||
+314
@@ -0,0 +1,314 @@
|
||||
package com.water.production.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.water.production.entity.EmergencySimulation;
|
||||
import com.water.production.entity.EmergencyPlan;
|
||||
import com.water.production.mapper.EmergencySimulationMapper;
|
||||
import com.water.production.mapper.EmergencyPlanMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmergencySimulationService {
|
||||
|
||||
private final EmergencySimulationMapper simulationMapper;
|
||||
private final EmergencyPlanMapper planMapper;
|
||||
private final DispatchCommandService dispatchCommandService;
|
||||
|
||||
/**
|
||||
* 创建爆管模拟
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencySimulation createPipeBurstSimulation(Double lng, Double lat, String pipeDiameter,
|
||||
String creatorName) {
|
||||
EmergencySimulation simulation = new EmergencySimulation();
|
||||
simulation.setSimulationNo("SIM-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
|
||||
simulation.setScenarioType("pipe_burst");
|
||||
simulation.setScenarioName("爆管应急推演");
|
||||
simulation.setLocationLng(lng);
|
||||
simulation.setLocationLat(lat);
|
||||
simulation.setPipeDiameter(pipeDiameter);
|
||||
simulation.setStatus("draft");
|
||||
simulation.setCreatorName(creatorName);
|
||||
simulation.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
// 分析影响区域和方案
|
||||
Map<String, Object> analysis = analyzePipeBurstImpact(lng, lat, pipeDiameter);
|
||||
simulation.setAffectedArea((String) analysis.get("affectedArea"));
|
||||
simulation.setAffectedCustomers((Integer) analysis.get("affectedCustomers"));
|
||||
simulation.setProposedActions(formatActions((List<String>) analysis.get("suggestedActions")));
|
||||
simulation.setEstimatedRecoveryHours((Integer) analysis.get("estimatedRecoveryHours"));
|
||||
|
||||
simulationMapper.insert(simulation);
|
||||
log.info("创建爆管模拟: {}", simulation.getSimulationNo());
|
||||
return simulation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建水质异常推演
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencySimulation createWaterQualityIncident(String area, String pollutant,
|
||||
Double lng, Double lat, String creatorName) {
|
||||
EmergencySimulation simulation = new EmergencySimulation();
|
||||
simulation.setSimulationNo("SIM-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
|
||||
simulation.setScenarioType("water_quality");
|
||||
simulation.setScenarioName("水质异常应急推演");
|
||||
simulation.setLocationLng(lng);
|
||||
simulation.setLocationLat(lat);
|
||||
simulation.setAffectedArea(area);
|
||||
simulation.setStatus("draft");
|
||||
simulation.setCreatorName(creatorName);
|
||||
simulation.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
// 分析水质异常影响和方案
|
||||
Map<String, Object> analysis = analyzeWaterQualityImpact(area, pollutant);
|
||||
simulation.setAffectedCustomers((Integer) analysis.get("affectedCustomers"));
|
||||
simulation.setProposedActions(formatActions((List<String>) analysis.get("suggestedActions")));
|
||||
simulation.setRiskLevel((String) analysis.get("riskLevel"));
|
||||
simulation.setBackupWaterSource((String) analysis.get("backupWaterSource"));
|
||||
simulation.setEstimatedRecoveryHours((Integer) analysis.get("estimatedRecoveryHours"));
|
||||
|
||||
simulationMapper.insert(simulation);
|
||||
log.info("创建水质异常模拟: {}", simulation.getSimulationNo());
|
||||
return simulation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行爆管模拟
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencySimulation executePipeBurstSimulation(Long simulationId, String operatorName) {
|
||||
EmergencySimulation simulation = getSimulationOrThrow(simulationId);
|
||||
if (!"pipe_burst".equals(simulation.getScenarioType())) {
|
||||
throw new IllegalArgumentException("该模拟不是爆管模拟");
|
||||
}
|
||||
|
||||
simulation.setStatus("executing");
|
||||
simulation.setUpdatedAt(LocalDateTime.now());
|
||||
simulationMapper.updateById(simulation);
|
||||
|
||||
// 模拟执行逻辑
|
||||
Map<String, Object> executionResult = executeSimulationLogic(simulation);
|
||||
|
||||
simulation.setStatus("completed");
|
||||
simulation.setUpdatedAt(LocalDateTime.now());
|
||||
simulationMapper.updateById(simulation);
|
||||
|
||||
log.info("完成爆管模拟执行: {}", simulation.getSimulationNo());
|
||||
return simulation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行水质异常模拟
|
||||
*/
|
||||
@Transactional
|
||||
public EmergencySimulation executeWaterQualitySimulation(Long simulationId, String operatorName) {
|
||||
EmergencySimulation simulation = getSimulationOrThrow(simulationId);
|
||||
if (!"water_quality".equals(simulation.getScenarioType())) {
|
||||
throw new IllegalArgumentException("该模拟不是水质异常模拟");
|
||||
}
|
||||
|
||||
simulation.setStatus("executing");
|
||||
simulation.setUpdatedAt(LocalDateTime.now());
|
||||
simulationMapper.updateById(simulation);
|
||||
|
||||
// 模拟执行逻辑
|
||||
Map<String, Object> executionResult = executeSimulationLogic(simulation);
|
||||
|
||||
simulation.setStatus("completed");
|
||||
simulation.setUpdatedAt(LocalDateTime.now());
|
||||
simulationMapper.updateById(simulation);
|
||||
|
||||
log.info("完成水质异常模拟执行: {}", simulation.getSimulationNo());
|
||||
return simulation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询模拟列表
|
||||
*/
|
||||
public IPage<Map<String, Object>> listSimulations(int page, int size, String scenarioType,
|
||||
String status, String keyword, String startDate, String endDate) {
|
||||
Page<Map<String, Object>> pageParam = new Page<>(page, size);
|
||||
return simulationMapper.selectSimulationPage(pageParam, scenarioType, status, keyword, startDate, endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模拟详情
|
||||
*/
|
||||
public Map<String, Object> getSimulationDetail(Long simulationId) {
|
||||
Map<String, Object> detail = simulationMapper.selectSimulationDetail(simulationId);
|
||||
if (detail == null) {
|
||||
throw new IllegalArgumentException("模拟记录不存在");
|
||||
}
|
||||
|
||||
// 获取相关预案
|
||||
List<Map<String, Object>> relatedPlans = simulationMapper.selectRelatedPlans((String) detail.get("scenario_type"));
|
||||
detail.put("relatedPlans", relatedPlans);
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟统计
|
||||
*/
|
||||
public List<Map<String, Object>> getSimulationStats() {
|
||||
return simulationMapper.selectSimulationStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析爆管影响
|
||||
*/
|
||||
private Map<String, Object> analyzePipeBurstImpact(Double lng, Double lat, String pipeDiameter) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
// 基于管道直径和位置计算影响范围
|
||||
double impactRadius = calculateImpactRadius(pipeDiameter);
|
||||
String areaDescription = String.format("半径%.0fm圆形区域", impactRadius);
|
||||
|
||||
// 模拟计算受影响用户数量
|
||||
int affectedCustomers = (int) (Math.PI * impactRadius * impactRadius / 1000 * 50); // 假设每平米0.05用户
|
||||
|
||||
// 生成建议操作
|
||||
List<String> actions = new ArrayList<>();
|
||||
actions.add("关闭上游阀门 V-001, V-002");
|
||||
actions.add("启动应急供水方案 B");
|
||||
actions.add("通知受影响用户(短信+公告)");
|
||||
actions.add("调度抢修队出发");
|
||||
|
||||
// 根据管道直径估算恢复时间
|
||||
int recoveryHours = 2 + getRecoveryHoursByDiameter(pipeDiameter);
|
||||
|
||||
result.put("affectedArea", areaDescription);
|
||||
result.put("affectedCustomers", affectedCustomers);
|
||||
result.put("suggestedActions", actions);
|
||||
result.put("estimatedRecoveryHours", recoveryHours);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析水质异常影响
|
||||
*/
|
||||
private Map<String, Object> analyzeWaterQualityImpact(String area, String pollutant) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
|
||||
// 根据污染物类型确定风险等级
|
||||
String riskLevel = determineRiskLevel(pollutant);
|
||||
|
||||
// 模拟受影响用户数量
|
||||
int affectedCustomers = getAffectedCustomersByArea(area);
|
||||
|
||||
// 生成建议操作
|
||||
List<String> actions = new ArrayList<>();
|
||||
actions.add("立即停止该片区供水");
|
||||
actions.add("启动备用水源");
|
||||
actions.add("水质采样送检");
|
||||
actions.add("向下游水厂发出预警");
|
||||
|
||||
// 根据风险等级估算恢复时间
|
||||
int recoveryHours = riskLevel.equals("critical") ? 8 : (riskLevel.equals("high") ? 4 : 2);
|
||||
|
||||
// 确定备用水源
|
||||
String backupSource = determineBackupWaterSource(area);
|
||||
|
||||
result.put("affectedCustomers", affectedCustomers);
|
||||
result.put("suggestedActions", actions);
|
||||
result.put("riskLevel", riskLevel);
|
||||
result.put("backupWaterSource", backupSource);
|
||||
result.put("estimatedRecoveryHours", recoveryHours);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行模拟逻辑
|
||||
*/
|
||||
private Map<String, Object> executeSimulationLogic(EmergencySimulation simulation) {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("simulationNo", simulation.getSimulationNo());
|
||||
result.put("executionTime", LocalDateTime.now());
|
||||
|
||||
// 模拟执行结果
|
||||
if ("pipe_burst".equals(simulation.getScenarioType())) {
|
||||
result.put("actualAffectedCustomers", simulation.getAffectedCustomers() + (int)(Math.random() * 20 - 10));
|
||||
result.put("actualRecoveryHours", simulation.getEstimatedRecoveryHours() + (int)(Math.random() * 2 - 1));
|
||||
result.put("actualCost", 50000 + (int)(Math.random() * 30000));
|
||||
} else {
|
||||
result.put("actualAffectedCustomers", simulation.getAffectedCustomers() + (int)(Math.random() * 15 - 7));
|
||||
result.put("actualRecoveryHours", simulation.getEstimatedRecoveryHours() + (int)(Math.random() * 2 - 1));
|
||||
result.put("waterQualityIndex", 85 + (int)(Math.random() * 10));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 辅助方法
|
||||
private double calculateImpactRadius(String pipeDiameter) {
|
||||
switch (pipeDiameter) {
|
||||
case "DN50": return 200;
|
||||
case "DN80": return 350;
|
||||
case "DN100": return 500;
|
||||
case "DN150": return 700;
|
||||
default: return 500;
|
||||
}
|
||||
}
|
||||
|
||||
private int getRecoveryHoursByDiameter(String pipeDiameter) {
|
||||
switch (pipeDiameter) {
|
||||
case "DN50": return 1;
|
||||
case "DN80": return 2;
|
||||
case "DN100": return 3;
|
||||
case "DN150": return 4;
|
||||
default: return 3;
|
||||
}
|
||||
}
|
||||
|
||||
private String determineRiskLevel(String pollutant) {
|
||||
if (pollutant.contains("重金属") || pollutant.contains("剧毒")) {
|
||||
return "critical";
|
||||
} else if (pollutant.contains("细菌") || pollutant.contains("病毒")) {
|
||||
return "high";
|
||||
} else {
|
||||
return "medium";
|
||||
}
|
||||
}
|
||||
|
||||
private int getAffectedCustomersByArea(String area) {
|
||||
// 简化的区域人口估算
|
||||
switch (area) {
|
||||
case "市区": return 5000;
|
||||
case "郊区": return 2000;
|
||||
case "工业区": return 3000;
|
||||
default: return 1500;
|
||||
}
|
||||
}
|
||||
|
||||
private String determineBackupWaterSource(String area) {
|
||||
if (area.contains("市区")) {
|
||||
return "备用水厂A";
|
||||
} else if (area.contains("工业区")) {
|
||||
return "应急水车调度";
|
||||
} else {
|
||||
return "深水井备用系统";
|
||||
}
|
||||
}
|
||||
|
||||
private String formatActions(List<String> actions) {
|
||||
return String.join("\n", actions);
|
||||
}
|
||||
|
||||
public void updateSimulation(EmergencySimulation simulation) {
|
||||
simulationMapper.updateById(simulation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
-- 应急推演模块 DDL
|
||||
|
||||
-- 应急推演记录表
|
||||
CREATE TABLE IF NOT EXISTS prod_emergency_simulation (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
simulation_no VARCHAR(64) NOT NULL UNIQUE,
|
||||
scenario_type VARCHAR(32) NOT NULL, -- pipe_burst | water_quality
|
||||
scenario_name VARCHAR(100) NOT NULL,
|
||||
location_lng DOUBLE PRECISION,
|
||||
location_lat DOUBLE PRECISION,
|
||||
pipe_diameter VARCHAR(20),
|
||||
affected_area TEXT,
|
||||
affected_customers INTEGER,
|
||||
proposed_actions TEXT,
|
||||
estimated_recovery_hours INTEGER,
|
||||
backup_water_source VARCHAR(100),
|
||||
risk_level VARCHAR(20),
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'draft', -- draft | executing | completed | with_plan
|
||||
related_command_no VARCHAR(64),
|
||||
incident_report_no VARCHAR(64),
|
||||
creator_name VARCHAR(64),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- 应急预案表
|
||||
CREATE TABLE IF NOT EXISTS prod_emergency_plan (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
plan_no VARCHAR(64) NOT NULL UNIQUE,
|
||||
plan_name VARCHAR(100) NOT NULL,
|
||||
plan_type VARCHAR(32) NOT NULL, -- disaster | accident | emergency
|
||||
scenario VARCHAR(100) NOT NULL,
|
||||
trigger_conditions TEXT,
|
||||
response_procedure TEXT,
|
||||
responsible_departments TEXT,
|
||||
contact_info TEXT,
|
||||
resource_requirements TEXT,
|
||||
backup_solutions TEXT,
|
||||
evacuation_plan TEXT,
|
||||
communication_protocol TEXT,
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'draft', -- draft | active | inactive | expired
|
||||
creator_name VARCHAR(64),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_used_at TIMESTAMP,
|
||||
last_used_in_simulation VARCHAR(64)
|
||||
);
|
||||
|
||||
-- 索引创建
|
||||
CREATE INDEX IF NOT EXISTS idx_sim_scenario_type ON prod_emergency_simulation(scenario_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_sim_status ON prod_emergency_simulation(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_sim_created ON prod_emergency_simulation(created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_sim_location ON prod_emergency_simulation(location_lng, location_lat);
|
||||
CREATE INDEX IF NOT EXISTS idx_plan_plan_type ON prod_emergency_plan(plan_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_plan_status ON prod_emergency_plan(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_plan_scenario ON prod_emergency_plan(scenario);
|
||||
CREATE INDEX IF NOT EXISTS idx_plan_created ON prod_emergency_plan(created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_plan_last_used ON prod_emergency_plan(last_used_at);
|
||||
@@ -0,0 +1,53 @@
|
||||
-- 应急推演模块初始化数据
|
||||
|
||||
-- 插入示例应急预案
|
||||
INSERT INTO prod_emergency_plan (plan_no, plan_name, plan_type, scenario, trigger_conditions, response_procedure, responsible_departments, contact_info, resource_requirements, backup_solutions, evacuation_plan, communication_protocol, status, creator_name, created_at, updated_at) VALUES
|
||||
('PLAN-20240614010001', '爆管应急预案', 'disaster', '爆管',
|
||||
'1. 管道压力异常波动\n2. 地面出现喷水现象\n3. 用户报告大面积停水\n4. 系统监测到漏水量异常',
|
||||
'1. 紧急情况确认\n - 接到报告后30分钟内现场确认\n - 调取监控录像和传感器数据\n - 评估事态严重程度\n\n2. 应急响应启动\n - 通知应急指挥中心\n - 调集应急资源\n - 向上级部门报告\n\n3. 抢修流程\n - 关闭相关阀门\n - 组织抢修队伍\n - 调配抢修物资\n - 制定临时供水方案\n\n4. 恢复重建\n - 修复完成后水质检测\n - 逐步恢复供水\n - 用户通知和解释\n - 事后总结和改进',
|
||||
'应急指挥中心:负责统一指挥和协调\n抢修队伍:负责管道维修和恢复供水\n水质检测组:负责水质监测和分析\n用户服务组:负责用户通知和解释\n后勤保障组:负责物资调配和后勤支持',
|
||||
'应急指挥中心:400-123-4567\n抢修队伍:138-0000-1234\n水质检测:138-0000-5678\n用户服务:95598\n24小时值班:110-119-120',
|
||||
'1. 人员:抢修人员10-20人,技术人员5人\n2. 设备:挖掘机、焊接设备、检测仪器\n3. 物资:管道配件、消毒剂、备用水管\n4. 交通:应急车辆3-5台\n5. 通讯:对讲机、卫星电话',
|
||||
'1. 应急供水车:提供临时用水\n2. 邻区调水:协调邻近区域供水\n3. 加压供水:启动备用加压站\n4. 瓶装水:发放给特殊用户',
|
||||
'1. 疏散范围:根据影响区域确定\n2. 疏散路线:提前规划多条路线\n3. 集中地点:学校、体育馆等公共场所\n4. 物资准备:饮用水、食品、药品\n5. 交通保障:提供交通工具',
|
||||
'1. 内部通讯:使用应急通讯频道\n2. 外部通讯:24小时值班电话\n3. 信息发布:官方渠道及时发布\n4. 媒体应对:统一对外口径\n5. 用户沟通:专人负责用户解释',
|
||||
'active', 'system', NOW(), NOW());
|
||||
|
||||
INSERT INTO prod_emergency_plan (plan_no, plan_name, plan_type, scenario, trigger_conditions, response_procedure, responsible_departments, contact_info, resource_requirements, backup_solutions, evacuation_plan, communication_protocol, status, creator_name, created_at, updated_at) VALUES
|
||||
('PLAN-20240614010002', '水质异常应急预案', 'emergency', '水质异常',
|
||||
'1. 水质检测指标超标\n2. 用户反映水质异常\n3. 上游水源污染报告\n4. 系统监测到浊度/色度异常',
|
||||
'1. 紧急情况确认\n - 接到报告后15分钟内现场确认\n - 多点采集水样进行检测\n - 评估污染程度和范围\n\n2. 应急响应启动\n - 通知应急指挥中心\n - 启动备用水源\n - 向相关部门报告\n\n3. 水质处置流程\n - 立即停止该片区供水\n - 启动备用水源\n - 组织水质检测\n - 实施临时供水方案\n - 发布停水通知\n\n4. 恢复重建\n - 水质达标后恢复供水\n - 全面清洗管道系统\n - 用户通知和解释\n - 事后总结和改进',
|
||||
'应急指挥中心:负责统一指挥和协调\n水质检测组:负责水质监测和分析\n抢修队伍:负责管道系统修复\n用户服务组:负责用户通知和解释\n后勤保障组:负责物资调配和后勤支持',
|
||||
'应急指挥中心:400-123-4567\n水质检测:138-0000-5678\n用户服务:95598\n24小时值班:110-119-120',
|
||||
'1. 人员:检测人员5-10人,技术人员3人\n2. 设备:水质检测仪器、净化设备\n3. 物资:消毒剂、净化材料、采样瓶\n4. 交通:应急车辆2-3台\n5. 通讯:对讲机、卫星电话',
|
||||
'1. 备用水源:启动备用水厂\n2. 水质处理:临时净化设备\n3. 外购水:联系周边水厂支援\n4. 分时段供水:错峰供水方案',
|
||||
'1. 疏散范围:根据污染区域确定\n2. 疏散路线:避开污染区域\n3. 集中地点:清洁区域公共场所\n4. 物资准备:瓶装水、食品、药品\n5. 交通保障:提供安全交通工具',
|
||||
'1. 内部通讯:使用应急通讯频道\n2. 外部通讯:24小时值班电话\n3. 信息发布:官方渠道及时发布\n4. 媒体应对:统一对外口径\n5. 用户沟通:专人负责用户解释',
|
||||
'active', 'system', NOW(), NOW());
|
||||
|
||||
-- 插入示例应急推演记录
|
||||
INSERT INTO prod_emergency_simulation (simulation_no, scenario_type, scenario_name, location_lng, location_lat, pipe_diameter, affected_area, affected_customers, proposed_actions, estimated_recovery_hours, status, creator_name, created_at, updated_at) VALUES
|
||||
('SIM-20240614010001', 'pipe_burst', '爆管应急推演', 116.4074, 39.9042, 'DN100', '半径500m圆形区域', 230,
|
||||
'关闭上游阀门 V-001, V-002\n启动应急供水方案 B\n通知受影响用户(短信+公告)\n调度抢修队出发', 4, 'completed', 'system', NOW(), NOW());
|
||||
|
||||
INSERT INTO prod_emergency_simulation (simulation_no, scenario_type, scenario_name, location_lng, location_lat, affected_area, affected_customers, proposed_actions, risk_level, backup_water_source, estimated_recovery_hours, status, creator_name, created_at, updated_at) VALUES
|
||||
('SIM-20240614010002', 'water_quality', '水质异常应急推演', 116.4074, 39.9042, '市中心区域', 5000,
|
||||
'立即停止该片区供水\n启动备用水源\n水质采样送检\n向下游水厂发出预警', 4, 'high', '备用水厂A', 8, 'completed', 'system', NOW(), NOW());
|
||||
|
||||
-- 创建示例调度指令关联
|
||||
UPDATE prod_emergency_simulation
|
||||
SET related_command_no = 'CMD-20240614010001'
|
||||
WHERE simulation_no = 'SIM-20240614010001';
|
||||
|
||||
UPDATE prod_emergency_simulation
|
||||
SET related_command_no = 'CMD-20240614010002'
|
||||
WHERE simulation_no = 'SIM-20240614010002';
|
||||
|
||||
-- 更新预案使用记录
|
||||
UPDATE prod_emergency_plan
|
||||
SET last_used_at = NOW(), last_used_in_simulation = 'SIM-20240614010001'
|
||||
WHERE plan_no = 'PLAN-20240614010001';
|
||||
|
||||
UPDATE prod_emergency_plan
|
||||
SET last_used_at = NOW(), last_used_in_simulation = 'SIM-20240614010002'
|
||||
WHERE plan_no = 'PLAN-20240614010002';
|
||||
Reference in New Issue
Block a user