refactor: 统一业务异常处理,标准化结果码和错误响应

1.  新增并完善ResultCode枚举,补充标准HTTP状态码对应的业务状态码
2.  重构BusinessException,新增基于ResultCode的构造函数和ThrowIf扩展方法
3.  替换所有硬编码的HTTP状态码为统一的ResultCode枚举
4.  优化全局异常中间件,根据业务状态码映射对应HTTP状态码并规范化JSON响应
5.  修复OssImageHelper和AutoDotCodeConsumer中的OSS文件处理逻辑
6.  新增用户答题快照实体类
7.  清理废弃的宠物模块迁移脚本
This commit is contained in:
glz
2026-06-29 16:34:26 +08:00
parent 4579fefef9
commit bdaa6a0dc8
35 changed files with 693 additions and 364 deletions

View File

@ -116,13 +116,13 @@ public class WeChatCommunityService(
if (input.MessageId <= 0)
{
throw new BusinessException("消息ID无效", 400);
throw new BusinessException("消息ID无效", ResultCode.BAD_REQUEST);
}
var message = await messageRepository.GetByIdAsync(input.MessageId);
if (message == null)
{
throw new BusinessException("消息不存在", 404);
throw new BusinessException("消息不存在", ResultCode.NOT_FOUND);
}
// 检查是否已点赞
@ -132,7 +132,7 @@ public class WeChatCommunityService(
if (existingLike != null)
{
throw new BusinessException("您已点赞过该消息", 400);
throw new BusinessException("您已点赞过该消息", ResultCode.BAD_REQUEST);
}
// 插入点赞记录
@ -151,7 +151,7 @@ public class WeChatCommunityService(
var insertResult = await Context.Insertable(like).ExecuteCommandAsync();
if (insertResult <= 0)
{
throw new BusinessException("点赞失败", 500);
throw new BusinessException("点赞失败", ResultCode.GLOBAL_ERROR);
}
// 更新点赞数
@ -183,13 +183,13 @@ public class WeChatCommunityService(
if (messageId <= 0)
{
throw new BusinessException("消息ID无效", 400);
throw new BusinessException("消息ID无效", ResultCode.BAD_REQUEST);
}
var message = await messageRepository.GetByIdAsync(messageId);
if (message == null)
{
throw new BusinessException("消息不存在", 404);
throw new BusinessException("消息不存在", ResultCode.NOT_FOUND);
}
var existingLike = await Context.Queryable<CommunityMessageLike>()
@ -198,7 +198,7 @@ public class WeChatCommunityService(
if (existingLike == null)
{
throw new BusinessException("您尚未点赞过该消息", 400);
throw new BusinessException("您尚未点赞过该消息", ResultCode.BAD_REQUEST);
}
// 软删除点赞记录