|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 任务日志服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TaskLogService : ServiceBase, ITaskLogService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="provider"></param>
|
|
|
|
|
public TaskLogService(IServiceProvider provider) : base(provider)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取业务日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">业务ID</param>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<BusinessTaskLog>>> ReadLogAsync(long id, BusinessType businessType)
|
|
|
|
|
{
|
|
|
|
|
var list = await TenantDb.Queryable<BusinessTaskLog>().Where(x => x.BusinessId == id && x.BusinessType == businessType)
|
|
|
|
|
.OrderBy(x => x.CreateTime).ToListAsync();
|
|
|
|
|
var result = DataResult<List<BusinessTaskLog>>.Success(list);
|
|
|
|
|
result.Count = list.Count;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入任务日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task WriteLogAsync(TaskUpdateRequest request, string? remark = null)
|
|
|
|
|
{
|
|
|
|
|
long userId = long.Parse(User.UserId);
|
|
|
|
|
string userName = await Db.Queryable<SysUser>().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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入任务日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="task"></param>
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task WriteLogAsync(BusinessTask task, string? remark = null)
|
|
|
|
|
{
|
|
|
|
|
string userNames = string.Empty;
|
|
|
|
|
if (task.RecvUserIdArray?.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var list = await Db.Queryable<SysUser>().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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入任务日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logs">任务日志</param>
|
|
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="logs"/>为null</exception>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task WriteLogAsync(params BusinessTaskLog[] logs)
|
|
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(logs, nameof(logs));
|
|
|
|
|
|
|
|
|
|
await TenantDb.Insertable(logs).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|