using System;
|
using HH.WCS.Mobox3.RiDong.dto;
|
using HH.WCS.Mobox3.RiDong.generalMethod;
|
using HH.WCS.Mobox3.RiDong.models;
|
using HH.WCS.Mobox3.RiDong.util;
|
using HH.WCS.Mobox3.RiDong.wms;
|
|
namespace HH.WCS.Mobox3.RiDong.apiMethod;
|
|
/// <summary>
|
/// 综合性方法类
|
/// </summary>
|
public static class SynthesizeService
|
{
|
/// <summary>
|
/// 创建作业
|
/// <remarks>存在中转货位(入库、出库、盘点入、盘点出)</remarks>
|
/// </summary>
|
/// <param name="input">作业模型</param>
|
/// <returns></returns>
|
public static ApiModel.SimpleResult AddOperation(OperationDto input)
|
{
|
var result = new ApiModel.SimpleResult();
|
|
int group = 0;
|
|
// 查询当前使用的容器
|
var container = AdoSqlMethod<Container>.QueryFirst(p => p.S_CODE == input.cntrCode);
|
|
// 判断当前容器是否存在
|
if (container == null)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "当前容器不存在";
|
Console.WriteLine("当前容器不存在");
|
return result;
|
}
|
|
LogHelper.Info($"托盘{input.cntrCode}生成任务,该托盘的类型为{container.S_TYPE}");
|
|
// 判断当前托盘是否有未完成的任务
|
if (AdoSqlMethod<Operation>.QueryCount(p => p.S_CNTR_CODE == input.cntrCode && p.N_B_STATE < 2) > 0)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "当前容器已存在任务,请勿重复下发任务";
|
Console.WriteLine("当前容器已存在任务,请勿重复下发任务");
|
return result;
|
}
|
|
// 如果是入库,则需要计算入库的货位数据
|
if (input.taskType == 1 || input.taskType == 3)
|
{
|
// 判断是否有容器货位表
|
if (AdoSqlMethod<LocCntrRel>.QueryCount(p => p.S_CNTR_CODE == input.cntrCode) > 0)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "当前容器已在立库,请勿重复下发任务";
|
Console.WriteLine("当前容器已在立库,请勿重复下发任务");
|
return result;
|
}
|
|
// 根据容器类型以及容器对应的库区找到对应的货位信息
|
var location = LocationMethod.QueryStereoscopicStorehouseLocation(container.S_TYPE);
|
|
if (location == null)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "无可用货位";
|
Console.WriteLine("无可用货位");
|
return result;
|
}
|
|
// 重新计算终点、赋值
|
input.endLocation = location.S_CODE;
|
group = location.N_ROADWAY;
|
}
|
else
|
{
|
var location = AdoSqlMethod<Location>.QueryFirst(p=>p.S_CODE == input.startLocation);
|
group = location.N_ROADWAY;
|
}
|
|
// 获取中转货位
|
var queryRandomLocation = LocationMethod.QueryLocation(input);
|
|
// 为空
|
if (queryRandomLocation == null)
|
{
|
result.resultCode = -1;
|
result.resultMsg = "输送线中转接驳位获取失败,请检查是否配置";
|
Console.WriteLine("输送线中转接驳位获取失败,请检查是否配置");
|
return result;
|
}
|
|
// 创建任务,不需要进行货位管控
|
var operation = new Operation
|
{
|
// 任务号
|
S_CODE = HelperMethod.GenerateTaskNo("作业号", "OP"),
|
// 任务类型
|
N_TYPE = input.taskType,
|
// 任务类型
|
S_TYPE = Operation.GetTypeStr(input.taskType),
|
// 起点货位
|
S_START_LOC = input.startLocation,
|
// 起点库区编码
|
S_START_AREA = Operation.GetArea(input.startLocation),
|
// 拓展字段(中转货位)
|
S_EXT_ATTR1 = queryRandomLocation.S_CODE,
|
// 终点货位
|
S_END_LOC = input.endLocation,
|
// 终点库区编码
|
S_END_AREA = Operation.GetArea(input.endLocation),
|
// 容器编码
|
S_CNTR_CODE = input.cntrCode,
|
// 作业定义名称
|
S_OP_DEF_NAME = Operation.GetTypeStr(input.taskType),
|
// 盘点单号
|
S_COUNT_NO = input.odd,
|
// 拓展字段(任务组)
|
S_EXT_ATTR2 = Operation.GetGroup(group),
|
// 巷道
|
N_ROADWAY = group
|
};
|
|
// 实现事务
|
var sqlSugarClient = AdoSqlMethod<object>.QuerySqlSugarClient();
|
|
try
|
{
|
sqlSugarClient.BeginTran();
|
if (AdoSqlMethod<Operation>.AddFirstTran(sqlSugarClient, operation))
|
{
|
if (operation.N_TYPE == 1 || operation.N_TYPE == 3)
|
{
|
// 货位需要上锁
|
LocationHelper.LockLoc(operation.S_END_LOC, 1);
|
}
|
else if (operation.N_TYPE == 4)
|
{
|
// 货位需要上锁
|
LocationHelper.LockLoc(operation.S_START_LOC, 2);
|
|
container.C_ENABLE = 'N';
|
container.N_LOCK_STATE = 4;
|
AdoSqlMethod<Container>.UpdateFirst(container, p => new { p.C_ENABLE, p.N_LOCK_STATE });
|
}
|
else
|
{
|
// 货位需要上锁
|
LocationHelper.LockLoc(operation.S_START_LOC, 2);
|
|
container.C_ENABLE = 'N';
|
AdoSqlMethod<Container>.UpdateFirst(container, p => new { p.C_ENABLE });
|
}
|
|
result.resultCode = 0;
|
result.resultMsg = "作业创建成功";
|
}
|
else
|
{
|
result.resultCode = -1;
|
result.resultMsg = "作业创建失败";
|
}
|
|
sqlSugarClient.CommitTran();
|
|
return result;
|
}
|
catch (Exception e)
|
{
|
sqlSugarClient.RollbackTran();
|
Console.WriteLine(e);
|
throw;
|
}
|
}
|
}
|