2026-06-02 14:10:43 +08:00
|
|
|
|
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;
|
|
|
|
|
|
|
2026-06-02 17:58:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 微信用户控制器
|
|
|
|
|
|
/// </summary>
|
2026-06-02 14:10:43 +08:00
|
|
|
|
[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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-02 17:58:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建微信用户
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input">创建微信用户输入参数</param>
|
|
|
|
|
|
/// <returns>创建的微信用户输出参数</returns>
|
2026-06-02 14:10:43 +08:00
|
|
|
|
[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);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<WxUserOutput>.Fail(ex.Message);
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "创建微信用户系统异常,参数:{Input}", input);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<WxUserOutput>.Fail("创建微信用户失败,请稍后重试");
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-02 17:58:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新微信用户
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">微信用户ID</param>
|
|
|
|
|
|
/// <param name="input">更新微信用户输入参数</param>
|
|
|
|
|
|
/// <returns>更新的微信用户输出参数</returns>
|
2026-06-02 14:10:43 +08:00
|
|
|
|
[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);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<WxUserOutput>.Fail(ex.Message);
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "更新微信用户系统异常,ID:{Id},参数:{Input}", id, input);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<WxUserOutput>.Fail("更新微信用户失败,请稍后重试");
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-02 17:58:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除微信用户
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">微信用户ID</param>
|
|
|
|
|
|
/// <returns>删除的微信用户输出参数</returns>
|
2026-06-02 14:10:43 +08:00
|
|
|
|
[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);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<object>.Fail(ex.Message);
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "删除微信用户系统异常,ID:{Id}", id);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<object>.Fail("删除微信用户失败,请稍后重试");
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-02 17:58:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取微信用户信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">微信用户ID</param>
|
|
|
|
|
|
/// <returns>微信用户信息输出参数</returns>
|
2026-06-02 14:10:43 +08:00
|
|
|
|
[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);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<WxUserOutput>.Fail(ex.Message);
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "获取微信用户系统异常,ID:{Id}", id);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<WxUserOutput>.Fail("获取微信用户信息失败,请稍后重试");
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-02 17:58:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取微信用户列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input">查询微信用户列表输入参数</param>
|
|
|
|
|
|
/// <returns>微信用户列表输出参数</returns>
|
2026-06-02 14:10:43 +08:00
|
|
|
|
[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);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<PageListModel<WxUserOutput>>.Fail(ex.Message);
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "查询微信用户列表系统异常,参数:{Input}", input);
|
2026-06-02 17:58:10 +08:00
|
|
|
|
return BaseResponse<PageListModel<WxUserOutput>>.Fail("查询微信用户列表失败,请稍后重试");
|
2026-06-02 14:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|