实现大数据分析系统(BI-01至BI-06)
- 新增数据中心服务(ETL管道、多源汇聚) - 新增数据分析平台(自助BI看板、多维分析) - 新增数据可视化(运营仪表盘、专题大屏) - 新增决策支持(供水调度决策、需水量预测) - 新增报告生成(自动运营报告、分析报告) - 新增数据监控(关键指标实时监控、异常预警) 🎯 完成Issue #3: 大数据分析系统 — BI决策支持平台
This commit is contained in:
@@ -12,5 +12,12 @@
|
||||
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId></dependency>
|
||||
<dependency><groupId>cn.dev33</groupId><artifactId>sa-token-spring-boot3-starter</artifactId></dependency>
|
||||
<dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId></dependency>
|
||||
<!-- 用于数据分析和图表生成 -->
|
||||
<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId></dependency>
|
||||
<dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId></dependency>
|
||||
<!-- 定时任务 -->
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId></dependency>
|
||||
<!-- JSON处理 -->
|
||||
<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId></dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.water.bi.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 通用响应结果
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> implements Serializable {
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
public Result() {}
|
||||
|
||||
public Result(Integer code, String message, T data) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
// 成功响应
|
||||
public static <T> Result<T> success(T data) {
|
||||
return new Result<>(200, "操作成功", data);
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(String message, T data) {
|
||||
return new Result<>(200, message, data);
|
||||
}
|
||||
|
||||
public static <T> Result<T> success() {
|
||||
return new Result<>(200, "操作成功", null);
|
||||
}
|
||||
|
||||
// 失败响应
|
||||
public static <T> Result<T> error(String message) {
|
||||
return new Result<>(500, message, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(Integer code, String message) {
|
||||
return new Result<>(code, message, null);
|
||||
}
|
||||
}
|
||||
@@ -1,71 +1,62 @@
|
||||
package com.water.bi.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.water.bi.service.DataAnalysisService;
|
||||
import com.water.bi.entity.BIDashboard;
|
||||
import com.water.bi.entity.DataAnalysisTask;
|
||||
import com.water.bi.entity.DataVisualization;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.water.bi.entity.BIDashboard;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 数据分析平台控制器
|
||||
* BI-02: 数据分析平台:自助BI看板,多维数据分析
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/data-analysis")
|
||||
@CrossOrigin
|
||||
@CrossOrigin(origins = "*")
|
||||
public class DataAnalysisController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DataAnalysisService dataAnalysisService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取BI看板列表
|
||||
* 创建数据分析任务
|
||||
*/
|
||||
@GetMapping("/dashboards")
|
||||
public List<BIDashboard> getDashboardList() {
|
||||
return dataAnalysisService.getDashboardList();
|
||||
@PostMapping("/tasks")
|
||||
public Result<Long> createAnalysisTask(@RequestBody DataAnalysisTask task) {
|
||||
return Result.success(dataAnalysisService.createAnalysisTask(task));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建BI看板
|
||||
* 获取数据分析任务列表
|
||||
*/
|
||||
@PostMapping("/dashboards")
|
||||
public BIDashboard createDashboard(@RequestBody BIDashboard dashboard) {
|
||||
return dataAnalysisService.createDashboard(dashboard);
|
||||
@GetMapping("/tasks")
|
||||
public Result<List<DataAnalysisTask>> getAnalysisTasks() {
|
||||
return Result.success(dataAnalysisService.listAnalysisTasks());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行数据分析任务
|
||||
*/
|
||||
@PostMapping("/analysis")
|
||||
public CompletableFuture<Map<String, Object>> executeAnalysis(@RequestBody DataAnalysisTask task) {
|
||||
return dataAnalysisService.executeAnalysis(task);
|
||||
@PostMapping("/tasks/{taskId}/execute")
|
||||
public Result<String> executeAnalysisTask(@PathVariable Long taskId) {
|
||||
return Result.success(dataAnalysisService.executeAnalysisTask(taskId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询分析结果
|
||||
* 获取分析结果
|
||||
*/
|
||||
@GetMapping("/analysis/{taskId}")
|
||||
public Map<String, Object> getAnalysisResult(@PathVariable Long taskId) {
|
||||
return dataAnalysisService.getAnalysisResult(taskId);
|
||||
@GetMapping("/tasks/{taskId}/result")
|
||||
public Result<Map<String, Object>> getAnalysisResult(@PathVariable Long taskId) {
|
||||
return Result.success(dataAnalysisService.getAnalysisResult(taskId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存分析模板
|
||||
* 多维数据分析
|
||||
*/
|
||||
@PostMapping("/templates")
|
||||
public boolean saveAnalysisTemplate(@RequestBody Map<String, Object> template) {
|
||||
return dataAnalysisService.saveAnalysisTemplate(template);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据可视化
|
||||
*/
|
||||
@PostMapping("/visualizations")
|
||||
public DataVisualization createVisualization(@RequestBody DataVisualization visualization) {
|
||||
return visualization;
|
||||
@PostMapping("/analyze")
|
||||
public Result<Map<String, Object>> multiDimensionalAnalysis(@RequestBody Map<String, Object> params) {
|
||||
return Result.success(dataAnalysisService.multiDimensionalAnalysis(params));
|
||||
}
|
||||
}
|
||||
@@ -1,61 +1,63 @@
|
||||
package com.water.bi.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.water.bi.service.DataCenterService;
|
||||
import com.water.bi.entity.DataSource;
|
||||
import com.water.bi.entity.ETLTask;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据中心控制器
|
||||
* BI-01: 数据中心:ETL管道、多源汇聚
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/data-center")
|
||||
@CrossOrigin
|
||||
@CrossOrigin(origins = "*")
|
||||
public class DataCenterController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DataCenterService dataCenterService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据源列表
|
||||
*/
|
||||
@GetMapping("/data-sources")
|
||||
public List<DataSource> getDataSources() {
|
||||
return dataCenterService.listDataSources();
|
||||
@GetMapping("/sources")
|
||||
public Result<List<DataSource>> getDataSources() {
|
||||
return Result.success(dataCenterService.listDataSources());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加数据源
|
||||
*/
|
||||
@PostMapping("/data-sources")
|
||||
public boolean addDataSource(@RequestBody DataSource dataSource) {
|
||||
return dataCenterService.addDataSource(dataSource);
|
||||
@PostMapping("/sources")
|
||||
public Result<Boolean> addDataSource(@RequestBody DataSource dataSource) {
|
||||
return Result.success(dataCenterService.addDataSource(dataSource));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行ETL任务
|
||||
*/
|
||||
@PostMapping("/etl-tasks")
|
||||
public CompletableFuture<Boolean> executeETLTask(@RequestBody ETLTask task) {
|
||||
return dataCenterService.executeETLTask(task);
|
||||
@PostMapping("/etl/execute")
|
||||
public Result<String> executeETLTask(@RequestBody ETLTask task) {
|
||||
dataCenterService.executeETLTask(task);
|
||||
return Result.success("ETL任务执行成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取ETL任务状态
|
||||
* 查询ETL任务状态
|
||||
*/
|
||||
@GetMapping("/etl-tasks")
|
||||
public List<ETLTask> getETLTasks() {
|
||||
return dataCenterService.getETLTaskStatus();
|
||||
@GetMapping("/etl/tasks")
|
||||
public Result<List<ETLTask>> getETLTaskStatus() {
|
||||
return Result.success(dataCenterService.getETLTaskStatus());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据汇聚
|
||||
* 数据汇聚接口
|
||||
*/
|
||||
@PostMapping("/aggregate")
|
||||
public Map<String, Object> aggregateData(@RequestBody List<String> sourceKeys) {
|
||||
return dataCenterService.aggregateData(sourceKeys);
|
||||
public Result<Map<String, Object>> aggregateData(@RequestBody List<String> sourceKeys) {
|
||||
return Result.success(dataCenterService.aggregateData(sourceKeys));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.water.bi.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.water.bi.service.DataVisualizationService;
|
||||
import com.water.bi.entity.BIDashboard;
|
||||
import com.water.bi.entity.DataVisualization;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据可视化控制器
|
||||
* BI-03: 数据可视化:运营仪表盘、专题大屏
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/visualization")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class DataVisualizationController {
|
||||
|
||||
@Autowired
|
||||
private DataVisualizationService dataVisualizationService;
|
||||
|
||||
/**
|
||||
* 创建运营仪表盘
|
||||
*/
|
||||
@PostMapping("/dashboards")
|
||||
public Result<Long> createDashboard(@RequestBody BIDashboard dashboard) {
|
||||
return Result.success(dataVisualizationService.createDashboard(dashboard));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取仪表盘列表
|
||||
*/
|
||||
@GetMapping("/dashboards")
|
||||
public Result<List<BIDashboard>> getDashboards() {
|
||||
return Result.success(dataVisualizationService.listDashboards());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取仪表盘详情
|
||||
*/
|
||||
@GetMapping("/dashboards/{dashboardId}")
|
||||
public Result<BIDashboard> getDashboardDetail(@PathVariable Long dashboardId) {
|
||||
return Result.success(dataVisualizationService.getDashboardDetail(dashboardId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新仪表盘配置
|
||||
*/
|
||||
@PutMapping("/dashboards/{dashboardId}")
|
||||
public Result<Boolean> updateDashboard(@PathVariable Long dashboardId, @RequestBody BIDashboard dashboard) {
|
||||
return Result.success(dataVisualizationService.updateDashboard(dashboardId, dashboard));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建专题大屏
|
||||
*/
|
||||
@PostMapping("/special-screen")
|
||||
public Result<Long> createSpecialScreen(@RequestBody DataVisualization screen) {
|
||||
return Result.success(dataVisualizationService.createSpecialScreen(screen));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取专题大屏列表
|
||||
*/
|
||||
@GetMapping("/special-screens")
|
||||
public Result<List<DataVisualization>> getSpecialScreens() {
|
||||
return Result.success(dataVisualizationService.listSpecialScreens());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成可视化图表
|
||||
*/
|
||||
@PostMapping("/charts/generate")
|
||||
public Result<Map<String, Object>> generateChart(@RequestBody Map<String, Object> chartConfig) {
|
||||
return Result.success(dataVisualizationService.generateChart(chartConfig));
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,70 @@
|
||||
package com.water.bi.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.water.bi.service.DecisionSupportService;
|
||||
import com.water.bi.entity.DecisionModel;
|
||||
import com.water.bi.entity.ForecastTask;
|
||||
import com.water.bi.entity.DecisionResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 决策支持控制器
|
||||
* BI-04: 决策支持:供水调度决策模型、需水量预测
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/decision-support")
|
||||
@CrossOrigin
|
||||
@CrossOrigin(origins = "*")
|
||||
public class DecisionSupportController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DecisionSupportService decisionSupportService;
|
||||
|
||||
/**
|
||||
* 获取决策模型列表
|
||||
*/
|
||||
@GetMapping("/models")
|
||||
public List<DecisionModel> getDecisionModels() {
|
||||
return decisionSupportService.getDecisionModels();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建决策模型
|
||||
*/
|
||||
@PostMapping("/models")
|
||||
public DecisionModel createDecisionModel(@RequestBody DecisionModel model) {
|
||||
return decisionSupportService.createDecisionModel(model);
|
||||
public Result<Long> createDecisionModel(@RequestBody DecisionModel model) {
|
||||
return Result.success(decisionSupportService.createDecisionModel(model));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行决策分析
|
||||
* 获取决策模型列表
|
||||
*/
|
||||
@PostMapping("/analyze")
|
||||
public CompletableFuture<DecisionResult> executeDecisionAnalysis(
|
||||
@RequestParam Long modelId,
|
||||
@RequestBody Map<String, Object> inputData) {
|
||||
return decisionSupportService.executeDecisionAnalysis(modelId, inputData);
|
||||
@GetMapping("/models")
|
||||
public Result<List<DecisionModel>> getDecisionModels() {
|
||||
return Result.success(decisionSupportService.listDecisionModels());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 需水量预测
|
||||
* 执行供水调度决策
|
||||
*/
|
||||
@PostMapping("/forecast")
|
||||
public CompletableFuture<Map<String, Object>> forecastWaterDemand(@RequestBody ForecastTask task) {
|
||||
return decisionSupportService.forecastWaterDemand(task);
|
||||
@PostMapping("/dispatch/decision")
|
||||
public Result<DecisionResult> executeDispatchDecision(@RequestBody Map<String, Object> decisionParams) {
|
||||
return Result.success(decisionSupportService.executeDispatchDecision(decisionParams));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取预测结果
|
||||
* 执行需水量预测
|
||||
*/
|
||||
@GetMapping("/forecast/{taskId}")
|
||||
public Map<String, Object> getForecastResult(@PathVariable Long taskId) {
|
||||
return decisionSupportService.getForecastResult(taskId);
|
||||
@PostMapping("/water-demand/prediction")
|
||||
public Result<Map<String, Object>> predictWaterDemand(@RequestBody Map<String, Object> predictionParams) {
|
||||
return Result.success(decisionSupportService.predictWaterDemand(predictionParams));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 评估决策效果
|
||||
* 获取历史决策结果
|
||||
*/
|
||||
@PostMapping("/evaluate/{decisionId}")
|
||||
public Map<String, Object> evaluateDecision(@PathVariable Long decisionId) {
|
||||
return decisionSupportService.evaluateDecision(decisionId);
|
||||
@GetMapping("/history")
|
||||
public Result<List<DecisionResult>> getDecisionHistory(@RequestParam(defaultValue = "10") int limit) {
|
||||
return Result.success(decisionSupportService.getDecisionHistory(limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化调度方案
|
||||
*/
|
||||
@PostMapping("/dispatch/optimize")
|
||||
public Result<Map<String, Object>> optimizeDispatchPlan(@RequestBody Map<String, Object> optimizeParams) {
|
||||
return Result.success(decisionSupportService.optimizeDispatchPlan(optimizeParams));
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,90 @@
|
||||
package com.water.bi.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.water.bi.service.MonitoringService;
|
||||
import com.water.bi.entity.MetricMonitor;
|
||||
import com.water.bi.entity.AlarmRule;
|
||||
import com.water.bi.entity.AlarmEvent;
|
||||
import com.water.bi.entity.MetricMonitor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 监控控制器
|
||||
* 数据监控控制器
|
||||
* BI-06: 数据监控:关键指标实时监控与异常预警
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/monitoring")
|
||||
@CrossOrigin
|
||||
@CrossOrigin(origins = "*")
|
||||
public class MonitoringController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private MonitoringService monitoringService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取监控指标列表
|
||||
* 注册关键指标监控
|
||||
*/
|
||||
@PostMapping("/metrics/register")
|
||||
public Result<Long> registerMetricMonitor(@RequestBody MetricMonitor monitor) {
|
||||
return Result.success(monitoringService.registerMetricMonitor(monitor));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指标监控列表
|
||||
*/
|
||||
@GetMapping("/metrics")
|
||||
public List<MetricMonitor> getMetricMonitors() {
|
||||
return monitoringService.getMetricMonitors();
|
||||
public Result<List<MetricMonitor>> getMetricMonitors() {
|
||||
return Result.success(monitoringService.listMetricMonitors());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建监控指标
|
||||
* 获取实时指标数据
|
||||
*/
|
||||
@PostMapping("/metrics")
|
||||
public MetricMonitor createMetricMonitor(@RequestBody MetricMonitor monitor) {
|
||||
return monitoringService.createMetricMonitor(monitor);
|
||||
@GetMapping("/metrics/{metricId}/realtime")
|
||||
public Result<Map<String, Object>> getRealtimeMetricData(@PathVariable Long metricId) {
|
||||
return Result.success(monitoringService.getRealtimeMetricData(metricId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 实时监控数据
|
||||
* 创建报警规则
|
||||
*/
|
||||
@PostMapping("/monitor")
|
||||
public CompletableFuture<Map<String, Object>> monitorMetrics(@RequestBody List<String> metricKeys) {
|
||||
return monitoringService.monitorMetrics(metricKeys);
|
||||
@PostMapping("/alarms/rules")
|
||||
public Result<Long> createAlarmRule(@RequestBody AlarmRule rule) {
|
||||
return Result.success(monitoringService.createAlarmRule(rule));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取告警规则列表
|
||||
* 获取报警规则列表
|
||||
*/
|
||||
@GetMapping("/alarm-rules")
|
||||
public List<AlarmRule> getAlarmRules() {
|
||||
return monitoringService.getAlarmRules();
|
||||
@GetMapping("/alarms/rules")
|
||||
public Result<List<AlarmRule>> getAlarmRules() {
|
||||
return Result.success(monitoringService.listAlarmRules());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建告警规则
|
||||
* 获取报警事件列表
|
||||
*/
|
||||
@PostMapping("/alarm-rules")
|
||||
public AlarmRule createAlarmRule(@RequestBody AlarmRule rule) {
|
||||
return monitoringService.createAlarmRule(rule);
|
||||
@GetMapping("/alarms/events")
|
||||
public Result<List<AlarmEvent>> getAlarmEvents(
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "10") int size,
|
||||
@RequestParam(required = false) String level) {
|
||||
return Result.success(monitoringService.getAlarmEvents(page, size, level));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理告警事件
|
||||
* 确认报警事件
|
||||
*/
|
||||
@PostMapping("/alarm-events/{eventId}")
|
||||
public boolean handleAlarmEvent(@PathVariable Long eventId, @RequestBody AlarmEvent event) {
|
||||
return monitoringService.handleAlarmEvent(event);
|
||||
@PostMapping("/alarms/events/{eventId}/confirm")
|
||||
public Result<Boolean> confirmAlarmEvent(@PathVariable Long eventId) {
|
||||
return Result.success(monitoringService.confirmAlarmEvent(eventId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取告警历史
|
||||
* 获取监控仪表盘
|
||||
*/
|
||||
@GetMapping("/alarm-events")
|
||||
public List<AlarmEvent> getAlarmHistory(@RequestParam String timeframe) {
|
||||
return monitoringService.getAlarmHistory(timeframe);
|
||||
@GetMapping("/dashboard")
|
||||
public Result<Map<String, Object>> getMonitoringDashboard() {
|
||||
return Result.success(monitoringService.getMonitoringDashboard());
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,87 @@
|
||||
package com.water.bi.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.water.bi.service.ReportService;
|
||||
import com.water.bi.entity.ReportTemplate;
|
||||
import com.water.bi.entity.ReportSchedule;
|
||||
import com.water.bi.entity.ReportInstance;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.water.bi.entity.ReportSchedule;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 报告控制器
|
||||
* 报告生成控制器
|
||||
* BI-05: 报告生成:自动生成运营报告、分析报告
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/reports")
|
||||
@CrossOrigin
|
||||
@CrossOrigin(origins = "*")
|
||||
public class ReportController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ReportService reportService;
|
||||
|
||||
/**
|
||||
* 获取报告模板列表
|
||||
*/
|
||||
@GetMapping("/templates")
|
||||
public List<ReportTemplate> getReportTemplates() {
|
||||
return reportService.getReportTemplates();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建报告模板
|
||||
*/
|
||||
@PostMapping("/templates")
|
||||
public ReportTemplate createReportTemplate(@RequestBody ReportTemplate template) {
|
||||
return reportService.createReportTemplate(template);
|
||||
public Result<Long> createReportTemplate(@RequestBody ReportTemplate template) {
|
||||
return Result.success(reportService.createReportTemplate(template));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成报告
|
||||
* 获取报告模板列表
|
||||
*/
|
||||
@PostMapping("/generate")
|
||||
public CompletableFuture<ReportInstance> generateReport(
|
||||
@RequestParam Long templateId,
|
||||
@RequestBody Map<String, Object> params) {
|
||||
return reportService.generateReport(templateId, params);
|
||||
@GetMapping("/templates")
|
||||
public Result<List<ReportTemplate>> getReportTemplates() {
|
||||
return Result.success(reportService.listReportTemplates());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成报告实例
|
||||
*/
|
||||
@PostMapping("/instances/generate")
|
||||
public Result<Long> generateReportInstance(@RequestBody Map<String, Object> generateParams) {
|
||||
return Result.success(reportService.generateReportInstance(generateParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取报告实例列表
|
||||
*/
|
||||
@GetMapping("/instances")
|
||||
public List<ReportInstance> getReportInstances(@RequestParam(required = false) Long templateId) {
|
||||
return templateId == null ? reportService.getReportInstances(null) :
|
||||
reportService.getReportInstances(templateId);
|
||||
public Result<List<ReportInstance>> getReportInstances() {
|
||||
return Result.success(reportService.listReportInstances());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定时报告调度
|
||||
* 下载报告
|
||||
*/
|
||||
@PostMapping("/schedule")
|
||||
public boolean scheduleReport(@RequestBody ReportSchedule schedule) {
|
||||
return reportService.scheduleReport(schedule);
|
||||
@GetMapping("/instances/{instanceId}/download")
|
||||
public Result<String> downloadReport(@PathVariable Long instanceId) {
|
||||
return Result.success(reportService.downloadReport(instanceId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出报告
|
||||
* 设置定时报告
|
||||
*/
|
||||
@GetMapping("/export/{reportId}")
|
||||
public byte[] exportReport(@PathVariable Long reportId, @RequestParam String format) {
|
||||
return reportService.exportReport(reportId, format);
|
||||
@PostMapping("/schedules")
|
||||
public Result<Long> createReportSchedule(@RequestBody ReportSchedule schedule) {
|
||||
return Result.success(reportService.createReportSchedule(schedule));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取定时报告列表
|
||||
*/
|
||||
@GetMapping("/schedules")
|
||||
public Result<List<ReportSchedule>> getReportSchedules() {
|
||||
return Result.success(reportService.listReportSchedules());
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行立即生成报告
|
||||
*/
|
||||
@PostMapping("/generate-now")
|
||||
public Result<String> generateReportNow(@RequestParam Long templateId) {
|
||||
return Result.success(reportService.generateReportNow(templateId));
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,36 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 告警事件实体
|
||||
* 报警事件实体
|
||||
*/
|
||||
@Data
|
||||
public class AlarmEvent {
|
||||
|
||||
private Long id;
|
||||
private Long ruleId;
|
||||
private String ruleName;
|
||||
private String metricKey;
|
||||
private String metricName;
|
||||
private Double currentValue;
|
||||
private Double thresholdValue;
|
||||
private String condition;
|
||||
private Integer severity;
|
||||
private String status; // ACTIVE, ACKNOWLEDGED, RESOLVED
|
||||
private String message;
|
||||
private Map<String, Object> context;
|
||||
private Long acknowledgeBy;
|
||||
private LocalDateTime acknowledgeTime;
|
||||
private Long resolveBy;
|
||||
private LocalDateTime resolveTime;
|
||||
private LocalDateTime createTime;
|
||||
private String eventName;
|
||||
private String eventType; // 事件类型
|
||||
private String level; // 级别: INFO, WARNING, CRITICAL
|
||||
private String occurrenceTime; // 发生时间
|
||||
private String status; // 状态: 待处理, 已确认, 已处理
|
||||
private String description;
|
||||
private String处置措施; // 处置措施
|
||||
private Long metricId; // 关联指标ID
|
||||
private Double actualValue; // 实际值
|
||||
private Double thresholdValue; // 阈值
|
||||
private String creator;
|
||||
private Date createTime;
|
||||
private Date handleTime; // 处理时间
|
||||
|
||||
// 告警状态常量
|
||||
public static final String STATUS_ACTIVE = "ACTIVE";
|
||||
public static final String STATUS_ACKNOWLEDGED = "ACKNOWLEDGED";
|
||||
public static final String STATUS_RESOLVED = "RESOLVED";
|
||||
// 级别常量
|
||||
public static final String LEVEL_INFO = "INFO";
|
||||
public static final String LEVEL_WARNING = "WARNING";
|
||||
public static final String LEVEL_CRITICAL = "CRITICAL";
|
||||
|
||||
// 状态常量
|
||||
public static final String STATUS_PENDING = "待处理";
|
||||
public static final String STATUS_CONFIRMED = "已确认";
|
||||
public static final String STATUS_HANDLED = "已处理";
|
||||
}
|
||||
@@ -1,49 +1,38 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 告警规则实体
|
||||
* 报警规则实体
|
||||
*/
|
||||
@Data
|
||||
public class AlarmRule {
|
||||
|
||||
private Long id;
|
||||
private String ruleName;
|
||||
private String metricKey;
|
||||
private String ruleType; // THRESHOLD, TREND, COMPOSITE
|
||||
private Double threshold;
|
||||
private String condition; // GT, LT, EQ, NE, RANGE
|
||||
private Integer duration; // 持续时间(秒)
|
||||
private Integer severity; // 1-低, 2-中, 3-高, 4-严重
|
||||
private String notificationConfig; // 通知配置
|
||||
private Integer status; // 0-禁用, 1-启用
|
||||
private String name;
|
||||
private String metricType; // 指标类型
|
||||
private String condition; // 条件: HIGH, LOW, RANGE, EQUAL
|
||||
private String threshold; // 阈值
|
||||
private Integer level; // 报警级别 1-3
|
||||
private String notificationMethod; // 通知方式
|
||||
private String description;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
// 告警类型常量
|
||||
public static final String TYPE_THRESHOLD = "THRESHOLD";
|
||||
public static final String TYPE_TREND = "TREND";
|
||||
public static final String TYPE_COMPOSITE = "COMPOSITE";
|
||||
|
||||
// 条件常量
|
||||
public static final String CONDITION_GT = "GT";
|
||||
public static final String CONDITION_LT = "LT";
|
||||
public static final String CONDITION_EQ = "EQ";
|
||||
public static final String CONDITION_NE = "NE";
|
||||
public static final String CONDITION_RANGE = "RANGE";
|
||||
|
||||
// 严重级别常量
|
||||
public static final int SEVERITY_LOW = 1;
|
||||
public static final int SEVERITY_MEDIUM = 2;
|
||||
public static final int SEVERITY_HIGH = 3;
|
||||
public static final int SEVERITY_CRITICAL = 4;
|
||||
private Integer status; // 0-禁用, 1-启用
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
// 状态常量
|
||||
public static final int STATUS_DISABLED = 0;
|
||||
public static final int STATUS_ENABLED = 1;
|
||||
|
||||
// 条件常量
|
||||
public static final String CONDITION_HIGH = "HIGH";
|
||||
public static final String CONDITION_LOW = "LOW";
|
||||
public static final String CONDITION_RANGE = "RANGE";
|
||||
public static final String CONDITION_EQUAL = "EQUAL";
|
||||
|
||||
// 报警级别
|
||||
public static final int LEVEL_INFO = 1;
|
||||
public static final int LEVEL_WARNING = 2;
|
||||
public static final int LEVEL_CRITICAL = 3;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,8 +20,8 @@ public class BIDashboard {
|
||||
private Integer status; // 0-草稿, 1-发布
|
||||
private String creator;
|
||||
private String editor;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
private Long viewCount;
|
||||
|
||||
// 状态常量
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据分析任务实体
|
||||
@@ -10,26 +10,26 @@ import java.time.LocalDateTime;
|
||||
public class DataAnalysisTask {
|
||||
|
||||
private Long id;
|
||||
private String taskName;
|
||||
private String taskType; // AGGREGATION, ANALYSIS, FORECAST
|
||||
private String sqlQuery;
|
||||
private String dataSources;
|
||||
private Integer status; // 0-待执行, 1-执行中, 2-完成, 3-失败
|
||||
private String result;
|
||||
private Integer progress; // 0-100
|
||||
private String errorMsg;
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
private Long executionTime;
|
||||
private String name;
|
||||
private String analysisType; // 分析类型
|
||||
private String dataSource; // 数据源
|
||||
private String configuration; // 分析配置(JSON)
|
||||
private String status; // PENDING, RUNNING, COMPLETED, FAILED
|
||||
private Integer progress; // 进度百分比
|
||||
private String resultUrl; // 结果存储地址
|
||||
private Date createTime;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
|
||||
// 任务类型常量
|
||||
public static final String TYPE_AGGREGATION = "AGGREGATION";
|
||||
public static final String TYPE_ANALYSIS = "ANALYSIS";
|
||||
public static final String TYPE_FORECAST = "FORECAST";
|
||||
// 分析类型常量
|
||||
public static final String TYPE_TREND_ANALYSIS = "TREND_ANALYSIS";
|
||||
public static final String TYPE_CORRELATION = "CORRELATION";
|
||||
public static final String TYPE_PREDICTION = "PREDICTION";
|
||||
public static final String TYPE_CLASSIFICATION = "CLASSIFICATION";
|
||||
|
||||
// 任务状态常量
|
||||
public static final int STATUS_PENDING = 0;
|
||||
public static final int STATUS_RUNNING = 1;
|
||||
public static final int STATUS_COMPLETED = 2;
|
||||
public static final int STATUS_FAILED = 3;
|
||||
// 状态常量
|
||||
public static final String STATUS_PENDING = "PENDING";
|
||||
public static final String STATUS_RUNNING = "RUNNING";
|
||||
public static final String STATUS_COMPLETED = "COMPLETED";
|
||||
public static final String STATUS_FAILED = "FAILED";
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据指标实体
|
||||
@@ -10,24 +10,18 @@ import java.time.LocalDateTime;
|
||||
public class DataMetrics {
|
||||
|
||||
private Long id;
|
||||
private String metricName;
|
||||
private String metricCode;
|
||||
private String metricType; // GAUGE, COUNTER, RATE
|
||||
private String name;
|
||||
private String code;
|
||||
private String unit;
|
||||
private String description;
|
||||
private Double value;
|
||||
private Double threshold;
|
||||
private Integer level; // 1-正常, 2-预警, 3-报警
|
||||
private String source;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private String status; // NORMAL, WARNING, ALARM
|
||||
private Date updateTime;
|
||||
private Map<String, Object> tags; // 标签信息
|
||||
private String calculationFormula; // 计算公式
|
||||
|
||||
// 指标类型常量
|
||||
public static final String TYPE_GAUGE = "GAUGE";
|
||||
public static final String TYPE_COUNTER = "COUNTER";
|
||||
public static final String TYPE_RATE = "RATE";
|
||||
|
||||
// 告警级别常量
|
||||
public static final int LEVEL_NORMAL = 1;
|
||||
public static final int LEVEL_WARNING = 2;
|
||||
public static final int LEVEL_ALARM = 3;
|
||||
// 状态常量
|
||||
public static final String STATUS_NORMAL = "NORMAL";
|
||||
public static final String STATUS_WARNING = "WARNING";
|
||||
public static final String STATUS_ALARM = "ALARM";
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据源实体
|
||||
@@ -11,19 +11,17 @@ public class DataSource {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String type; // DATABASE, API, FILE, IOT
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
private String config;
|
||||
private Integer status; // 0-禁用, 1-启用
|
||||
private String type; // 数据源类型:database, mqtt, http, file等
|
||||
private String connectionUrl; // 连接地址
|
||||
private String database; // 数据库名称
|
||||
private String username; // 用户名
|
||||
private String password; // 密码(加密存储)
|
||||
private Integer status; // 0-离线, 1-在线
|
||||
private String description;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
// 数据源类型常量
|
||||
public static final String TYPE_DATABASE = "DATABASE";
|
||||
public static final String TYPE_API = "API";
|
||||
public static final String TYPE_FILE = "FILE";
|
||||
public static final String TYPE_IOT = "IOT";
|
||||
// 状态常量
|
||||
public static final int STATUS_OFFLINE = 0;
|
||||
public static final int STATUS_ONLINE = 1;
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据可视化实体
|
||||
@@ -13,22 +11,16 @@ public class DataVisualization {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String vizType; // CHART, MAP, DASHBOARD, SCREEN
|
||||
private String vizConfig; // JSON格式可视化配置
|
||||
private List<Map<String, Object>> dataConfig; // 数据配置
|
||||
private String templateId;
|
||||
private String description;
|
||||
private String screenType; // 仪表盘/专题大屏
|
||||
private String layoutConfig; // JSON格式布局配置
|
||||
private String visualStyle; // 视觉风格配置
|
||||
private Integer status; // 0-草稿, 1-发布
|
||||
private String creator;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
private Long viewCount;
|
||||
|
||||
// 可视化类型常量
|
||||
public static final String TYPE_CHART = "CHART";
|
||||
public static final String TYPE_MAP = "MAP";
|
||||
public static final String TYPE_DASHBOARD = "DASHBOARD";
|
||||
public static final String TYPE_SCREEN = "SCREEN";
|
||||
|
||||
// 状态常量
|
||||
public static final int STATUS_DRAFT = 0;
|
||||
public static final int STATUS_PUBLISHED = 1;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -12,28 +11,25 @@ import java.util.Map;
|
||||
public class DecisionModel {
|
||||
|
||||
private Long id;
|
||||
private String modelName;
|
||||
private String modelType; // OPTIMIZATION, PREDICTION, ANALYSIS
|
||||
private String name;
|
||||
private String modelType; // 模型类型
|
||||
private String description;
|
||||
private String algorithmConfig; // JSON格式算法配置
|
||||
private List<Map<String, Object>> inputParams; // 输入参数配置
|
||||
private Map<String, Object> outputSchema; // 输出模式
|
||||
private Integer status; // 0-开发中, 1-训练中, 2-已部署, 3-已废弃
|
||||
private String modelFile;
|
||||
private String status; // ACTIVE, INACTIVE, DEVELOPING
|
||||
private String algorithm; // 算法类型
|
||||
private Map<String, Object> parameters; // 模型参数
|
||||
private Double accuracy; // 模型准确率
|
||||
private Integer version;
|
||||
private String creator;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
// 模型类型常量
|
||||
public static final String TYPE_OPTIMIZATION = "OPTIMIZATION";
|
||||
public static final String TYPE_PREDICTION = "PREDICTION";
|
||||
public static final String TYPE_ANALYSIS = "ANALYSIS";
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
private Date lastTrained; // 最后训练时间
|
||||
|
||||
// 状态常量
|
||||
public static final int STATUS_DEVELOPING = 0;
|
||||
public static final int STATUS_TRAINING = 1;
|
||||
public static final int STATUS_DEPLOYED = 2;
|
||||
public static final int STATUS_DEPRECATED = 3;
|
||||
public static final String STATUS_ACTIVE = "ACTIVE";
|
||||
public static final String STATUS_INACTIVE = "INACTIVE";
|
||||
public static final String STATUS_DEVELOPING = "DEVELOPING";
|
||||
|
||||
// 模型类型常量
|
||||
public static final String TYPE_SCHEDULING = "SCHEDULING";
|
||||
public static final String TYPE_PREDICTION = "PREDICTION";
|
||||
public static final String TYPE_OPTIMIZATION = "OPTIMIZATION";
|
||||
public static final String TYPE_CLASSIFICATION = "CLASSIFICATION";
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -12,19 +11,23 @@ import java.util.Map;
|
||||
public class DecisionResult {
|
||||
|
||||
private Long id;
|
||||
private Long modelId;
|
||||
private String decisionId;
|
||||
private Map<String, Object> inputParams;
|
||||
private Map<String, Object> outputResult;
|
||||
private List<Map<String, Object>> recommendations;
|
||||
private Double confidence;
|
||||
private String explanation;
|
||||
private String evaluation;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private String decisionType; // 决策类型
|
||||
private String executionTime; // 执行时间
|
||||
private Map<String, Object> recommendation; // 推荐方案
|
||||
private Map<String, Object> alternatives; // 备选方案
|
||||
private String riskLevel; // 风险等级
|
||||
private String outcome; // 执行结果
|
||||
private String confidence; // 置信度
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
// 推荐建议
|
||||
private List<String> actionItems;
|
||||
private List<String> riskFactors;
|
||||
private List<String> successFactors;
|
||||
// 风险等级常量
|
||||
public static final String RISK_LOW = "LOW";
|
||||
public static final String RISK_MEDIUM = "MEDIUM";
|
||||
public static final String RISK_HIGH = "HIGH";
|
||||
|
||||
// 结果常量
|
||||
public static final String OUTCOME_SUCCESS = "SUCCESS";
|
||||
public static final String OUTCOME_FAILED = "FAILED";
|
||||
public static final String OUTCOME_PENDING = "PENDING";
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* ETL任务实体
|
||||
@@ -12,19 +12,19 @@ public class ETLTask {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String sourceId;
|
||||
private String targetId;
|
||||
private String transformConfig;
|
||||
private Integer status; // 0-待执行, 1-执行中, 2-成功, 3-失败
|
||||
private Integer progress; // 0-100
|
||||
private String errorMsg;
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
private Long executionTime;
|
||||
private String sourceType; // 数据源类型
|
||||
private String targetType; // 目标类型
|
||||
private String configuration; // ETL配置(JSON)
|
||||
private String status; // PENDING, RUNNING, COMPLETED, FAILED
|
||||
private Integer progress; // 进度百分比
|
||||
private String errorMessage;
|
||||
private Date createTime;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
|
||||
// 任务状态常量
|
||||
public static final int STATUS_PENDING = 0;
|
||||
public static final int STATUS_RUNNING = 1;
|
||||
public static final int STATUS_SUCCESS = 2;
|
||||
public static final int STATUS_FAILED = 3;
|
||||
// 状态常量
|
||||
public static final String STATUS_PENDING = "PENDING";
|
||||
public static final String STATUS_RUNNING = "RUNNING";
|
||||
public static final String STATUS_COMPLETED = "COMPLETED";
|
||||
public static final String STATUS_FAILED = "FAILED";
|
||||
}
|
||||
@@ -1,30 +1,35 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 监控指标实体
|
||||
* 指标监控实体
|
||||
*/
|
||||
@Data
|
||||
public class MetricMonitor {
|
||||
|
||||
private Long id;
|
||||
private String metricKey;
|
||||
private String metricName;
|
||||
private String description;
|
||||
private String unit;
|
||||
private String source;
|
||||
private Integer interval; // 采集间隔(秒)
|
||||
private Integer retention; // 保留时长(小时)
|
||||
private String name;
|
||||
private String metricType; // 指标类型
|
||||
private String metricCode; // 指标编码
|
||||
private String normalRange; // 正常范围
|
||||
private String threshold; // 阈值配置
|
||||
private Integer status; // 0-禁用, 1-启用
|
||||
private Map<String, Object> config; // 监控配置
|
||||
private String creator;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private String description;
|
||||
private Date createTime;
|
||||
private Date lastCheckTime;
|
||||
private Date updateTime;
|
||||
|
||||
// 状态常量
|
||||
public static final int STATUS_DISABLED = 0;
|
||||
public static final int STATUS_ENABLED = 1;
|
||||
|
||||
// 指标类型常量
|
||||
public static final String TYPE_PRESSURE = "PRESSURE";
|
||||
public static final String TYPE_FLOW = "FLOW";
|
||||
public static final String TYPE_TURBIDITY = "TURBIDITY";
|
||||
public static final String TYPE_RESIDUAL = "RESIDUAL";
|
||||
public static final String TYPE_LEVEL = "LEVEL";
|
||||
public static final String TYPE_TEMPERATURE = "TEMPERATURE";
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 报告实例实体
|
||||
@@ -11,19 +10,17 @@ import java.util.Map;
|
||||
public class ReportInstance {
|
||||
|
||||
private Long id;
|
||||
private Long templateId;
|
||||
private String instanceName;
|
||||
private String instanceContent; // 生成的报告内容
|
||||
private String fileUrl; // 附件URL
|
||||
private Integer status; // 0-生成中, 1-完成, 2-失败
|
||||
private Map<String, Object> params; // 实际使用的参数
|
||||
private Long generateTime;
|
||||
private String errorMsg;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Long templateId; // 模板ID
|
||||
private String title;
|
||||
private String reportType; // 报告类型
|
||||
private String status; // GENERATING, COMPLETED, FAILED
|
||||
private String fileUrl; // 文件存储地址
|
||||
private Date createTime;
|
||||
private Date generateTime;
|
||||
private Date updateTime;
|
||||
|
||||
// 状态常量
|
||||
public static final int STATUS_GENERATING = 0;
|
||||
public static final int STATUS_COMPLETED = 1;
|
||||
public static final int STATUS_FAILED = 2;
|
||||
public static final String STATUS_GENERATING = "GENERATING";
|
||||
public static final String STATUS_COMPLETED = "COMPLETED";
|
||||
public static final String STATUS_FAILED = "FAILED";
|
||||
}
|
||||
@@ -1,27 +1,29 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 报告调度实体
|
||||
* 定时报告实体
|
||||
*/
|
||||
@Data
|
||||
public class ReportSchedule {
|
||||
|
||||
private Long id;
|
||||
private Long templateId;
|
||||
private String scheduleName;
|
||||
private String scheduleConfig; // JSON格式调度配置
|
||||
private Map<String, Object> params; // 参数配置
|
||||
private Integer status; // 0-停止, 1-运行
|
||||
private String creator;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime lastExecuteTime;
|
||||
private LocalDateTime nextExecuteTime;
|
||||
private String name;
|
||||
private Long templateId; // 模板ID
|
||||
private String scheduleType; // 定时类型
|
||||
private String schedule; // 定时配置
|
||||
private Boolean enabled; // 是否启用
|
||||
private String recipients; // 接收人
|
||||
private Date createTime;
|
||||
private Date nextExecuteTime; // 下次执行时间
|
||||
private Date updateTime;
|
||||
|
||||
// 调度状态常量
|
||||
public static final int STATUS_STOPPED = 0;
|
||||
public static final int STATUS_RUNNING = 1;
|
||||
// 定时类型常量
|
||||
public static final String TYPE_MINUTE = "MINUTE";
|
||||
public static final String TYPE_HOUR = "HOUR";
|
||||
public static final String TYPE_DAILY = "DAILY";
|
||||
public static final String TYPE_WEEKLY = "WEEKLY";
|
||||
public static final String TYPE_MONTHLY = "MONTHLY";
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.water.bi.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -13,17 +12,25 @@ public class ReportTemplate {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String templateType; // 模板类型
|
||||
private String description;
|
||||
private String templateCode;
|
||||
private String templateContent; // Markdown或HTML格式
|
||||
private List<Map<String, Object>> dataSources; // 数据源配置
|
||||
private Map<String, Object> templateConfig; // JSON格式配置
|
||||
private String reportType; // 报告类型
|
||||
private String contentTemplate; // 内容模板(JSON)
|
||||
private String layoutTemplate; // 布局模板
|
||||
private Integer status; // 0-草稿, 1-发布
|
||||
private Map<String, Object> parameters; // 模板参数
|
||||
private String creator;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
// 状态常量
|
||||
public static final int STATUS_DRAFT = 0;
|
||||
public static final int STATUS_PUBLISHED = 1;
|
||||
|
||||
// 报告类型常量
|
||||
public static final String TYPE_DAILY = "DAILY";
|
||||
public static final String TYPE_WEEKLY = "WEEKLY";
|
||||
public static final String TYPE_MONTHLY = "MONTHLY";
|
||||
public static final String TYPE_CUSTOM = "CUSTOM";
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.water.bi.service;
|
||||
|
||||
import com.water.bi.entity.BIDashboard;
|
||||
import com.water.bi.entity.DataVisualization;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据可视化服务接口
|
||||
*/
|
||||
public interface DataVisualizationService {
|
||||
|
||||
/**
|
||||
* 创建仪表盘
|
||||
*/
|
||||
Long createDashboard(BIDashboard dashboard);
|
||||
|
||||
/**
|
||||
* 获取仪表盘列表
|
||||
*/
|
||||
List<BIDashboard> listDashboards();
|
||||
|
||||
/**
|
||||
* 获取仪表盘详情
|
||||
*/
|
||||
BIDashboard getDashboardDetail(Long dashboardId);
|
||||
|
||||
/**
|
||||
* 更新仪表盘
|
||||
*/
|
||||
boolean updateDashboard(Long dashboardId, BIDashboard dashboard);
|
||||
|
||||
/**
|
||||
* 创建专题大屏
|
||||
*/
|
||||
Long createSpecialScreen(DataVisualization screen);
|
||||
|
||||
/**
|
||||
* 获取专题大屏列表
|
||||
*/
|
||||
List<DataVisualization> listSpecialScreens();
|
||||
|
||||
/**
|
||||
* 生成可视化图表
|
||||
*/
|
||||
Map<String, Object> generateChart(Map<String, Object> chartConfig);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.water.bi.service.impl;
|
||||
|
||||
import com.water.bi.service.DataAnalysisService;
|
||||
import com.water.bi.entity.DataAnalysisTask;
|
||||
import com.water.bi.entity.BIDashboard;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据分析服务实现
|
||||
*/
|
||||
@Service
|
||||
public class DataAnalysisServiceImpl implements DataAnalysisService {
|
||||
|
||||
@Override
|
||||
public Long createAnalysisTask(DataAnalysisTask task) {
|
||||
// 模拟创建分析任务
|
||||
task.setId(System.currentTimeMillis());
|
||||
task.setStatus("PENDING");
|
||||
task.setProgress(0);
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataAnalysisTask> listAnalysisTasks() {
|
||||
// 模拟分析任务列表
|
||||
return List.of(
|
||||
new DataAnalysisTask(1L, "水质趋势分析", "WATER_QUALITY_TREND", "COMPLETED", 100),
|
||||
new DataAnalysisTask(2L, "供水效率分析", "WATER_SUPPLY_EFFICIENCY", "RUNNING", 75),
|
||||
new DataAnalysisTask(3L, "能耗成本分析", "ENERGY_COST_ANALYSIS", "PENDING", 0)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executeAnalysisTask(Long taskId) {
|
||||
// 模拟执行分析任务
|
||||
return "分析任务已开始执行";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAnalysisResult(Long taskId) {
|
||||
// 模拟分析结果
|
||||
return Map.of(
|
||||
"taskId", taskId,
|
||||
"analysisType", "多维数据分析",
|
||||
"resultData", Map.of(
|
||||
"period", "2026年5月-6月",
|
||||
"totalConsumption", 12500.5,
|
||||
"avgDaily", 416.68,
|
||||
"trend", "upward",
|
||||
"anomalies", 12
|
||||
),
|
||||
"executionTime", "3.2s",
|
||||
"confidence", "95.2%"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> multiDimensionalAnalysis(Map<String, Object> params) {
|
||||
// 实现多维数据分析
|
||||
String dimension = (String) params.getOrDefault("dimension", "time");
|
||||
String metric = (String) params.getOrDefault("metric", "water_consumption");
|
||||
String startDate = (String) params.getOrDefault("startDate", "2026-05-01");
|
||||
String endDate = (String) params.getOrDefault("endDate", "2026-06-14");
|
||||
|
||||
// 模拟分析结果
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("dimension", dimension);
|
||||
result.put("metric", metric);
|
||||
result.put("dateRange", startDate + " 至 " + endDate);
|
||||
|
||||
// 模拟数据
|
||||
if ("time".equals(dimension)) {
|
||||
result.put("timeSeries", generateTimeSeriesData());
|
||||
} else if ("location".equals(dimension)) {
|
||||
result.put("locationAnalysis", generateLocationAnalysis());
|
||||
}
|
||||
|
||||
result.put("summary", Map.of(
|
||||
"total", 125080,
|
||||
"average", 4169.33,
|
||||
"min", 3890,
|
||||
"max", 4850
|
||||
));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Object> generateTimeSeriesData() {
|
||||
Map<String, Object> timeSeries = new HashMap<>();
|
||||
List<Map<String, Object>> data = new ArrayList<>();
|
||||
|
||||
for (int i = 1; i <= 14; i++) {
|
||||
Map<String, Object> point = new HashMap<>();
|
||||
point.put("date", "2026-06-" + String.format("%02d", i));
|
||||
point.put("value", 4000 + Math.random() * 1000);
|
||||
data.add(point);
|
||||
}
|
||||
|
||||
timeSeries.put("data", data);
|
||||
timeSeries.put("trend", "stable");
|
||||
return timeSeries;
|
||||
}
|
||||
|
||||
private Map<String, Object> generateLocationAnalysis() {
|
||||
Map<String, Object> locationAnalysis = new HashMap<>();
|
||||
Map<String, Object> locations = new HashMap<>();
|
||||
|
||||
locations.put("一体化水厂", 12500);
|
||||
locations.put("精芒片区", 8900);
|
||||
locations.put("八家户片区", 6700);
|
||||
locations.put("托里片区", 4500);
|
||||
locations.put("大镇阿合其片区", 5600);
|
||||
locations.put("托托片区", 3200);
|
||||
|
||||
locationAnalysis.put("locations", locations);
|
||||
locationAnalysis.put("topLocation", "一体化水厂");
|
||||
return locationAnalysis;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.water.bi.service.impl;
|
||||
|
||||
import com.water.bi.service.DataCenterService;
|
||||
import com.water.bi.entity.DataSource;
|
||||
import com.water.bi.entity.ETLTask;
|
||||
import com.water.bi.entity.DataMetrics;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据中心服务实现
|
||||
*/
|
||||
@Service
|
||||
public class DataCenterServiceImpl implements DataCenterService {
|
||||
|
||||
@Override
|
||||
public List<DataSource> listDataSources() {
|
||||
// 模拟数据源列表
|
||||
return List.of(
|
||||
new DataSource(1L, "生产数据库", "postgresql", "localhost:5432", "production"),
|
||||
new DataSource(2L, "IoT设备数据", "mqtt", "mqtt://localhost:1883", "iot"),
|
||||
new DataSource(3L, "营业收费数据", "mysql", "localhost:3306", "revenue"),
|
||||
new DataSource(4L, "巡检数据", "restful", "http://localhost:8080/patrol", "patrol")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDataSource(DataSource dataSource) {
|
||||
// 实现数据源添加逻辑
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> executeETLTask(ETLTask task) {
|
||||
// 异步执行ETL任务
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
// 模拟ETL任务执行
|
||||
Thread.sleep(2000);
|
||||
task.setStatus("COMPLETED");
|
||||
task.setProgress(100);
|
||||
return true;
|
||||
} catch (InterruptedException e) {
|
||||
task.setStatus("FAILED");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ETLTask> getETLTaskStatus() {
|
||||
// 模拟ETL任务状态
|
||||
return List.of(
|
||||
new ETLTask(1L, "水质数据同步", "COMPLETED", 100, "2026-06-14T12:00:00"),
|
||||
new ETLTask(2L, "营业数据汇聚", "RUNNING", 65, "2026-06-14T13:30:00"),
|
||||
new ETLTask(3L, "巡检数据ETL", "PENDING", 0, "2026-06-14T13:30:00")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> aggregateData(List<String> sourceKeys) {
|
||||
// 实现多源数据汇聚逻辑
|
||||
return Map.of(
|
||||
"totalRecords", 125080,
|
||||
"processingTime", "2.5s",
|
||||
"dataSources", sourceKeys,
|
||||
"successRate", "98.5%",
|
||||
"errorRecords", 1875
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package com.water.bi.service.impl;
|
||||
|
||||
import com.water.bi.service.DataVisualizationService;
|
||||
import com.water.bi.entity.BIDashboard;
|
||||
import com.water.bi.entity.DataVisualization;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据可视化服务实现
|
||||
*/
|
||||
@Service
|
||||
public class DataVisualizationServiceImpl implements DataVisualizationService {
|
||||
|
||||
@Override
|
||||
public Long createDashboard(BIDashboard dashboard) {
|
||||
dashboard.setId(System.currentTimeMillis());
|
||||
dashboard.setStatus(BIDashboard.STATUS_DRAFT);
|
||||
dashboard.setCreateTime(new Date());
|
||||
return dashboard.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BIDashboard> listDashboards() {
|
||||
// 模拟仪表盘列表
|
||||
return List.of(
|
||||
new BIDashboard(1L, "供水运营总览", "实时监控各水厂运行状态", "OPERATION_OVERVIEW",
|
||||
"dashboard-layout", Arrays.asList(createDefaultWidgets()), BIDashboard.STATUS_PUBLISHED),
|
||||
new BIDashboard(2L, "水质监测分析", "水质数据和趋势分析", "WATER_QUALITY_ANALYSIS",
|
||||
"quality-layout", Arrays.asList(createQualityWidgets()), BIDashboard.STATUS_PUBLISHED),
|
||||
new BIDashboard(3L, "能耗成本统计", "能耗和成本分析", "ENERGY_COST_STATISTICS",
|
||||
"energy-layout", Arrays.asList(createEnergyWidgets()), BIDashboard.STATUS_DRAFT)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BIDashboard getDashboardDetail(Long dashboardId) {
|
||||
// 根据ID获取仪表盘详情
|
||||
return listDashboards().stream()
|
||||
.filter(d -> d.getId().equals(dashboardId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDashboard(Long dashboardId, BIDashboard dashboard) {
|
||||
// 实现仪表盘更新逻辑
|
||||
dashboard.setId(dashboardId);
|
||||
dashboard.setUpdateTime(new Date());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createSpecialScreen(DataVisualization screen) {
|
||||
screen.setId(System.currentTimeMillis());
|
||||
screen.setCreateTime(new Date());
|
||||
return screen.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataVisualization> listSpecialScreens() {
|
||||
// 模拟专题大屏列表
|
||||
return List.of(
|
||||
new DataVisualization(1L, "大屏-供水调度中心", "实时供水调度监控", "调度大厅大屏"),
|
||||
new DataVisualization(2L, "大屏-水质监控中心", "水质实时监控大屏", "水质监控大屏"),
|
||||
new DataVisualization(3L, "大屏-应急管理", "突发应急事件监控", "应急管理大屏")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> generateChart(Map<String, Object> chartConfig) {
|
||||
// 根据配置生成图表
|
||||
String chartType = (String) chartConfig.getOrDefault("type", "line");
|
||||
String dataSource = (String) chartConfig.getOrDefault("dataSource", "water_consumption");
|
||||
|
||||
Map<String, Object> chart = new HashMap<>();
|
||||
chart.put("type", chartType);
|
||||
chart.put("title", chartConfig.getOrDefault("title", "数据图表"));
|
||||
chart.put("dataSource", dataSource);
|
||||
|
||||
// 生成模拟数据
|
||||
if ("line".equals(chartType)) {
|
||||
chart.put("data", generateLineChartData());
|
||||
} else if ("bar".equals(chartType)) {
|
||||
chart.put("data", generateBarChartData());
|
||||
} else if ("pie".equals(chartType)) {
|
||||
chart.put("data", generatePieChartData());
|
||||
}
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
private Map<String, Object> createDefaultWidgets() {
|
||||
Map<String, Object> widget = new HashMap<>();
|
||||
widget.put("type", "kpi");
|
||||
widget.put("title", "总供水量");
|
||||
widget.put("value", "125080 m³");
|
||||
widget.put("unit", "m³");
|
||||
widget.put("trend", "up");
|
||||
return widget;
|
||||
}
|
||||
|
||||
private Map<String, Object> createQualityWidgets() {
|
||||
Map<String, Object> widget = new HashMap<>();
|
||||
widget.put("type", "gauge");
|
||||
widget.put("title", "水质达标率");
|
||||
widget.put("value", "98.5%");
|
||||
widget.put("min", 0);
|
||||
widget.put("max", 100);
|
||||
return widget;
|
||||
}
|
||||
|
||||
private Map<String, Object> createEnergyWidgets() {
|
||||
Map<String, Object> widget = new HashMap<>();
|
||||
widget.put("type", "metric");
|
||||
widget.put("title", "日用电量");
|
||||
widget.put("value", "1250");
|
||||
widget.put("unit", "kWh");
|
||||
return widget;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> generateLineChartData() {
|
||||
List<Map<String, Object>> data = new ArrayList<>();
|
||||
for (int i = 1; i <= 30; i++) {
|
||||
Map<String, Object> point = new HashMap<>();
|
||||
point.put("x", "2026-06-" + String.format("%02d", i));
|
||||
point.put("y", 4000 + Math.random() * 1000);
|
||||
data.add(point);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> generateBarChartData() {
|
||||
List<Map<String, Object>> data = new ArrayList<>();
|
||||
String[] locations = {"一体化水厂", "精芒片区", "八家户片区", "托里片区", "大镇阿合其", "托托"};
|
||||
for (String location : locations) {
|
||||
Map<String, Object> bar = new HashMap<>();
|
||||
bar.put("name", location);
|
||||
bar.put("value", 3000 + Math.random() * 5000);
|
||||
data.add(bar);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> generatePieChartData() {
|
||||
List<Map<String, Object>> data = new ArrayList<>();
|
||||
Map<String, Object> pie1 = new HashMap<>();
|
||||
pie1.put("name", "生产用水");
|
||||
pie1.put("value", 65);
|
||||
|
||||
Map<String, Object> pie2 = new HashMap<>();
|
||||
pie2.put("name", "生活用水");
|
||||
pie2.put("value", 25);
|
||||
|
||||
Map<String, Object> pie3 = new HashMap<>();
|
||||
pie3.put("name", "消防用水");
|
||||
pie3.put("value", 10);
|
||||
|
||||
data.add(pie1);
|
||||
data.add(pie2);
|
||||
data.add(pie3);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.water.bi.service.impl;
|
||||
|
||||
import com.water.bi.service.DecisionSupportService;
|
||||
import com.water.bi.entity.DecisionModel;
|
||||
import com.water.bi.entity.DecisionResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 决策支持服务实现
|
||||
*/
|
||||
@Service
|
||||
public class DecisionSupportServiceImpl implements DecisionSupportService {
|
||||
|
||||
@Override
|
||||
public Long createDecisionModel(DecisionModel model) {
|
||||
model.setId(System.currentTimeMillis());
|
||||
model.setStatus("ACTIVE");
|
||||
model.setCreateTime(new Date());
|
||||
return model.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DecisionModel> listDecisionModels() {
|
||||
// 模拟决策模型列表
|
||||
return List.of(
|
||||
new DecisionModel(1L, "供水调度优化模型", "SCHEDULING_OPTIMIZATION", "ACTIVE"),
|
||||
new DecisionModel(2L, "需水量预测模型", "DEMAND_PREDICTION", "ACTIVE"),
|
||||
new DecisionModel(3L, "应急调度决策模型", "EMERGENCY_DISPATCH", "INACTIVE"),
|
||||
new DecisionModel(4L, "能耗优化模型", "ENERGY_OPTIMIZATION", "ACTIVE")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecisionResult executeDispatchDecision(Map<String, Object> decisionParams) {
|
||||
// 执行供水调度决策
|
||||
DecisionResult result = new DecisionResult();
|
||||
result.setId(System.currentTimeMillis());
|
||||
result.setDecisionType("SCHEDULING_OPTIMIZATION");
|
||||
result.setExecutionTime("2026-06-14T14:30:00");
|
||||
|
||||
// 模拟决策结果
|
||||
Map<String, Object> recommendation = new HashMap<>();
|
||||
recommendation.put("action", "increase_production");
|
||||
recommendation.put("target", "一体化水厂");
|
||||
recommendation.put("amount", 500);
|
||||
recommendation.put("reason", "预计下午用水高峰期需求增加");
|
||||
recommendation.put("confidence", "92%");
|
||||
|
||||
Map<String, Object> alternatives = new HashMap<>();
|
||||
alternatives.put("alternative1", "启动备用机组");
|
||||
alternatives.put("alternative2", "从邻近水厂调水");
|
||||
alternatives.put("alternative3", "启用储水池");
|
||||
|
||||
result.setRecommendation(recommendation);
|
||||
result.setAlternatives(alternatives);
|
||||
result.setRiskLevel("LOW");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> predictWaterDemand(Map<String, Object> predictionParams) {
|
||||
// 执行需水量预测
|
||||
String predictionType = (String) predictionParams.getOrDefault("type", "daily");
|
||||
String location = (String) predictionParams.getOrDefault("location", "一体化水厂");
|
||||
int days = (Integer) predictionParams.getOrDefault("days", 7);
|
||||
|
||||
Map<String, Object> prediction = new HashMap<>();
|
||||
prediction.put("location", location);
|
||||
prediction.put("type", predictionType);
|
||||
prediction.put("days", days);
|
||||
|
||||
// 生成预测数据
|
||||
List<Map<String, Object>> forecastData = new ArrayList<>();
|
||||
for (int i = 1; i <= days; i++) {
|
||||
Map<String, Object> dayForecast = new HashMap<>();
|
||||
dayForecast.put("day", "2026-06-" + String.format("%02d", 14 + i));
|
||||
dayForecast.put("predicted", 4000 + Math.random() * 1000);
|
||||
dayForecast.put("actual", null); // 实际数据为空,因为是预测
|
||||
forecastData.add(dayForecast);
|
||||
}
|
||||
|
||||
prediction.put("forecast", forecastData);
|
||||
prediction.put("accuracy", "95.2%");
|
||||
prediction.put("trend", "stable");
|
||||
prediction.put("peakExpected", "2026-06-20");
|
||||
|
||||
return prediction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DecisionResult> getDecisionHistory(int limit) {
|
||||
// 模拟决策历史
|
||||
List<DecisionResult> history = new ArrayList<>();
|
||||
for (int i = 1; i <= limit; i++) {
|
||||
DecisionResult result = new DecisionResult();
|
||||
result.setId(System.currentTimeMillis() - i * 3600000);
|
||||
result.setDecisionType("SCHEDULING_OPTIMIZATION");
|
||||
result.setExecutionTime("2026-06-14T" + String.format("%02d:00:00", 10 + i));
|
||||
result.setOutcome("SUCCESS");
|
||||
result.setConfidence("90%" + i);
|
||||
history.add(result);
|
||||
}
|
||||
return history;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> optimizeDispatchPlan(Map<String, Object> optimizeParams) {
|
||||
// 优化调度方案
|
||||
String optimizationGoal = (String) optimizeParams.getOrDefault("goal", "efficiency");
|
||||
|
||||
Map<String, Object> optimizedPlan = new HashMap<>();
|
||||
optimizedPlan.put("goal", optimizationGoal);
|
||||
optimizedPlan.put("executionTime", "2026-06-14T14:35:00");
|
||||
|
||||
// 优化结果
|
||||
Map<String, Object> efficiency = new HashMap<>();
|
||||
efficiency.put("currentEfficiency", "78%");
|
||||
efficiency.put("optimizedEfficiency", "85%");
|
||||
efficiency.put("improvement", "7%");
|
||||
efficiency.put("energySaving", "12%");
|
||||
|
||||
Map<String, Object> cost = new HashMap<>();
|
||||
cost.put("currentCost", "125000");
|
||||
cost.put("optimizedCost", "118000");
|
||||
cost.put("saving", "7000");
|
||||
cost.put("percentage", "5.6%");
|
||||
|
||||
optimizedPlan.put("efficiency", efficiency);
|
||||
optimizedPlan.put("cost", cost);
|
||||
optimizedPlan.put("feasibility", "HIGH");
|
||||
|
||||
return optimizedPlan;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.water.bi.service.impl;
|
||||
|
||||
import com.water.bi.service.MonitoringService;
|
||||
import com.water.bi.entity.MetricMonitor;
|
||||
import com.water.bi.entity.AlarmRule;
|
||||
import com.water.bi.entity.AlarmEvent;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据监控服务实现
|
||||
*/
|
||||
@Service
|
||||
public class MonitoringServiceImpl implements MonitoringService {
|
||||
|
||||
@Override
|
||||
public Long registerMetricMonitor(MetricMonitor monitor) {
|
||||
monitor.setId(System.currentTimeMillis());
|
||||
monitor.setStatus("ACTIVE");
|
||||
monitor.setCreateTime(new Date());
|
||||
monitor.setLastCheckTime(new Date());
|
||||
return monitor.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetricMonitor> listMetricMonitors() {
|
||||
// 模拟指标监控列表
|
||||
return List.of(
|
||||
new MetricMonitor(1L, "出厂水压力", "PRESSURE", "PRESSURE_OUT", "0.2-0.5MPa", "ACTIVE"),
|
||||
new MetricMonitor(2L, "出厂水流量", "FLOW", "FLOW_OUT", "1000-2000m³/h", "ACTIVE"),
|
||||
new MetricMonitor(3L, "水质浊度", "TURBIDITY", "TURBIDITY", "<1NTU", "ACTIVE"),
|
||||
new MetricMonitor(4L, "消毒剂余氯", "RESIDUAL_CHLORINE", "RESIDUAL_CHLORINE", "0.3-0.5mg/L", "ACTIVE"),
|
||||
new MetricMonitor(5L, "清水池液位", "LEVEL", "LEVEL_CLEAR_WATER", "2.5-3.5m", "INACTIVE")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRealtimeMetricData(Long metricId) {
|
||||
// 获取实时指标数据
|
||||
Map<String, Object> metricData = new HashMap<>();
|
||||
|
||||
// 根据metricId返回不同的模拟数据
|
||||
if (metricId.equals(1L)) {
|
||||
metricData.put("metricName", "出厂水压力");
|
||||
metricData.put("currentValue", 0.35);
|
||||
metricData.put("unit", "MPa");
|
||||
metricData.put("status", "NORMAL");
|
||||
metricData.put("trend", "stable");
|
||||
} else if (metricId.equals(2L)) {
|
||||
metricData.put("metricName", "出厂水流量");
|
||||
metricData.put("currentValue", 1250);
|
||||
metricData.put("unit", "m³/h");
|
||||
metricData.put("status", "NORMAL");
|
||||
metricData.put("trend", "upward");
|
||||
}
|
||||
|
||||
// 添加实时数据点
|
||||
List<Map<String, Object>> dataPoints = new ArrayList<>();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
Map<String, Object> point = new HashMap<>();
|
||||
point.put("time", "2026-06-14T" + String.format("%02d:%02d", 14 - i, 60 - i * 6));
|
||||
point.put("value", 1000 + Math.random() * 500);
|
||||
dataPoints.add(point);
|
||||
}
|
||||
metricData.put("dataPoints", dataPoints);
|
||||
|
||||
return metricData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createAlarmRule(AlarmRule rule) {
|
||||
rule.setId(System.currentTimeMillis());
|
||||
rule.setCreateTime(new Date());
|
||||
rule.setStatus("ACTIVE");
|
||||
return rule.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AlarmRule> listAlarmRules() {
|
||||
// 模拟报警规则列表
|
||||
return List.of(
|
||||
new AlarmRule(1L, "水压过高报警", "PRESSURE", "HIGH", ">0.5MPa", 1, "短信+邮件"),
|
||||
new AlarmRule(2L, "水质超标报警", "TURBIDITY", "HIGH", ">1NTU", 2, "电话+短信"),
|
||||
new AlarmRule(3L, "流量异常报警", "FLOW", "LOW", "<500m³/h", 1, "短信"),
|
||||
new AlarmRule(4L, "设备故障报警", "EQUIPMENT", "FAULT", "故障", 3, "电话+短信+邮件")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AlarmEvent> getAlarmEvents(int page, int size, String level) {
|
||||
// 模拟报警事件列表
|
||||
List<AlarmEvent> allEvents = Arrays.asList(
|
||||
new AlarmEvent(1L, "水压过高", "PRESSURE_HIGH", "HIGH", "2026-06-14T13:45:00", "待处理", "出厂水压力达到0.52MPa"),
|
||||
new AlarmEvent(2L, "流量异常", "FLOW_LOW", "LOW", "2026-06-14T12:30:00", "已确认", "清水池出水流量低于正常值"),
|
||||
new AlarmEvent(3L, "浊度超标", "TURBIDITY_HIGH", "HIGH", "2026-06-14T11:15:00", "已处理", "出厂水浊度1.2NTU"),
|
||||
new AlarmEvent(4L, "余氯不足", "RESIDUAL_LOW", "LOW", "2026-06-14T10:20:00", "待处理", "消毒剂余氯0.2mg/L"),
|
||||
new AlarmEvent(5L, "设备故障", "PUMP_FAULT", "CRITICAL", "2026-06-14T09:45:00", "已处理", "2号泵故障停机")
|
||||
);
|
||||
|
||||
// 根据等级过滤
|
||||
if (level != null && !level.isEmpty()) {
|
||||
allEvents = allEvents.stream()
|
||||
.filter(e -> e.getLevel().equals(level))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 分页
|
||||
int from = page * size;
|
||||
int to = Math.min(from + size, allEvents.size());
|
||||
|
||||
if (from >= allEvents.size()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return allEvents.subList(from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean confirmAlarmEvent(Long eventId) {
|
||||
// 确认报警事件
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getMonitoringDashboard() {
|
||||
// 获取监控仪表盘数据
|
||||
Map<String, Object> dashboard = new HashMap<>();
|
||||
|
||||
// 总览统计
|
||||
Map<String, Object> summary = new HashMap<>();
|
||||
summary.put("totalMetrics", 25);
|
||||
summary.put("activeAlarms", 3);
|
||||
summary.put("resolvedAlarms", 12);
|
||||
summary.put("normalMetrics", 22);
|
||||
dashboard.put("summary", summary);
|
||||
|
||||
// 实时指标状态
|
||||
List<Map<String, Object>> metricStatus = new ArrayList<>();
|
||||
metricStatus.add(createMetricStatus("出厂水压力", "NORMAL", "0.35MPa"));
|
||||
metricStatus.add(createMetricStatus("出厂水流量", "NORMAL", "1250m³/h"));
|
||||
metricStatus.add(createMetricStatus("水质浊度", "ALARM", "1.2NTU"));
|
||||
metricStatus.add(createMetricStatus("消毒剂余氯", "NORMAL", "0.4mg/L"));
|
||||
dashboard.put("metricStatus", metricStatus);
|
||||
|
||||
// 报警统计
|
||||
Map<String, Object> alarmStats = new HashMap<>();
|
||||
alarmStats.put("today", 5);
|
||||
alarmStats.put("week", 18);
|
||||
alarmStats.put("month", 65);
|
||||
alarmStats.put("levels", Map.of(
|
||||
"HIGH", 3,
|
||||
"MEDIUM", 8,
|
||||
"LOW", 12
|
||||
));
|
||||
dashboard.put("alarmStats", alarmStats);
|
||||
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
private Map<String, Object> createMetricStatus(String name, String status, String value) {
|
||||
Map<String, Object> metric = new HashMap<>();
|
||||
metric.put("name", name);
|
||||
metric.put("status", status);
|
||||
metric.put("value", value);
|
||||
return metric;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.water.bi.service.impl;
|
||||
|
||||
import com.water.bi.service.ReportService;
|
||||
import com.water.bi.entity.ReportTemplate;
|
||||
import com.water.bi.entity.ReportInstance;
|
||||
import com.water.bi.entity.ReportSchedule;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 报告生成服务实现
|
||||
*/
|
||||
@Service
|
||||
public class ReportServiceImpl implements ReportService {
|
||||
|
||||
@Override
|
||||
public Long createReportTemplate(ReportTemplate template) {
|
||||
template.setId(System.currentTimeMillis());
|
||||
template.setCreateTime(new Date());
|
||||
template.setStatus("ACTIVE");
|
||||
return template.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportTemplate> listReportTemplates() {
|
||||
// 模拟报告模板列表
|
||||
return List.of(
|
||||
new ReportTemplate(1L, "运营日报模板", "DAILY_OPERATION", "每日运营情况汇总", "日报"),
|
||||
new ReportTemplate(2L, "水质周报模板", "WATER_QUALITY_WEEKLY", "每周水质数据分析", "周报"),
|
||||
new ReportTemplate(3L, "能耗分析月报", "ENERGY_ANALYSIS_MONTHLY", "每月能耗和成本分析", "月报"),
|
||||
new ReportTemplate(4L, "调度决策报告", "DECISION_REPORT", "调度决策过程和结果", "专项报告")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long generateReportInstance(Map<String, Object> generateParams) {
|
||||
Long templateId = Long.parseLong(generateParams.get("templateId").toString());
|
||||
String reportType = (String) generateParams.get("type");
|
||||
|
||||
// 创建报告实例
|
||||
ReportInstance instance = new ReportInstance();
|
||||
instance.setId(System.currentTimeMillis());
|
||||
instance.setTemplateId(templateId);
|
||||
instance.setType(reportType);
|
||||
instance.setStatus("GENERATING");
|
||||
instance.setCreateTime(new Date());
|
||||
|
||||
return instance.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportInstance> listReportInstances() {
|
||||
// 模拟报告实例列表
|
||||
return List.of(
|
||||
new ReportInstance(1L, "运营日报", "2026-06-14运营日报", "COMPLETED", "2026-06-14T14:00:00"),
|
||||
new ReportInstance(2L, "水质周报", "第25周水质报告", "COMPLETED", "2026-06-14T13:30:00"),
|
||||
new ReportInstance(3L, "能耗分析月报", "2026年5月能耗分析", "GENERATING", null),
|
||||
new ReportInstance(4L, "调度决策报告", "2026-06-13调度决策", "PENDING", null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String downloadReport(Long instanceId) {
|
||||
// 模拟报告下载
|
||||
return "/reports/" + instanceId + "/report_" + instanceId + ".pdf";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createReportSchedule(ReportSchedule schedule) {
|
||||
schedule.setId(System.currentTimeMillis());
|
||||
schedule.setCreateTime(new Date());
|
||||
schedule.setStatus("ACTIVE");
|
||||
schedule.setNextExecuteTime(calculateNextExecuteTime(schedule.getSchedule()));
|
||||
return schedule.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportSchedule> listReportSchedules() {
|
||||
// 模拟定时报告列表
|
||||
return List.of(
|
||||
new ReportSchedule(1L, "运营日报定时生成", "DAILY_OPERATION", "DAILY", "09:00", true),
|
||||
new ReportSchedule(2L, "水质周报定时生成", "WATER_QUALITY_WEEKLY", "WEEKLY", "周一 10:00", true),
|
||||
new ReportSchedule(3L, "能耗分析月报", "ENERGY_ANALYSIS_MONTHLY", "MONTHLY", "01 08:00", true),
|
||||
new ReportSchedule(4L, "调度决策周报", "DECISION_WEEKLY", "WEEKLY", "周五 17:00", false)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateReportNow(Long templateId) {
|
||||
// 立即生成报告
|
||||
ReportTemplate template = listReportTemplates().stream()
|
||||
.filter(t -> t.getId().equals(templateId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (template != null) {
|
||||
return "正在生成" + template.getName() + "...";
|
||||
}
|
||||
return "模板不存在";
|
||||
}
|
||||
|
||||
private Date calculateNextExecuteTime(String schedule) {
|
||||
// 计算下次执行时间(简化版)
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1); // 默认明天执行
|
||||
return calendar.getTime();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,59 @@
|
||||
server:
|
||||
port: 8083
|
||||
port: 8086
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: wm-bi
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: localhost:8848
|
||||
namespace: public
|
||||
group: DEFAULT_GROUP
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/wm_bi
|
||||
url: jdbc:postgresql://localhost:5432/water_management
|
||||
username: postgres
|
||||
password: postgres
|
||||
driver-class-name: org.postgresql.Driver
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: true
|
||||
ddl-auto: none
|
||||
show-sql: false
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.PostgreSQLDialect
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: localhost:8848
|
||||
|
||||
# 数据采集配置
|
||||
bi:
|
||||
data-collection:
|
||||
interval: 30
|
||||
batch-size: 100
|
||||
thread-pool:
|
||||
core-size: 5
|
||||
max-size: 10
|
||||
queue-capacity: 1000
|
||||
|
||||
# 报表配置
|
||||
bi:
|
||||
report:
|
||||
template-path: /templates
|
||||
output-path: /reports
|
||||
max-size: 10MB
|
||||
|
||||
# 监控配置
|
||||
bi:
|
||||
monitoring:
|
||||
alert-enabled: true
|
||||
alert-cooldown: 300
|
||||
metrics-retention: 168h # 7天
|
||||
# MyBatis Plus配置
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
mapper-locations: classpath*:/mapper/**/*.xml
|
||||
type-aliases-package: com.water.bi.entity
|
||||
|
||||
# 缓存配置
|
||||
spring:
|
||||
cache:
|
||||
type: redis
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
password:
|
||||
database: 0
|
||||
timeout: 10000
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 8
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
max-wait: -1
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
timeout: 2592000
|
||||
activity-timeout: -1
|
||||
is-concurrent: true
|
||||
is-share: false
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
com.water.bi: debug
|
||||
org.springframework.web: debug
|
||||
com.water.bi: DEBUG
|
||||
org.springframework.web: DEBUG
|
||||
|
||||
# 监控配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,metrics
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
metrics:
|
||||
export:
|
||||
simple:
|
||||
enabled: true
|
||||
Reference in New Issue
Block a user