fix:修改采集设备产能

main
HuangHuiKang 1 day ago
parent 4dc54fcbc8
commit 000aa526e8

@ -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, "产品最近半年平均报工值为0productId={}productCode={}productName={}");
ErrorCode SCHEDULE_DEVICE_COLLECTION_CAPACITY_ZERO = new ErrorCode(100_301_0017, "设备最近半年数据采集产能为0deviceId={}deviceName={}");
ErrorCode SCHEDULE_DEVICE_COLLECTION_CAPACITY_ZERO = new ErrorCode(100_301_0017, "{}-{}设备最近半年数据采集产能为0deviceId={}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={}");

@ -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<DeviceCandidate> 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<OrganizationDO>()
.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<PlanSaveReqVO> sortedPlans, boolean skipHoliday,
CapacityTypeEnum capacityType) {
CapacityContext context = new CapacityContext();

Loading…
Cancel
Save