Files
QYZH.InteractiveMagazine/QYZH.InteractiveMagazine.WebApi/Controllers/WxUserController.cs
glz 0a32754740 refactor: 完成系统基础架构重构与业务逻辑优化
本次提交包含多项核心变更:
1.  **用户体系重构**:将管理员用户状态从字符串改为整型枚举,移除微信用户冗余字段Points和GrowthPoints,新增通用基础实体主键配置
2.  **代码清理**:删除HealthController、WxUserMedal、WxUserBag等废弃文件,移除WeChatDto中冗余查询字段
3.  **响应格式统一**:重构BaseResponse与ResultCode枚举,标准化全局响应格式
4.  **权限与验证优化**:添加JWT认证与开发环境免认证逻辑,新增模型验证过滤器,统一控制器认证配置
5.  **工具与配置更新**:新增dotnet-tools.json配置EF工具,调整Swagger与压缩中间件配置,优化SqlSugar默认值处理逻辑
6.  **业务逻辑简化**:移除AutoMapper映射,改为手动映射DTO以提升性能,修复异常处理与响应返回逻辑
2026-06-02 17:58:10 +08:00

148 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.IService.Dto;
using QYZH.InteractiveMagazine.Models.Common;
using QYZH.InteractiveMagazine.Models.Dto;
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
/// <summary>
/// 微信用户控制器
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class WxUserController : BaseController
{
private readonly IWxUserService _wxUserService;
private readonly ILogger<WxUserController> _logger;
public WxUserController(IWxUserService wxUserService, ILogger<WxUserController> logger)
{
_wxUserService = wxUserService;
_logger = logger;
}
/// <summary>
/// 创建微信用户
/// </summary>
/// <param name="input">创建微信用户输入参数</param>
/// <returns>创建的微信用户输出参数</returns>
[HttpPost("users")]
public async Task<BaseResponse<WxUserOutput>> CreateUserAsync([FromBody] WxUserInput input)
{
try
{
var result = await _wxUserService.CreateAsync(input);
return Success(result, "创建微信用户成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "创建微信用户业务异常: {Message}", ex.Message);
return BaseResponse<WxUserOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "创建微信用户系统异常,参数:{Input}", input);
return BaseResponse<WxUserOutput>.Fail("创建微信用户失败,请稍后重试");
}
}
/// <summary>
/// 更新微信用户
/// </summary>
/// <param name="id">微信用户ID</param>
/// <param name="input">更新微信用户输入参数</param>
/// <returns>更新的微信用户输出参数</returns>
[HttpPut("users/{id}")]
public async Task<BaseResponse<WxUserOutput>> UpdateUserAsync(long id, [FromBody] WxUserInput input)
{
try
{
var result = await _wxUserService.UpdateAsync(id, input);
return Success(result, "更新微信用户成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "更新微信用户业务异常: {Message}", ex.Message);
return BaseResponse<WxUserOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "更新微信用户系统异常ID{Id},参数:{Input}", id, input);
return BaseResponse<WxUserOutput>.Fail("更新微信用户失败,请稍后重试");
}
}
/// <summary>
/// 删除微信用户
/// </summary>
/// <param name="id">微信用户ID</param>
/// <returns>删除的微信用户输出参数</returns>
[HttpDelete("users/{id}")]
public async Task<BaseResponse<object>> DeleteUserAsync(long id)
{
try
{
await _wxUserService.DeleteAsync(id);
return Success(new object(), "删除微信用户成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "删除微信用户业务异常: {Message}", ex.Message);
return BaseResponse<object>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "删除微信用户系统异常ID{Id}", id);
return BaseResponse<object>.Fail("删除微信用户失败,请稍后重试");
}
}
/// <summary>
/// 获取微信用户信息
/// </summary>
/// <param name="id">微信用户ID</param>
/// <returns>微信用户信息输出参数</returns>
[HttpGet("users/{id}")]
public async Task<BaseResponse<WxUserOutput>> GetUserByIdAsync(long id)
{
try
{
var result = await _wxUserService.GetByIdAsync(id);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "获取微信用户业务异常: {Message}", ex.Message);
return BaseResponse<WxUserOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取微信用户系统异常ID{Id}", id);
return BaseResponse<WxUserOutput>.Fail("获取微信用户信息失败,请稍后重试");
}
}
/// <summary>
/// 获取微信用户列表
/// </summary>
/// <param name="input">查询微信用户列表输入参数</param>
/// <returns>微信用户列表输出参数</returns>
[HttpPost("users/list")]
public async Task<BaseResponse<PageListModel<WxUserOutput>>> GetUsersListAsync([FromBody] WxUserQueryInput input)
{
try
{
var result = await _wxUserService.GetListAsync(input);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询微信用户列表业务异常: {Message}", ex.Message);
return BaseResponse<PageListModel<WxUserOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询微信用户列表系统异常,参数:{Input}", input);
return BaseResponse<PageListModel<WxUserOutput>>.Fail("查询微信用户列表失败,请稍后重试");
}
}
}