返回信息修改

parent 06001699
package com.aps.common.exception;
import com.aps.common.util.ExceptionMessageUtil;
import com.aps.common.util.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.BindingException;
......@@ -37,7 +38,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleIllegalArgumentException(IllegalArgumentException e) {
log.error("参数校验失败:", e);
return R.failed(500, e.getMessage());
return R.failed(500, ExceptionMessageUtil.cleanMessage(e.getMessage(), "参数校验失败"));
}
/**
......@@ -47,7 +48,17 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleSceneGenerationException(SceneGenerationException e) {
log.error("场景生成异常:", e);
return R.failed(500, e.getMessage());
return R.failed(500, ExceptionMessageUtil.cleanMessage(e.getMessage(), "场景生成失败,请检查场景数据后重试"));
}
/**
* 处理业务异常
*/
@ExceptionHandler(BusinessException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R<Void> handleBusinessException(BusinessException e) {
log.error("业务异常:", e);
return R.failed(500, ExceptionMessageUtil.cleanMessage(e.getMessage(), "业务处理失败,请稍后重试"));
}
/**
......@@ -57,7 +68,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleRuntimeException(RuntimeException e) {
log.error("运行时异常:", e);
return R.failed(500, e.getMessage());
return R.failed(500, ExceptionMessageUtil.toClientMessage(e, "系统处理失败,请稍后重试或联系管理员"));
}
/**
......@@ -67,7 +78,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleBindingException(BindingException e) {
log.error("MyBatis绑定异常:", e);
return R.failed(500, "数据绑定异常: " + e.getMessage());
return R.failed(500, "数据绑定异常,请联系管理员");
}
/**
......@@ -81,7 +92,7 @@ public class GlobalExceptionHandler {
if (cause != null && cause.getMessage().contains("ORA-17004")) {
return R.failed(500, "数据库列类型无效,请检查查询参数是否正确");
}
return R.failed(500, "数据库操作异常: " + (cause != null ? cause.getMessage() : e.getMessage()));
return R.failed(500, "数据库操作异常,请联系管理员");
}
/**
......@@ -91,7 +102,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleSQLException(SQLException e) {
log.error("SQL异常:", e);
return R.failed(500, "数据库访问异常: " + e.getMessage());
return R.failed(500, "数据库访问异常,请联系管理员");
}
/**
......@@ -101,7 +112,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R<Void> handleDataAccessException(DataAccessException e) {
log.error("数据访问异常:", e);
return R.failed(500, "数据访问异常: " + e.getMessage());
return R.failed(500, "数据访问异常,请联系管理员");
}
/**
......@@ -113,7 +124,8 @@ public class GlobalExceptionHandler {
log.error("参数验证异常:", e);
FieldError fieldError = e.getBindingResult().getFieldError();
if (fieldError != null) {
return R.failed(400, Objects.requireNonNull(fieldError.getDefaultMessage()));
return R.failed(400, ExceptionMessageUtil.cleanMessage(
Objects.requireNonNull(fieldError.getDefaultMessage()), "参数验证失败"));
}
return R.failed(400, "参数验证失败");
}
......@@ -127,7 +139,8 @@ public class GlobalExceptionHandler {
log.error("参数绑定异常:", e);
FieldError fieldError = e.getBindingResult().getFieldError();
if (fieldError != null) {
return R.failed(500, Objects.requireNonNull(fieldError.getDefaultMessage()));
return R.failed(500, ExceptionMessageUtil.cleanMessage(
Objects.requireNonNull(fieldError.getDefaultMessage()), "参数绑定失败"));
}
return R.failed(500, "参数绑定失败");
}
......
......@@ -95,7 +95,7 @@ public class R<T> implements Serializable {
public R(Throwable e) {
super();
this.msg = e.getMessage();
this.msg = ExceptionMessageUtil.toClientMessage(e, "系统异常,请联系管理员");
this.code = 500;
}
......
package com.aps.controller;
import com.aps.common.util.R;
import com.aps.common.util.ExceptionMessageUtil;
import com.aps.entity.Algorithm.Chromosome;
import com.aps.entity.ProdSceneConfig;
import com.aps.service.LanuchService;
......@@ -72,6 +73,9 @@ public class LanuchController {
@Operation(summary = "运算")
public R<String> schedule(@RequestBody Map<String, String> params) {
String sceneId = params.get("sceneId");
if (sceneId == null || sceneId.trim().isEmpty()) {
throw new IllegalArgumentException("场景ID不能为空");
}
// 如果需要处理时间字段,可以从params中获取并转换
// 例如:开始时间、结束时间等
......@@ -82,7 +86,7 @@ public class LanuchController {
// 根据不同格式解析时间字符串
Chromosome scheduleChromosomes = planResultService.execute2(sceneId);
return R.ok("运算完成");
return R.ok("排产计算成功", "排产计算成功");
}
/**
......@@ -151,7 +155,8 @@ public class LanuchController {
}
} catch (Exception e) {
hasDeletionFailure = true;
failureMessage += "场景ID " + scene.getSceneId() + " 删除异常: " + e.getMessage() + "; ";
failureMessage += "场景ID " + scene.getSceneId() + " 删除异常: "
+ ExceptionMessageUtil.toClientMessage(e, "删除场景失败") + "; ";
}
}
......
package com.aps.controller;
import com.aps.common.exception.BusinessException;
import com.aps.entity.*;
import com.aps.mapper.EquipinfoMapper;
import com.aps.mapper.MpsplannedorderMapper;
......@@ -114,7 +115,7 @@ public class ScheduleController {
orders, processes, operations, operationEquipments, equipments);
return result;
} catch (Exception e) {
throw new RuntimeException("调度执行失败: " + e.getMessage(), e);
throw new BusinessException("调度执行失败,请检查调度数据后重试", e);
}
}
}
......@@ -146,7 +146,7 @@ public class ScheduleResultController {
return R.ok(ganttVO);
} catch (Exception e) {
return R.failed("调度执行失败: " + e.getMessage());
return R.failed("调度执行失败,请检查调度数据后重试");
}
}
}
package com.aps.service.impl;
import com.aps.common.exception.BusinessException;
import com.aps.common.exception.SceneGenerationException;
import com.aps.common.util.GlobalCacheUtil;
import com.aps.common.util.R;
......@@ -116,7 +117,7 @@ public class LanuchServiceImpl implements LanuchService {
// 1. 创建场景
ProdSceneConfig sceneConfig = createScene(sceneName, username);
if (sceneConfig == null) {
throw new RuntimeException("场景名称已存在");
throw new BusinessException("场景名称已存在");
}
sceneId = sceneConfig.getSceneId();
......@@ -171,7 +172,7 @@ public class LanuchServiceImpl implements LanuchService {
generateProcessRelationsBatch(prodLaunchOrders, sceneId);
log.info("场景数据生成完成,场景ID:{}", sceneId);
return R.ok(sceneConfig);
return R.ok(sceneConfig, "场景新建成功");
}
......@@ -191,7 +192,7 @@ public class LanuchServiceImpl implements LanuchService {
}
if (newSceneName == null || newSceneName.trim().isEmpty()) {
throw new IllegalArgumentException("复制场景ID不能为空");
throw new IllegalArgumentException("新场景名称不能为空");
}
if (username == null || username.trim().isEmpty()) {
......@@ -204,12 +205,12 @@ public class LanuchServiceImpl implements LanuchService {
.one();
if (oldScene == null) {
throw new RuntimeException("源场景不存在");
throw new BusinessException("源场景不存在");
}
// 创建场景
ProdSceneConfig newSceneConfig = createScene(newSceneName, username);
if (newSceneConfig == null) {
throw new RuntimeException("场景名称已存在");
throw new BusinessException("场景名称已存在");
}
String newSceneId = newSceneConfig.getSceneId();
......@@ -223,7 +224,7 @@ public class LanuchServiceImpl implements LanuchService {
// 复制染色体文件(排产结果)
copyChromosomeFile(oldScene.getSceneId(), newSceneId);
return R.ok(newSceneConfig);
return R.ok(newSceneConfig, "场景复制成功");
}
/**
......@@ -1939,6 +1940,7 @@ public class LanuchServiceImpl implements LanuchService {
log.info("成功复制染色体文件,从场景 {} 到场景 {}", oldSceneId, newSceneId);
} else {
log.warn("复制染色体文件失败,从场景 {} 到场景 {}", oldSceneId, newSceneId);
throw new BusinessException("场景复制失败:排产结果复制失败,请稍后重试");
}
}
} else {
......@@ -1946,8 +1948,7 @@ public class LanuchServiceImpl implements LanuchService {
}
} catch (Exception e) {
log.error("复制染色体文件时发生异常,从场景 {} 到场景 {}", oldSceneId, newSceneId, e);
// 重新抛出异常,让全局异常处理器处理
throw e;
throw new BusinessException("场景复制失败:排产结果复制失败,请稍后重试", e);
}
}
......
package com.aps.service.plan;
import com.aps.common.exception.BusinessException;
import com.aps.common.util.*;
import com.aps.common.util.redis.RedisUtils;
import com.aps.controller.gantt.FileUploadController;
......@@ -258,14 +259,19 @@ public class PlanResultService {
// 这里会从 Dispatch 表加载锁定期工单,并添加到 chromosome.result 中
lockedOrderProcessorService.addLockedOrdersToResult(chromosome);
_sceneService.saveChromosomeToFile(chromosome, SceneId);
boolean saved = _sceneService.saveChromosomeToFile(chromosome, SceneId);
if (!saved) {
throw new BusinessException("排产计算结果保存失败,请稍后重试或联系管理员");
}
WriteScheduleSummary(chromosome);
return chromosome;
} catch (BusinessException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("调度执行失败:"+e.getMessage(), e);
throw new BusinessException("排产计算失败,请检查场景数据后重试", e);
}
}
......@@ -1865,14 +1871,19 @@ public class PlanResultService {
chromosomes.setBaseTime(param.getBaseTime());
// chromosomes.setOperatRel(new CopyOnWriteArrayList<>(entryRel));
// 保存chromosomes到文件
_sceneService.saveChromosomeToFile(chromosomes, SceneId);
boolean saved = _sceneService.saveChromosomeToFile(chromosomes, SceneId);
if (!saved) {
throw new BusinessException("排产计算结果保存失败,请稍后重试或联系管理员");
}
// Chromosomes.forEach(this::WriteScheduleSummary);
FileHelper.writeLogFile("schedule-----------结束-----------"+SceneId);
return chromosomes;
} catch (BusinessException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("调度执行失败", e);
throw new BusinessException("排产计算失败,请检查场景数据后重试", e);
}
}
......
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