- 替换原有自定义生命周期接口为通用基础服务体系 - 将所有实体基类替换为带雪花ID的SqlSugarBaseEntity - 迁移DTO到Models项目并统一管理 - 移除冗余的Repository层实现,改用通用基础服务 - 添加Yitter.IdGenerator雪花ID生成支持 - 重构SqlSugar数据库上下文与依赖注入配置 - 新增微信用户、用户勋章、背包等实体与配套服务 - 整理分页查询与结果封装类 - 优化WebApi控制器结构
122 lines
4.3 KiB
C#
122 lines
4.3 KiB
C#
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;
|
||
|
||
[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;
|
||
}
|
||
|
||
[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, ex.Code);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "创建微信用户系统异常,参数:{Input}", input);
|
||
return BaseResponse<WxUserOutput>.Fail("创建微信用户失败,请稍后重试", 500);
|
||
}
|
||
}
|
||
|
||
[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, ex.Code);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "更新微信用户系统异常,ID:{Id},参数:{Input}", id, input);
|
||
return BaseResponse<WxUserOutput>.Fail("更新微信用户失败,请稍后重试", 500);
|
||
}
|
||
}
|
||
|
||
[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, ex.Code);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "删除微信用户系统异常,ID:{Id}", id);
|
||
return BaseResponse<object>.Fail("删除微信用户失败,请稍后重试", 500);
|
||
}
|
||
}
|
||
|
||
[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, ex.Code);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "获取微信用户系统异常,ID:{Id}", id);
|
||
return BaseResponse<WxUserOutput>.Fail("获取微信用户信息失败,请稍后重试", 500);
|
||
}
|
||
}
|
||
|
||
[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, ex.Code);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "查询微信用户列表系统异常,参数:{Input}", input);
|
||
return BaseResponse<PageListModel<WxUserOutput>>.Fail("查询微信用户列表失败,请稍后重试", 500);
|
||
}
|
||
}
|
||
}
|