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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|