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.Application/Service/Fee/FeeCurrencyExchangeService.cs

165 lines
5.7 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 = "FeeCurrencyExchange", Order = 1)]
public class FeeCurrencyExchangeService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<FeeCurrencyExchange> _repCode;
private readonly ILogger<FeeCurrencyExchangeService> _logger;
private readonly ISysCacheService _cache;
private readonly IEventPublisher _publisher;
public FeeCurrencyExchangeService(SqlSugarRepository<FeeCurrencyExchange> repCode,
ILogger<FeeCurrencyExchangeService> logger,
ISysCacheService cache,
IEventPublisher publisher)
{
_repCode = repCode;
_logger = logger;
_cache = cache;
_publisher = publisher;
}
/// <summary>
/// 费用代码查询
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/FeeCurrencyExchange/Page")]
public async Task<dynamic> Page(FeeCurrencyExchangePageInput input)
{
var entities = await _repCode.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(input.Currency), u => u.Currency.Contains(input.Currency))
.WhereIF(input.StartTimeBegin.HasValue, u => u.StartTime > input.StartTimeBegin.Value)
.WhereIF(input.StartTimeEnd.HasValue, u => u.StartTime < input.StartTimeEnd.Value.AddDays(1))
.WhereIF(input.EndTimeBegin.HasValue, u => u.EndTime > input.EndTimeBegin.Value)
.WhereIF(input.EndTimeEnd.HasValue, u => u.EndTime < input.EndTimeEnd.Value.AddDays(1))
.ToPagedListAsync(input.PageNo, input.PageSize);
var result = entities.Adapt<SqlSugarPagedList<FeeCurrencyExchangePageOutput>>();
return result.XnPagedResult();
}
/// <summary>
/// 保存
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/FeeCurrencyExchange/Save")]
public async Task<FeeCurrencyExchangeSaveDto> Save(FeeCurrencyExchangeSaveDto input)
{
if (input == null)
{
throw Oops.Bah("请传入正常数据!");
}
var minDate = DateTime.Today.AddYears(-1);
if (input.StartTime < minDate || input.EndTime < minDate)
{
throw Oops.Bah("开始日期或结束日期有误!");
}
FeeCurrencyExchange entity = null;
if (input.Id == 0)
{
//判断时间范围重复
var cc = await _repCode.AsQueryable().Where(x => (input.StartTime >= x.StartTime && input.StartTime <= x.EndTime)
|| (input.EndTime >= x.StartTime && input.EndTime <= x.EndTime))
.CountAsync();
if (cc > 0)
{
throw Oops.Bah("日期范围存在交叉的数据!");
}
entity = input.Adapt<FeeCurrencyExchange>();
entity.Id = YitIdHelper.NextId();
await _repCode.InsertAsync(entity);
}
else
{
//判断时间范围重复
var cc = await _repCode.AsQueryable().Where(x => x.Id != input.Id &&
(
(input.StartTime >= x.StartTime && input.StartTime <= x.EndTime)
|| (input.EndTime >= x.StartTime && input.EndTime <= x.EndTime)
))
.CountAsync();
if (cc > 0)
{
throw Oops.Bah("日期范围存在交叉的数据!");
}
entity = await _repCode.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == input.Id);
entity = input.Adapt(entity);
await _repCode.UpdateAsync(entity);
}
return entity.Adapt<FeeCurrencyExchangeSaveDto>();
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("/FeeCurrencyExchange/Detail")]
public async Task<FeeCurrencyExchangeSaveDto> Detail(long id)
{
var entity = await _repCode.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == id);
return entity.Adapt<FeeCurrencyExchangeSaveDto>();
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[HttpPost("/FeeCurrencyExchange/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();
}
}
}