审核任务驳回时更新驳回理由

dev
嵇文龙 3 months ago
parent 229d5b9e69
commit ff0a271a64

@ -0,0 +1,48 @@
using DS.Module.Core;
using DS.Module.UserModule;
using DS.WMS.Core.Op.Entity;
using SqlSugar;
namespace DS.WMS.Core.Fee.Dtos
{
/// <summary>
/// 报表生成上下文
/// </summary>
public class ReportContext
{
/// <summary>
/// 服务提供程序
/// </summary>
public IServiceProvider ServiceProvider { get; internal set; }
/// <summary>
/// 获取主库访问对象
/// </summary>
public ISqlSugarClient Db { get; internal set; }
/// <summary>
/// 获取租户库访问对象
/// </summary>
public ISqlSugarClient TenantDb { get; internal set; }
/// <summary>
/// 请求用户
/// </summary>
public IUser User { get; internal set; }
/// <summary>
/// 操作结果,用于记录错误信息
/// </summary>
public DataResult? ErrorResult { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType BusinessType { get; set; } = BusinessType.OceanShippingExport;
/// <summary>
/// 业务ID
/// </summary>
public long[] Ids { get; set; } = [];
}
}

@ -96,12 +96,13 @@ public interface IFeeRecordService
Task WriteBackStatusAsync(long businessId, BusinessType businessType);
/// <summary>
/// 获取费用核算单打印信息
/// 获取费用打印信息
/// </summary>
/// <param name="providerName">数据提供程序</param>
/// <param name="businessType">业务类型</param>
/// <param name="idArray">费用记录ID</param>
/// <returns></returns>
Task<DataResult<CostAccountingForm>> GetPrintInfoAsync(BusinessType businessType, params long[] idArray);
Task<DataResult<dynamic>> GetPrintInfoAsync(string providerName, BusinessType businessType, params long[] idArray);
/// <summary>
/// 设置发票启用状态

@ -0,0 +1,17 @@
using DS.WMS.Core.Fee.Dtos;
namespace DS.WMS.Core.Fee.Interface
{
/// <summary>
/// 用于输出报表的数据提供程序
/// </summary>
public interface IReportProvider
{
/// <summary>
/// 返回所需的JSON格式的数据
/// </summary>
/// <param name="context">报表输出上下文</param>
/// <returns></returns>
Task<dynamic?> GetDataAsync(ReportContext context);
}
}

@ -927,110 +927,33 @@ namespace DS.WMS.Core.Fee.Method
}
/// <summary>
/// 获取费用核算单打印信息
/// 获取费用打印信息
/// </summary>
/// <param name="providerName"></param>
/// <param name="businessType">业务类型</param>
/// <param name="idArray">费用记录ID</param>
/// <returns></returns>
public async Task<DataResult<CostAccountingForm>> GetPrintInfoAsync(BusinessType businessType, params long[] idArray)
public async Task<DataResult<dynamic>> GetPrintInfoAsync(string providerName, BusinessType businessType, params long[] idArray)
{
CostAccountingForm form = null;
switch (businessType)
{
case BusinessType.OceanShippingExport:
form = await GetOceanShippingExportAsync(idArray);
break;
case BusinessType.OceanShippingImport:
break;
default:
return DataResult<CostAccountingForm>.Failed(string.Format(
MultiLanguageConst.BusinessNotSupported, businessType.GetDescription()));
}
Type type = Type.GetType(providerName, false);
if (type == null)
return DataResult<dynamic>.Failed("未能找到数据提供程序");
if (form != null)
var provider = Fasterflect.ConstructorExtensions.CreateInstance(type) as IReportProvider;
var context = new ReportContext
{
long UserId = long.Parse(User.UserId);
form.Creator = Db.Queryable<SysUser>().Where(x => x.Id == UserId).Select(x => x.UserName).First();
form.ReceivableRMB = form.Details.FindAll(x => x.Type == FeeType.Receivable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount);
form.PayableRMB = form.Details.FindAll(x => x.Type == FeeType.Payable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount);
form.ReceivableUSD = form.Details.FindAll(x => x.Type == FeeType.Receivable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount);
form.PayableUSD = form.Details.FindAll(x => x.Type == FeeType.Payable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount);
form.ReceivableOther = form.Details.FindAll(x => x.Type == FeeType.Receivable && (x.Currency != FeeCurrency.RMB_CODE && x.Currency != FeeCurrency.USD_CODE)).Sum(x => x.Amount);
form.PayableOther = form.Details.FindAll(x => x.Type == FeeType.Payable && (x.Currency == FeeCurrency.RMB_CODE && x.Currency != FeeCurrency.USD_CODE)).Sum(x => x.Amount);
//获取美元汇率
var fees = new List<FeeRecord> {
new FeeRecord { Currency = FeeCurrency.USD_CODE, FeeType = FeeType.Receivable },
new FeeRecord { Currency = FeeCurrency.USD_CODE, FeeType = FeeType.Payable }
};
await FetchExchangeRateAsync(fees);
form.ExchangeRate = fees[0].ExchangeRate.HasValue ? fees[0].ExchangeRate.Value : 1;
form.TotalReceivable = Math.Round(form.ReceivableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.ReceivableRMB + form.ReceivableOther;
form.TotalPayable = Math.Round(form.PayableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.PayableRMB + form.PayableOther;
}
return DataResult<CostAccountingForm>.Success(form);
}
//获取海运出口打印数据
async Task<CostAccountingForm> GetOceanShippingExportAsync(params long[] idArray)
{
CostAccountingForm form = null;
var list = await TenantDb.Queryable<FeeRecord>().InnerJoin<SeaExport>((x, y) => x.BusinessId == y.Id)
.Where((x, y) => idArray.Contains(x.Id)
//&& x.FeeStatus == FeeStatus.SettlementCompleted
).Select((x, y) => new
{
x.FeeType,
x.FeeName,
x.Currency,
x.ExchangeRate,
x.Amount,
x.CustomerName,
y.CustomerNo, //业务编号
y.AccountDate, //会计期间
y.ETA,
y.ETD,
y.Voyno,
y.MBLNO,
y.Carrier,
y.LoadPort,
y.DischargePort,
y.CntrTotal, //Volume
y.IssueType //放单方式
}).ToListAsync();
if (list.Count == 0)
return form;
var item = list[0];
form = new CostAccountingForm
{
BusinessNo = item.CustomerNo,
AccountingPeriod = item.AccountDate,
ETA = item.ETA,
ETD = item.ETD,
Voy = item.Voyno,
MBLNo = item.MBLNO,
Carrier = item.Carrier,
POL = item.LoadPort,
POD = item.DischargePort,
Volume = item.CntrTotal,
ReleaseType = item.IssueType,
PrintTime = DateTime.Now,
Details = list.Select(x => new CostAccountingDetail
{
Amount = x.Amount,
Currency = x.Currency,
CustomerName = x.CustomerName,
FeeName = x.FeeName,
Type = x.FeeType
}).ToList()
BusinessType = businessType,
Ids = idArray,
Db = Db,
TenantDb = TenantDb,
User = User,
ServiceProvider = ServiceProvider
};
var data = provider.GetDataAsync(context);
if (context.ErrorResult == null)
return DataResult<dynamic>.Success(data);
return form;
return DataResult<dynamic>.Failed(context.ErrorResult.Message, context.ErrorResult.MultiCode);
}
/// <summary>

@ -0,0 +1,123 @@
using DS.Module.Core;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Fee.Interface;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Fee.Method.ReportProviders
{
/// <summary>
/// 费用核算单
/// </summary>
public class CostAccountingReport : IReportProvider
{
public async Task<dynamic?> GetDataAsync(ReportContext context)
{
CostAccountingForm? form = null;
switch (context.BusinessType)
{
case BusinessType.OceanShippingExport:
form = await GetOceanShippingExportAsync(context.TenantDb, context.Ids);
break;
case BusinessType.OceanShippingImport:
break;
default:
context.ErrorResult = DataResult.Failed(string.Format(MultiLanguageConst.GetDescription(
MultiLanguageConst.BusinessNotSupported), context.BusinessType.GetDescription()));
break;
}
if (form != null)
{
long UserId = long.Parse(context.User.UserId);
form.Creator = context.Db.Queryable<SysUser>().Where(x => x.Id == UserId).Select(x => x.UserName).First();
form.ReceivableRMB = form.Details.FindAll(x => x.Type == FeeType.Receivable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount);
form.PayableRMB = form.Details.FindAll(x => x.Type == FeeType.Payable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount);
form.ReceivableUSD = form.Details.FindAll(x => x.Type == FeeType.Receivable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount);
form.PayableUSD = form.Details.FindAll(x => x.Type == FeeType.Payable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount);
form.ReceivableOther = form.Details.FindAll(x => x.Type == FeeType.Receivable && (x.Currency != FeeCurrency.RMB_CODE && x.Currency != FeeCurrency.USD_CODE)).Sum(x => x.Amount);
form.PayableOther = form.Details.FindAll(x => x.Type == FeeType.Payable && (x.Currency == FeeCurrency.RMB_CODE && x.Currency != FeeCurrency.USD_CODE)).Sum(x => x.Amount);
//获取美元汇率
var currencyService = context.ServiceProvider.GetRequiredService<IFeeCurrencyExchangeService>();
var exchange = new ExchangeRate
{
CurrencyFrom = FeeCurrency.USD_CODE,
CurrencyTo = FeeCurrency.RMB_CODE
};
exchange = (await currencyService.GetExchangeRateAsync(exchange))?.Data;
form.ExchangeRate = exchange.Rate;
form.TotalReceivable = Math.Round(form.ReceivableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.ReceivableRMB + form.ReceivableOther;
form.TotalPayable = Math.Round(form.PayableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.PayableRMB + form.PayableOther;
}
return form;
}
//获取海运出口打印数据
static async Task<CostAccountingForm> GetOceanShippingExportAsync(ISqlSugarClient tenantDb, params long[] idArray)
{
CostAccountingForm form = null;
var list = await tenantDb.Queryable<FeeRecord>().InnerJoin<SeaExport>((x, y) => x.BusinessId == y.Id)
.Where((x, y) => idArray.Contains(x.Id)
//&& x.FeeStatus == FeeStatus.SettlementCompleted
).Select((x, y) => new
{
x.FeeType,
x.FeeName,
x.Currency,
x.ExchangeRate,
x.Amount,
x.CustomerName,
y.CustomerNo, //业务编号
y.AccountDate, //会计期间
y.ETA,
y.ETD,
y.Voyno,
y.MBLNO,
y.Carrier,
y.LoadPort,
y.DischargePort,
y.CntrTotal, //Volume
y.IssueType //放单方式
}).ToListAsync();
if (list.Count == 0)
return form;
var item = list[0];
form = new CostAccountingForm
{
BusinessNo = item.CustomerNo,
AccountingPeriod = item.AccountDate,
ETA = item.ETA,
ETD = item.ETD,
Voy = item.Voyno,
MBLNo = item.MBLNO,
Carrier = item.Carrier,
POL = item.LoadPort,
POD = item.DischargePort,
Volume = item.CntrTotal,
ReleaseType = item.IssueType,
PrintTime = DateTime.Now,
Details = list.Select(x => new CostAccountingDetail
{
Amount = x.Amount,
Currency = x.Currency,
CustomerName = x.CustomerName,
FeeName = x.FeeName,
Type = x.FeeType
}).ToList()
};
return form;
}
}
}

@ -463,7 +463,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
{
BusinessTask task = await GetQuery(request.BusinessId, request.BusinessType, request.TaskType).FirstAsync();
if (task == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskNotExists));
if (task.TaskStatus == TaskStatusEnum.Complete)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskCompleted));
//if (task.TaskStatus == TaskStatusEnum.Cancel)
@ -869,16 +869,20 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (callback.FlowStatus == FlowStatusEnum.Reject)
{
var task = await GetQuery(callback.BusinessId, callback.BusinessType, callback.AuditType.Value).FirstAsync();
//创建驳回任务以进行通知
await CreateTaskAsync(new TaskCreationRequest
var request = new TaskCreationRequest
{
BusinessId = callback.BusinessId,
BusinessType = callback.BusinessType,
TaskTypeName = GetRejectedType(callback.AuditType.Value).ToString(),
RecvUserIdList = [task.CreateBy] //通知任务发起人
});
};
//创建驳回任务以进行通知
await CreateTaskAsync(request);
//更新任务描述为驳回原因
await SetTaskBaseDescription(callback.BusinessId, request.TaskType, callback.RejectReason);
remark += ";驳回理由:" + callback.RejectReason;
remark += ";驳回原因" + callback.RejectReason;
}
long userId = long.Parse(User.UserId);

@ -3,6 +3,7 @@ using DS.Module.Core.Data;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Fee.Interface;
using DS.WMS.Core.Fee.Method.ReportProviders;
using DS.WMS.Core.Op.Entity;
using Microsoft.AspNetCore.Mvc;
@ -204,12 +205,16 @@ namespace DS.WMS.FeeApi.Controllers
/// <param name="model">费用记录ID</param>
/// <returns></returns>
[HttpPost, Route("GetPrintInfo")]
public async Task<DataResult<CostAccountingForm>> GetPrintInfoAsync(IdModel model)
public async Task<DataResult<dynamic>> GetPrintInfoAsync(IdModel model)
{
if (model == null || model.Ids?.Length == 0)
return DataResult<CostAccountingForm>.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return DataResult<dynamic>.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return await _feeService.GetPrintInfoAsync((BusinessType)model.BusinessType.Value, model.Ids);
string providerName = model.Value?.ToString();
if (string.IsNullOrEmpty(providerName))
providerName = typeof(CostAccountingReport).AssemblyQualifiedName;
return await _feeService.GetPrintInfoAsync(providerName, (BusinessType)model.BusinessType.Value, model.Ids);
}
/// <summary>

Loading…
Cancel
Save