排产相关-sjx

master
sunjianxi 3 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
public void scheduling() {
//查询待排产订单,状态是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());
if (CollectionUtils.isNotEmpty(list)) {
//校验已排产订单
@ -144,7 +144,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
list1 -> {
// 排序逻辑:优先级升序 → CR值降序 → 数量降序 → 时间升序
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()
.thenComparing(YieldOrderEntity::getReleaseDate));
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) {
List<WorkOrderEntity> workOrderList = new ArrayList<>();
for (YieldOrderEntity order : list) {
//是否可以排产
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());
if(workCenterList.size() != craftList.size()){
order.setErrorInfo("工序信息不完整,含有未匹配作业中心的工序");
order.setStatus(6);
yieldOrderService.updateById(order);
continue;
}
try {
//是否可以排产
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());
if(workCenterList.size() != craftList.size()){
order.setErrorInfo("工序信息不完整,含有未匹配作业中心的工序");
order.setStatus(6);
yieldOrderService.updateById(order);
continue;
}
//上一道工序结束时间
LocalDateTime prevProcessEnd = LocalDateTime.now();
//判断是否有公共工序已经处理了,如果有则重新定义workPlanList,获取公共工序的最后结束时间和当前时间做比较,取大的作为上一道工序结束时间
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();
}
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()));
if(CollectionUtils.isEmpty(equipAbilityList)){
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)){
//上一道工序结束时间
LocalDateTime prevProcessEnd = LocalDateTime.now();
//判断是否有公共工序已经处理了,如果有则重新定义workPlanList,获取公共工序的最后结束时间和当前时间做比较,取大的作为上一道工序结束时间
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();
}
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()));
if(CollectionUtils.isEmpty(equipAbilityList)){
order.setErrorInfo("设备未匹配到对应的设备能力");
order.setStatus(6);
order.setErrorInfo("工序:"+craft.getPpsId()+"未匹配到对应的设备资源");
yieldOrderService.updateById(order);
isSchecuding = false;
break;
}
//设备资源按照时间段分组并按时间排序,然后再每个组内按照剩余产能倒序排序
Map<LocalDateTime, List<EquipResourceEntity>> equipResourceMap = equipResourceList.stream()
.collect(Collectors.groupingBy(
EquipResourceEntity::getStartTime, // 分组字段:startTime
// 用TreeMap接收,指定startTime降序(分组的排序)
TreeMap::new,
// 组内收集器:按restCapacity降序排序
Collectors.collectingAndThen(
Collectors.toList(),
list1 -> list1.stream()
.sorted(Comparator.comparing(
EquipResourceEntity::getRestCapacity,
// restCapacity 降序比较器(BigDecimal专用)
Comparator.reverseOrder()
))
.collect(Collectors.toList())
)
));
//计算生产所需产能,需将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()){
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());
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.setErrorInfo("工序:"+craft.getPpsId()+"未匹配到对应的设备资源");
yieldOrderService.updateById(order);
isSchecuding = false;
break;
}
//设备资源按照时间段分组并按时间排序,然后再每个组内按照剩余产能倒序排序
Map<LocalDateTime, List<EquipResourceEntity>> equipResourceMap = equipResourceList.stream()
.collect(Collectors.groupingBy(
EquipResourceEntity::getStartTime, // 分组字段:startTime
// 用TreeMap接收,指定startTime降序(分组的排序)
TreeMap::new,
// 组内收集器:按restCapacity降序排序
Collectors.collectingAndThen(
Collectors.toList(),
list1 -> list1.stream()
.sorted(Comparator.comparing(
EquipResourceEntity::getRestCapacity,
// restCapacity 降序比较器(BigDecimal专用)
Comparator.reverseOrder()
))
.collect(Collectors.toList())
)
));
//计算生产所需产能,需将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()){
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());
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;
}
if (isOccupied) {
break;
}
}
if (isOccupied) {
break;
}
}
}
}
if(!isSchecuding){
break;
}
if(!isSchecuding){
break;
}
} else if ("人".equals(mainProducerMap.get(craft.getPpsId()))) {
//匹配人资源
/* String personAbility = craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId();
if (personAbilityMap.containsKey(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId())) {
} else if ("人".equals(mainProducerMap.get(craft.getPpsId()))) {
//匹配人资源
/* String personAbility = craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId();
if (personAbilityMap.containsKey(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId())) {
} else {
order.setStatus(6);
order.setErrorInfo("工序:"+personAbility+"未匹配到对应的人员能力");
yieldOrderService.updateById(order);
isSchecuding = false;
break;
}*/
WorkPlanEntity workPlan = new WorkPlanEntity();
BigDecimal totalTime = new BigDecimal(0);
PersonAbilityEntity ability = personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId());
//由于客户提供的数据不全,先判断有没有对应的能力,如果没有先不计算时间
/* if(ability != null){
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){
//通过加锁的方式保证每次查询到的人力资源都是最新的
Long craftId = craft.getCaId();
Lock craftLock = getCraftLock(craftId);
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;
}
} else {
order.setStatus(6);
order.setErrorInfo("工序:"+personAbility+"未匹配到对应的人员能力");
yieldOrderService.updateById(order);
isSchecuding = false;
break;
}*/
WorkPlanEntity workPlan = new WorkPlanEntity();
BigDecimal totalTime = new BigDecimal(0);
PersonAbilityEntity ability = personAbilityMap.get(craft.getWorkCenterId() + "-" + craft.getPpsId() + "-" + craft.getCaId());
//由于客户提供的数据不全,先判断有没有对应的能力,如果没有先不计算时间
List<Integer> caIds = Arrays.asList(10,21);
//镀后检验和镀后接收先按半小时计算
if(ability != null){
if(caIds.contains(craft.getCaId())){
totalTime = BigDecimal.valueOf(30);
workPlan.setStartTime(prevProcessEnd);
workPlan.setEndTime(prevProcessEnd.plusMinutes(30));
if(craft.getCaId() == 10){
workPlan.setMakeTeam(Long.valueOf(64));
}
if(isUsedIndex != -1){
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;
if(craft.getCaId() == 21){
workPlan.setMakeTeam(Long.valueOf(65));
}
//占用时间段
/*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();
}else{
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()));
}
//通过加锁的方式保证每次查询到的人力资源都是最新的
/*Long craftId = craft.getCaId();
Lock craftLock = getCraftLock(craftId);
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){
endTime = personResource.getEndTime();
if(isUsedIndex != -1){
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");
personResourceService.updateById(personResource);
if(j!=period-1){
personResourceIds.append(personResource.getId()).append(",");
}else{
personResourceIds.append(personResource.getId());
}
workPlan.setPersonResourceIds(personResource.getId().toString());
workPlan.setStartTime(personResource.getStartTime());
workPlan.setEndTime(personResource.getEndTime());
workPlan.setMakeTeam(personResourceList.get(0).getTeamId());
}*/
PersonResourceEntity personResource = personResourceList.get(0);
personResource.setIsUsed("1");
personResourceService.updateById(personResource);
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(); // 释放本地锁
prevProcessEnd = personResource.getEndTime();
}
}finally {
craftLock.unlock(); // 释放本地锁
}*/
}
}
workPlan.setWoId(order.getId());
workPlan.setCaId(craft.getCaId());
workPlan.setPpsId(craft.getPpsId());
workPlan.setWorkQty(order.getYpQty());
workPlan.setHourQuota(totalTime);
workPlan.setWorkCenterId(craft.getWorkCenterId());
workPlan.setOrders(craft.getProcessNo());
workPlan.setOem("0");
workPlan.setTestQty(0);
workPlan.setQualifiedQty(0);
workPlan.setUnqualifiedQty(0);
workPlan.setScrapQty(0);
workPlanList.add(workPlan);
}else{
//未匹配到设备和人力资源,将工序状态改为6,标识为未排产
craft.setStatus(6);
yieldOrderCraftService.updateById(craft);
workPlan.setWoId(order.getId());
workPlan.setCaId(craft.getCaId());
workPlan.setPpsId(craft.getPpsId());
workPlan.setWorkQty(order.getYpQty());
workPlan.setHourQuota(totalTime);
workPlan.setWorkCenterId(craft.getWorkCenterId());
workPlan.setOrders(craft.getProcessNo());
workPlan.setOem("0");
workPlan.setTestQty(0);
workPlan.setQualifiedQty(0);
workPlan.setUnqualifiedQty(0);
workPlan.setScrapQty(0);
workPlanList.add(workPlan);
}else{
//未匹配到设备和人力资源,将工序状态改为6,标识为未排产
craft.setStatus(6);
yieldOrderCraftService.updateById(craft);
}
if(!isSchecuding){
break;
}
}
if(!isSchecuding){
break;
continue;
}
}
if(!isSchecuding){
continue;
}
if (CollectionUtils.isNotEmpty(workPlanList)) {
//为人员工序赋值开始结束时间
WorkPlanTimeCalculator(workPlanList);
//新增车间订单和车间计划
WorkOrderEntity workOrder = new WorkOrderEntity();
workOrder.setWoCode(this.nextCode(order.getYpCode()));
workOrder.setCardNo(order.getCardNo());
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.setInventoryQty(0);
workOrder.setRunStatus(2);
workOrder.setPickingStatus(0);
workOrder.setOem("0");
workOrder.setPriority(order.getPriorityAps());
workOrder.setApprovalStatus(1);
workOrder.setScrapQty(0);
workOrder.setOemOut("0");
workOrder.setOemType(-1);
workOrder.setPrintFlag("0");
workOrder.setPushFlag("0");
workOrder.setQuotaExceptional("0");
workOrder.setReInStore("0");
workOrder.setPartCode(order.getPartCode());
this.save(workOrder);
workPlanList.forEach(workPlanEntity -> {
workPlanEntity.setWoId(workOrder.getId());
workPlanService.save(workPlanEntity);
});
workOrder.setWpId(workPlanList.get(0).getId());
this.updateById(workOrder);
//更新订单状态为已排产
order.setStatus(4);
order.setErrorInfo(null);
yieldOrderService.updateById(order);
workOrderList.add(workOrder);
if (CollectionUtils.isNotEmpty(workPlanList)) {
//为人员工序赋值开始结束时间
WorkPlanTimeCalculator(workPlanList);
//新增车间订单和车间计划
WorkOrderEntity workOrder = new WorkOrderEntity();
workOrder.setWoCode(this.nextCode(order.getYpCode()));
workOrder.setCardNo(order.getCardNo());
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.setInventoryQty(0);
workOrder.setRunStatus(2);
workOrder.setPickingStatus(0);
workOrder.setOem("0");
workOrder.setPriority(order.getPriorityAps());
workOrder.setApprovalStatus(1);
workOrder.setScrapQty(0);
workOrder.setOemOut("0");
workOrder.setOemType(-1);
workOrder.setPrintFlag("0");
workOrder.setPushFlag("0");
workOrder.setQuotaExceptional("0");
workOrder.setReInStore("0");
workOrder.setPartCode(order.getPartCode());
this.save(workOrder);
workPlanList.forEach(workPlanEntity -> {
workPlanEntity.setWoId(workOrder.getId());
workPlanService.save(workPlanEntity);
});
workOrder.setWpId(workPlanList.get(0).getId());
this.updateById(workOrder);
//更新订单状态为已排产
order.setStatus(4);
order.setErrorInfo(null);
yieldOrderService.updateById(order);
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(",")));
if(CollectionUtils.isNotEmpty(personResourceList)){
personResourceList.forEach(item ->{
@ -984,7 +1002,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
personResourceService.updateById(item);
});
}
}
}*/
workPlanService.deleteLogic(Arrays.asList(workPlan.getId()));
}
@ -1074,6 +1092,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
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){
continue;
}
//计算订单总产能
BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(100)).multiply(BigDecimal.valueOf(order.getYpQty()));
//计算需要占用几个时间段

Loading…
Cancel
Save