kpi计算

parent a3632e76
...@@ -19,7 +19,10 @@ public class GAScheduleResult { ...@@ -19,7 +19,10 @@ public class GAScheduleResult {
*/ */
public String ExecId ; public String ExecId ;
public String OrderId ; public String OrderId ;
public String OrderCode ;
private String productId; private String productId;
private String productName;
private String productCode;
private long MachineId; private long MachineId;
private int StartTime; // 相对开始时间(秒) private int StartTime; // 相对开始时间(秒)
private int EndTime; // 相对结束时间(秒) private int EndTime; // 相对结束时间(秒)
......
...@@ -23,6 +23,9 @@ public class TaskVO { ...@@ -23,6 +23,9 @@ public class TaskVO {
@Schema(description = "计划ID") @Schema(description = "计划ID")
private String planId; private String planId;
@Schema(description = "计划编号")
private String planCode;
@Schema(description = "产品类型") @Schema(description = "产品类型")
private Integer productType; private Integer productType;
...@@ -32,6 +35,9 @@ public class TaskVO { ...@@ -32,6 +35,9 @@ public class TaskVO {
@Schema(description = "产品ID") @Schema(description = "产品ID")
private String productId; private String productId;
@Schema(description = "产品编码")
private String productCode;
@Schema(description = "数量") @Schema(description = "数量")
private double quantity; private double quantity;
......
...@@ -19,6 +19,7 @@ public class ProdLaunchOrder { ...@@ -19,6 +19,7 @@ public class ProdLaunchOrder {
private String createUser; private String createUser;
private String productType; private String productType;
private String materialCode; private String materialCode;
private String materialName;
private String materialVer; private String materialVer;
private LocalDateTime startDate; private LocalDateTime startDate;
private LocalDateTime endDate; private LocalDateTime endDate;
......
...@@ -14,6 +14,7 @@ public class ProdProcessExec { ...@@ -14,6 +14,7 @@ public class ProdProcessExec {
private String execId; private String execId;
private String sceneId; private String sceneId;
private String orderId; private String orderId;
private String orderCode;
private Long routingDetailId; private Long routingDetailId;
private Long taskSeq; private Long taskSeq;
private String routingDetailName; private String routingDetailName;
......
...@@ -32,6 +32,8 @@ public class Entry { ...@@ -32,6 +32,8 @@ public class Entry {
public String OrderId ; public String OrderId ;
public String OrderCode ;
/** /**
* 原订单ID * 原订单ID
*/ */
...@@ -45,6 +47,8 @@ public class Entry { ...@@ -45,6 +47,8 @@ public class Entry {
private String productId; private String productId;
private String productCode;
private String productName;
/** /**
* 工单ID * 工单ID
*/ */
......
...@@ -17,6 +17,7 @@ public class Order { ...@@ -17,6 +17,7 @@ public class Order {
private int productId; private int productId;
private String materialId; private String materialId;
private String materialCode; private String materialCode;
private String materialName;
private String serie; private String serie;
private Integer routingId; private Integer routingId;
private String routingCode; private String routingCode;
......
...@@ -488,7 +488,10 @@ if(finishedOrder==null||finishedOrder.size()==0) ...@@ -488,7 +488,10 @@ if(finishedOrder==null||finishedOrder.size()==0)
result.setOperationId(operation.getId()); result.setOperationId(operation.getId());
result.setExecId(operation.getExecId()); result.setExecId(operation.getExecId());
result.setOrderId(operation.getOrderId()); result.setOrderId(operation.getOrderId());
result.setOrderCode(operation.getOrderCode());
result.setProductId(operation.getProductId()); result.setProductId(operation.getProductId());
result.setProductName(operation.getProductName());
result.setProductCode(operation.getProductCode());
result.setMachineId(machine.getId()); result.setMachineId(machine.getId());
......
...@@ -41,7 +41,7 @@ public class KpiCalculator { ...@@ -41,7 +41,7 @@ public class KpiCalculator {
.mapToDouble(Machine::getRate) .mapToDouble(Machine::getRate)
.min() .min()
.orElse(0); .orElse(0);
addKpi(kpiMetrics,"最小设备利用率", machineMinRate, "实际工作时间/计划工作时间 最小", 0, 1); addKpi(kpiMetrics,"最小设备利用率", Math.round(machineMinRate * 100.0) / 100.0, "实际工作时间/计划工作时间 最小", 0, 1);
double machineActualWorkTime = chromosome.getMachines().stream() double machineActualWorkTime = chromosome.getMachines().stream()
.mapToDouble(Machine::getActualWorkTime) .mapToDouble(Machine::getActualWorkTime)
...@@ -53,8 +53,8 @@ public class KpiCalculator { ...@@ -53,8 +53,8 @@ public class KpiCalculator {
double orderNoDelayCount = chromosome.getOrders().stream() double orderNoDelayCount = chromosome.getOrders().stream()
.filter(t -> t.getDelayHours() <= 0) .filter(t -> t.getDelayHours() <= 0)
.count(); .count();
//
double orderOnTime = Math.round(orderNoDelayCount / chromosome.getOrders().size() * 10000) / 10000 * 100; double orderOnTime = Math.round(orderNoDelayCount * 10000.0 / chromosome.getOrders().size()) / 100.0;
addKpi(kpiMetrics,"订单按时完成率", orderOnTime, "规定时间内交付的订单数量/所有订单数量", 0, 1); addKpi(kpiMetrics,"订单按时完成率", orderOnTime, "规定时间内交付的订单数量/所有订单数量", 0, 1);
//最大延迟 //最大延迟
double OrderMaxDelay = chromosome.getOrders().stream() double OrderMaxDelay = chromosome.getOrders().stream()
...@@ -73,7 +73,7 @@ public class KpiCalculator { ...@@ -73,7 +73,7 @@ public class KpiCalculator {
.mapToDouble(Order::getDelayHours) .mapToDouble(Order::getDelayHours)
.sum(); .sum();
//平均延迟 //平均延迟
double OrderDelay = Math.round(OrderSumDelay / chromosome.getOrders().size() * 100) / 100; double OrderDelay = Math.round(OrderSumDelay / chromosome.getOrders().size() * 100.0) / 100.0;
addKpi(kpiMetrics,"平均延迟", OrderDelay, "所有订单的延迟时间平均值", 2, 1); addKpi(kpiMetrics,"平均延迟", OrderDelay, "所有订单的延迟时间平均值", 2, 1);
//最长生产周期 //最长生产周期
double OrderMaxProductTime = chromosome.getOrders().stream() double OrderMaxProductTime = chromosome.getOrders().stream()
...@@ -92,7 +92,7 @@ public class KpiCalculator { ...@@ -92,7 +92,7 @@ public class KpiCalculator {
.mapToDouble(Order::getOrderProductTime) .mapToDouble(Order::getOrderProductTime)
.sum(); .sum();
//平均生产周期 //平均生产周期
double OrderProductTime= Math.round(OrderSumProductTime / chromosome.getOrders().size() * 100) / 100; double OrderProductTime= Math.round(OrderSumProductTime / chromosome.getOrders().size() * 100.0) / 100.0;
addKpi(kpiMetrics,"平均生产周期", OrderProductTime, "订单在计划中的实际存续时长", 2, 1); addKpi(kpiMetrics,"平均生产周期", OrderProductTime, "订单在计划中的实际存续时长", 2, 1);
//最大流量 //最大流量
...@@ -114,7 +114,7 @@ public class KpiCalculator { ...@@ -114,7 +114,7 @@ public class KpiCalculator {
.mapToDouble(Order::getOrderFlow) .mapToDouble(Order::getOrderFlow)
.sum(); .sum();
//平均流量 //平均流量
double OrderFlow= Math.round(OrderSumFlow / chromosome.getOrders().size() * 100) / 100; double OrderFlow= Math.round(OrderSumFlow / chromosome.getOrders().size() * 100.0) / 100.0;
addKpi(kpiMetrics,"平均流量", OrderFlow, "订单的最短理论耗时与其在计划中的实际耗时的比值", 0, 1); addKpi(kpiMetrics,"平均流量", OrderFlow, "订单的最短理论耗时与其在计划中的实际耗时的比值", 0, 1);
chromosome.setKpiMetrics(kpiMetrics); chromosome.setKpiMetrics(kpiMetrics);
...@@ -234,7 +234,7 @@ public class KpiCalculator { ...@@ -234,7 +234,7 @@ public class KpiCalculator {
Duration Orderduration = Duration.between(actualStartTime,actualCompletionTime); Duration Orderduration = Duration.between(actualStartTime,actualCompletionTime);
double orderProductTime =Orderduration.getSeconds(); double orderProductTime =Orderduration.getSeconds();
order.setOrderProductTime(orderProductTime); order.setOrderProductTime(orderProductTime);
double flow=Math.round(orderProcessingTime/orderProductTime *10000)/10000*100; double flow=Math.round(orderProcessingTime/orderProductTime *10000.0)/10000.0*100.0;
order.setOrderFlow(flow); order.setOrderFlow(flow);
// 计算延迟时间(若提前完成则延迟为0) // 计算延迟时间(若提前完成则延迟为0)
......
...@@ -411,6 +411,7 @@ if(routingIds.size()==0) ...@@ -411,6 +411,7 @@ if(routingIds.size()==0)
launchOrder.setSerie(order.getSerie()); launchOrder.setSerie(order.getSerie());
launchOrder.setCreateUser("GA"); launchOrder.setCreateUser("GA");
launchOrder.setMaterialCode(order.getMaterialCode()); launchOrder.setMaterialCode(order.getMaterialCode());
launchOrder.setMaterialName(order.getMaterialName());
// launchOrder.setStartDate(order.get); // launchOrder.setStartDate(order.get);
launchOrder.setEndDate(order.getDueDate()); launchOrder.setEndDate(order.getDueDate());
// launchOrder.setOrderPriority(order.getPrioritry()); // launchOrder.setOrderPriority(order.getPrioritry());
...@@ -603,6 +604,7 @@ if(routingIds.size()==0) ...@@ -603,6 +604,7 @@ if(routingIds.size()==0)
childorder.setOrderId(OrderId); childorder.setOrderId(OrderId);
childorder.setMaterialId(material.getId()); childorder.setMaterialId(material.getId());
childorder.setMaterialCode(material.getCode()); childorder.setMaterialCode(material.getCode());
childorder.setMaterialName(material.getName());
childorder.setOrderCode(material.getCode()); childorder.setOrderCode(material.getCode());
childorder.setQuantity((int) orderMaterial.getQjQty()); childorder.setQuantity((int) orderMaterial.getQjQty());
childorder.setFinishOrderId(new ArrayList<>()); childorder.setFinishOrderId(new ArrayList<>());
......
...@@ -214,6 +214,7 @@ public class RoutingDataService { ...@@ -214,6 +214,7 @@ public class RoutingDataService {
entry.setRuntime(op.getRuntime()); entry.setRuntime(op.getRuntime());
entry.setSingleOut(op.getSingleOut()); entry.setSingleOut(op.getSingleOut());
entry.setOrderId(op.getOrderId()); entry.setOrderId(op.getOrderId());
entry.setOrderCode(op.getOrderCode());
entry.setQuantity(op.getPlanQty()); entry.setQuantity(op.getPlanQty());
entry.setRoutingId(op.getRoutingId()); entry.setRoutingId(op.getRoutingId());
entry.setRoutingDetailId(op.getRoutingDetailId()); entry.setRoutingDetailId(op.getRoutingDetailId());
...@@ -225,6 +226,8 @@ public class RoutingDataService { ...@@ -225,6 +226,8 @@ public class RoutingDataService {
.findFirst().orElse(null); .findFirst().orElse(null);
if (order != null) { if (order != null) {
entry.setProductId(order.getMaterialId()); entry.setProductId(order.getMaterialId());
entry.setProductCode(order.getMaterialCode());
entry.setProductName(order.getMaterialName());
entry.setPriority(order.getActualPriority()); entry.setPriority(order.getActualPriority());
order.setId(entry.getGroupId()); order.setId(entry.getGroupId());
} }
......
...@@ -515,6 +515,7 @@ Integer newMachineId1=newMachineId.intValue(); ...@@ -515,6 +515,7 @@ Integer newMachineId1=newMachineId.intValue();
Entry newOp = ProductionDeepCopyUtil.deepCopy(entry,Entry.class); Entry newOp = ProductionDeepCopyUtil.deepCopy(entry,Entry.class);
newOp.setExecId(newId); newOp.setExecId(newId);
newOp.setOrderId(neworder.getOrderId()); newOp.setOrderId(neworder.getOrderId());
newOp.setOrderCode(neworder.getOrderCode());
newOp.setGroupId(maxorderId); newOp.setGroupId(maxorderId);
newOp.setQuantity(splitCounts[i]); newOp.setQuantity(splitCounts[i]);
newOp.setNewCreate(true); newOp.setNewCreate(true);
......
...@@ -1104,6 +1104,7 @@ public class ChromosomeDataService { ...@@ -1104,6 +1104,7 @@ public class ChromosomeDataService {
prodProcessExec.setExecId(entry.ExecId); prodProcessExec.setExecId(entry.ExecId);
prodProcessExec.setSceneId(entry.SceneId); prodProcessExec.setSceneId(entry.SceneId);
prodProcessExec.setOrderId(entry.OrderId); prodProcessExec.setOrderId(entry.OrderId);
prodProcessExec.setRoutingDetailId(entry.getRoutingDetailId()); prodProcessExec.setRoutingDetailId(entry.getRoutingDetailId());
prodProcessExec.setTaskSeq(entry.getTaskSeq()); prodProcessExec.setTaskSeq(entry.getTaskSeq());
prodProcessExec.setRoutingDetailName(entry.getRoutingDetailName()); prodProcessExec.setRoutingDetailName(entry.getRoutingDetailName());
......
...@@ -10,90 +10,183 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -10,90 +10,183 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.*;
import java.util.Objects; import java.util.concurrent.ConcurrentHashMap;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author MyBatis-Plus
* @since 2025-12-03
*/
@Service @Service
public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscreteParameterMatrixMapper, DiscreteParameterMatrix> implements DiscreteParameterMatrixService { public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscreteParameterMatrixMapper, DiscreteParameterMatrix> implements DiscreteParameterMatrixService {
@Autowired @Autowired
private RoutingDiscreteParamService _routingDiscreteParamService; private RoutingDiscreteParamService _routingDiscreteParamService;
@Override
public double getDiscreteParameterMatrixValue(Entry entry, Entry lastEntry) {
// 缓存配置
private static final int MAX_RESULT_CACHE_SIZE = 1000; // 结果缓存最大容量
private static final int MAX_MATRIX_CACHE_SIZE = 500; // 矩阵数据缓存最大容量
private static final int CLEANUP_INTERVAL = 100; // 每100次调用清理一次
// 双缓存:计算结果缓存 + 矩阵数据缓存
private final ConcurrentHashMap<String, Double> resultCache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, List<DiscreteParameterMatrix>> matrixDataCache = new ConcurrentHashMap<>();
// 调用计数器
private int callCount = 0;
// 1. 参数验证 @Override
public double getDiscreteParameterMatrixValue(Entry entry, Entry lastEntry) {
// 参数校验
if (entry == null || lastEntry == null) { if (entry == null || lastEntry == null) {
return 0.0; return 0.0;
} }
// 2. 获取基础数据
List<RoutingDiscreteParam> firstParams = lastEntry.getDiscreteParameter(); List<RoutingDiscreteParam> firstParams = lastEntry.getDiscreteParameter();
List<RoutingDiscreteParam> secondParams = entry.getDiscreteParameter(); List<RoutingDiscreteParam> secondParams = entry.getDiscreteParameter();
// 检查参数列表是否为null if (firstParams == null || secondParams == null || firstParams.isEmpty() || secondParams.isEmpty()) {
if (firstParams == null || secondParams == null) {
return 0.0; return 0.0;
} }
if (firstParams.isEmpty() || secondParams.isEmpty()) { // 生成缓存键
return 0.0; String cacheKey = generateCacheKey(entry, lastEntry, firstParams, secondParams);
// 使用computeIfAbsent:线程安全,有则返回,无则计算
double result = resultCache.computeIfAbsent(cacheKey, key -> {
// 查找匹配参数
List<RoutingDiscreteParam> matchingParams = findMatchingParams(firstParams, secondParams);
if (matchingParams.isEmpty()) {
return 0.0;
}
// 获取设备/设备类型ID
long firstEquipId = lastEntry.getSelectMachineID() != null ? lastEntry.getSelectMachineID() : 0L;
long secondEquipId = entry.getSelectMachineID() != null ? entry.getSelectMachineID() : 0L;
long firstEquipTypeId = lastEntry.getEquipTypeID() != null ? lastEntry.getEquipTypeID() : 0L;
long secondEquipTypeId = entry.getEquipTypeID() != null ? entry.getEquipTypeID() : 0L;
if (firstEquipId == 0 || secondEquipId == 0 || firstEquipTypeId == 0 || secondEquipTypeId == 0) {
System.out.println(firstEquipId + "-- " + secondEquipId + "-- " + firstEquipTypeId + "-- " + secondEquipTypeId);
return 0.0;
}
// 查找最大换型时间
return findMaxChangeOverTime(matchingParams, secondParams, firstEquipId, secondEquipId, firstEquipTypeId, secondEquipTypeId);
});
// 定期清理缓存
synchronized (this) {
callCount++;
if (callCount >= CLEANUP_INTERVAL) {
cleanCachesIfNeeded();
callCount = 0;
}
} }
// 3. 查找匹配的参数 return result;
List<RoutingDiscreteParam> matchingParams = findMatchingParams(firstParams, secondParams); }
if (matchingParams.isEmpty()) {
return 0.0;
}
long firstEquipId = lastEntry.getSelectMachineID() != null ? lastEntry.getSelectMachineID() : 0L;
long secondEquipId = entry.getSelectMachineID() != null ? entry.getSelectMachineID() : 0L;
long firstEquipTypeId = lastEntry.getEquipTypeID() != null ? lastEntry.getEquipTypeID() : 0L;
long secondEquipTypeId = entry.getSelectMachineID() != null ? entry.getSelectMachineID() : 0L;
if (firstEquipId == 0 || secondEquipId == 0 || firstEquipTypeId == 0 || secondEquipTypeId == 0) { /**
System.out.println(firstEquipId + "-- " + secondEquipId + "-- " + firstEquipTypeId + "-- " + secondEquipTypeId); * 获取矩阵数据(带缓存)
*/
private List<DiscreteParameterMatrix> getMatrixDataWithCache(Set<String> groupIds) {
if (groupIds == null || groupIds.isEmpty()) {
return Collections.emptyList();
}
return 0.0; // 生成缓存键
String cacheKey = groupIds.stream()
.filter(Objects::nonNull)
.sorted()
.collect(Collectors.joining(","));
if (cacheKey.isEmpty()) {
return Collections.emptyList();
} }
// 使用computeIfAbsent缓存矩阵数据
return matrixDataCache.computeIfAbsent(cacheKey, key ->
this.lambdaQuery()
.in(DiscreteParameterMatrix::getGroupid, groupIds)
.eq(DiscreteParameterMatrix::getIsdeleted, 0)
.list()
);
}
/**
* 清理缓存(如果需要)
*/
private void cleanCachesIfNeeded() {
// 清理结果缓存
if (resultCache.size() > MAX_RESULT_CACHE_SIZE) {
cleanCache(resultCache, MAX_RESULT_CACHE_SIZE);
}
// 4. 获取矩阵数据并计算最大时长 // 清理矩阵缓存
return findMaxChangeOverTime(matchingParams, secondParams,firstEquipId,secondEquipId,firstEquipTypeId,secondEquipTypeId); if (matrixDataCache.size() > MAX_MATRIX_CACHE_SIZE) {
cleanCache(matrixDataCache, MAX_MATRIX_CACHE_SIZE);
}
} }
/**
* 通用的缓存清理方法
*/
private <K, V> void cleanCache(ConcurrentHashMap<K, V> cache, int maxSize) {
if (cache.size() <= maxSize) {
return;
}
int targetSize = maxSize * 3 / 4; // 清理到75%
Iterator<K> iterator = cache.keySet().iterator();
int removed = 0;
while (cache.size() > targetSize && iterator.hasNext()) {
iterator.next();
iterator.remove();
removed++;
}
}
/** /**
* 获取路由参数列表 * 生成结果缓存键
*/ */
private List<RoutingDiscreteParam> getRoutingParams(Long detailId) { private String generateCacheKey(Entry entry, Entry lastEntry,
return _routingDiscreteParamService.lambdaQuery() List<RoutingDiscreteParam> firstParams,
.eq(RoutingDiscreteParam::getRoutingDetailId, detailId) List<RoutingDiscreteParam> secondParams) {
.eq(RoutingDiscreteParam::getIsDeleted, 0) StringBuilder key = new StringBuilder();
.list(); key.append("E").append(entry.getId())
.append("_LE").append(lastEntry.getId())
.append("_EID").append(entry.getSelectMachineID())
.append("_LEID").append(lastEntry.getSelectMachineID())
.append("_ET").append(entry.getEquipTypeID())
.append("_LET").append(lastEntry.getEquipTypeID());
// 参数哈希(避免顺序影响)
if (firstParams != null && secondParams != null) {
key.append("_PH").append(getParamsHash(firstParams)).append("_").append(getParamsHash(secondParams));
}
return key.toString();
} }
/** /**
* 查找匹配的参数(first中groupId在second中也存在的参数) * 计算参数哈希值
*/ */
private List<RoutingDiscreteParam> findMatchingParams( private int getParamsHash(List<RoutingDiscreteParam> params) {
List<RoutingDiscreteParam> firstParams, if (params == null || params.isEmpty()) {
List<RoutingDiscreteParam> secondParams) { return 0;
}
String paramStr = params.stream()
.filter(Objects::nonNull)
.map(p -> (p.getGroupId() != null ? p.getGroupId() : "") + ":" + (p.getParameterId() != null ? p.getParameterId() : ""))
.sorted()
.collect(Collectors.joining("#"));
return paramStr.hashCode();
}
/**
* 查找匹配的参数(first中groupId在second中存在的参数)
*/
private List<RoutingDiscreteParam> findMatchingParams(List<RoutingDiscreteParam> firstParams, List<RoutingDiscreteParam> secondParams) {
Set<String> secondGroupIds = secondParams.stream() Set<String> secondGroupIds = secondParams.stream()
.map(RoutingDiscreteParam::getGroupId) .map(RoutingDiscreteParam::getGroupId)
.filter(Objects::nonNull) .filter(Objects::nonNull)
...@@ -108,7 +201,9 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara ...@@ -108,7 +201,9 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara
* 查找最大换型时间 * 查找最大换型时间
*/ */
private double findMaxChangeOverTime(List<RoutingDiscreteParam> matchingParams, private double findMaxChangeOverTime(List<RoutingDiscreteParam> matchingParams,
List<RoutingDiscreteParam> secondParams,long firstEquipId, long secondEquipId, long firstEquipTypeId, long secondEquipTypeId) { List<RoutingDiscreteParam> secondParams,
long firstEquipId, long secondEquipId,
long firstEquipTypeId, long secondEquipTypeId) {
Set<String> groupIds = matchingParams.stream() Set<String> groupIds = matchingParams.stream()
.map(RoutingDiscreteParam::getGroupId) .map(RoutingDiscreteParam::getGroupId)
...@@ -119,67 +214,67 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara ...@@ -119,67 +214,67 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara
return 0.0; return 0.0;
} }
// 获取矩阵数据 // 获取矩阵数据(走缓存)
List<DiscreteParameterMatrix> matrixData = getMatrixData(groupIds); List<DiscreteParameterMatrix> matrixData = getMatrixDataWithCache(groupIds);
// 按优先级查找匹配的矩阵记录 // 按优先级匹配矩阵记录
List<DiscreteParameterMatrix> matchedMatrix = findMatchedMatrixByPriority( List<DiscreteParameterMatrix> matchedMatrix = findMatchedMatrixByPriority(
matchingParams, secondParams, matrixData,firstEquipId,secondEquipId,firstEquipTypeId,secondEquipTypeId); matchingParams, secondParams, matrixData,
firstEquipId, secondEquipId, firstEquipTypeId, secondEquipTypeId);
// 获取最大时长
return getMaxDuration(matchedMatrix); return getMaxDuration(matchedMatrix);
} }
/** /**
* 获取矩阵数据 * 按优先级匹配矩阵记录(设备级→设备类型级→全局级)
*/
private List<DiscreteParameterMatrix> getMatrixData(Set<String> groupIds) {
// 直接使用this调用,避免循环依赖
return this.lambdaQuery()
.in(DiscreteParameterMatrix::getGroupid, groupIds)
.eq(DiscreteParameterMatrix::getIsdeleted, 0)
.list();
}
/**
* 按优先级查找匹配的矩阵记录
*/ */
private List<DiscreteParameterMatrix> findMatchedMatrixByPriority( private List<DiscreteParameterMatrix> findMatchedMatrixByPriority(
List<RoutingDiscreteParam> matchingParams, List<RoutingDiscreteParam> matchingParams,
List<RoutingDiscreteParam> secondParams, List<RoutingDiscreteParam> secondParams,
List<DiscreteParameterMatrix> matrixData,long firstEquipId, long secondEquipId, long firstEquipTypeId, long secondEquipTypeId) { List<DiscreteParameterMatrix> matrixData,
long firstEquipId, long secondEquipId,
long firstEquipTypeId, long secondEquipTypeId) {
// 优先级1: 设备级别匹配 (isEquip=1, isEquipType=0, isGlobal=0) // 优先级1:设备级别
List<DiscreteParameterMatrix> result = findMatrixMatches( List<DiscreteParameterMatrix> result = findMatrixMatches(
matchingParams, secondParams, matrixData, 1, 0, 0,firstEquipId,secondEquipId,firstEquipTypeId,secondEquipTypeId); matchingParams, secondParams, matrixData, 1, 0, 0,
firstEquipId, secondEquipId, firstEquipTypeId, secondEquipTypeId);
if (!result.isEmpty()) { if (!result.isEmpty()) {
return result; return result;
} }
// 优先级2: 设备类型级别匹配 (isEquip=0, isEquipType=1, isGlobal=0) // 优先级2:设备类型级别
result = findMatrixMatches(matchingParams, secondParams, matrixData, 0, 1, 0,firstEquipId,secondEquipId,firstEquipTypeId,secondEquipTypeId); result = findMatrixMatches(matchingParams, secondParams, matrixData, 0, 1, 0,
firstEquipId, secondEquipId, firstEquipTypeId, secondEquipTypeId);
if (!result.isEmpty()) { if (!result.isEmpty()) {
return result; return result;
} }
// 优先级3: 全局级别匹配 (isEquip=0, isEquipType=0, isGlobal=1) // 优先级3:全局级别
return findMatrixMatches(matchingParams, secondParams, matrixData, 0, 0, 1,firstEquipId,secondEquipId,firstEquipTypeId,secondEquipTypeId); return findMatrixMatches(matchingParams, secondParams, matrixData, 0, 0, 1,
firstEquipId, secondEquipId, firstEquipTypeId, secondEquipTypeId);
} }
/** /**
* 查找矩阵匹配记录 * 匹配矩阵记录
*/ */
private List<DiscreteParameterMatrix> findMatrixMatches( private List<DiscreteParameterMatrix> findMatrixMatches(
List<RoutingDiscreteParam> matchingParams, List<RoutingDiscreteParam> matchingParams,
List<RoutingDiscreteParam> secondParams, List<RoutingDiscreteParam> secondParams,
List<DiscreteParameterMatrix> matrixData, List<DiscreteParameterMatrix> matrixData,
int isEquip, int isEquipType, int isGlobal,long firstEquipId, long secondEquipId, long firstEquipTypeId, long secondEquipTypeId) { int isEquip, int isEquipType, int isGlobal,
long firstEquipId, long secondEquipId,
long firstEquipTypeId, long secondEquipTypeId) {
return matchingParams.stream() return matchingParams.stream()
.flatMap(firstParam -> secondParams.stream() .flatMap(firstParam -> secondParams.stream()
.flatMap(secondParam -> matrixData.stream() .flatMap(secondParam -> matrixData.stream()
.filter(matrix -> isMatrixMatch(matrix, firstParam, secondParam, isEquip, isEquipType, isGlobal,firstEquipId,secondEquipId,firstEquipTypeId,secondEquipTypeId)) .filter(matrix -> isMatrixMatch(matrix, firstParam, secondParam,
isEquip, isEquipType, isGlobal,
firstEquipId, secondEquipId, firstEquipTypeId, secondEquipTypeId))
) )
) )
.collect(Collectors.toList()); .collect(Collectors.toList());
...@@ -188,68 +283,59 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara ...@@ -188,68 +283,59 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara
/** /**
* 检查矩阵是否匹配 * 检查矩阵是否匹配
*/ */
/**
* 检查矩阵是否匹配(最简修正)
*/
private boolean isMatrixMatch(DiscreteParameterMatrix matrix, private boolean isMatrixMatch(DiscreteParameterMatrix matrix,
RoutingDiscreteParam firstParam, RoutingDiscreteParam firstParam,
RoutingDiscreteParam secondParam, RoutingDiscreteParam secondParam,
int requiredEquip, int requiredEquipType, int requiredGlobal,long firstEquipId, long secondEquipId, long firstEquipTypeId, long secondEquipTypeId) { int requiredEquip, int requiredEquipType, int requiredGlobal,
long firstEquipId, long secondEquipId,
long firstEquipTypeId, long secondEquipTypeId) {
// 1. 先检查参数ID匹配 // 参数ID匹配校验
if (!Objects.equals(matrix.getFirstparameterid(), firstParam.getParameterId()) || if (!Objects.equals(matrix.getFirstparameterid(), firstParam.getParameterId()) ||
!Objects.equals(matrix.getSecondparameterid(), secondParam.getParameterId())) { !Objects.equals(matrix.getSecondparameterid(), secondParam.getParameterId())) {
return false; return false;
} }
// 2. 按优先级检查:处理null值,null视为0 // 设备级别匹配
if (requiredEquip == 1) { if (requiredEquip == 1) {
return ((matrix.getIsequip() != null ? matrix.getIsequip() : 0) == 1) && return (matrix.getIsequip() != null ? matrix.getIsequip() : 0) == 1 &&
Objects.equals(matrix.getEquipid(), firstEquipId) && Objects.equals(matrix.getEquipid(), firstEquipId) &&
Objects.equals(matrix.getEquipid(), secondEquipId) && Objects.equals(matrix.getEquipid(), secondEquipId) &&
firstEquipId == secondEquipId; // 确保前后工序使用同一设备 firstEquipId == secondEquipId;
} }
// 设备类型级别匹配
if (requiredEquipType == 1) { if (requiredEquipType == 1) {
return ((matrix.getIsequiptype() != null ? matrix.getIsequiptype() : 0) == 1) && return (matrix.getIsequiptype() != null ? matrix.getIsequiptype() : 0) == 1 &&
Objects.equals(matrix.getEquiptypeid(), firstEquipTypeId) && Objects.equals(matrix.getEquiptypeid(), firstEquipTypeId) &&
Objects.equals(matrix.getEquiptypeid(), secondEquipTypeId) && Objects.equals(matrix.getEquiptypeid(), secondEquipTypeId) &&
firstEquipTypeId == secondEquipTypeId; // 确保前后工序使用同类型设备 firstEquipTypeId == secondEquipTypeId;
} }
// 全局级别匹配
if (requiredGlobal == 1) { if (requiredGlobal == 1) {
return (matrix.getIsglobal() != null ? matrix.getIsglobal() : 0) == 1; return (matrix.getIsglobal() != null ? matrix.getIsglobal() : 0) == 1;
} }
return false; return false;
} }
/** /**
* 获取最大时长 * 获取最大换型时长
*/ */
private double getMaxDuration(List<DiscreteParameterMatrix> matrixList) { private double getMaxDuration(List<DiscreteParameterMatrix> matrixList) {
return matrixList.stream() return matrixList.stream()
.filter(matrix -> matrix.getDurationsecond() > 0) .filter(matrix -> matrix.getDurationsecond() > 0)
.map(DiscreteParameterMatrix::getDurationsecond) // 保持Double类型 .map(DiscreteParameterMatrix::getDurationsecond)
.max(Double::compareTo) // 使用Double的比较器 .max(Double::compareTo)
.orElse(0.0); .orElse(0.0);
} }
/**
* 清理所有缓存
*/
public void clearCache() {
resultCache.clear();
matrixDataCache.clear();
}
} }
\ No newline at end of file
...@@ -360,9 +360,10 @@ public class LanuchServiceImpl implements LanuchService { ...@@ -360,9 +360,10 @@ public class LanuchServiceImpl implements LanuchService {
launchOrder.setSerie(order.getSeries()); launchOrder.setSerie(order.getSeries());
launchOrder.setCreateUser(String.valueOf(order.getCreatoruserid())); launchOrder.setCreateUser(String.valueOf(order.getCreatoruserid()));
launchOrder.setMaterialCode(order.getMmcode()); launchOrder.setMaterialCode(order.getMmcode());
launchOrder.setMaterialName(order.getMmname());
launchOrder.setEndDate(order.getDeliverytime()); launchOrder.setEndDate(order.getDeliverytime());
launchOrder.setStartDate(order.getBegintime()); launchOrder.setStartDate(order.getBegintime());
launchOrder.setOrderCode(order.getCode());
try { try {
launchOrder.setOrderPriority(Integer.valueOf(order.getPrioritry())); launchOrder.setOrderPriority(Integer.valueOf(order.getPrioritry()));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
...@@ -687,6 +688,7 @@ public class LanuchServiceImpl implements LanuchService { ...@@ -687,6 +688,7 @@ public class LanuchServiceImpl implements LanuchService {
ProdProcessExec prodProcessExec = new ProdProcessExec(); ProdProcessExec prodProcessExec = new ProdProcessExec();
prodProcessExec.setExecId(UUID.randomUUID().toString().replace("-", "")); prodProcessExec.setExecId(UUID.randomUUID().toString().replace("-", ""));
prodProcessExec.setOrderId(prodOrderMain.getOrderId()); prodProcessExec.setOrderId(prodOrderMain.getOrderId());
prodProcessExec.setOrderCode(prodOrderMain.getOrderCode());
prodProcessExec.setRoutingDetailId(detail.getId()); prodProcessExec.setRoutingDetailId(detail.getId());
prodProcessExec.setTaskSeq(detail.getTaskSeq()); prodProcessExec.setTaskSeq(detail.getTaskSeq());
prodProcessExec.setRoutingDetailName(detail.getName()); prodProcessExec.setRoutingDetailName(detail.getName());
......
...@@ -7,6 +7,7 @@ import com.aps.entity.*; ...@@ -7,6 +7,7 @@ import com.aps.entity.*;
import com.aps.entity.Algorithm.*; import com.aps.entity.Algorithm.*;
import com.aps.entity.Algorithm.IDAndChildID.GroupResult; import com.aps.entity.Algorithm.IDAndChildID.GroupResult;
import com.aps.entity.Algorithm.IDAndChildID.NodeInfo; import com.aps.entity.Algorithm.IDAndChildID.NodeInfo;
import com.aps.entity.Gantt.TaskVO;
import com.aps.entity.Schedule.SceneChromsome; import com.aps.entity.Schedule.SceneChromsome;
import com.aps.entity.basic.ScheduleChromosome; import com.aps.entity.basic.ScheduleChromosome;
import com.aps.entity.Schedule.GenVO; import com.aps.entity.Schedule.GenVO;
...@@ -936,6 +937,7 @@ private GlobalParam InitGlobalParam() ...@@ -936,6 +937,7 @@ private GlobalParam InitGlobalParam()
for (ProdLaunchOrder lo : ProdLaunchOrders) { for (ProdLaunchOrder lo : ProdLaunchOrders) {
Order order=new Order(); Order order=new Order();
order.setMaterialCode(lo.getMaterialCode()); order.setMaterialCode(lo.getMaterialCode());
order.setMaterialName(lo.getMaterialName());
order.setSerie(lo.getSerie()==null?"":lo.getSerie()); order.setSerie(lo.getSerie()==null?"":lo.getSerie());
order.setOrderCode(lo.getOrderCode()); order.setOrderCode(lo.getOrderCode());
order.setOrderId(lo.getOrderId()); order.setOrderId(lo.getOrderId());
...@@ -1539,12 +1541,14 @@ private GlobalParam InitGlobalParam() ...@@ -1539,12 +1541,14 @@ private GlobalParam InitGlobalParam()
.filter(t -> t.getId() == gene.getOperationId()).findFirst().orElse(null); .filter(t -> t.getId() == gene.getOperationId()).findFirst().orElse(null);
com.aps.entity.Gantt.TaskVO taskVO = new com.aps.entity.Gantt.TaskVO(); TaskVO taskVO = new TaskVO();
taskVO.setId(String.valueOf(gene.getOperationId())); taskVO.setId(String.valueOf(gene.getOperationId()));
taskVO.setPlanId(gene.getOrderId()); // 默认值 taskVO.setPlanId(gene.getOrderId()); // 默认值
taskVO.setPlanCode(gene.getOrderCode()); // 默认值
// taskVO.setProductType(0); // 默认值 // taskVO.setProductType(0); // 默认值
// taskVO.setProductName("产品"+gene.getProductId()); taskVO.setProductName(gene.getProductName());
taskVO.setProductId(gene.getProductId()); // 默认值 taskVO.setProductId(gene.getProductId()); // 默认值
taskVO.setProductCode(gene.getProductCode()); // 默认值
taskVO.setQuantity(gene.getQuantity()); taskVO.setQuantity(gene.getQuantity());
taskVO.setStart(scheduleChromosome.getBaseTime().plusSeconds(gene.getStartTime())); taskVO.setStart(scheduleChromosome.getBaseTime().plusSeconds(gene.getStartTime()));
taskVO.setEnd(scheduleChromosome.getBaseTime().plusSeconds(gene.getEndTime())); taskVO.setEnd(scheduleChromosome.getBaseTime().plusSeconds(gene.getEndTime()));
...@@ -1569,22 +1573,14 @@ private GlobalParam InitGlobalParam() ...@@ -1569,22 +1573,14 @@ private GlobalParam InitGlobalParam()
taskVO.setShopId(machine.getId()); taskVO.setShopId(machine.getId());
taskVO.setShopName(resourceGanttVO.getShopName()); taskVO.setShopName(resourceGanttVO.getShopName());
taskVO.setStatus(0); // 默认值 taskVO.setStatus(0); // 默认值
taskVO.setDetailId((long) gene.getStartTime()); // 将productId和operationID组合为detailId taskVO.setDetailId(entry.getRoutingDetailId()); // 将productId和operationID组合为detailId
taskVO.setHeaderId(gene.getEndTime()); // 默认值 taskVO.setHeaderId(entry.getRoutingId()); // 默认值
// taskVO.setHeaderName("工艺"+gene.getProductId()); // 默认值 taskVO.setHeaderName(entry.getRoutingName()); // 默认值
// taskVO.setSeq(gene.getSequenceId()); // 使用工序ID taskVO.setSeq(Math.toIntExact(entry.getTaskSeq())); // 使用工序ID
// taskVO.setSeqName( "工序名称"+gene.getSequenceId()); taskVO.setSeqName(entry.getRoutingDetailName());
taskVO.setProcessingTime(gene.getProcessingTime()); taskVO.setProcessingTime(gene.getProcessingTime());
// taskVO.setAbsoluteStart(scheduleChromosome.getBaseTime().plusMinutes(gene.getStartTime()));
// taskVO.setAbsoluteEnd(scheduleChromosome.getBaseTime().plusMinutes(gene.getEndTime()));
taskVOList.add(taskVO);
// 调试:检查machine中的shifts状态 taskVOList.add(taskVO);
// if (machine.getShifts() != null) {
// for (Shift shift : machine.getShifts()) {
// System.out.println("Before setting shifts - Shift status: " + shift.getStatus());
// }
// }
taskVO.setAbsolutePreparationTime(gene.getTeardownTime()); taskVO.setAbsolutePreparationTime(gene.getTeardownTime());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment