refactor: 重构用户与商品模块,统一业务模型与服务
1. 新增用户状态枚举UserStatusEnum,统一用户状态定义 2. 重构用户体系:合并WxUser与User实体为Users实体,统一用户管理 3. 新增微信小程序认证相关服务与控制器,实现一键登录功能 4. 新增商品管理完整服务与控制器,修复商品表字段映射问题 5. 删除冗余的WxUser相关服务与控制器代码 6. 新增Newtonsoft.Json依赖用于微信接口响应解析 7. 清理无用的文件夹引用配置
This commit is contained in:
151
QYZH.InteractiveMagazine.WebApi/Controllers/ProductController.cs
Normal file
151
QYZH.InteractiveMagazine.WebApi/Controllers/ProductController.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 商品管理控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
||||
public class ProductController : BaseController
|
||||
{
|
||||
private readonly IProductService _productService;
|
||||
private readonly ILogger<ProductController> _logger;
|
||||
|
||||
public ProductController(IProductService productService, ILogger<ProductController> logger)
|
||||
{
|
||||
_productService = productService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建商品
|
||||
/// </summary>
|
||||
/// <param name="input">商品信息</param>
|
||||
/// <returns>创建的商品信息</returns>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<ProductOutput>> CreateAsync([FromBody] ProductInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _productService.CreateAsync(input);
|
||||
return Success(result, "创建商品成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "创建商品业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<ProductOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "创建商品系统异常,参数:{Input}", input);
|
||||
return BaseResponse<ProductOutput>.Fail("创建商品失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新商品
|
||||
/// </summary>
|
||||
/// <param name="id">商品ID</param>
|
||||
/// <param name="input">商品信息</param>
|
||||
/// <returns>更新后的商品信息</returns>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<BaseResponse<ProductOutput>> UpdateAsync(long id, [FromBody] ProductInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _productService.UpdateAsync(id, input);
|
||||
return Success(result, "更新商品成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "更新商品业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<ProductOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "更新商品系统异常,ID:{Id},参数:{Input}", id, input);
|
||||
return BaseResponse<ProductOutput>.Fail("更新商品失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除商品
|
||||
/// </summary>
|
||||
/// <param name="id">商品ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<BaseResponse<object>> DeleteAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _productService.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>
|
||||
/// 根据ID获取商品
|
||||
/// </summary>
|
||||
/// <param name="id">商品ID</param>
|
||||
/// <returns>商品信息</returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<BaseResponse<ProductOutput>> GetByIdAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _productService.GetByIdAsync(id);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "获取商品业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<ProductOutput>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取商品系统异常,ID:{Id}", id);
|
||||
return BaseResponse<ProductOutput>.Fail("获取商品信息失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询商品列表
|
||||
/// </summary>
|
||||
/// <param name="input">查询条件</param>
|
||||
/// <returns>分页结果</returns>
|
||||
[HttpPost("list")]
|
||||
public async Task<BaseResponse<PageListModel<ProductOutput>>> GetListAsync([FromBody] ProductQueryInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _productService.GetListAsync(input);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "查询商品列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<PageListModel<ProductOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "查询商品列表系统异常,参数:{Input}", input);
|
||||
return BaseResponse<PageListModel<ProductOutput>>.Fail("查询商品列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user