using DS.Module.Core; using DS.WMS.Core.Op.Dtos.TaskInteraction; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; using DS.WMS.Core.Sys.Entity; namespace DS.WMS.Core.Op.Method.TaskInteraction { /// /// 任务日志服务 /// public class TaskLogService : ServiceBase, ITaskLogService { /// /// 初始化 /// /// public TaskLogService(IServiceProvider provider) : base(provider) { } /// /// 读取业务日志 /// /// 业务ID /// 业务类型 /// public async Task>> ReadLogAsync(long id, BusinessType businessType) { var list = await TenantDb.Queryable().Where(x => x.BusinessId == id && x.BusinessType == businessType) .OrderBy(x => x.CreateTime).ToListAsync(); var result = DataResult>.Success(list); result.Count = list.Count; return result; } /// /// 写入任务日志 /// /// /// 备注 /// public async Task WriteLogAsync(TaskUpdateRequest request, string? remark = null) { long userId = long.Parse(User.UserId); string userName = await Db.Queryable().Where(x => x.Id == userId).Select( x => x.UserName).FirstAsync(); BusinessTaskLog taskLog = new BusinessTaskLog { ActionType = ActionType.StatusChanged, BusinessId = request.BusinessId, BusinessType = request.BusinessType, CreateBy = long.Parse(User.UserId), CreateTime = DateTime.Now, TaskStatus = request.TaskStatus, TaskType = request.TaskType, Remark = remark, RecvUsers = userName }; await WriteLogAsync(taskLog); } /// /// 写入任务日志 /// /// /// 备注 /// public async Task WriteLogAsync(BusinessTask task, string? remark = null) { string userNames = string.Empty; if (task.RecvUserIdArray?.Length > 0) { var list = await Db.Queryable().Where(x => task.RecvUserIdArray.Contains(x.Id)).Select( x => x.UserName).ToListAsync(); userNames = string.Join(",", list); } BusinessTaskLog taskLog = new BusinessTaskLog { 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 }; await WriteLogAsync(taskLog); } /// /// 写入任务日志 /// /// 任务日志 /// 为null /// public async Task WriteLogAsync(params BusinessTaskLog[] logs) { ArgumentNullException.ThrowIfNull(logs, nameof(logs)); await TenantDb.Insertable(logs).ExecuteCommandAsync(); } } }