@ -22,7 +22,6 @@ namespace Khd.Core.Wcs.Wcs
public class CreateTaskByRecord
{
private readonly IHost _host ;
private readonly Plc . S7 . Plc _plc ;
List < BasePlcpoint > ScanPoint { get ; set ; } //点位信息
private BaseSitenode ? sitenode { get ; set ; } //站台信息
@ -33,10 +32,9 @@ namespace Khd.Core.Wcs.Wcs
private NodeSetting ? NodeSettingWcsSend { get ; set ; }
private NodeSetting ? NodeSettingWcsSendMaterial { 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 . _plc = plc ;
this . ScanPoint = StaticData . BasePlcpointList . ToList ( ) ; //加载当前站点所对应的点位
this . sitenode = StaticData . SiteNodeList . FirstOrDefault ( t = > t . siteNo = = siteNo ) ; //获取当前站台信息
//this.NodeSettingCarNo = this.ScanPoint.FirstOrDefault(t => t.plcpointNo.Contains("carno"));
@ -64,20 +62,20 @@ namespace Khd.Core.Wcs.Wcs
/// </summary>
public void StartPoint ( )
{
var createBearAgvReturnThread = new Thread ( CreateBearAgvReturnLogic ) ;
createBearAgvReturnThread . Start ( ) ;
//var createBearAgvReturnThread = new Thread(CreateBearAgvReturnLogic) ;
//createBearAgvReturnThread.Start() ;
var createRawInWareTaskThread = new Thread ( CreateRawInWareTaskLogic ) ;
createRawInWareTaskThread . Start ( ) ;
//var createRawInWareTaskThread = new Thread(CreateRawInWareTaskLogic) ;
//createRawInWareTaskThread.Start() ;
var createFiveProductTaskThread = new Thread ( CreateFiveProductTaskLogic ) ;
createFiveProductTaskThread . Start ( ) ;
//var createFiveProductTaskThread = new Thread(CreateFiveProductTaskLogic) ;
//createFiveProductTaskThread.Start() ;
var createRawTaskThread = new Thread ( CreateRawTaskLogic ) ;
createRawTaskThread . Start ( ) ;
var createThirdOutTaskThread = new Thread ( CreateThirdOutTaskLogic ) ;
createThirdOutTaskThread . Start ( ) ;
//var createThirdOutTaskThread = new Thread(CreateThirdOutTaskLogic) ;
//createThirdOutTaskThread.Start() ;
Console . WriteLine ( DateTime . Now + ":出库任务监听启动成功" ) ;
LogManager . Info ( "出库任务监听启动成功" ) ;
@ -293,7 +291,7 @@ namespace Khd.Core.Wcs.Wcs
floorNo = 5 ,
masterId = wmsRawReturn . materialId ,
fromFloorNo = 5 ,
materialNo = wmsRawReturn . materialBatch ,
//materialNo = wmsRawReturn.materialBatch ,
} ;
wmsRawReturn . executeStatus = "1" ;
dbContext . Add ( wcsTask ) ;
@ -449,7 +447,7 @@ namespace Khd.Core.Wcs.Wcs
location . updateBy = "WCS" ;
location . updateTime = DateTime . Now ;
MesBaseBarcodeInfo ? mesBaseBarcodeInfo = dbContext . MesBaseBarcodeInfo . Where ( t = > t . barcodeInfo = = stock . productBatch ) . FirstOrDefault ( ) ;
if ( mesBaseBarcodeInfo ! = null )
if ( mesBaseBarcodeInfo ! = null )
{
WmsProductOutstockDetail wmsProductOutstockDetail = new WmsProductOutstockDetail ( )
{
@ -464,7 +462,7 @@ namespace Khd.Core.Wcs.Wcs
planAmount = item . applyQty ,
warehouseId = item . warehouseId ,
productBatch = mesBaseBarcodeInfo . batchCode ,
productBarcode = mesBaseBarcodeInfo . barcodeInfo
productBarcode = mesBaseBarcodeInfo . barcodeInfo
} ;
dbContext . Add ( wmsProductOutstockDetail ) ;
dbContext . Update ( location ) ;
@ -475,9 +473,9 @@ namespace Khd.Core.Wcs.Wcs
{
break ;
}
}
}
}
if ( item . beginTime = = null )
{
item . beginTime = DateTime . Now ;
@ -514,242 +512,150 @@ namespace Khd.Core.Wcs.Wcs
. Where ( t = > t . outstockAmount > t . realOutstockAmount )
. Where ( t = > t . auditStatus = = "1" )
. 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 )
{
decimal? RealOutNumber = item . realOutstockAmount ;
var endEquip = StaticData . BaseEquip . FirstOrDefault ( t = > t . equipNo = = item . endStationCode ) ;
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 ( wcsOutstockLock . qty = = 0 & & wcsOutstockLock . boxStatus = = 0 )
if ( endEquip . equipType = = 8 ) //CTU出库
{
var wmsRawStocks = rawStock
. Where ( t = > t . materialId = = item . materialId )
. 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 )
var wcsOutstockLock = dbContext . WcsOutstockLock . Where ( t = > t . warehouseId = = 512 ) . First ( ) ;
if ( wcsOutstockLock . qty = = 0 & & wcsOutstockLock . boxStatus = = 0 )
{
bill = bill . OrderBy ( t = > t . a . locColumn ) . ToList ( ) ;
}
else
{
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . ToList ( ) ;
}
//做数量限制
var wmsRawStocks = rawStock
. Where ( t = > t . materialId = = item . materialId )
. Where ( t = > t . warehouseId = = item . warehouseId )
. Select ( t = > t . locationCode )
. ToList ( ) ;
//bill = bill.Take(5 - dbContext.WcsCmd.Where(t => t.cmdStatus < 3 && t.nextPointId == 20).Count());
bill = bill . Take ( 6 ) ;
BaseEquip ctuEquip = StaticData . BaseEquip . First ( t = > t . objid = = 11 ) ;
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . objid = = 20 ) ;
foreach ( var b in bill )
{
needNumber = item . outstockAmount - RealOutNumber ;
item . executeStatus = "1" ;
WmsBaseLocation location = b . a ;
WmsRawStock stock = b . b ;
WcsTask wcsTask ;
int qty = 0 ;
int outNumber = 0 ;
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
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 )
{
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 ;
bill = bill . OrderBy ( t = > t . a . locColumn ) . ToList ( ) ;
}
else
{
RealOutNumber + = needNumber ;
outNumber = Convert . ToInt32 ( needNumber ) ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . ToList ( ) ;
}
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
. 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.Take(5 - dbContext.WcsCmd.Where(t => t.cmdStatus < 3 && t.nextPointId == 20).Count());
bill = bill . Take ( 6 ) ;
BaseEquip ctuEquip = StaticData . BaseEquip . First ( t = > t . objid = = 11 ) ;
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . objid = = 20 ) ;
foreach ( var b in bill )
{
needNumber = item . outstockAmount - RealOutNumber ;
item . executeStatus = "1" ;
WmsBaseLocation location = b . a ;
WmsRawStock stock = b . b ;
WcsTask wcsTask ;
int qty = 0 ;
int outNumber = 0 ;
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = 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
{
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . ToList ( ) ;
RealOutNumber + = needNumber ;
outNumber = Convert . ToInt32 ( needNumber ) ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
}
//做数量限制
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 )
wcsTask = new WcsTask ( )
{
item . executeStatus = "1" ;
WmsBaseLocation location = b . a ;
WmsRawStock stock = b . b ;
WcsTask wcsTask ;
int qty = 0 ;
if ( stock . totalAmount - stock . occupyAmount - stock . frozenAmount < = needNumber ) //该料箱全部出
objid = StaticData . SnowId . NextId ( ) ,
orderId = item . rawOutstockId ,
taskType = 38 ,
containerNo = location . containerCode ,
createBy = "WCS" ,
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 ;
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 = 38 ,
containerNo = location . containerCode ,
createBy = "WCS" ,
createTime = DateTime . Now ,
taskStatus = 0 ,
rawOutstockDetailId = StaticData . SnowId . NextId ( ) ,
rawOutstockId = item . rawOutstockId ,
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 = qty
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 . qty + = 1 ;
dbContext . Update ( wcsOutstockLock ) ;
wcsOutstockLock . boxStatus = 1 ;
dbContext . Update ( location ) ;
dbContext . Add ( wcsTask ) ;
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 )
{
item . beginTime = DateTime . Now ;
}
wcsOutstockLock . boxStatus = 1 ;
dbContext . Update ( wcsOutstockLock ) ;
dbContext . Add ( bearAgvTask ) ;
dbContext . Update ( item ) ;
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
. 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 )
if ( endEquip . emptyCount = = 0 )
{
item . executeStatus = "2" ;
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
continue ;
}
var wmsRawStocks = rawStock
. 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" )
. Where ( t = > t . totalAmount > t . occupyAmount + t . frozenAmount )
. Select ( t = > t . palletInfoCode )
. ToList ( ) ;
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
{
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . Take ( 1 ) . 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 ( ) ;
BaseEquip bearAgvEquip = StaticData . BaseEquip . First ( t = > t . objid = = 10 ) ;
BaseEquip lineEquip = StaticData . BaseEquip . First ( t = > t . equipNo = = item . endStationCode ) ;
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 ) //该料箱全部出
decimal? needNumber = item . outstockAmount - item . realOutstockAmount ;
if ( needNumber < = 0 )
{
item . realOutstockAmount + = stock . totalAmount - stock . occupyAmount - stock . frozenAmount ;
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
stock . occupyAmount + = qty ;
stock . updateDate = DateTime . Now ;
item . executeStatus = "2" ;
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
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
{
item . realOutstockAmount + = needNumber ;
stock . occupyAmount + = needNumber ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
bill = bill . OrderByDescending ( t = > t . a . locColumn ) . Take ( 1 ) . ToList ( ) ;
}
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 ( ) ,
orderId = item . rawOutstockId ,
taskType = endEquip . equipType = = 12 ? 46 : 33 , //如果是12那么就是原材料到柜体验收区,如果是13那么就是原材料到背板安装区
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 = 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 ;
dbContext . Update ( location ) ;
dbContext . Add ( wcsTask ) ;
dbContext . Update ( stock ) ;
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 ;
qty = Convert . ToInt32 ( stock . totalAmount - stock . frozenAmount ) ;
stock . occupyAmount + = qty ;
stock . updateDate = DateTime . Now ;
}
else
{
item . realOutstockAmount + = needNumber ;
stock . occupyAmount + = needNumber ;
qty = Convert . ToInt32 ( needNumber ) ;
stock . updateDate = DateTime . Now ;
}
wcsTask = new WcsTask ( )
{
objid = StaticData . SnowId . NextId ( ) ,
orderId = item . rawOutstockId ,
taskType = endEquip . equipType = = 12 ? 46 : 33 , //如果是12那么就是原材料到柜体验收区,如果是13那么就是原材料到背板安装区
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 = 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 ( ) ;
if ( qty > = needNumber )
{
break ;
}
}
if ( item . beginTime = = null )
{
item . beginTime = DateTime . Now ;
}
dbContext . Update ( item ) ;
dbContext . SaveChanges ( ) ;
}
}
}