using HH.Redis.ReisModel;
|
using HH.WMS.BLL.Algorithm;
|
using HH.WMS.BLL.Basic;
|
using HH.WMS.BLL.External;
|
using HH.WMS.BLL.InStock;
|
using HH.WMS.BLL.Interface;
|
using HH.WMS.BLL.MoveStock;
|
using HH.WMS.Common;
|
using HH.WMS.Common.Algorithm;
|
using HH.WMS.Common.External;
|
using HH.WMS.DAL;
|
using HH.WMS.DAL.Basic;
|
using HH.WMS.DAL.InStock;
|
using HH.WMS.DAL.Pda;
|
using HH.WMS.DAL.SysMgr;
|
using HH.WMS.Entitys;
|
using HH.WMS.Entitys.Basic;
|
using HH.WMS.Entitys.Dto;
|
using HH.WMS.Entitys.Entitys;
|
using HH.WMS.Entitys.External;
|
using HH.WMS.Entitys.MoveStock;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace HH.WMS.BLL.Pda
|
{
|
public class JxBLL : DapperBaseBLL
|
{
|
|
|
|
#region 生成任务
|
/// <summary>
|
/// PDA专用 生成任务
|
/// </summary>
|
/// <param name="startPosition"></param>
|
/// <param name="endPosition"></param>
|
/// <param name="taskPriority"></param>
|
/// <param name="objLocationEntity"></param>
|
/// <param name="taskNo"></param>
|
/// <param name="SendAms"></param>
|
/// <returns></returns>
|
public OperateResult CreateTransTask(string startPosition, string endPosition, string taskPriority, string tranType, string projectCode)
|
{
|
OperateResult result = new OperateResult();
|
#region 货位逻辑判断检测
|
|
TN_WM_LOCATION_EXTEntity startlocation = BLLCreator.Create<TN_WM_LOCATION_EXTBLL>().GetExtModel(" where CN_S_LOCATION_CODE='" + startPosition + "'");
|
if (startlocation == null)
|
{
|
return OperateResult.Error("在表TN_WM_LOCATION_EXT中未查询到该起点货位!");
|
}
|
if (startlocation.CN_S_LOCATION_STATE != Constants.Location_State_Normal)
|
{
|
return OperateResult.Error(string.Format("当前起点位置状态为{0},不允许从该位置取料!", startlocation.CN_S_LOCATION_STATE));
|
}
|
AutoBomStockAreaEntity startArea = CreateDAL<TN_AB_STOCK_LOCATIONDAL>().GetAreaModelByLocation(startPosition);
|
if (startArea == null)
|
{
|
//非法的目的货位
|
return OperateResult.Error(string.Format("在mongo(TN_AB_B_STOCK_AREA或TN_AB_STOCK_LOCATION表)中未查询到该起点货位{0}的库区信息!", startPosition));
|
}
|
if (startArea.CN_C_IS_CONTROL_QTY.Equals("Y"))
|
{
|
if (startlocation.CN_S_USE_STATE != Constants.Use_State_Full)
|
{
|
return OperateResult.Error(string.Format("起点库区管控数量并且货位存储状态为{0},不允许从该位置取料!", startlocation.CN_S_USE_STATE));
|
|
}
|
}
|
//判断货位是否绑定托盘
|
List<TN_WM_B_TRAY_LOCATIONEntity> lstStartTray = CreateDAL<TN_WM_B_TRAY_LOCATIONDAL>().GetListByLocationCode(startPosition);
|
if (lstStartTray.Count == 0)
|
{
|
return OperateResult.Error("在该起点位置上未绑定托盘物料信息!");
|
}
|
|
TN_WM_LOCATION_EXTEntity endlocation = BLLCreator.Create<TN_WM_LOCATION_EXTBLL>().GetExtModel(" where CN_S_LOCATION_CODE='" + endPosition + "'");
|
if (endlocation == null)
|
{
|
return OperateResult.Error("在表TN_WM_LOCATION_EXT未查询到该目的货位!");
|
}
|
if (endlocation.CN_S_LOCATION_STATE != Constants.Location_State_Normal)
|
{
|
return OperateResult.Error(string.Format("当前起点位置状态为{0},不允许往该位置卸料!", endlocation.CN_S_LOCATION_STATE));
|
|
}
|
AutoBomStockAreaEntity endArea = CreateDAL<TN_AB_STOCK_LOCATIONDAL>().GetAreaModelByLocation(endPosition);
|
if (endArea == null)
|
{
|
//非法的目的货位
|
return OperateResult.Error(string.Format("在mongo(TN_AB_B_STOCK_AREA或TN_AB_STOCK_LOCATION表)中未查询到该目的货位{0}的库区信息!", startPosition));
|
}
|
if (endArea.CN_C_IS_CONTROL_QTY.Equals("Y") && endlocation.CN_S_USE_STATE != Constants.Use_State_Empty)
|
{
|
return OperateResult.Error(string.Format("终点库区管控数量并且货位存储状态为{0},不允许往该位置卸料!", endlocation.CN_S_USE_STATE));
|
}
|
//判断货位是否绑定托盘
|
List<TN_WM_B_TRAY_LOCATIONEntity> lstEndTray = CreateDAL<TN_WM_B_TRAY_LOCATIONDAL>().GetListByLocationCode(endPosition);
|
if (lstEndTray.Count > 0)
|
{
|
return OperateResult.Error("该目的位置上已绑定其他托盘物料信息!");
|
}
|
#endregion
|
//生成入库任务
|
TN_WM_TASKEntity taskEntity = new TN_WM_TASKEntity();
|
string postData = "{\"appCode\":\"" + Constants.appCode + "\",\"ruleName\":\"" + Constants.Rule_TransTaskNo + "\",\"orgId\":\"\",\"orgFlag\":\"0\"}";
|
string taskNo = WebApiManager.HttpAutoBom_Post("api/BillRule/GenBillNo", postData);
|
if (string.IsNullOrEmpty(taskNo))
|
{
|
return OperateResult.Error("任务号生成失败,请检查autobom中是否配置了转运任务号生成规则!");
|
}
|
taskEntity.CN_S_TASK_NO = taskNo;
|
taskEntity.CN_S_STATE = Constants.TaskStateList[Constants.TaskExecState_NoExec];
|
taskEntity.CN_T_CREATE = DateTime.Now;
|
taskEntity.CN_S_TASK_TYPE = tranType;
|
taskEntity.CN_S_TRAY_CODE = lstStartTray[0].CN_S_TRAY_CODE;
|
taskEntity.CN_S_START_BIT = startPosition;
|
taskEntity.CN_S_END_BIT = endPosition;
|
taskEntity.CN_N_PRIORITY = int.Parse(taskPriority);
|
taskEntity.CN_S_PROJECT_CODE = projectCode;
|
taskEntity.CN_S_END_AREA = endArea.CN_S_AREA_CODE;
|
taskEntity.CN_S_START_AREA = startArea.CN_S_AREA_CODE;
|
taskEntity.CN_S_STOCK_CODE = startArea.CN_S_STOCK_CODE;
|
taskEntity.CN_S_START_AREA_TYPE = startArea.CN_S_STRUCTURE;
|
taskEntity.CN_S_END_AREA_TYPE = endArea.CN_S_STRUCTURE;
|
taskEntity.CN_C_START_IS_CONTROL_QTY = startArea.CN_C_IS_CONTROL_QTY;
|
taskEntity.CN_C_END_IS_CONTROL_QTY = endArea.CN_C_IS_CONTROL_QTY;
|
taskEntity.CN_S_START_CONTROL_INV = startArea.CN_C_IS_INVENTORY;
|
taskEntity.CN_S_END_CONTROL_INV = endArea.CN_C_IS_INVENTORY;
|
taskEntity.CN_S_CREATOR = "AmsPoint";
|
taskEntity.CN_S_CREATOR_BY = "AmsPoint";
|
taskEntity.CN_T_CREATE = DateTime.Now;
|
taskEntity.CN_S_MODIFY = "AmsPoint";
|
taskEntity.CN_S_MODIFY_BY = "AmsPoint";
|
taskEntity.CN_T_MODIFY = DateTime.Now;
|
result = UseTransaction(trans =>
|
{
|
#region 事务
|
|
//新增任务
|
CreateDAL<DapperDAL<TN_WM_TASKEntity>>().Add(taskEntity, trans);
|
|
//锁定目的位置货位-预入库锁定
|
if (endArea.CN_C_IS_CONTROL_QTY.Equals("Y"))
|
{
|
result = CreateDAL<TN_WM_LOCATION_EXTDAL>().UpdateLocationExtStateLock(taskEntity.CN_S_END_BIT, Constants.Location_State_InLock, Constants.Location_State_Normal, "", taskNo, trans);
|
if (result.AffectedRows == 0)
|
{
|
throw new Exception("更新目的货位状态并发冲突,该货位状态可能已经发生变化");
|
}
|
BLLCreator.Create<TN_WM_B_LOCATION_CHANGEBLL>().AddStateChange(endPosition, "正常", "预入库锁定", "AMS生成点对点任务锁定终点货位", "AMS", "ams", taskNo, endArea.CN_S_STOCK_CODE, endArea.CN_S_AREA_CODE, trans);
|
}
|
if (startArea.CN_C_IS_CONTROL_QTY.Equals("Y"))
|
{
|
//锁定起始位置货位-预出库锁定
|
result = CreateDAL<TN_WM_LOCATION_EXTDAL>().UpdateLocationExtStateLock(taskEntity.CN_S_START_BIT, Constants.Location_State_OutLock, Constants.Location_State_Normal, "", taskNo, trans);
|
|
if (result.AffectedRows == 0)
|
{
|
throw new Exception("更新起点货位状态并发冲突,该货位状态可能已经发生变化");
|
}
|
BLLCreator.Create<TN_WM_B_LOCATION_CHANGEBLL>().AddStateChange(startPosition, "正常", "预出库锁定", "AMS生成点对点任务锁定起点货位", "AMS", "ams", taskNo, startArea.CN_S_STOCK_CODE, startArea.CN_S_AREA_CODE, trans);
|
}
|
|
//OperateResult re = new OtherSysApi().SendAmsCreateTask(taskEntity);
|
//if (!re.Success)
|
//{
|
// throw new Exception(re.Msg);
|
//}
|
#endregion
|
});
|
result.Data = taskNo;
|
return result;
|
|
}
|
#endregion
|
|
|
}
|
}
|