ldj/WcfService1/BLL/lWmsPlate.cs

1371 lines
46 KiB
C#
Raw Normal View History

2023-05-23 16:13:17 +08:00

/// <summary>
///LOGIC CLASS FOR TABLE t_WmsPlate
///By wm with codesmith.
///on 04/06/2020
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeiNiu.wms.Data.Model;
using System.Data;
using System.Transactions;
using DeiNiu.Utils;
2023-11-21 19:18:23 +08:00
using System.Threading;
2023-05-23 16:13:17 +08:00
namespace DeiNiu.wms.Logical
{
[Serializable]
public class lWmsPlate :lbase
{
WmsPlate _obj;
public lWmsPlate()
{
initialize();
}
public WmsPlate getWmsPlate
{
get
{
if (_obj == null)
{
_obj = new WmsPlate();
}
_obj.operater = operId;
return _obj;
}
}
2023-09-04 22:41:19 +08:00
WmsPlateStock_tmp _plateStk;
2024-02-06 19:36:47 +08:00
public WmsPlateStock_tmp plateStk
2023-09-04 22:41:19 +08:00
{
get
{
if (_plateStk == null)
{
_plateStk = new WmsPlateStock_tmp();
}
_plateStk.operater = operId;
return _plateStk;
}
}
2023-11-21 19:18:23 +08:00
lWmsOutPickRequest _lop;
public lWmsOutPickRequest lop
{
get
{
if (_lop == null || _lop.operId!=operId)
{
// log.Debug(string.Format("_lop is null? {0},lop.operId {1}, operId {2}", _lop == null, lop.operId, operId));
_lop = new lWmsOutPickRequest(operId);
}
return _lop;
}
}
2023-09-04 22:41:19 +08:00
public lWmsPlate(int operId)
2023-05-23 16:13:17 +08:00
: base(operId)
{
initialize();
}
/// <summary>
/// get all data
/// </summary>
public DataSet getAllData()
{
return _obj.Query();
}
/// <summary>
/// get all data
/// </summary>
public DataSet getAllActiveData()
{
return _obj.QueryActived();
}
/// <summary>
/// get a record by id
/// </summary>
public void initialize(int id)
{
_obj = id != 0 ? new WmsPlate(id) : new WmsPlate();
}
/// <summary>
/// get a record by id 0
/// </summary>
public void initialize()
{
initialize(0);
}
/// <summary>
/// get a record by id
/// </summary>
public void initialize(DataRow dr)
{
_obj = new WmsPlate(dr);
}
protected override DeiNiu.Data.BaseObject.BaseModel getModel()
{
return _obj;
}
//begin cust db operation, query, excute sql etc.
internal int add(WmsPlate obj,int count)
{
for (int i = 0; i < count; i++)
{
2024-02-06 19:36:47 +08:00
obj.inPlate = "";
2023-05-23 16:13:17 +08:00
obj.Add();
2024-02-06 19:36:47 +08:00
obj.plateId = Util.getBoxId((enumPlateLevel)obj.type, obj.color, plateStk.getNextSeq("seqplate" + obj.type + obj.color));
2023-05-23 16:13:17 +08:00
obj.Update();
2023-12-03 22:13:49 +08:00
2023-05-23 16:13:17 +08:00
}
return 1;
}
/// <summary>
/// put goods into a plate
/// </summary>
2023-09-04 22:41:19 +08:00
2023-05-23 16:13:17 +08:00
public enumRegPlateResult inPlate(string plateId,enumPlateStatus type, string goodsId,string barcode,int skuId,decimal count,string orderNo)
{
2023-09-04 22:41:19 +08:00
/*if (valid( plateId, type, goodsId, skuId) == enumRegPlateResult.)
2023-05-23 16:13:17 +08:00
{
using (TransactionScope scope = new TransactionScope())
{
WmsPlate plate = new WmsPlate(plateId);
plate.type =(int)type;
WmsPlateStock_tmp pst = new WmsPlateStock_tmp(plateId,skuId);
if (pst.ID == 0)
{
pst.plateId = plateId;
pst.goodsId = goodsId;
pst.skuId = skuId;
pst.count = count;
pst.operater = operId;
pst.barcode = barcode;
pst.Add();
}
else
{
pst.count += count;
pst.operater = operId;
pst.Update();
}
switch (type)
{
// case enumPlateStatus.播种周转:
// plate.customerId = orderNo;
// break;
case enumPlateStatus.:
plate.locationId = orderNo;
break;
case enumPlateStatus.:
break;
case enumPlateStatus.:
plate.preInOrderNo = orderNo;
break;
case enumPlateStatus.:
plate.pickOrderNo = orderNo;
break;
case enumPlateStatus.:
plate.transNo = orderNo;
break;
}
plate.operater = operId;
plate.Update();
scope.Complete();
}
2023-09-04 22:41:19 +08:00
}*/
2023-05-23 16:13:17 +08:00
return enumRegPlateResult.;
}
2023-09-04 22:41:19 +08:00
2023-05-23 16:13:17 +08:00
private enumRegPlateResult valid(string plateId, enumPlateStatus type, string goodsId, int skuId)
{
if (enumPlateStatus. == type)
{
WmsPlateStock_tmp pst = new WmsPlateStock_tmp();
DataTable dt = pst.getPlateStockDetail(plateId);
if (dt.Rows.Count == 0)
{
return enumRegPlateResult.;
}
foreach (DataRow dr in dt.Rows)
{
if (dr["goodsId"].ToString() == goodsId)//存在goodsid
{
return enumRegPlateResult.;
}
}
WmsGoods wg = new WmsGoods(goodsId);
foreach (DataRow dr in dt.Rows)
{
2023-11-21 19:18:23 +08:00
if ( Convert.ToInt32(dr["goodsType"].ToString()) == wg.goodsType)//存在goods type
2023-05-23 16:13:17 +08:00
{
return enumRegPlateResult.;
}
}
return enumRegPlateResult.使;
}
return enumRegPlateResult.;
}
2023-09-04 22:41:19 +08:00
/// <summary>
/// 下级容器可并入上级容器
/// 客户笼车、线路码头 集货验证
/// </summary>
/// <param name="fromPlate"></param>
/// <param name="toPlate"></param>
/// <returns></returns>
2023-11-21 19:18:23 +08:00
public enumRegPlateResult putPlateIntoPlate(string fromPlate, string toPlate)
2023-09-04 22:41:19 +08:00
{
//
WmsPlate toP = new WmsPlate(toPlate);
WmsPlate fromP = new WmsPlate(fromPlate);
if (toP.type <= fromP.type)
{
return enumRegPlateResult.;
}
2023-11-21 19:18:23 +08:00
else if (fromP.getParentPlate(fromPlate).ID > 0)
{
2024-02-06 19:36:47 +08:00
return enumRegPlateResult.;
2023-11-21 19:18:23 +08:00
}
2023-09-04 22:41:19 +08:00
2023-11-21 19:18:23 +08:00
List<WmsOutPickRequest> requests = getWmsPlate.getPlateRequests(fromPlate, true);
if (requests.Count == 0)
{
return enumRegPlateResult.;
}
2023-09-04 22:41:19 +08:00
WmsPlatePack wpp = new WmsPlatePack();
2023-11-21 19:18:23 +08:00
// wpp.getUpPlateId(fromPlate);
2023-09-04 22:41:19 +08:00
wpp.plateId = toPlate;
wpp.subPlateId = fromPlate;
2023-11-21 19:18:23 +08:00
string custId = "";
int lineId = 0;
2023-09-04 22:41:19 +08:00
2023-11-21 19:18:23 +08:00
toP.volume += fromP.volume;
toP.load += fromP.load;
if (toP.type == (int)enumPlateLevel.)
{
2024-02-06 19:36:47 +08:00
WmsPlateStock_tmp ptmp = new WmsPlateStock_tmp();
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
if (new WmsPlatePack(toPlate, fromPlate).ID > 0)
2023-11-21 19:18:23 +08:00
{
return enumRegPlateResult.;
}
2023-09-04 22:41:19 +08:00
2024-02-06 19:36:47 +08:00
custId = requests[0].customerId;
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
List<WmsFlow> jflows = new List<WmsFlow>();
2023-09-04 22:41:19 +08:00
2024-02-06 19:36:47 +08:00
foreach(WmsOutPickRequest wop in requests)
{
jflows.Add(new WmsFlow(wop.pickOrderNo + fromPlate));
2023-11-21 19:18:23 +08:00
}
2023-09-04 22:41:19 +08:00
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
if (string.IsNullOrEmpty(toP.customerId) || toP.customerId == custId)
{
2024-02-06 19:36:47 +08:00
DataTable dt = ptmp.getStockLst(fromPlate);
2023-11-21 19:18:23 +08:00
using (TransactionScope scope = new TransactionScope())
{
2024-02-06 19:36:47 +08:00
foreach (DataRow dr in dt.Rows)
{
ptmp = new WmsPlateStock_tmp(dr);
if (toP.partion == 0)
{
if (fromP.partion == 0)
{
WmsGoods goods = new WmsGoods(ptmp.goodsId);
fromP.partion = goods.part;
fromP.Update();
}
toP.partion = fromP.partion;
toP.Update();
}
DataTable dt1 = ptmp.getOutPort(ptmp.outPortId);
foreach (DataRow dr1 in dt1.Rows)
{
custId = dr1["customerId"].ToString();
lineId = Convert.ToInt32(dr1["lineId"].ToString());
toP.volume += Convert.ToDecimal(dr1["volCm"].ToString());
toP.load += Convert.ToDecimal(dr1["weight"].ToString());
break;
}
/*
if(flow.orderNo.Equals(ptmp.orderNo) || flow.flowNo.Equals(fromPlate))
{
flow = new WmsFlow(ptmp.orderNo + ptmp.plateId);
}
*/
foreach(WmsFlow flow in jflows)
{
flow.finishedTasksPlus(operId, 1);
}
ptmp.inPlate = toPlate;
ptmp.Update();
}
//客户容器不进行线路集货, 直接装车,则生成装车任务
if (!WmsConstants.IS_PLATE_IN_LINE && string.IsNullOrEmpty(toP.customerId))
{
string ldTask = toP.jobNo;
if (string.IsNullOrEmpty(ldTask)) //
{
foreach (WmsOutPickRequest req in requests)
{
if (string.IsNullOrEmpty(req.loadTruckJob))
{
ldTask = requests[0].createLoadTruckJob(operId);
}
else
{
ldTask = req.loadTruckJob; //每个订单一个装车任务,在开始分拣时生成
}
break;
}
}
WmsFlow wmsflow = new WmsFlow(ldTask);
wmsflow.taskCnt++;// 每个订单的装车任务的 客户集货容器数量
wmsflow.Update();
toP.jobNo = wmsflow.task;
}
toP.customerId = custId;
toP.lineId = lineId;
2023-11-21 19:18:23 +08:00
wpp.removeUp();
wpp.operater = operId;
wpp.Add();
fromP.inPlate = toP.plateId;
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
fromP.Update();
toP.Update();
2024-02-06 19:36:47 +08:00
foreach (WmsOutPickRequest req in requests)
{
if (string.IsNullOrEmpty(req.loadTruckJob) && string.IsNullOrEmpty(toP.jobNo))
{
req.loadTruckJob = toP.jobNo;
req.Update();
}
if (req.state == (int)enumOutStockRequestStatus.)
{
foreach (WmsFlow flow in jflows)
{
if (flow.orderNo == req.pickOrderNo)
{
if (flow.getUnFinishedByOrderNo(req.pickOrderNo, EnumFlowTaskType.).Rows.Count == 0)
{
req.state = (int)enumOutStockRequestStatus.;
req.Update();
}
}
}
}
}
2023-11-21 19:18:23 +08:00
scope.Complete();
}
return enumRegPlateResult.;
2023-09-04 22:41:19 +08:00
}
else if (toP.customerId != custId)
{
2023-11-21 19:18:23 +08:00
return enumRegPlateResult.;
2023-09-04 22:41:19 +08:00
}
}
2023-11-21 19:18:23 +08:00
else
2023-09-04 22:41:19 +08:00
2023-11-21 19:18:23 +08:00
if (toP.type == (int)enumPlateLevel.线)
2023-09-04 22:41:19 +08:00
{
2023-11-21 19:18:23 +08:00
// log.Debug(string.Format("线路集货 from plate {0}, to plate {1}, to plate line id {2},from plate line id {3}",fromPlate,toPlate,toP.lineId,lineId));
2024-02-06 19:36:47 +08:00
if (!String.IsNullOrEmpty(fromP.inPlate))
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
// return enumRegPlateResult.容器已完成码头集货;
2023-11-21 19:18:23 +08:00
}
if (fromP.type != (int)enumPlateLevel.)
{
2024-02-06 19:36:47 +08:00
// return enumRegPlateResult.码头集货需要客户类型的容器;
}
if (!String.IsNullOrEmpty(toP.inPlate))
{
return enumRegPlateResult.;
}
if (WmsConstants.JIHUO_CHECK_PRE_STATE)
{
if (fromP.type == (int)enumPlateLevel.)
{
WmsFlow flow = new WmsFlow();
foreach (WmsOutPickRequest req in requests)
{
/* if (req.state != (int)enumOutStockRequestStatus. && req.state == (int)enumOutStockRequestStatus.)
{
if (flow.getUnFinishedByOrderNo(req.pickOrderNo, EnumFlowTaskType. ).Rows.Count == 0)
{
req.state = (int)enumOutStockRequestStatus.;
req.Update();
}
}
if (req.state != (int)enumOutStockRequestStatus.)
{
return enumRegPlateResult.;
}*/
if (flow.getUnFinishedByOrderNo(req.pickOrderNo, EnumFlowTaskType.).Rows.Count > 0)
{
return enumRegPlateResult.;
}
}
}
2023-11-21 19:18:23 +08:00
}
// 检测客户是否已经在其它码头集货
DataTable dt2 = getWmsPlate.getLineId(fromP.customerId);
foreach (DataRow dr in dt2.Rows)
{
WmsPlate wp = new WmsPlate(dr);
if (!String.IsNullOrEmpty(wp.inPlate) && wp.inPlate != toP.plateId)
{
return enumRegPlateResult.;
}
}
2023-09-04 22:41:19 +08:00
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
if (toP.lineId == 0)
2023-09-04 22:41:19 +08:00
{
2023-11-21 19:18:23 +08:00
toP.lineId = fromP.lineId;
2023-09-04 22:41:19 +08:00
}
2024-02-06 19:36:47 +08:00
else if (WmsConstants.IS_PLATE_IN_LINE && toP.lineId != (fromP.lineId) && fromP.lineId > 0)
2023-09-04 22:41:19 +08:00
{
2024-02-06 19:36:47 +08:00
return enumRegPlateResult.线;
2023-09-04 22:41:19 +08:00
}
2023-11-21 19:18:23 +08:00
fromP.inPlate = toP.plateId;
2024-02-06 19:36:47 +08:00
WmsPlateStock_tmp ptmp = new WmsPlateStock_tmp();
DataTable dt = ptmp.getStockLst(fromPlate);
2023-11-21 19:18:23 +08:00
using (TransactionScope scope = new TransactionScope())
{
2024-02-06 19:36:47 +08:00
foreach (DataRow dr in dt.Rows)
{
ptmp = new WmsPlateStock_tmp(dr);
ptmp.inPlate = toPlate;
ptmp.Update();
}
toP.volume += fromP.volume;
toP.load += fromP.load;
2023-11-21 19:18:23 +08:00
wpp.removeUp();
wpp.operater = operId;
wpp.Add();
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
toP.Update();
WmsFlow wmsflow = new WmsFlow();
wmsflow.operater = operId;
wmsflow.orderNo = toP.plateId;
wmsflow.flowNo = fromP.plateId;
wmsflow.type = (int)EnumFlowTaskType.;
wmsflow.typeName = EnumFlowTaskType..ToString();
wmsflow.task = Util.getOrderNo(enumCreateOrderType.pickJobNo, _obj.getNextSeq(enumCreateOrderType.pickJobNo));
wmsflow.taskCnt = fromP.getSubPlateIds(fromP.plateId).Count;
wmsflow.Add();
2024-02-06 19:36:47 +08:00
foreach (WmsOutPickRequest req in requests)
2023-11-21 19:18:23 +08:00
{
req.loadTruckJob = wmsflow.task;
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
req.Update();
}
2024-02-06 19:36:47 +08:00
fromP.jobNo = wmsflow.task;
2023-11-21 19:18:23 +08:00
fromP.Update();
scope.Complete();
}
2023-09-04 22:41:19 +08:00
}
2024-02-06 19:36:47 +08:00
else if (toP.type == (int)enumPlateLevel.)
2023-09-04 22:41:19 +08:00
{
2023-11-21 19:18:23 +08:00
//容器临时库存转移到车辆结束拣货单据更新拣货状态通知erp
//update the pickrequest directly to validation status.
if (fromP.type != (int)enumPlateLevel.线)
{
2024-02-06 19:36:47 +08:00
// return enumRegPlateResult.装车集货需要码头类型的容器;
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
if (!String.IsNullOrEmpty(fromP.inPlate))
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
// return enumRegPlateResult.容器已完成装车集货;
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
fromP.inPlate = toP.plateId;
List<WmsPlate> custPlates = fromP.getSubPlates(fromP.plateId);
log.Debug(string.Format(" 装车 {0} ,码头拣货单数量 {1}", fromPlate, requests.Count));
using (TransactionScope scope = new TransactionScope())
{
2024-02-06 19:36:47 +08:00
toP.volume += fromP.volume;
toP.load += fromP.load;
2023-11-21 19:18:23 +08:00
if (string.IsNullOrEmpty(toP.transNo))
{
toP.transNo = Util.getOrderNo(enumCreateOrderType.transOrder, _obj.getNextSeq(enumCreateOrderType.transOrder));
toP.Update();
logPlate.Debug(string.Format("plate {0} start new trans {1}", toPlate, toP.transNo));
2024-02-06 19:36:47 +08:00
new lTmsTranRequest(operId).createSimpleTran(requests, toP);// req.transNo = toP.transNo;
2023-11-21 19:18:23 +08:00
}
// toP.Update();
wpp.removeUp();
wpp.operater = operId;
wpp.Add();
fromP.Update();
log.Debug(string.Format(" 集货,自动复核 {0} ,客户拣货单数量 {1}", fromPlate, requests.Count));
foreach (WmsOutPickRequest req in requests)
{
// log.Debug(string.Format(" 集货,开始复核客户拣货单 {0}", req.pickOrderNo));
2024-02-06 19:36:47 +08:00
//TODO: check 订单没有集货的容器,没有完成拣货的订单
/*
if (req.state >= (int)enumOutStockRequestStatus.
//|| req.state == (int)enumOutStockRequestStatus.复核异常)
)
{
// check all flowno
WmsPlateStock_tmp wst = new WmsPlateStock_tmp();
DataTable dt = wst.getByOrder(req.pickOrderNo);
DataView dv = dt.DefaultView;
dv.RowFilter = "isnull(inPlate,'') = ''";
if (dv.Count == 0)
{
req.state = (int)enumOutStockRequestStatus.;
}
}
*/
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
foreach (WmsPlate plate in custPlates)
2023-11-21 19:18:23 +08:00
{
plate.transNo = toPlate;
plate.Update();
}
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
scope.Complete();
}
}
2024-02-06 19:36:47 +08:00
// log.Debug(string.Format("to plate custid {0}, to plate lineid {1} ", toP.customerId, toP.lineId ));
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
return enumRegPlateResult.;
}
/// <summary>
/// 按客户装车
/// </summary>
/// <param name="fromPlate">客户集货的容器号码</param>
/// <returns></returns>
2024-02-06 19:36:47 +08:00
public enumRegPlateResult loadTruck(string fromPlate, string toPlate)
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
logPlate.Debug("start load truck, fromPlate " + fromPlate + ", toPlate " + toPlate);
2023-11-21 19:18:23 +08:00
WmsPlate fromP = new WmsPlate(fromPlate);
2024-02-06 19:36:47 +08:00
if (fromP.getParentPlate(fromPlate).ID > 0)
{
return enumRegPlateResult.;
}
2023-11-21 19:18:23 +08:00
/*
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
if (fromP.type != (int)enumPlateLevel.)
{
return enumRegPlateResult.;
}
2024-02-06 19:36:47 +08:00
if (String.IsNullOrEmpty(fromP.inPlate))
{
return enumRegPlateResult.;
}
if (String.IsNullOrEmpty(fromP.transNo))
{
return enumRegPlateResult.;
}
if (!fromP.transNo.Trim().ToUpper() .Equals(toPlate.Trim().ToUpper()))
{
return enumRegPlateResult.;
}
*/
List<WmsOutPickRequest> requests = getWmsPlate.getPlateRequests(fromPlate, true);
if (requests.Count == 0)
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
return enumRegPlateResult.;
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
if (string.IsNullOrEmpty(requests[0].customerId))
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
return enumRegPlateResult.;
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
WmsPlateStock_tmp ptmp = new WmsPlateStock_tmp();
WmsFlow jflow = new WmsFlow();
// List<WmsFlow> jflows = new List<WmsFlow>();
WmsPlate toP = new WmsPlate(toPlate);
int lineId = fromP.lineId;
if (fromP.ID == 0 || fromP.volume==0 ) //临时容器
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
DataTable dt2 = ptmp.getStockLst(fromPlate);
foreach (DataRow dr in dt2.Rows)
{
ptmp = new WmsPlateStock_tmp(dr);
if (jflow.ID == 0)
{
jflow = new WmsFlow(ptmp.jobNo); // 拣货任务??
}
DataTable dt1 = ptmp.getOutPort(ptmp.outPortId);
foreach (DataRow dr1 in dt1.Rows)
{
lineId = Convert.ToInt32(dr1["lineId"].ToString());
fromP.volume += Convert.ToDecimal(dr1["volCm"].ToString());
fromP.load += Convert.ToDecimal(dr1["weight"].ToString());
break;
}
/*
if(string.IsNullOrEmpty(ptmp.inPlate))
{
ptmp.inPlate = toPlate;
ptmp.Update();
}*/
}
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
toP.load += fromP.load;
toP.volume += fromP.volume;
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
if (toP.ID == 0) //非注册车辆,可能为第三方运单等
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
toP.plateId = toPlate;
toP.type = (int)enumPlateLevel.;
toP.plateLevel = toP.type;
toP.lineId = lineId;
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
if(WmsConstants.IS_PLATE_IN_LINE && lineId>0 && lineId != toP.lineId)
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
return enumRegPlateResult.线;
}
WmsPlatePack wpp = new WmsPlatePack();
wpp.plateId = toPlate;
wpp.subPlateId = fromPlate;
DataTable dt = getPateJobsDt(fromPlate);
DataView dv = dt.DefaultView;
dv.RowFilter = String.Format("orderNo='{0}'", requests[0].pickOrderNo);
2023-11-21 19:18:23 +08:00
using (TransactionScope scope = new TransactionScope())
2024-02-06 19:36:47 +08:00
{
if (jflow.ID > 0)
{
jflow.finishedTasksPlus(operId,1, false, true);
}
wpp.removeUp();
int id= wpp.Add();
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
log.Debug("load truck add plate pack id " + id);
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
//支持跳过线路集货,直接装车
if (string.IsNullOrEmpty(toP.transNo))
{
toP.transNo = Util.getOrderNo(enumCreateOrderType.transOrder, _obj.getNextSeq(enumCreateOrderType.transOrder));
logPlate.Debug(string.Format("plate {0} start new trans {1}", toPlate, toP.transNo));
new lTmsTranRequest(operId).createSimpleTran(requests, toP);// req.transNo = toP.transNo;
// return enumRegPlateResult.完成装车集货后才能装车;
}
else
{
foreach (WmsOutPickRequest op in requests)
{
if (string.IsNullOrEmpty(op.transNo))
{
op.operater = operId;
op.transNo = toP.transNo;
op.Update();
TmsTranRequestDetail td = new TmsTranRequestDetail();
td.pickOrderNo = op.pickOrderNo;
td.transNo = toP.transNo;
td.operater = operId;
td.Add();
}
}
}
foreach (DataRowView drv in dv)
{
WmsPlateStock_tmp wst = new WmsPlateStock_tmp(drv.Row);
wst.transNo = toP.transNo;
wst.inPlate = toPlate;
wst.Update();
}
TmsTranRequest tmsTranRequest = new TmsTranRequest(toP.transNo);
tmsTranRequest.sumVol += toP.volume;
tmsTranRequest.sumWeight += toP.load;
tmsTranRequest.Update();
if (toP.ID == 0)
{
toP.Add();
}
else
{
toP.Update();
}
2023-11-21 19:18:23 +08:00
foreach (WmsOutPickRequest req in requests)
{
2024-02-06 19:36:47 +08:00
if (req.state == (int)enumOutStockRequestStatus.)
{
req.state = (int)enumOutStockRequestStatus.;
req.Update();
}
}
if (fromP.ID > 0)
{
//to release plates of customer type
List<WmsPlate> lst = getWmsPlate.getSubPlates(fromPlate);
foreach (WmsPlate s in lst)
{
s.releaseSubPlate(s.plateId); //to release customer and its subs
// log.Debug(string.Format("on truck load, released plate {0}, type{1}", s.plateId, (enumPlateLevel)s.type));
}
getWmsPlate.releaseSubPlate(fromPlate); //to release custType type and its subs
log.Debug(string.Format("on truck load, released plate {0} ", fromPlate));
}
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
//to release plate of Line
// 线路码头容器里面的客户容器是否已经全部装车了,如果都已装车(释放),则释放线路容器
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
if (fromP.plateLevel == (int)enumPlateLevel.)
{
WmsPlate linePlate = new WmsPlate(fromP.inPlate);
if (linePlate.lineId > 0)
{
int cnt = getWmsPlate.getSubPlates(linePlate.plateId).Count;
logOut.Debug(string.Format(" line plate {0} sub plates cnt {1}", linePlate.plateId, cnt));
if (cnt == 0)
{
linePlate.releaseSubPlate(linePlate.plateId);
}
}
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
}
string ldTask = fromP.jobNo;
// if (string.IsNullOrEmpty(ldTask)) // 非固定容器、非客户集货类型的容器,容器没有装车任务信息
{
foreach (WmsOutPickRequest req in requests) //容器里可能有多个分拣单,多个装车任务
{
ldTask = req.loadTruckJob;
WmsFlow flow = new WmsFlow(ldTask); // ref: fromP.pickOrderNo = wmsflow.task;
flow.finishedTasksPlus(operId, 1, true);
logPlate.Debug("updated loadtruck task " + ldTask);
}
}
//客户容器的装车任务
2023-11-21 19:18:23 +08:00
2023-09-04 22:41:19 +08:00
scope.Complete();
2024-02-06 19:36:47 +08:00
}
2023-11-21 19:18:23 +08:00
return enumRegPlateResult.;
}
internal enumRegPlateResult startTran(string plateId)
{
WmsPlate plate = new WmsPlate(plateId);
2024-02-06 19:36:47 +08:00
if (plate.ID > 0 && plate.type != (int)enumPlateLevel.)
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
// return enumRegPlateResult.发车需要运输类型的容器;
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
if (string.IsNullOrEmpty(plate.transNo))
{
return enumRegPlateResult.;
}
TmsTranRequest tmsTranRequest = new TmsTranRequest(plate.transNo);
if (tmsTranRequest.state == (int)enumTranStatus.)
{
return enumRegPlateResult.;
}
2024-02-06 19:36:47 +08:00
if (WmsConstants.IS_PLATE_IN_LINE)
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
List<WmsPlate> lst = getWmsPlate.getSubPlates(plateId);
foreach (WmsPlate s in lst)//to release line and its subs
{
s.releaseSubPlate(s.plateId);
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
// log.Debug(string.Format("on start tran load, released plate {0}, type{1}", s.plateId, (enumPlateLevel)s.type));
}
}
plate.partion = 0;
//TODO: 按车发货,订单满足关单条件(全部发出) 再关单
2023-11-21 19:18:23 +08:00
Thread threadPreProcess = new Thread(new ParameterizedThreadStart(porcessStock4TransStart));
threadPreProcess.IsBackground = true;
threadPreProcess.Start(plate);
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
return enumRegPlateResult.;
}
void porcessStock4TransStart(object plate)
{
2024-02-06 19:36:47 +08:00
try
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
WmsPlate tranP = (WmsPlate)plate;
List<WmsOutPickRequest> requests = new lWmsOutPickRequest(operId).getRequestsByTransNo(tranP.transNo);
logPlate.Debug("装车后续处理。。。。开始, plateId " + tranP.plateId);
WmsPlateStock_tmp wpt = new WmsPlateStock_tmp();
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
using (TransactionScope scope = new TransactionScope())
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
foreach (WmsOutPickRequest req in requests)
{
// req.state = (int)enumOutStockRequestStatus.已出库;
// req.Update();
logPlate.Debug(" 开始处理 " + req.pickOrderNo);
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
req.finishAllFlowTasks(req.pickOrderNo);//完成所有未完成的任务
logPlate.Debug(" force finished all tasks of " + req.pickOrderNo);
DataTable dt = wpt.getByOrder(req.pickOrderNo);
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
foreach (DataRow dr in dt.Rows)
{
wpt = new WmsPlateStock_tmp(dr);
WmsStock stk = new WmsStock(wpt.locationid, wpt.skuId, wpt.goodsId);
stk.plateCount -= wpt.count;
stk.updateCountOut();
}
//to finish all pick tasks
WmsOutPickPort wop = new WmsOutPickPort();
DataTable dt2 = wop.getPickDetails(req.pickOrderNo, (int)enumPickState.);
foreach (DataRow dr in dt2.Rows)
{
wop = new WmsOutPickPort(dr);
WmsStock st = new WmsStock(wop.locationId, Convert.ToInt32(dr["skuId"].ToString()), dr["goodsId"].ToString());
if (wop.virtialCnt > 0) //还回未出库虚拟库存
{
st.virtialCount -= wop.virtialCnt;
st.virtialCount = st.virtialCount > 0 ? st.virtialCount : 0;
WmsStock virSt = st.getVirStock(st.goodsId);
virSt.countOuting -= wop.virtialCnt;
virSt.updateCountOut();
}
st.countOuting -= wop.count;
st.countOuting = st.countOuting > 0 ? st.countOuting : 0; ;
st.updateCountOut();
}
wop.closePickPorts(req.pickOrderNo);
logPlate.Debug(" 关闭所有的拣货任务, 释放锁定库存 " + req.pickOrderNo);
//to realse plate tmp stock.
int cnt = wpt.releasePlateByOrder(req.pickOrderNo);
logPlate.Debug(req.pickOrderNo + " released tmp stock item cnt " + cnt);
lop.finishRequest(req); //更新订单状态通知ERP
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
getWmsPlate.releaseSubPlate(tranP.plateId); //to release truck type and its subs
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
logPlate.Debug(" 释放此次运输相关临时容器 " + tranP.plateId);
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
log.Debug("装车后续处理。。。。结束");
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
TmsTranRequest tmsTranRequest = new TmsTranRequest(tranP.transNo);
tmsTranRequest.state = (int)enumTranStatus.;
tmsTranRequest.Update();
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
if (tranP.plateLevel == (int)enumPlateLevel.)
{
// tranP.Delete();
}
scope.Complete();
}
2023-11-21 19:18:23 +08:00
2023-09-04 22:41:19 +08:00
}
2024-02-06 19:36:47 +08:00
catch (Exception er)
{
logPlate.Error(er);
}
2023-09-04 22:41:19 +08:00
}
2023-12-03 22:13:49 +08:00
public enumRegPlateResult mergePlate(string fromPlate, string toPlate)
2023-09-04 22:41:19 +08:00
{
2023-12-03 22:13:49 +08:00
// stock out port plate merge
List<WmsOutPickRequest> requests = getWmsPlate.getPlateRequests(fromPlate, true);
WmsPlate fromP = new WmsPlate(fromPlate);
WmsPlate toP = new WmsPlate(toPlate);
if (fromP.plateLevel != toP.plateLevel)
{
return enumRegPlateResult.;
}
if (fromP.getParentPlate(fromPlate).ID > 0
&& fromP.getParentPlate(fromPlate).ID != toP.getParentPlate(toPlate).ID)
{
return enumRegPlateResult.;
}
using (TransactionScope scope = new TransactionScope())
{
foreach (WmsOutPickRequest wop in requests)
{
2024-02-06 19:36:47 +08:00
plateStk.merge(fromPlate, toPlate, wop.pickOrderNo);
2023-12-03 22:13:49 +08:00
}
scope.Complete();
}
return 0;
2023-09-04 22:41:19 +08:00
}
public void releasePlateStock(string plateId,decimal count, int inPortId =0,int outPortId =0)
{
logPlate.Debug(string.Format("plateId {0},count {1},inPortId {2},outPortId {3}", plateId, count, inPortId, outPortId));
WmsPlateStock_tmp plateStock = new WmsPlateStock_tmp();
if(count==0 && inPortId==0 && outPortId == 0)
{
int cnt= plateStock.releasePlate(plateId);
logPlate.Debug(string.Format("release plate {0} ",plateId));
return;
}
DataTable dt;
if (inPortId > 0) {
dt = plateStock.getPlateIn(plateId, inPortId);
}
else
dt = plateStock.getPlateOut(plateId, outPortId);
logPlate.Debug(string.Format(" stk items count {0} ", dt.Rows.Count));
foreach (DataRow dr in dt.Rows)
{
WmsPlateStock_tmp tmp = new WmsPlateStock_tmp(dr);
tmp.count -= count;
if (tmp.count <= 0)
{
tmp.Delete();
logPlate.Debug(string.Format("release stk {0} ", tmp.ID));
}
else
{
tmp.Update();
}
}
}
public DataTable getPateJobsDt(string plateId, bool showSub = false)
{
2023-11-21 19:18:23 +08:00
DataTable dt = getWmsPlate.getPateJobsDt( plateId, showSub );
logTest.Debug(string.Format("plate {0} ,showSub {1}, all contents size {2}", plateId, showSub, dt.Rows.Count));
return dt;
2023-09-04 22:41:19 +08:00
}
2023-11-21 19:18:23 +08:00
2024-02-06 19:36:47 +08:00
internal DataTable queryRegistedPlate(string flowNo)
{
return getWmsPlate.queryRegistedPlate(flowNo);
}
internal DataTable getFromPlate(string flowNo)
2023-11-21 19:18:23 +08:00
{
2024-02-06 19:36:47 +08:00
return getWmsPlate.queryFromPlate(flowNo);
2023-11-21 19:18:23 +08:00
}
2024-02-06 19:36:47 +08:00
2023-11-21 19:18:23 +08:00
internal enumRegPlateResult takeOutPlate(string fromPlate, string plate)
{
WmsPlatePack wpp = new WmsPlatePack(fromPlate,plate);
log.Debug(string.Format("fromPlate {0}, plate {1}", fromPlate, plate));
if (wpp.ID == 0)
{
return enumRegPlateResult.;
}
using (TransactionScope scope = new TransactionScope())
{
wpp.Delete();
if (wpp.getSubPlates(fromPlate).Rows.Count == 0)
{
WmsPlate wmsPlate = new WmsPlate(fromPlate);
wmsPlate.customerId = "";
wmsPlate.lineId = 0;
wmsPlate.Update();
}
scope.Complete();
}
return enumRegPlateResult.;
}
2024-02-06 19:36:47 +08:00
/// <summary>
/// 容器复核
/// </summary>
/// <param name="portId"></param>
/// <param name="skuId"></param>
/// <param name="productDate"></param>
/// <param name="validDate"></param>
/// <param name="batch"></param>
/// <param name="validationCnt"></param>
/// <param name="validReason"></param>
/// <param name="finialValidation">是否只纠正账目,品相正确只是数量差异,则按实际拿的发</param>
/// <returns></returns>
internal enumOutValidResult plateValidation(string plateId,int portId,int skuId,string productDate,string validDate,string batch, decimal validationCnt, string validReason,bool finialValidation=true)
{
log.Debug(string.Format("容器复核。。。。 portId {0}, skuId {1}, productDate {2}, validDate {3}, batch {4}, validationCnt {5}, validReason {6}, finialValidation {7}",
portId, skuId, productDate, validDate, batch, validationCnt, validReason, finialValidation));
WmsPlateStock_tmp wst = new WmsPlateStock_tmp().getModelByOutPort(plateId,portId);
2023-11-21 19:18:23 +08:00
WmsOutPickPort wpp = new WmsOutPickPort(portId);
2024-02-06 19:36:47 +08:00
WmsOutPickDetail wpd = new WmsOutPickDetail(wpp.pickDetailId);
// WmsOrderRequest wor = new WmsOrderRequest();
2023-11-21 19:18:23 +08:00
wpp.validationCnt = validationCnt;
wpp.checkBy = operId;
wpp.checkTime = wpp.getDateTime();
wpp.validationReason = validReason;
decimal diffCnt = wst.count - validationCnt;
2024-02-06 19:36:47 +08:00
if (!finialValidation) //
{
wpp.description += "; 实物多退少补";
diffCnt = 0;
}
log.Debug(string.Format("容器复核 原数量 {0}, 差异 {1} ", wst.count, diffCnt));
WmsStock stk = null;
2023-11-21 19:18:23 +08:00
WmsStockRecord wsr = null;
if (diffCnt != 0)
{
wst.count = validationCnt;
wsr = new WmsStockRecord(wpp.recordId);
stk = new WmsStock(wpp.locationId, skuId);
2024-02-06 19:36:47 +08:00
// stk.adjustingCnt += diffCnt;
stk.count += diffCnt;
log.Debug(string.Format("容器复核 volType {0}, 差异 {1}, pickdetail id {2} ,pick bulk cnt {3}, seeded cnt {4} pick batch cnt {5} ", wst.count, diffCnt,wpd.ID, wpd.bulkPicked,wpd.seeded,wpd.batchPicked));
//少拿不补
//多拿不退
2023-11-21 19:18:23 +08:00
if (wpp.volType == 0)
{
wpd.bulkPicked -= diffCnt;
}
else
{
2024-02-06 19:36:47 +08:00
wpd.batchPicked -= diffCnt;
2023-11-21 19:18:23 +08:00
}
}
using (TransactionScope scope = new TransactionScope())
{
2024-02-06 19:36:47 +08:00
wpp.Update();
2023-11-21 19:18:23 +08:00
if (diffCnt != 0)
{
2024-02-06 19:36:47 +08:00
string description = string.Format("\n 业务类型:{0} {5},拣货任务{1},计划数量 {2} 实际数量{3} 备注:{4}", "容器复核",
wpp.ID,wpp.count,validationCnt, validReason, finialValidation ? " 按拣货数量发货" :" 实物多退少补,按需求发" );
log.Debug(description);
int i = wpd.Update();
log.Debug(" pick detail count updated rows " + i);
2023-11-21 19:18:23 +08:00
wst.Update();
2024-02-06 19:36:47 +08:00
if (stk.Update() == 0)
{
stk.locationId = new WmsLocation().getLocation(enumWhLocVol., wpd.goods.part, wpd.goods.ABC).locationId;
stk.goodsId = wsr.goodsId;
2023-11-21 19:18:23 +08:00
stk.skuId = skuId;
2024-02-06 19:36:47 +08:00
stk.batch = batch;
2023-11-21 19:18:23 +08:00
stk.productDate = productDate;
stk.validDate = validDate;
stk.Add();
}
2024-02-06 19:36:47 +08:00
wsr.description = description;
wsr.Update(); //更新记录
wsr.count = validationCnt;
wsr.count1 = diffCnt;
wsr.locationId = stk.locationId;
wsr.operater = operId;
wsr.rectype = (int)enumStockRecordType.;
wsr.Add(); //新增记录
2023-11-21 19:18:23 +08:00
}
scope.Complete();
}
//new lWmsOutPickRequest(operId).validationPickrequests();//对于复核完毕的订单进行回传erp操作
return enumOutValidResult.;
}
2024-02-06 19:36:47 +08:00
internal string getLatestPlate(string custId, string goodsId)
{
return getWmsPlate.getLatestPlate(custId, goodsId).plateId;
}
public DataTable getUnLoadTruckStks(string toPlate, int cnt)
{
return plateStk.getUnLoadTruckStks(toPlate,cnt);
}
public DataTable getLoadContent(string toPlate)
{
return plateStk.getLoadContent(toPlate);
}
internal string getGoodsById(string goodsId)
{
WmsGoods goods = new WmsGoods(goodsId,0,"");
return goods.stockAvCount+"";
}
2023-05-23 16:13:17 +08:00
}
2023-09-04 22:41:19 +08:00
2023-05-23 16:13:17 +08:00
}