|
@@ -18,6 +18,7 @@ import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ProductionScheduleServiceImpl implements ProductionScheduleService {
|
|
@@ -54,7 +55,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
|
|
|
// optaplanner 求解器运行
|
|
|
ApsSolution solvedBalance = solver.solve(apsSolution);
|
|
|
System.out.println("*****************************");
|
|
|
- System.out.println(solvedBalance);
|
|
|
+// System.out.println(solvedBalance);
|
|
|
SolutionManager<ApsSolution, HardSoftScore> scoreManager = SolutionManager.create(solverFactory);
|
|
|
System.out.println(scoreManager.explain(solvedBalance));
|
|
|
System.out.println("*****************************");
|
|
@@ -74,7 +75,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
|
|
|
* @param productionScheduleVo
|
|
|
* @return
|
|
|
*/
|
|
|
- private static ApsSolution getPreApsSolution(ProductionScheduleVo productionScheduleVo){
|
|
|
+ private ApsSolution getPreApsSolution(ProductionScheduleVo productionScheduleVo){
|
|
|
ApsSolution unsolvedCloudBalance = new ApsSolution();
|
|
|
// 排程全局配置
|
|
|
ApsOverallConfig apsOverallConfig = new ApsOverallConfig();
|
|
@@ -89,7 +90,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
|
|
|
// 根据前道、后道工序ID,转换为前道、后道工序对象
|
|
|
Map<String,ProductionProcesses> idMaps = new HashMap<>();
|
|
|
for (ProductionProcesses process : productionScheduleVo.getProcesses()) {
|
|
|
- idMaps.put(process.getId(),process);
|
|
|
+ idMaps.put(String.join(",",process.getBsProcessesId()),process);
|
|
|
}
|
|
|
for (ProductionProcesses process : productionScheduleVo.getProcesses()) {
|
|
|
// 全局配置设置
|
|
@@ -98,7 +99,12 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
|
|
|
if(process.getPreviousProcessesIds() != null && process.getPreviousProcessesIds().size()>0){
|
|
|
List<ProductionProcesses> pres = new ArrayList<>();
|
|
|
for (String previousProcessesId : process.getPreviousProcessesIds()) {
|
|
|
- pres.add(idMaps.get(previousProcessesId));
|
|
|
+ for (ProductionProcesses productionScheduleVoProcess : productionScheduleVo.getProcesses()) {
|
|
|
+ if(productionScheduleVoProcess.getBsProcessesId().contains(previousProcessesId)){
|
|
|
+ pres.add(productionScheduleVoProcess);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
if(pres != null && pres.size()>0){
|
|
|
process.setPreviousProcesses(pres);
|
|
@@ -125,8 +131,77 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
|
|
|
}
|
|
|
// 设备列表初始化
|
|
|
unsolvedCloudBalance.setEquipmentList(productionScheduleVo.getEquipmentList());
|
|
|
+
|
|
|
+ List<ProductionProcesses> productionProcesses = sortProcess(productionScheduleVo.getProcesses());
|
|
|
// 工序任务初始化
|
|
|
- unsolvedCloudBalance.setProcessesList(productionScheduleVo.getProcesses());
|
|
|
+ unsolvedCloudBalance.setProcessesList(productionProcesses);
|
|
|
return unsolvedCloudBalance;
|
|
|
}
|
|
|
+
|
|
|
+ private List<ProductionProcesses> sortProcess(List<ProductionProcesses> sources){
|
|
|
+ // 排序后的列表
|
|
|
+ List<ProductionProcesses> processes = new ArrayList<>();
|
|
|
+ // 任务的排序
|
|
|
+ List<ProductionProcesses> processesSort = sources;
|
|
|
+ // 已排序的数据
|
|
|
+// List<String> bsIds = new ArrayList<>();
|
|
|
+ // 最开始任务
|
|
|
+ List<ProductionProcesses> roots = new ArrayList<>();
|
|
|
+ for (ProductionProcesses productionProcesses : processesSort) {
|
|
|
+ if(productionProcesses.getPreviousProcesses() == null || productionProcesses.getPreviousProcesses().size() == 0){
|
|
|
+ roots.add(productionProcesses);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (ProductionProcesses root : roots) {
|
|
|
+ List<Integer> repeatPro = new ArrayList<>();
|
|
|
+ Map<Integer,Integer> repeatProMap = new HashMap<>();
|
|
|
+ List<ProductionProcesses> subprocesses = new ArrayList<>();
|
|
|
+ subprocesses.add(root);
|
|
|
+// bsIds.add(root.getBsProcessesId());
|
|
|
+ getNextProcess(root,subprocesses,repeatPro,processes,repeatProMap);
|
|
|
+
|
|
|
+ if(repeatPro != null && repeatPro.size()>0){
|
|
|
+ Collections.sort(repeatPro);
|
|
|
+ int a = 0;
|
|
|
+ for (Integer integer : repeatPro) {
|
|
|
+ for(int i=integer-1;i>=a;i--){
|
|
|
+ int finalI = i;
|
|
|
+ List<ProductionProcesses> ps = processes.stream().filter(v -> v.getId().equals(subprocesses.get(finalI).getId())).collect(Collectors.toList());
|
|
|
+ if(ps == null || ps .size() == 0){
|
|
|
+ processes.add(repeatProMap.get(integer),subprocesses.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 最后一个把所有后面的工序插入到总工序列表后面
|
|
|
+ /*if(integer.equals(repeatPro.get(repeatPro.size() - 1))){
|
|
|
+ for(int i=integer+1;i<subprocesses.size();i++){
|
|
|
+ processes.add(subprocesses.get(i));
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ processes.addAll(subprocesses);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return processes;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getNextProcess(ProductionProcesses proces,List<ProductionProcesses> subprocesses,
|
|
|
+ List<Integer> repeatPro,List<ProductionProcesses> processes,Map<Integer,Integer> repeatProMap){
|
|
|
+ if(proces.getNextProcesses() != null && proces.getNextProcesses().size()>0){
|
|
|
+ for (ProductionProcesses nextProcess : proces.getNextProcesses()) {
|
|
|
+ subprocesses.add(nextProcess);
|
|
|
+ // 重复的工序
|
|
|
+ if(processes != null && processes.size()>0){
|
|
|
+ for (int i=0;i<processes.size();i++) {
|
|
|
+ ProductionProcesses process = processes.get(i);
|
|
|
+ if(nextProcess.getId().equals(process.getId())){
|
|
|
+ repeatPro.add(subprocesses.size()-1);
|
|
|
+ repeatProMap.put(subprocesses.size()-1,i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getNextProcess(nextProcess,subprocesses,repeatPro,processes,repeatProMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|