From 000aa526e8ddb03ac74444f97e0db6cda1a078bc Mon Sep 17 00:00:00 2001 From: HuangHuiKang Date: Wed, 6 May 2026 18:00:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E9=87=87=E9=9B=86?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=BA=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/mes/enums/ErrorCodeConstants.java | 4 +- .../mes/service/task/TaskServiceImpl.java | 65 +++++++++++++++++-- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index 07b20e9b0..ed9942634 100644 --- a/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -195,7 +195,9 @@ public interface ErrorCodeConstants { ErrorCode WAREHOUSE_NOT_EXISTS= new ErrorCode(100_301_0014, "仓库Id不能为空"); ErrorCode PLAN_RECORD_NOT_EXISTS = new ErrorCode(100_301_0015, "生产计划操作记录不存在"); ErrorCode SCHEDULE_PRODUCT_DAILY_AVERAGE_ZERO = new ErrorCode(100_301_0016, "产品最近半年平均报工值为0,productId={},productCode={},productName={}"); - ErrorCode SCHEDULE_DEVICE_COLLECTION_CAPACITY_ZERO = new ErrorCode(100_301_0017, "设备最近半年数据采集产能为0,deviceId={},deviceName={}"); + ErrorCode SCHEDULE_DEVICE_COLLECTION_CAPACITY_ZERO = new ErrorCode(100_301_0017, "{}-{},设备最近半年数据采集产能为0,deviceId={},deviceName={}"); + ErrorCode SCHEDULE_DEVICE_ORGANIZATION_NOT_FOUND = new ErrorCode(100_301_0018, "{}-{},设备未关联产线工位,deviceId={},deviceName={}"); + ErrorCode SCHEDULE_DEVICE_COLLECTION_MAPPING_MISSING = new ErrorCode(100_301_0019, "{}-{},设备未关联采集设备,deviceId={},deviceName={}"); diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java index da9f7bfc0..121447ecc 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java @@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanSaveReqVO; import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanStatusEnum; import cn.iocoder.yudao.module.mes.controller.admin.task.vo.*; import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO; import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO; import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDO; import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDetailDO; @@ -28,6 +29,7 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.task.ViewTaskProductSummary; import cn.iocoder.yudao.module.mes.dal.mysql.baogongrecord.BaogongRecordMapper; import cn.iocoder.yudao.module.mes.dal.mysql.calholiday.CalHolidayMapper; import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper; +import cn.iocoder.yudao.module.mes.dal.mysql.organization.OrganizationMapper; import cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper; import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskDetailMapper; import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskMapper; @@ -86,6 +88,9 @@ public class TaskServiceImpl implements TaskService { @Resource private DeviceLedgerMapper deviceLedgerMapper; + @Resource + private OrganizationMapper organizationMapper; + @Resource @Lazy private DeviceMapper deviceMapper; @@ -552,7 +557,7 @@ public class TaskServiceImpl implements TaskService { List candidates = new ArrayList<>(); for (ProductRelationRespVO rel : deviceRels) { DeviceLedgerDO device = deviceLedgerMapper.selectById(rel.getId()); - Integer dailyCapacity = resolveCapacityValue(capacityType, device, item.getProductId(), rel.getId(), capacityContext); + Integer dailyCapacity = resolveCapacityValue(capacityType, device, item.getProductId(), rel.getId(), item.getPlanNumber(), capacityContext); if (dailyCapacity == null || dailyCapacity <= 0) { continue; } @@ -874,7 +879,7 @@ public class TaskServiceImpl implements TaskService { } private Integer resolveCapacityValue(CapacityTypeEnum capacityType, DeviceLedgerDO device, - Long productId, Long deviceId, CapacityContext capacityContext) { + Long productId, Long deviceId, Long planNumber, CapacityContext capacityContext) { if (capacityType == CapacityTypeEnum.RATED) { return device == null ? null : capacityType.getCapacity(device); } @@ -898,17 +903,65 @@ public class TaskServiceImpl implements TaskService { if (deviceId == null) { return null; } - Integer value = capacityContext.getDeviceCollectionAverageCapacity(deviceId); + DeviceLedgerDO ledger = device != null ? device : deviceLedgerMapper.selectById(deviceId); + String deviceName = ledger == null ? null : ledger.getDeviceName(); + Long collectDeviceId = resolveCollectDeviceId(deviceId, deviceName, productId, planNumber); + Integer value = capacityContext.getDeviceCollectionAverageCapacity(collectDeviceId); if (value == null || value <= 0) { - DeviceDO deviceInfo = capacityContext.getDeviceCache().get(deviceId); - throw exception(SCHEDULE_DEVICE_COLLECTION_CAPACITY_ZERO, deviceId, - deviceInfo == null ? null : deviceInfo.getDeviceName()); + DeviceDO deviceInfo = queryCollectDeviceWithDeleted(collectDeviceId); + ErpProductDO product = productId == null ? null : erpProductMapper.selectById(productId); + throw exception(SCHEDULE_DEVICE_COLLECTION_CAPACITY_ZERO, + product == null ? null : product.getName(), + planNumber, + collectDeviceId, + buildCollectDeviceName(deviceInfo)); } return value; } return device == null ? null : capacityType.getCapacity(device); } + private Long resolveCollectDeviceId(Long machineId, String deviceName, Long productId, Long planNumber) { + OrganizationDO organization = organizationMapper.selectOne( + new LambdaQueryWrapper() + .eq(OrganizationDO::getMachineId, machineId) + .last("limit 1")); + ErpProductDO product = productId == null ? null : erpProductMapper.selectById(productId); + if (organization == null) { + throw exception(SCHEDULE_DEVICE_ORGANIZATION_NOT_FOUND, + product == null ? null : product.getName(), + planNumber, + machineId, + deviceName); + } + if (organization.getDvId() == null) { + throw exception(SCHEDULE_DEVICE_COLLECTION_MAPPING_MISSING, + product == null ? null : product.getName(), + planNumber, + machineId, + deviceName); + } + return organization.getDvId(); + } + + private DeviceDO queryCollectDeviceWithDeleted(Long collectDeviceId) { + if (collectDeviceId == null) { + return null; + } + return deviceMapper.selectByIdWithDeleted(collectDeviceId); + } + + private String buildCollectDeviceName(DeviceDO deviceInfo) { + if (deviceInfo == null) { + return null; + } + String deviceName = deviceInfo.getDeviceName(); + if (Boolean.TRUE.equals(deviceInfo.getDeleted())) { + return StringUtils.defaultString(deviceName) + "(已被删除)"; + } + return deviceName; + } + private CapacityContext buildCapacityContext(List sortedPlans, boolean skipHoliday, CapacityTypeEnum capacityType) { CapacityContext context = new CapacityContext();