订单修改

parent 4148b970
......@@ -36,7 +36,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleIllegalArgumentException(IllegalArgumentException e) {
log.debug("参数校验失败: {}", e.getMessage());
log.error("参数校验失败:", e);
return R.failed(500, e.getMessage());
}
......@@ -46,7 +46,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(SceneGenerationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleSceneGenerationException(SceneGenerationException e) {
log.debug("场景生成异常: {}", e.getMessage());
log.error("场景生成异常:", e);
return R.failed(500, e.getMessage());
}
......@@ -56,7 +56,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleRuntimeException(RuntimeException e) {
log.debug("运行时异常: {}", e.getMessage());
log.error("运行时异常:", e);
return R.failed(500, e.getMessage());
}
......@@ -66,7 +66,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BindingException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleBindingException(BindingException e) {
log.debug("MyBatis绑定异常: {}", e.getMessage());
log.error("MyBatis绑定异常:", e);
return R.failed(500, "数据绑定异常: " + e.getMessage());
}
......@@ -76,7 +76,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MyBatisSystemException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleMyBatisSystemException(MyBatisSystemException e) {
log.debug("MyBatis系统异常: {}", e.getMessage());
log.error("MyBatis系统异常:", e);
Throwable cause = e.getCause();
if (cause != null && cause.getMessage().contains("ORA-17004")) {
return R.failed(500, "数据库列类型无效,请检查查询参数是否正确");
......@@ -90,7 +90,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(SQLException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleSQLException(SQLException e) {
log.debug("SQL异常: {}", e.getMessage());
log.error("SQL异常:", e);
return R.failed(500, "数据库访问异常: " + e.getMessage());
}
......@@ -100,7 +100,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(DataAccessException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleDataAccessException(DataAccessException e) {
log.debug("数据访问异常: {}", e.getMessage());
log.error("数据访问异常:", e);
return R.failed(500, "数据访问异常: " + e.getMessage());
}
......@@ -110,7 +110,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
log.debug("参数验证异常: {}", e.getMessage());
log.error("参数验证异常:", e);
FieldError fieldError = e.getBindingResult().getFieldError();
if (fieldError != null) {
return R.failed(400, Objects.requireNonNull(fieldError.getDefaultMessage()));
......@@ -124,7 +124,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleBindException(BindException e) {
log.debug("参数绑定异常: {}", e.getMessage());
log.error("参数绑定异常:", e);
FieldError fieldError = e.getBindingResult().getFieldError();
if (fieldError != null) {
return R.failed(500, Objects.requireNonNull(fieldError.getDefaultMessage()));
......@@ -138,7 +138,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
log.debug("请求参数缺失: {}", e.getMessage());
log.error("请求参数缺失:", e);
return R.failed(500, "缺少必要参数: " + e.getParameterName());
}
......@@ -148,7 +148,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) {
log.debug("参数类型不匹配: {}", e.getMessage());
log.error("参数类型不匹配:", e);
return R.failed(500, "参数类型不匹配: " + e.getName());
}
......@@ -158,7 +158,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
log.debug("HTTP消息不可读: {}", e.getMessage());
log.error("HTTP消息不可读:", e);
return R.failed(500, "请求体格式错误");
}
......@@ -168,7 +168,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public R<Void> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
log.debug("HTTP请求方法不支持: {}", e.getMessage());
log.error("HTTP请求方法不支持:", e);
return R.failed(405, "请求方法不支持: " + e.getMethod());
}
......@@ -178,7 +178,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
public R<Void> handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) {
log.debug("HTTP媒体类型不支持: {}", e.getMessage());
log.error("HTTP媒体类型不支持:", e);
return R.failed(415, "媒体类型不支持: " + e.getContentType());
}
......@@ -188,7 +188,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public R<Void> handleNoHandlerFoundException(NoHandlerFoundException e) {
log.debug("404异常: {}", e.getMessage());
log.error("404异常:", e);
return R.failed(404, "请求的资源不存在: " + e.getRequestURL());
}
......@@ -198,7 +198,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleException(Exception e) {
log.debug("未知异常: {}", e.getMessage());
log.error("未知异常:", e);
return R.failed(500, "系统异常,请联系管理员");
}
}
\ No newline at end of file
......@@ -167,14 +167,14 @@ public class SwaggerMapParamConfig {
));
break;
case "operationedit":
case "operationEdit":
properties.put("sceneId", new StringSchema().description("场景ID").example("B571EF6682DB463AB2977B1055A74112"));
properties.put("operation", new StringSchema().description("操作对象"));
properties.put("entry", new StringSchema().description("操作对象"));
examples.put("编辑操作示例", createExample(
"编辑指定的操作",
"{\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"operation\": {}\n" +
" \"entry\": {}\n" +
"}"
));
break;
......
package com.aps.controller.gantt;
import cn.hutool.core.bean.BeanUtil;
import com.aps.common.util.NumberUtils;
import com.aps.common.util.ParamValidator;
import com.aps.common.util.R;
......@@ -146,11 +147,31 @@ public class ResourceGanttController {
}
@GetMapping("/SyncMachines")
@Operation(summary = "更新设备信息缓存", description = "更新设备信息缓存")
public void SyncMachines() {
// 调用 PlanResultService 获取 ScheduleChromosome 列表
planResultService.InitCalendarToAllMachines();
@PostMapping("/editOrder")
@Operation(summary = "修改订单", description = "编辑场景中的订单信息",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "编辑订单参数",
content = @io.swagger.v3.oas.annotations.media.Content(
mediaType = "application/json",
examples = @io.swagger.v3.oas.annotations.media.ExampleObject(
name = "编辑订单示例",
value = "{\n \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n \"order\": { }\n}"
)
)
)
)
public R<Chromosome> editOrder(@RequestBody Map<String, Object> params) {
log.info("editOrder 请求参数: {}", params);
String sceneId = ParamValidator.getString(params, "sceneId", "场景ID");
ParamValidator.validateSceneExists(sceneService, sceneId);
// 使用BeanUtil转换LinkedHashMap为Order对象
Order order = BeanUtil.toBean(params.get("order"), Order.class);
Chromosome result = planResultService.EditOrder(sceneId, order);
return R.ok(result);
}
......@@ -231,17 +252,16 @@ public class ResourceGanttController {
@PostMapping("/operationedit")
@PostMapping("/operationEdit")
@Operation(summary = "修改工单", description = "修改工单")
public R<Chromosome> operationedit(@RequestBody Map<String, Object> params) {
log.info("operationedit 请求参数: {}", params);
public R<Chromosome> operationEdit(@RequestBody Map<String, Object> params) {
log.info("operationEdit 请求参数: {}", params);
String sceneId = ParamValidator.getString(params, "sceneId", "场景ID");
ParamValidator.validateSceneExists(sceneService, sceneId);
// 处理Entry对象
Entry entry = (Entry) params.get("operation");
// 使用BeanUtil转换LinkedHashMap为Entry对象
Entry entry = BeanUtil.toBean(params.get("entry"), Entry.class);
Chromosome result = planResultService.EditOperation(sceneId, entry);
return R.ok(result);
......
......@@ -140,4 +140,7 @@ public class Entry {
private BigDecimal runtime;//持续时间
private BigDecimal singleOut;//单件产出
private double changeLineTime;//换模时间
private BigDecimal setupTime;
private int constTime;
}
......@@ -141,10 +141,13 @@ public class KpiCalculator {
*/
private void calculateMachine() {
// 按设备ID分组工序列表(对应C# GroupBy + ToList)
// 按设备ID分组工序列表(对应C# GroupBy + ToList)- Java 8兼容方式,处理null键
List<GAScheduleResult> list= chromosome.getResult() ;
Map<Long, List<GAScheduleResult>> machineTasks = list.stream()
.collect(Collectors.groupingBy(GAScheduleResult::getMachineId));
Map<Long, List<GAScheduleResult>> machineTasks = new HashMap<>();
list.forEach(result -> {
Long machineId = result.getMachineId();
machineTasks.computeIfAbsent(machineId, k -> new ArrayList<>()).add(result);
});
// 计划工作时间:最后一个任务结束时间 - 第一个任务开始时间
int firstTaskStart = list.stream()
......@@ -202,9 +205,12 @@ public class KpiCalculator {
*/
private void calculateOrder() {
List<GAScheduleResult> list= chromosome.getResult();
// 按GroupId(订单ID)分组 - 对应C#的GroupBy
Map<String, List<GAScheduleResult>> orderGroups = list.stream()
.collect(Collectors.groupingBy(GAScheduleResult::getOrderId));
// 按GroupId(订单ID)分组 - Java 8兼容方式,处理null键
Map<String, List<GAScheduleResult>> orderGroups = new HashMap<>();
list.forEach(result -> {
String orderId = result.getOrderId();
orderGroups.computeIfAbsent(orderId, k -> new ArrayList<>()).add(result);
});
for (Map.Entry<String, List<GAScheduleResult>> entry : orderGroups.entrySet()) {
String orderId = entry.getKey();
......
......@@ -65,7 +65,7 @@ public class MachineCalculator {
Machine machine, int processingTime, LocalDateTime currentTime,
String prevtime, List<GAScheduleResult> existingTasks,double oneTime,double quantity, boolean checkprevtime, boolean islockMachineTime
,boolean isInterrupt) {
List<GAScheduleResult> machineTasks = existingTasks.stream()
List<GAScheduleResult> machineTasks = new ArrayList<>(existingTasks).stream()
.filter(t -> t.getMachineId() == machine.getId())
.sorted(Comparator.comparingInt(GAScheduleResult::getStartTime))
.collect(Collectors.toList());
......@@ -307,7 +307,7 @@ public class MachineCalculator {
LocalDateTime current = start;
// 预先排序设备可用片段,避免后续遍历混乱
List<TimeSegment> allUseTimeSegment = machine.getAvailability().stream()
List<TimeSegment> allUseTimeSegment = new ArrayList<>(machine.getAvailability()).stream()
.filter(slot -> !slot.isUsed() && slot.getType() != SegmentType.MAINTENANCE)
.sorted(Comparator.comparing(TimeSegment::getStart, (a, b) -> a.compareTo(b)))
.collect(Collectors.toList());
......@@ -627,7 +627,7 @@ public class MachineCalculator {
// 2. 已有任务冲突
if (machineTasks != null && machineTasks.size()>0) {
// 第一步:转换任务为TimeSegment并过滤重叠冲突
List<TimeSegment> taskConflicts = machineTasks.stream()
List<TimeSegment> taskConflicts = new ArrayList<>(machineTasks).stream()
.map(w -> {
// 计算任务起始和结束时间:baseTime.AddMinutes(w.StartTime)/w.EndTime
LocalDateTime taskStart = baseTime.plusSeconds(w.getStartTime());
......@@ -664,10 +664,10 @@ public class MachineCalculator {
double requiredMinutes) {
// 遍历所有冲突片段
for (TimeSegment conflict : conflictSegments) {
for (TimeSegment conflict : new ArrayList<>(conflictSegments)) {
LocalDateTime currentTime1=currentTime;
// 过滤冲突前的可用片段(
List<TimeSegment> preConflictSegments = useSegments.stream()
List<TimeSegment> preConflictSegments = new ArrayList<>(useSegments).stream()
.filter(slot ->
(slot.getStart().compareTo(currentTime1) >= 0 || slot.getEnd().compareTo(currentTime1) > 0)
&& slot.getEnd().compareTo(conflict.getStart()) <= 0
......@@ -712,7 +712,7 @@ public class MachineCalculator {
private boolean CheckTask(Machine machine,List<GAScheduleResult> machineTasks,LocalDateTime prevEnd,LocalDateTime shiftStart) {
LocalDateTime finalPrevEnd = prevEnd;
boolean hasTask = machineTasks.stream()
boolean hasTask = new ArrayList<>(machineTasks).stream()
.anyMatch(t -> {
LocalDateTime taskStart = baseTime.plusSeconds(t.getStartTime());
return taskStart.isAfter(finalPrevEnd) && taskStart.isBefore(shiftStart);
......@@ -721,7 +721,7 @@ public class MachineCalculator {
// 检查班次间维修窗口
if (machine.getMaintenanceWindows() != null) {
LocalDateTime finalPrevEnd1 = prevEnd;
boolean hasMaintenance = machine.getMaintenanceWindows().stream()
boolean hasMaintenance = new ArrayList<>(machine.getMaintenanceWindows()).stream()
.anyMatch(w -> w.getStartTime().isAfter(finalPrevEnd1) && w.getStartTime().isBefore(shiftStart));
return hasMaintenance;
......@@ -785,7 +785,7 @@ public class MachineCalculator {
LocalDateTime currentTime, LocalDateTime startTime,
List<GAScheduleResult> existingTasks) {
// 获取设备上已有任务并按开始时间排序
List<GAScheduleResult> machineTasks = existingTasks.stream()
List<GAScheduleResult> machineTasks = new ArrayList<>(existingTasks).stream()
.filter(t -> t.getMachineId() == machine.getId())
.sorted(Comparator.comparing(GAScheduleResult::getStartTime))
.collect(Collectors.toList());
......
......@@ -179,9 +179,12 @@ public class OrderSortService {
return;
}
// 1. 按当前条件分组
Map<Object, List<Order>> groups = orders.stream()
.collect(Collectors.groupingBy(keyExtractor));
// 1. 按当前条件分组 处理null键
Map<Object, List<Order>> groups = new HashMap<>();
orders.forEach(order -> {
Object key = keyExtractor.apply(order);
groups.computeIfAbsent(key, k -> new ArrayList<>()).add(order);
});
// 2. 对分组键排序(关键:按条件配置的方向排序)
List<Object> sortedKeys = getSortedKeys(groups, currentCondition);
......
......@@ -213,6 +213,8 @@ public class RoutingDataService {
entry.setEquipTypeCode(op.getEquipTypeCode());
entry.setRuntime(op.getRuntime());
entry.setSingleOut(op.getSingleOut());
entry.setSetupTime(op.getSetupTime());
entry.setConstTime(op.getConstTime());
entry.setOrderId(op.getOrderId());
entry.setOrderCode(op.getOrderCode());
entry.setQuantity(op.getPlanQty());
......
......@@ -388,31 +388,93 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
public Chromosome EditOperation(String SceneId,Entry operation) {
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
public Chromosome EditOperation(String SceneId, Entry operation) {
Chromosome chromosome = _sceneService.loadChromosomeFromFile(SceneId);
if (chromosome == null || chromosome.getAllOperations() == null) {
return chromosome; // 直接返回,空值由上层处理
return chromosome;
}
List<Entry> operations = chromosome.getAllOperations();
// 直接查找匹配元素的索引(避免先找元素再查索引的冗余)
int position = IntStream.range(0, operations.size())
.filter(i -> {
Entry t = operations.get(i);
return t.getId()==operation.getId();
})
.filter(i -> operations.get(i).getId() == operation.getId())
.findFirst()
.orElse(-1);
// 索引有效时替换
if (position != -1) {
operations.set(position, operation);
Entry oldEntry = operations.set(position, operation);
List<GlobalOperationInfo> globalOpList = chromosome.getGlobalOpList();
if (globalOpList != null) {
globalOpList.stream()
.filter(opInfo -> opInfo.getOp() == oldEntry)
.forEach(opInfo -> opInfo.setOp(operation));
}
}
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
GlobalParam globalParam=new GlobalParam();
ScheduleOperation.redecode(chromosome,chromosome.getBaseTime(), globalParam);
return chromosome;
return redecodeChromosome(chromosome);
}
public Chromosome EditOrder(String SceneId, Order order) {
Chromosome chromosome = _sceneService.loadChromosomeFromFile(SceneId);
if (chromosome == null || chromosome.getOrders() == null) {
return chromosome;
}
List<Order> orders = chromosome.getOrders();
int position = IntStream.range(0, orders.size())
.filter(i -> orders.get(i).getId() == order.getId())
.findFirst()
.orElse(-1);
if (position != -1) {
orders.set(position, order);
}
orderSortService.initializeFieldExtractors();
OrderSortRule rule = createMultiConditionRule(orders);
orderSortService.assignPriority(orders, rule);
updateOrderRelatedEntries(chromosome, order);
return redecodeChromosome(chromosome);
}
/**
* 更新订单相关的所有Entry的数量和优先级
*/
private void updateOrderRelatedEntries(Chromosome chromosome, Order order) {
// 更新所有操作中的Entry
List<Entry> allOperations = chromosome.getAllOperations();
if (allOperations != null) {
allOperations.stream()
.filter(entry -> entry.getOrderId() != null && entry.getOrderId().equals(order.getOrderId()))
.forEach(entry -> {
entry.setQuantity(order.getQuantity());
entry.setPriority(order.getActualPriority());
});
}
// 更新GlobalOperationInfo中的Entry
List<GlobalOperationInfo> globalOpList = chromosome.getGlobalOpList();
if (globalOpList != null) {
globalOpList.stream()
.map(GlobalOperationInfo::getOp)
.filter(entry -> entry != null && entry.getOrderId() != null && entry.getOrderId().equals(order.getOrderId()))
.forEach(entry -> {
entry.setQuantity(order.getQuantity());
entry.setPriority(order.getActualPriority());
});
}
}
/**
* 重新解码染色体
*/
private Chromosome redecodeChromosome(Chromosome chromosome) {
GlobalParam globalParam = new GlobalParam();
ScheduleOperationService scheduleOperation = new ScheduleOperationService();
scheduleOperation.redecode(chromosome, chromosome.getBaseTime(), globalParam);
return chromosome;
}
public Chromosome ChangeBaseTime(String SceneId,LocalDateTime BaseTime) {
......
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