From 154ea8973b5b2498c2a30044b3445a8adfad8634 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期三, 04 十一月 2026 15:08:31 +0800
Subject: [PATCH] feat(mes): 移植 OEE 分析功能(需求18 OEE分析)
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvOeeRespVO.java | 65 ++++++++++
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/MesDvStatisticsController.java | 218 ++++++++++++++++++++++++++++++++++++
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvStatisticsRespVO.java | 59 +++++++++
3 files changed, 342 insertions(+), 0 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/MesDvStatisticsController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/MesDvStatisticsController.java
new file mode 100644
index 0000000..fd4b9f8
--- /dev/null
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/MesDvStatisticsController.java
@@ -0,0 +1,218 @@
+package cn.iocoder.yudao.module.mes.controller.admin.dv.statistics;
+
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.mes.controller.admin.dv.statistics.vo.MesDvOeeRespVO;
+import cn.iocoder.yudao.module.mes.controller.admin.dv.statistics.vo.MesDvStatisticsRespVO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryTypeDO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordDO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.dv.repair.MesDvRepairDO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.pro.task.MesProTaskDO;
+import cn.iocoder.yudao.module.mes.dal.mysql.dv.machinery.MesDvMachineryMapper;
+import cn.iocoder.yudao.module.mes.dal.mysql.dv.machinery.MesDvMachineryTypeMapper;
+import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordMapper;
+import cn.iocoder.yudao.module.mes.dal.mysql.dv.repair.MesDvRepairMapper;
+import cn.iocoder.yudao.module.mes.dal.mysql.pro.task.MesProTaskMapper;
+import cn.iocoder.yudao.module.mes.enums.dv.MesDvMachineryStatusEnum;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "绠$悊鍚庡彴 - MES 璁惧缁熻")
+@RestController
+@RequestMapping("/mes/dv/statistics")
+@Validated
+public class MesDvStatisticsController {
+
+ @Resource
+ private MesDvMachineryMapper machineryMapper;
+ @Resource
+ private MesDvMachineryTypeMapper machineryTypeMapper;
+ @Resource
+ private MesDvRepairMapper repairMapper;
+ @Resource
+ private MesDvMaintenRecordMapper maintenRecordMapper;
+ @Resource
+ private MesProTaskMapper taskMapper;
+
+ @GetMapping("/summary")
+ @Operation(summary = "璁惧缁熻姹囨�伙紙鍙拌处/缁翠慨/淇濆吇/绫诲瀷鍒嗗竷锛�")
+ public CommonResult<MesDvStatisticsRespVO> getSummary() {
+ MesDvStatisticsRespVO vo = new MesDvStatisticsRespVO();
+
+ // 1. 璁惧鍙拌处缁熻
+ Long total = machineryMapper.selectCount();
+ Long producing = machineryMapper.selectCount(new LambdaQueryWrapperX<MesDvMachineryDO>()
+ .eq(MesDvMachineryDO::getStatus, MesDvMachineryStatusEnum.PRODUCING.getStatus()));
+ Long stopped = machineryMapper.selectCount(new LambdaQueryWrapperX<MesDvMachineryDO>()
+ .eq(MesDvMachineryDO::getStatus, MesDvMachineryStatusEnum.STOP.getStatus()));
+ Long maintaining = machineryMapper.selectCount(new LambdaQueryWrapperX<MesDvMachineryDO>()
+ .eq(MesDvMachineryDO::getStatus, MesDvMachineryStatusEnum.MAINTENANCE.getStatus()));
+ vo.setTotalMachinery(total);
+ vo.setProducingCount(producing);
+ vo.setStoppedCount(stopped);
+ vo.setMaintainingCount(maintaining);
+ vo.setFaultRate(total != null && total > 0
+ ? (double) (stopped + maintaining) / total * 100 : 0D);
+
+ // 2. 缁翠慨缁熻
+ vo.setTotalRepair(repairMapper.selectCount());
+ vo.setFinishedRepair(repairMapper.selectCount(new LambdaQueryWrapperX<MesDvRepairDO>()
+ .eq(MesDvRepairDO::getStatus, cn.iocoder.yudao.module.mes.enums.dv.MesDvRepairStatusEnum.FINISHED.getStatus())));
+ vo.setProcessingRepair((vo.getTotalRepair() != null ? vo.getTotalRepair() : 0L)
+ - (vo.getFinishedRepair() != null ? vo.getFinishedRepair() : 0L));
+
+ // 3. 淇濆吇缁熻
+ vo.setTotalMainten(maintenRecordMapper.selectCount());
+ vo.setFinishedMainten(maintenRecordMapper.selectCount(new LambdaQueryWrapperX<MesDvMaintenRecordDO>()
+ .eq(MesDvMaintenRecordDO::getStatus, cn.iocoder.yudao.module.mes.enums.dv.MesDvMaintenRecordStatusEnum.SUBMITTED.getStatus())));
+
+ // 4. 鎸夎澶囩被鍨嬪垎甯�
+ List<MesDvMachineryDO> machineryList = machineryMapper.selectList();
+ Map<Long, Long> typeCountMap = new HashMap<>();
+ for (MesDvMachineryDO machinery : machineryList) {
+ if (machinery.getMachineryTypeId() == null) {
+ continue;
+ }
+ typeCountMap.merge(machinery.getMachineryTypeId(), 1L, Long::sum);
+ }
+ List<MesDvMachineryTypeDO> typeList = machineryTypeMapper.selectList();
+ Map<Long, String> typeNameMap = new HashMap<>();
+ for (MesDvMachineryTypeDO type : typeList) {
+ typeNameMap.put(type.getId(), type.getName());
+ }
+ List<MesDvStatisticsRespVO.TypeItem> typeDistribution = new ArrayList<>();
+ typeCountMap.forEach((typeId, count) -> {
+ MesDvStatisticsRespVO.TypeItem item = new MesDvStatisticsRespVO.TypeItem();
+ item.setMachineryTypeId(typeId);
+ item.setMachineryTypeName(typeNameMap.get(typeId));
+ item.setCount(count);
+ typeDistribution.add(item);
+ });
+ vo.setTypeDistribution(typeDistribution);
+ return success(vo);
+ }
+
+ @GetMapping("/oee")
+ @Operation(summary = "璁惧 OEE 缁熻锛堢鍔ㄧ巼脳鎬ц兘寮�鍔ㄧ巼脳鑹搧鐜囷級")
+ public CommonResult<MesDvOeeRespVO> getOee(
+ @RequestParam(value = "startTime", required = false)
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
+ @RequestParam(value = "endTime", required = false)
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) {
+ // 1. 鏌ヨ缁熻鍖洪棿鍐呬换鍔★紙鎸夊畬鎴愭椂闂磋繃婊わ紱涓嶄紶鍖洪棿鍒欑粺璁″叏閮級
+ List<MesProTaskDO> allTasks = taskMapper.selectList(new LambdaQueryWrapperX<MesProTaskDO>()
+ .betweenIfPresent(MesProTaskDO::getFinishDate, new LocalDateTime[]{startTime, endTime}));
+
+ // 2. 鏁翠綋 OEE
+ MesDvOeeRespVO vo = new MesDvOeeRespVO();
+ OeeCalc overall = calcOee(allTasks);
+ vo.setOverallOee(overall.oee);
+ vo.setOverallAvailability(overall.availability);
+ vo.setOverallPerformance(overall.performance);
+ vo.setOverallQuality(overall.quality);
+ vo.setTaskCount((long) allTasks.size());
+
+ // 3. 鎸夎澶囪仛鍚堬細浠诲姟鎸夊伐浣滅珯鍒嗙粍锛岃澶囬�氳繃 workstationId 鍏宠仈宸ヤ綔绔�
+ Map<Long, List<MesProTaskDO>> tasksByWorkstation = new HashMap<>();
+ for (MesProTaskDO task : allTasks) {
+ if (task.getWorkstationId() == null) {
+ continue;
+ }
+ tasksByWorkstation.computeIfAbsent(task.getWorkstationId(), k -> new ArrayList<>()).add(task);
+ }
+ List<MesDvOeeRespVO.MachineryOee> items = new ArrayList<>();
+ for (MesDvMachineryDO machinery : machineryMapper.selectList()) {
+ if (machinery.getWorkstationId() == null) {
+ continue; // 鏈粦瀹氬伐浣滅珯锛屾棤娉曞叧鑱斾换鍔�
+ }
+ List<MesProTaskDO> tasks = tasksByWorkstation.getOrDefault(machinery.getWorkstationId(), Collections.emptyList());
+ OeeCalc calc = calcOee(tasks);
+ MesDvOeeRespVO.MachineryOee item = new MesDvOeeRespVO.MachineryOee();
+ item.setMachineryId(machinery.getId());
+ item.setMachineryCode(machinery.getCode());
+ item.setMachineryName(machinery.getName());
+ item.setOee(calc.oee);
+ item.setAvailability(calc.availability);
+ item.setPerformance(calc.performance);
+ item.setQuality(calc.quality);
+ item.setTaskCount((long) tasks.size());
+ item.setPlannedQuantity(calc.plannedQuantity);
+ item.setProducedQuantity(calc.producedQuantity);
+ items.add(item);
+ }
+ vo.setItems(items);
+ return success(vo);
+ }
+
+ private static OeeCalc calcOee(List<MesProTaskDO> tasks) {
+ double totalPlannedHours = 0, totalActualHours = 0;
+ BigDecimal totalPlannedQty = BigDecimal.ZERO, totalProducedQty = BigDecimal.ZERO, totalQualifyQty = BigDecimal.ZERO;
+ for (MesProTaskDO task : tasks) {
+ if (task.getDuration() != null) {
+ totalPlannedHours += task.getDuration() * 8D; // 1 宸ヤ綔鏃� = 8 灏忔椂
+ }
+ if (task.getFirstFeedbackTime() != null && task.getLastFeedbackTime() != null
+ && task.getLastFeedbackTime().isAfter(task.getFirstFeedbackTime())) {
+ totalActualHours += Duration.between(task.getFirstFeedbackTime(), task.getLastFeedbackTime()).toMinutes() / 60D;
+ }
+ if (task.getQuantity() != null) {
+ totalPlannedQty = totalPlannedQty.add(task.getQuantity());
+ }
+ if (task.getProducedQuantity() != null) {
+ totalProducedQty = totalProducedQty.add(task.getProducedQuantity());
+ }
+ if (task.getQualifyQuantity() != null) {
+ totalQualifyQty = totalQualifyQty.add(task.getQualifyQuantity());
+ }
+ }
+ OeeCalc calc = new OeeCalc();
+ // 绋煎姩鐜� = 瀹為檯鎶ュ伐鏃堕暱 / 璁″垝鏃堕暱锛堟棤璁″垝鏃堕暱鏃舵寜 1 澶勭悊锛�
+ calc.availability = percent(totalPlannedHours > 0 ? Math.min(1D, totalActualHours / totalPlannedHours) : 1D);
+ // 鎬ц兘寮�鍔ㄧ巼 = 瀹為檯浜ч噺 / 璁″垝浜ч噺
+ calc.performance = totalPlannedQty.compareTo(BigDecimal.ZERO) > 0
+ ? percent(Math.min(1D, totalProducedQty.divide(totalPlannedQty, 4, RoundingMode.HALF_UP).doubleValue())) : 0D;
+ // 鑹搧鐜� = 鍚堟牸鍝� / 瀹為檯浜ч噺锛堟棤浜ч噺鏃舵寜 1 澶勭悊锛�
+ calc.quality = totalProducedQty.compareTo(BigDecimal.ZERO) > 0
+ ? percent(Math.min(1D, totalQualifyQty.divide(totalProducedQty, 4, RoundingMode.HALF_UP).doubleValue())) : 100D;
+ // OEE(%) = 绋煎姩鐜�(%) 脳 鎬ц兘(%) 脳 鑹搧鐜�(%) / 10000锛屼繚鐣欎袱浣嶅皬鏁�
+ calc.oee = Math.round(calc.availability * calc.performance * calc.quality / 10000D * 100D) / 100D;
+ calc.plannedQuantity = totalPlannedQty;
+ calc.producedQuantity = totalProducedQty;
+ return calc;
+ }
+
+ /** 姣斾緥(0-1) 杞櫨鍒嗘瘮锛屼繚鐣欎袱浣嶅皬鏁� */
+ private static double percent(double ratio) {
+ return Math.round(ratio * 10000D) / 100D;
+ }
+
+ private static class OeeCalc {
+ private Double availability;
+ private Double performance;
+ private Double quality;
+ private Double oee;
+ private BigDecimal plannedQuantity;
+ private BigDecimal producedQuantity;
+ }
+
+}
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvOeeRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvOeeRespVO.java
new file mode 100644
index 0000000..cc41788
--- /dev/null
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvOeeRespVO.java
@@ -0,0 +1,65 @@
+package cn.iocoder.yudao.module.mes.controller.admin.dv.statistics.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.List;
+
+@Schema(description = "绠$悊鍚庡彴 - MES 璁惧 OEE 缁熻 Response VO")
+@Data
+public class MesDvOeeRespVO {
+
+ @Schema(description = "鏁翠綋 OEE锛�%锛�")
+ private Double overallOee;
+
+ @Schema(description = "鏁翠綋绋煎姩鐜囷紙%锛�")
+ private Double overallAvailability;
+
+ @Schema(description = "鏁翠綋鎬ц兘寮�鍔ㄧ巼锛�%锛�")
+ private Double overallPerformance;
+
+ @Schema(description = "鏁翠綋鑹搧鐜囷紙%锛�")
+ private Double overallQuality;
+
+ @Schema(description = "缁熻浠诲姟鎬绘暟")
+ private Long taskCount;
+
+ @Schema(description = "鎸夎澶� OEE 鏄庣粏")
+ private List<MachineryOee> items;
+
+ @Schema(description = "璁惧 OEE 鏄庣粏椤�")
+ @Data
+ public static class MachineryOee {
+
+ @Schema(description = "璁惧缂栧彿")
+ private Long machineryId;
+
+ @Schema(description = "璁惧缂栫爜")
+ private String machineryCode;
+
+ @Schema(description = "璁惧鍚嶇О")
+ private String machineryName;
+
+ @Schema(description = "OEE锛�%锛�")
+ private Double oee;
+
+ @Schema(description = "绋煎姩鐜囷紙%锛�")
+ private Double availability;
+
+ @Schema(description = "鎬ц兘寮�鍔ㄧ巼锛�%锛�")
+ private Double performance;
+
+ @Schema(description = "鑹搧鐜囷紙%锛�")
+ private Double quality;
+
+ @Schema(description = "鍏宠仈浠诲姟鏁�")
+ private Long taskCount;
+
+ @Schema(description = "璁″垝浜ч噺")
+ private java.math.BigDecimal plannedQuantity;
+
+ @Schema(description = "瀹為檯浜ч噺")
+ private java.math.BigDecimal producedQuantity;
+ }
+
+}
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvStatisticsRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvStatisticsRespVO.java
new file mode 100644
index 0000000..3108b66
--- /dev/null
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/statistics/vo/MesDvStatisticsRespVO.java
@@ -0,0 +1,59 @@
+package cn.iocoder.yudao.module.mes.controller.admin.dv.statistics.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.List;
+
+@Schema(description = "绠$悊鍚庡彴 - MES 璁惧缁熻 Response VO")
+@Data
+public class MesDvStatisticsRespVO {
+
+ @Schema(description = "璁惧鎬绘暟")
+ private Long totalMachinery;
+
+ @Schema(description = "鐢熶骇涓澶囨暟")
+ private Long producingCount;
+
+ @Schema(description = "鍋滄満璁惧鏁�")
+ private Long stoppedCount;
+
+ @Schema(description = "缁存姢涓澶囨暟")
+ private Long maintainingCount;
+
+ @Schema(description = "璁惧鏁呴殰鐜囷紙鍋滄満+缁存姢 / 鎬绘暟 * 100锛�%锛�")
+ private Double faultRate;
+
+ @Schema(description = "缁翠慨鍗曟�绘暟")
+ private Long totalRepair;
+
+ @Schema(description = "缁翠慨涓�/寰呴獙鏀跺崟鏁�")
+ private Long processingRepair;
+
+ @Schema(description = "宸茬‘璁ょ淮淇崟鏁�")
+ private Long finishedRepair;
+
+ @Schema(description = "淇濆吇璁板綍鎬绘暟")
+ private Long totalMainten;
+
+ @Schema(description = "宸插畬鎴愪繚鍏昏褰曟暟")
+ private Long finishedMainten;
+
+ @Schema(description = "鎸夎澶囩被鍨嬪垎甯�")
+ private List<TypeItem> typeDistribution;
+
+ @Schema(description = "璁惧绫诲瀷鍒嗗竷椤�")
+ @Data
+ public static class TypeItem {
+
+ @Schema(description = "璁惧绫诲瀷缂栧彿")
+ private Long machineryTypeId;
+
+ @Schema(description = "璁惧绫诲瀷鍚嶇О")
+ private String machineryTypeName;
+
+ @Schema(description = "璁惧鏁伴噺")
+ private Long count;
+ }
+
+}
--
Gitblit v1.9.3