27 changed files with 1375 additions and 0 deletions
@ -0,0 +1,95 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.DayReportvo.*; |
|||
import cn.iocoder.yudao.module.alert.dao.domain.DayReport; |
|||
import cn.iocoder.yudao.module.alert.dao.service.DayReportService; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.time.ZoneId; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Tag(name = "日报") |
|||
@RestController |
|||
@RequestMapping("/alarm") |
|||
public class DayReportController { |
|||
private final DayReportService service; |
|||
|
|||
public DayReportController(DayReportService service) { |
|||
this.service = service; |
|||
} |
|||
@Operation(summary = "获取日报表数据") |
|||
@GetMapping("/daily-report") |
|||
public CommonResult<PageResult<AlarmDailyVO>> getDailyReport( |
|||
@RequestParam(required = false) String unit, |
|||
@RequestParam(required = false) String driverType, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date, |
|||
@RequestParam(defaultValue = "1") Integer pageNo, |
|||
@RequestParam(defaultValue = "10") Integer pageSize) { |
|||
|
|||
PageResult<DayReport> pageResult = service.getDailyAlarmData(unit, driverType, date, pageNo, pageSize); |
|||
List<AlarmDailyVO> vos = pageResult.getList().stream() |
|||
.map(this::convertToVO) |
|||
.collect(Collectors.toList()); |
|||
return CommonResult.success(new PageResult<>(vos, pageResult.getTotal())); |
|||
} |
|||
|
|||
private AlarmDailyVO convertToVO(DayReport domain) { |
|||
AlarmDailyVO vo = new AlarmDailyVO(); |
|||
vo.setId(domain.getId()); |
|||
vo.setInstanceName(domain.getInstanceName()); |
|||
vo.setTotalAlarms(domain.getTotalAlarms()); |
|||
vo.setHourCounts(domain.getHourCounts()); |
|||
vo.setAlarmDuration(domain.getAlarmDuration()); |
|||
vo.setHasDetails(true); // 添加详情标识
|
|||
return vo; |
|||
} |
|||
|
|||
@Operation(summary = "获取报警详情") |
|||
@GetMapping("/details/{instanceId}") |
|||
public CommonResult<List<AlarmDetailVO>> getDetails( |
|||
@PathVariable String instanceId, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { |
|||
|
|||
List<AlarmDetailVO> details = service.getAlarmDetails(instanceId, date).stream() |
|||
.map(domain -> { |
|||
AlarmDetailVO vo = new AlarmDetailVO(); |
|||
vo.setTagname(domain.getTagname()); |
|||
vo.setAlarmcount(domain.getAlarmcount()); |
|||
vo.setAlarmtime(domain.getAlarmtime()); |
|||
return vo; |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
return CommonResult.success(details); |
|||
} |
|||
|
|||
@Operation(summary = "获取光字牌报警详情") |
|||
@GetMapping("/gzp-details/{gzpName}") |
|||
public CommonResult<List<GzpAlarmDetailVO>> getGzpDetails( |
|||
@PathVariable String gzpName, |
|||
@RequestParam String instanceId, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { |
|||
|
|||
List<GzpAlarmDetailVO> details = service.getGzpAlarmDetails(gzpName, instanceId, date).stream() |
|||
.map(domain -> { |
|||
GzpAlarmDetailVO vo = new GzpAlarmDetailVO(); |
|||
vo.setGzpName(domain.getGzpName()); |
|||
vo.setStartTime(domain.getStartTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime()); |
|||
vo.setEndTime(domain.getEndTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime()); |
|||
vo.setDuration(domain.getExceedDuration()); |
|||
return vo; |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
return CommonResult.success(details); |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.DayReportvo; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
@Schema(description = "报警日报表视图对象") |
|||
public class AlarmDailyVO { |
|||
@Schema(description = "实例ID", example = "mp_123456") |
|||
private String id; |
|||
|
|||
@Schema(description = "实例名称", example = "锅炉1号压力传感器") |
|||
private String instanceName; |
|||
|
|||
@Schema( description= "总报警次数", example = "42") |
|||
private Integer totalAlarms; |
|||
|
|||
@Schema(description = "各小时报警数量", example = "{\"hour_0\":10,\"hour_1\":20}") |
|||
private Map<String, Integer> hourCounts; |
|||
|
|||
@Schema(description = "总报警时长(秒)", example = "8130") |
|||
private Long alarmDuration; |
|||
@Schema(description = "是否可查看详情", example = "true") |
|||
private Boolean hasDetails; |
|||
|
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.DayReportvo; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
@Schema(description = "报警详情视图对象") |
|||
public class AlarmDetailVO { |
|||
@Schema(description = "光字牌名称", example = "锅炉超压报警") |
|||
private String tagname; |
|||
|
|||
@Schema(description = "报警次数", example = "5") |
|||
private Integer alarmcount; |
|||
|
|||
@Schema(description = "报警时长(秒)", example = "1510") |
|||
private Long alarmtime; |
|||
} |
@ -0,0 +1,23 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.DayReportvo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
@Data |
|||
@Schema(description = "光字牌详情视图对象") |
|||
public class GzpAlarmDetailVO { |
|||
|
|||
@Schema(description = "光字牌名称", example = "锅炉压力高报警") |
|||
private String gzpName; |
|||
|
|||
@Schema(description = "开始时间", example = "2023-08-01 10:15:30") |
|||
private LocalDateTime startTime; |
|||
|
|||
@Schema(description = "结束时间", example = "2023-08-01 10:25:45") |
|||
private LocalDateTime endTime; |
|||
|
|||
@Schema(description = "超限时长(秒)", example = "615") |
|||
private Long duration; |
|||
} |
@ -0,0 +1,61 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis; |
|||
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.MonthReportvo.*; |
|||
import cn.iocoder.yudao.module.alert.dao.service.MonthReportService; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.time.YearMonth; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Tag(name = "管理后台 - 月报分析") |
|||
@RestController |
|||
@RequestMapping("/alarm") |
|||
public class MonthReportController { |
|||
|
|||
private final MonthReportService monthlyReportService; |
|||
|
|||
public MonthReportController(MonthReportService monthlyReportService) { |
|||
this.monthlyReportService = monthlyReportService; |
|||
} |
|||
|
|||
@Operation(summary = "获取月报表数据") |
|||
@GetMapping("/monthly-report") |
|||
public CommonResult<PageResult<AlarmMonthlyVO>> getMonthlyReport( |
|||
@RequestParam(required = false) String unit, |
|||
@RequestParam(required = false) String driverType, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM") YearMonth month, |
|||
@RequestParam(defaultValue = "1") Integer pageNo, |
|||
@RequestParam(defaultValue = "10") Integer pageSize) { |
|||
|
|||
PageResult<AlarmMonthlyVO> result = monthlyReportService.getMonthlyAlarmData(unit, driverType, month, pageNo, pageSize); |
|||
return CommonResult.success(result); |
|||
} |
|||
|
|||
@Operation(summary = "获取报警详情") |
|||
@GetMapping("/monthly-details/{instanceId}") |
|||
public CommonResult<List<AlarmDetailVO>> getMonthlyDetails( |
|||
@PathVariable String instanceId, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM") YearMonth month) { |
|||
|
|||
List<AlarmDetailVO> details = monthlyReportService.getAlarmDetails(instanceId, month); |
|||
return CommonResult.success(details); |
|||
} |
|||
|
|||
@Operation(summary = "获取光字牌报警详情") |
|||
@GetMapping("/monthly-gzp-details/{gzpName}") |
|||
public CommonResult<List<GzpAlarmDetailVO>> getGzpMonthlyDetails( |
|||
@PathVariable String gzpName, |
|||
@RequestParam String instanceId, |
|||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM") YearMonth month) { |
|||
|
|||
List<GzpAlarmDetailVO> details = monthlyReportService.getGzpAlarmDetails(gzpName, instanceId, month); |
|||
return CommonResult.success(details); |
|||
} |
|||
} |
|||
|
|||
|
@ -0,0 +1,18 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.MonthReportvo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
@Schema(description = "报警详情视图对象") |
|||
public class AlarmDetailVO { |
|||
|
|||
@Schema(description = "光字牌名称", example = "锅炉超压报警") |
|||
private String tagname; |
|||
|
|||
@Schema(description = "报警次数", example = "5") |
|||
private Integer alarmcount; |
|||
|
|||
@Schema(description = "报警时长(秒)", example = "1510") |
|||
private Long alarmtime; |
|||
} |
@ -0,0 +1,28 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.MonthReportvo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
@Schema(description = "报警月报表视图对象") |
|||
public class AlarmMonthlyVO { |
|||
|
|||
@Schema(description = "实例ID", example = "mp_123456") |
|||
private String id; |
|||
|
|||
@Schema(description = "实例名称", example = "锅炉1号压力传感器") |
|||
private String instanceName; |
|||
|
|||
@Schema(description = "总报警次数", example = "42") |
|||
private Integer totalAlarms; |
|||
|
|||
@Schema(description = "各天报警数量", example = "{\"day_1\":10,\"day_2\":20}") |
|||
private Map<String, Integer> dayCounts; |
|||
|
|||
@Schema(description = "总报警时长(秒)", example = "8130") |
|||
private Long alarmDuration; |
|||
|
|||
@Schema(description = "是否可查看详情", example = "true") |
|||
private Boolean hasDetails; |
|||
} |
@ -0,0 +1,22 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.MonthReportvo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import java.time.LocalDateTime; |
|||
|
|||
@Data |
|||
@Schema(description = "光字牌详情视图对象") |
|||
public class GzpAlarmDetailVO { |
|||
|
|||
@Schema(description = "光字牌名称", example = "锅炉压力高报警") |
|||
private String gzpName; |
|||
|
|||
@Schema(description = "开始时间", example = "2023-08-01 10:15:30") |
|||
private LocalDateTime startTime; |
|||
|
|||
@Schema(description = "结束时间", example = "2023-08-01 10:25:45") |
|||
private LocalDateTime endTime; |
|||
|
|||
@Schema(description = "超限时长(秒)", example = "615") |
|||
private Long duration; |
|||
} |
@ -0,0 +1,95 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.YearReportvo.*; |
|||
import cn.iocoder.yudao.module.alert.dao.domain.YearReport; |
|||
import cn.iocoder.yudao.module.alert.dao.service.YearReportService; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.time.ZoneId; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Tag(name = "年报") |
|||
@RestController |
|||
@RequestMapping("/alarm") |
|||
public class YearReportController { |
|||
private final YearReportService service; |
|||
|
|||
public YearReportController(YearReportService service) { |
|||
this.service = service; |
|||
} |
|||
|
|||
@Operation(summary = "获取年报表数据") |
|||
@GetMapping("/yearly-report") |
|||
public CommonResult<PageResult<AlarmYearlyVO>> getYearlyReport( |
|||
@RequestParam(required = false) String unit, |
|||
@RequestParam(required = false) String driverType, |
|||
@RequestParam(required = false) Integer year, |
|||
@RequestParam(defaultValue = "1") Integer pageNo, |
|||
@RequestParam(defaultValue = "10") Integer pageSize) { |
|||
|
|||
PageResult<YearReport> pageResult = service.getYearlyAlarmData(unit, driverType, year, pageNo, pageSize); |
|||
List<AlarmYearlyVO> vos = pageResult.getList().stream() |
|||
.map(this::convertToVO) |
|||
.collect(Collectors.toList()); |
|||
return CommonResult.success(new PageResult<>(vos, pageResult.getTotal())); |
|||
} |
|||
|
|||
private AlarmYearlyVO convertToVO(YearReport domain) { |
|||
AlarmYearlyVO vo = new AlarmYearlyVO(); |
|||
vo.setId(domain.getId()); |
|||
vo.setInstanceName(domain.getInstanceName()); |
|||
vo.setTotalAlarms(domain.getTotalAlarms()); |
|||
vo.setMonthCounts(domain.getMonthCounts()); |
|||
vo.setAlarmDuration(domain.getAlarmDuration()); |
|||
vo.setHasDetails(true); |
|||
return vo; |
|||
} |
|||
|
|||
@Operation(summary = "获取报警详情") |
|||
@GetMapping("/yearly-details/{instanceId}") |
|||
public CommonResult<List<AlarmDetailVO>> getYearlyDetails( |
|||
@PathVariable String instanceId, |
|||
@RequestParam(required = false) Integer year) { |
|||
|
|||
List<AlarmDetailVO> details = service.getAlarmDetails(instanceId, year).stream() |
|||
.map(domain -> { |
|||
AlarmDetailVO vo = new AlarmDetailVO(); |
|||
vo.setTagname(domain.getTagname()); |
|||
vo.setAlarmcount(domain.getAlarmcount()); |
|||
vo.setAlarmtime(domain.getAlarmtime()); |
|||
return vo; |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
return CommonResult.success(details); |
|||
} |
|||
|
|||
@Operation(summary = "获取光字牌报警详情") |
|||
@GetMapping("/yearly-gzp-details/{gzpName}") |
|||
public CommonResult<List<GzpAlarmDetailVO>> getGzpYearlyDetails( |
|||
@PathVariable String gzpName, |
|||
@RequestParam String instanceId, |
|||
@RequestParam(required = false) Integer year) { |
|||
|
|||
List<GzpAlarmDetailVO> details = service.getGzpAlarmDetails(gzpName, instanceId, year).stream() |
|||
.map(domain -> { |
|||
GzpAlarmDetailVO vo = new GzpAlarmDetailVO(); |
|||
vo.setGzpName(domain.getGzpName()); |
|||
vo.setStartTime(domain.getStartTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime()); |
|||
vo.setEndTime(domain.getEndTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime()); |
|||
vo.setDuration(domain.getExceedDuration()); |
|||
return vo; |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
return CommonResult.success(details); |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.YearReportvo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
@Schema(description = "报警详情视图对象") |
|||
public class AlarmDetailVO { |
|||
|
|||
@Schema(description = "光字牌名称", example = "锅炉超压报警") |
|||
private String tagname; |
|||
|
|||
@Schema(description = "报警次数", example = "5") |
|||
private Integer alarmcount; |
|||
|
|||
@Schema(description = "报警时长(秒)", example = "1510") |
|||
private Long alarmtime; |
|||
} |
@ -0,0 +1,27 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.YearReportvo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
@Schema(description = "报警年报表视图对象") |
|||
public class AlarmYearlyVO { |
|||
@Schema(description = "实例ID", example = "mp_123456") |
|||
private String id; |
|||
|
|||
@Schema(description = "实例名称", example = "锅炉1号压力传感器") |
|||
private String instanceName; |
|||
|
|||
@Schema(description = "总报警次数", example = "42") |
|||
private Integer totalAlarms; |
|||
|
|||
@Schema(description = "各月报警数量", example = "{\"month_1\":10,\"month_2\":20}") |
|||
private Map<String, Integer> monthCounts; |
|||
|
|||
@Schema(description = "总报警时长(秒)", example = "8130") |
|||
private Long alarmDuration; |
|||
|
|||
@Schema(description = "是否可查看详情", example = "true") |
|||
private Boolean hasDetails; |
|||
} |
@ -0,0 +1,22 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.YearReportvo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import java.time.LocalDateTime; |
|||
|
|||
@Data |
|||
@Schema(description = "光字牌详情视图对象") |
|||
public class GzpAlarmDetailVO { |
|||
|
|||
@Schema(description = "光字牌名称", example = "锅炉压力高报警") |
|||
private String gzpName; |
|||
|
|||
@Schema(description = "开始时间", example = "2023-08-01 10:15:30") |
|||
private LocalDateTime startTime; |
|||
|
|||
@Schema(description = "结束时间", example = "2023-08-01 10:25:45") |
|||
private LocalDateTime endTime; |
|||
|
|||
@Schema(description = "超限时长(秒)", example = "615") |
|||
private Long duration; |
|||
} |
@ -0,0 +1,56 @@ |
|||
package cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import lombok.Data; |
|||
import java.util.Date; |
|||
@Data |
|||
public class dayDO { |
|||
private Long id; |
|||
private String warnId; |
|||
private Date startTime; |
|||
private Date endTime; |
|||
|
|||
@TableField("超限时长") |
|||
private Long exceedDuration; // 超限时长(秒)
|
|||
|
|||
private String year; |
|||
|
|||
private Integer month; |
|||
private Integer day; |
|||
|
|||
private Integer hour; |
|||
private String timeFlag; |
|||
|
|||
private String mpId; |
|||
private String unitId; |
|||
|
|||
private String systemTypeName; |
|||
private String systemName; |
|||
private String systemTypeId; |
|||
private String systemId; |
|||
private String algorithmId; |
|||
private String modelId; |
|||
private String mpName; // 实例名称
|
|||
private String alarmTypeId; |
|||
|
|||
@TableField("UNIT") |
|||
private String unit; // 机组
|
|||
|
|||
private String alarmLevelName; |
|||
private String alarmModelRuleName; |
|||
private String pointId; |
|||
private String pointName; |
|||
private String modelOrRuleName; |
|||
private String warnStatus1; |
|||
private String pointOrModel; |
|||
private String gzpName; // 光字牌名称
|
|||
private Integer alarmCount; |
|||
@TableField("Algorithm_ShortName") |
|||
private String algorithmShortName; |
|||
@TableField("Confirmed") |
|||
private Boolean confirmed; |
|||
@TableField("SUGGESTION") |
|||
private String suggestion; |
|||
|
|||
private Date confirmTime; |
|||
private String modelName; |
|||
} |
@ -0,0 +1,67 @@ |
|||
package cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@TableName("WARN_HISTORY_VIEW") |
|||
public class monthDO { |
|||
private Long id; |
|||
private String warnId; |
|||
private Date startTime; |
|||
private Date endTime; |
|||
|
|||
@TableField("超限时长") |
|||
private Long exceedDuration; |
|||
|
|||
private String year; |
|||
private Integer month; |
|||
private Integer day; |
|||
private Integer hour; |
|||
private String timeFlag; |
|||
|
|||
private String mpId; |
|||
private String unitId; |
|||
|
|||
private String systemTypeName; |
|||
private String systemName; |
|||
private String systemTypeId; |
|||
private String systemId; |
|||
private String algorithmId; |
|||
private String modelId; |
|||
|
|||
@TableField("mpName") |
|||
private String mpName; |
|||
|
|||
private String alarmTypeId; |
|||
|
|||
@TableField("UNIT") |
|||
private String unit; |
|||
|
|||
private String alarmLevelName; |
|||
private String alarmModelRuleName; |
|||
private String pointId; |
|||
private String pointName; |
|||
private String modelOrRuleName; |
|||
private String warnStatus1; |
|||
private String pointOrModel; |
|||
|
|||
@TableField("gzpName") |
|||
private String gzpName; |
|||
|
|||
private Integer alarmCount; |
|||
|
|||
@TableField("Algorithm_ShortName") |
|||
private String algorithmShortName; |
|||
|
|||
@TableField("Confirmed") |
|||
private Boolean confirmed; |
|||
|
|||
@TableField("SUGGESTION") |
|||
private String suggestion; |
|||
|
|||
private Date confirmTime; |
|||
private String modelName; |
|||
} |
@ -0,0 +1,59 @@ |
|||
package cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import lombok.Data; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
public class yearDO { |
|||
private Long id; |
|||
private String warnId; |
|||
private Date startTime; |
|||
private Date endTime; |
|||
|
|||
@TableField("超限时长") |
|||
private Long exceedDuration; // 超限时长(秒)
|
|||
|
|||
private Integer year; |
|||
private Integer month; |
|||
private Integer day; |
|||
private Integer hour; |
|||
private String timeFlag; |
|||
|
|||
private String mpId; |
|||
private String unitId; |
|||
|
|||
private String systemTypeName; |
|||
private String systemName; |
|||
private String systemTypeId; |
|||
private String systemId; |
|||
private String algorithmId; |
|||
private String modelId; |
|||
private String mpName; // 实例名称
|
|||
private String alarmTypeId; |
|||
|
|||
@TableField("UNIT") |
|||
private String unit; // 机组
|
|||
|
|||
private String alarmLevelName; |
|||
private String alarmModelRuleName; |
|||
private String pointId; |
|||
private String pointName; |
|||
private String modelOrRuleName; |
|||
private String warnStatus1; |
|||
private String pointOrModel; |
|||
private String gzpName; // 光字牌名称
|
|||
private Integer alarmCount; |
|||
|
|||
@TableField("Algorithm_ShortName") |
|||
private String algorithmShortName; |
|||
|
|||
@TableField("Confirmed") |
|||
private Boolean confirmed; |
|||
|
|||
@TableField("SUGGESTION") |
|||
private String suggestion; |
|||
|
|||
private Date confirmTime; |
|||
private String modelName; |
|||
} |
@ -0,0 +1,16 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.domain; |
|||
import lombok.Data; |
|||
import java.util.Map; |
|||
@Data |
|||
public class DayReport { |
|||
private String id; |
|||
private String instanceName; |
|||
private Integer totalAlarms; |
|||
private Long alarmDuration; |
|||
private Map<String, Integer> hourCounts; |
|||
|
|||
// 详情用
|
|||
private String tagname; |
|||
private Integer alarmcount; |
|||
private Long alarmtime; |
|||
} |
@ -0,0 +1,24 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.domain; |
|||
|
|||
import lombok.Data; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
public class MonthReport { |
|||
private String id; |
|||
private String instanceName; |
|||
private Integer totalAlarms; |
|||
private Long alarmDuration; |
|||
private Map<String, Integer> dayCounts; |
|||
|
|||
// 详情用字段
|
|||
private String tagname; |
|||
private Integer alarmcount; |
|||
private Long alarmtime; |
|||
|
|||
// 光字牌详情用字段
|
|||
private String gzpName; |
|||
private java.util.Date startTime; |
|||
private java.util.Date endTime; |
|||
private Long exceedDuration; |
|||
} |
@ -0,0 +1,18 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.domain; |
|||
|
|||
import lombok.Data; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
public class YearReport { |
|||
private String id; |
|||
private String instanceName; |
|||
private Integer totalAlarms; |
|||
private Long alarmDuration; |
|||
private Map<String, Integer> monthCounts; |
|||
|
|||
// 详情用
|
|||
private String tagname; |
|||
private Integer alarmcount; |
|||
private Long alarmtime; |
|||
} |
@ -0,0 +1,51 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.mapper; |
|||
|
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.dayDO; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Mapper |
|||
public interface DayReportMapper extends BaseMapper<dayDO> { |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"<where>" + |
|||
" <if test='unit != null'> AND unit_id = #{unit} </if>" + |
|||
" <if test='driverType != null'> AND model_or_rule_name = #{driverType} </if>" + |
|||
" <if test='date != null'> " + |
|||
" AND YY = YEAR(#{date}) AND MM = MONTH(#{date}) AND DD = DAY(#{date}) " + |
|||
" </if>" + |
|||
"</where>" + |
|||
"</script>") |
|||
List<dayDO> selectByCondition( |
|||
@Param("unit") String unit, |
|||
@Param("driverType") String driverType, |
|||
@Param("date") String date); |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"WHERE mp_id = #{instanceId} " + |
|||
"<if test='date != null'> " + |
|||
" AND YY = YEAR(#{date}) AND MM = MONTH(#{date}) AND DD = DAY(#{date}) " + |
|||
"</if>" + |
|||
"</script>") |
|||
List<dayDO> selectDetailsByInstanceId( |
|||
@Param("instanceId") String instanceId, |
|||
@Param("date") String date); |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"WHERE mp_id = #{instanceId} AND gzp_name = #{gzpName} " + |
|||
"<if test='date != null'> " + |
|||
" AND YY = YEAR(#{date}) AND MM = MONTH(#{date}) AND DD = DAY(#{date}) " + |
|||
"</if>" + |
|||
"</script>") |
|||
List<dayDO> selectGzpDetails( |
|||
@Param("gzpName") String gzpName, |
|||
@Param("instanceId") String instanceId, |
|||
@Param("date") String date); |
|||
} |
@ -0,0 +1,53 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.mapper; |
|||
|
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.monthDO; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Mapper |
|||
public interface MonthReportMapper extends BaseMapper<monthDO>{ |
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"<where>" + |
|||
" <if test='unit != null'> AND unit_id = #{unit} </if>" + |
|||
" <if test='driverType != null'> AND model_or_rule_name = #{driverType} </if>" + |
|||
" <if test='year != null and month != null'> " + |
|||
" AND YY = #{year} AND MM = #{month} " + |
|||
" </if>" + |
|||
"</where>" + |
|||
"</script>") |
|||
List<monthDO> selectByCondition( |
|||
@Param("unit") String unit, |
|||
@Param("driverType") String driverType, |
|||
@Param("year") Integer year, |
|||
@Param("month") Integer month); |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"WHERE mp_id = #{instanceId} " + |
|||
"<if test='year != null and month != null'> " + |
|||
" AND YY = #{year} AND MM = #{month} " + |
|||
"</if>" + |
|||
"</script>") |
|||
List<monthDO> selectDetailsByInstanceId( |
|||
@Param("instanceId") String instanceId, |
|||
@Param("year") Integer year, |
|||
@Param("month") Integer month); |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"WHERE mp_id = #{instanceId} AND gzp_name = #{gzpName} " + |
|||
"<if test='year != null and month != null'> " + |
|||
" AND YY = #{year} AND MM = #{month} " + |
|||
"</if>" + |
|||
"</script>") |
|||
List<monthDO> selectGzpDetails( |
|||
@Param("gzpName") String gzpName, |
|||
@Param("instanceId") String instanceId, |
|||
@Param("year") Integer year, |
|||
@Param("month") Integer month); |
|||
} |
@ -0,0 +1,45 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.mapper; |
|||
|
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.yearDO; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.apache.ibatis.annotations.Select; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Mapper |
|||
public interface YearReportMapper extends BaseMapper<yearDO> { |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"<where>" + |
|||
" <if test='unit != null'> AND unit_id = #{unit} </if>" + |
|||
" <if test='driverType != null'> AND MODEL_OR_RULE_NAME = #{driverType} </if>" + |
|||
" <if test='year != null'> AND YY = #{year} </if>" + |
|||
"</where>" + |
|||
"</script>") |
|||
List<yearDO> selectByCondition( |
|||
@Param("unit") String unit, |
|||
@Param("driverType") String driverType, |
|||
@Param("year") Integer year); |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"WHERE mp_id = #{instanceId} " + |
|||
"<if test='year != null'> AND YY = #{year} </if>" + |
|||
"</script>") |
|||
List<yearDO> selectDetailsByInstanceId( |
|||
@Param("instanceId") String instanceId, |
|||
@Param("year") Integer year); |
|||
|
|||
@Select("<script>" + |
|||
"SELECT * FROM WARN_HISTORY_VIEW " + |
|||
"WHERE mp_id = #{instanceId} AND gzp_name = #{gzpName} " + |
|||
"<if test='year != null'> AND YY = #{year} </if>" + |
|||
"</script>") |
|||
List<yearDO> selectGzpDetails( |
|||
@Param("gzpName") String gzpName, |
|||
@Param("instanceId") String instanceId, |
|||
@Param("year") Integer year); |
|||
} |
@ -0,0 +1,31 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.service; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.dayDO; |
|||
import cn.iocoder.yudao.module.alert.dao.domain.DayReport; |
|||
import java.time.LocalDate; |
|||
import java.util.List; |
|||
|
|||
public interface DayReportService { |
|||
/** |
|||
* 获取日报表数据(分页版本) |
|||
*/ |
|||
PageResult<DayReport> getDailyAlarmData(String unit, String driverType, LocalDate date, int pageNo, int pageSize); |
|||
|
|||
/** |
|||
* 获取报警详情 |
|||
*/ |
|||
List<DayReport> getAlarmDetails(String instanceId, LocalDate date); |
|||
/** |
|||
* @deprecated 使用分页版本 {@link #getDailyAlarmData(String, String, LocalDate, int, int)} 代替 |
|||
*/ |
|||
@Deprecated |
|||
default List<DayReport> getDailyAlarmData(String unit, String driverType, String date) { |
|||
return getDailyAlarmData(unit, driverType, date != null ? LocalDate.parse(date) : null, 1, Integer.MAX_VALUE).getList(); |
|||
} |
|||
|
|||
/** |
|||
* 获取光字牌报警详情 |
|||
*/ |
|||
List<dayDO> getGzpAlarmDetails(String gzpName, String instanceId, LocalDate date); |
|||
} |
@ -0,0 +1,22 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.service; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.MonthReportvo.*; |
|||
import java.time.YearMonth; |
|||
import java.util.List; |
|||
public interface MonthReportService { |
|||
/** |
|||
* 获取月报表数据 |
|||
*/ |
|||
PageResult<AlarmMonthlyVO> getMonthlyAlarmData(String unit, String driverType, YearMonth month, int pageNo, int pageSize); |
|||
|
|||
/** |
|||
* 获取报警详情 |
|||
*/ |
|||
List<AlarmDetailVO> getAlarmDetails(String instanceId, YearMonth month); |
|||
|
|||
/** |
|||
* 获取光字牌报警详情 |
|||
*/ |
|||
List<GzpAlarmDetailVO> getGzpAlarmDetails(String gzpName, String instanceId, YearMonth month); |
|||
} |
@ -0,0 +1,23 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.service; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.yearDO; |
|||
import cn.iocoder.yudao.module.alert.dao.domain.YearReport; |
|||
import java.util.List; |
|||
|
|||
public interface YearReportService { |
|||
/** |
|||
* 获取年报表数据(分页版本) |
|||
*/ |
|||
PageResult<YearReport> getYearlyAlarmData(String unit, String driverType, Integer year, int pageNo, int pageSize); |
|||
|
|||
/** |
|||
* 获取报警详情 |
|||
*/ |
|||
List<YearReport> getAlarmDetails(String instanceId, Integer year); |
|||
|
|||
/** |
|||
* 获取光字牌报警详情 |
|||
*/ |
|||
List<yearDO> getGzpAlarmDetails(String gzpName, String instanceId, Integer year); |
|||
} |
@ -0,0 +1,156 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.service.impl; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.dayDO; |
|||
import cn.iocoder.yudao.module.alert.dao.domain.DayReport; |
|||
import cn.iocoder.yudao.module.alert.dao.mapper.DayReportMapper; |
|||
import cn.iocoder.yudao.module.alert.dao.service.DayReportService; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import java.time.*; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Service |
|||
public class DayReportServiceImpl implements DayReportService { |
|||
|
|||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.BASIC_ISO_DATE; |
|||
|
|||
private final DayReportMapper dayReportMapper; |
|||
|
|||
public DayReportServiceImpl(DayReportMapper dayReportMapper) { |
|||
this.dayReportMapper = dayReportMapper; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public PageResult<DayReport> getDailyAlarmData(String unit, String driverType, LocalDate date, int pageNo, int pageSize) { |
|||
Page<dayDO> page = new Page<>(pageNo, pageSize); |
|||
String formattedDate = (date != null) ? date.format(DATE_FORMATTER) : null; |
|||
|
|||
List<dayDO> rawData = dayReportMapper.selectByCondition( unit, driverType, formattedDate); |
|||
if (CollectionUtils.isEmpty(rawData)) { |
|||
return new PageResult<>(Collections.emptyList(), 0L); |
|||
} |
|||
|
|||
// 动态计算 exceedDuration、year、month、day、hour
|
|||
rawData.forEach(this::calculateDynamicFields); |
|||
|
|||
Map<String, List<dayDO>> groupByInstance = rawData.stream() |
|||
.collect(Collectors.groupingBy(dayDO::getMpName)); |
|||
|
|||
// 4. 获取所有 instanceName 并按分页截取
|
|||
List<String> instanceNames = new ArrayList<>(groupByInstance.keySet()); |
|||
Long totalInstances = (long) instanceNames.size(); |
|||
|
|||
// 5. 计算分页范围
|
|||
int fromIndex = (pageNo - 1) * pageSize; |
|||
if (fromIndex >= totalInstances) { |
|||
return new PageResult<>(Collections.emptyList(), (long) totalInstances); |
|||
} |
|||
int toIndex = (int) Math.min(fromIndex + pageSize, totalInstances); |
|||
List<String> pagedInstanceNames = instanceNames.subList(fromIndex, toIndex); |
|||
|
|||
// 6. 构建分页结果
|
|||
List<DayReport> result = pagedInstanceNames.stream() |
|||
.map(instanceName -> { |
|||
List<dayDO> instanceData = groupByInstance.get(instanceName); |
|||
return buildDayReport(instanceName, instanceData); |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
|
|||
return new PageResult<>(result, (Long) totalInstances); |
|||
} |
|||
|
|||
@Override |
|||
public List<DayReport> getAlarmDetails(String instanceId, LocalDate date) { |
|||
// 1. 查询原始数据(按 instanceId + 日期)
|
|||
List<dayDO> rawData = dayReportMapper.selectDetailsByInstanceId( |
|||
instanceId, |
|||
date != null ? date.format(DATE_FORMATTER) : null |
|||
); |
|||
|
|||
if (CollectionUtils.isEmpty(rawData)) { |
|||
return Collections.emptyList(); |
|||
} |
|||
|
|||
// 2. 动态计算 exceedDuration
|
|||
rawData.forEach(this::calculateDynamicFields); |
|||
|
|||
// 3. 按 GZP_NAME 分组
|
|||
Map<String, List<dayDO>> groupByGzp = rawData.stream() |
|||
.collect(Collectors.groupingBy(dayDO::getGzpName)); |
|||
|
|||
// 4. 构建返回结果
|
|||
List<DayReport> result = new ArrayList<>(groupByGzp.size()); |
|||
groupByGzp.forEach((gzpName, gzpData) -> { |
|||
DayReport domain = new DayReport(); |
|||
domain.setTagname(gzpName); |
|||
domain.setAlarmcount(gzpData.size()); |
|||
domain.setAlarmtime(gzpData.stream() |
|||
.mapToLong(item -> item.getExceedDuration() != null ? item.getExceedDuration() : 0L) |
|||
.sum()); |
|||
result.add(domain); |
|||
}); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public List<dayDO> getGzpAlarmDetails(String gzpName, String instanceId, LocalDate date) { |
|||
String formattedDate = (date != null) ? date.format(DATE_FORMATTER) : null; |
|||
List<dayDO> rawData = dayReportMapper.selectGzpDetails(gzpName, instanceId, formattedDate); |
|||
rawData.forEach(this::calculateDynamicFields); |
|||
return rawData; |
|||
} |
|||
/** |
|||
* 动态计算字段:exceedDuration、year、month、day、hour |
|||
*/ |
|||
private void calculateDynamicFields(dayDO item) { |
|||
if (item.getStartTime() != null && item.getEndTime() != null) { |
|||
// 计算超限时长(秒)
|
|||
long durationSeconds = Duration.between( |
|||
item.getStartTime().toInstant(), |
|||
item.getEndTime().toInstant() |
|||
).getSeconds(); |
|||
item.setExceedDuration(durationSeconds); |
|||
|
|||
// 计算年、月、日、小时
|
|||
LocalDateTime localStart = item.getStartTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime(); |
|||
item.setYear(String.valueOf(localStart.getYear())); |
|||
item.setMonth(localStart.getMonthValue()); |
|||
item.setDay(localStart.getDayOfMonth()); |
|||
item.setHour(localStart.getHour()); |
|||
|
|||
} |
|||
} |
|||
|
|||
private DayReport buildDayReport(String instanceName, List<dayDO> instanceData) { |
|||
DayReport domain = new DayReport(); |
|||
domain.setId(instanceData.get(0).getMpId()); |
|||
domain.setInstanceName(instanceName); |
|||
domain.setTotalAlarms(instanceData.size()); |
|||
domain.setAlarmDuration(instanceData.stream() |
|||
.mapToLong(item -> item.getExceedDuration() != null ? item.getExceedDuration() : 0) |
|||
.sum()); |
|||
domain.setHourCounts(calculateHourlyCounts(instanceData)); |
|||
return domain; |
|||
} |
|||
|
|||
private Map<String, Integer> calculateHourlyCounts(List<dayDO> data) { |
|||
Map<String, Integer> hourCounts = new HashMap<>(24); |
|||
for (int i = 0; i < 24; i++) { |
|||
final int hour = i; |
|||
hourCounts.put("hour_" + i, (int) data.stream() |
|||
.filter(item -> item.getHour() != null && item.getHour() == hour) |
|||
.count()); |
|||
|
|||
} |
|||
return hourCounts; |
|||
} |
|||
} |
@ -0,0 +1,169 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.service.impl; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.alarm.analysis.MonthReportvo.*; |
|||
import cn.iocoder.yudao.module.alert.dao.service.MonthReportService; |
|||
import cn.iocoder.yudao.module.alert.dao.mapper.MonthReportMapper; |
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.monthDO; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import java.time.*; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Service |
|||
public class MonthReportServiceImpl implements MonthReportService { |
|||
private final MonthReportMapper monthlyReportMapper; |
|||
|
|||
public MonthReportServiceImpl(MonthReportMapper monthlyReportMapper) { |
|||
this.monthlyReportMapper = monthlyReportMapper; |
|||
} |
|||
|
|||
@Override |
|||
public PageResult<AlarmMonthlyVO> getMonthlyAlarmData(String unit, String driverType, YearMonth month, int pageNo, int pageSize) { |
|||
|
|||
Integer year = month != null ? month.getYear() : null; |
|||
Integer monthValue = month != null ? month.getMonthValue() : null; |
|||
List<monthDO> rawData = monthlyReportMapper.selectByCondition(unit, driverType, year, monthValue); |
|||
if (CollectionUtils.isEmpty(rawData)) { |
|||
return new PageResult<>(Collections.emptyList(), 0L); |
|||
} |
|||
// 动态计算字段
|
|||
rawData.forEach(this::calculateDynamicFields); |
|||
|
|||
// 按实例名称分组
|
|||
Map<String, List<monthDO>> groupByInstance = rawData.stream() |
|||
.collect(Collectors.groupingBy(monthDO::getMpName)); |
|||
|
|||
List<String> instanceNames = new ArrayList<>(groupByInstance.keySet()); |
|||
Long totalInstances = (long) instanceNames.size(); |
|||
|
|||
// 分页处理
|
|||
int fromIndex = (pageNo - 1) * pageSize; |
|||
if (fromIndex >= totalInstances) { |
|||
return new PageResult<>(Collections.emptyList(), totalInstances); |
|||
} |
|||
int toIndex = (int) Math.min(fromIndex + pageSize, totalInstances); |
|||
List<String> pagedInstanceNames = instanceNames.subList(fromIndex, toIndex); |
|||
// 构建结果
|
|||
List<AlarmMonthlyVO> result = pagedInstanceNames.stream() |
|||
.map(instanceName -> { |
|||
List<monthDO> instanceData = groupByInstance.get(instanceName); |
|||
return buildMonthlyVO(instanceName, instanceData, month); |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
|
|||
return new PageResult<>(result, totalInstances); |
|||
} |
|||
|
|||
@Override |
|||
public List<AlarmDetailVO> getAlarmDetails(String instanceId, YearMonth month) { |
|||
Integer year = month != null ? month.getYear() : null; |
|||
Integer monthValue = month != null ? month.getMonthValue() : null; |
|||
|
|||
List<monthDO> rawData = monthlyReportMapper.selectDetailsByInstanceId(instanceId, year, monthValue); |
|||
if (CollectionUtils.isEmpty(rawData)) { |
|||
return Collections.emptyList(); |
|||
} |
|||
|
|||
for (monthDO rawDatum : rawData) { |
|||
calculateDynamicFields(rawDatum); |
|||
} |
|||
|
|||
// 按光字牌名称分组
|
|||
Map<String, List<monthDO>> groupByGzp = rawData.stream() |
|||
.collect(Collectors.groupingBy(monthDO::getGzpName)); |
|||
|
|||
List<AlarmDetailVO> result = new ArrayList<>(); |
|||
groupByGzp.forEach((gzpName, gzpData) -> { |
|||
AlarmDetailVO vo = new AlarmDetailVO(); |
|||
vo.setTagname(gzpName); |
|||
vo.setAlarmcount(gzpData.size()); |
|||
vo.setAlarmtime(gzpData.stream() |
|||
.mapToLong(item -> item.getExceedDuration() != null ? item.getExceedDuration() : 0L) |
|||
.sum()); |
|||
result.add(vo); |
|||
}); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public List<GzpAlarmDetailVO> getGzpAlarmDetails(String gzpName, String instanceId, YearMonth month) { |
|||
Integer year = month != null ? month.getYear() : null; |
|||
Integer monthValue = month != null ? month.getMonthValue() : null; |
|||
|
|||
List<monthDO> rawData = monthlyReportMapper.selectGzpDetails(gzpName, instanceId, year, monthValue); |
|||
if (CollectionUtils.isEmpty(rawData)) { |
|||
return Collections.emptyList(); |
|||
} |
|||
|
|||
rawData.forEach(this::calculateDynamicFields); |
|||
|
|||
return rawData.stream() |
|||
.map(this::convertToGzpDetailVO) |
|||
.collect(Collectors.toList()); |
|||
} |
|||
|
|||
private void calculateDynamicFields(monthDO item) { |
|||
if (item.getStartTime() != null && item.getEndTime() != null) { |
|||
// 计算超限时长(秒)
|
|||
long durationSeconds = Duration.between( |
|||
item.getStartTime().toInstant(), |
|||
item.getEndTime().toInstant() |
|||
).getSeconds(); |
|||
item.setExceedDuration(durationSeconds); |
|||
|
|||
// 计算年、月、日
|
|||
LocalDateTime localStart = item.getStartTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime(); |
|||
item.setYear(String.valueOf(localStart.getYear())); |
|||
item.setMonth(localStart.getMonthValue()); |
|||
item.setDay(localStart.getDayOfMonth()); |
|||
item.setHour(localStart.getHour()); |
|||
} |
|||
} |
|||
|
|||
private AlarmMonthlyVO buildMonthlyVO(String instanceName, List<monthDO> instanceData, YearMonth month) { |
|||
AlarmMonthlyVO vo = new AlarmMonthlyVO(); |
|||
vo.setId(instanceData.get(0).getMpId()); |
|||
vo.setInstanceName(instanceName); |
|||
vo.setTotalAlarms(instanceData.size()); |
|||
vo.setAlarmDuration(instanceData.stream() |
|||
.mapToLong(item -> item.getExceedDuration() != null ? item.getExceedDuration() : 0L) |
|||
.sum()); |
|||
vo.setDayCounts(calculateDailyCounts(instanceData, month)); |
|||
vo.setHasDetails(true); |
|||
return vo; |
|||
} |
|||
|
|||
private Map<String, Integer> calculateDailyCounts(List<monthDO> data, YearMonth month) { |
|||
int daysInMonth = month != null ? month.lengthOfMonth() : YearMonth.now().lengthOfMonth(); |
|||
Map<String, Integer> dayCounts = new HashMap<>(daysInMonth); |
|||
|
|||
for (int day = 1; day <= daysInMonth; day++) { |
|||
final int targetDay = day; |
|||
long count = data.stream() |
|||
.filter(item -> item.getDay() != null && item.getDay() == targetDay) |
|||
.count(); |
|||
dayCounts.put("day_" + day, (int) count); |
|||
} |
|||
return dayCounts; |
|||
} |
|||
private GzpAlarmDetailVO convertToGzpDetailVO(monthDO domain) { |
|||
GzpAlarmDetailVO vo = new GzpAlarmDetailVO(); |
|||
vo.setGzpName(domain.getGzpName()); |
|||
vo.setStartTime(domain.getStartTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime()); |
|||
vo.setEndTime(domain.getEndTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime()); |
|||
vo.setDuration(domain.getExceedDuration()); |
|||
return vo; |
|||
} |
|||
} |
@ -0,0 +1,133 @@ |
|||
package cn.iocoder.yudao.module.alert.dao.service.impl; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.dao.domain.YearReport; |
|||
import cn.iocoder.yudao.module.alert.dao.mapper.YearReportMapper; |
|||
import cn.iocoder.yudao.module.alert.dao.service.YearReportService; |
|||
import cn.iocoder.yudao.module.alert.dal.dataobject.alarm.analysis.yearDO; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import java.time.Duration; |
|||
import java.time.LocalDateTime; |
|||
import java.time.ZoneId; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Service |
|||
public class YearReportServiceImpl implements YearReportService { |
|||
|
|||
private final YearReportMapper yearReportMapper; |
|||
|
|||
public YearReportServiceImpl(YearReportMapper yearReportMapper) { |
|||
this.yearReportMapper = yearReportMapper; |
|||
} |
|||
|
|||
@Override |
|||
public PageResult<YearReport> getYearlyAlarmData(String unit, String driverType, Integer year, int pageNo, int pageSize) { |
|||
System.out.printf("查询参数 - unit: %s, driverType: %s, year: %d, pageNo: {}, pageSize: {}", |
|||
unit, driverType, year, pageNo, pageSize); |
|||
|
|||
List<yearDO> rawData = yearReportMapper.selectByCondition(unit, driverType, year); |
|||
if (CollectionUtils.isEmpty(rawData)) { |
|||
return new PageResult<>(Collections.emptyList(), 0L); |
|||
} |
|||
|
|||
rawData.forEach(this::calculateDynamicFields); |
|||
|
|||
Map<String, List<yearDO>> groupByInstance = rawData.stream() |
|||
.collect(Collectors.groupingBy(yearDO::getMpName)); |
|||
|
|||
List<String> instanceNames = new ArrayList<>(groupByInstance.keySet()); |
|||
Long totalInstances = (long) instanceNames.size(); |
|||
|
|||
int fromIndex = (pageNo - 1) * pageSize; |
|||
if (fromIndex >= totalInstances) { |
|||
return new PageResult<>(Collections.emptyList(), totalInstances); |
|||
} |
|||
int toIndex = (int) Math.min(fromIndex + pageSize, totalInstances); |
|||
List<String> pagedInstanceNames = instanceNames.subList(fromIndex, toIndex); |
|||
|
|||
List<YearReport> result = pagedInstanceNames.stream() |
|||
.map(instanceName -> { |
|||
List<yearDO> instanceData = groupByInstance.get(instanceName); |
|||
return buildYearReport(instanceName, instanceData); |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
|
|||
return new PageResult<>(result, totalInstances); |
|||
} |
|||
|
|||
private void calculateDynamicFields(yearDO item) { |
|||
if (item.getStartTime() != null && item.getEndTime() != null) { |
|||
long durationSeconds = Duration.between( |
|||
item.getStartTime().toInstant(), |
|||
item.getEndTime().toInstant() |
|||
).getSeconds(); |
|||
item.setExceedDuration(durationSeconds); |
|||
|
|||
LocalDateTime localStart = item.getStartTime().toInstant() |
|||
.atZone(ZoneId.systemDefault()) |
|||
.toLocalDateTime(); |
|||
item.setYear(localStart.getYear()); |
|||
item.setMonth(localStart.getMonthValue()); |
|||
} |
|||
} |
|||
|
|||
private YearReport buildYearReport(String instanceName, List<yearDO> instanceData) { |
|||
YearReport domain = new YearReport(); |
|||
domain.setId(instanceData.get(0).getMpId()); |
|||
domain.setInstanceName(instanceName); |
|||
domain.setTotalAlarms(instanceData.size()); |
|||
domain.setAlarmDuration(instanceData.stream() |
|||
.mapToLong(item -> item.getExceedDuration() != null ? item.getExceedDuration() : 0) |
|||
.sum()); |
|||
domain.setMonthCounts(calculateMonthlyCounts(instanceData)); |
|||
return domain; |
|||
} |
|||
|
|||
private Map<String, Integer> calculateMonthlyCounts(List<yearDO> data) { |
|||
Map<String, Integer> monthCounts = new HashMap<>(12); |
|||
for (int i = 1; i <= 12; i++) { |
|||
final int month = i; |
|||
monthCounts.put("month_" + i, (int) data.stream() |
|||
.filter(item -> item.getMonth() != null && item.getMonth() == month) |
|||
.count()); |
|||
} |
|||
return monthCounts; |
|||
} |
|||
|
|||
@Override |
|||
public List<YearReport> getAlarmDetails(String instanceId, Integer year) { |
|||
List<yearDO> rawData = yearReportMapper.selectDetailsByInstanceId(instanceId, year); |
|||
|
|||
if (CollectionUtils.isEmpty(rawData)) { |
|||
return Collections.emptyList(); |
|||
} |
|||
|
|||
rawData.forEach(this::calculateDynamicFields); |
|||
|
|||
Map<String, List<yearDO>> groupByGzp = rawData.stream() |
|||
.collect(Collectors.groupingBy(yearDO::getGzpName)); |
|||
|
|||
List<YearReport> result = new ArrayList<>(groupByGzp.size()); |
|||
groupByGzp.forEach((gzpName, gzpData) -> { |
|||
YearReport domain = new YearReport(); |
|||
domain.setTagname(gzpName); |
|||
domain.setAlarmcount(gzpData.size()); |
|||
domain.setAlarmtime(gzpData.stream() |
|||
.mapToLong(item -> item.getExceedDuration() != null ? item.getExceedDuration() : 0L) |
|||
.sum()); |
|||
result.add(domain); |
|||
}); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public List<yearDO> getGzpAlarmDetails(String gzpName, String instanceId, Integer year) { |
|||
List<yearDO> rawData = yearReportMapper.selectGzpDetails(gzpName, instanceId, year); |
|||
rawData.forEach(this::calculateDynamicFields); |
|||
return rawData; |
|||
} |
|||
} |
Loading…
Reference in new issue