@ -22,7 +22,6 @@ namespace Khd.Core.Wcs.Wcs
public class CreateTaskByRecord
public class CreateTaskByRecord
{
{
private readonly IHost _host ;
private readonly IHost _host ;
private readonly Plc . S7 . Plc _plc ;
List < BasePlcpoint > ScanPoint { get ; set ; } //点位信息
List < BasePlcpoint > ScanPoint { get ; set ; } //点位信息
private BaseSitenode ? sitenode { get ; set ; } //站台信息
private BaseSitenode ? sitenode { get ; set ; } //站台信息
@ -33,10 +32,9 @@ namespace Khd.Core.Wcs.Wcs
private NodeSetting ? NodeSettingWcsSend { get ; set ; }
private NodeSetting ? NodeSettingWcsSend { get ; set ; }
private NodeSetting ? NodeSettingWcsSendMaterial { get ; set ; }
private NodeSetting ? NodeSettingWcsSendMaterial { get ; set ; }
private NodeSetting ? NodeSettingPLCSendSendMaterialstate { get ; set ; }
private NodeSetting ? NodeSettingPLCSendSendMaterialstate { get ; set ; }
public CreateTaskByRecord ( IHost host , Plc . S7 . Plc plc , string siteNo )
public CreateTaskByRecord ( IHost host , string siteNo )
{
{
this . _host = host ;
this . _host = host ;
this . _plc = plc ;
this . ScanPoint = StaticData . BasePlcpointList . ToList ( ) ; //加载当前站点所对应的点位
this . ScanPoint = StaticData . BasePlcpointList . ToList ( ) ; //加载当前站点所对应的点位
this . sitenode = StaticData . SiteNodeList . FirstOrDefault ( t = > t . siteNo = = siteNo ) ; //获取当前站台信息
this . sitenode = StaticData . SiteNodeList . FirstOrDefault ( t = > t . siteNo = = siteNo ) ; //获取当前站台信息
//this.NodeSettingCarNo = this.ScanPoint.FirstOrDefault(t => t.plcpointNo.Contains("carno"));
//this.NodeSettingCarNo = this.ScanPoint.FirstOrDefault(t => t.plcpointNo.Contains("carno"));
@ -64,20 +62,20 @@ namespace Khd.Core.Wcs.Wcs
/// </summary>
/// </summary>
public void StartPoint ( )
public void StartPoint ( )
{
{
var createBearAgvReturnThread = new Thread ( CreateBearAgvReturnLogic ) ;
//var createBearAgvReturnThread = new Thread(CreateBearAgvReturnLogic) ;
createBearAgvReturnThread . Start ( ) ;
//createBearAgvReturnThread.Start() ;
var createRawInWareTaskThread = new Thread ( CreateRawInWareTaskLogic ) ;
//var createRawInWareTaskThread = new Thread(CreateRawInWareTaskLogic) ;
createRawInWareTaskThread . Start ( ) ;
//createRawInWareTaskThread.Start() ;
var createFiveProductTaskThread = new Thread ( CreateFiveProductTaskLogic ) ;
//var createFiveProductTaskThread = new Thread(CreateFiveProductTaskLogic) ;
createFiveProductTaskThread . Start ( ) ;
//createFiveProductTaskThread.Start() ;
var createRawTaskThread = new Thread ( CreateRawTaskLogic ) ;
var createRawTaskThread = new Thread ( CreateRawTaskLogic ) ;
createRawTaskThread . Start ( ) ;
createRawTaskThread . Start ( ) ;
var createThirdOutTaskThread = new Thread ( CreateThirdOutTaskLogic ) ;
//var createThirdOutTaskThread = new Thread(CreateThirdOutTaskLogic) ;
createThirdOutTaskThread . Start ( ) ;
//createThirdOutTaskThread.Start() ;
Console . WriteLine ( DateTime . Now + ":出库任务监听启动成功" ) ;
Console . WriteLine ( DateTime . Now + ":出库任务监听启动成功" ) ;
LogManager . Info ( "出库任务监听启动成功" ) ;
LogManager . Info ( "出库任务监听启动成功" ) ;
@ -293,7 +291,7 @@ namespace Khd.Core.Wcs.Wcs
floorNo = 5 ,
floorNo = 5 ,
masterId = wmsRawReturn . materialId ,
masterId = wmsRawReturn . materialId ,
fromFloorNo = 5 ,
fromFloorNo = 5 ,
materialNo = wmsRawReturn . materialBatch ,
//materialNo = wmsRawReturn.materialBatch ,
} ;
} ;
wmsRawReturn . executeStatus = "1" ;
wmsRawReturn . executeStatus = "1" ;
dbContext . Add ( wcsTask ) ;
dbContext . Add ( wcsTask ) ;
@ -449,7 +447,7 @@ namespace Khd.Core.Wcs.Wcs
location . updateBy = "WCS" ;
location . updateBy = "WCS" ;
location . updateTime = DateTime . Now ;
location . updateTime = DateTime . Now ;
MesBaseBarcodeInfo ? mesBaseBarcodeInfo = dbContext . MesBaseBarcodeInfo . Where ( t = > t . barcodeInfo = = stock . productBatch ) . FirstOrDefault ( ) ;
MesBaseBarcodeInfo ? mesBaseBarcodeInfo = dbContext . MesBaseBarcodeInfo . Where ( t = > t . barcodeInfo = = stock . productBatch ) . FirstOrDefault ( ) ;
if ( mesBaseBarcodeInfo ! = null )
if ( mesBaseBarcodeInfo ! = null )
{
{
WmsProductOutstockDetail wmsProductOutstockDetail = new WmsProductOutstockDetail ( )
WmsProductOutstockDetail wmsProductOutstockDetail = new WmsProductOutstockDetail ( )
{
{
@ -464,7 +462,7 @@ namespace Khd.Core.Wcs.Wcs
planAmount = item . applyQty ,
planAmount = item . applyQty ,
warehouseId = item . warehouseId ,
warehouseId = item . warehouseId ,
productBatch = mesBaseBarcodeInfo . batchCode ,
productBatch = mesBaseBarcodeInfo . batchCode ,
productBarcode = mesBaseBarcodeInfo . barcodeInfo
productBarcode = mesBaseBarcodeInfo . barcodeInfo
} ;
} ;
dbContext . Add ( wmsProductOutstockDetail ) ;
dbContext . Add ( wmsProductOutstockDetail ) ;
dbContext . Update ( location ) ;
dbContext . Update ( location ) ;
@ -475,9 +473,9 @@ namespace Khd.Core.Wcs.Wcs
{
{
break ;
break ;
}
}
}
}
}
}
if ( item . beginTime = = null )
if ( item . beginTime = = null )
{
{
item . beginTime = DateTime . Now ;
item . beginTime = DateTime . Now ;
@ -514,242 +512,150 @@ namespace Khd.Core.Wcs.Wcs
. Where ( t = > t . outstockAmount > t . realOutstockAmount )
. Where ( t = > t . outstockAmount > t . realOutstockAmount )
. Where ( t = > t . auditStatus = = "1" )
. Where ( t = > t . auditStatus = = "1" )
. ToList ( ) ;
. ToList ( ) ;
List < WcsTaskManual > wcsTaskManuals = dbContext . WcsTaskManual . OrderBy ( t = > t . createBy ) . ToList ( ) ;
if ( wcsTaskManuals . Count > 0 )
{
WcsOutstockLock wcsOutstockLock = dbContext . WcsOutstockLock . Where ( t = > t . warehouseId = = 512 ) . First ( ) ;
int taskCount = dbContext . WcsTask . Where ( t = > t . nextPointId = = 11 ) . Count ( ) ;
if ( taskCount = = 0 & & wcsOutstockLock . qty = = 0 & & wcsOutstockLock . boxStatus = = 0 )
{
foreach ( var wcs in wcsTaskManuals . Take ( 6 ) )
{
WcsTask wcsTask = CoreMapper . Map < WcsTask > ( wcs ) ;
WcsTaskLog wcsTaskLog = CoreMapper . Map < WcsTaskLog > ( wcsTask ) ;
wcsOutstockLock . qty + = 1 ;
wcsOutstockLock . boxStatus = 1 ;
dbContext . Update ( wcsOutstockLock ) ;
dbContext . Add ( wcsTask ) ;
dbContext . Add ( wcsTaskLog ) ;
dbContext . WcsTaskManual . Where ( t = > t . objid = = wcs . objid ) . Delete ( ) ;
}
dbContext . SaveChanges ( ) ;
}
}
foreach ( var item in rawOutStock )
foreach ( var item in rawOutStock )
{
{
decimal? RealOutNumber = item . realOutstockAmount ;
decimal? RealOutNumber = item . realOutstockAmount ;
var endEquip = StaticData . BaseEquip . FirstOrDefault ( t = > t . equipNo = = item . endStationCode ) ;
var endEquip = StaticData . BaseEquip . FirstOrDefault ( t = > t . equipNo = = item . endStationCode ) ;
if ( endEquip ! = null & & endEquip . floorNo = = 5 )
if ( endEquip ! = null & & endEquip . floorNo = = 5 )
{
{
if ( endEquip . equipType = = 8 ) //CTU出库
lock ( SystemData . outStockLock )
{
{
WcsOutstockLock wcsOutstockLock = dbContext . WcsOutstockLock . Where ( t = > t . warehouseId = = 512 ) . First ( ) ;
if ( endEquip . equipType = = 8 ) //CTU出库
if ( wcsOutstockLock . qty = = 0 & & wcsOutstockLock . boxStatus = = 0 )
{
{
var wmsRawStocks = rawStock
var wcsOutstockLock = dbContext . WcsOutstockLock . Where ( t = > t . warehouseId = = 512 ) . First ( ) ;
. Where ( t = > t . materialId = = item . materialId )
if ( wcsOutstockLock . qty = = 0 & & wcsOutstockLock . boxStatus = = 0 )
. Where ( t = > t . warehouseId = = item . warehouseId )
. Select ( t = > t . locationCode )
. ToList ( ) ;
var wmsBaseLocations = dbContext . WmsBaseLocation
. Where ( t = > t . activeFlag = = "1" )
. Where ( t = > t . delFlag = = "0" )
. Where ( t = > t . locationScrapType = = "1" )
. Where ( t = > t . instockFlag = = "0" )
. Where ( t = > t . outstockFlag = = "0" )
. Where ( t = > t . ContainerStatus = = "1" )
. Where ( t = > t . warehouseId = = item . warehouseId )
. Where ( t = > wmsRawStocks . Contains ( t . locationCode ) )
. ToList ( ) ;
decimal? needNumber = item . outstockAmount - RealOutNumber ;
var bill = from a in wmsBaseLocations
from b in rawStock
where a . locationCode = = b . locationCode
select new { a , b } ;
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
if ( bill . Where ( t = > t . a . locColumn = = 1 ) . Select ( t = > t . b . totalAmount - t . b . occupyAmount - t . b . frozenAmount ) . Sum ( ) > needNumber )
{
{
bill = bill . OrderBy ( t = > t . a . locColumn ) . ToList ( ) ;
var wmsRawStocks = rawStock
}
. Where ( t = > t . materialId = = item . materialId )
else
. Where ( t = > t . warehouseId = = item . warehouseId )
{
. Select ( t = > t . locationCode )
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . ToList ( ) ;
. ToList ( ) ;
}
//做数量限制
//bill = bill.Take(5 - dbContext.WcsCmd.Where(t => t.cmdStatus < 3 && t.nextPointId == 20).Count());
var wmsBaseLocations = dbContext . WmsBaseLocation
bill = bill . Take ( 6 ) ;
. Where ( t = > t . activeFlag = = "1" )
BaseEquip ctuEquip = StaticData . BaseEquip . First ( t = > t . objid = = 11 ) ;
. Where ( t = > t . delFlag = = "0" )
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . objid = = 20 ) ;
. Where ( t = > t . locationScrapType = = "1" )
foreach ( var b in bill )
. Where ( t = > t . instockFlag = = "0" )
{
. Where ( t = > t . outstockFlag = = "0" )
needNumber = item . outstockAmount - RealOutNumber ;
. Where ( t = > t . ContainerStatus = = "1" )
item . executeStatus = "1" ;
. Where ( t = > t . warehouseId = = item . warehouseId )
WmsBaseLocation location = b . a ;
. Where ( t = > wmsRawStocks . Contains ( t . locationCode ) )
WmsRawStock stock = b . b ;
. ToList ( ) ;
WcsTask wcsTask ;
int qty = 0 ;
decimal? needNumber = item . outstockAmount - RealOutNumber ;
int outNumber = 0 ;
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
var bill = from a in wmsBaseLocations
from b in rawStock
where a . locationCode = = b . locationCode
select new { a , b } ;
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
if ( bill . Where ( t = > t . a . locColumn = = 1 ) . Select ( t = > t . b . totalAmount - t . b . occupyAmount - t . b . frozenAmount ) . Sum ( ) > needNumber )
{
{
RealOutNumber + = stock . totalAmount - stock . occupyAmount - stock . frozenAmount ;
bill = bill . OrderBy ( t = > t . a . locColumn ) . ToList ( ) ;
outNumber = Convert . ToInt32 ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount ) ;
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
stock . updateDate = DateTime . Now ;
}
}
else
else
{
{
RealOutNumber + = needNumber ;
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . ToList ( ) ;
outNumber = Convert . ToInt32 ( needNumber ) ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
}
}
wcsTask = new WcsTask ( )
//做数量限制
{
objid = StaticData . SnowId . NextId ( ) ,
orderId = item . rawOutstockId ,
taskType = 38 ,
containerNo = location . containerCode ,
createBy = "WCS" ,
createTime = DateTime . Now ,
taskStatus = 0 ,
materialId = item . materialId ,
currPointId = location . locationId ,
currPointNo = location . locationCode ,
startPointId = location . locationId ,
startPointNo = location . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = lineEquip . objid ,
endPointNo = lineEquip . equipNo ,
equipmentNo = ctuEquip . equipNo ,
useFlag = 1 ,
qty = outNumber
} ;
MesBaseBarcodeInfo ? mesBaseBarcodeInfo = dbContext . MesBaseBarcodeInfo . Where ( t = > t . barcodeInfo = = stock . instockBatch ) . FirstOrDefault ( ) ;
if ( mesBaseBarcodeInfo ! = null )
{
WmsRawOutstockDetail wmsProductOutstockDetail = new WmsRawOutstockDetail ( )
{
rawOutstockDetailId = StaticData . SnowId . NextId ( ) ,
rawOutstockId = item . rawOutstockId ,
materialId = item . materialId ,
createDate = DateTime . Now ,
createBy = "WCS" ,
taskCode = wcsTask . objid . ToString ( ) ,
executeStatus = "1" ,
locationCode = location . locationCode ,
outstockAmount = qty ,
planAmount = item . outstockAmount ,
warehouseId = item . warehouseId ,
materialBarcode = mesBaseBarcodeInfo . barcodeInfo ,
instockBatch = mesBaseBarcodeInfo . batchCode
} ;
dbContext . Add ( wmsProductOutstockDetail ) ;
location . outstockFlag = "1" ;
location . locationStatus = "6" ;
location . updateBy = "WCS" ;
location . updateTime = DateTime . Now ;
wcsOutstockLock . boxStatus = 1 ;
dbContext . Update ( location ) ;
dbContext . Add ( wcsTask ) ;
dbContext . Update ( stock ) ;
dbContext . SaveChanges ( ) ;
if ( qty > = needNumber )
{
break ;
}
}
}
if ( item . beginTime = = null )
{
item . beginTime = DateTime . Now ;
}
dbContext . Update ( wcsOutstockLock ) ;
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
}
} //CTU出库
else if ( endEquip . equipType = = 10 ) //CTU出库到装配区
{
WcsOutstockLock wcsOutstockLock = dbContext . WcsOutstockLock
. Where ( t = > t . warehouseId = = 512 )
. First ( ) ;
if ( wcsOutstockLock . qty = = 0 & & wcsOutstockLock . boxStatus = = 0 )
{
var orderList = rawOutStock . Where ( t = > t . endStationCode = = item . endStationCode ) . ToList ( ) ;
foreach ( var order in orderList )
{
decimal? RealOutNummber = order . realOutstockAmount ;
WcsTask ? task = dbContext . WcsTask . FirstOrDefault ( t = > t . taskType = = 32 ) ;
if ( task = = null )
{
var wmsRawStocks = rawStock
. Where ( t = > t . materialId = = order . materialId & & t . warehouseId = = order . warehouseId )
. Select ( t = > t . palletInfoCode )
. ToList ( ) ;
var wmsBaseLocations = dbContext . WmsBaseLocation
//bill = bill.Take(5 - dbContext.WcsCmd.Where(t => t.cmdStatus < 3 && t.nextPointId == 20).Count());
. Where ( t = > t . activeFlag = = "1" )
bill = bill . Take ( 6 ) ;
. Where ( t = > t . delFlag = = "0" )
BaseEquip ctuEquip = StaticData . BaseEquip . First ( t = > t . objid = = 11 ) ;
. Where ( t = > t . locationScrapType = = "1" )
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . objid = = 20 ) ;
. Where ( t = > t . instockFlag = = "0" )
foreach ( var b in bill )
. Where ( t = > t . outstockFlag = = "0" )
{
. Where ( t = > t . warehouseId = = order . warehouseId )
needNumber = item . outstockAmount - RealOutNumber ;
. Where ( t = > wmsRawStocks . Contains ( t . containerCode ) )
item . executeStatus = "1" ;
. ToList ( ) ;
WmsBaseLocation location = b . a ;
WmsRawStock stock = b . b ;
decimal? needNumber = order . outstockAmount - RealOutNummber ;
WcsTask wcsTask ;
int qty = 0 ;
var bill = from a in wmsBaseLocations
int outNumber = 0 ;
from b in rawStock
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
where a . containerCode = = b . palletInfoCode
select new { a , b } ;
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
if ( bill . Where ( t = > t . a . locColumn = = 1 ) . Select ( t = > t . b . totalAmount - t . b . occupyAmount - t . b . frozenAmount ) . Sum ( ) > needNumber )
{
{
bill = bill . OrderBy ( t = > t . a . locColumn ) . ToList ( ) ;
RealOutNumber + = stock . totalAmount - stock . occupyAmount - stock . frozenAmount ;
outNumber = Convert . ToInt32 ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount ) ;
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
stock . updateDate = DateTime . Now ;
}
}
else
else
{
{
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . ToList ( ) ;
RealOutNumber + = needNumber ;
outNumber = Convert . ToInt32 ( needNumber ) ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
}
}
//做数量限制
wcsTask = new WcsTask ( )
bill = bill . Take ( 5 - dbContext . WcsCmd . Where ( t = > t . cmdStatus < 3 & & t . nextPointId = = 20 ) . Count ( ) ) ;
BaseEquip ctuEquip = StaticData . BaseEquip . First ( t = > t . objid = = 11 ) ;
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . objid = = 20 ) ;
foreach ( var b in bill )
{
{
item . executeStatus = "1" ;
objid = StaticData . SnowId . NextId ( ) ,
WmsBaseLocation location = b . a ;
orderId = item . rawOutstockId ,
WmsRawStock stock = b . b ;
taskType = 38 ,
WcsTask wcsTask ;
containerNo = location . containerCode ,
int qty = 0 ;
createBy = "WCS" ,
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
createTime = DateTime . Now ,
taskStatus = - 1 ,
materialId = item . materialId ,
currPointId = location . locationId ,
currPointNo = location . locationCode ,
startPointId = location . locationId ,
startPointNo = location . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = lineEquip . objid ,
endPointNo = lineEquip . equipNo ,
equipmentNo = ctuEquip . equipNo ,
ud1 = location . locColumn ,
useFlag = 1 ,
qty = outNumber
} ;
MesBaseBarcodeInfo ? mesBaseBarcodeInfo = dbContext . MesBaseBarcodeInfo . Where ( t = > t . barcodeInfo = = stock . instockBatch ) . FirstOrDefault ( ) ;
if ( mesBaseBarcodeInfo ! = null )
{
WmsRawOutstockDetail wmsProductOutstockDetail = new WmsRawOutstockDetail ( )
{
{
RealOutNummber + = stock . totalAmount - stock . occupyAmount - stock . frozenAmount ;
rawOutstockDetailId = StaticData . SnowId . NextId ( ) ,
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
rawOutstockId = item . rawOutstockId ,
stock . occupyAmount + = qty ;
stock . updateDate = DateTime . Now ;
}
else
{
RealOutNummber + = needNumber ;
stock . occupyAmount + = needNumber ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
}
wcsTask = new WcsTask ( )
{
objid = StaticData . SnowId . NextId ( ) ,
orderId = item . rawOutstockId ,
taskType = 38 ,
containerNo = location . containerCode ,
createBy = "WCS" ,
createTime = DateTime . Now ,
taskStatus = 0 ,
materialId = item . materialId ,
materialId = item . materialId ,
currPointId = location . locationId ,
createDate = DateTime . Now ,
currPointNo = location . locationCode ,
createBy = "WCS" ,
startPointId = location . locationId ,
taskCode = wcsTask . objid . ToString ( ) ,
startPointNo = location . locationCode ,
executeStatus = "1" ,
nextPointId = ctuEquip . objid ,
locationCode = location . locationCode ,
nextPointNo = ctuEquip . equipNo ,
outstockAmount = qty ,
endPointId = lineEquip . objid ,
planAmount = item . outstockAmount ,
endPointNo = lineEquip . equipNo ,
warehouseId = item . warehouseId ,
equipmentNo = ctuEquip . equipNo ,
materialBarcode = mesBaseBarcodeInfo . barcodeInfo ,
useFlag = 1 ,
instockBatch = mesBaseBarcodeInfo . batchCode
qty = qty
} ;
} ;
dbContext . Add ( wmsProductOutstockDetail ) ;
location . outstockFlag = "1" ;
location . outstockFlag = "1" ;
location . locationStatus = "6" ;
location . locationStatus = "6" ;
location . updateBy = "WCS" ;
location . updateBy = "WCS" ;
location . updateTime = DateTime . Now ;
location . updateTime = DateTime . Now ;
wcsOutstockLock . qty + = 1 ;
wcsOutstockLock . boxStatus = 1 ;
dbContext . Update ( wcsOutstockLock ) ;
dbContext . Update ( location ) ;
dbContext . Update ( location ) ;
dbContext . Add ( wcsTask ) ;
dbContext . Add ( wcsTask ) ;
dbContext . Update ( stock ) ;
dbContext . Update ( stock ) ;
@ -760,156 +666,284 @@ namespace Khd.Core.Wcs.Wcs
}
}
}
}
}
}
BaseEquip startStationEquip = StaticData . BaseEquip . First ( t = > t . objid = = 21 ) ;
BaseEquip bearAgvEquip = StaticData . BaseEquip . First ( t = > t . objid = = 10 ) ;
BaseEquip endStationEquip = StaticData . BaseEquip . First ( t = > t . equipNo = = item . endStationCode ) ;
WcsTask bearAgvTask = new ( )
{
objid = StaticData . SnowId . NextId ( ) ,
orderId = item . orderId ,
taskType = 32 ,
containerNo = "" ,
startPointId = startStationEquip . objid ,
startPointNo = startStationEquip . equipNo ,
currPointId = startStationEquip . objid ,
currPointNo = startStationEquip . equipNo ,
nextPointId = bearAgvEquip . objid ,
nextPointNo = bearAgvEquip . equipNo ,
endPointId = endStationEquip . objid ,
endPointNo = endStationEquip . equipNo ,
serialNo = SystemData . GetSerialNo ( dbContext ) ,
taskStatus = 0 ,
createTime = DateTime . Now ,
createBy = "WCS" ,
materialId = item . materialId ,
qty = 1 ,
useFlag = 0 ,
equipmentNo = startStationEquip . equipNo ,
remark = "组装出库" ,
floorNo = 5 ,
masterId = item . materialId ,
fromFloorNo = 5 ,
materialNo = item . materialBatch ,
} ;
if ( item . beginTime = = null )
if ( item . beginTime = = null )
{
{
item . beginTime = DateTime . Now ;
item . beginTime = DateTime . Now ;
}
}
wcsOutstockLock . boxStatus = 1 ;
dbContext . Update ( wcsOutstockLock ) ;
dbContext . Update ( wcsOutstockLock ) ;
dbContext . Add ( bearAgvTask ) ;
dbContext . Update ( item ) ;
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
dbContext . SaveChanges ( ) ;
}
}
} //CTU出库
if ( endEquip . equipType = = 10 ) //CTU出库到装配区
{
bool CreateSuccess = false ;
var wcsOutstockLock = dbContext . WcsOutstockLock
. Where ( t = > t . warehouseId = = 512 )
. First ( ) ;
if ( wcsOutstockLock . qty = = 0 & & wcsOutstockLock . boxStatus = = 0 )
{
var orderList = rawOutStock . Where ( t = > t . endStationCode = = item . endStationCode ) . ToList ( ) ;
foreach ( var order in orderList )
{
decimal? RealOutNummber = order . realOutstockAmount ;
WcsTask ? task = dbContext . WcsTask . FirstOrDefault ( t = > t . taskType = = 32 ) ;
if ( task = = null )
{
var wmsRawStocks = rawStock
. Where ( t = > t . materialId = = order . materialId & & t . warehouseId = = order . warehouseId )
. Select ( t = > t . palletInfoCode )
. ToList ( ) ;
var wmsBaseLocations = dbContext . WmsBaseLocation
. Where ( t = > t . activeFlag = = "1" )
. Where ( t = > t . delFlag = = "0" )
. Where ( t = > t . locationScrapType = = "1" )
. Where ( t = > t . instockFlag = = "0" )
. Where ( t = > t . outstockFlag = = "0" )
. Where ( t = > t . warehouseId = = order . warehouseId )
. Where ( t = > wmsRawStocks . Contains ( t . containerCode ) )
. ToList ( ) ;
decimal? needNumber = order . outstockAmount - RealOutNummber ;
var bill = from a in wmsBaseLocations
from b in rawStock
where a . containerCode = = b . palletInfoCode
select new { a , b } ;
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
if ( bill . Where ( t = > t . a . locColumn = = 1 ) . Select ( t = > t . b . totalAmount - t . b . occupyAmount - t . b . frozenAmount ) . Sum ( ) > needNumber )
{
bill = bill . OrderBy ( t = > t . a . locColumn ) . ToList ( ) ;
}
else
{
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . ToList ( ) ;
}
//做数量限制
bill = bill . Take ( 5 - dbContext . WcsCmd . Where ( t = > t . cmdStatus < 3 & & t . nextPointId = = 20 ) . Count ( ) ) ;
BaseEquip ctuEquip = StaticData . BaseEquip . First ( t = > t . objid = = 11 ) ;
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . objid = = 20 ) ;
foreach ( var b in bill )
{
item . executeStatus = "1" ;
WmsBaseLocation location = b . a ;
WmsRawStock stock = b . b ;
WcsTask wcsTask ;
int qty = 0 ;
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
{
RealOutNummber + = stock . totalAmount - stock . occupyAmount - stock . frozenAmount ;
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
stock . occupyAmount + = qty ;
stock . updateDate = DateTime . Now ;
}
else
{
RealOutNummber + = needNumber ;
stock . occupyAmount + = needNumber ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
}
wcsTask = new WcsTask ( )
{
objid = StaticData . SnowId . NextId ( ) ,
orderId = item . rawOutstockId ,
taskType = 30 ,
containerNo = location . containerCode ,
createBy = "WCS" ,
createTime = DateTime . Now ,
taskStatus = 0 ,
materialId = item . materialId ,
currPointId = location . locationId ,
currPointNo = location . locationCode ,
startPointId = location . locationId ,
startPointNo = location . locationCode ,
nextPointId = ctuEquip . objid ,
nextPointNo = ctuEquip . equipNo ,
endPointId = lineEquip . objid ,
endPointNo = lineEquip . equipNo ,
equipmentNo = ctuEquip . equipNo ,
ud1 = location . locColumn ,
useFlag = 0 ,
qty = qty
} ;
location . outstockFlag = "1" ;
location . locationStatus = "6" ;
location . updateBy = "WCS" ;
location . updateTime = DateTime . Now ;
wcsOutstockLock . qty + = 1 ;
wcsOutstockLock . boxStatus = 1 ;
dbContext . Update ( wcsOutstockLock ) ;
dbContext . Update ( location ) ;
dbContext . Add ( wcsTask ) ;
dbContext . Update ( stock ) ;
dbContext . SaveChanges ( ) ;
CreateSuccess = true ;
if ( qty > = needNumber )
{
break ;
}
}
}
if ( CreateSuccess )
{
BaseEquip startStationEquip = StaticData . BaseEquip . First ( t = > t . objid = = 21 ) ;
BaseEquip bearAgvEquip = StaticData . BaseEquip . First ( t = > t . objid = = 10 ) ;
BaseEquip endStationEquip = StaticData . BaseEquip . First ( t = > t . equipNo = = item . endStationCode ) ;
WcsTask bearAgvTask = new ( )
{
objid = StaticData . SnowId . NextId ( ) ,
orderId = item . orderId ,
taskType = 32 ,
containerNo = "" ,
startPointId = startStationEquip . objid ,
startPointNo = startStationEquip . equipNo ,
currPointId = startStationEquip . objid ,
currPointNo = startStationEquip . equipNo ,
nextPointId = bearAgvEquip . objid ,
nextPointNo = bearAgvEquip . equipNo ,
endPointId = endStationEquip . objid ,
endPointNo = endStationEquip . equipNo ,
serialNo = SystemData . GetSerialNo ( dbContext ) ,
taskStatus = 0 ,
createTime = DateTime . Now ,
createBy = "WCS" ,
materialId = item . materialId ,
qty = 1 ,
useFlag = 1 ,
equipmentNo = startStationEquip . equipNo ,
remark = "组装出库" ,
floorNo = 5 ,
masterId = item . materialId ,
fromFloorNo = 5 ,
materialNo = item . materialBatch ,
} ;
if ( item . beginTime = = null )
{
item . beginTime = DateTime . Now ;
}
dbContext . Add ( bearAgvTask ) ;
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
}
}
}
}
}
}
}
else if ( endEquip . equipType = = 12 | | endEquip . equipType = = 13 ) //原材料到柜体验收区
if ( endEquip . equipType = = 12 | | endEquip . equipType = = 13 ) //原材料到柜体验收区
{
{
var wmsRawStocks = rawStock
if ( endEquip . emptyCount = = 0 )
. Where ( t = > t . materialId = = item . materialId & & t . warehouseId = = item . warehouseId )
. WhereIf ( endEquip . equipType = = 13 , t = > t . completeFlag = = "0" )
. WhereIf ( endEquip . equipType = = 12 , t = > t . completeFlag = = "1" )
. Select ( t = > t . palletInfoCode )
. ToList ( ) ;
var wmsBaseLocations = dbContext . WmsBaseLocation
. Where ( t = > t . activeFlag = = "1" )
. Where ( t = > t . delFlag = = "0" )
. Where ( t = > t . locationScrapType = = "1" )
. Where ( t = > t . instockFlag = = "0" )
. Where ( t = > t . outstockFlag = = "0" )
. Where ( t = > t . warehouseId = = item . warehouseId )
. Where ( t = > wmsRawStocks . Contains ( t . containerCode ) )
. ToList ( ) ;
decimal? needNumber = item . outstockAmount - item . realOutstockAmount ;
if ( needNumber < = 0 )
{
{
item . executeStatus = "2" ;
var wmsRawStocks = rawStock
dbContext . Update ( item ) ;
. Where ( t = > t . materialId = = item . materialId & & t . warehouseId = = item . warehouseId )
dbContext . SaveChanges ( ) ;
. WhereIf ( endEquip . equipType = = 13 , t = > t . completeFlag = = "0" )
continue ;
. WhereIf ( endEquip . equipType = = 12 , t = > t . completeFlag = = "1" )
}
. Where ( t = > t . totalAmount > t . occupyAmount + t . frozenAmount )
. Select ( t = > t . palletInfoCode )
. ToList ( ) ;
var bill = from a in wmsBaseLocations
var wmsBaseLocations = dbContext . WmsBaseLocation
from b in rawStock
. Where ( t = > t . activeFlag = = "1" )
where a . containerCode = = b . palletInfoCode
. Where ( t = > t . delFlag = = "0" )
select new { a , b } ;
. Where ( t = > t . locationScrapType = = "1" )
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
. Where ( t = > t . instockFlag = = "0" )
if ( bill . Where ( t = > t . a . locColumn = = 1 ) . Select ( t = > t . b . totalAmount - t . b . occupyAmount - t . b . frozenAmount ) . Sum ( ) > needNumber )
. Where ( t = > t . outstockFlag = = "0" )
{
. Where ( t = > t . warehouseId = = item . warehouseId )
bill = bill . OrderBy ( t = > t . a . locColumn ) . Take ( 1 ) . ToList ( ) ;
. Where ( t = > wmsRawStocks . Contains ( t . containerCode ) )
}
. ToList ( ) ;
else
{
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . Take ( 1 ) . ToList ( ) ;
}
BaseEquip bearAgvEquip = StaticData . BaseEquip . First ( t = > t . objid = = 10 ) ;
decimal? needNumber = item . outstockAmount - item . realOutstockAmount ;
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . equipNo = = item . endStationCode ) ;
if ( needNumber < = 0 )
foreach ( var b in bill )
{
item . executeStatus = "1" ;
WmsBaseLocation location = b . a ;
WmsRawStock stock = b . b ;
WcsTask wcsTask ;
int qty = 0 ;
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
{
{
item . realOutstockAmount + = stock . totalAmount - stock . occupyAmount - stock . frozenAmount ;
item . executeStatus = "2" ;
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
dbContext . Update ( item ) ;
stock . occupyAmount + = qty ;
dbContext . SaveChanges ( ) ;
stock . updateDate = DateTime . Now ;
continue ;
}
var bill = from a in wmsBaseLocations
from b in rawStock
where a . containerCode = = b . palletInfoCode
select new { a , b } ;
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
if ( bill . Where ( t = > t . a . locColumn = = 1 ) . Select ( t = > t . b . totalAmount - t . b . occupyAmount - t . b . frozenAmount ) . Sum ( ) > needNumber )
{
bill = bill . OrderBy ( t = > t . a . locColumn ) . Take ( 1 ) . ToList ( ) ;
}
}
else
else
{
{
item . realOutstockAmount + = needNumber ;
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . Take ( 1 ) . ToList ( ) ;
stock . occupyAmount + = needNumber ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
}
}
wcsTask = new WcsTask ( )
BaseEquip bearAgvEquip = StaticData . BaseEquip . First ( t = > t . objid = = 28 ) ;
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . equipNo = = item . endStationCode ) ;
foreach ( var b in bill )
{
{
objid = StaticData . SnowId . NextId ( ) ,
item . executeStatus = "1" ;
orderId = item . rawOutstockId ,
WmsBaseLocation location = b . a ;
taskType = endEquip . equipType = = 12 ? 46 : 33 , //如果是12那么就是原材料到柜体验收区,如果是13那么就是原材料到背板安装区
WmsRawStock stock = b . b ;
containerNo = location . containerCode ,
WcsTask wcsTask ;
createBy = "WCS" ,
int qty = 0 ;
createTime = DateTime . Now ,
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
taskStatus = 0 ,
{
materialId = item . materialId ,
item . realOutstockAmount + = stock . totalAmount - stock . occupyAmount - stock . frozenAmount ;
currPointId = location . locationId ,
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
currPointNo = location . locationCode ,
stock . occupyAmount + = qty ;
startPointId = location . locationId ,
stock . updateDate = DateTime . Now ;
startPointNo = location . locationCode ,
}
nextPointId = bearAgvEquip . objid ,
else
nextPointNo = bearAgvEquip . equipNo ,
{
endPointId = lineEquip . objid ,
item . realOutstockAmount + = needNumber ;
endPointNo = lineEquip . equipNo ,
stock . occupyAmount + = needNumber ;
equipmentNo = bearAgvEquip . equipNo ,
qty = Convert . ToInt32 ( needNumber ) ;
useFlag = 1 ,
stock . updateDate = DateTime . Now ;
qty = qty
}
} ;
wcsTask = new WcsTask ( )
location . outstockFlag = "1" ;
{
location . locationStatus = "6" ;
objid = StaticData . SnowId . NextId ( ) ,
location . updateBy = "WCS" ;
orderId = item . rawOutstockId ,
location . updateTime = DateTime . Now ;
taskType = endEquip . equipType = = 12 ? 46 : 33 , //如果是12那么就是原材料到柜体验收区,如果是13那么就是原材料到背板安装区
dbContext . Update ( location ) ;
containerNo = location . containerCode ,
dbContext . Add ( wcsTask ) ;
createBy = "WCS" ,
dbContext . Update ( stock ) ;
createTime = DateTime . Now ,
taskStatus = 0 ,
materialId = item . materialId ,
currPointId = location . locationId ,
currPointNo = location . locationCode ,
startPointId = location . locationId ,
startPointNo = location . locationCode ,
nextPointId = bearAgvEquip . objid ,
nextPointNo = bearAgvEquip . equipNo ,
endPointId = lineEquip . objid ,
endPointNo = lineEquip . equipNo ,
equipmentNo = bearAgvEquip . equipNo ,
useFlag = 1 ,
qty = qty
} ;
location . outstockFlag = "1" ;
location . locationStatus = "6" ;
location . updateBy = "WCS" ;
location . updateTime = DateTime . Now ;
endEquip . emptyCount = 1 ;
dbContext . Update ( endEquip ) ;
dbContext . Update ( location ) ;
dbContext . Add ( wcsTask ) ;
dbContext . Update ( stock ) ;
dbContext . SaveChanges ( ) ;
if ( qty > = needNumber )
{
break ;
}
}
if ( item . beginTime = = null )
{
item . beginTime = DateTime . Now ;
}
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
dbContext . SaveChanges ( ) ;
if ( qty > = needNumber )
{
break ;
}
}
}
if ( item . beginTime = = null )
{
item . beginTime = DateTime . Now ;
}
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
}
}
}
}
}
}