排产开发-sjx

liweidong
sunjianxi 1 week ago
parent d108bf3a5d
commit bfb09d89b8
  1. 5
      blade-service/blade-scheduling/src/main/java/org/springblade/scheduling/scheduling/service/impl/EquipResourceServiceImpl.java
  2. 7
      blade-service/blade-scheduling/src/main/java/org/springblade/scheduling/scheduling/service/impl/PersonResourceServiceImpl.java
  3. 153
      blade-service/blade-scheduling/src/main/java/org/springblade/scheduling/scheduling/service/impl/WorkOrderServiceImpl.java

@ -36,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.jackson.JsonUtil; import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.scheduling.pojo.entity.EquipAbilityEntity; import org.springblade.scheduling.pojo.entity.EquipAbilityEntity;
@ -57,6 +58,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 工艺能力表 服务实现类 * 工艺能力表 服务实现类
@ -107,7 +109,8 @@ public class EquipResourceServiceImpl extends BaseServiceImpl<EquipResourceMappe
} }
//删除3天之前的数据 //删除3天之前的数据
List<EquipResourceEntity> deleteList = this.list(Wrappers.<EquipResourceEntity>lambdaQuery().le(EquipResourceEntity::getDateTime,DateFormatUtils.format(DateUtils.addDays(date,-3),"yyyy-MM-dd"))); List<EquipResourceEntity> deleteList = this.list(Wrappers.<EquipResourceEntity>lambdaQuery().le(EquipResourceEntity::getDateTime,DateFormatUtils.format(DateUtils.addDays(date,-3),"yyyy-MM-dd")));
deleteList.forEach(item -> baseMapper.deleteById(item.getId())); List<Long> idList = deleteList.stream().map(BaseEntity::getId).collect(Collectors.toList());
baseMapper.deleteByIds(idList);
log.info("初始化设备资源结束:"+ DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss")); log.info("初始化设备资源结束:"+ DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
} }

@ -33,6 +33,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.scheduling.pojo.entity.PersonAbilityEntity; import org.springblade.scheduling.pojo.entity.PersonAbilityEntity;
import org.springblade.scheduling.pojo.entity.PersonResourceEntity; import org.springblade.scheduling.pojo.entity.PersonResourceEntity;
@ -45,12 +46,12 @@ import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 工艺能力表 服务实现类 * 工艺能力表 服务实现类
@ -87,6 +88,10 @@ public class PersonResourceServiceImpl extends BaseServiceImpl<PersonResourceMap
generateData(today); generateData(today);
} }
} }
//删除3天之前的数据
List<PersonResourceEntity> deleteList = this.list(Wrappers.<PersonResourceEntity>lambdaQuery().le(PersonResourceEntity::getDateTime,DateFormatUtils.format(DateUtils.addDays(date,-3),"yyyy-MM-dd")));
List<Long> idList = deleteList.stream().map(BaseEntity::getId).collect(Collectors.toList());
baseMapper.deleteByIds(idList);
log.info("初始化人力资源结束:"+ DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss")); log.info("初始化人力资源结束:"+ DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
} }

@ -528,23 +528,25 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
} else { } else {
if ("设备".equals(mainProducerMap.get(craft.getPpsId()))) { if ("设备".equals(mainProducerMap.get(craft.getPpsId()))) {
String glassCodeStr = null; String glassCodeStr = null;
Map<String, Object> sameFurnaceMap = new HashMap<>(); Map<String, Object> sameMap = new HashMap<>();
//同炉同槽 //同炉同槽
if(order.getYieldType() == YieldOrderEnum.YIELD_TYPE_1.getCode()){ if(order.getYieldType() == YieldOrderEnum.YIELD_TYPE_1.getCode()){
//热表同槽 //热表同槽
Boolean isSameTrough = sameTrough(order, craft, localDateTime, workPlanList); sameMap = sameTrough(order, craft, localDateTime, workPlanList, prevProcessEnd);
//同槽就不需要继续匹配了 //同槽就不需要继续匹配了
if (isSameTrough) { if (sameMap.get("isSameTrough").toString() == "true") {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
prevProcessEnd = LocalDateTime.parse(sameMap.get("prevProcessEnd").toString(), formatter);
continue; continue;
} }
}else{ }else{
//烧结同炉 //烧结同炉
if (sintMap.containsKey(craft.getPpsId())) { if (sintMap.containsKey(craft.getPpsId())) {
sameFurnaceMap = sameFurnace(order, craft, workPlanList, localDateTime, glassCodeStr, sintMap, part, processMap, prevProcessEnd); sameMap = sameFurnace(order, craft, workPlanList, localDateTime, glassCodeStr, sintMap, part, processMap, prevProcessEnd);
//同炉的话就不用走下面的匹配了,直接下一工序 //同炉的话就不用走下面的匹配了,直接下一工序
if (sameFurnaceMap.get("isSameFurnace").toString() == "true") { if (sameMap.get("isSameFurnace").toString() == "true") {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
prevProcessEnd = LocalDateTime.parse(sameFurnaceMap.get("prevProcessEnd").toString(), formatter); prevProcessEnd = LocalDateTime.parse(sameMap.get("prevProcessEnd").toString(), formatter);
continue; continue;
} }
} }
@ -688,8 +690,8 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
//更新剩余产能 //更新剩余产能
equipResource.setRestCapacity(equipResource.getRestCapacity().subtract(capacity)); equipResource.setRestCapacity(equipResource.getRestCapacity().subtract(capacity));
equipResource.setIsUsed("1"); equipResource.setIsUsed("1");
if (order.getYieldType() != YieldOrderEnum.YIELD_TYPE_1.getCode() && sameFurnaceMap.get("glassCode") != null) { if (order.getYieldType() != YieldOrderEnum.YIELD_TYPE_1.getCode() && sameMap.get("glassCode") != null) {
equipResource.setGlassCode(sameFurnaceMap.get("glassCode").toString()); equipResource.setGlassCode(sameMap.get("glassCode").toString());
} }
equipResourceService.updateById(equipResource); equipResourceService.updateById(equipResource);
//同一个设备可能有多个工艺能力,同一时间只能做一个工艺能力的零件,所以需要把当前设备所有工艺能力的剩余产能都更新调 //同一个设备可能有多个工艺能力,同一时间只能做一个工艺能力的零件,所以需要把当前设备所有工艺能力的剩余产能都更新调
@ -703,8 +705,8 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
for(EquipResourceEntity otherResource : otherResourceList){ for(EquipResourceEntity otherResource : otherResourceList){
otherResource.setRestCapacity(otherResource.getTotalCapacity().multiply(rate).setScale(0, RoundingMode.FLOOR)); otherResource.setRestCapacity(otherResource.getTotalCapacity().multiply(rate).setScale(0, RoundingMode.FLOOR));
otherResource.setIsUsed("1"); otherResource.setIsUsed("1");
if (order.getYieldType() != YieldOrderEnum.YIELD_TYPE_1.getCode() && sameFurnaceMap.get("glassCode") != null) { if (order.getYieldType() != YieldOrderEnum.YIELD_TYPE_1.getCode() && sameMap.get("glassCode") != null) {
otherResource.setGlassCode(sameFurnaceMap.get("glassCode").toString()); otherResource.setGlassCode(sameMap.get("glassCode").toString());
} }
equipResourceService.updateById(otherResource); equipResourceService.updateById(otherResource);
} }
@ -809,13 +811,7 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
wrapper.eq(PersonResourceEntity::getTeamId,craft.getMakeTeam()); wrapper.eq(PersonResourceEntity::getTeamId,craft.getMakeTeam());
} }
wrapper.orderByAsc(PersonResourceEntity::getDateTime,PersonResourceEntity::getStartTime); wrapper.orderByAsc(PersonResourceEntity::getDateTime,PersonResourceEntity::getStartTime);
List<PersonResourceEntity> personResourceList = personResourceService.list(Wrappers.<PersonResourceEntity>lambdaQuery() List<PersonResourceEntity> personResourceList = personResourceService.list(wrapper);
.eq(PersonResourceEntity::getWorkCenterId, craft.getWorkCenterId())
.eq(PersonResourceEntity::getProcessId, craft.getPpsId())
.eq(PersonResourceEntity::getCraftId, craft.getCaId())
.le(PersonResourceEntity::getStartTime, prevProcessEnd)
.orderByAsc(PersonResourceEntity::getDateTime,PersonResourceEntity::getStartTime)
.eq(PersonResourceEntity::getTeamId,craft.getMakeTeam()));
if (CollectionUtils.isNotEmpty(personResourceList)) { if (CollectionUtils.isNotEmpty(personResourceList)) {
workPlan.setMakeTeam(personResourceList.get(0).getTeamId()); workPlan.setMakeTeam(personResourceList.get(0).getTeamId());
} }
@ -1417,29 +1413,110 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
} }
} }
public Boolean sameTrough(YieldOrderEntity order, YieldOrderCraftEntity craft, LocalDateTime dateTime, List<WorkPlanEntity> workPlanList) { public Map<String, Object> sameTrough(YieldOrderEntity order,
YieldOrderCraftEntity craft,
LocalDateTime dateTime,
List<WorkPlanEntity> workPlanList,
LocalDateTime prevProcessEnd) {
Map<String, Object> map = new HashMap<>();
Boolean isSameTrough = false; Boolean isSameTrough = false;
SameTroughEntity sameTrough = sameTroughService.getOne(Wrappers.<SameTroughEntity>lambdaQuery() SameTroughEntity sameTrough = sameTroughService.getOne(Wrappers.<SameTroughEntity>lambdaQuery()
.eq(SameTroughEntity::getWorkCenterId, craft.getWorkCenterId()) .eq(SameTroughEntity::getWorkCenterId, craft.getWorkCenterId())
.eq(SameTroughEntity::getCraftId, craft.getCaId()) .eq(SameTroughEntity::getCraftId, craft.getCaId())
.eq(SameTroughEntity::getProcessId, craft.getPpsId())); .eq(SameTroughEntity::getProcessId, craft.getPpsId()));
if (sameTrough != null) { LambdaQueryWrapper<WorkPlanEntity> wrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper<WorkPlanEntity> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(WorkPlanEntity::getWorkCenterId, craft.getWorkCenterId())
wrapper.eq(WorkPlanEntity::getWorkCenterId, craft.getWorkCenterId()) .eq(WorkPlanEntity::getCaId, craft.getCaId())
.eq(WorkPlanEntity::getCaId, craft.getCaId()) .eq(WorkPlanEntity::getPpsId, craft.getPpsId())
.eq(WorkPlanEntity::getPpsId, craft.getPpsId()) .ge(WorkPlanEntity::getPlanStartTime, dateTime);
.ge(WorkPlanEntity::getPlanStartTime, dateTime); //返工订单需要原班组加工
//返工订单需要原班组加工 if(StringUtils.isNotEmpty(order.getReworkCode())){
if(StringUtils.isNotEmpty(order.getReworkCode())){ wrapper.eq(WorkPlanEntity::getMakeTeam,craft.getMakeTeam());
wrapper.eq(WorkPlanEntity::getMakeTeam,craft.getMakeTeam()); }
wrapper.orderByAsc(WorkPlanEntity::getPlanStartTime);
//查询是否有已经排产的计划
List<WorkPlanEntity> workPlanOldList = workPlanService.list(wrapper);
//如果没有查询到非同槽条件,默认同槽
if(sameTrough == null){
if (CollectionUtils.isNotEmpty(workPlanOldList)) {
//总生产量
BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(order.getYpQty()));
for (WorkPlanEntity entry : workPlanOldList) {
List<Long> resourceList = new ArrayList<>();
if (StringUtils.isNotEmpty(entry.getEquipResourceId())) {
List<Long> resourceIdList = Arrays.stream(entry.getEquipResourceId().split(","))
.map(String::trim)
.map(Long::valueOf)
.collect(Collectors.toList());
for(Long resourceId : resourceIdList){
EquipResourceEntity equipResource = equipResourceService.getById(resourceId);
if(equipResource == null){
continue;
}
//判断剩余产能是否满足总产能
if (sumCapacity.compareTo(equipResource.getRestCapacity()) > 0) {
resourceList.clear();
break;
} else {
resourceList.add(resourceId);
}
}
}
List<WorkPlanEntity> processPlanList = new ArrayList<>();
for(Long resourceId : resourceList){
EquipResourceEntity equipResource = equipResourceService.getById(resourceId);
//生成车间订单
WorkPlanEntity workPlan = new WorkPlanEntity();
workPlan.setPlanStartTime(equipResource.getStartTime());
if ("0".equals(equipResource.getEquipType())) {
workPlan.setPlanEndTime(equipResource.getStartTime().plusMinutes(equipResource.getStandardTime().setScale(0, RoundingMode.CEILING).longValue()));
} else {
workPlan.setPlanEndTime(equipResource.getEndTime());
}
workPlan.setWorkQty(0);
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((double)ChronoUnit.MINUTES.between(workPlan.getPlanStartTime(), workPlan.getPlanEndTime()));
workPlan.setEquipCode(equipResource.getEquipCode());
workPlan.setEquipName(equipResource.getEquipName());
workPlan.setEquipResourceId(equipResource.getId().toString());
processPlanList.add(workPlan);
equipResource.setRestCapacity(equipResource.getRestCapacity().subtract(sumCapacity));
equipResourceService.updateById(equipResource);
isSameTrough = true;
}
if(CollectionUtils.isNotEmpty(processPlanList)){
WorkPlanEntity workPlan = new WorkPlanEntity();
BeanUtils.copyProperties(processPlanList.get(0),workPlan);
workPlan.setPlanStartTime(processPlanList.get(0).getPlanStartTime());
workPlan.setPlanEndTime(processPlanList.get(processPlanList.size()-1).getPlanEndTime());
String equipCode = processPlanList.stream().map(WorkPlanEntity::getEquipCode).collect(Collectors.joining(","));
String equipName = processPlanList.stream().map(WorkPlanEntity::getEquipName).collect(Collectors.joining(","));
String equipResourceId = processPlanList.stream().map(WorkPlanEntity::getEquipResourceId).map(String::valueOf).collect(Collectors.joining(","));
Double hourQuota = processPlanList.stream().mapToDouble(WorkPlanEntity::getHourQuota).sum();
workPlan.setEquipCode(equipCode);
workPlan.setEquipName(equipName);
workPlan.setEquipResourceId(equipResourceId);
workPlan.setHourQuota(hourQuota);
workPlanList.add(workPlan);
prevProcessEnd = workPlan.getPlanEndTime();
//排完了跳出循环
break;
}
}
} }
wrapper.orderByAsc(WorkPlanEntity::getPlanStartTime); }else if(sameTrough != null) {
//查询是否有已经排产的计划
List<WorkPlanEntity> workPlanOldList = workPlanService.list(Wrappers.<WorkPlanEntity>lambdaQuery()
.eq(WorkPlanEntity::getWorkCenterId, craft.getWorkCenterId())
.eq(WorkPlanEntity::getCaId, craft.getCaId())
.eq(WorkPlanEntity::getPpsId, craft.getPpsId())
.ge(WorkPlanEntity::getPlanStartTime, dateTime).orderByAsc(WorkPlanEntity::getPlanStartTime));
if (CollectionUtils.isNotEmpty(workPlanOldList)) { if (CollectionUtils.isNotEmpty(workPlanOldList)) {
//总生产量 //总生产量
BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(order.getYpQty())); BigDecimal sumCapacity = order.getYpArea().multiply(BigDecimal.valueOf(order.getYpQty()));
@ -1466,7 +1543,6 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
resourceList.add(resourceId); resourceList.add(resourceId);
} }
} }
} }
//如果产能满足,再判断是否满足同槽条件 //如果产能满足,再判断是否满足同槽条件
if (isEnough) { if (isEnough) {
@ -1579,6 +1655,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
workPlan.setEquipResourceId(equipResourceId); workPlan.setEquipResourceId(equipResourceId);
workPlan.setHourQuota(hourQuota); workPlan.setHourQuota(hourQuota);
workPlanList.add(workPlan); workPlanList.add(workPlan);
prevProcessEnd = workPlan.getPlanEndTime();
//排完了跳出循环
break;
} }
} }
} }
@ -1588,7 +1667,9 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
} }
} }
} }
return isSameTrough; map.put("isSameTrough", isSameTrough);
map.put("prevProcessEnd" , prevProcessEnd);
return map;
} }
public Map<String, Object> sameFurnace(YieldOrderEntity order, public Map<String, Object> sameFurnace(YieldOrderEntity order,

Loading…
Cancel
Save