|
|
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 Furion.Logging;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using Myshipping.Core.Entity;
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
|
namespace Myshipping.Core.Service
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// EDI参数设置服务
|
|
|
/// </summary>
|
|
|
[ApiDescriptionSettings(Name = "DjyEdiSetting", Order = 1)]
|
|
|
public class DjyEdiSettingService : IDjyEdiSettingService, IDynamicApiController, ITransient
|
|
|
{
|
|
|
private readonly SqlSugarRepository<DjyEdiSetting> _rep;
|
|
|
private readonly ISysCacheService _cacheService;
|
|
|
private readonly ILogger<DjyEdiSetting> _logger;
|
|
|
|
|
|
public DjyEdiSettingService(SqlSugarRepository<DjyEdiSetting> rep, ILogger<DjyEdiSetting> logger, ISysCacheService cacheService)
|
|
|
{
|
|
|
_rep = rep;
|
|
|
_logger = logger;
|
|
|
_cacheService = cacheService;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 分页查询EDI参数设置
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DjyEdiSetting/page")]
|
|
|
public async Task<dynamic> Page([FromQuery] QueryDjyEdiSettingInput input)
|
|
|
{
|
|
|
var entities = await _rep.AsQueryable().Filter(null, true)
|
|
|
.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.CARRIERID), u => u.CARRIERID.Contains(input.CARRIERID.Trim()))
|
|
|
.WhereIF(input.TenantId > 0, u => u.TenantId == input.TenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TenantName), u => u.TenantName.Contains(input.TenantName.Trim()))
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
return entities.XnPagedResult();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 增加EDI参数设置(准备作废,使用save接口代替)
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyEdiSetting/add")]
|
|
|
public async Task<long> Add(AddDjyEdiSettingInput input)
|
|
|
{
|
|
|
var cc = _rep.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType);
|
|
|
if (cc > 0)
|
|
|
{
|
|
|
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})、相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
|
|
|
}
|
|
|
|
|
|
var entity = input.Adapt<DjyEdiSetting>();
|
|
|
await _rep.InsertAsync(entity);
|
|
|
await CacheData();
|
|
|
|
|
|
|
|
|
|
|
|
return entity.Id;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存EDI参数设置
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyEdiSetting/save")]
|
|
|
public async Task<long> Save(UpdateDjyEdiSettingInput input)
|
|
|
{
|
|
|
DjyEdiSetting entity = null;
|
|
|
if (input.Id == 0) //新增
|
|
|
{
|
|
|
var cc = _rep.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType);
|
|
|
|
|
|
if (cc > 0)
|
|
|
{
|
|
|
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})、相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
|
|
|
}
|
|
|
|
|
|
entity = input.Adapt<DjyEdiSetting>();
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
|
//其他同船司、同发送类型的都禁用
|
|
|
var otherList = _rep.Where(x => x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.Id != entity.Id).ToList();
|
|
|
foreach (var item in otherList)
|
|
|
{
|
|
|
item.EnableFlag = false;
|
|
|
await _rep.UpdateAsync(item);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
entity = _rep.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.First(x => x.Id == input.Id);
|
|
|
if (entity == null)
|
|
|
{
|
|
|
throw Oops.Bah($"未找到数据");
|
|
|
}
|
|
|
|
|
|
var cc = _rep.AsQueryable().Filter(null, true)
|
|
|
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType && x.Id != input.Id);
|
|
|
if (cc > 0)
|
|
|
{
|
|
|
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})、相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
|
|
|
}
|
|
|
|
|
|
entity = input.Adapt(entity);
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
}
|
|
|
|
|
|
await CacheData();
|
|
|
return entity.Id;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新EDI参数设置(准备作废,使用save接口代替)
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyEdiSetting/edit")]
|
|
|
public async Task<long> Update(UpdateDjyEdiSettingInput input)
|
|
|
{
|
|
|
var entity = _rep.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.First(x => x.Id == input.Id);
|
|
|
if (entity == null)
|
|
|
{
|
|
|
throw Oops.Bah($"未找到数据");
|
|
|
}
|
|
|
|
|
|
var cc = _rep.AsQueryable().Filter(null, true)
|
|
|
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType && x.Id != input.Id);
|
|
|
if (cc > 0)
|
|
|
{
|
|
|
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})、相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
|
|
|
}
|
|
|
|
|
|
entity = input.Adapt(entity);
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
|
|
|
await CacheData();
|
|
|
return entity.Id;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设置启用(启用后,同船司、同发送类型的其他EDI通道会被取消启用)
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyEdiSetting/SetEnable")]
|
|
|
public async Task SetEnable(long id)
|
|
|
{
|
|
|
var entity = _rep.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.First(x => x.Id == id);
|
|
|
if (entity == null)
|
|
|
{
|
|
|
throw Oops.Bah($"未找到数据");
|
|
|
}
|
|
|
|
|
|
entity.EnableFlag = true;
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
|
|
|
|
|
|
//其他同船司、同发送类型的都禁用
|
|
|
var otherList = _rep.Where(x => x.TenantId == entity.TenantId && x.CARRIERID == entity.CARRIERID && x.Id != entity.Id).ToList();
|
|
|
foreach (var item in otherList)
|
|
|
{
|
|
|
item.EnableFlag = false;
|
|
|
await _rep.UpdateAsync(item);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除EDI参数设置
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyEdiSetting/delete")]
|
|
|
public async Task Delete(GetDjyEdiSettingInput input)
|
|
|
{
|
|
|
var entity = await _rep.AsQueryable().Filter(null, true)
|
|
|
.FirstAsync(u => u.Id == input.Id);
|
|
|
if (entity == null)
|
|
|
{
|
|
|
throw Oops.Bah($"未找到数据");
|
|
|
}
|
|
|
await _rep.DeleteAsync(entity);
|
|
|
await CacheData();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取EDI参数设置
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DjyEdiSetting/detail")]
|
|
|
public async Task<DjyEdiSetting> Get([FromQuery] GetDjyEdiSettingInput input)
|
|
|
{
|
|
|
return await _rep.AsQueryable().Filter(null, true).FirstAsync(u => u.Id == input.Id);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 缓存数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
/// <exception cref="System.NotImplementedException"></exception>
|
|
|
[NonAction]
|
|
|
public async Task CacheData(bool flag = false)
|
|
|
{
|
|
|
if (flag)
|
|
|
{
|
|
|
if (!_cacheService.Exists(CommonConst.CACHE_KEY_DJY_EDI_SETTING))
|
|
|
{
|
|
|
var list = _rep.AsQueryable().Filter(null, true).OrderBy(x => x.EDINAME).ToList();
|
|
|
await _cacheService.SetAllEdiSetting(list);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var list = _rep.AsQueryable().Filter(null, true).OrderBy(x => x.EDINAME).ToList();
|
|
|
await _cacheService.SetAllEdiSetting(list);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
///// 获取EDI参数设置列表
|
|
|
///// </summary>
|
|
|
///// <param name="input"></param>
|
|
|
///// <returns></returns>
|
|
|
//[HttpGet("/DjyEdiSetting/list")]
|
|
|
//public async Task<dynamic> List([FromQuery] QueryDjyEdiSettingInput input)
|
|
|
//{
|
|
|
// return await _rep.ToListAsync();
|
|
|
//}
|
|
|
}
|
|
|
}
|