任务完成或取消前判断当前登陆人是否为所选任务的处理人

dev
zhangxiaofeng 2 months ago
parent c275cf04cf
commit 9325d06ffa

@ -1572,6 +1572,12 @@ public static class MultiLanguageConst
[Description("上传完成,请关注相关任务及订单状态")]
public const string UploadBcThenRunTaskSuccess = "UploadBcThenRunTaskSuccess";
[Description("当前任务非当前登陆人的待处理任务,请检查您是否在所选任务的接收人列表之内,任务流水号:{0}")]
public const string TaskNotHaveAuthorSingle = "TaskNotHaveAuthorSingle";
[Description("所选任务中存在非当前登陆人待处理的任务,请检查您是否在以下任务的接收人列表之内,任务流水号:{0}")]
public const string TaskNotHaveAuthor = "TaskNotHaveAuthor";
#endregion
#region 邮件解析配置

@ -736,7 +736,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
{
await TenantDb.Updateable<SeaExport>().SetColumns(x => x.BusinessStatusName == null)
.Where(x => x.Id == request.BusinessId).ExecuteCommandAsync();
}
}
if (useTransaction)
await TenantDb.Ado.CommitTranAsync();
@ -778,6 +778,22 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (tasks.Exists(x => x.FlowId == null))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FlowNotFound));
//审核前判断是否为此任务的处理人
//var hasAuthor = await ManagerService.HasTaskHandleAuthorityWithBsno(tasks.Select(x => (x.BusinessId, x.TaskType)));
//if (!hasAuthor.Succeeded && hasAuthor.Data?.Count > 0)
//{
// if (tasks.Count == 1)
// {
// return DataResult.Failed(string.Format(
// MultiLanguageConst.GetDescription(MultiLanguageConst.TaskNotHaveAuthorSingle), string.Join("、", hasAuthor.Data)));
// }
// else
// {
// return DataResult.Failed(string.Format(
// MultiLanguageConst.GetDescription(MultiLanguageConst.TaskNotHaveAuthor), string.Join("、", hasAuthor.Data!)));
// }
//}
DataResult result = DataResult.Success;
var flowIds = tasks.Select(x => x.FlowId.Value);
var flowInstances = await Db.Queryable<FlowInstance>().Where(x => flowIds.Contains(x.Id)).ToListAsync();

@ -779,40 +779,40 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <param name="cachePortLoad">起始港缓存</param>
/// <param name="cacheMapPortLoadFunc">起始港缓存映射</param>
/// <returns>起始港对象</returns>
protected async Task<DataResult<CodePortRes>> PlaceReceiptToPortload(string portEnName, List<CodePortRes> cachePortLoad, Func<Task<DataResult<List<MappingPortRes>>>> cacheMapPortLoadFunc)
protected async Task<DataResult<CodePortRes?>> PlaceReceiptToPortload(string portEnName, List<CodePortRes> cachePortLoad, Func<Task<DataResult<List<MappingPortRes>>>> cacheMapPortLoadFunc)
{
CodePortRes portInfo = null;
CodePortRes? portInfo = null;
if (string.IsNullOrEmpty(portEnName))
{
return DataResult<CodePortRes>.FailedData(portInfo);
return DataResult<CodePortRes?>.FailedData(portInfo);
}
// 匹配方式1精准匹配
portInfo = cachePortLoad.FirstOrDefault(x => x.PortName.Equals(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
// 匹配方式2起始模糊匹配
portInfo = cachePortLoad.FirstOrDefault(x => x.PortName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
// 匹配方式3完整模糊匹配
portInfo = cachePortLoad.FirstOrDefault(x => x.PortName.Contains(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
// 匹配方式4精准映射匹配
var mapCachePortLoad = await cacheMapPortLoadFunc();
var map = mapCachePortLoad.Data.FirstOrDefault(x => x.Module == MappingModuleConst.RECEIPT_TO_PORTLOAD
var map = mapCachePortLoad?.Data?.FirstOrDefault(x => x.Module == MappingModuleConst.RECEIPT_TO_PORTLOAD
&& x.MapName.Equals(portEnName, StringComparison.OrdinalIgnoreCase));
if (map != null)
{
portInfo = cachePortLoad.FirstOrDefault(x => x.Id == map.LinkId);
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
}
return DataResult<CodePortRes>.FailedData(portInfo);
return DataResult<CodePortRes?>.FailedData(portInfo);
}
#endregion
@ -824,40 +824,40 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <param name="cachePort">目的港缓存</param>
/// <param name="cacheMapPortFunc">目的港缓存映射</param>
/// <returns>目的港对象</returns>
protected async Task<DataResult<CodePortRes>> PlaceDeliveryToPort(string portEnName, List<CodePortRes> cachePort, Func<Task<DataResult<List<MappingPortRes>>>> cacheMapPortFunc)
protected async Task<DataResult<CodePortRes?>> PlaceDeliveryToPort(string portEnName, List<CodePortRes> cachePort, Func<Task<DataResult<List<MappingPortRes>>>> cacheMapPortFunc)
{
CodePortRes portInfo = null;
CodePortRes? portInfo = null;
if (string.IsNullOrEmpty(portEnName))
{
return DataResult<CodePortRes>.FailedData(portInfo);
return DataResult<CodePortRes?>.FailedData(portInfo);
}
// 匹配方式1精准匹配
portInfo = cachePort.FirstOrDefault(x => x.PortName.Equals(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
// 匹配方式2起始模糊匹配
portInfo = cachePort.FirstOrDefault(x => x.PortName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
// 匹配方式3完整模糊匹配
portInfo = cachePort.FirstOrDefault(x => x.PortName.Contains(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
// 匹配方式4精准映射匹配
var mapCachePort = await cacheMapPortFunc();
var map = mapCachePort.Data.FirstOrDefault(x => x.Module == MappingModuleConst.DELIVERY_TO_PORT
var map = mapCachePort?.Data?.FirstOrDefault(x => x.Module == MappingModuleConst.DELIVERY_TO_PORT
&& x.MapName.Equals(portEnName, StringComparison.OrdinalIgnoreCase));
if (map != null)
{
portInfo = cachePort.FirstOrDefault(x => x.Id == map.LinkId);
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
if (portInfo != null) return DataResult<CodePortRes?>.Success(portInfo);
}
return DataResult<CodePortRes>.FailedData(portInfo);
return DataResult<CodePortRes?>.FailedData(portInfo);
}
#endregion
}

@ -1506,7 +1506,7 @@ namespace DS.WMS.Core.TaskPlat.Method
}
var portInfo = await PlaceReceiptToPortload(taskRouteChangeAdvisoryInfo.READ_PORTLOAD, portCodeList, () => mappingPortService.GetAllList());
if (!portInfo.Succeeded)
if (!portInfo.Succeeded || portInfo.Data == null)
{
logger.LogInformation($"通过收货地城市名称未匹配到港口信息航线船舶截止时间调整的通知Id{taskRouteChangeAdvisoryInfo.Id}");
}
@ -3164,6 +3164,90 @@ namespace DS.WMS.Core.TaskPlat.Method
}
/// <summary>
/// 完成任务(可批量)
/// </summary>
/// <param name="ids">任务主键数组</param>
/// <returns>返回结果</returns>
public async Task<DataResult<TaskManageOrderResultDto>> CompleteTask(long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var userId = long.Parse(user.UserId);
string batchNo = Guid.NewGuid().ToString();
var hasAuthor = await HasTaskHandleAuthority(ids);
if (!hasAuthor.Succeeded && hasAuthor.Data?.Count > 0)
{
if (ids.Length == 1)
{
result.succ = false;
result.msg = string.Format(MultiLanguageConst.GetDescription(MultiLanguageConst.TaskNotHaveAuthorSingle), string.Join("、", hasAuthor.Data));
}
else
{
result.succ = false;
result.msg = string.Format(MultiLanguageConst.GetDescription(MultiLanguageConst.TaskNotHaveAuthor), string.Join("、", hasAuthor.Data!));
}
return DataResult<TaskManageOrderResultDto>.FailedData(result);
}
var taskList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(x => ids.Contains(x.Id)).ToListAsync();
List<TaskManageOrderResultDto> taskRunList = new List<TaskManageOrderResultDto>();
logger.LogInformation("批次={no} ids={ids} 完成任务开始", batchNo, string.Join(",", ids));
var noList = ids.Select((a, idx) => new { no = idx + 1, id = a }).ToList();
foreach (var bk in taskList)
{
var sortNo = noList.FirstOrDefault(a => a.id == bk.Id).no;
taskRunList.Add(await InnerManualTask(batchNo, bk, TaskOperTypeEnum.COMPLETE_TASK, sortNo));
}
result.succ = true;
result.msg = "执行成功";
var downResultList = taskRunList.Select(x => x).ToList();
if (downResultList.Any(x => !x.succ))
{
result.succ = false;
result.msg = "执行失败";
}
else
{
result.succ = true;
result.msg = downResultList.FirstOrDefault().msg;
}
result.ext = downResultList;
var succ = downResultList.Count(x => x.succ);
var fail = downResultList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
return DataResult<TaskManageOrderResultDto>.Success(result);
}
/// <summary>
/// 取消任务(可批量)
@ -3172,12 +3256,30 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <returns>返回结果</returns>
public async Task<DataResult<TaskManageOrderResultDto>> CancelTask(long[] ids)
{
ArgumentNullException.ThrowIfNull(ids);
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var userId = long.Parse(user.UserId);
string batchNo = Guid.NewGuid().ToString();
var hasAuthor = await HasTaskHandleAuthority(ids);
if (!hasAuthor.Succeeded && hasAuthor.Data?.Count > 0)
{
if (ids.Length == 1)
{
result.succ = false;
result.msg = string.Format(MultiLanguageConst.GetDescription(MultiLanguageConst.TaskNotHaveAuthorSingle), string.Join("、", hasAuthor.Data));
}
else
{
result.succ = false;
result.msg = string.Format(MultiLanguageConst.GetDescription(MultiLanguageConst.TaskNotHaveAuthor), string.Join("、", hasAuthor.Data!));
}
return DataResult<TaskManageOrderResultDto>.FailedData(result);
}
var taskList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(x => ids.Contains(x.Id)).ToListAsync();
@ -3493,76 +3595,6 @@ namespace DS.WMS.Core.TaskPlat.Method
return result;
}
/// <summary>
/// 完成任务(可批量)
/// </summary>
/// <param name="ids">任务主键数组</param>
/// <returns>返回结果</returns>
public async Task<DataResult<TaskManageOrderResultDto>> CompleteTask(long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var userId = long.Parse(user.UserId);
string batchNo = Guid.NewGuid().ToString();
var taskList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(x => ids.Contains(x.Id)).ToListAsync();
List<TaskManageOrderResultDto> taskRunList = new List<TaskManageOrderResultDto>();
logger.LogInformation("批次={no} ids={ids} 完成任务开始", batchNo, string.Join(",", ids));
var noList = ids.Select((a, idx) => new { no = idx + 1, id = a }).ToList();
foreach (var bk in taskList)
{
var sortNo = noList.FirstOrDefault(a => a.id == bk.Id).no;
taskRunList.Add(await InnerManualTask(batchNo, bk, TaskOperTypeEnum.COMPLETE_TASK, sortNo));
}
result.succ = true;
result.msg = "执行成功";
var downResultList = taskRunList.Select(x => x).ToList();
if (downResultList.Any(x => !x.succ))
{
result.succ = false;
result.msg = "执行失败";
}
else
{
result.succ = true;
result.msg = downResultList.FirstOrDefault().msg;
}
result.ext = downResultList;
var succ = downResultList.Count(x => x.succ);
var fail = downResultList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
return DataResult<TaskManageOrderResultDto>.Success(result);
}
/// <summary>
/// 领取任务到当前登陆人(可批量)
/// </summary>
@ -3664,9 +3696,6 @@ namespace DS.WMS.Core.TaskPlat.Method
}
/// <summary>
/// 测试用
/// </summary>

Loading…
Cancel
Save