You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Core/Service/DjyCustomerParam/DjyCustomerParamService.cs

146 lines
5.2 KiB
C#

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
{
/// <summary>
/// 客户参数
/// </summary>
[ApiDescriptionSettings(Name = "DJYCustomerParam", Order = 1)]
public class DjyCustomerParamService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<DjyCustomerParam> _repParam;
private readonly SqlSugarRepository<DjyCustomerParamItem> _repParamItem;
private readonly SqlSugarRepository<DjyCustomerParamValue> _repParamValue;
private readonly ILogger<DjyCustomerParam> _logger;
private readonly ISysCacheService _cache;
private readonly SqlSugarRepository<DjyCustomer> _repCustomer;
public DjyCustomerParamService(SqlSugarRepository<DjyCustomerParam> repParam,
SqlSugarRepository<DjyCustomerParamItem> repParamItem,
SqlSugarRepository<DjyCustomerParamValue> repParamValue,
ISysCacheService cache, ILogger<DjyCustomerParam> logger,
SqlSugarRepository<DjyCustomer> repCustomer)
{
_repParam = repParam;
_logger = logger;
_repParamItem = repParamItem;
_repParamValue = repParamValue;
_cache = cache;
_repCustomer = repCustomer;
}
#region 参数类别
/// <summary>
/// 获取所有参数类别
/// </summary>
/// <returns></returns>
[HttpGet("/DJYCustomerParam/ParamList")]
public async Task<List<DjyCustomerParamListOutput>> ParamList()
{
var list = await _repParam.AsQueryable().OrderBy(x => x.Sort).ToListAsync();
return list.Adapt<List<DjyCustomerParamListOutput>>();
}
/// <summary>
/// 获取参数选项
/// </summary>
/// <param name="paraCode"></param>
/// <returns></returns>
[HttpGet("/DJYCustomerParam/ParamItemList")]
public async Task<List<DjyCustomerParamItemDto>> ParamItemList([FromQuery] string paraCode)
{
var list = await _repParamItem.AsQueryable().Where(x => x.ParaCode == paraCode).OrderBy(x => x.Sort).ToListAsync();
return list.Adapt<List<DjyCustomerParamItemDto>>();
}
#endregion
#region 参数值
/// <summary>
/// 分页获取参数值
/// </summary>
/// <returns></returns>
[HttpPost("/DJYCustomerParam/PageParamValue")]
public async Task<SqlSugarPagedList<DjyCustomerParamValueListOutput>> 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);
var rtn = list.Adapt<SqlSugarPagedList<DjyCustomerParamValueListOutput>>();
var listParam = await _repParam.AsQueryable().ToListAsync();
var listParamItem = await _repParamItem.AsQueryable().ToListAsync();
var listCustomer = await _repCustomer.AsQueryable().Select(x => new { x.Id, x.ShortName }).ToListAsync();
foreach (var item in rtn.Items)
{
var p = listParam.FirstOrDefault(x => x.ParaCode == item.ParaCode);
item.ParaName = p.ParaName;
var t = listCustomer.FirstOrDefault(x => x.Id == item.CustomerId);
item.CustomerName = t.ShortName;
var it = listParamItem.FirstOrDefault(x => x.ParaCode == item.ParaCode && x.ItemCode == item.ItemCode);
if (it != null)
{
item.ItemCodeName = it.ItemName;
}
}
return rtn;
}
/// <summary>
/// 增加参数
/// </summary>
/// <returns></returns>
[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<DjyCustomerParamValue>();
await _repParamValue.InsertAsync(entity);
}
}
/// <summary>
///删除参数
/// </summary>
/// <returns></returns>
[HttpPost("/DJYCustomerParam/deleteParamValue")]
[SqlSugarUnitOfWork]
public async Task DeleteParamValue(long Id)
{
await _repParamValue.DeleteAsync(u => u.Id == Id);
}
#endregion
}
}