任务台相关接口

usertest
zhangxiaofeng 4 months ago
parent 31ffe6ae7f
commit 7f00cc5114

@ -1408,4 +1408,9 @@ public static class MultiLanguageConst
[Description("此类型的任务已存在")]
public const string Task_Exists = "Task_Exists";
#endregion
#region 任务台相关
[Description("当前状态是{0}不能执行完成")]
public const string TaskCannotCompleteWhenStatusMismatch = "TaskCannotCompleteWhenStatusMismatch";
#endregion
}

@ -0,0 +1,16 @@
using System.ComponentModel;
namespace DS.Module.Core
{
/// <summary>
/// 任务完成类型枚举
/// </summary>
public enum TaskCompleteDealEnum
{
/// <summary>
/// 手工完成
/// </summary>
[Description("手工完成")]
MANUAL,
}
}

@ -0,0 +1,26 @@
using System.ComponentModel;
namespace DS.Module.Core
{
/// <summary>
/// 任务操作类型枚举
/// </summary>
public enum TaskOperTypeEnum
{
/// <summary>
/// 完成任务
/// </summary>
[Description("完成任务")]
COMPLETE_TASK,
/// <summary>
/// 取消任务
/// </summary>
[Description("取消任务")]
CANCEL_TASK,
/// <summary>
/// 挂起任务
/// </summary>
[Description("挂起任务")]
PENDING_TASK,
}
}

@ -98,20 +98,20 @@ namespace DS.WMS.Core.TaskPlat.Entity
/// <summary>
/// 是否异常 1-异常 0-未异常
/// </summary>
[SugarColumn(ColumnDescription = "是否异常 1-异常 0-未异常", IsNullable = true)]
public int? IS_EXCEPT { get; set; }
[SugarColumn(ColumnDescription = "是否异常 1-异常 0-未异常", IsNullable = false)]
public int IS_EXCEPT { get; set; }
/// <summary>
/// 是否公共 0-非公共 1-公共(当无法确认任务所属人的情况被默认为公共)
/// </summary>
[SugarColumn(ColumnDescription = "是否公共 0-非公共 1-公共(当无法确认任务所属人的情况被默认为公共)", IsNullable = true)]
public int? IS_PUBLIC { get; set; }
[SugarColumn(ColumnDescription = "是否公共 0-非公共 1-公共(当无法确认任务所属人的情况被默认为公共)", IsNullable = false)]
public int IS_PUBLIC { get; set; }
/// <summary>
/// 是否完成 1-已完成 0-未完成
/// </summary>
[SugarColumn(ColumnDescription = "是否完成 1-已完成 0-未完成", IsNullable = true)]
public int? IS_COMPLETE { get; set; }
[SugarColumn(ColumnDescription = "是否完成 1-已完成 0-未完成", IsNullable = false)]
public int IS_COMPLETE { get; set; }
/// <summary>
/// 任务启动时间

@ -1,4 +1,5 @@
using DS.Module.Core;
using DS.Module.DjyServiceStatus;
using DS.WMS.Core.TaskPlat.Dtos;
using Microsoft.AspNetCore.Http;
@ -6,6 +7,13 @@ namespace DS.WMS.Core.TaskPlat.Interface
{
public interface ITaskManageService
{
/// <summary>
/// 取消任务(可批量)
/// </summary>
/// <param name="ids">任务主键数组</param>
/// <returns>返回结果</returns>
Task<DataResult<TaskManageOrderResultDto>> CancelTask(long[] ids);
/// <summary>
/// 获取登陆人相关的任务统计信息
/// </summary>

@ -14,6 +14,7 @@ using Newtonsoft.Json;
using SqlSugar;
using System.Runtime.InteropServices;
using DS.Module.Core.Extensions;
using DS.Module.DjyServiceStatus;
namespace DS.WMS.Core.TaskPlat.Method
{
@ -680,11 +681,18 @@ namespace DS.WMS.Core.TaskPlat.Method
whereList = tenantDb.Utilities.JsonToConditionalModels(querySearch.QueryCondition);
}
// 格式化参数
TaskBaseTypeEnum? taskType = null;
if (Enum.TryParse(typeof(TaskBaseTypeEnum), querySearch.OtherQueryCondition?.TaskType, out object? temp))
{
taskType = (TaskBaseTypeEnum)temp;
};
TaskStatLevelEnum? taskStatLevel = null;
if (Enum.TryParse(typeof(TaskStatLevelEnum), querySearch.OtherQueryCondition?.TaskCategory, out object? tempStat))
{
taskStatLevel = (TaskStatLevelEnum)tempStat;
};
var userId = long.Parse(user.UserId);
DataResult<List<dynamic>> result;
@ -696,6 +704,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskBCInfo>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
Id = t.Id.SelectAll(),
@ -783,6 +794,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskSiSubmitted>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -836,6 +850,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskPerBillBase>((t, a, bc) => t.Id == bc.TASK_PKID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -859,6 +876,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskTruck>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -923,6 +943,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskCutDateChangeInfo>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -942,6 +965,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskRollingNomination>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -967,6 +993,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskDraftInfo>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -989,6 +1018,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskPodDischargeGateoutFull>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -1007,6 +1039,9 @@ namespace DS.WMS.Core.TaskPlat.Method
.LeftJoin<TaskCautionNotice>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -1034,9 +1069,12 @@ namespace DS.WMS.Core.TaskPlat.Method
case TaskBaseTypeEnum.ROUTE_CUT_CHANGE:
{
result = await tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskRouteChangeAdvisory>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.LeftJoin<TaskRouteChangeAdvisory>((t, a, bc) => t.Id == bc.TASK_ID)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
@ -1067,6 +1105,9 @@ namespace DS.WMS.Core.TaskPlat.Method
result = await tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.Where(whereList)
.Where((t, a) => a.UserId == userId || t.CreateBy == userId)
.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.Select<dynamic>(t => t)
.ToQueryPageAsync(querySearch.PageCondition);
return result;
@ -1315,9 +1356,6 @@ namespace DS.WMS.Core.TaskPlat.Method
return DataResult<TaskUserStatResultInfo>.Success(resultInfo);
}
#region 私有方法
/// <summary>
@ -1433,6 +1471,192 @@ namespace DS.WMS.Core.TaskPlat.Method
return fileType;
}
#endregion
/// <summary>
/// 取消任务(可批量)
/// </summary>
/// <param name="ids">任务主键数组</param>
/// <returns>返回结果</returns>
public async Task<DataResult<TaskManageOrderResultDto>> CancelTask(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>()
.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.CANCEL_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);
}
#region 单票执行任务
/// <summary>
/// 单票执行任务
/// </summary>
/// <param name="batchNo">批次号</param>
/// <param name="model">任务详情</param>
/// <param name="taskOperTypeEnum">操作类型</param>
/// <param name="sortNo">顺序号</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> InnerManualTask(string batchNo, TaskBaseInfo model,
TaskOperTypeEnum taskOperTypeEnum, int sortNo)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
result.bno = model.TASK_NO;
try
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var userId = long.Parse(user.UserId);
if (taskOperTypeEnum == TaskOperTypeEnum.COMPLETE_TASK)
{
if (model.TASK_TYPE == TaskBaseTypeEnum.TRUCK_DISPATCH.ToString())
{
if (model.STATUS == TaskStatusEnum.Cancel.ToString())
{
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskCannotCompleteWhenStatusMismatch)), TaskStatusEnum.Cancel.EnumDescription()));
}
}
if (model.TASK_TYPE == TaskBaseTypeEnum.CANCELLATION.ToString())
{
//收到订舱已被取消邮件后生成的任务,如果点击完成,(订舱状态变为【退舱】,注意这里还需要确认)
}
model.COMPLETE_DATE = DateTime.Now;
model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.EnumDescription();
model.IS_COMPLETE = 1;
model.STATUS = TaskStatusEnum.Complete.ToString();
model.STATUS_NAME = TaskStatusEnum.Complete.EnumDescription();
await tenantDb.Updateable(model).UpdateColumns(it => new
{
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.IS_COMPLETE,
it.STATUS,
it.STATUS_NAME,
it.UpdateBy,
it.UpdateTime,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else if (taskOperTypeEnum == TaskOperTypeEnum.CANCEL_TASK)
{
if (model.TASK_TYPE == TaskBaseTypeEnum.CHANGE_SHIP.ToString())
{
model.STATUS = TaskStatusEnum.Cancel.ToString();
model.STATUS_NAME = TaskStatusEnum.Cancel.EnumDescription();
await tenantDb.Updateable(model).UpdateColumns(it => new
{
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.IS_COMPLETE,
it.STATUS,
it.STATUS_NAME,
it.UpdateBy,
it.UpdateTime,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else if (model.TASK_TYPE == TaskBaseTypeEnum.ABORT_CHANGE_SHIP.ToString())
{
/*
1.
2.
3.
*/
// 查询同票主单的是否有未处理的换船通知
// _taskBaseInfoRepository.AsQueryable().Where(t=>t.MBL_NO.Equals(taskBaseInfo.MBL_NO) && )
}
else
{
model.STATUS = TaskStatusEnum.Cancel.ToString();
model.STATUS_NAME = TaskStatusEnum.Cancel.EnumDescription();
await tenantDb.Updateable(model).UpdateColumns(it => new
{
it.STATUS,
it.STATUS_NAME,
it.UpdateBy,
it.UpdateTime,
it.UpdateUserName
}).ExecuteCommandAsync();
}
}
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = ex.Message;
}
return result;
}
#endregion
}
}

@ -1,5 +1,6 @@
using DS.Module.Core;
using DS.Module.Core.Attributes;
using DS.Module.DjyServiceStatus;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Interface;
using Microsoft.AspNetCore.Authorization;
@ -95,14 +96,12 @@ public class TaskManageController : ApiController
/// <param name="Ids">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("CancelTask")]
public async Task<DataResult<TaskUserStatResultInfo>> CancelTask([FromBody] string[] Ids)
public async Task<DataResult<TaskManageOrderResultDto>> CancelTask([FromBody] long[] Ids)
{
return default;
//var result = await taskManageService.GetCurrentTotalStat(isReCalc);
//return result;
var result = await taskManageService.CancelTask(Ids);
return result;
}
/// <summary>
/// 获取任务台相关的枚举类型的值
/// </summary>
@ -136,6 +135,8 @@ public class TaskManageController : ApiController
return DataResult.Success(result);
}
// /TaskManage/CreateBCTaskJob
// /TaskManage/CreateDRAFTTaskJob
// /TaskManage/CreateAdvisoryTaskJob

Loading…
Cancel
Save