#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_TaskInfoService
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Enums;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_TaskInfoService
|
{
|
public class TaskExecuteDetailService : ServiceBase<Dt_TaskExecuteDetail, ITaskExecuteDetailRepository>, ITaskExecuteDetailService
|
{
|
private readonly ITaskRepository _taskRepository;
|
|
public TaskExecuteDetailService(ITaskExecuteDetailRepository BaseDal, ITaskRepository taskRepository) : base(BaseDal)
|
{
|
_taskRepository = taskRepository;
|
}
|
|
public void AddTaskExecuteDetail(int taskId, int taskNum, int taskState, string description = "", bool isManual = false)
|
{
|
try
|
{
|
bool isNormal = true;
|
;
|
if (Enum.TryParse(typeof(TaskOutStatusEnum), taskState.ToString(), out object? result))
|
{
|
if ((int)(TaskOutStatusEnum)result > (int)TaskOutStatusEnum.OutFinish)
|
isNormal = false;
|
|
}
|
else if (Enum.TryParse(typeof(TaskInStatusEnum), taskState.ToString(), out result))
|
{
|
if ((int)(TaskOutStatusEnum)result > (int)TaskOutStatusEnum.OutFinish)
|
isNormal = false;
|
}
|
else if (Enum.TryParse(typeof(TaskRelocationTypeEnum), taskState.ToString(), out result))
|
{
|
|
}
|
else if (Enum.TryParse(typeof(TaskOtherTypeEnum), taskState.ToString(), out result))
|
{
|
|
}
|
Dt_TaskExecuteDetail taskExecuteDetail = new Dt_TaskExecuteDetail()
|
{
|
IsManual = isManual,
|
IsNormal = isNormal,
|
TaskNum = taskNum,
|
TaskId = taskId,
|
TaskState = taskState,
|
Description = description
|
};
|
BaseDal.AddData(taskExecuteDetail);
|
}
|
catch (Exception ex)
|
{
|
|
}
|
}
|
|
public WebResponseContent GetDetailInfo(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
int active = -1;
|
List<object> list = new List<object>();
|
|
List<int> steps = new List<int>();
|
Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
|
if (task != null)
|
{
|
|
if (!int.TryParse(Enum.Parse<TaskOutboundTypeEnum>(task.TaskType.ToString()).ToString(), out int result))
|
{
|
steps = Enum.GetValues(typeof(TaskOutStatusEnum)).Cast<int>().Where(x => x <= (int)TaskOutStatusEnum.OutFinish).ToList();
|
|
foreach (var item in steps)
|
{
|
object obj;
|
FieldInfo? fieldInfo = typeof(TaskOutStatusEnum).GetField(((TaskOutStatusEnum)item).ToString());
|
DescriptionAttribute? descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
if (descriptionAttribute != null)
|
{
|
obj = new { title = item, description = descriptionAttribute.Description };
|
}
|
else
|
{
|
obj = new { title = item, description = ((TaskOutStatusEnum)item).ToString() };
|
}
|
list.Add(obj);
|
}
|
}
|
else if (!int.TryParse(Enum.Parse<TaskInboundTypeEnum>(task.TaskType.ToString()).ToString(), out result))
|
{
|
steps = Enum.GetValues(typeof(TaskInStatusEnum)).Cast<int>().Where(x => x <= (int)TaskInStatusEnum.InFinish).ToList();
|
foreach (var item in steps)
|
{
|
object obj;
|
FieldInfo? fieldInfo = typeof(TaskInStatusEnum).GetField(((TaskInStatusEnum)item).ToString());
|
DescriptionAttribute? descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
if (descriptionAttribute != null)
|
{
|
obj = new { title = item, description = descriptionAttribute.Description };
|
}
|
else
|
{
|
obj = new { title = item, description = ((TaskInStatusEnum)item).ToString() };
|
}
|
list.Add(obj);
|
}
|
}
|
else if (!int.TryParse(Enum.Parse<TaskRelocationTypeEnum>(task.TaskType.ToString()).ToString(), out result))
|
{
|
//todo 调用WMS移库完成
|
}
|
else if (!int.TryParse(Enum.Parse<TaskOtherTypeEnum>(task.TaskType.ToString()).ToString(), out result))
|
{
|
|
}
|
else
|
{
|
throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】");
|
}
|
|
List<int> details = BaseDal.QueryData(x => x.TaskNum == taskNum && x.TaskState <= task.TaskState).GroupBy(x => x.TaskState).Select(x => x.Key).ToList();
|
if (details.Count == 0)
|
{
|
active = steps.IndexOf(task.TaskState) + 1;
|
if (active < steps.Count)
|
{
|
active -= 1;
|
}
|
}
|
else
|
{
|
if (details.Count == steps.Count)
|
{
|
active = details.Count;
|
}
|
else
|
{
|
active = details.Count - 1;
|
}
|
}
|
}
|
|
content = WebResponseContent.Instance.OK(data: new { active, list });
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return content;
|
}
|
|
public WebResponseContent GetDetailDatas(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
|
Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
|
if (task != null)
|
{
|
List<Dt_TaskExecuteDetail> taskExecuteDetails = BaseDal.QueryData(x => x.TaskId == task.TaskId, new Dictionary<string, SqlSugar.OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), SqlSugar.OrderByType.Asc } });
|
|
content = WebResponseContent.Instance.OK(data: taskExecuteDetails);
|
}
|
else
|
{
|
content = WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
|
}
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return content;
|
}
|
}
|
}
|