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.
684 lines
34 KiB
684 lines
34 KiB
1 year ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ServiceModel;
|
||
|
using Newtonsoft.Json;
|
||
|
using SSWMS.Common;
|
||
|
|
||
|
namespace SSWMS.Server
|
||
|
{
|
||
|
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single,
|
||
|
ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = int.MaxValue, UseSynchronizationContext = false)]
|
||
|
public class S_ControlService : I_ControlService
|
||
|
{
|
||
|
// 新增调度任务
|
||
|
public void CreateIOControl(MANAGE_MAIN mm, STORAGE_MAIN sm, IList<STORAGE_LIST> lStorageList, string sCurrentTime)
|
||
|
{
|
||
|
string sStartWarehouseCode = "1";
|
||
|
string sEndWarehouseCode = "1";
|
||
|
string sTaskLevel = "0";
|
||
|
string sControlRemark = string.Empty;
|
||
|
string sPlanCode = string.Empty;
|
||
|
if (mm.PLAN_ID > 0)
|
||
|
{
|
||
|
PLAN_MAIN pm = S_BaseService._P_PLAN_MAIN.GetModel(mm.PLAN_ID);
|
||
|
if (pm != null)
|
||
|
{
|
||
|
sPlanCode = pm.PLAN_CODE;
|
||
|
if (!string.IsNullOrWhiteSpace(pm.PLAN_PROPERTY_04) &&
|
||
|
pm.PLAN_PROPERTY_04 != sTaskLevel)
|
||
|
{
|
||
|
sTaskLevel = pm.PLAN_PROPERTY_04;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
S_BaseService._P_IO_CONTROL.Add(new IO_CONTROL()
|
||
|
{
|
||
|
RELATIVE_CONTROL_ID = -1,
|
||
|
MANAGE_ID = mm.MANAGE_ID,
|
||
|
CONTROL_TASK_TYPE = SystemCode.CONTROL_TYPE.GetControlType(mm.MANAGE_TYPE),
|
||
|
CONTROL_TASK_LEVEL = sTaskLevel,
|
||
|
START_WAREHOUSE_CODE = sStartWarehouseCode,
|
||
|
END_WAREHOUSE_CODE = sEndWarehouseCode,
|
||
|
STOCK_BARCODE = mm.STOCK_BARCODE,
|
||
|
START_DEVICE_CODE = mm.START_CELL_CODE,
|
||
|
END_DEVICE_CODE = mm.END_CELL_CODE,
|
||
|
CONTROL_BEGIN_TIME = sCurrentTime,
|
||
|
PRE_CONTROL_STATUS = SystemCode.CONTROL_STATUS.Waiting,
|
||
|
CONTROL_STATUS = SystemCode.CONTROL_STATUS.Waiting,
|
||
|
CONTROL_REMARK = sControlRemark,
|
||
|
STOCK_SIZE = lStorageList[0].STORAGE_PROPERTY_10,
|
||
|
STOCK_HEIGHT = lStorageList.Count > 1 ? SystemCode.STOCK_HEIGHT.High : lStorageList[0].STORAGE_PROPERTY_09,
|
||
|
PLAN_CODE = sPlanCode
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 新增入出库记录 立库
|
||
|
private void CreateRecord(MANAGE_MAIN mm, IList<MANAGE_LIST> lManageList)
|
||
|
{
|
||
|
RECORD_MAIN rm = new RECORD_MAIN
|
||
|
{
|
||
|
MANAGE_TYPE = mm.MANAGE_TYPE,
|
||
|
MANAGE_STATUS = mm.MANAGE_STATUS,
|
||
|
PLAN_ID = mm.PLAN_ID,
|
||
|
STOCK_BARCODE = mm.STOCK_BARCODE,
|
||
|
START_POSITION = mm.START_CELL_CODE,
|
||
|
END_POSITION = mm.END_CELL_CODE,
|
||
|
NEXT_POSITION = mm.NEXT_CELL_CODE,
|
||
|
MANAGE_BEGIN_TIME = mm.MANAGE_CREATE_TIME,
|
||
|
MANAGE_END_TIME = StringUtils.GetCurrentTime(),
|
||
|
RECORD_OPERATOR = mm.MANAGE_OPERATOR,
|
||
|
RECORD_REMARK = mm.MANAGE_REMARK
|
||
|
};
|
||
|
S_BaseService._P_RECORD_MAIN.Add(rm);
|
||
|
foreach (MANAGE_LIST ml in lManageList)
|
||
|
{
|
||
|
STORAGE_LIST sl = S_BaseService._P_STORAGE_LIST.GetModel(ml.STORAGE_LIST_ID);
|
||
|
S_BaseService._P_RECORD_LIST.Add(new RECORD_LIST()
|
||
|
{
|
||
|
RECORD_ID = rm.RECORD_ID,
|
||
|
GOODS_ID = sl == null ? 0 : sl.GOODS_ID,
|
||
|
BOX_BARCODE = sl == null ? string.Empty : sl.BOX_BARCODE,
|
||
|
GOODS_BARCODE = sl == null ? string.Empty : sl.GOODS_BARCODE,
|
||
|
RECORD_LIST_QUANTITY = ml.MANAGE_LIST_QUANTITY,
|
||
|
STORAGE_PROPERTY_01 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_01,
|
||
|
STORAGE_PROPERTY_02 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_02,
|
||
|
STORAGE_PROPERTY_03 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_03,
|
||
|
STORAGE_PROPERTY_04 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_04,
|
||
|
STORAGE_PROPERTY_05 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_05,
|
||
|
STORAGE_PROPERTY_06 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_06,
|
||
|
STORAGE_PROPERTY_07 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_07,
|
||
|
STORAGE_PROPERTY_08 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_08,
|
||
|
STORAGE_PROPERTY_09 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_09,
|
||
|
STORAGE_PROPERTY_10 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_10,
|
||
|
STORAGE_PROPERTY_11 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_11,
|
||
|
STORAGE_PROPERTY_12 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_12
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 新增入出库记录 暂存
|
||
|
public void CreateRecord(string sManageType, STORAGE_MAIN sm, IList<STORAGE_LIST> lStorageList, string sOperator)
|
||
|
{
|
||
|
string sCurrentTime = StringUtils.GetCurrentTime();
|
||
|
RECORD_MAIN rm = new RECORD_MAIN
|
||
|
{
|
||
|
MANAGE_TYPE = sManageType,
|
||
|
MANAGE_STATUS = SystemCode.MANAGE_STATUS.Complete,
|
||
|
PLAN_ID = sm.PLAN_ID,
|
||
|
STOCK_BARCODE = sm.STOCK_BARCODE,
|
||
|
START_POSITION = sManageType == SystemCode.MANAGE_TYPE.InPing ? SystemCode.WH_CELL_CODE.GroupDeviceCode : sm.CELL_CODE,
|
||
|
END_POSITION = sManageType == SystemCode.MANAGE_TYPE.OutPing ? SystemCode.WH_CELL_CODE.GroupDeviceCode : sm.CELL_CODE,
|
||
|
MANAGE_BEGIN_TIME = sCurrentTime,
|
||
|
MANAGE_END_TIME = sCurrentTime,
|
||
|
RECORD_OPERATOR = sOperator,
|
||
|
RECORD_REMARK = string.Empty
|
||
|
};
|
||
|
S_BaseService._P_RECORD_MAIN.Add(rm);
|
||
|
foreach (STORAGE_LIST sl in lStorageList)
|
||
|
{
|
||
|
S_BaseService._P_RECORD_LIST.Add(new RECORD_LIST()
|
||
|
{
|
||
|
RECORD_ID = rm.RECORD_ID,
|
||
|
GOODS_ID = sl == null ? 0 : sl.GOODS_ID,
|
||
|
BOX_BARCODE = sl == null ? string.Empty : sl.BOX_BARCODE,
|
||
|
GOODS_BARCODE = sl == null ? string.Empty : sl.GOODS_BARCODE,
|
||
|
RECORD_LIST_QUANTITY = sl == null ? 0 : sl.STORAGE_LIST_QUANTITY,
|
||
|
STORAGE_PROPERTY_01 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_01,
|
||
|
STORAGE_PROPERTY_02 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_02,
|
||
|
STORAGE_PROPERTY_03 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_03,
|
||
|
STORAGE_PROPERTY_04 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_04,
|
||
|
STORAGE_PROPERTY_05 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_05,
|
||
|
STORAGE_PROPERTY_06 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_06,
|
||
|
STORAGE_PROPERTY_07 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_07,
|
||
|
STORAGE_PROPERTY_08 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_08,
|
||
|
STORAGE_PROPERTY_09 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_09,
|
||
|
STORAGE_PROPERTY_10 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_10,
|
||
|
STORAGE_PROPERTY_11 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_11,
|
||
|
STORAGE_PROPERTY_12 = sl == null ? string.Empty : sl.STORAGE_PROPERTY_12
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 任务执行
|
||
|
public bool ManageExecute(int MANAGE_ID, out string sResult)
|
||
|
{
|
||
|
sResult = string.Empty;
|
||
|
try
|
||
|
{
|
||
|
S_BaseService._P_Base_House.BeginTransaction();
|
||
|
|
||
|
S_BaseService._P_Base_House.CommitTransaction();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
sResult = ex.Message;
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// 任务完成
|
||
|
public bool ManageComplete(int iManageID, int iControlID, out string sResult)
|
||
|
{
|
||
|
sResult = string.Empty;
|
||
|
try
|
||
|
{
|
||
|
S_BaseService._P_Base_House.BeginTransaction();
|
||
|
// 管理任务
|
||
|
MANAGE_MAIN mm = S_BaseService._P_MANAGE_MAIN.GetModel(iManageID);
|
||
|
IList<MANAGE_LIST> lManageList = S_BaseService._P_MANAGE_LIST.GetListByManageID(iManageID);
|
||
|
if (mm == null || lManageList == null || lManageList.Count == 0)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
sResult = $"未找到任务ID {iManageID}";
|
||
|
return false;
|
||
|
}
|
||
|
if (iControlID == 0)
|
||
|
{
|
||
|
IO_CONTROL ic = S_BaseService._P_IO_CONTROL.GetModelByManageID(iManageID);
|
||
|
if (ic != null && ic.CONTROL_STATUS != SystemCode.CONTROL_STATUS.Complete)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
sResult = $"任务ID {iManageID} 调度任务状态错误";
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 新增入出库记录
|
||
|
//mm.MANAGE_STATUS = SystemCode.MANAGE_STATUS.Complete;
|
||
|
mm.MANAGE_STATUS = SystemCode.MANAGE_STATUS.Interface;
|
||
|
this.CreateRecord(mm, lManageList);
|
||
|
|
||
|
// 更新计划
|
||
|
string sCurrentTime = StringUtils.GetCurrentTime();
|
||
|
string sPlanCode = string.Empty;
|
||
|
if (mm.PLAN_ID > 0)
|
||
|
{
|
||
|
PLAN_MAIN pm = S_BaseService._P_PLAN_MAIN.GetModel(mm.PLAN_ID);
|
||
|
if (pm != null)
|
||
|
{
|
||
|
sPlanCode = pm.PLAN_CODE;
|
||
|
}
|
||
|
if (S_BaseService._P_MANAGE_MAIN.GetListByPlanID(mm.PLAN_ID).Count == 1 &&
|
||
|
pm != null &&
|
||
|
(pm.PLAN_STATUS == SystemCode.PLAN_STATUS.Executing ||
|
||
|
pm.PLAN_STATUS == SystemCode.PLAN_STATUS.Auto))
|
||
|
{
|
||
|
IList<PLAN_LIST> lPlanList = S_BaseService._P_PLAN_LIST.GetListByPlanID(mm.PLAN_ID);
|
||
|
if (lPlanList != null && lPlanList.Count > 0)
|
||
|
{
|
||
|
bool bPlanComplete = true;
|
||
|
foreach (PLAN_LIST pl in lPlanList)
|
||
|
{
|
||
|
if (pl.PLAN_LIST_FINISHED_QUANTITY < pl.PLAN_LIST_QUANTITY)
|
||
|
{
|
||
|
bPlanComplete = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (bPlanComplete)
|
||
|
{
|
||
|
pm.PLAN_STATUS = SystemCode.PLAN_STATUS.Complete;
|
||
|
pm.ERROR_TEXT = string.Empty;
|
||
|
pm.PLAN_END_TIME = sCurrentTime;
|
||
|
S_BaseService._P_PLAN_MAIN.Update(pm);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 更新库存
|
||
|
STORAGE_MAIN sm = S_BaseService._P_STORAGE_MAIN.GetModelByStockBarcode(mm.STOCK_BARCODE);
|
||
|
//STORAGE_MAIN sm = S_BaseService._P_STORAGE_MAIN.GetModel(mm.STORAGE_ID);
|
||
|
if (sm != null)
|
||
|
{
|
||
|
switch (mm.MANAGE_TYPE)
|
||
|
{
|
||
|
case SystemCode.MANAGE_TYPE.InCell:
|
||
|
case SystemCode.MANAGE_TYPE.OutPick:
|
||
|
case SystemCode.MANAGE_TYPE.MoveCell:
|
||
|
case SystemCode.MANAGE_TYPE.MoveStation:
|
||
|
sm.CELL_CODE = mm.END_CELL_CODE;
|
||
|
sm.UPDATE_TIME = sCurrentTime;
|
||
|
S_BaseService._P_STORAGE_MAIN.Update(sm);
|
||
|
break;
|
||
|
case SystemCode.MANAGE_TYPE.OutCell:
|
||
|
S_BaseService._P_STORAGE_LIST.DeleteByStorageID(sm.STORAGE_ID);
|
||
|
S_BaseService._P_STORAGE_MAIN.Delete(sm.STORAGE_ID);
|
||
|
LED.Update(mm.END_CELL_CODE, string.Empty, sm.STOCK_BARCODE, string.IsNullOrWhiteSpace(sPlanCode) ? "手动出库" : sPlanCode);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 删除任务
|
||
|
if (mm.APPLY_ID > 0)
|
||
|
{
|
||
|
S_BaseService._P_IO_CONTROL_APPLY.Delete(mm.APPLY_ID);
|
||
|
}
|
||
|
S_BaseService._P_IO_CONTROL.DeleteByManageID(iManageID);
|
||
|
|
||
|
S_BaseService._P_MANAGE_LIST.DeleteByManageID(iManageID);
|
||
|
S_BaseService._P_MANAGE_MAIN.Delete(iManageID);
|
||
|
S_BaseService._P_Base_House.CommitTransaction();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
sResult = ex.Message;
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// 任务删除
|
||
|
public bool ManageDelete(int iManageID, int iControlID, out string sResult)
|
||
|
{
|
||
|
sResult = string.Empty;
|
||
|
try
|
||
|
{
|
||
|
S_BaseService._P_Base_House.BeginTransaction();
|
||
|
// 管理任务
|
||
|
MANAGE_MAIN mm = S_BaseService._P_MANAGE_MAIN.GetModel(iManageID);
|
||
|
IList<MANAGE_LIST> lManageList = S_BaseService._P_MANAGE_LIST.GetListByManageID(iManageID);
|
||
|
if (mm == null || lManageList == null || lManageList.Count == 0)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
sResult = $"未找到任务ID {iManageID}";
|
||
|
return false;
|
||
|
}
|
||
|
if (iControlID == 0)
|
||
|
{
|
||
|
IO_CONTROL ic = S_BaseService._P_IO_CONTROL.GetModelByManageID(iManageID);
|
||
|
if (ic != null && ic.CONTROL_STATUS != SystemCode.CONTROL_STATUS.Delete)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
sResult = $"任务ID {iManageID} 调度任务状态错误";
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 新增入出库记录
|
||
|
mm.MANAGE_STATUS = SystemCode.MANAGE_STATUS.Delete;
|
||
|
this.CreateRecord(mm, lManageList);
|
||
|
|
||
|
// 更新计划
|
||
|
if (mm.PLAN_ID > 0 && (mm.MANAGE_TYPE == SystemCode.MANAGE_TYPE.InCell ||
|
||
|
mm.MANAGE_TYPE == SystemCode.MANAGE_TYPE.OutCell || mm.MANAGE_TYPE == SystemCode.MANAGE_TYPE.MoveCell))
|
||
|
{
|
||
|
IList<PLAN_LIST> lPlanList = S_BaseService._P_PLAN_LIST.GetListByPlanID(mm.PLAN_ID);
|
||
|
if (lPlanList != null && lPlanList.Count > 0)
|
||
|
{
|
||
|
foreach (MANAGE_LIST ml in lManageList)
|
||
|
{
|
||
|
STORAGE_LIST sl = S_BaseService._P_STORAGE_LIST.GetModel(ml.STORAGE_LIST_ID);
|
||
|
if (sl != null)
|
||
|
{
|
||
|
foreach (PLAN_LIST pl in lPlanList)
|
||
|
{
|
||
|
if (string.IsNullOrWhiteSpace(pl.GOODS_BARCODE) || sl.GOODS_BARCODE == pl.GOODS_BARCODE)
|
||
|
{
|
||
|
pl.PLAN_LIST_FINISHED_QUANTITY -= ml.MANAGE_LIST_QUANTITY;
|
||
|
S_BaseService._P_PLAN_LIST.Update(pl);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 更新库存
|
||
|
if (mm.MANAGE_TYPE == SystemCode.MANAGE_TYPE.InCell)
|
||
|
{
|
||
|
STORAGE_MAIN sm = S_BaseService._P_STORAGE_MAIN.GetModelByStockBarcode(mm.STOCK_BARCODE);
|
||
|
//STORAGE_MAIN sm = S_BaseService._P_STORAGE_MAIN.GetModel(mm.STORAGE_ID);
|
||
|
if (sm != null)
|
||
|
{
|
||
|
S_BaseService._P_STORAGE_LIST.DeleteByStorageID(sm.STORAGE_ID);
|
||
|
S_BaseService._P_STORAGE_MAIN.Delete(sm.STORAGE_ID);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 删除任务
|
||
|
if (mm.APPLY_ID > 0)
|
||
|
{
|
||
|
IO_CONTROL_APPLY ica = S_BaseService._P_IO_CONTROL_APPLY.GetModel(mm.APPLY_ID);
|
||
|
if (ica != null)
|
||
|
{
|
||
|
ica.APPLY_TASK_STATUS = SystemCode.APPLY_STATUS.Error;
|
||
|
ica.ERROR_TEXT = "任务删除";
|
||
|
S_BaseService._P_IO_CONTROL_APPLY.Update(ica);
|
||
|
}
|
||
|
}
|
||
|
S_BaseService._P_IO_CONTROL.DeleteByManageID(iManageID);
|
||
|
S_BaseService._P_MANAGE_LIST.DeleteByManageID(iManageID);
|
||
|
S_BaseService._P_MANAGE_MAIN.Delete(iManageID);
|
||
|
S_BaseService._P_Base_House.CommitTransaction();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
sResult = ex.Message;
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// 任务状态更新
|
||
|
private void ManageUpdateStatus(MANAGE_MAIN mm, IO_CONTROL ic, string sManageStatus, string sResult)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
S_BaseService._P_Base_House.BeginTransaction();
|
||
|
if (mm.MANAGE_TYPE == SystemCode.MANAGE_TYPE.OutCell ||
|
||
|
mm.MANAGE_TYPE == SystemCode.MANAGE_TYPE.OutPick)
|
||
|
{
|
||
|
mm.LOCK_CELL_CODE = null;
|
||
|
}
|
||
|
mm.MANAGE_STATUS = sManageStatus;
|
||
|
mm.ERROR_TEXT = sResult;
|
||
|
if (sManageStatus == SystemCode.MANAGE_STATUS.Executing)
|
||
|
{
|
||
|
mm.MANAGE_BEGIN_TIME = StringUtils.GetCurrentTime();
|
||
|
}
|
||
|
S_BaseService._P_MANAGE_MAIN.Update(mm);
|
||
|
ic.PRE_CONTROL_STATUS = ic.CONTROL_STATUS;
|
||
|
S_BaseService._P_IO_CONTROL.Update(ic);
|
||
|
//S_BaseService._P_Base_House.ExecuteNonQuery(
|
||
|
// $"update IO_CONTROL set PRE_CONTROL_STATUS={ic.CONTROL_STATUS} where CONTROL_ID={ic.CONTROL_ID}");
|
||
|
S_BaseService._P_Base_House.CommitTransaction();
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public readonly static Dictionary<string, string> dScanBack = new Dictionary<string, string>()
|
||
|
{
|
||
|
{ "126902", "126901" },
|
||
|
{ "127002", "127001" },
|
||
|
{ "130003", "120003" },
|
||
|
{ "130206", "120208" },
|
||
|
{ "130706", "120708" },
|
||
|
{ "131106", "121108" },
|
||
|
{ "19003", "126501" },
|
||
|
{ "19004", "126601" },
|
||
|
{ "19005", "126701" },
|
||
|
{ "19006", "126801" },
|
||
|
{ "19014", "121512" }
|
||
|
};
|
||
|
// 更新申请任务
|
||
|
private void ApplyUpdateStatus(IO_CONTROL_APPLY ica, int iApplyStatus, string sResult)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
S_BaseService._P_Base_House.BeginTransaction();
|
||
|
if (iApplyStatus == SystemCode.APPLY_STATUS.Finish)
|
||
|
{
|
||
|
LED.Update(ica.DEVICE_CODE, string.Empty, ica.STOCK_BARCODE, "入库成功");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (string.IsNullOrWhiteSpace(ica.CONTROL_APPLY_REMARK))
|
||
|
{
|
||
|
if (dScanBack.ContainsKey(ica.DEVICE_CODE) &&
|
||
|
S_BaseService._P_Base_House.GetDataTable(
|
||
|
$"select 1 from IO_CONTROL where START_DEVICE_CODE='{ica.DEVICE_CODE}' and END_DEVICE_CODE='{dScanBack[ica.DEVICE_CODE]}' and CONTROL_STATUS<10"
|
||
|
).Rows.Count == 0)
|
||
|
{
|
||
|
S_BaseService._P_IO_CONTROL.Add(new IO_CONTROL()
|
||
|
{
|
||
|
RELATIVE_CONTROL_ID = -1,
|
||
|
CONTROL_TASK_LEVEL = "0",
|
||
|
STOCK_BARCODE = "111111",
|
||
|
CONTROL_TASK_TYPE = SystemCode.CONTROL_TYPE.MoveStation,
|
||
|
PRE_CONTROL_STATUS = SystemCode.CONTROL_STATUS.Waiting,
|
||
|
CONTROL_STATUS = SystemCode.CONTROL_STATUS.Waiting,
|
||
|
START_WAREHOUSE_CODE = "1",
|
||
|
END_WAREHOUSE_CODE = "1",
|
||
|
START_DEVICE_CODE = ica.DEVICE_CODE,
|
||
|
END_DEVICE_CODE = dScanBack[ica.DEVICE_CODE],
|
||
|
CONTROL_BEGIN_TIME = StringUtils.GetCurrentTime(),
|
||
|
STOCK_SIZE = "1",
|
||
|
STOCK_HEIGHT = "1"
|
||
|
});
|
||
|
}
|
||
|
ica.CONTROL_APPLY_REMARK = sResult;
|
||
|
}
|
||
|
ica.APPLY_TASK_STATUS = iApplyStatus;
|
||
|
S_BaseService._P_IO_CONTROL_APPLY.AddHistory(ica);
|
||
|
LED.Update(ica.DEVICE_CODE, string.Empty, ica.STOCK_BARCODE, ica.CONTROL_APPLY_REMARK);
|
||
|
}
|
||
|
S_BaseService._P_IO_CONTROL_APPLY.Delete(ica.APPLY_ID);
|
||
|
S_BaseService._P_Base_House.CommitTransaction();
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 任务线程 调度任务
|
||
|
public bool IOControlTask(out string sResult)
|
||
|
{
|
||
|
bool bResult = true;
|
||
|
sResult = string.Empty;
|
||
|
foreach (IO_CONTROL ic in S_BaseService._P_IO_CONTROL.GetListByStatus(SystemCode.CONTROL_STATUS.Runing))
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
MANAGE_MAIN mm = S_BaseService._P_MANAGE_MAIN.GetModel(ic.MANAGE_ID);
|
||
|
if (mm == null)
|
||
|
{
|
||
|
if (ic.CONTROL_STATUS == SystemCode.CONTROL_STATUS.Complete ||
|
||
|
ic.CONTROL_STATUS == SystemCode.CONTROL_STATUS.Delete)
|
||
|
{
|
||
|
S_BaseService._P_IO_CONTROL.Delete(ic.CONTROL_ID);
|
||
|
MainWindow.log.Debug($"CONTROL_DELETE {ic.START_DEVICE_CODE} {ic.END_DEVICE_CODE} {ic.CONTROL_STATUS} {ic.CONTROL_BEGIN_TIME} {StringUtils.GetCurrentTime()}");
|
||
|
}
|
||
|
continue;
|
||
|
}
|
||
|
bool bSingleResult = true;
|
||
|
string sSingleResult = string.Empty;
|
||
|
switch (ic.CONTROL_STATUS)
|
||
|
{
|
||
|
case SystemCode.CONTROL_STATUS.Delete:
|
||
|
case SystemCode.CONTROL_STATUS.ExceptionDelete:
|
||
|
case SystemCode.CONTROL_STATUS.DuplicateDelete:
|
||
|
bSingleResult = this.ManageDelete(ic.MANAGE_ID, ic.CONTROL_ID, out sSingleResult);
|
||
|
break;
|
||
|
case SystemCode.CONTROL_STATUS.Complete:
|
||
|
case SystemCode.CONTROL_STATUS.ExceptionComplete:
|
||
|
bSingleResult = this.ManageComplete(ic.MANAGE_ID, ic.CONTROL_ID, out sSingleResult);
|
||
|
break;
|
||
|
case SystemCode.CONTROL_STATUS.Runing:
|
||
|
case SystemCode.CONTROL_STATUS.DeviceRuning:
|
||
|
this.ManageUpdateStatus(mm, ic, SystemCode.MANAGE_STATUS.Executing, string.Empty);
|
||
|
break;
|
||
|
}
|
||
|
if (!bSingleResult)
|
||
|
{
|
||
|
this.ManageUpdateStatus(mm, ic, SystemCode.MANAGE_STATUS.Error, sSingleResult);
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
sResult += $"调度任务ID {ic.CONTROL_ID} {ex.Message}\n";
|
||
|
bResult = false;
|
||
|
}
|
||
|
}
|
||
|
sResult.Trim('\n');
|
||
|
return bResult;
|
||
|
}
|
||
|
|
||
|
// 任务线程 申请任务
|
||
|
public bool IOControlApplyTask(out string sResult)
|
||
|
{
|
||
|
bool bResult = true;
|
||
|
sResult = string.Empty;
|
||
|
string sSingleResult = string.Empty;
|
||
|
foreach (IO_CONTROL_APPLY ica in S_BaseService._P_IO_CONTROL_APPLY.GetListByStatus(SystemCode.APPLY_STATUS.Waiting))
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
switch (ica.CONTROL_APPLY_TYPE)
|
||
|
{
|
||
|
case SystemCode.APPLY_TYPE.ScanIn:
|
||
|
STORAGE_MAIN sm = null;
|
||
|
IList<STORAGE_LIST> lStorageList = null;
|
||
|
string sStockBarcode = ica.STOCK_BARCODE;
|
||
|
if (string.IsNullOrWhiteSpace(ica.STOCK_BARCODE) || ica.STOCK_BARCODE == "111111")
|
||
|
{
|
||
|
if (!string.IsNullOrWhiteSpace(ica.CONTROL_APPLY_REMARK))
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, string.Empty);
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
else if (ica.STOCK_BARCODE.StartsWith("{"))
|
||
|
{
|
||
|
StockBarcodeData data = JsonConvert.DeserializeObject<StockBarcodeData>(ica.STOCK_BARCODE);
|
||
|
if (data != null)
|
||
|
{
|
||
|
sStockBarcode = data.salverNumver;
|
||
|
ica.STOCK_BARCODE = sStockBarcode;
|
||
|
}
|
||
|
}
|
||
|
else if (ica.STOCK_BARCODE.StartsWith("\"") &&
|
||
|
ica.STOCK_BARCODE.Length == 22)
|
||
|
{
|
||
|
sStockBarcode = ica.STOCK_BARCODE.Substring(1, 20);
|
||
|
ica.STOCK_BARCODE = sStockBarcode;
|
||
|
}
|
||
|
|
||
|
MANAGE_MAIN mm = S_BaseService._P_MANAGE_MAIN.GetModelByInSend(ica.DEVICE_CODE);
|
||
|
if (mm != null &&
|
||
|
mm.MANAGE_TYPE == SystemCode.MANAGE_TYPE.InCell &&
|
||
|
mm.MANAGE_STATUS == SystemCode.MANAGE_STATUS.Send)
|
||
|
{
|
||
|
if (!string.IsNullOrWhiteSpace(sStockBarcode) && sStockBarcode != "111111" && sStockBarcode != mm.STOCK_BARCODE)
|
||
|
{
|
||
|
if (this.ManageDelete(mm.MANAGE_ID, 0, out sSingleResult))
|
||
|
{
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"入库站台 {ica.DEVICE_CODE} 删除手动任务失败 {sSingleResult}");
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sm = S_BaseService._P_STORAGE_MAIN.GetModel(mm.STORAGE_ID);
|
||
|
if (sm == null)
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"托盘条码 {mm.STOCK_BARCODE} 未找到库存");
|
||
|
continue;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
lStorageList = S_BaseService._P_STORAGE_LIST.GetListByStorageID(sm.STORAGE_ID);
|
||
|
if (lStorageList == null || lStorageList.Count == 0)
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"托盘条码 {mm.STOCK_BARCODE} 未找到库存列表");
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
if (lStorageList.Count == 1 && ica.STOCK_COUNT == SystemCode.STOCK_HEIGHT.High)
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"单托货物托盘超高");
|
||
|
continue;
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
S_BaseService._P_Base_House.BeginTransaction();
|
||
|
mm.ERROR_TEXT = string.Empty;
|
||
|
mm.MANAGE_STATUS = SystemCode.MANAGE_STATUS.Waiting;
|
||
|
S_BaseService._P_MANAGE_MAIN.Update(mm);
|
||
|
S_BaseService._S_ControlService.CreateIOControl(mm, sm, lStorageList, StringUtils.GetCurrentTime());
|
||
|
S_BaseService._P_Base_House.CommitTransaction();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
S_BaseService._P_Base_House.RollBackTransaction();
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"异常 {ex.Message}");
|
||
|
continue;
|
||
|
}
|
||
|
ica.STOCK_BARCODE = mm.STOCK_BARCODE;
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Finish, string.Empty);
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
if (string.IsNullOrWhiteSpace(ica.STOCK_BARCODE) || ica.STOCK_BARCODE == "111111")
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, "扫码异常");
|
||
|
continue;
|
||
|
}
|
||
|
if (!StringUtils.StockBarcodeValidate(sStockBarcode))
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"托盘条码 {sStockBarcode} 格式错误");
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
sm = S_BaseService._P_STORAGE_MAIN.GetModelByStockBarcode(sStockBarcode);
|
||
|
lStorageList = null;
|
||
|
if (sm == null)
|
||
|
{
|
||
|
lStorageList = S_BaseService._S_ERPService.ERPGetBarCode(ica.STOCK_BARCODE, out sSingleResult);
|
||
|
if (lStorageList == null || lStorageList.Count == 0)
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"接口异常 托盘条码 {sStockBarcode} {sSingleResult}");
|
||
|
continue;
|
||
|
}
|
||
|
sm = new STORAGE_MAIN()
|
||
|
{
|
||
|
STOCK_BARCODE = sStockBarcode,
|
||
|
CELL_MODEL = SystemCode.CELL_MODEL.Low,
|
||
|
CELL_CODE = ica.DEVICE_CODE
|
||
|
};
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"托盘条码 {sStockBarcode} 存在库存");
|
||
|
continue;
|
||
|
//if (sm.CELL_CODE.Contains("-"))
|
||
|
//{
|
||
|
// this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"托盘条码 {sStockBarcode} 存在库存");
|
||
|
// continue;
|
||
|
//}
|
||
|
//sm.CELL_CODE = ica.DEVICE_CODE;
|
||
|
//sm.CELL_MODEL = SystemCode.CELL_MODEL.Low;
|
||
|
//sm.STOCK_WEIGHT = ica.STOCK_WEIGHT;
|
||
|
//lStorageList = S_BaseService._P_STORAGE_LIST.GetListByStorageID(sm.STORAGE_ID);
|
||
|
}
|
||
|
if (lStorageList.Count == 1 && ica.STOCK_COUNT == SystemCode.STOCK_HEIGHT.High)
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, $"单托货物托盘超高");
|
||
|
continue;
|
||
|
}
|
||
|
if (S_BaseService._S_ManageService.ManageInCell(sm, lStorageList, string.Empty, false, "WMS", out sSingleResult))
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Finish, string.Empty);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.ApplyUpdateStatus(ica, SystemCode.APPLY_STATUS.Error, sSingleResult);
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
sResult += $"申请任务ID {ica.APPLY_ID} {ex.Message}\n";
|
||
|
bResult = false;
|
||
|
}
|
||
|
}
|
||
|
sResult.Trim('\n');
|
||
|
return bResult;
|
||
|
}
|
||
|
}
|
||
|
}
|