using Myshipping.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using Myshipping.Core.Entity;
using System;
using Furion.FriendlyException;
namespace Myshipping.Core.Service
{
///
/// 客户参数
///
[ApiDescriptionSettings(Name = "DJYCustomerParam", Order = 1)]
public class DjyCustomerParamService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _repParam;
private readonly SqlSugarRepository _repParamItem;
private readonly SqlSugarRepository _repParamValue;
private readonly ILogger _logger;
private readonly ISysCacheService _cache;
private readonly SqlSugarRepository _repCustomer;
public DjyCustomerParamService(SqlSugarRepository repParam,
SqlSugarRepository repParamItem,
SqlSugarRepository repParamValue,
ISysCacheService cache, ILogger logger,
SqlSugarRepository repCustomer)
{
_repParam = repParam;
_logger = logger;
_repParamItem = repParamItem;
_repParamValue = repParamValue;
_cache = cache;
_repCustomer = repCustomer;
}
#region 参数类别
///
/// 获取所有参数类别
///
///
[HttpGet("/DJYCustomerParam/ParamList")]
public async Task> ParamList()
{
var list = await _repParam.AsQueryable().OrderBy(x => x.Sort).ToListAsync();
return list.Adapt>();
}
///
/// 获取参数选项
///
///
///
[HttpGet("/DJYCustomerParam/ParamItemList")]
public async Task> ParamItemList([FromQuery] string paraCode)
{
var list = await _repParamItem.AsQueryable().Where(x => x.ParaCode == paraCode).OrderBy(x => x.Sort).ToListAsync();
return list.Adapt>();
}
#endregion
#region 参数值
///
/// 分页获取参数值
///
///
[HttpPost("/DJYCustomerParam/PageParamValue")]
public async Task> PageParamValue(DjyCustomerParamValueQueryInput input)
{
var list = await _repParamValue.AsQueryable().Filter(null, true)
.WhereIF(!string.IsNullOrEmpty(input.ParaCode), x => x.ParaCode == input.ParaCode)
.WhereIF(input.CustomerId.HasValue, x => x.CustomerId == input.CustomerId)
.OrderBy(x => x.Sort)
.ToPagedListAsync(input.PageNo, input.PageSize);
return list.Adapt>();
}
///
/// 增加参数
///
///
[HttpPost("/DJYCustomerParam/saveParamValue")]
public async Task SaveParamValue(DjyCustomerParamValueSaveInput input)
{
DjyCustomerParamValue entity = null;
if (input.Id > 0)
{
entity = await _repParamValue.AsQueryable().FirstAsync(x => x.Id == input.Id);
input.Adapt(entity);
await _repParamValue.UpdateAsync(entity);
}
else
{
entity = input.Adapt();
await _repParamValue.InsertAsync(entity);
}
}
///
///删除参数
///
///
[HttpPost("/DJYCustomerParam/deleteParamValue")]
[SqlSugarUnitOfWork]
public async Task DeleteParamValue(long Id)
{
await _repParamValue.DeleteAsync(u => u.Id == Id);
}
#endregion
}
}