取消固定日期

parent d209cd62
...@@ -170,7 +170,7 @@ public class ChromosomeDataController { ...@@ -170,7 +170,7 @@ public class ChromosomeDataController {
if (entityName.equalsIgnoreCase("machine")){ if (entityName.equalsIgnoreCase("machine")){
return updateMachineOption(sceneId, taskId, data); return chromosomeDataService.updateMachineOption(sceneId, taskId, data);
} }
...@@ -181,148 +181,6 @@ public class ChromosomeDataController { ...@@ -181,148 +181,6 @@ public class ChromosomeDataController {
} }
private R<String> updateMachineOption(String sceneId, String taskId, Map<String, Object> data) {
// 1. 加载Chromosome对象
Chromosome chromosome = sceneService.loadChromosomeFromFile(sceneId);
// 2. 根据taskId找到对应的entry
Entry targetEntry = null;
for (Entry entry : chromosome.getAllOperations()) {
if (String.valueOf(entry.getId()).equals(taskId)) {
targetEntry = entry;
break;
}
}
Long machineId = null;
Object machineIdObj = data.get("machineId");
if (machineIdObj instanceof Long) {
machineId = (Long) machineIdObj;
} else if (machineIdObj instanceof Integer) {
machineId = ((Integer) machineIdObj).longValue();
} else if (machineIdObj instanceof String) {
machineId = Long.parseLong((String) machineIdObj);
}
// 4. 在entry的machineOptions列表中找到对应的machineOption
MachineOption targetMachineOption = null;
for (MachineOption machineOption : targetEntry.getMachineOptions()) {
if (machineOption.getMachineId().equals(machineId)) {
targetMachineOption = machineOption;
break;
}
}
// 5. 只更新传入的字段,保留原有字段值
updateMachineOptionFields(targetMachineOption, data);
// 6. 调用editMachine方法
planResultService.editMachine(chromosome, sceneId, targetEntry);
// 7. 保存更新后的Chromosome
boolean saved = sceneService.saveChromosomeToFile(chromosome, sceneId);
return R.ok("更新成功");
}
/**
* 只更新MachineOption的传入字段,保留原有字段值
*/
private void updateMachineOptionFields(MachineOption machineOption, Map<String, Object> data) {
// 处理runtime字段
if (data.containsKey("runtime")) {
Object runtimeObj = data.get("runtime");
if (runtimeObj instanceof Integer) {
machineOption.setRuntime(new BigDecimal((Integer) runtimeObj));
} else if (runtimeObj instanceof Long) {
machineOption.setRuntime(new BigDecimal((Long) runtimeObj));
} else if (runtimeObj instanceof Double) {
machineOption.setRuntime(new BigDecimal((Double) runtimeObj));
} else if (runtimeObj instanceof String) {
machineOption.setRuntime(new BigDecimal((String) runtimeObj));
}
}
// 处理singleOut字段
if (data.containsKey("singleOut")) {
Object singleOutObj = data.get("singleOut");
if (singleOutObj instanceof Integer) {
machineOption.setSingleOut(new BigDecimal((Integer) singleOutObj));
} else if (singleOutObj instanceof Long) {
machineOption.setSingleOut(new BigDecimal((Long) singleOutObj));
} else if (singleOutObj instanceof Double) {
machineOption.setSingleOut(new BigDecimal((Double) singleOutObj));
} else if (singleOutObj instanceof String) {
machineOption.setSingleOut(new BigDecimal((String) singleOutObj));
}
}
// 处理preTime字段
if (data.containsKey("preTime")) {
Object preTimeObj = data.get("preTime");
if (preTimeObj instanceof Integer) {
machineOption.setPreTime((Integer) preTimeObj);
} else if (preTimeObj instanceof Long) {
machineOption.setPreTime(((Long) preTimeObj).intValue());
} else if (preTimeObj instanceof String) {
machineOption.setPreTime(Integer.parseInt((String) preTimeObj));
}
}
// 处理processingTime字段 - 修改为:时间(runtime) ÷ 数量(singleOut)
if (data.containsKey("processingTime") || data.containsKey("singleOut") || data.containsKey("runtime")) {
// 1. 获取singleOut值
BigDecimal singleOut = machineOption.getSingleOut();
if (data.containsKey("singleOut")) {
Object singleOutObj = data.get("singleOut");
if (singleOutObj instanceof Integer) {
singleOut = new BigDecimal((Integer) singleOutObj);
} else if (singleOutObj instanceof Long) {
singleOut = new BigDecimal((Long) singleOutObj);
} else if (singleOutObj instanceof Double) {
singleOut = new BigDecimal((Double) singleOutObj);
} else if (singleOutObj instanceof String) {
singleOut = new BigDecimal((String) singleOutObj);
} else if (singleOutObj instanceof BigDecimal) {
singleOut = (BigDecimal) singleOutObj;
}
}
// 2. 获取runtime值
BigDecimal runtime = machineOption.getRuntime();
if (data.containsKey("runtime")) {
Object runtimeObj = data.get("runtime");
if (runtimeObj instanceof Integer) {
runtime = new BigDecimal((Integer) runtimeObj);
} else if (runtimeObj instanceof Long) {
runtime = new BigDecimal((Long) runtimeObj);
} else if (runtimeObj instanceof Double) {
runtime = new BigDecimal((Double) runtimeObj);
} else if (runtimeObj instanceof String) {
runtime = new BigDecimal((String) runtimeObj);
} else if (runtimeObj instanceof BigDecimal) {
runtime = (BigDecimal) runtimeObj;
}
}
// 3. 计算processingTime = runtime ÷ singleOut(时间 ÷ 数量)
double processingTime = 0.0;
if (singleOut != null && runtime != null && runtime.compareTo(BigDecimal.ZERO) != 0) {
// 考虑runtime单位转换:如果runtime是毫秒,转换为秒
BigDecimal runtimeSeconds = runtime.divide(new BigDecimal(1000), 6, RoundingMode.HALF_UP);
// 关键修改:时间(秒) ÷ 数量,保留2位小数
processingTime = runtimeSeconds.divide(singleOut, 2, RoundingMode.HALF_UP).doubleValue();
}
// 4. 设置计算后的processingTime
machineOption.setProcessingTime(processingTime);
}
// //
...@@ -373,7 +231,7 @@ public class ChromosomeDataController { ...@@ -373,7 +231,7 @@ public class ChromosomeDataController {
// } // }
// 忽略id等未知字段 // 忽略id等未知字段
}
private boolean updateMachineOptionsForEntry(Entry targetEntry, List<?> machineOptions, ObjectMapper objectMapper) { private boolean updateMachineOptionsForEntry(Entry targetEntry, List<?> machineOptions, ObjectMapper objectMapper) {
......
...@@ -473,7 +473,11 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -473,7 +473,11 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
public void UnlockStartTime(String sceneId, int opId) {
Chromosome chromosome = _sceneService.loadChromosomeFromFile(sceneId);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperation.UnlockStartTime(chromosome, opId);
}
/** /**
......
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