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 Myshipping.Application.Entity;
using Furion.Logging;
using Microsoft.Extensions.Logging;
namespace Myshipping.Core.Service
{
///
/// EDI参数设置服务
///
[ApiDescriptionSettings(Name = "DjyEdiSetting", Order = 1)]
public class DjyEdiSettingService : IDjyEdiSettingService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly ILogger _logger;
public DjyEdiSettingService(SqlSugarRepository rep, ILogger logger)
{
_rep = rep;
_logger = logger;
}
///
/// 分页查询EDI参数设置
///
///
///
[HttpGet("/DjyEdiSetting/page")]
public async Task Page([FromQuery] QueryDjyEdiSettingInput input)
{
_rep.Context.QueryFilter.Clear();
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.EDICODE), u => u.EDICODE == input.EDICODE)
.WhereIF(!string.IsNullOrWhiteSpace(input.EDINAME), u => u.EDINAME.Contains(input.EDINAME.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SERVERIP), u => u.SERVERIP.Contains(input.SERVERIP.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.FOLDERNAME), u => u.FOLDERNAME.Contains(input.FOLDERNAME.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.USERNAME), u => u.USERNAME.Contains(input.USERNAME.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.PASSWORD), u => u.PASSWORD.Contains(input.PASSWORD.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SENDCODE), u => u.SENDCODE.Contains(input.SENDCODE.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.RECEIVECODE), u => u.RECEIVECODE.Contains(input.RECEIVECODE.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SENDNAME), u => u.SENDNAME.Contains(input.SENDNAME.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SENDATTN), u => u.SENDATTN.Contains(input.SENDATTN.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SENDTEL), u => u.SENDTEL.Contains(input.SENDTEL.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SENDEMAIL), u => u.SENDEMAIL.Contains(input.SENDEMAIL.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SENDCOMPANYCODE), u => u.SENDCOMPANYCODE.Contains(input.SENDCOMPANYCODE.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SENDSUBCOMPANYCODE), u => u.SENDSUBCOMPANYCODE.Contains(input.SENDSUBCOMPANYCODE.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.CARRIERID), u => u.CARRIERID.Contains(input.CARRIERID.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.RECEIVEEMAIL), u => u.RECEIVEEMAIL.Contains(input.RECEIVEEMAIL.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.RECEIVESIEMAIL), u => u.RECEIVESIEMAIL.Contains(input.RECEIVESIEMAIL.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.RECEIVEOP), u => u.RECEIVEOP.Contains(input.RECEIVEOP.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.RECEIVESALE), u => u.RECEIVESALE.Contains(input.RECEIVESALE.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.RECEIVEDEPT), u => u.RECEIVEDEPT.Contains(input.RECEIVEDEPT.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERTEL), u => u.SHIPPERTEL.Contains(input.SHIPPERTEL.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEETEL), u => u.CONSIGNEETEL.Contains(input.CONSIGNEETEL.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYTEL), u => u.NOTIFYPARTYTEL == input.NOTIFYPARTYTEL)
.WhereIF(!string.IsNullOrWhiteSpace(input.ISUSETEL), u => u.ISUSETEL == input.ISUSETEL)
.WhereIF(!string.IsNullOrWhiteSpace(input.TenantName), u => u.TenantName.Contains(input.TenantName.Trim()))
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加EDI参数设置(同一租户、同一代码的会更新)
///
///
///
[HttpPost("/DjyEdiSetting/add")]
public async Task Add(AddDjyEdiSettingInput input)
{
_rep.Context.QueryFilter.Clear();
var entity = _rep.FirstOrDefault(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId);
if (entity == null)
{
entity = input.Adapt();
await _rep.InsertAsync(entity);
}
else
{
entity = input.Adapt(entity);
await _rep.UpdateAsync(entity);
}
}
///
/// 更新EDI参数设置
///
///
///
[HttpPost("/DjyEdiSetting/edit")]
public async Task Update(UpdateDjyEdiSettingInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 删除EDI参数设置
///
///
///
[HttpPost("/DjyEdiSetting/delete")]
public async Task Delete(GetDjyEdiSettingInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 获取EDI参数设置
///
///
///
[HttpGet("/DjyEdiSetting/detail")]
public async Task Get([FromQuery] GetDjyEdiSettingInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/////
///// 获取EDI参数设置列表
/////
/////
/////
//[HttpGet("/DjyEdiSetting/list")]
//public async Task List([FromQuery] QueryDjyEdiSettingInput input)
//{
// return await _rep.ToListAsync();
//}
}
}