业务任务表继续自默认基类

dev
嵇文龙 2 days ago
parent f51de4a001
commit b6288dbd5e

@ -1,4 +1,5 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Op.Entity;
using SqlSugar;
@ -9,14 +10,8 @@ namespace DS.WMS.Core.TaskInteraction.Entity
/// 业务任务交互表
/// </summary>
[SugarTable("business_task", "业务任务交互表")]
public class BusinessTask
public class BusinessTask : BaseModelV2<long>
{
/// <summary>
/// ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 上级任务ID
/// </summary>
@ -78,36 +73,6 @@ namespace DS.WMS.Core.TaskInteraction.Entity
public long[] RecvUserIdArray => RecvUsers.IsNullOrEmpty() ? [] :
RecvUsers.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnDescription = "创建人", IsNullable = false)]
public long CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnDescription = "创建时间", IsNullable = false)]
public DateTime CreateTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
[SugarColumn(ColumnDescription = "更新人", IsNullable = true)]
public long? UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[SugarColumn(ColumnDescription = "更新时间", IsNullable = true)]
public DateTime? UpdateTime { get; set; }
/// <summary>
/// 审批驳回理由
/// </summary>
[SugarColumn(ColumnDescription = "审批驳回理由", Length = 200, IsNullable = true)]
public string? RejectReason { get; set; }
/// <summary>
/// 任务步骤
/// </summary>

@ -86,6 +86,15 @@ namespace DS.WMS.Core.TaskInteraction.Interface
/// <returns></returns>
Task<DataResult> SendAsync(MailDraft draft);
/// <summary>
/// 根据任务类型的默认配置创建草稿
/// </summary>
/// <param name="task">任务信息</param>
/// <param name="templateModel">模板数据</param>
/// <param name="saveDraft">是否保存草稿</param>
/// <returns></returns>
Task<DataResult<MailDraft>> CreateDraftAsync(BusinessTask task, MailTemplateModel? templateModel = null, bool saveDraft = false);
/// <summary>
/// 根据模板配置创建草稿
/// </summary>

@ -34,6 +34,14 @@ namespace DS.WMS.Core.TaskInteraction.Interface
/// <returns></returns>
Task WriteLogAsync(BusinessTask task, string? remark = null);
/// <summary>
/// 写入任务日志
/// </summary>
/// <param name="remark">备注</param>
/// <param name="tasks">任务</param>
/// <returns></returns>
Task WriteLogAsync(string? remark = null, params BusinessTask[] tasks);
/// <summary>
/// 写入任务日志
/// </summary>

@ -228,13 +228,13 @@ namespace DS.WMS.Core.TaskInteraction.Method
task.UpdateBy = long.Parse(User.UserId);
task.UpdateTime = DateTime.Now;
task.RejectReason = request.RejectReason;
task.Note = request.RejectReason;
//更新当前任务状态
task.TaskStatus = request.TaskStatus;
await TenantDb.Updateable(task).UpdateColumns(x => new
{
x.TaskStatus,
x.RejectReason,
x.Note,
x.UpdateBy,
x.UpdateTime
}).ExecuteCommandAsync();

@ -15,11 +15,13 @@ using DS.WMS.Core.TaskInteraction.Interface;
using Fasterflect;
using HtmlAgilityPack;
using Masuit.Tools;
using Masuit.Tools.Systems;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using RazorEngineCore;
using SqlSugar;
namespace DS.WMS.Core.TaskInteraction.Method
{
@ -578,11 +580,30 @@ namespace DS.WMS.Core.TaskInteraction.Method
return await SendAsync(result.Data!);
}
/// <summary>
/// 根据任务类型的默认配置创建草稿
/// </summary>
/// <param name="task">任务信息</param>
/// <param name="templateModel">模板数据</param>
/// <param name="saveDraft">是否保存草稿</param>
/// <returns></returns>
public async Task<DataResult<MailDraft>> CreateDraftAsync(BusinessTask task, MailTemplateModel? templateModel = null, bool saveDraft = false)
{
var mailConfig = await TenantDb.Queryable<BusinessTaskMail>()
.Includes(x => x.Sender).Includes(x => x.Receivers).Includes(x => x.CC).Includes(x => x.Attachments)
.Where(x => SqlFunc.Subqueryable<TaskMailRelation>().Where(y => x.Id == y.MailId && y.TaskType == task.TaskType && y.IsDefault).Any())
.FirstAsync();
if (mailConfig == null)
return DataResult<MailDraft>.Failed($"无法获取【{task.TaskType.GetDescription()}】的默认邮件模板配置");
return await CreateDraftAsync(task, mailConfig, templateModel, saveDraft);
}
/// <summary>
/// 根据模板配置创建草稿
/// </summary>
/// <param name="mailConfig">邮件配置</param>
/// <param name="task">任务信息</param>
/// <param name="mailConfig">邮件配置</param>
/// <param name="templateModel">模板数据</param>
/// <param name="saveDraft">是否保存草稿</param>
/// <returns></returns>

@ -1,11 +1,11 @@
using DS.Module.Core;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskInteraction.Dtos;
using DS.WMS.Core.TaskInteraction.Entity;
using DS.WMS.Core.TaskInteraction.Interface;
using DS.WMS.Core.TaskPlat.Dtos;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
namespace DS.WMS.Core.TaskInteraction.Method
{
@ -14,7 +14,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
/// </summary>
public class PreAlertTaskService : TaskService, IPreAlertTaskService
{
const TaskBaseTypeEnum TASK_TYPE = TaskBaseTypeEnum.PRE_ALERT;
IMailTemplateService mailTemplateService;
ITaskLogService logService;
/// <summary>
/// 初始化
@ -22,6 +23,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
/// <param name="provider"></param>
public PreAlertTaskService(IServiceProvider provider) : base(provider)
{
mailTemplateService = provider.GetRequiredService<IMailTemplateService>();
logService = provider.GetRequiredService<ITaskLogService>();
}
/// <summary>
@ -72,7 +75,9 @@ namespace DS.WMS.Core.TaskInteraction.Method
s.Id,
s.CustomerNo,
s.CustomerId,
s.BLConfirmationId,
s.BLConfirmationId, //提单确认方
s.AgentId, //国外代理
s.IssueType,
s.IssuingWay,
s.MBLNO,
s.ETD,
@ -123,7 +128,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
foreach (var task in taskList)
{
var order = orders.Find(s => s.Id == task.BusinessId);
var request2 = new TaskCreationRequest
var request2 = new TaskCreationRequest //委托单位PA
{
BusinessId = task.BusinessId,
BusinessType = task.BusinessType,
@ -151,7 +156,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
if ((order.SourceName != "CIF-自揽货" && order.SourceDetailName != "WSL Member") || (order.SourceName != "CIF-自揽货" && order.SourceDetailName != "国外同行"))
{
var request3 = new TaskCreationRequest
var request3 = new TaskCreationRequest //国外代理PA
{
BusinessId = task.BusinessId,
BusinessType = task.BusinessType,
@ -180,7 +185,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
if (order.IssuingWay == "zd" && order.CustomerId != order.BLConfirmationId)
{
var request4 = new TaskCreationRequest
var request4 = new TaskCreationRequest //提单确认方PA
{
BusinessId = task.BusinessId,
BusinessType = task.BusinessType,
@ -209,6 +214,58 @@ namespace DS.WMS.Core.TaskInteraction.Method
}
await TenantDb.Fastest<BusinessTask>().BulkCopyAsync(subTaskList);//保存子任务
var allTasks = taskList.Union(subTaskList).ToArray();
await logService.WriteLogAsync(string.Empty, allTasks);
var unionIds = orders.Select(x => x.Id).Union(bills.Select(x => x.Id)); //合并订单ID与分单ID
var opFiles = await TenantDb.Queryable<OpFile>().Where(x => unionIds.Contains(x.LinkId))
.Select(x => new
{
x.LinkId,
x.TypeCode,
x.FileName,
x.FilePath
}).ToListAsync();
List<MailDraft> mailDrafts = [];
foreach (var task in subTaskList)
{
var draftResult = await mailTemplateService.CreateDraftAsync(task);
if (!draftResult.Succeeded)
{
await LogService.WriteLogAsync(task, "未能创建默认草稿,错误消息:" + draftResult.Message);
continue;
}
draftResult.Data.TaskId = task.Id;
var order = orders.Find(x => x.Id == task.BusinessId);
string typeCode = string.Empty;
switch (order.IssueType)
{
case "正本":
typeCode = "OringinalBill_Mbl"; //正本提单扫描件
break;
case "SWB":
typeCode = "swb";
break;
case "EBL":
typeCode = "OringinalBill_Mbl";
break;
}
var opFile = opFiles.Find(x => x.LinkId == order.Id && x.TypeCode == typeCode);
opFile ??= opFiles.Find(x => x.LinkId == order.Id && x.TypeCode == "format_sheet");
if (opFile == null) //获取不到订单附件则记录错误日志
{
}
mailDrafts.Add(draftResult.Data);
}
if (mailDrafts.Count > 0)
await TenantDb.InsertNav(mailDrafts).Include(x => x.Attaches).ExecuteCommandAsync();
if (useTransaction)
await TenantDb.Ado.CommitTranAsync();
@ -220,9 +277,6 @@ namespace DS.WMS.Core.TaskInteraction.Method
if (useTransaction)
await TenantDb.Ado.RollbackTranAsync();
if (result.Data is FlowInstance instance)
await Db.Deleteable(instance).ExecuteCommandAsync();
await ex.LogAsync(Db);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}

@ -72,28 +72,51 @@ namespace DS.WMS.Core.TaskInteraction.Method
/// <returns></returns>
public async Task WriteLogAsync(BusinessTask task, string? remark = null)
{
string userNames = string.Empty;
if (task.RecvUserIdArray?.Length > 0)
await WriteLogAsync(remark, task);
}
/// <summary>
/// 写入任务日志
/// </summary>
/// <param name="remark">备注</param>
/// <param name="tasks">任务</param>
/// <returns></returns>
public async Task WriteLogAsync(string? remark = null, params BusinessTask[] tasks)
{
var ids = tasks.SelectMany(x => x.RecvUserIdArray).Distinct();
var list = await Db.Queryable<SysUser>().Where(x => ids.Contains(x.Id)).Select(x => new
{
var list = await Db.Queryable<SysUser>().Where(x => task.RecvUserIdArray.Contains(x.Id)).Select(
x => x.UserName).ToListAsync();
userNames = string.Join(",", list);
}
x.Id,
x.UserName
}).ToListAsync();
BusinessTaskLog taskLog = new BusinessTaskLog
BusinessTaskLog[] logs = new BusinessTaskLog[tasks.Length];
var dtNow = DateTime.Now;
for (int i = 0; i < tasks.Length; i++)
{
ActionType = ActionType.Create,
BusinessId = task.BusinessId,
BusinessType = task.BusinessType,
CreateBy = long.Parse(User.UserId),
CreateTime = DateTime.Now,
RecvUsers = userNames,
TaskStatus = task.TaskStatus,
TaskType = task.TaskType,
Remark = remark
};
var task = tasks[i];
BusinessTaskLog taskLog = new()
{
ActionType = ActionType.Create,
BusinessId = task.BusinessId,
BusinessType = task.BusinessType,
CreateBy = UserId,
CreateTime = dtNow,
TaskStatus = task.TaskStatus,
TaskType = task.TaskType,
Remark = remark
};
await WriteLogAsync(taskLog);
if (task.RecvUserIdArray?.Length > 0)
{
var userNames = list.Where(x => task.RecvUserIdArray.Contains(x.Id)).Select(x => x.UserName);
taskLog.RecvUsers = string.Join(",", userNames);
}
logs[i] = taskLog;
}
await WriteLogAsync(logs);
}
/// <summary>

@ -345,9 +345,6 @@ namespace DS.WMS.Core.TaskInteraction.Method
if (useTransaction)
await TenantDb.Ado.RollbackTranAsync();
if (result.Data is FlowInstance instance)
await Db.Deleteable(instance).ExecuteCommandAsync();
await ex.LogAsync(Db);
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
@ -460,13 +457,13 @@ namespace DS.WMS.Core.TaskInteraction.Method
task.UpdateBy = long.Parse(User.UserId);
task.UpdateTime = DateTime.Now;
task.RejectReason = request.RejectReason;
task.Note = request.RejectReason;
//更新当前任务状态
task.TaskStatus = request.TaskStatus;
await TenantDb.Updateable(task).UpdateColumns(x => new
{
x.TaskStatus,
x.RejectReason,
x.Note,
x.UpdateBy,
x.UpdateTime
}).ExecuteCommandAsync();

Loading…
Cancel
Save