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/DjyEdiSetting/DjyEdiSettingService.cs

172 lines
6.1 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 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;
2 years ago
private readonly ISysCacheService _cacheService;
private readonly ILogger<DjyEdiSetting> _logger;
2 years ago
public DjyEdiSettingService(SqlSugarRepository<DjyEdiSetting> rep, ILogger<DjyEdiSetting> logger, ISysCacheService cacheService)
{
_rep = rep;
_logger = logger;
2 years ago
_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参数设置
/// </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);
if (cc > 0)
{
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})相同船司({input.CARRIERID})的参数设置");
}
var entity = input.Adapt<DjyEdiSetting>();
await _rep.InsertAsync(entity);
2 years ago
await CacheData();
return entity.Id;
}
/// <summary>
/// 更新EDI参数设置
/// </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.Id != input.Id);
if (cc > 0)
{
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})相同船司({input.CARRIERID})的参数设置");
}
entity = input.Adapt(entity);
await _rep.UpdateAsync(entity);
2 years ago
await CacheData();
return entity.Id;
}
/// <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);
2 years ago
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);
}
2 years ago
/// <summary>
/// 缓存数据
/// </summary>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
[NonAction]
2 years ago
public async Task CacheData(bool flag = false)
2 years ago
{
2 years ago
if (flag)
{
if (!_cacheService.Exists(CommonConst.CACHE_KEY_DJY_EDI_SETTING))
{
var list = _rep.AsQueryable().Filter(null, true).ToList();
await _cacheService.SetAllEdiSetting(list);
}
}
else
{
var list = _rep.AsQueryable().Filter(null, true).ToList();
await _cacheService.SetAllEdiSetting(list);
}
2 years ago
2 years ago
}
2 years ago
///// <summary>
///// 获取EDI参数设置列表
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpGet("/DjyEdiSetting/list")]
//public async Task<dynamic> List([FromQuery] QueryDjyEdiSettingInput input)
//{
// return await _rep.ToListAsync();
//}
}
}