排产相关-sjx

master
sunjianxi 4 days ago
parent 99c325494c
commit ed15a6136a
  1. 567
      blade-service/blade-scheduling/src/main/java/org/springblade/scheduling/scheduling/service/impl/WorkOrderServiceImpl.java

@ -113,7 +113,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
@Override @Override
public void scheduling() { public void scheduling() {
//查询待排产订单,状态是3 //查询待排产订单,状态是3
List<YieldOrderEntity> list = yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().eq(BaseEntity::getStatus, YieldOrderConst.STATUS_APS).isNotNull(YieldOrderEntity::getWorkCenterId)); List<YieldOrderEntity> list = yieldOrderService.list(Wrappers.<YieldOrderEntity>lambdaQuery().eq(BaseEntity::getStatus, YieldOrderConst.STATUS_APS).isNotNull(YieldOrderEntity::getWorkCenterId).isNotNull(YieldOrderEntity::getReleaseDate));
log.info("待排产订单数量为:" + list.size()); log.info("待排产订单数量为:" + list.size());
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
//校验已排产订单 //校验已排产订单
@ -144,7 +144,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
list1 -> { list1 -> {
// 排序逻辑:优先级升序 → CR值降序 → 数量降序 → 时间升序 // 排序逻辑:优先级升序 → CR值降序 → 数量降序 → 时间升序
list1.sort(Comparator.comparingInt(YieldOrderEntity::getPriorityAps).reversed() list1.sort(Comparator.comparingInt(YieldOrderEntity::getPriorityAps).reversed()
//.thenComparing((e1, e2) -> e2.getCrValue().compareTo(e1.getCrValue())) .thenComparing((e1, e2) -> e2.getCrValue().compareTo(e1.getCrValue()))
.thenComparingInt(YieldOrderEntity::getYpQty).reversed() .thenComparingInt(YieldOrderEntity::getYpQty).reversed()
.thenComparing(YieldOrderEntity::getReleaseDate)); .thenComparing(YieldOrderEntity::getReleaseDate));
return list1; return list1;
@ -468,302 +468,320 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
public void allocateResources(List<YieldOrderEntity> list,Map<String, PersonAbilityEntity> personAbilityMap,Map<Long, String> mainProducerMap,Map<String,List<WorkPlanEntity>> planMap) { public void allocateResources(List<YieldOrderEntity> list,Map<String, PersonAbilityEntity> personAbilityMap,Map<Long, String> mainProducerMap,Map<String,List<WorkPlanEntity>> planMap) {
List<WorkOrderEntity> workOrderList = new ArrayList<>(); List<WorkOrderEntity> workOrderList = new ArrayList<>();
for (YieldOrderEntity order : list) { for (YieldOrderEntity order : list) {
//是否可以排产 try {
Boolean isSchecuding = true; //是否可以排产
List<WorkPlanEntity> workPlanList = new ArrayList<>(); 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<Long> workCenterList = craftList.stream().filter(item -> item.getWorkCenterId() != null).map(YieldOrderCraftEntity::getWorkCenterId).collect(Collectors.toList()); List<YieldOrderCraftEntity> craftList = yieldOrderCraftService.list(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId, order.getId()).ne(YieldOrderCraftEntity::getCaId,27).orderByAsc(YieldOrderCraftEntity::getProcessNo));
if(workCenterList.size() != craftList.size()){ List<Long> workCenterList = craftList.stream().filter(item -> item.getWorkCenterId() != null).map(YieldOrderCraftEntity::getWorkCenterId).collect(Collectors.toList());
order.setErrorInfo("工序信息不完整,含有未匹配作业中心的工序"); if(workCenterList.size() != craftList.size()){
order.setStatus(6); order.setErrorInfo("工序信息不完整,含有未匹配作业中心的工序");
yieldOrderService.updateById(order); order.setStatus(6);
continue; yieldOrderService.updateById(order);
} continue;
}
//上一道工序结束时间 //上一道工序结束时间
LocalDateTime prevProcessEnd = LocalDateTime.now(); LocalDateTime prevProcessEnd = LocalDateTime.now();
//判断是否有公共工序已经处理了,如果有则重新定义workPlanList,获取公共工序的最后结束时间和当前时间做比较,取大的作为上一道工序结束时间 //判断是否有公共工序已经处理了,如果有则重新定义workPlanList,获取公共工序的最后结束时间和当前时间做比较,取大的作为上一道工序结束时间
if(planMap.containsKey(order.getYoCode())){ if(planMap.containsKey(order.getYoCode())){
workPlanList = planMap.get(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++) { for (int i = 0; i < craftList.size(); i++) {
YieldOrderCraftEntity craft = craftList.get(i); YieldOrderCraftEntity craft = craftList.get(i);
if ("设备".equals(mainProducerMap.get(craft.getPpsId()))) { if ("设备".equals(mainProducerMap.get(craft.getPpsId()))) {
//根据作业中心查询所有设备 //根据作业中心查询所有设备
List<EquipAbilityEntity> equipAbilityList = equipAbilityService.list(Wrappers.<EquipAbilityEntity>lambdaQuery().in(EquipAbilityEntity::getWorkCenterId, craft.getWorkCenterId())); List<EquipAbilityEntity> equipAbilityList = equipAbilityService.list(Wrappers.<EquipAbilityEntity>lambdaQuery().in(EquipAbilityEntity::getWorkCenterId, craft.getWorkCenterId()));
if(CollectionUtils.isEmpty(equipAbilityList)){ if(CollectionUtils.isEmpty(equipAbilityList)){
order.setErrorInfo("设备未匹配到对应的设备能力"); order.setErrorInfo("设备未匹配到对应的设备能力");
order.setStatus(6);
yieldOrderService.updateById(order);
isSchecuding = false;
break;
}
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()){
//根据时间点获取所有设备资源
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(6); order.setStatus(6);
order.setErrorInfo("工序:"+craft.getPpsId()+"未匹配到对应的设备资源");
yieldOrderService.updateById(order); yieldOrderService.updateById(order);
isSchecuding = false; isSchecuding = false;
break; break;
} }
//设备资源按照时间段分组并按时间排序,然后再每个组内按照剩余产能倒序排序 Map<Integer,List<EquipAbilityEntity>> equipAbilityMap = equipAbilityList.stream().collect(Collectors.groupingBy(EquipAbilityEntity::getEquipOrder));
Map<LocalDateTime, List<EquipResourceEntity>> equipResourceMap = equipResourceList.stream()
.collect(Collectors.groupingBy( //匹配设备资源
EquipResourceEntity::getStartTime, // 分组字段:startTime //获取下一个整数点
// 用TreeMap接收,指定startTime降序(分组的排序) LocalDateTime dateTime = getNextIntegerTime(prevProcessEnd);
TreeMap::new, for(Map.Entry<Integer,List<EquipAbilityEntity>> entry : equipAbilityMap.entrySet()){
// 组内收集器:按restCapacity降序排序 //根据时间点获取所有设备资源
Collectors.collectingAndThen( 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()));
Collectors.toList(), if(CollectionUtils.isEmpty(equipResourceList)){
list1 -> list1.stream() order.setStatus(6);
.sorted(Comparator.comparing( order.setErrorInfo("工序:"+craft.getPpsId()+"未匹配到对应的设备资源");
EquipResourceEntity::getRestCapacity, yieldOrderService.updateById(order);
// restCapacity 降序比较器(BigDecimal专用) isSchecuding = false;
Comparator.reverseOrder() break;
)) }
.collect(Collectors.toList()) //设备资源按照时间段分组并按时间排序,然后再每个组内按照剩余产能倒序排序
) Map<LocalDateTime, List<EquipResourceEntity>> equipResourceMap = equipResourceList.stream()
)); .collect(Collectors.groupingBy(
//计算生产所需产能,需将m2换算成dm2 EquipResourceEntity::getStartTime, // 分组字段:startTime
BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(order.getYpQty())); // 用TreeMap接收,指定startTime降序(分组的排序)
//需要判断设备额定生产能力是否满足订单总产能,如果不满足,则需要把总产能进行拆分 TreeMap::new,
List<BigDecimal> capacityList = capacitySplit(equipResourceMap,sumCapacity); // 组内收集器:按restCapacity降序排序
for(BigDecimal capacity : capacityList){ Collectors.collectingAndThen(
for(Map.Entry<LocalDateTime, List<EquipResourceEntity>> entry1 : equipResourceMap.entrySet()){ Collectors.toList(),
Boolean isOccupied = false; list1 -> list1.stream()
List<EquipResourceEntity> resourceList = entry1.getValue(); .sorted(Comparator.comparing(
for (EquipResourceEntity equipResource : resourceList) { EquipResourceEntity::getRestCapacity,
//如果产能最大的设备都不满足,后面的设备就不需要判断了 // restCapacity 降序比较器(BigDecimal专用)
if (equipResource.getRestCapacity().compareTo(capacity) < 0) { Comparator.reverseOrder()
break; ))
} else { .collect(Collectors.toList())
//生成车间订单 )
WorkPlanEntity workPlan = new WorkPlanEntity(); ));
workPlan.setStartTime(equipResource.getStartTime()); //计算生产所需产能,需将m2换算成dm2
if(entry.getKey() == 1){ BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(order.getYpQty()));
workPlan.setEndTime(equipResource.getStartTime().plusMinutes(equipResource.getStandardTime().longValue())); //需要判断设备额定生产能力是否满足订单总产能,如果不满足,则需要把总产能进行拆分
}else{ List<BigDecimal> capacityList = capacitySplit(equipResourceMap,sumCapacity);
workPlan.setEndTime(equipResource.getEndTime()); 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) {
//如果产能最大的设备都不满足,后面的设备就不需要判断了
if (equipResource.getRestCapacity().compareTo(capacity) < 0) {
break;
} else {
//生成车间订单
WorkPlanEntity workPlan = new WorkPlanEntity();
workPlan.setStartTime(equipResource.getStartTime());
if(entry.getKey() == 1){
workPlan.setEndTime(equipResource.getStartTime().plusMinutes(equipResource.getStandardTime().longValue()));
}else{
workPlan.setEndTime(equipResource.getEndTime());
}
workPlan.setWorkQty(order.getYpQty());
workPlan.setCaId(craft.getCaId());
workPlan.setPpsId(craft.getPpsId());
workPlan.setMakeTeam(equipResource.getTeamId());
workPlan.setWorkCenterId(craft.getWorkCenterId());
workPlan.setOrders(craft.getProcessNo());
workPlan.setWoId(order.getId());
workPlan.setOem("0");
workPlan.setTestQty(0);
workPlan.setQualifiedQty(0);
workPlan.setUnqualifiedQty(0);
workPlan.setScrapQty(0);
workPlan.setHourQuota(BigDecimal.valueOf(ChronoUnit.MINUTES.between(workPlan.getStartTime(), workPlan.getEndTime())));
workPlan.setEquipCode(equipResource.getEquipCode());
workPlan.setEquipName(equipResource.getEquipName());
workPlan.setEquipResourceId(equipResource.getId());
workPlanList.add(workPlan);
//更新剩余产能
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){
//
// }
//同一个设备可能有多个工艺能力,同一时间只能做一个工艺能力的零件,所以需要把当前设备所有工艺能力的剩余产能都更新调
LambdaUpdateWrapper<EquipResourceEntity> equipWrapper = new LambdaUpdateWrapper<>();
equipWrapper.eq(EquipResourceEntity::getEquipCode,equipResource.getEquipCode());
equipWrapper.eq(EquipResourceEntity::getDateTime,equipResource.getDateTime());
equipWrapper.eq(EquipResourceEntity::getPeriod,equipResource.getPeriod());
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());
EquipResourceEntity equipResource1 = new EquipResourceEntity();
equipResource1.setIsUsed("1");
equipResourceService.update(equipResource1, updateWrapper);
//当前工序的结束时间作为下一工序的开始时间
prevProcessEnd = workPlan.getEndTime();
dateTime = workPlan.getEndTime();
isOccupied = true;
break;
} }
workPlan.setWorkQty(order.getYpQty()); }
workPlan.setCaId(craft.getCaId()); if (isOccupied) {
workPlan.setPpsId(craft.getPpsId());
workPlan.setMakeTeam(equipResource.getTeamId());
workPlan.setWorkCenterId(craft.getWorkCenterId());
workPlan.setOrders(craft.getProcessNo());
workPlan.setWoId(order.getId());
workPlan.setOem("0");
workPlan.setTestQty(0);
workPlan.setQualifiedQty(0);
workPlan.setUnqualifiedQty(0);
workPlan.setScrapQty(0);
workPlan.setHourQuota(BigDecimal.valueOf(ChronoUnit.MINUTES.between(workPlan.getStartTime(), workPlan.getEndTime())));
workPlan.setEquipCode(equipResource.getEquipCode());
workPlan.setEquipName(equipResource.getEquipName());
workPlan.setEquipResourceId(equipResource.getId());
workPlanList.add(workPlan);
//更新剩余产能
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){
//
// }
//同一个设备可能有多个工艺能力,同一时间只能做一个工艺能力的零件,所以需要把当前设备所有工艺能力的剩余产能都更新调
LambdaUpdateWrapper<EquipResourceEntity> equipWrapper = new LambdaUpdateWrapper<>();
equipWrapper.eq(EquipResourceEntity::getEquipCode,equipResource.getEquipCode());
equipWrapper.eq(EquipResourceEntity::getDateTime,equipResource.getDateTime());
equipWrapper.eq(EquipResourceEntity::getPeriod,equipResource.getPeriod());
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());
EquipResourceEntity equipResource1 = new EquipResourceEntity();
equipResource1.setIsUsed("1");
equipResourceService.update(equipResource1, updateWrapper);
//当前工序的结束时间作为下一工序的开始时间
prevProcessEnd = workPlan.getEndTime();
dateTime = workPlan.getEndTime();
isOccupied = true;
break; break;
} }
} }
if (isOccupied) {
break;
}
} }
} }
} if(!isSchecuding){
if(!isSchecuding){ break;
break; }
}
} else if ("人".equals(mainProducerMap.get(craft.getPpsId()))) { } else if ("人".equals(mainProducerMap.get(craft.getPpsId()))) {
//匹配人资源 //匹配人资源
/* String personAbility = craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId(); /* String personAbility = craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId();
if (personAbilityMap.containsKey(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId())) { if (personAbilityMap.containsKey(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId())) {
} else { } else {
order.setStatus(6); order.setStatus(6);
order.setErrorInfo("工序:"+personAbility+"未匹配到对应的人员能力"); order.setErrorInfo("工序:"+personAbility+"未匹配到对应的人员能力");
yieldOrderService.updateById(order); yieldOrderService.updateById(order);
isSchecuding = false; isSchecuding = false;
break; break;
}*/ }*/
WorkPlanEntity workPlan = new WorkPlanEntity(); WorkPlanEntity workPlan = new WorkPlanEntity();
BigDecimal totalTime = new BigDecimal(0); 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){ List<Integer> caIds = Arrays.asList(10,21);
totalTime = totalTime.add(BigDecimal.valueOf(order.getYpQty()).multiply(personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId()).getStandardTime()).add(personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId()).getPrepareTime())); //镀后检验和镀后接收先按半小时计算
}*/ if(ability != null){
//镀后检验和镀后接收先按半小时计算 if(caIds.contains(craft.getCaId())){
if(ability != null){ totalTime = BigDecimal.valueOf(30);
//通过加锁的方式保证每次查询到的人力资源都是最新的 workPlan.setStartTime(prevProcessEnd);
Long craftId = craft.getCaId(); workPlan.setEndTime(prevProcessEnd.plusMinutes(30));
Lock craftLock = getCraftLock(craftId); if(craft.getCaId() == 10){
craftLock.lock(); // 加本地锁,同一工艺ID串行执行 workPlan.setMakeTeam(Long.valueOf(64));
try{
//查询大于当前时间+半小时的所有人员资源
List<PersonResourceEntity> personResourceList = personResourceService.list(Wrappers.<PersonResourceEntity>lambdaQuery().ge(PersonResourceEntity::getStartTime,prevProcessEnd.plusMinutes(30)).eq(PersonResourceEntity::getCraftId,craft.getCaId()).eq(PersonResourceEntity::getIsUsed,0).orderByAsc(PersonResourceEntity::getStartTime).last("for update"));
//如果personResourceList不为空,说明是镀后检验或者镀后验收这类跨作业中心的工艺
if(CollectionUtils.isNotEmpty(personResourceList)){
//剔除掉personResourceList中isUsed=1之前的数据,isUsed=1说明这些时间被占用了
/* int isUsedIndex = -1;
for(int m=0;m<personResourceList.size();m++){
if("1".equals(personResourceList.get(m).getIsUsed())){
isUsedIndex = m;
}
} }
if(isUsedIndex != -1){ if(craft.getCaId() == 21){
personResourceList = personResourceList.subList(isUsedIndex + 1, personResourceList.size()); workPlan.setMakeTeam(Long.valueOf(65));
}*/
//计算加工时间占几个人力片段
//int period = totalTime.divide(BigDecimal.valueOf(30),0, RoundingMode.CEILING).intValue();
//1.如果size=0,说明最近3天的资源都排满了,就不需要排了
if(personResourceList.size() == 0){
//还原已占用资源
restoreResource(workPlanList);
order.setErrorInfo("最近3天人力资源已占满,需下次排产");
yieldOrderService.updateById(order);
isSchecuding = false;
break;
} }
//占用时间段 }else{
/*LocalDateTime startTime = LocalDateTime.now(); totalTime = totalTime.add(BigDecimal.valueOf(order.getYpQty()).multiply(personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId()).getStandardTime()).add(personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId()).getPrepareTime()));
LocalDateTime endTime = LocalDateTime.now(); }
StringBuilder personResourceIds = new StringBuilder();
for(int j=0;j<period;j++){
//通过加锁的方式保证每次查询到的人力资源都是最新的
PersonResourceEntity personResource = personResourceList.get(j); /*Long craftId = craft.getCaId();
if(j == 0){ Lock craftLock = getCraftLock(craftId);
startTime = personResource.getStartTime(); craftLock.lock(); // 加本地锁,同一工艺ID串行执行
try{
//查询大于当前时间+半小时的所有人员资源
List<PersonResourceEntity> personResourceList = personResourceService.list(Wrappers.<PersonResourceEntity>lambdaQuery().ge(PersonResourceEntity::getStartTime,prevProcessEnd.plusMinutes(30)).eq(PersonResourceEntity::getCraftId,craft.getCaId()).eq(PersonResourceEntity::getIsUsed,0).orderByAsc(PersonResourceEntity::getStartTime).last("for update"));
//如果personResourceList不为空,说明是镀后检验或者镀后验收这类跨作业中心的工艺
if(CollectionUtils.isNotEmpty(personResourceList)){
//剔除掉personResourceList中isUsed=1之前的数据,isUsed=1说明这些时间被占用了
*//* int isUsedIndex = -1;
for(int m=0;m<personResourceList.size();m++){
if("1".equals(personResourceList.get(m).getIsUsed())){
isUsedIndex = m;
}
} }
if(j == period - 1){ if(isUsedIndex != -1){
endTime = personResource.getEndTime(); personResourceList = personResourceList.subList(isUsedIndex + 1, personResourceList.size());
}*//*
//计算加工时间占几个人力片段
//int period = totalTime.divide(BigDecimal.valueOf(30),0, RoundingMode.CEILING).intValue();
//1.如果size=0,说明最近3天的资源都排满了,就不需要排了
if(personResourceList.size() == 0){
//还原已占用资源
restoreResource(workPlanList);
order.setErrorInfo("最近3天人力资源已占满,需下次排产");
yieldOrderService.updateById(order);
isSchecuding = false;
break;
} }
//占用时间段
*//*LocalDateTime startTime = LocalDateTime.now();
LocalDateTime endTime = LocalDateTime.now();
StringBuilder personResourceIds = new StringBuilder();
for(int j=0;j<period;j++){
PersonResourceEntity personResource = personResourceList.get(j);
if(j == 0){
startTime = personResource.getStartTime();
}
if(j == period - 1){
endTime = personResource.getEndTime();
}
personResource.setIsUsed("1");
personResourceService.updateById(personResource);
if(j!=period-1){
personResourceIds.append(personResource.getId()).append(",");
}else{
personResourceIds.append(personResource.getId());
}
}*//*
PersonResourceEntity personResource = personResourceList.get(0);
personResource.setIsUsed("1"); personResource.setIsUsed("1");
personResourceService.updateById(personResource); personResourceService.updateById(personResource);
if(j!=period-1){ workPlan.setPersonResourceIds(personResource.getId().toString());
personResourceIds.append(personResource.getId()).append(","); workPlan.setStartTime(personResource.getStartTime());
}else{ workPlan.setEndTime(personResource.getEndTime());
personResourceIds.append(personResource.getId()); workPlan.setMakeTeam(personResourceList.get(0).getTeamId());
}
}*/ prevProcessEnd = personResource.getEndTime();
PersonResourceEntity personResource = personResourceList.get(0); }
personResource.setIsUsed("1"); }finally {
personResourceService.updateById(personResource); craftLock.unlock(); // 释放本地锁
workPlan.setPersonResourceIds(personResource.getId().toString()); }*/
workPlan.setStartTime(personResource.getStartTime());
workPlan.setEndTime(personResource.getEndTime());
workPlan.setMakeTeam(personResourceList.get(0).getTeamId());
prevProcessEnd = personResource.getEndTime();
}
}finally {
craftLock.unlock(); // 释放本地锁
} }
}
workPlan.setWoId(order.getId()); workPlan.setWoId(order.getId());
workPlan.setCaId(craft.getCaId()); workPlan.setCaId(craft.getCaId());
workPlan.setPpsId(craft.getPpsId()); workPlan.setPpsId(craft.getPpsId());
workPlan.setWorkQty(order.getYpQty()); workPlan.setWorkQty(order.getYpQty());
workPlan.setHourQuota(totalTime); workPlan.setHourQuota(totalTime);
workPlan.setWorkCenterId(craft.getWorkCenterId()); workPlan.setWorkCenterId(craft.getWorkCenterId());
workPlan.setOrders(craft.getProcessNo()); workPlan.setOrders(craft.getProcessNo());
workPlan.setOem("0"); workPlan.setOem("0");
workPlan.setTestQty(0); workPlan.setTestQty(0);
workPlan.setQualifiedQty(0); workPlan.setQualifiedQty(0);
workPlan.setUnqualifiedQty(0); workPlan.setUnqualifiedQty(0);
workPlan.setScrapQty(0); workPlan.setScrapQty(0);
workPlanList.add(workPlan); workPlanList.add(workPlan);
}else{ }else{
//未匹配到设备和人力资源,将工序状态改为6,标识为未排产 //未匹配到设备和人力资源,将工序状态改为6,标识为未排产
craft.setStatus(6); craft.setStatus(6);
yieldOrderCraftService.updateById(craft); yieldOrderCraftService.updateById(craft);
}
if(!isSchecuding){
break;
}
} }
if(!isSchecuding){ if(!isSchecuding){
break; continue;
} }
}
if(!isSchecuding){
continue;
}
if (CollectionUtils.isNotEmpty(workPlanList)) { if (CollectionUtils.isNotEmpty(workPlanList)) {
//为人员工序赋值开始结束时间 //为人员工序赋值开始结束时间
WorkPlanTimeCalculator(workPlanList); WorkPlanTimeCalculator(workPlanList);
//新增车间订单和车间计划 //新增车间订单和车间计划
WorkOrderEntity workOrder = new WorkOrderEntity(); WorkOrderEntity workOrder = new WorkOrderEntity();
workOrder.setWoCode(this.nextCode(order.getYpCode())); workOrder.setWoCode(this.nextCode(order.getYpCode()));
workOrder.setCardNo(order.getCardNo()); workOrder.setCardNo(order.getCardNo());
workOrder.setBatchNo(order.getBatchNo()); workOrder.setBatchNo(order.getBatchNo());
workOrder.setYoId(order.getId()); workOrder.setYoId(order.getId());
workOrder.setMakeQty(order.getYpQty()); workOrder.setMakeQty(order.getYpQty());
workOrder.setPlanStartDate(workPlanList.get(0).getStartTime() == null ? null :workPlanList.get(0).getStartTime().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.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.setInventoryQty(0);
workOrder.setRunStatus(2); workOrder.setRunStatus(2);
workOrder.setPickingStatus(0); workOrder.setPickingStatus(0);
workOrder.setOem("0"); workOrder.setOem("0");
workOrder.setPriority(order.getPriorityAps()); workOrder.setPriority(order.getPriorityAps());
workOrder.setApprovalStatus(1); workOrder.setApprovalStatus(1);
workOrder.setScrapQty(0); workOrder.setScrapQty(0);
workOrder.setOemOut("0"); workOrder.setOemOut("0");
workOrder.setOemType(-1); workOrder.setOemType(-1);
workOrder.setPrintFlag("0"); workOrder.setPrintFlag("0");
workOrder.setPushFlag("0"); workOrder.setPushFlag("0");
workOrder.setQuotaExceptional("0"); workOrder.setQuotaExceptional("0");
workOrder.setReInStore("0"); workOrder.setReInStore("0");
workOrder.setPartCode(order.getPartCode()); workOrder.setPartCode(order.getPartCode());
this.save(workOrder); this.save(workOrder);
workPlanList.forEach(workPlanEntity -> { workPlanList.forEach(workPlanEntity -> {
workPlanEntity.setWoId(workOrder.getId()); workPlanEntity.setWoId(workOrder.getId());
workPlanService.save(workPlanEntity); workPlanService.save(workPlanEntity);
}); });
workOrder.setWpId(workPlanList.get(0).getId()); workOrder.setWpId(workPlanList.get(0).getId());
this.updateById(workOrder); this.updateById(workOrder);
//更新订单状态为已排产 //更新订单状态为已排产
order.setStatus(4); order.setStatus(4);
order.setErrorInfo(null); order.setErrorInfo(null);
yieldOrderService.updateById(order); yieldOrderService.updateById(order);
workOrderList.add(workOrder); workOrderList.add(workOrder);
}
} catch (Exception e) {
log.error("报错订单是:"+order.getId()+",报错信息是:"+e.getMessage());
throw new RuntimeException(e);
} }
} }
@ -976,7 +994,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
} }
//还原人力资源 //还原人力资源
if(workPlan.getPersonResourceIds() != null){ /*if(workPlan.getPersonResourceIds() != null){
List<PersonResourceEntity> personResourceList = personResourceService.list(Wrappers.<PersonResourceEntity>lambdaQuery().in(BaseEntity::getId,workPlan.getPersonResourceIds().split(","))); List<PersonResourceEntity> personResourceList = personResourceService.list(Wrappers.<PersonResourceEntity>lambdaQuery().in(BaseEntity::getId,workPlan.getPersonResourceIds().split(",")));
if(CollectionUtils.isNotEmpty(personResourceList)){ if(CollectionUtils.isNotEmpty(personResourceList)){
personResourceList.forEach(item ->{ personResourceList.forEach(item ->{
@ -984,7 +1002,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
personResourceService.updateById(item); personResourceService.updateById(item);
}); });
} }
} }*/
workPlanService.deleteLogic(Arrays.asList(workPlan.getId())); workPlanService.deleteLogic(Arrays.asList(workPlan.getId()));
} }
@ -1074,6 +1092,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
List<WorkPlanEntity> workPlanList = new ArrayList<>(); List<WorkPlanEntity> workPlanList = new ArrayList<>();
//获取相关工序 //获取相关工序
YieldOrderCraftEntity craft = yieldOrderCraftService.getOne(Wrappers.<YieldOrderCraftEntity>lambdaQuery().eq(YieldOrderCraftEntity::getYoId,order.getId()).eq(YieldOrderCraftEntity::getCaId,equipAbility.getCraftId())); 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())); BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(100)).multiply(BigDecimal.valueOf(order.getYpQty()));
//计算需要占用几个时间段 //计算需要占用几个时间段

Loading…
Cancel
Save