|
|
|
|
@ -82,13 +82,13 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
private final IEquipResourceService equipResourceService; |
|
|
|
|
private final IPersonResourceService personResourceService; |
|
|
|
|
|
|
|
|
|
@Value("${business.oldMes.url}") |
|
|
|
|
private String oldMesUrl; |
|
|
|
|
@Value("${business.oldMes.pushApsResult}") |
|
|
|
|
private String pushApsResult; |
|
|
|
|
@Value("${business.oldMes.url}") |
|
|
|
|
private String oldMesUrl; |
|
|
|
|
@Value("${business.oldMes.pushApsResult}") |
|
|
|
|
private String pushApsResult; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义细粒度锁容器(全局单例)
|
|
|
|
|
// 定义细粒度锁容器(全局单例)
|
|
|
|
|
private static final Map<Long, Lock> CRAFT_LOCK_MAP = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
// 获取工艺ID对应的锁(不存在则创建)
|
|
|
|
|
@ -115,7 +115,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
public void scheduling() { |
|
|
|
|
//查询待排产订单,状态是3
|
|
|
|
|
List<YieldOrderEntity> list = |
|
|
|
|
yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().eq(BaseEntity::getStatus, YieldOrderEnum.STATUS_APS.getCategory()).isNotNull(YieldOrderEntity::getWorkCenterId).isNotNull(YieldOrderEntity::getReleaseDate)); |
|
|
|
|
yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().eq(BaseEntity::getStatus, YieldOrderEnum.STATUS_APS.getCategory()).isNotNull(YieldOrderEntity::getWorkCenterId).isNotNull(YieldOrderEntity::getReleaseDate)); |
|
|
|
|
log.info("待排产订单数量为:" + list.size()); |
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
|
//校验已排产订单
|
|
|
|
|
@ -154,23 +154,23 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
) |
|
|
|
|
)); |
|
|
|
|
//处理带有公共前置工序的订单
|
|
|
|
|
Map<String,List<WorkPlanEntity>> planMap = dealCommonCraftOrders(); |
|
|
|
|
Map<String, List<WorkPlanEntity>> planMap = dealCommonCraftOrders(); |
|
|
|
|
//多线程排产
|
|
|
|
|
ExecutorService threadPool = new ThreadPoolExecutor( |
|
|
|
|
map.size(), map.size(), 0L, TimeUnit.MILLISECONDS, |
|
|
|
|
new LinkedBlockingQueue<>(), |
|
|
|
|
r -> new Thread(r, "scheduling-thread-" + System.currentTimeMillis())); |
|
|
|
|
map.forEach((workcenter, orders) -> { |
|
|
|
|
threadPool.execute(() -> allocateResources(orders,personAbilityMap,mainProducerMap,planMap)); |
|
|
|
|
threadPool.execute(() -> allocateResources(orders, personAbilityMap, mainProducerMap, planMap)); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Map<String,List<WorkOrderDto>> schedulingBoard(WorkOrderDto workOrder) { |
|
|
|
|
public Map<String, List<WorkOrderDto>> schedulingBoard(WorkOrderDto workOrder) { |
|
|
|
|
List<WorkOrderDto> list = baseMapper.selectWorkOrderList(workOrder); |
|
|
|
|
Map<String,List<WorkOrderDto>> resultList = new HashMap<>(); |
|
|
|
|
Map<String, List<WorkOrderDto>> resultList = new HashMap<>(); |
|
|
|
|
Map<String, List<WorkOrderDto>> woCodeGroup = list.stream().collect(Collectors.groupingBy(WorkOrderDto::getWoCode)); |
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<WorkOrderDto>> entry : woCodeGroup.entrySet()) { |
|
|
|
|
@ -195,7 +195,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
WorkOrderDto mergedDto = new WorkOrderDto(); |
|
|
|
|
mergedDto.setWoCode(woCode); |
|
|
|
|
mergedDto.setProcessName(processName); |
|
|
|
|
for(WorkOrderDto dto : processList){ |
|
|
|
|
for (WorkOrderDto dto : processList) { |
|
|
|
|
mergedDto.setTeamName(dto.getTeamName()); |
|
|
|
|
mergedDto.setCardNo(dto.getCardNo()); |
|
|
|
|
mergedDto.setBatchNo(dto.getBatchNo()); |
|
|
|
|
@ -204,22 +204,22 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
mergedDto.setMakeQty(dto.getMakeQty()); |
|
|
|
|
mergedDto.setEquipName(dto.getEquipName()); |
|
|
|
|
mergedDto.setProductIdent(dto.getProductIdent()); |
|
|
|
|
if(dto.getPlanStartTime().equals(minStartTime)){ |
|
|
|
|
if (dto.getPlanStartTime().equals(minStartTime)) { |
|
|
|
|
mergedDto.setStartTime(dto.getStartTime()); |
|
|
|
|
mergedDto.setFactStartTime(dto.getFactStartTime()); |
|
|
|
|
} |
|
|
|
|
if(dto.getPlanEndTime().equals(maxEndTime)){ |
|
|
|
|
if (dto.getPlanEndTime().equals(maxEndTime)) { |
|
|
|
|
mergedDto.setEndTime(dto.getEndTime()); |
|
|
|
|
mergedDto.setFactEndTime(dto.getFactEndTime()); |
|
|
|
|
mergedDto.setPlanStatus(dto.getPlanStatus()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//处理跨天的工序
|
|
|
|
|
if(!maxEndTime.substring(0,10).equals(minStartTime.substring(0,10))){ |
|
|
|
|
if(minStartTime.substring(0,10).equals(workOrder.getStartTime())){ |
|
|
|
|
if (!maxEndTime.substring(0, 10).equals(minStartTime.substring(0, 10))) { |
|
|
|
|
if (minStartTime.substring(0, 10).equals(workOrder.getStartTime())) { |
|
|
|
|
mergedDto.setEndTime("24:00"); |
|
|
|
|
} |
|
|
|
|
if(maxEndTime.substring(0,10).equals(workOrder.getStartTime())){ |
|
|
|
|
if (maxEndTime.substring(0, 10).equals(workOrder.getStartTime())) { |
|
|
|
|
mergedDto.setStartTime("0:00"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -236,41 +236,41 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
return resultList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void sendWorkOrderToOldMes(List<WorkOrderEntity> workOrderEntityList) { |
|
|
|
|
List<JSONObject> requestList = new ArrayList<>(); |
|
|
|
|
@Override |
|
|
|
|
public void sendWorkOrderToOldMes(List<WorkOrderEntity> workOrderEntityList) { |
|
|
|
|
List<JSONObject> requestList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for (WorkOrderEntity workOrderEntity : workOrderEntityList) { |
|
|
|
|
JSONObject requestJson = new JSONObject(); |
|
|
|
|
for (WorkOrderEntity workOrderEntity : workOrderEntityList) { |
|
|
|
|
JSONObject requestJson = new JSONObject(); |
|
|
|
|
|
|
|
|
|
List<WorkPlanEntity> workPlanList = workPlanService.list(Wrappers.<WorkPlanEntity>lambdaQuery() |
|
|
|
|
.eq(WorkPlanEntity::getWoId, workOrderEntity.getId())); |
|
|
|
|
List<WorkPlanEntity> workPlanList = workPlanService.list(Wrappers.<WorkPlanEntity>lambdaQuery() |
|
|
|
|
.eq(WorkPlanEntity::getWoId, workOrderEntity.getId())); |
|
|
|
|
|
|
|
|
|
requestJson.put("workOrder", workOrderEntity); |
|
|
|
|
requestJson.put("workPlanList", workPlanList); |
|
|
|
|
requestList.add(requestJson); |
|
|
|
|
} |
|
|
|
|
requestJson.put("workOrder", workOrderEntity); |
|
|
|
|
requestJson.put("workPlanList", workPlanList); |
|
|
|
|
requestList.add(requestJson); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 向旧MES推送排产结果数据
|
|
|
|
|
String url = oldMesUrl + pushApsResult; |
|
|
|
|
try { |
|
|
|
|
HttpUtil.post(url, JSONObject.toJSONString(requestList)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 向旧MES推送排产结果数据
|
|
|
|
|
String url = oldMesUrl + pushApsResult; |
|
|
|
|
try { |
|
|
|
|
HttpUtil.post(url, JSONObject.toJSONString(requestList)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<WorkOrderDto> schedulingCount(WorkOrderDto workOrder) { |
|
|
|
|
if(StringUtils.isNotEmpty(workOrder.getStartTime())){ |
|
|
|
|
if (StringUtils.isNotEmpty(workOrder.getStartTime())) { |
|
|
|
|
workOrder.setStartTime(workOrder.getStartTime().concat(" 00:00:00")); |
|
|
|
|
} |
|
|
|
|
if(StringUtils.isNotEmpty(workOrder.getEndTime())){ |
|
|
|
|
if (StringUtils.isNotEmpty(workOrder.getEndTime())) { |
|
|
|
|
workOrder.setEndTime(workOrder.getEndTime().concat(" 23:59:59")); |
|
|
|
|
} |
|
|
|
|
List<WorkOrderDto> list = baseMapper.selectSchedulingCount(workOrder); |
|
|
|
|
list.forEach(item -> { |
|
|
|
|
item.setSchedulingRate(String.format("%.2f", (double)item.getSchedulingCount()/item.getTotalCount()*100)); |
|
|
|
|
item.setSchedulingRate(String.format("%.2f", (double) item.getSchedulingCount() / item.getTotalCount() * 100)); |
|
|
|
|
}); |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
@ -291,26 +291,26 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void calculateCr(List<YieldOrderEntity> list) { |
|
|
|
|
//查询订单下的工序,计算cr值
|
|
|
|
|
for (YieldOrderEntity entity : list) { |
|
|
|
|
List<YieldOrderCraftEntity> craftList = yieldOrderCraftService.list(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId, entity.getId())); |
|
|
|
|
//定义订单总工时
|
|
|
|
|
BigDecimal total = new BigDecimal(0); |
|
|
|
|
for (YieldOrderCraftEntity craftEntity : craftList) { |
|
|
|
|
total = total.add(craftEntity.getHourQuota()); |
|
|
|
|
} |
|
|
|
|
//换算成天
|
|
|
|
|
total = total.divide(BigDecimal.valueOf(1440), 2, RoundingMode.HALF_UP); |
|
|
|
|
if(total.compareTo(new BigDecimal(0)) == 0){ |
|
|
|
|
//查询订单下的工序,计算cr值
|
|
|
|
|
for (YieldOrderEntity entity : list) { |
|
|
|
|
List<YieldOrderCraftEntity> craftList = yieldOrderCraftService.list(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId, entity.getId())); |
|
|
|
|
//定义订单总工时
|
|
|
|
|
BigDecimal total = new BigDecimal(0); |
|
|
|
|
for (YieldOrderCraftEntity craftEntity : craftList) { |
|
|
|
|
total = total.add(craftEntity.getHourQuota()); |
|
|
|
|
} |
|
|
|
|
//换算成天
|
|
|
|
|
total = total.divide(BigDecimal.valueOf(1440), 2, RoundingMode.HALF_UP); |
|
|
|
|
if (total.compareTo(new BigDecimal(0)) == 0) { |
|
|
|
|
entity.setCrValue(new BigDecimal(0)); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//获取交期剩余天数
|
|
|
|
|
BigDecimal restDays = new BigDecimal(TimeUnit.DAYS.convert(entity.getDemandDate().getTime() - DateUtil.now().getTime(), TimeUnit.MILLISECONDS)); |
|
|
|
|
//计算cr值剩余交期天数/生产所需额定时长
|
|
|
|
|
entity.setCrValue(restDays.divide(total, 2, RoundingMode.HALF_UP)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//获取交期剩余天数
|
|
|
|
|
BigDecimal restDays = new BigDecimal(TimeUnit.DAYS.convert(entity.getDemandDate().getTime() - DateUtil.now().getTime(), TimeUnit.MILLISECONDS)); |
|
|
|
|
//计算cr值剩余交期天数/生产所需额定时长
|
|
|
|
|
entity.setCrValue(restDays.divide(total, 2, RoundingMode.HALF_UP)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -321,8 +321,8 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
* @author sjx |
|
|
|
|
* @since 2025/12/1 18:08 |
|
|
|
|
**/ |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void allocateResources(List<YieldOrderEntity> list,Map<String, PersonAbilityEntity> personAbilityMap,Map<Long, String> mainProducerMap,Map<String,List<WorkPlanEntity>> planMap) { |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void allocateResources(List<YieldOrderEntity> list, Map<String, PersonAbilityEntity> personAbilityMap, Map<Long, String> mainProducerMap, Map<String, List<WorkPlanEntity>> planMap) { |
|
|
|
|
List<WorkOrderEntity> workOrderList = new ArrayList<>(); |
|
|
|
|
for (YieldOrderEntity order : list) { |
|
|
|
|
try { |
|
|
|
|
@ -330,9 +330,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
Boolean isSchecuding = true; |
|
|
|
|
List<WorkPlanEntity> workPlanList = new ArrayList<>(); |
|
|
|
|
//查询所有工序
|
|
|
|
|
List<YieldOrderCraftEntity> craftList = yieldOrderCraftService.list(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId, order.getId()).ne(YieldOrderCraftEntity::getCaId,27).orderByAsc(YieldOrderCraftEntity::getProcessNo)); |
|
|
|
|
List<YieldOrderCraftEntity> craftList = yieldOrderCraftService.list(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId, order.getId()).ne(YieldOrderCraftEntity::getCaId, 27).orderByAsc(YieldOrderCraftEntity::getProcessNo)); |
|
|
|
|
List<Long> workCenterList = craftList.stream().filter(item -> item.getWorkCenterId() != null).map(YieldOrderCraftEntity::getWorkCenterId).collect(Collectors.toList()); |
|
|
|
|
if(workCenterList.size() != craftList.size()){ |
|
|
|
|
if (workCenterList.size() != craftList.size()) { |
|
|
|
|
order.setErrorInfo("工序信息不完整,含有未匹配作业中心的工序"); |
|
|
|
|
order.setStatus(YieldOrderEnum.STATUS_PROCESS_ERROR.getCategory()); |
|
|
|
|
yieldOrderService.updateById(order); |
|
|
|
|
@ -342,33 +342,33 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
//上一道工序结束时间
|
|
|
|
|
LocalDateTime prevProcessEnd = LocalDateTime.now(); |
|
|
|
|
//判断是否有公共工序已经处理了,如果有则重新定义workPlanList,获取公共工序的最后结束时间和当前时间做比较,取大的作为上一道工序结束时间
|
|
|
|
|
if(planMap.containsKey(order.getYoCode())){ |
|
|
|
|
if (planMap.containsKey(order.getYoCode())) { |
|
|
|
|
workPlanList = planMap.get(order.getYoCode()); |
|
|
|
|
prevProcessEnd = prevProcessEnd.compareTo(workPlanList.get(workPlanList.size()-1).getEndTime()) > 0 ? prevProcessEnd : workPlanList.get(workPlanList.size()-1).getEndTime(); |
|
|
|
|
prevProcessEnd = prevProcessEnd.compareTo(workPlanList.get(workPlanList.size() - 1).getEndTime()) > 0 ? prevProcessEnd : workPlanList.get(workPlanList.size() - 1).getEndTime(); |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < craftList.size(); i++) { |
|
|
|
|
YieldOrderCraftEntity craft = craftList.get(i); |
|
|
|
|
if ("设备".equals(mainProducerMap.get(craft.getPpsId()))) { |
|
|
|
|
//根据作业中心查询所有设备
|
|
|
|
|
List<EquipAbilityEntity> equipAbilityList = equipAbilityService.list(Wrappers.<EquipAbilityEntity>lambdaQuery().in(EquipAbilityEntity::getWorkCenterId, craft.getWorkCenterId()).eq(EquipAbilityEntity::getCraftId,craft.getCaId())); |
|
|
|
|
if(CollectionUtils.isEmpty(equipAbilityList)){ |
|
|
|
|
List<EquipAbilityEntity> equipAbilityList = equipAbilityService.list(Wrappers.<EquipAbilityEntity>lambdaQuery().in(EquipAbilityEntity::getWorkCenterId, craft.getWorkCenterId()).eq(EquipAbilityEntity::getCraftId, craft.getCaId())); |
|
|
|
|
if (CollectionUtils.isEmpty(equipAbilityList)) { |
|
|
|
|
order.setErrorInfo("设备未匹配到对应的设备能力"); |
|
|
|
|
order.setStatus(YieldOrderEnum.STATUS_PROCESS_ERROR.getCategory()); |
|
|
|
|
yieldOrderService.updateById(order); |
|
|
|
|
isSchecuding = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
Map<Integer,List<EquipAbilityEntity>> equipAbilityMap = equipAbilityList.stream().collect(Collectors.groupingBy(EquipAbilityEntity::getEquipOrder)); |
|
|
|
|
Map<Integer, List<EquipAbilityEntity>> equipAbilityMap = equipAbilityList.stream().collect(Collectors.groupingBy(EquipAbilityEntity::getEquipOrder)); |
|
|
|
|
|
|
|
|
|
//匹配设备资源
|
|
|
|
|
//获取下一个整数点
|
|
|
|
|
LocalDateTime dateTime = getNextIntegerTime(prevProcessEnd); |
|
|
|
|
for(Map.Entry<Integer,List<EquipAbilityEntity>> entry : equipAbilityMap.entrySet()){ |
|
|
|
|
for (Map.Entry<Integer, List<EquipAbilityEntity>> entry : equipAbilityMap.entrySet()) { |
|
|
|
|
//根据时间点获取所有设备资源
|
|
|
|
|
List<EquipResourceEntity> equipResourceList = equipResourceService.list(Wrappers.<EquipResourceEntity>lambdaQuery().eq(EquipResourceEntity::getCraftId,craft.getCaId()).eq(EquipResourceEntity::getWorkCenterId,craft.getWorkCenterId()).ge(EquipResourceEntity::getStartTime, dateTime).eq(EquipResourceEntity::getIsUsed, 0).in(EquipResourceEntity::getEquipOrder, entry.getKey())); |
|
|
|
|
if(CollectionUtils.isEmpty(equipResourceList)){ |
|
|
|
|
List<EquipResourceEntity> equipResourceList = equipResourceService.list(Wrappers.<EquipResourceEntity>lambdaQuery().eq(EquipResourceEntity::getCraftId, craft.getCaId()).eq(EquipResourceEntity::getWorkCenterId, craft.getWorkCenterId()).ge(EquipResourceEntity::getStartTime, dateTime).eq(EquipResourceEntity::getIsUsed, 0).in(EquipResourceEntity::getEquipOrder, entry.getKey())); |
|
|
|
|
if (CollectionUtils.isEmpty(equipResourceList)) { |
|
|
|
|
order.setStatus(YieldOrderEnum.STATUS_PROCESS_ERROR.getCategory()); |
|
|
|
|
order.setErrorInfo("工序:"+craft.getPpsId()+"未匹配到对应的设备资源"); |
|
|
|
|
order.setErrorInfo("工序:" + craft.getPpsId() + "未匹配到对应的设备资源"); |
|
|
|
|
yieldOrderService.updateById(order); |
|
|
|
|
isSchecuding = false; |
|
|
|
|
break; |
|
|
|
|
@ -394,9 +394,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
//计算生产所需产能,需将m2换算成dm2
|
|
|
|
|
BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(order.getYpQty())); |
|
|
|
|
//需要判断设备额定生产能力是否满足订单总产能,如果不满足,则需要把总产能进行拆分
|
|
|
|
|
List<BigDecimal> capacityList = capacitySplit(equipResourceMap,sumCapacity); |
|
|
|
|
for(BigDecimal capacity : capacityList){ |
|
|
|
|
for(Map.Entry<LocalDateTime, List<EquipResourceEntity>> entry1 : equipResourceMap.entrySet()){ |
|
|
|
|
List<BigDecimal> capacityList = capacitySplit(equipResourceMap, sumCapacity); |
|
|
|
|
for (BigDecimal capacity : capacityList) { |
|
|
|
|
for (Map.Entry<LocalDateTime, List<EquipResourceEntity>> entry1 : equipResourceMap.entrySet()) { |
|
|
|
|
Boolean isOccupied = false; |
|
|
|
|
List<EquipResourceEntity> resourceList = entry1.getValue(); |
|
|
|
|
for (EquipResourceEntity equipResource : resourceList) { |
|
|
|
|
@ -407,9 +407,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
//生成车间订单
|
|
|
|
|
WorkPlanEntity workPlan = new WorkPlanEntity(); |
|
|
|
|
workPlan.setStartTime(equipResource.getStartTime()); |
|
|
|
|
if(entry.getKey() == 1){ |
|
|
|
|
if (entry.getKey() == 1) { |
|
|
|
|
workPlan.setEndTime(equipResource.getStartTime().plusMinutes(equipResource.getStandardTime().longValue())); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
workPlan.setEndTime(equipResource.getEndTime()); |
|
|
|
|
} |
|
|
|
|
workPlan.setWorkQty(order.getYpQty()); |
|
|
|
|
@ -433,22 +433,22 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
equipResource.setRestCapacity(equipResource.getRestCapacity().subtract(capacity)); |
|
|
|
|
equipResource.setIsUsed("1"); |
|
|
|
|
//如果剩余产能占总产能不足20%,则修改为已占用
|
|
|
|
|
// if(equipResource.getRestCapacity().divide(equipResource.getTotalCapacity(),2,RoundingMode.HALF_UP).compareTo(BigDecimal.valueOf(0.2)) < 0){
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// if(equipResource.getRestCapacity().divide(equipResource.getTotalCapacity(),2,RoundingMode.HALF_UP).compareTo(BigDecimal.valueOf(0.2)) < 0){
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//同一个设备可能有多个工艺能力,同一时间只能做一个工艺能力的零件,所以需要把当前设备所有工艺能力的剩余产能都更新调
|
|
|
|
|
LambdaUpdateWrapper<EquipResourceEntity> equipWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getEquipCode,equipResource.getEquipCode()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getDateTime,equipResource.getDateTime()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getPeriod,equipResource.getPeriod()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getStartTime,equipResource.getStartTime()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getEndTime,equipResource.getEndTime()); |
|
|
|
|
equipResourceService.update(equipResource,equipWrapper); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getEquipCode, equipResource.getEquipCode()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getDateTime, equipResource.getDateTime()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getPeriod, equipResource.getPeriod()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getStartTime, equipResource.getStartTime()); |
|
|
|
|
equipWrapper.eq(EquipResourceEntity::getEndTime, equipResource.getEndTime()); |
|
|
|
|
equipResourceService.update(equipResource, equipWrapper); |
|
|
|
|
//该设备后续所有开始时间小于当前结束时间的时间段都变为不可用
|
|
|
|
|
LambdaUpdateWrapper<EquipResourceEntity> updateWrapper = new LambdaUpdateWrapper(); |
|
|
|
|
updateWrapper.lt(EquipResourceEntity::getStartTime, equipResource.getEndTime()); |
|
|
|
|
updateWrapper.gt(EquipResourceEntity::getStartTime, equipResource.getStartTime()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getEquipCode,equipResource.getEquipCode()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getEquipCode, equipResource.getEquipCode()); |
|
|
|
|
EquipResourceEntity equipResource1 = new EquipResourceEntity(); |
|
|
|
|
equipResource1.setIsUsed("1"); |
|
|
|
|
equipResourceService.update(equipResource1, updateWrapper); |
|
|
|
|
@ -465,7 +465,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(!isSchecuding){ |
|
|
|
|
if (!isSchecuding) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -483,24 +483,24 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
}*/ |
|
|
|
|
WorkPlanEntity workPlan = new WorkPlanEntity(); |
|
|
|
|
BigDecimal totalTime = new BigDecimal(0); |
|
|
|
|
PersonAbilityEntity ability = personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId()); |
|
|
|
|
PersonAbilityEntity ability = personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId()); |
|
|
|
|
//镀后检验和镀后接收先按半小时计算
|
|
|
|
|
if(ability != null){ |
|
|
|
|
if("镀后检验".equals(ability.getProcessName()) || "镀后接收".equals(ability.getProcessName())){ |
|
|
|
|
if (ability != null) { |
|
|
|
|
if ("镀后检验".equals(ability.getProcessName()) || "镀后接收".equals(ability.getProcessName())) { |
|
|
|
|
totalTime = BigDecimal.valueOf(30); |
|
|
|
|
workPlan.setStartTime(prevProcessEnd.plusMinutes(30)); |
|
|
|
|
workPlan.setEndTime(prevProcessEnd.plusMinutes(60)); |
|
|
|
|
if("镀后接收".equals(ability.getProcessName())){ |
|
|
|
|
if ("镀后接收".equals(ability.getProcessName())) { |
|
|
|
|
workPlan.setMakeTeam(Long.valueOf(64)); |
|
|
|
|
} |
|
|
|
|
if("镀后检验".equals(ability.getProcessName())){ |
|
|
|
|
if ("镀后检验".equals(ability.getProcessName())) { |
|
|
|
|
workPlan.setMakeTeam(Long.valueOf(65)); |
|
|
|
|
} |
|
|
|
|
prevProcessEnd = workPlan.getEndTime(); |
|
|
|
|
}else{ |
|
|
|
|
if("0".equals(ability.getType())){ |
|
|
|
|
} else { |
|
|
|
|
if ("0".equals(ability.getType())) { |
|
|
|
|
totalTime = totalTime.add(BigDecimal.valueOf(order.getYpQty()).multiply(ability.getStandardTime()).add(ability.getPrepareTime())); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
totalTime = totalTime.add(ability.getStandardTime()).add(ability.getPrepareTime()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -573,7 +573,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
craftLock.unlock(); // 释放本地锁
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
//没有人员能力的先默认30分钟
|
|
|
|
|
totalTime = BigDecimal.valueOf(30); |
|
|
|
|
workPlan.setStartTime(prevProcessEnd); |
|
|
|
|
@ -596,16 +596,16 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
workPlanList.add(workPlan); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
//未匹配到设备和人力资源,将工序状态改为6,标识为未排产
|
|
|
|
|
craft.setStatus(YieldOrderEnum.STATUS_PROCESS_ERROR.getCategory()); |
|
|
|
|
yieldOrderCraftService.updateById(craft); |
|
|
|
|
} |
|
|
|
|
if(!isSchecuding){ |
|
|
|
|
if (!isSchecuding) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(!isSchecuding){ |
|
|
|
|
if (!isSchecuding) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -619,8 +619,8 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
workOrder.setBatchNo(order.getBatchNo()); |
|
|
|
|
workOrder.setYoId(order.getId()); |
|
|
|
|
workOrder.setMakeQty(order.getYpQty()); |
|
|
|
|
workOrder.setPlanStartDate(workPlanList.get(0).getStartTime() == null ? null :workPlanList.get(0).getStartTime().truncatedTo(ChronoUnit.DAYS).toString().substring(0,10)); |
|
|
|
|
workOrder.setPlanEndDate(workPlanList.get(workPlanList.size()-1).getEndTime() == null ? null : workPlanList.get(workPlanList.size()-1).getEndTime().truncatedTo(ChronoUnit.DAYS).toString().substring(0,10)); |
|
|
|
|
workOrder.setPlanStartDate(workPlanList.get(0).getStartTime() == null ? null : workPlanList.get(0).getStartTime().truncatedTo(ChronoUnit.DAYS).toString().substring(0, 10)); |
|
|
|
|
workOrder.setPlanEndDate(workPlanList.get(workPlanList.size() - 1).getEndTime() == null ? null : workPlanList.get(workPlanList.size() - 1).getEndTime().truncatedTo(ChronoUnit.DAYS).toString().substring(0, 10)); |
|
|
|
|
workOrder.setInventoryQty(0); |
|
|
|
|
workOrder.setRunStatus(2); |
|
|
|
|
workOrder.setPickingStatus(0); |
|
|
|
|
@ -642,13 +642,13 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
workPlanEntity.setWoId(workOrder.getId()); |
|
|
|
|
workPlanService.save(workPlanEntity); |
|
|
|
|
}); |
|
|
|
|
for(int i=0;i<workPlanList.size();i++){ |
|
|
|
|
for (int i = 0; i < workPlanList.size(); i++) { |
|
|
|
|
WorkPlanEntity workPlan = workPlanList.get(i); |
|
|
|
|
if(i != 0){ |
|
|
|
|
workPlan.setFrontWpId(workPlanList.get(i-1).getId()); |
|
|
|
|
if (i != 0) { |
|
|
|
|
workPlan.setFrontWpId(workPlanList.get(i - 1).getId()); |
|
|
|
|
} |
|
|
|
|
if(i != workPlanList.size() -1){ |
|
|
|
|
workPlan.setNextWpId(workPlanList.get(i+1).getId()); |
|
|
|
|
if (i != workPlanList.size() - 1) { |
|
|
|
|
workPlan.setNextWpId(workPlanList.get(i + 1).getId()); |
|
|
|
|
} |
|
|
|
|
workPlanService.updateById(workPlan); |
|
|
|
|
} |
|
|
|
|
@ -661,12 +661,12 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
workOrderList.add(workOrder); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("报错订单是:"+order.getId()+",报错信息是:"+e.getMessage()); |
|
|
|
|
log.error("报错订单是:" + order.getId() + ",报错信息是:" + e.getMessage()); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if(CollectionUtils.isNotEmpty(workOrderList)){ |
|
|
|
|
if (CollectionUtils.isNotEmpty(workOrderList)) { |
|
|
|
|
this.sendWorkOrderToOldMes(workOrderList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -695,24 +695,24 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
//根据设备的计划推算其他人力工序的开始结束时间
|
|
|
|
|
public void WorkPlanTimeCalculator(List<WorkPlanEntity> list) { |
|
|
|
|
//根据作业中心分组
|
|
|
|
|
Map<Long,List<WorkPlanEntity>> workPlanMap = list.stream().collect(Collectors.groupingBy(WorkPlanEntity::getWorkCenterId)); |
|
|
|
|
for(Map.Entry<Long,List<WorkPlanEntity>> entry : workPlanMap.entrySet()){ |
|
|
|
|
Map<Long, List<WorkPlanEntity>> workPlanMap = list.stream().collect(Collectors.groupingBy(WorkPlanEntity::getWorkCenterId)); |
|
|
|
|
for (Map.Entry<Long, List<WorkPlanEntity>> entry : workPlanMap.entrySet()) { |
|
|
|
|
List<WorkPlanEntity> workPlanList = entry.getValue(); |
|
|
|
|
int startIndex = -1; |
|
|
|
|
int endIndex = -1; |
|
|
|
|
for(int i =0;i<workPlanList.size();i++){ |
|
|
|
|
if(workPlanList.get(i).getStartTime() != null){ |
|
|
|
|
for (int i = 0; i < workPlanList.size(); i++) { |
|
|
|
|
if (workPlanList.get(i).getStartTime() != null) { |
|
|
|
|
startIndex = i; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for(int i=workPlanList.size() -1 ;i>0;i--){ |
|
|
|
|
if(workPlanList.get(i).getEndTime() != null){ |
|
|
|
|
for (int i = workPlanList.size() - 1; i > 0; i--) { |
|
|
|
|
if (workPlanList.get(i).getEndTime() != null) { |
|
|
|
|
endIndex = i; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(startIndex != -1){ |
|
|
|
|
if (startIndex != -1) { |
|
|
|
|
// 向前推算(锚点之前的计划:从锚点前一个开始,依次往前)
|
|
|
|
|
for (int i = startIndex - 1; i >= 0; i--) { |
|
|
|
|
WorkPlanEntity current = workPlanList.get(i); |
|
|
|
|
@ -729,7 +729,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
current.setMakeTeam(next.getMakeTeam()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(endIndex != -1){ |
|
|
|
|
if (endIndex != -1) { |
|
|
|
|
// 向后推算(锚点之后的计划:从锚点后一个开始,依次往后)
|
|
|
|
|
for (int i = endIndex + 1; i < workPlanList.size(); i++) { |
|
|
|
|
WorkPlanEntity current = workPlanList.get(i); |
|
|
|
|
@ -746,7 +746,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
current.setMakeTeam(prev.getMakeTeam()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<list.size();i++){ |
|
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -755,11 +755,12 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<BigDecimal> capacitySplit(Map<LocalDateTime, List<EquipResourceEntity>> map,BigDecimal sumCapacity){ |
|
|
|
|
public List<BigDecimal> capacitySplit(Map<LocalDateTime, List<EquipResourceEntity>> map, BigDecimal sumCapacity) { |
|
|
|
|
List<EquipResourceEntity> equipResourceList1 = map.values().stream().flatMap(List::stream).collect(Collectors.toList()); |
|
|
|
|
BigDecimal maxRestCapacity = equipResourceList1.stream().filter(entity -> entity.getRestCapacity().compareTo(BigDecimal.ZERO) >= 0).map(EquipResourceEntity::getRestCapacity).max(BigDecimal::compareTo).orElseThrow(() -> new IllegalArgumentException("列表中无有效的 restCapacity 数值"));; |
|
|
|
|
BigDecimal maxRestCapacity = equipResourceList1.stream().filter(entity -> entity.getRestCapacity().compareTo(BigDecimal.ZERO) >= 0).map(EquipResourceEntity::getRestCapacity).max(BigDecimal::compareTo).orElseThrow(() -> new IllegalArgumentException("列表中无有效的 restCapacity 数值")); |
|
|
|
|
; |
|
|
|
|
List<BigDecimal> capacityList = new ArrayList<>(); |
|
|
|
|
if(sumCapacity.compareTo(maxRestCapacity) > 0){ |
|
|
|
|
if (sumCapacity.compareTo(maxRestCapacity) > 0) { |
|
|
|
|
// 计算商(fullCount)和余数(remainder):divideAndRemainder返回[商, 余数]
|
|
|
|
|
BigDecimal[] divideResult = sumCapacity.divideAndRemainder(maxRestCapacity); |
|
|
|
|
BigDecimal fullCountBig = divideResult[0]; // 商(如11/2=5)
|
|
|
|
|
@ -785,11 +786,13 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
result[fullCount] = remainder; |
|
|
|
|
} |
|
|
|
|
capacityList = Arrays.asList(result); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
capacityList.add(sumCapacity); |
|
|
|
|
} |
|
|
|
|
return capacityList; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取时间列表中的最早时间(字符串转LocalDateTime比较) |
|
|
|
|
@ -839,42 +842,43 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
.map(dt -> dt.format(dateTimeFormatter)) |
|
|
|
|
.orElse(null); |
|
|
|
|
} |
|
|
|
|
public void checkSchedulingOrder(List<YieldOrderEntity> list){ |
|
|
|
|
|
|
|
|
|
public void checkSchedulingOrder(List<YieldOrderEntity> list) { |
|
|
|
|
//判断待排产优先级,1级所有1级往后订单重新排产,2级订单重新排4/5级订单
|
|
|
|
|
List<Integer> priorityList = list.stream().map(YieldOrderEntity::getPriorityAps).collect(Collectors.toList()); |
|
|
|
|
if(priorityList.contains(1)){ |
|
|
|
|
if (priorityList.contains(1)) { |
|
|
|
|
//查询所有非一级的待生产订单
|
|
|
|
|
List<YieldOrderEntity> schedulingOrderList = yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().ne(YieldOrderEntity::getPriorityAps,1).eq(YieldOrderEntity::getStatus,4)); |
|
|
|
|
List<YieldOrderEntity> schedulingOrderList = yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().ne(YieldOrderEntity::getPriorityAps, 1).eq(YieldOrderEntity::getStatus, 4)); |
|
|
|
|
//校验已排产订单资源占用情况
|
|
|
|
|
checkResource(schedulingOrderList); |
|
|
|
|
} |
|
|
|
|
if(priorityList.contains(2)){ |
|
|
|
|
if (priorityList.contains(2)) { |
|
|
|
|
//查询4/5级的待生产订单
|
|
|
|
|
List<YieldOrderEntity> schedulingOrderList = yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().in(YieldOrderEntity::getPriorityAps,Arrays.asList("4","5")).eq(YieldOrderEntity::getStatus,4)); |
|
|
|
|
List<YieldOrderEntity> schedulingOrderList = yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().in(YieldOrderEntity::getPriorityAps, Arrays.asList("4", "5")).eq(YieldOrderEntity::getStatus, 4)); |
|
|
|
|
checkResource(schedulingOrderList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void checkResource(List<YieldOrderEntity> list){ |
|
|
|
|
if(CollectionUtils.isNotEmpty(list)){ |
|
|
|
|
public void checkResource(List<YieldOrderEntity> list) { |
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
|
//根据订单查询设备资源
|
|
|
|
|
for(YieldOrderEntity yieldOrder : list){ |
|
|
|
|
for (YieldOrderEntity yieldOrder : list) { |
|
|
|
|
//查询相关车间订单
|
|
|
|
|
WorkOrderEntity workOrder = this.getOne(Wrappers.<WorkOrderEntity>lambdaQuery().eq(WorkOrderEntity::getYoId,yieldOrder.getId())); |
|
|
|
|
if(workOrder != null){ |
|
|
|
|
List<WorkPlanEntity> schedulingPlanList = workPlanService.list(Wrappers.<WorkPlanEntity>lambdaQuery().eq(WorkPlanEntity::getWoId,workOrder.getId())); |
|
|
|
|
if(CollectionUtils.isNotEmpty(schedulingPlanList)){ |
|
|
|
|
for(WorkPlanEntity workPlan : schedulingPlanList){ |
|
|
|
|
WorkOrderEntity workOrder = this.getOne(Wrappers.<WorkOrderEntity>lambdaQuery().eq(WorkOrderEntity::getYoId, yieldOrder.getId())); |
|
|
|
|
if (workOrder != null) { |
|
|
|
|
List<WorkPlanEntity> schedulingPlanList = workPlanService.list(Wrappers.<WorkPlanEntity>lambdaQuery().eq(WorkPlanEntity::getWoId, workOrder.getId())); |
|
|
|
|
if (CollectionUtils.isNotEmpty(schedulingPlanList)) { |
|
|
|
|
for (WorkPlanEntity workPlan : schedulingPlanList) { |
|
|
|
|
//还原设备资源
|
|
|
|
|
if(workPlan.getEquipResourceId() != null){ |
|
|
|
|
if (workPlan.getEquipResourceId() != null) { |
|
|
|
|
EquipResourceEntity equipResource = equipResourceService.getById(workPlan.getEquipResourceId()); |
|
|
|
|
equipResource.setIsUsed("0"); |
|
|
|
|
equipResource.setRestCapacity(equipResource.getRestCapacity().add(workPlan.getHourQuota())); |
|
|
|
|
LambdaUpdateWrapper<EquipResourceEntity> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getEquipCode,equipResource.getEquipCode()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getDateTime,equipResource.getDateTime()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getPeriod,equipResource.getPeriod()); |
|
|
|
|
equipResourceService.update(equipResource,updateWrapper); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getEquipCode, equipResource.getEquipCode()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getDateTime, equipResource.getDateTime()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getPeriod, equipResource.getPeriod()); |
|
|
|
|
equipResourceService.update(equipResource, updateWrapper); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//还原人力资源
|
|
|
|
|
@ -960,33 +964,33 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
return batches; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Map<String,List<WorkPlanEntity>> dealCommonCraftOrders(){ |
|
|
|
|
public Map<String, List<WorkPlanEntity>> dealCommonCraftOrders() { |
|
|
|
|
List<YieldOrderEntity> commonCraftOrderList = yieldOrderService.selectCommonCraftOrderList(); |
|
|
|
|
Map<String,List<WorkPlanEntity>> planMap = new HashMap<>(); |
|
|
|
|
if(CollectionUtils.isNotEmpty(commonCraftOrderList)){ |
|
|
|
|
Map<String, List<WorkPlanEntity>> planMap = new HashMap<>(); |
|
|
|
|
if (CollectionUtils.isNotEmpty(commonCraftOrderList)) { |
|
|
|
|
//对订单进行排序,每5个相同workCenterId的为一组,实现负载均衡
|
|
|
|
|
commonCraftOrderList = sortByWorkcenterIdPer5Group(commonCraftOrderList); |
|
|
|
|
//对前置公共工序进行排产
|
|
|
|
|
//获取公共工序设备能力,根据工艺能力查询,写死ID是27
|
|
|
|
|
EquipAbilityEntity equipAbility = equipAbilityService.getOne(Wrappers.<EquipAbilityEntity>lambdaQuery().eq(EquipAbilityEntity::getCraftId,27)); |
|
|
|
|
EquipAbilityEntity equipAbility = equipAbilityService.getOne(Wrappers.<EquipAbilityEntity>lambdaQuery().eq(EquipAbilityEntity::getCraftId, 27)); |
|
|
|
|
BigDecimal standardProcessAbility = equipAbility.getStandardProcessAbility(); |
|
|
|
|
//获取所有空闲的公共工序资源
|
|
|
|
|
List<EquipResourceEntity> equipResourceList = equipResourceService.selectCommonCraftList(); |
|
|
|
|
for(YieldOrderEntity order : commonCraftOrderList){ |
|
|
|
|
for (YieldOrderEntity order : commonCraftOrderList) { |
|
|
|
|
List<WorkPlanEntity> workPlanList = new ArrayList<>(); |
|
|
|
|
//获取相关工序
|
|
|
|
|
YieldOrderCraftEntity craft = yieldOrderCraftService.getOne(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId,order.getId()).eq(YieldOrderCraftEntity::getCaId,equipAbility.getCraftId())); |
|
|
|
|
if(craft == null){ |
|
|
|
|
YieldOrderCraftEntity craft = yieldOrderCraftService.getOne(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId, order.getId()).eq(YieldOrderCraftEntity::getCaId, equipAbility.getCraftId())); |
|
|
|
|
if (craft == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//计算订单总产能
|
|
|
|
|
BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(100)).multiply(BigDecimal.valueOf(order.getYpQty())); |
|
|
|
|
//计算需要占用几个时间段
|
|
|
|
|
int period = sumCapacity.divide(standardProcessAbility,0, RoundingMode.CEILING).intValue(); |
|
|
|
|
int period = sumCapacity.divide(standardProcessAbility, 0, RoundingMode.CEILING).intValue(); |
|
|
|
|
|
|
|
|
|
for(int i=0;i<period;i++){ |
|
|
|
|
for(int j=0;j<equipResourceList.size();j++){ |
|
|
|
|
if(i==j){ |
|
|
|
|
for (int i = 0; i < period; i++) { |
|
|
|
|
for (int j = 0; j < equipResourceList.size(); j++) { |
|
|
|
|
if (i == j) { |
|
|
|
|
EquipResourceEntity equipResource = equipResourceList.get(j); |
|
|
|
|
equipResource.setIsUsed("1"); |
|
|
|
|
equipResourceService.updateById(equipResource); |
|
|
|
|
@ -1014,7 +1018,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
planMap.put(order.getYoCode(),workPlanList); |
|
|
|
|
planMap.put(order.getYoCode(), workPlanList); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1043,7 +1047,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
public static final String prefix(String StringToFix, String fixChar, int targetLen) { |
|
|
|
|
int len = StringToFix.length(); |
|
|
|
|
|
|
|
|
|
for(int i = 0; i < targetLen - len; i += fixChar.length()) { |
|
|
|
|
for (int i = 0; i < targetLen - len; i += fixChar.length()) { |
|
|
|
|
StringToFix = fixChar + StringToFix; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1051,31 +1055,31 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void restoreResource(List<WorkPlanEntity> list){ |
|
|
|
|
for(WorkPlanEntity workPlan : list){ |
|
|
|
|
public void restoreResource(List<WorkPlanEntity> list) { |
|
|
|
|
for (WorkPlanEntity workPlan : list) { |
|
|
|
|
//还原设备资源
|
|
|
|
|
if(workPlan.getEquipResourceId() != null){ |
|
|
|
|
if (workPlan.getEquipResourceId() != null) { |
|
|
|
|
EquipResourceEntity equipResource = equipResourceService.getById(workPlan.getEquipResourceId()); |
|
|
|
|
equipResource.setIsUsed("0"); |
|
|
|
|
equipResource.setRestCapacity(equipResource.getRestCapacity().add(workPlan.getHourQuota())); |
|
|
|
|
LambdaUpdateWrapper<EquipResourceEntity> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getEquipCode,equipResource.getEquipCode()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getDateTime,equipResource.getDateTime()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getPeriod,equipResource.getPeriod()); |
|
|
|
|
equipResourceService.update(equipResource,updateWrapper); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getEquipCode, equipResource.getEquipCode()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getDateTime, equipResource.getDateTime()); |
|
|
|
|
updateWrapper.eq(EquipResourceEntity::getPeriod, equipResource.getPeriod()); |
|
|
|
|
equipResourceService.update(equipResource, updateWrapper); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//还原人力资源
|
|
|
|
|
if(workPlan.getPersonResourceIds() != null){ |
|
|
|
|
List<PersonResourceEntity> personResourceList = personResourceService.list(Wrappers.<PersonResourceEntity>lambdaQuery().in(BaseEntity::getId,workPlan.getPersonResourceIds().split(","))); |
|
|
|
|
if(CollectionUtils.isNotEmpty(personResourceList)){ |
|
|
|
|
personResourceList.forEach(item ->{ |
|
|
|
|
if (workPlan.getPersonResourceIds() != null) { |
|
|
|
|
List<PersonResourceEntity> personResourceList = personResourceService.list(Wrappers.<PersonResourceEntity>lambdaQuery().in(BaseEntity::getId, workPlan.getPersonResourceIds().split(","))); |
|
|
|
|
if (CollectionUtils.isNotEmpty(personResourceList)) { |
|
|
|
|
personResourceList.forEach(item -> { |
|
|
|
|
item.setIsUsed("0"); |
|
|
|
|
personResourceService.updateById(item); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(workPlan.getId() != null){ |
|
|
|
|
if (workPlan.getId() != null) { |
|
|
|
|
workPlanService.deleteLogic(Arrays.asList(workPlan.getId())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|