|
|
|
|
@ -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();
|
|
|
|
|
|