refactor: 重构状态更新接口,新增商品管理与勋章规则配置
1. 重构用户、宠物模板、勋章、管理员状态更新接口,移除冗余参数改为自动切换状态 2. 重命名宠物背景枚举为宠物皮肤,调整商品状态字段为枚举类型 3. 新增商品上下架状态管理接口与对应逻辑 4. 新增勋章规则配置系统,支持动态加载可用表和字段 5. 优化商品查询与展示逻辑,适配新的状态字段
This commit is contained in:
@ -214,6 +214,31 @@ public class AdminController : BaseController
|
||||
return BaseResponse<PageListModel<AdminUserOutput>>.Fail("查询管理员列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换管理员状态(激活/冻结)
|
||||
/// </summary>
|
||||
/// <param name="id">管理员ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPut("users/{id}/status")]
|
||||
public async Task<BaseResponse<object>> ToggleUserStatusAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _adminUserService.ToggleStatusAsync(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("切换状态失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ChangePasswordInput
|
||||
|
||||
@ -156,22 +156,59 @@ public class MedalController : BaseController
|
||||
/// <param name="status">状态: 0=禁用, 1=启用</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPut("{id}/status")]
|
||||
public async Task<BaseResponse<object>> UpdateStatusAsync(long id, [FromBody] int status)
|
||||
public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _medalService.UpdateStatusAsync(id, status);
|
||||
return Success(new object(), status == 1 ? "启用勋章成功" : "禁用勋章成功");
|
||||
var res = await _medalService.UpdateStatusAsync(id);
|
||||
return Success(res, "更新勋章状态成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "更新勋章状态业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
return BaseResponse<bool>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "更新勋章状态系统异常,ID:{Id},Status:{Status}", id, status);
|
||||
return BaseResponse<object>.Fail("更新勋章状态失败,请稍后重试");
|
||||
_logger.LogError(ex, "更新勋章状态系统异常,ID:{Id}", id);
|
||||
return BaseResponse<bool>.Fail("更新勋章状态失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取规则配置中可用的目标表列表
|
||||
/// </summary>
|
||||
[HttpGet("rule-config/tables")]
|
||||
public async Task<BaseResponse<List<MedalRuleTableOptionOutput>>> GetAvailableTables()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _medalService.GetAvailableTablesAsync();
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取可用目标表列表系统异常");
|
||||
return BaseResponse<List<MedalRuleTableOptionOutput>>.Fail("获取可用目标表列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定表的可用字段列表
|
||||
/// </summary>
|
||||
/// <param name="tableName">表名</param>
|
||||
[HttpGet("rule-config/tables/{tableName}/fields")]
|
||||
public async Task<BaseResponse<List<MedalRuleFieldOptionOutput>>> GetTableFields(string tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _medalService.GetTableFieldsAsync(tableName);
|
||||
return Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取可用字段列表系统异常,表名:{TableName}", tableName);
|
||||
return BaseResponse<List<MedalRuleFieldOptionOutput>>.Fail("获取可用字段列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,11 +145,11 @@ public class PetManageController : BaseController
|
||||
/// 更新宠物模板状态(启用/禁用)
|
||||
/// </summary>
|
||||
[HttpPut("{id}/status")]
|
||||
public async Task<BaseResponse<object>> UpdateTemplateStatusAsync(long id, [FromBody] int status)
|
||||
public async Task<BaseResponse<object>> UpdateTemplateStatusAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _petService.UpdateTemplateStatusAsync(id, status);
|
||||
await _petService.UpdateTemplateStatusAsync(id);
|
||||
return Success(new object(), "更新状态成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
|
||||
@ -148,4 +148,29 @@ public class ProductController : BaseController
|
||||
return BaseResponse<PageListModel<ProductOutput>>.Fail("查询商品列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新商品上架/下架状态
|
||||
/// </summary>
|
||||
/// <param name="id">商品ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPut("{id}/status")]
|
||||
public async Task<BaseResponse<object>> UpdateSaleStatusAsync(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _productService.UpdateSaleStatusAsync(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("更新商品状态失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,9 +45,9 @@ public class UsersController : BaseController
|
||||
/// 更新用户状态
|
||||
/// </summary>
|
||||
[HttpPut("{id}/status")]
|
||||
public async Task<BaseResponse> UpdateStatus(long id, [FromBody] UpdateUserStatusInput input)
|
||||
public async Task<BaseResponse> UpdateStatus(long id)
|
||||
{
|
||||
return await _usersService.UpdateStatusAsync(id, input);
|
||||
return await _usersService.UpdateStatusAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -14,6 +14,7 @@ using QYZH.InteractiveMagazine.Infrastructure.Extensions;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Middleware;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using QYZH.InteractiveMagazine.Models.Enum;
|
||||
using QYZH.InteractiveMagazine.Models.Settings;
|
||||
using QYZH.InteractiveMagazine.Repository;
|
||||
using QYZH.InteractiveMagazine.Repository.Core;
|
||||
using Serilog;
|
||||
@ -25,6 +26,9 @@ using Yitter.IdGenerator;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// 加载勋章规则独立配置文件
|
||||
builder.Configuration.AddJsonFile("medal-rule-config.json", optional: false, reloadOnChange: true);
|
||||
|
||||
// 初始化雪花ID生成器
|
||||
YitIdHelper.SetIdGenerator(new IdGeneratorOptions() { WorkerId = 1 });
|
||||
// autofac注入 允许使用autofac作为DI容器
|
||||
@ -141,6 +145,9 @@ builder.Services.AddInfrastructureServices(builder.Configuration, builder.Enviro
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddScoped(typeof(BaseRepository<>));
|
||||
|
||||
// 注册勋章规则配置
|
||||
builder.Services.Configure<MedalRuleConfigSettings>(builder.Configuration.GetSection("MedalRuleConfig"));
|
||||
|
||||
// 添加CORS
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
|
||||
43
QYZH.InteractiveMagazine.WebApi/medal-rule-config.json
Normal file
43
QYZH.InteractiveMagazine.WebApi/medal-rule-config.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"MedalRuleConfig": {
|
||||
"Tables": [
|
||||
{
|
||||
"TableName": "CheckInRecord",
|
||||
"DisplayName": "签到记录",
|
||||
"Fields": [
|
||||
{ "FieldName": "ContinuousDays", "DisplayName": "连续天数" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"TableName": "UserPet",
|
||||
"DisplayName": "宠物",
|
||||
"Fields": [
|
||||
{
|
||||
"FieldName": "GrowthPoints",
|
||||
"DisplayName": "成长值"
|
||||
},
|
||||
{
|
||||
"FieldName": "FeedingCount",
|
||||
"DisplayName": "喂养次数"
|
||||
},
|
||||
{
|
||||
"FieldName": "Comprehension",
|
||||
"DisplayName": "理解力"
|
||||
},
|
||||
{
|
||||
"FieldName": "Judgment",
|
||||
"DisplayName": "判断力"
|
||||
},
|
||||
{
|
||||
"FieldName": "Expression",
|
||||
"DisplayName": "表达力"
|
||||
},
|
||||
{
|
||||
"FieldName": "Persuasiveness",
|
||||
"DisplayName": "说服力"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user