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.
130 lines
4.7 KiB
C#
130 lines
4.7 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.Fee.Entity;
|
|
using DS.WMS.Core.Flow.Entity;
|
|
using LanguageExt.Pipes;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.Fee.Method
|
|
{
|
|
/// <summary>
|
|
/// 费用服务基类
|
|
/// </summary>
|
|
public abstract class FeeServiceBase
|
|
{
|
|
/// <summary>
|
|
/// 人民币代码
|
|
/// </summary>
|
|
public const string RMB_CODE = "CNY";
|
|
|
|
/// <summary>
|
|
/// 美元代码
|
|
/// </summary>
|
|
public const string USD_CODE = "USD";
|
|
|
|
/// <summary>
|
|
/// 工作流运行状态值
|
|
/// </summary>
|
|
public static readonly int RunningStatus = (int)FlowStatusEnum.Running;
|
|
|
|
/// <summary>
|
|
/// 获取用户相关信息
|
|
/// </summary>
|
|
protected IUser User { get; private set; }
|
|
/// <summary>
|
|
/// 获取主库访问对象
|
|
/// </summary>
|
|
protected ISqlSugarClient Db { get; private set; }
|
|
/// <summary>
|
|
/// 获取业务库访问对象
|
|
/// </summary>
|
|
protected ISaasDbService SaasService { get; private set; }
|
|
|
|
SqlSugarScopeProvider? _tenantDb;
|
|
/// <summary>
|
|
/// 获取业务库访问对象
|
|
/// </summary>
|
|
protected SqlSugarScopeProvider TenantDb
|
|
{
|
|
get
|
|
{
|
|
if (_tenantDb == null)
|
|
_tenantDb = SaasService.GetBizDbScopeById(User.TenantId);
|
|
|
|
return _tenantDb;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="serviceProvider">服务提供程序</param>
|
|
protected FeeServiceBase(IServiceProvider serviceProvider)
|
|
{
|
|
User = serviceProvider.GetRequiredService<IUser>();
|
|
Db = serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
SaasService = serviceProvider.GetRequiredService<ISaasDbService>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找模板
|
|
/// </summary>
|
|
/// <param name="auditType">审批类型</param>
|
|
/// <returns></returns>
|
|
protected async Task<FlowTemplateTenant> FindTemplateAsync(AuditType auditType)
|
|
{
|
|
string typeStr = auditType.ToString();
|
|
return await Db.Queryable<FlowTemplateTenant>().FirstAsync(x =>
|
|
x.Status == StatusEnum.Enable && x.AuditType == typeStr);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取汇率
|
|
/// </summary>
|
|
/// <param name="items"></param>
|
|
/// <returns></returns>
|
|
protected async Task FetchExchangeRateAsync(IEnumerable<FeeRecord> items)
|
|
{
|
|
var exRecords = items.Where(x => !x.ExchangeRate.HasValue && x.Currency != x.LocalCurrency).ToList();
|
|
if (exRecords.Count > 0)
|
|
{
|
|
var codes = exRecords.Select(x => x.Currency).Distinct().ToList();
|
|
var currencies = await TenantDb.Queryable<FeeCurrency>().Where(x => codes.Contains(x.CodeName)).Includes(x => x.Exchanges).ToListAsync();
|
|
DateTime dtNow = DateTime.Now;
|
|
foreach (var item in exRecords)
|
|
{
|
|
var currency = currencies.Find(x => x.CodeName == item.Currency);
|
|
if (currency != null)
|
|
{
|
|
item.ExchangeRate = currency.DefaultRate;
|
|
if (currency.Exchanges != null && currency.Exchanges.Count > 0)
|
|
{
|
|
//取当前时间范围内的最新一条
|
|
var exchange = currency.Exchanges.FindAll(x => x.Status == StatusEnum.Enable &&
|
|
x.StartDate >= dtNow && x.EndDate <= dtNow).OrderByDescending(x => x.UpdateTime).FirstOrDefault();
|
|
|
|
if (exchange != null)
|
|
item.ExchangeRate = item.FeeType == FeeType.Receivable ? exchange.DRValue : exchange.CRValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前登录用户的待审批工作流的查询对象
|
|
/// </summary>
|
|
/// <param name="auditTypes">审核类型</param>
|
|
/// <returns></returns>
|
|
protected ISugarQueryable<FlowInstance> GetCurrentFlowsQuery(string[] auditTypes)
|
|
{
|
|
return Db.Queryable<FlowInstance>().Where(x => x.FlowStatus == RunningStatus
|
|
&& SqlFunc.SplitIn(x.MakerList, User.UserId) && auditTypes.Contains(x.AuditType))
|
|
.Select(x => new FlowInstance { Id = x.Id, BusinessId = x.BusinessId, BusinessType = x.BusinessType });
|
|
}
|
|
}
|
|
}
|