using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extend.Entitys;
using JNPF.Extend.Entitys.Dto.ProductClassify;
using JNPF.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.Extend;
///
/// 产品分类.
///
[ApiDescriptionSettings(Tag = "Extend", Name = "Classify", Order = 600)]
[Route("api/extend/saleOrder/[controller]")]
public class ProductClassifyService : IDynamicApiController, ITransient
{
///
/// 服务基础仓储.
///
private readonly ISqlSugarRepository _repository;
///
/// 用户管理.
///
private readonly IUserManager _userManager;
public ProductClassifyService(
ISqlSugarRepository extProductRepository,
IUserManager userManager)
{
_repository = extProductRepository;
_userManager = userManager;
}
#region GET
///
/// 列表.
///
///
[HttpGet("")]
public async Task GetList()
{
var data = await _repository.AsQueryable().Where(t => t.DeleteMark == null).OrderBy(a => a.CreatorTime, OrderByType.Desc).ToListAsync();
List? treeList = data.Adapt>();
return new { list = treeList.ToTree("-1") };
}
///
/// 获取订单示例.
///
/// 主键值.
///
[HttpGet("{id}")]
public async Task GetInfo(string id)
{
return (await _repository.AsQueryable().FirstAsync(a => a.Id.Equals(id) && a.DeleteMark == null)).Adapt();
}
#endregion
#region POST
///
/// 新建.
///
/// 请求参数.
///
[HttpPost("")]
public async Task Create([FromBody] ProductClassifyCrInput input)
{
var entity = input.Adapt();
entity.Id = SnowflakeIdHelper.NextId();
var isOk = await _repository.AsInsertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
if (!(isOk > 0)) throw Oops.Oh(ErrorCode.COM1000);
}
///
/// 更新订单示例.
///
/// 主键值.
/// 参数.
///
[HttpPut("{id}")]
public async Task Update(string id, [FromBody] ProductClassifyUpInput input)
{
var entity = input.Adapt();
entity.LastModifyTime = DateTime.Now;
entity.LastModifyUserId = _userManager.UserId;
var isOk = await _repository.AsUpdateable(entity).UpdateColumns(it => new
{
it.ParentId,
it.FullName,
it.LastModifyTime,
it.LastModifyUserId
}).ExecuteCommandAsync();
if (!(isOk > 0)) throw Oops.Oh(ErrorCode.COM1001);
}
///
/// 删除订单示例.
///
///
[HttpDelete("{id}")]
public async Task Delete(string id)
{
var isOk = await _repository.AsDeleteable().Where(it => it.Id.Equals(id)).ExecuteCommandAsync();
if (!(isOk > 0)) throw Oops.Oh(ErrorCode.COM1002);
}
#endregion
}