策略优化

parent acfd275e
...@@ -1378,12 +1378,13 @@ public class GeneticDecoder { ...@@ -1378,12 +1378,13 @@ public class GeneticDecoder {
} }
// startTime 是相对 baseTime 的秒数,0 表示正好从排产基准时间开始,属于合法结果,不能当成失败。
int startTime = geneDetails.stream() int startTime = geneDetails.stream()
.mapToInt(ScheduleResultDetail::getStartTime) .mapToInt(ScheduleResultDetail::getStartTime)
.min() .min()
.orElse(0); .orElse(0);
if (startTime == 0) { if (startTime < 0) {
if(islockMachineTime) if(islockMachineTime)
{ {
// FileHelper.writeLogFile(" 半成品222222 " + operation.getGroupId() + " - " + operation.getSequence() + ",开始时间: " + startTime + ",结束时间: " + 0 + ",处理时间: " + processingTime + ", 后处理: " + teardownTime + // FileHelper.writeLogFile(" 半成品222222 " + operation.getGroupId() + " - " + operation.getSequence() + ",开始时间: " + startTime + ",结束时间: " + 0 + ",处理时间: " + processingTime + ", 后处理: " + teardownTime +
...@@ -1393,6 +1394,11 @@ public class GeneticDecoder { ...@@ -1393,6 +1394,11 @@ public class GeneticDecoder {
return null; return null;
} }
if (startTime == 0 && islockMachineTime) {
FileHelper.writeLogFile(String.format(
"排产结果从基准时间开始,正常写入result,订单:%s,工序:%d,设备:%d",
operation.getOrderCode(), operation.getId(), machine.getId()));
}
int endTime = geneDetails.stream() int endTime = geneDetails.stream()
.mapToInt(ScheduleResultDetail::getEndTime) .mapToInt(ScheduleResultDetail::getEndTime)
.max() .max()
......
...@@ -9,6 +9,7 @@ import com.aps.service.StrategyRuleService; ...@@ -9,6 +9,7 @@ import com.aps.service.StrategyRuleService;
import com.aps.service.UserStrategyRuleService; import com.aps.service.UserStrategyRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -346,7 +347,26 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap ...@@ -346,7 +347,26 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
} }
private List<StrategyScheduling> parseForwardScheduling(String json) { private List<StrategyScheduling> parseForwardScheduling(String json) {
return EnhancedJsonConversionUtil.convertJsonToEntities(json, null, StrategyScheduling.class); if (!StringUtils.hasText(json)) {
return new ArrayList<>();
}
try {
JsonNode root = objectMapper.readTree(json);
if (root == null || root.isNull()) {
return new ArrayList<>();
}
// 新版用户策略保存的是数组;老的全局策略可能保存为 {kpiList, ruleList}。
JsonNode schedulingNode = root.isArray() ? root : root.path("forwardScheduling");
if (!schedulingNode.isArray()) {
schedulingNode = root.path("ruleList");
}
if (!schedulingNode.isArray()) {
return new ArrayList<>();
}
return EnhancedJsonConversionUtil.convertJsonToEntities(schedulingNode.toString(), null, StrategyScheduling.class);
} catch (Exception e) {
return new ArrayList<>();
}
} }
private Object parseJson(String json) { private Object parseJson(String json) {
...@@ -397,8 +417,16 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap ...@@ -397,8 +417,16 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
return toLong(ruleId); return toLong(ruleId);
} }
Long baseRuleId = getLong(params, "baseRuleId"); Long baseRuleId = getLong(params, "baseRuleId");
// 前端保存策略时传的是 referenceId,这里兼容成基础策略 ID。 // 前端保存策略时可能传 referenceId;只有纯数字时才兼容成基础策略 ID,UUID 行引用要忽略。
return baseRuleId == null ? getLong(params, "referenceId") : baseRuleId; return baseRuleId == null ? getLongIfNumeric(params, "referenceId") : baseRuleId;
}
private Long getLongIfNumeric(Map<String, Object> params, String key) {
String value = getString(params, key);
if (!StringUtils.hasText(value) || !value.matches("\\d+")) {
return null;
}
return toLong(value);
} }
private String getString(Map<String, Object> params, String key) { private String getString(Map<String, Object> params, String key) {
......
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