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.
427 lines
18 KiB
427 lines
18 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ServiceModel;
|
|
using System.Windows.Markup;
|
|
using SSWMS.Common;
|
|
|
|
namespace SSWMS.Server
|
|
{
|
|
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.Single,
|
|
ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = int.MaxValue, UseSynchronizationContext = false)]
|
|
public class S_PlanService : I_PlanService
|
|
{
|
|
public PLAN_MAIN GetPlanMain(int iPlanID)
|
|
{
|
|
return S_BaseService._P_PLAN_MAIN.GetModel(iPlanID);
|
|
}
|
|
|
|
public IList<PLAN_LIST> GetPlanList(int iPlanID)
|
|
{
|
|
return S_BaseService._P_PLAN_LIST.GetListByPlanID(iPlanID);
|
|
}
|
|
|
|
public bool PlanAddOrUpdate(PLAN_MAIN pm, List<PLAN_LIST> lPlanList, out int iPlanID, out string sResult)
|
|
{
|
|
iPlanID = 0;
|
|
sResult = string.Empty;
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
if (pm.PLAN_ID == 0)
|
|
{
|
|
if (S_BaseService._P_PLAN_MAIN.GetModelByPlanCode(pm.PLAN_CODE) != null)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"拣货单号 {pm.PLAN_CODE} 已存在";
|
|
return false;
|
|
}
|
|
S_BaseService._P_PLAN_MAIN.Add(pm);
|
|
iPlanID = pm.PLAN_ID;
|
|
foreach (PLAN_LIST pl in lPlanList)
|
|
{
|
|
//S_BaseService._P_PLAN_LIST.Add(new PLAN_LIST()
|
|
//{
|
|
// PLAN_ID = pm.PLAN_ID,
|
|
// GOODS_ID = pl.GOODS_ID,
|
|
// PLAN_LIST_FINISHED_QUANTITY = pl.PLAN_LIST_FINISHED_QUANTITY,
|
|
// PLAN_LIST_QUANTITY = pl.PLAN_LIST_QUANTITY
|
|
//});
|
|
pl.PLAN_ID = pm.PLAN_ID;
|
|
S_BaseService._P_PLAN_LIST.Add(pl);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
iPlanID = pm.PLAN_ID;
|
|
PLAN_MAIN pmBase = S_BaseService._P_PLAN_MAIN.GetModel(pm.PLAN_ID);
|
|
if (pmBase == null)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"未找到计划ID {pm.PLAN_ID}";
|
|
return false;
|
|
}
|
|
if (pmBase.PLAN_STATUS != SystemCode.PLAN_STATUS.Waiting)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"拣货单号 {pmBase.PLAN_CODE} 正在执行中";
|
|
return false;
|
|
}
|
|
if (pmBase.PLAN_CODE != pm.PLAN_CODE &&
|
|
S_BaseService._P_PLAN_MAIN.GetModelByPlanCode(pm.PLAN_CODE) != null)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"拣货单号 {pm.PLAN_CODE} 已存在";
|
|
return false;
|
|
}
|
|
S_BaseService._P_PLAN_MAIN.Update(pm);
|
|
S_BaseService._P_PLAN_LIST.DeleteByPlanID(pm.PLAN_ID);
|
|
foreach (PLAN_LIST pl in lPlanList)
|
|
{
|
|
//S_BaseService._P_PLAN_LIST.Add(new PLAN_LIST()
|
|
//{
|
|
// PLAN_ID = pm.PLAN_ID,
|
|
// GOODS_ID = pl.GOODS_ID,
|
|
// PLAN_LIST_FINISHED_QUANTITY = pl.PLAN_LIST_FINISHED_QUANTITY,
|
|
// PLAN_LIST_QUANTITY = pl.PLAN_LIST_QUANTITY
|
|
//});
|
|
pl.PLAN_ID = pm.PLAN_ID;
|
|
S_BaseService._P_PLAN_LIST.Add(pl);
|
|
}
|
|
//IList<PLAN_LIST> lPlanListBase = S_BaseService._P_PLAN_LIST.GetListByPlanID(pm.PLAN_ID);
|
|
//int i = 0;
|
|
//for (; i < lPlanListView.Count; ++i)
|
|
//{
|
|
// if (i < lPlanListBase.Count)
|
|
// {
|
|
// lPlanListBase[i].GOODS_ID = lPlanListView[i].GOODS_ID;
|
|
// lPlanListBase[i].PLAN_LIST_FINISHED_QUANTITY = lPlanListView[i].PLAN_LIST_FINISHED_QUANTITY;
|
|
// lPlanListBase[i].PLAN_LIST_QUANTITY = Convert.ToDecimal(lPlanListView[i].PLAN_LIST_QUANTITY);
|
|
// S_BaseService._P_PLAN_LIST.Update(lPlanListBase[i]);
|
|
// }
|
|
// else
|
|
// {
|
|
// S_BaseService._P_PLAN_LIST.Add(new PLAN_LIST()
|
|
// {
|
|
// PLAN_ID = pmBase.PLAN_ID,
|
|
// GOODS_ID = lPlanListView[i].GOODS_ID,
|
|
// PLAN_LIST_FINISHED_QUANTITY = lPlanListView[i].PLAN_LIST_FINISHED_QUANTITY,
|
|
// PLAN_LIST_QUANTITY = lPlanListView[i].PLAN_LIST_QUANTITY
|
|
// });
|
|
// }
|
|
//}
|
|
//for (; i < lPlanListBase.Count; ++i)
|
|
//{
|
|
// S_BaseService._P_PLAN_LIST.Delete(lPlanListBase[i].PLAN_LIST_ID);
|
|
//}
|
|
}
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = ex.Message;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool PlanUpdateStatus(int iPlanID, string sPlanStatus, string sOperator, out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
PLAN_MAIN pm = S_BaseService._P_PLAN_MAIN.GetModel(iPlanID);
|
|
if (pm == null)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"未找到计划ID {iPlanID}";
|
|
return false;
|
|
}
|
|
if (sPlanStatus == SystemCode.PLAN_STATUS.Complete ||
|
|
sPlanStatus == SystemCode.PLAN_STATUS.Delete)
|
|
{
|
|
if (S_BaseService._P_MANAGE_MAIN.GetListByPlanID(iPlanID).Count > 0)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"拣货单号 {pm.PLAN_CODE} 存在任务";
|
|
return false;
|
|
}
|
|
pm.PLAN_END_TIME = StringUtils.GetCurrentTime();
|
|
S_BaseService._P_SYS_LOG.Add(new SYS_LOG()
|
|
{
|
|
OPERATOR = sOperator,
|
|
LOG_TIME = StringUtils.GetCurrentTime(),
|
|
LOG_TYPE = sPlanStatus == SystemCode.PLAN_STATUS.Complete ? "完成计划" : "删除计划",
|
|
LOG_TEXT = $"拣货单号 {pm.PLAN_CODE}"
|
|
});
|
|
}
|
|
else if (sPlanStatus == SystemCode.PLAN_STATUS.Executing)
|
|
{
|
|
pm.PLAN_BEGIN_TIME = StringUtils.GetCurrentTime();
|
|
}
|
|
else if (sPlanStatus == SystemCode.PLAN_STATUS.Pause)
|
|
{
|
|
bool isWaiting = true;
|
|
if (S_BaseService._P_MANAGE_MAIN.GetListByPlanID(pm.PLAN_ID).Count == 0)
|
|
{
|
|
foreach (PLAN_LIST pl in S_BaseService._P_PLAN_LIST.GetListByPlanID(pm.PLAN_ID))
|
|
{
|
|
if (pl.PLAN_LIST_FINISHED_QUANTITY > 0)
|
|
{
|
|
isWaiting = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
isWaiting = false;
|
|
}
|
|
if (isWaiting)
|
|
{
|
|
sPlanStatus = SystemCode.PLAN_STATUS.Waiting;
|
|
}
|
|
}
|
|
else if (sPlanStatus == SystemCode.PLAN_STATUS.Auto)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(pm.PLAN_STATION))
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"请选择出库站台";
|
|
return false;
|
|
}
|
|
if (S_BaseService._P_MANAGE_MAIN.GetListByPlanOut(pm.PLAN_STATION).Count > 0)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"出库站台 {pm.PLAN_STATION} 存在任务";
|
|
return false;
|
|
}
|
|
}
|
|
pm.PLAN_STATUS = sPlanStatus;
|
|
S_BaseService._P_PLAN_MAIN.Update(pm);
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = ex.Message;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool PlanAutoOut(int iPlanID, string sPlanStation, string sPlanLevel, out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
PLAN_MAIN pm = S_BaseService._P_PLAN_MAIN.GetModel(iPlanID);
|
|
if (pm == null)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"未找到计划ID {iPlanID}";
|
|
return false;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(sPlanStation))
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"请选择出库站台";
|
|
return false;
|
|
}
|
|
if (pm.PLAN_TYPE == SystemCode.PLAN_TYPE.PlanOut &&
|
|
(pm.PLAN_STATUS == SystemCode.PLAN_STATUS.Waiting ||
|
|
pm.PLAN_STATUS == SystemCode.PLAN_STATUS.Pause))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"计划状态错误";
|
|
return false;
|
|
}
|
|
pm.PLAN_STATION = sPlanStation;
|
|
pm.PLAN_PROPERTY_04 = sPlanLevel;
|
|
pm.PLAN_STATUS = SystemCode.PLAN_STATUS.Auto;
|
|
pm.PLAN_BEGIN_TIME = StringUtils.GetCurrentTime();
|
|
S_BaseService._P_PLAN_MAIN.Update(pm);
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = ex.Message;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool PlanUpdateErrorText(int iPlanID, string sPlanStatus, string sErrorText, out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
if (sPlanStatus == SystemCode.PLAN_STATUS.Auto)
|
|
{
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
PLAN_MAIN pm = S_BaseService._P_PLAN_MAIN.GetModel(iPlanID);
|
|
if (pm.ERROR_TEXT != sErrorText)
|
|
{
|
|
pm.ERROR_TEXT = sErrorText;
|
|
}
|
|
S_BaseService._P_PLAN_MAIN.Update(pm);
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"异常 {ex.Message}";
|
|
return false;
|
|
}
|
|
}
|
|
else if (sPlanStatus == SystemCode.PLAN_STATUS.Pause)
|
|
{
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
PLAN_MAIN pm = S_BaseService._P_PLAN_MAIN.GetModel(iPlanID);
|
|
if (pm.PLAN_STATUS == SystemCode.PLAN_STATUS.Auto)
|
|
{
|
|
pm.PLAN_STATUS = SystemCode.PLAN_STATUS.Pause;
|
|
bool isWaiting = true;
|
|
if (S_BaseService._P_MANAGE_MAIN.GetListByPlanID(pm.PLAN_ID).Count == 0)
|
|
{
|
|
foreach (PLAN_LIST pl in S_BaseService._P_PLAN_LIST.GetListByPlanID(pm.PLAN_ID))
|
|
{
|
|
if (pl.PLAN_LIST_FINISHED_QUANTITY > 0)
|
|
{
|
|
isWaiting = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
isWaiting = false;
|
|
}
|
|
if (isWaiting)
|
|
{
|
|
sPlanStatus = SystemCode.PLAN_STATUS.Waiting;
|
|
}
|
|
}
|
|
if (pm.ERROR_TEXT != sErrorText)
|
|
{
|
|
pm.ERROR_TEXT = sErrorText;
|
|
}
|
|
S_BaseService._P_PLAN_MAIN.Update(pm);
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"异常 {ex.Message}";
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool PlanListUpdateErrorText(int iPlanListID, string sErrorText, out string sResult)
|
|
{
|
|
sResult = string.Empty;
|
|
try
|
|
{
|
|
S_BaseService._P_Base_House.BeginTransaction();
|
|
PLAN_LIST pl = S_BaseService._P_PLAN_LIST.GetModel(iPlanListID);
|
|
if (string.IsNullOrWhiteSpace(sErrorText))
|
|
{
|
|
pl.ERROR_TEXT = string.Empty;
|
|
S_BaseService._P_PLAN_LIST.Update(pl);
|
|
}
|
|
else
|
|
{
|
|
if (pl.PLAN_LIST_FINISHED_QUANTITY < pl.PLAN_LIST_QUANTITY)
|
|
{
|
|
pl.ERROR_TEXT = sErrorText;
|
|
S_BaseService._P_PLAN_LIST.Update(pl);
|
|
}
|
|
}
|
|
S_BaseService._P_Base_House.CommitTransaction();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
S_BaseService._P_Base_House.RollBackTransaction();
|
|
sResult = $"异常 {ex.Message}";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool PlanTask(out string sResult)
|
|
{
|
|
bool bResult = true;
|
|
sResult = string.Empty;
|
|
foreach (PLAN_MAIN pm in S_BaseService._P_PLAN_MAIN.GetListByStatus(SystemCode.PLAN_STATUS.Auto))
|
|
{
|
|
try
|
|
{
|
|
string sSingleResult = string.Empty;
|
|
if (string.IsNullOrWhiteSpace(pm.PLAN_STATION))
|
|
{
|
|
if (!PlanUpdateErrorText(pm.PLAN_ID, SystemCode.PLAN_STATUS.Pause, "请选择出库站台", out sSingleResult))
|
|
{
|
|
sResult += $"{sSingleResult}\n";
|
|
bResult = false;
|
|
}
|
|
continue;
|
|
}
|
|
string sErrorText = string.Empty;
|
|
//bool isComplete = true;
|
|
foreach (PLAN_LIST pl in S_BaseService._P_PLAN_LIST.GetListByPlanID(pm.PLAN_ID))
|
|
{
|
|
if (pl.PLAN_LIST_FINISHED_QUANTITY >= pl.PLAN_LIST_QUANTITY)
|
|
{
|
|
continue;
|
|
}
|
|
//isComplete = false;
|
|
if (S_BaseService._S_ManageService.ManageOutCell(
|
|
string.Empty, pm.PLAN_STATION, 0, pm.PLAN_ID, pl.PLAN_LIST_ID,
|
|
SystemCode.MANAGE_TYPE.OutCell, pm.PLAN_CREATER, out sErrorText))
|
|
{
|
|
if (!PlanListUpdateErrorText(pl.PLAN_LIST_ID, string.Empty, out sSingleResult))
|
|
{
|
|
sResult += sSingleResult;
|
|
bResult = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!PlanListUpdateErrorText(pl.PLAN_LIST_ID, sErrorText, out sSingleResult))
|
|
{
|
|
sResult += sSingleResult;
|
|
bResult = false;
|
|
}
|
|
}
|
|
}
|
|
//if (isComplete &&
|
|
// S_BaseService._P_MANAGE_MAIN.GetListByPlanID(pm.PLAN_ID).Count == 0)
|
|
//{
|
|
// if (!PlanUpdateStatus(pm.PLAN_ID, SystemCode.PLAN_STATUS.Complete, SystemCode.ConstCode.DefaultOperator, out sSingleResult))
|
|
// {
|
|
// sResult += sSingleResult;
|
|
// bResult = false;
|
|
// }
|
|
//}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sResult += $"异常 {ex.Message}\n";
|
|
bResult = false;
|
|
}
|
|
}
|
|
sResult.Trim('\n');
|
|
return bResult;
|
|
}
|
|
}
|
|
}
|