返回信息修改

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