using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using HH.WCS.Mobox3.Template.Entity;
|
using HH.WCS.Mobox3.Template.Util.Helper;
|
|
namespace HH.WCS.Mobox3.Template.Controller.Service;
|
|
/// <summary>
|
/// 任务
|
/// </summary>
|
public static class TaskService
|
{
|
/// <summary>
|
/// 创建作业
|
/// </summary>
|
/// <returns></returns>
|
public static void CreateTask()
|
{
|
// 1. 查询任务是否已创建
|
var operation = AdoSqlHelper<Operation>.QueryFirstByDecs(p => p.N_B_STATE == 0, p => p.T_CREATE);
|
|
if (operation == null)
|
{
|
return;
|
}
|
|
// 任务存在,根据任务类型做不同的操作
|
if (operation.N_TYPE == 1)
|
{
|
var inputLocation = InputLocation(operation.S_CNTR_CODE);
|
|
if (inputLocation == null)
|
{
|
LogHelper.Info($"当前容器未绑定物料,请检查", "出入库流程日志");
|
return;
|
}
|
|
// 任务
|
var task = new Task
|
{
|
// 作业编码
|
S_OP_CODE = operation.S_CODE,
|
// 任务号
|
S_CODE = HelperMethod.GenerateTaskNo("任务号", "TA"),
|
// 任务类型
|
N_TYPE = operation.N_TYPE,
|
// 任务类型
|
S_TYPE = Task.GetStateType(operation.N_TYPE),
|
// 起点货位
|
S_START_LOC = operation.S_START_LOC,
|
// 终点货位
|
S_END_LOC = inputLocation.S_CODE,
|
// 容器编码
|
S_CNTR_CODE = operation.S_CNTR_CODE,
|
};
|
|
// 修改作业状态为执行中
|
operation.N_B_STATE = 1;
|
operation.S_B_STATE = "执行";
|
operation.T_START_TIME = DateTime.Now;
|
|
var querySqlSugarClient = AdoSqlHelper<object>.QuerySqlSugarClient();
|
|
try
|
{
|
querySqlSugarClient.BeginTran();
|
AdoSqlHelper<Task>.AddFirstTran(querySqlSugarClient, task);
|
AdoSqlHelper<Operation>.UpdateFirstTran(querySqlSugarClient, operation,
|
p => new { p.N_B_STATE, p.S_B_STATE, p.T_START_TIME });
|
|
querySqlSugarClient.CommitTran();
|
}
|
catch (Exception e)
|
{
|
if (operation.N_TYPE == 1)
|
{
|
LogHelper.Info($"作业号为:{operation.S_CODE}的任务创建失败", "出入库流程日志");
|
}
|
else
|
{
|
LogHelper.Info($"作业号为:{operation.S_CODE}的任务创建失败", "出入库流程日志");
|
}
|
querySqlSugarClient.RollbackTran();
|
}
|
}
|
}
|
|
/// <summary>
|
/// 入库货位分配
|
/// </summary>
|
/// <returns></returns>
|
private static Location InputLocation(string container)
|
{
|
var cntrItemDetail = AdoSqlHelper<CntrItemDetail>.QueryFirst(p => p.S_CNTR_CODE == container);
|
|
if (cntrItemDetail == null)
|
{
|
return null;
|
}
|
|
return AdoSqlHelper<Location>.QueryInputLocation(cntrItemDetail.S_ITEM_CODE);
|
}
|
}
|