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.
173 lines
5.5 KiB
C#
173 lines
5.5 KiB
C#
using Furion;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Furion.EventBus;
|
|
using Furion.FriendlyException;
|
|
using Furion.LinqBuilder;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Myshipping.Application.ConfigOption;
|
|
using Myshipping.Application.Entity;
|
|
using Myshipping.Application.Event;
|
|
using Myshipping.Application.Service.BookingOrder.Dto;
|
|
using Myshipping.Application.Service.BookingSlot.Dto;
|
|
using Myshipping.Application.Service.Fee.Dto;
|
|
using Myshipping.Core;
|
|
using Myshipping.Core.Service;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
namespace Myshipping.Application
|
|
{
|
|
/// <summary>
|
|
/// 费用币别
|
|
/// </summary>
|
|
[ApiDescriptionSettings("Application", Name = "FeeCurrency", Order = 1)]
|
|
public class FeeCurrencyService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<FeeCurrency> _repCode;
|
|
|
|
private readonly ILogger<FeeCurrencyService> _logger;
|
|
private readonly ISysCacheService _cache;
|
|
|
|
private readonly IEventPublisher _publisher;
|
|
|
|
public FeeCurrencyService(SqlSugarRepository<FeeCurrency> repCode,
|
|
ILogger<FeeCurrencyService> logger,
|
|
ISysCacheService cache,
|
|
IEventPublisher publisher)
|
|
{
|
|
_repCode = repCode;
|
|
|
|
_logger = logger;
|
|
_cache = cache;
|
|
|
|
_publisher = publisher;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 币别分页查询
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/FeeCurrency/Page")]
|
|
public async Task<dynamic> Page(FeeCurrencyPageInput input)
|
|
{
|
|
var entities = await _repCode.AsQueryable()
|
|
.WhereIF(!string.IsNullOrEmpty(input.CodeName), u => u.CodeName.Contains(input.CodeName))
|
|
.WhereIF(!string.IsNullOrEmpty(input.Name), u => u.Name.Contains(input.Name))
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
var result = entities.Adapt<SqlSugarPagedList<FeeCurrencyPageOutput>>();
|
|
|
|
return result.XnPagedResult();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/FeeCurrency/Save")]
|
|
public async Task<FeeCurrencySaveDto> Save(FeeCurrencySaveDto input)
|
|
{
|
|
if (input == null)
|
|
{
|
|
throw Oops.Bah("请传入正常数据!");
|
|
}
|
|
|
|
FeeCurrency entity = null;
|
|
if (input.Id == 0)
|
|
{
|
|
entity = input.Adapt<FeeCurrency>();
|
|
entity.Id = YitIdHelper.NextId();
|
|
await _repCode.InsertAsync(entity);
|
|
|
|
}
|
|
else
|
|
{
|
|
entity = await _repCode.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == input.Id);
|
|
entity = input.Adapt(entity);
|
|
await _repCode.UpdateAsync(entity);
|
|
}
|
|
|
|
await CacheFeeCurrency();
|
|
|
|
return entity.Adapt<FeeCurrencySaveDto>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/FeeCurrency/Detail")]
|
|
public async Task<FeeCurrencySaveDto> Detail(long id)
|
|
{
|
|
var entity = await _repCode.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == id);
|
|
|
|
return entity.Adapt<FeeCurrencySaveDto>();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/FeeCurrency/Delete")]
|
|
public async Task Delete(List<long> ids)
|
|
{
|
|
var list = await _repCode.AsQueryable().Filter(null, true).Where(x => ids.Contains(x.Id)).ToListAsync();
|
|
list.ForEach(x => x.IsDeleted = true);
|
|
await _repCode.AsUpdateable(list).ExecuteCommandAsync();
|
|
await CacheFeeCurrency();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取币别列表
|
|
/// </summary>
|
|
[HttpGet("/FeeCurrency/List")]
|
|
public async Task<List<FeeCurrencyCacheDto>> List()
|
|
{
|
|
var cacheList = await _cache.GetAsync<List<FeeCurrencyCacheDto>>(CommonConst.CACHE_KEY_FEE_CURRENCY);
|
|
if (cacheList?.Any() == true)
|
|
{
|
|
List<FeeCurrencyCacheDto> result = cacheList.Where(f => f.TenantId == UserManager.TENANT_ID).ToList();
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
var cacheFeeCode = await CacheFeeCurrency();
|
|
|
|
List<FeeCurrencyCacheDto> result = cacheFeeCode.Where(f => f.TenantId == UserManager.TENANT_ID).ToList();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 缓存币别列表
|
|
/// </summary>
|
|
[NonAction]
|
|
public async Task<List<FeeCurrencyCacheDto>> CacheFeeCurrency()
|
|
{
|
|
var allFeeCurrency = await _repCode.AsQueryable().Filter(null, true).ToListAsync();
|
|
|
|
var cacheFeeCode = allFeeCurrency.Adapt<List<FeeCurrencyCacheDto>>();
|
|
await _cache.SetTimeoutAsync(CommonConst.CACHE_KEY_FEE_CURRENCY, cacheFeeCode, new TimeSpan(6, 0, 0));
|
|
|
|
return cacheFeeCode;
|
|
}
|
|
}
|
|
}
|