You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
750 lines
36 KiB
750 lines
36 KiB
using SSWMS.Common;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
|
|
namespace SSWMS.Server
|
|
{
|
|
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single,
|
|
ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = int.MaxValue, UseSynchronizationContext = false)]
|
|
public class S_CellService : I_CellService
|
|
{
|
|
public bool InitCell(out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
DataTable dtUpdate = null;
|
|
DataRow drUpdate = null;
|
|
if (AppSettings.IsOracleDatabase)
|
|
{
|
|
dtUpdate = S_BaseService._P_WH_CELL.GetDataTable("select * from WH_CELL where ROWNUM=1");
|
|
}
|
|
else
|
|
{
|
|
dtUpdate = S_BaseService._P_WH_CELL.GetDataTable("select top 1 * from WH_CELL");
|
|
}
|
|
if (dtUpdate.Rows.Count > 0)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = "货位表有数据";
|
|
return false;
|
|
}
|
|
object[][] aCellDescription = new object[][]
|
|
{
|
|
// WAREHOUSE_CODE, CELL_TYPE, DEVICE_CODE, MinZ, MaxZ, MinX, MaxX, MinY, MaxY
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18001", 1, 4, 2, 42, 1, 9},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18002", 5, 8, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18003", 9, 12, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18004", 13, 16, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18005", 17, 20, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18006", 21, 24, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18007", 25, 28, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18008", 29, 32, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18009", 33, 36, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18010", 37, 40, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18011", 41, 44, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18012", 45, 48, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18013", 49, 52, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18014", 53, 56, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18015", 57, 60, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18016", 61, 64, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18017", 65, 68, 2, 57, 1, 15},
|
|
new object[] { SystemCode.WAREHOUSE_CODE.Warehouse, SystemCode.CELL_TYPE.Cell, "18018", 69, 72, 2, 57, 1, 15}
|
|
};
|
|
List<int> lCellFarLeftZ = new List<int>();
|
|
List<int> lCellNearLeftZ = new List<int>();
|
|
List<int> lCellNearRightZ = new List<int>();
|
|
List<int> lCellFarRightZ = new List<int>();
|
|
for (int i = 0; i < 72; i += 4)
|
|
{
|
|
lCellFarLeftZ.Add(i + 1);
|
|
lCellNearLeftZ.Add(i + 2);
|
|
lCellNearRightZ.Add(i + 3);
|
|
lCellFarRightZ.Add(i + 4);
|
|
}
|
|
for (int iRow = 0; iRow < aCellDescription.Length; ++iRow)
|
|
{
|
|
object[] aCellDescriptionRow = aCellDescription[iRow];
|
|
string sWarehouseCode = aCellDescriptionRow[0].ToString();
|
|
string sCellType = aCellDescriptionRow[1].ToString();
|
|
string sDeviceCode = aCellDescriptionRow[2].ToString();
|
|
int iMinZ = Convert.ToInt32(aCellDescriptionRow[3]);
|
|
int iMaxZ = Convert.ToInt32(aCellDescriptionRow[4]);
|
|
int iMinX = Convert.ToInt32(aCellDescriptionRow[5]);
|
|
int iMaxX = Convert.ToInt32(aCellDescriptionRow[6]);
|
|
int iMinY = Convert.ToInt32(aCellDescriptionRow[7]);
|
|
int iMaxY = Convert.ToInt32(aCellDescriptionRow[8]);
|
|
for (int iCellZ = iMinZ; iCellZ <= iMaxZ; ++iCellZ)
|
|
{
|
|
string sForkType = SystemCode.FORK_TYPE.Normal;
|
|
if (lCellFarLeftZ.Contains(iCellZ) || lCellFarRightZ.Contains(iCellZ))
|
|
{
|
|
sForkType = SystemCode.FORK_TYPE.CellFar;
|
|
}
|
|
else if (lCellNearLeftZ.Contains(iCellZ) || lCellNearRightZ.Contains(iCellZ))
|
|
{
|
|
sForkType = SystemCode.FORK_TYPE.CellNear;
|
|
}
|
|
int iCellPOffsetX = 0;
|
|
if (lCellFarLeftZ.Contains(iCellZ) || lCellNearRightZ.Contains(iCellZ))
|
|
{
|
|
iCellPOffsetX = 1;
|
|
}
|
|
else if (lCellNearLeftZ.Contains(iCellZ) || lCellFarRightZ.Contains(iCellZ))
|
|
{
|
|
iCellPOffsetX = -1;
|
|
}
|
|
for (int iCellX = iMinX; iCellX <= iMaxX; ++iCellX)
|
|
{
|
|
for (int iCellY = iMinY; iCellY <= iMaxY; ++iCellY)
|
|
{
|
|
string sCellCode = $"{iCellZ:D2}-{iCellX:D2}-{iCellY:D2}";
|
|
drUpdate = dtUpdate.NewRow();
|
|
drUpdate["WAREHOUSE_CODE"] = sWarehouseCode;
|
|
drUpdate["CELL_X"] = iCellX;
|
|
drUpdate["CELL_Y"] = iCellY;
|
|
drUpdate["CELL_Z"] = iCellZ;
|
|
drUpdate["DEVICE_CODE"] = sDeviceCode;
|
|
drUpdate["CELL_CODE"] = sCellCode;
|
|
if (iCellPOffsetX == 0)
|
|
{
|
|
drUpdate["CELL_CODE_P"] = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
drUpdate["CELL_CODE_P"] = $"{(iCellZ + iCellPOffsetX):D2}-{iCellX:D2}-{iCellY:D2}";
|
|
}
|
|
drUpdate["CELL_NAME"] = $"{(iCellZ - 1) / 4 + 1}-{(iCellZ - 1) % 4 + 1}-{iCellX}-{iCellY}";
|
|
drUpdate["CELL_TYPE"] = sCellType;
|
|
drUpdate["FORK_TYPE"] = sForkType;
|
|
drUpdate["CELL_WIDTH"] = 40;
|
|
drUpdate["CELL_HEIGHT"] = 30;
|
|
drUpdate["CELL_MODEL"] = SystemCode.CELL_MODEL.Low;
|
|
drUpdate["CELL_FLAG"] = SystemCode.FLAG.Enable;
|
|
dtUpdate.Rows.Add(drUpdate);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
dtUpdate.DataSet.Tables.Remove(dtUpdate);
|
|
if (S_BaseService._P_Base_House.UpdateDataTable(dtUpdate, "WH_CELL", out sResult) == 0)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
return false;
|
|
}
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = ex.Message;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public IList<WH_CELL> GetCellByCellZ(string sWarehouseCode, int iCellZ, int iUserID = 0)
|
|
{
|
|
return S_BaseService._P_WH_CELL.GetListByCellZ(sWarehouseCode, iCellZ);
|
|
}
|
|
|
|
public bool UpdateCellFlag(string sWarehouseCode, string sCellFlag,
|
|
int iStartX, int iEndX, int iStartY, int iEndY, int iStartZ, int iEndZ, string sRemark, out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
S_BaseService._P_Base_House.ExecuteNonQuery($"update WH_CELL set CELL_FLAG='{sCellFlag}',CELL_REMARK='{sRemark}'" +
|
|
$" where CELL_TYPE='{SystemCode.CELL_TYPE.Cell}' and WAREHOUSE_CODE='{sWarehouseCode}'" +
|
|
$" and CELL_X>={iStartX} and CELL_X<={iEndX} and CELL_Y>={iStartY} and CELL_Y<={iEndY} and CELL_Z>={iStartZ} and CELL_Z<={iEndZ}");
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = ex.Message;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public DataTable GetCellZ(string sWarehouseCode)
|
|
{
|
|
return S_BaseService._P_Base_House.GetDataTable("select CELL_Z,FORK_TYPE,CELL_TYPE from WH_CELL" +
|
|
$" where WAREHOUSE_CODE='{sWarehouseCode}' group by CELL_Z,FORK_TYPE,CELL_TYPE order by CELL_TYPE,CELL_Z");
|
|
}
|
|
|
|
#region Get Check StartCell EndCell
|
|
private readonly Dictionary<int, List<string>> dLineGoods = new Dictionary<int, List<string>>()
|
|
{
|
|
//{ SystemCode.GOODS_ID.Stock, new List<string>() { } } // 托盘
|
|
};
|
|
|
|
// 校验出库货位 双深
|
|
public bool CheckStartCell(WH_CELL wcStartCell)
|
|
{
|
|
return wcStartCell.CELL_TYPE == SystemCode.CELL_TYPE.Cell &&
|
|
wcStartCell.CELL_FLAG == SystemCode.FLAG.Enable &&
|
|
wcStartCell.STORAGE_ID > 0 &&
|
|
wcStartCell.MANAGE_ID == 0 &&
|
|
(wcStartCell.FORK_TYPE != SystemCode.FORK_TYPE.CellFar || wcStartCell.STORAGE_ID_P == 0 || wcStartCell.CELL_FLAG_P == SystemCode.FLAG.Enable);
|
|
}
|
|
|
|
// 校验入库货位 双深
|
|
public bool CheckEndCell(WH_CELL wcEndCell)
|
|
{
|
|
return wcEndCell.CELL_TYPE == SystemCode.CELL_TYPE.Cell &&
|
|
wcEndCell.CELL_FLAG == SystemCode.FLAG.Enable &&
|
|
wcEndCell.STORAGE_ID == 0 &&
|
|
wcEndCell.MANAGE_ID == 0 &&
|
|
(wcEndCell.FORK_TYPE != SystemCode.FORK_TYPE.CellFar || (wcEndCell.STORAGE_ID_P == 0 && wcEndCell.MANAGE_ID_P == 0)) &&
|
|
(wcEndCell.FORK_TYPE != SystemCode.FORK_TYPE.CellNear || wcEndCell.MANAGE_ID_P == 0);
|
|
}
|
|
|
|
// 校验移库货位 双深
|
|
public bool CheckMoveCell(WH_CELL wcStartCell, WH_CELL wcEndCell)
|
|
{
|
|
if (wcEndCell.CELL_CODE == wcStartCell.CELL_CODE_P)
|
|
{
|
|
return wcStartCell.CELL_TYPE == SystemCode.CELL_TYPE.Cell &&
|
|
wcStartCell.CELL_FLAG == SystemCode.FLAG.Enable &&
|
|
wcStartCell.STORAGE_ID > 0 &&
|
|
wcStartCell.MANAGE_ID == 0 &&
|
|
wcEndCell.CELL_TYPE == SystemCode.CELL_TYPE.Cell &&
|
|
wcEndCell.CELL_FLAG == SystemCode.FLAG.Enable &&
|
|
wcEndCell.STORAGE_ID == 0 &&
|
|
wcEndCell.MANAGE_ID == 0;
|
|
}
|
|
return this.CheckStartCell(wcStartCell) && this.CheckEndCell(wcEndCell);
|
|
}
|
|
|
|
// 巷道优先级 双深
|
|
private Dictionary<string, int> LinePriority(bool bIsIn, string sCellCode, STORAGE_MAIN sm)
|
|
{
|
|
Dictionary<string, int> dLinePriority = new Dictionary<string, int>();
|
|
string sql = string.Empty;
|
|
string sRouteView = "V_IO_CONTROL_ROUTE";
|
|
IList<STORAGE_LIST> lStorageList = S_BaseService._P_STORAGE_LIST.GetListByStorageID(sm.STORAGE_ID);
|
|
if (lStorageList != null &&
|
|
lStorageList.Count > 0 &&
|
|
lStorageList[0].STORAGE_PROPERTY_10 == SystemCode.STOCK_SIZE.Rectangle)
|
|
{
|
|
sRouteView = "V_IO_CONTROL_ROUTE_L";
|
|
}
|
|
// 可用路径
|
|
if (bIsIn)
|
|
{
|
|
// 入库可用路径
|
|
if (lStorageList != null)
|
|
{
|
|
if (lStorageList.Count == 1)
|
|
{
|
|
if (SystemCode.WH_CELL_CODE.InBehind.Contains(sCellCode))
|
|
{
|
|
sql = $"select END_DEVICE as DEVICE_CODE from {sRouteView}" +
|
|
$" left outer join V_MANAGE_MAIN_DEVICE on START_DEVICE_CODE=END_DEVICE" +
|
|
$" where START_DEVICE='{sCellCode}' and END_DEVICE<>'18001' and CONTROL_ROUTE_TYPE={SystemCode.CONTROL_TYPE.InCell}" +
|
|
$" group by END_DEVICE having sum(case when END_DEVICE_CODE in ('{string.Join("','", SystemCode.WH_CELL_CODE.OutBehind)}') then 1 else 0 end)=0";
|
|
}
|
|
else
|
|
{
|
|
sql = $"select END_DEVICE as DEVICE_CODE from {sRouteView}" +
|
|
$" left outer join V_MANAGE_MAIN_DEVICE on START_DEVICE_CODE=END_DEVICE" +
|
|
$" where START_DEVICE='{sCellCode}' and END_DEVICE<>'18001' and CONTROL_ROUTE_TYPE={SystemCode.CONTROL_TYPE.InCell}" +
|
|
$" group by END_DEVICE having sum(case when MANAGE_TYPE<>'{SystemCode.MANAGE_TYPE.MoveCell}' and END_DEVICE_CODE not in ('{string.Join("','", SystemCode.WH_CELL_CODE.OutBehind)}') then 1 else 0 end)=0";
|
|
}
|
|
}
|
|
else if (lStorageList.Count == 2)
|
|
{
|
|
sql = $"select END_DEVICE as DEVICE_CODE from {sRouteView}" +
|
|
$" where START_DEVICE='{sCellCode}' and END_DEVICE='18001' and CONTROL_ROUTE_TYPE={SystemCode.CONTROL_TYPE.InCell}";
|
|
}
|
|
else
|
|
{
|
|
return dLinePriority;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 出库可用路径
|
|
if (string.IsNullOrWhiteSpace(sCellCode))
|
|
{
|
|
sql = $"select START_DEVICE as DEVICE_CODE from {sRouteView}" +
|
|
$" where CONTROL_ROUTE_TYPE={SystemCode.CONTROL_TYPE.OutCell}";
|
|
}
|
|
else
|
|
{
|
|
sql = $"select START_DEVICE as DEVICE_CODE from {sRouteView}" +
|
|
$" where END_DEVICE='{sCellCode}' and CONTROL_ROUTE_TYPE={SystemCode.CONTROL_TYPE.OutCell}";
|
|
}
|
|
}
|
|
foreach (DataRow dr in S_BaseService._P_Base_House.GetDataTable(sql).Rows)
|
|
{
|
|
string sDeviceCode = dr["DEVICE_CODE"].ToString();
|
|
if (!dLinePriority.ContainsKey(sDeviceCode))
|
|
{
|
|
dLinePriority.Add(sDeviceCode, 20000);
|
|
}
|
|
}
|
|
if (dLinePriority.Count < 2)
|
|
{
|
|
return dLinePriority;
|
|
}
|
|
// 优先物料专用巷道
|
|
//if (sm != null && this.dLineGoods.ContainsKey(sm.GOODS_ID))
|
|
//{
|
|
// foreach (string sDeviceCode in this.dLineGoods[sm.GOODS_ID])
|
|
// {
|
|
// if (dLinePriority.ContainsKey(sDeviceCode))
|
|
// {
|
|
// if (bIsIn)
|
|
// {
|
|
// // 优先专用巷道
|
|
// dLinePriority[sDeviceCode] += 10000;
|
|
// }
|
|
// else
|
|
// {
|
|
// // 优先非专用巷道
|
|
// dLinePriority[sDeviceCode] -= 10000;
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
// 优先任务少巷道
|
|
if (bIsIn)
|
|
{
|
|
// 优先入库任务少
|
|
sql = $"select END_DEVICE_CODE as DEVICE_CODE from V_MANAGE_MAIN_DEVICE where MANAGE_TYPE='{SystemCode.MANAGE_TYPE.InCell}'";
|
|
}
|
|
else
|
|
{
|
|
// 优先出库任务少
|
|
sql = $"select START_DEVICE_CODE as DEVICE_CODE from V_MANAGE_MAIN_DEVICE where MANAGE_TYPE='{SystemCode.MANAGE_TYPE.OutCell}' and (MANAGE_STATUS='{SystemCode.MANAGE_STATUS.Send}' or MANAGE_STATUS='{SystemCode.MANAGE_STATUS.Waiting}')";
|
|
}
|
|
foreach (DataRow dr in S_BaseService._P_Base_House.GetDataTable(sql).Rows)
|
|
{
|
|
string sDeviceCode = dr["DEVICE_CODE"].ToString();
|
|
if (dLinePriority.ContainsKey(sDeviceCode))
|
|
{
|
|
dLinePriority[sDeviceCode] -= 500;
|
|
}
|
|
}
|
|
// 优先物料平衡
|
|
if (sm != null && sm.GOODS_ID > 0)
|
|
{
|
|
if (sm.GOODS_ID == SystemCode.GOODS_ID.MultiGoods)
|
|
{
|
|
if (bIsIn)
|
|
{
|
|
foreach (DataRow dr in S_BaseService._P_Base_House.GetDataTable(
|
|
"select (select count(0) from V_STORAGE_MAIN" +
|
|
$" where GOODS_ID={SystemCode.GOODS_ID.MultiGoods} and DEVICE_CODE=V_WH_CELL_STATUS.DEVICE_CODE)" +
|
|
" as GOODS_COUNT,NOHAVE_COUNT,TOTAL_COUNT,DEVICE_CODE from V_WH_CELL_STATUS").Rows)
|
|
{
|
|
string sDeviceCode = dr["DEVICE_CODE"].ToString();
|
|
if (dLinePriority.ContainsKey(sDeviceCode))
|
|
{
|
|
// 优先物料少巷道
|
|
dLinePriority[sDeviceCode] += Convert.ToInt32(
|
|
(Convert.ToInt32(dr["NOHAVE_COUNT"]) - 2 * Convert.ToInt32(dr["GOODS_COUNT"]))
|
|
* 1000 / (Convert.ToInt32(dr["TOTAL_COUNT"]) + 0.1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow dr in S_BaseService._P_Base_House.GetDataTable(
|
|
$"select (select count(0) from V_STORAGE_LIST_CELL_OUT where GOODS_ID={sm.GOODS_ID}" +
|
|
$" and DEVICE_CODE=V_WH_CELL_STATUS.DEVICE_CODE) as GOODS_COUNT,NOHAVE_COUNT,TOTAL_COUNT,DEVICE_CODE from V_WH_CELL_STATUS").Rows)
|
|
{
|
|
string sDeviceCode = dr["DEVICE_CODE"].ToString();
|
|
if (dLinePriority.ContainsKey(sDeviceCode))
|
|
{
|
|
if (bIsIn)
|
|
{
|
|
// 优先物料少巷道
|
|
dLinePriority[sDeviceCode] += Convert.ToInt32(
|
|
(Convert.ToInt32(dr["NOHAVE_COUNT"]) - 2 * Convert.ToInt32(dr["GOODS_COUNT"]))
|
|
* 1000 / (Convert.ToInt32(dr["TOTAL_COUNT"]) + 0.1));
|
|
}
|
|
else
|
|
{
|
|
// 优先物料多巷道
|
|
dLinePriority[sDeviceCode] += Convert.ToInt32(
|
|
(2 * Convert.ToInt32(dr["GOODS_COUNT"]) - Convert.ToInt32(dr["NOHAVE_COUNT"]))
|
|
* 1000 / (Convert.ToInt32(dr["TOTAL_COUNT"]) + 0.1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return dLinePriority;
|
|
}
|
|
|
|
// 获取入库货位 双深
|
|
public WH_CELL GetEndCell(STORAGE_MAIN sm, WH_CELL wcStartCell, int iCellX, int iCellY, out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
Dictionary<string, int> dLinePriority = null;
|
|
if (wcStartCell == null)
|
|
{
|
|
dLinePriority = LinePriority(true, sm.CELL_CODE, sm);
|
|
if (string.IsNullOrWhiteSpace(sm.CELL_MODEL))
|
|
{
|
|
sm.CELL_MODEL = SystemCode.CELL_MODEL.Low;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dLinePriority = new Dictionary<string, int> { { wcStartCell.DEVICE_CODE, 0 } };
|
|
sm.CELL_MODEL = wcStartCell.CELL_MODEL;
|
|
}
|
|
if (dLinePriority.Count == 0)
|
|
{
|
|
sResult = $"起始位置 {sm.CELL_CODE} 入库路径不可用";
|
|
return null;
|
|
}
|
|
WH_CELL wc = GetEndCell(wcStartCell, dLinePriority, sm, iCellX, iCellY);
|
|
if (wc != null)
|
|
{
|
|
return wc;
|
|
}
|
|
//if (sm.CELL_MODEL == SystemCode.CELL_MODEL.Low)
|
|
//{
|
|
// sm.CELL_MODEL = SystemCode.CELL_MODEL.High;
|
|
// wc = GetEndCell(wcStartCell, dLinePriority, sm, iCellX, iCellY);
|
|
// if (wc != null)
|
|
// {
|
|
// return wc;
|
|
// }
|
|
//}
|
|
sResult = "没有可用目标位置";
|
|
return null;
|
|
}
|
|
|
|
// 获取入库货位 双深
|
|
private WH_CELL GetEndCell(WH_CELL wcStartCell, Dictionary<string, int> dLinePriority, STORAGE_MAIN sm, int iCellX, int iCellY)
|
|
{
|
|
WH_CELL wc = null;
|
|
string sOrderBy = "CELL_Y,CELL_X";
|
|
if (iCellX == int.MaxValue)
|
|
{
|
|
sOrderBy = "CELL_Y,CELL_X desc";
|
|
}
|
|
else if (iCellX > 0)
|
|
{
|
|
if (iCellY > 0)
|
|
{
|
|
sOrderBy = $"abs(CELL_X-{iCellX}),abs(CELL_Y-{iCellY})";
|
|
}
|
|
else
|
|
{
|
|
sOrderBy = $"abs(CELL_X-{iCellX}),CELL_Y";
|
|
}
|
|
}
|
|
foreach (KeyValuePair<string, int> p in dLinePriority.OrderByDescending(p => p.Value))
|
|
{
|
|
if (wcStartCell == null && S_BaseService._P_Base_House.GetDataTable(
|
|
$"select top 2 0 from V_WH_CELL_PAIR_CELL_IN where DEVICE_CODE='{p.Key}'").Rows.Count < 2)
|
|
{
|
|
continue;
|
|
}
|
|
string sqlFormat = "where CELL_ID=(select top 1 CELL_ID from V_WH_CELL_PAIR_CELL_IN" +
|
|
$" where DEVICE_CODE='{p.Key}' and CELL_MODEL='{sm.CELL_MODEL}' {{0}} order by {sOrderBy})";
|
|
//// 近空远是
|
|
//if (sm.GOODS_ID > 0)
|
|
//{
|
|
// wc = S_BaseService._P_WH_CELL.GetModel(string.Format(sqlFormat,
|
|
// $"and FORK_TYPE='{SystemCode.FORK_TYPE.CellNear}' and STORAGE_PROPERTY_P={sm.STORAGE_PROPERTY}"));
|
|
// if (wc != null)
|
|
// {
|
|
// return wc;
|
|
// }
|
|
//}
|
|
// 普通 or 远空近空 or 近空远禁
|
|
wc = S_BaseService._P_WH_CELL.GetModel(string.Format(sqlFormat,
|
|
$"and (FORK_TYPE<>'{SystemCode.FORK_TYPE.CellNear}' or CELL_FLAG_P='{SystemCode.FLAG.Disable}')"));
|
|
if (wc != null)
|
|
{
|
|
return wc;
|
|
}
|
|
// 近空远否
|
|
wc = S_BaseService._P_WH_CELL.GetModel(string.Format(sqlFormat,
|
|
$"and FORK_TYPE='{SystemCode.FORK_TYPE.CellNear}'"));
|
|
if (wc != null)
|
|
{
|
|
return wc;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// 获取出库货位 双深
|
|
public WH_CELL GetStartCell(string sEndCellCode, PLAN_LIST pl, int iCellX, int iCellY, out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
string sOrderBy = "CELL_X,CELL_Y";
|
|
if (iCellX > 0)
|
|
{
|
|
if (iCellY > 0)
|
|
{
|
|
sOrderBy = $"abs(CELL_X-{iCellX}),abs(CELL_Y-{iCellY})";
|
|
}
|
|
else
|
|
{
|
|
sOrderBy = $"abs(CELL_X-{iCellX}),CELL_Y";
|
|
}
|
|
}
|
|
if (pl.GOODS_ID > SystemCode.GOODS_ID.MaxStock)
|
|
{
|
|
sOrderBy = $"ENTRY_TIME,{sOrderBy}";
|
|
}
|
|
Dictionary<string, int> dLinePriority = LinePriority(false, sEndCellCode, new STORAGE_MAIN() { GOODS_ID = pl.GOODS_ID });
|
|
if (dLinePriority.Count == 0)
|
|
{
|
|
sResult = $"目标位置 {sEndCellCode} 出库路径不可用";
|
|
return null;
|
|
}
|
|
string sSqlFormat = $"where CELL_ID in (select top 1 CELL_ID from V_WH_CELL_PAIR_CELL_OUT" +
|
|
$" where DEVICE_CODE='{{0}}'";
|
|
if (pl.GOODS_ID > 0)
|
|
{
|
|
sSqlFormat += $" and GOODS_ID={pl.GOODS_ID}";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_01))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_01='{pl.STORAGE_PROPERTY_01}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_02))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_02='{pl.STORAGE_PROPERTY_02}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_03))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_03='{pl.STORAGE_PROPERTY_03}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_04))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_04='{pl.STORAGE_PROPERTY_04}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_05))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_05='{pl.STORAGE_PROPERTY_05}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_06))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_06='{pl.STORAGE_PROPERTY_06}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_07))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_07='{pl.STORAGE_PROPERTY_07}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_08))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_08='{pl.STORAGE_PROPERTY_08}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_09))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_09='{pl.STORAGE_PROPERTY_09}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.STORAGE_PROPERTY_10))
|
|
{
|
|
sSqlFormat += $" and STORAGE_PROPERTY_10='{pl.STORAGE_PROPERTY_10}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.BOX_BARCODE))
|
|
{
|
|
sSqlFormat += $" and BOX_BARCODE='{pl.BOX_BARCODE}'";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pl.GOODS_BARCODE))
|
|
{
|
|
sSqlFormat += $" and GOODS_BARCODE='{pl.GOODS_BARCODE}'";
|
|
}
|
|
sSqlFormat += $" {{1}} order by {sOrderBy})";
|
|
WH_CELL wc = null;
|
|
foreach (KeyValuePair<string, int> p in dLinePriority.OrderByDescending(p => p.Value))
|
|
{
|
|
// 近是远否
|
|
wc = S_BaseService._P_WH_CELL.GetModel(string.Format(sSqlFormat, p.Key,
|
|
$"and FORK_TYPE='{SystemCode.FORK_TYPE.CellNear}' and CELL_FLAG_P='{SystemCode.FLAG.Enable}' and STORAGE_PROPERTY<>STORAGE_PROPERTY_P"));
|
|
if (wc != null)
|
|
{
|
|
return wc;
|
|
}
|
|
// 普通 or 近是 or 远是近空 or 远是近出
|
|
wc = S_BaseService._P_WH_CELL.GetModel(string.Format(sSqlFormat, p.Key,
|
|
$"and (FORK_TYPE<>'{SystemCode.FORK_TYPE.CellFar}'" +
|
|
$" or (STORAGE_ID_P=0 and MANAGE_ID_P=0)" +
|
|
$" or (STORAGE_ID_P>0 and MANAGE_ID_P>0))"));
|
|
if (wc != null)
|
|
{
|
|
return wc;
|
|
}
|
|
// 远是近否
|
|
wc = S_BaseService._P_WH_CELL.GetModel(string.Format(sSqlFormat, p.Key,
|
|
$"and FORK_TYPE='{SystemCode.FORK_TYPE.CellFar}'"));
|
|
if (wc != null)
|
|
{
|
|
return wc;
|
|
}
|
|
}
|
|
sResult = "没有可用起始位置";
|
|
return null;
|
|
}
|
|
|
|
//// 获取入库货位 双叉
|
|
//public bool GetEndCell(string sStartCellCode, int iGoodsIDNear, int iGoodsIDFar, int iStoragePropertyIDNear, int iStoragePropertyIDFar,
|
|
// int iCellX, int iCellY, out WH_CELL wcNearCell, out WH_CELL wcFarCell, out string sResult)
|
|
//{
|
|
// wcNearCell = null;
|
|
// wcFarCell = null;
|
|
// sResult = string.Empty;
|
|
// string sOrderBy = "CELL_X,CELL_Y";
|
|
// if (iCellX > 0 && iCellY > 0)
|
|
// {
|
|
// sOrderBy = $"abs(CELL_X-{iCellX}),abs(CELL_Y-{iCellY})";
|
|
// }
|
|
// string sLineDeviceCode = SystemCode.WH_CELL_CODE.GetLineDeviceCode(sStartCellCode);
|
|
// if (string.IsNullOrWhiteSpace(sLineDeviceCode))
|
|
// {
|
|
// sResult = $"起始位置 {sStartCellCode} 入库路径不可用";
|
|
// return false;
|
|
// }
|
|
// string strFormat = "where CELL_ID=(select top 1 CELL_ID from V_WH_CELL_PAIR_FORK_IN" +
|
|
// $" where DEVICE_CODE='{sLineDeviceCode}' {{0}} order by {sOrderBy})";
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and FORK_TYPE='{SystemCode.FORK_TYPE.ForkFar}'" +
|
|
// $" and CELL_STATUS_P='{SystemCode.CELL_STATUS.Nohave}' and RUN_STATUS_P='{SystemCode.RUN_STATUS.Enable}'"));
|
|
// if (wcFarCell != null)
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModelByCellCode(wcFarCell.CELL_CODE_P);
|
|
// if (wcNearCell != null)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and GOODS_ID_P='{iGoodsIDFar}'"));
|
|
// if (wcFarCell != null)
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and CELL_ID<>{wcFarCell.CELL_ID}" +
|
|
// $" and GOODS_ID_P='{iGoodsIDNear}'"));
|
|
// }
|
|
// if (wcFarCell == null)
|
|
// {
|
|
// if (wcNearCell == null)
|
|
// {
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, string.Empty));
|
|
// }
|
|
// else
|
|
// {
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and CELL_ID<>{wcNearCell.CELL_ID}"));
|
|
// }
|
|
// if (wcFarCell == null)
|
|
// {
|
|
// sResult = "没有可用目标位置";
|
|
// return false;
|
|
// }
|
|
// }
|
|
// if (wcNearCell == null)
|
|
// {
|
|
// if (wcFarCell == null)
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, string.Empty));
|
|
// }
|
|
// else
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and CELL_ID<>{wcFarCell.CELL_ID}"));
|
|
// }
|
|
// if (wcNearCell == null)
|
|
// {
|
|
// sResult = "没有可用目标位置";
|
|
// return false;
|
|
// }
|
|
// }
|
|
// return true;
|
|
//}
|
|
|
|
//// 获取出库货位 双叉
|
|
//public bool GetStartCell(string sEndCellCode, STORAGE_MAIN sm, int iCount, int iCellX, int iCellY,
|
|
// out WH_CELL wcNearCell, out WH_CELL wcFarCell, out string sResult)
|
|
//{
|
|
// sResult = string.Empty;
|
|
// wcNearCell = null;
|
|
// wcFarCell = null;
|
|
// string sOrderBy = "CELL_X,CELL_Y";
|
|
// if (iCellX > 0 && iCellY > 0)
|
|
// {
|
|
// sOrderBy = $"abs(CELL_X-{iCellX}),abs(CELL_Y-{iCellY})";
|
|
// }
|
|
// if (sm.GOODS_ID > SystemCode.GOODS_ID.MaxStock)
|
|
// {
|
|
// sOrderBy = $"ENTRY_TIME,{sOrderBy}";
|
|
// }
|
|
// Dictionary<string, int> dLinePriority = LinePriority(false, sEndCellCode, sm);
|
|
// if (dLinePriority.Count == 0)
|
|
// {
|
|
// sResult = $"目标位置 {sEndCellCode} 出库路径不可用";
|
|
// return false;
|
|
// }
|
|
// foreach (KeyValuePair<string, int> p in dLinePriority.OrderByDescending(p => p.Value))
|
|
// {
|
|
// string strFormat = $"where CELL_ID=(select top 1 CELL_ID from V_WH_CELL_PAIR_FORK_OUT where DEVICE_CODE='{p.Key}'" +
|
|
// $" and GOODS_ID={sm.GOODS_ID} {{0}} order by {sOrderBy})";
|
|
// if (iCount > 1)
|
|
// {
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat,
|
|
// $"and GOODS_ID=GOODS_ID_P and FORK_TYPE='{SystemCode.FORK_TYPE.ForkFar}'" +
|
|
// $" and CELL_STATUS_P<>'{SystemCode.CELL_STATUS.Nohave}' and RUN_STATUS_P='{SystemCode.RUN_STATUS.Enable}'"));
|
|
// if (wcFarCell != null)
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModelByCellCode(wcFarCell.CELL_CODE_P);
|
|
// if (wcNearCell != null)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// }
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, "and GOODS_ID<>GOODS_ID_P"));
|
|
// if (iCount > 1 && wcFarCell != null)
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and CELL_ID<>{wcFarCell.CELL_ID}" +
|
|
// " and GOODS_ID<>GOODS_ID_P"));
|
|
// }
|
|
// if (wcFarCell == null)
|
|
// {
|
|
// if (wcNearCell == null)
|
|
// {
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, string.Empty));
|
|
// }
|
|
// else
|
|
// {
|
|
// wcFarCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and CELL_ID<>{wcNearCell.CELL_ID}"));
|
|
// }
|
|
// }
|
|
// if (iCount > 1 && wcNearCell == null)
|
|
// {
|
|
// if (wcFarCell == null)
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, string.Empty));
|
|
// }
|
|
// else
|
|
// {
|
|
// wcNearCell = S_BaseService._P_WH_CELL.GetModel(string.Format(strFormat, $"and CELL_ID<>{wcFarCell.CELL_ID}"));
|
|
// }
|
|
// }
|
|
// if (wcFarCell != null)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// sResult = "没有可用起始位置";
|
|
// return false;
|
|
//}
|
|
#endregion
|
|
}
|
|
}
|