@ -4,10 +4,13 @@ using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework ;
using Khd.Core.Library.Mapper ;
using Khd.Core.Wcs.Global ;
using Masuit.Tools ;
using Masuit.Tools.Logging ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.Hosting ;
using Newtonsoft.Json ;
using System.Diagnostics ;
using Thrift.Protocol ;
using Z.EntityFramework.Plus ;
namespace Khd.Core.Wcs.Wcs
@ -75,10 +78,6 @@ namespace Khd.Core.Wcs.Wcs
. Where ( t = > t . useFlag = = 1 )
. Where ( t = > t . nextPointId = = agvID ) . OrderBy ( t = > t . createTime ) . ToList ( ) ;
dbContext . ChangeTracker . Entries ( ) . ToList ( ) . ForEach ( e = > e . Reload ( ) ) ;
if ( taskList . Count = = 0 )
{
LogManager . Info ( FloorNo + "楼AGV无任务" ) ;
}
foreach ( var item in taskList )
{
if ( taskList . Where ( t = > t . taskStatus > 0 ) . Where ( t = > t . objid ! = item . objid ) . Any ( ) )
@ -132,6 +131,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -202,6 +202,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -262,6 +263,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -320,6 +322,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -378,6 +381,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -437,6 +441,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -495,6 +500,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -553,6 +559,7 @@ namespace Khd.Core.Wcs.Wcs
var reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发任务成功: " + message ) ;
wcsCmd . taskCode = reponseMessage . data ;
wcsCmd . cmdStatus = 1 ;
item . taskStatus = 1 ;
@ -574,6 +581,7 @@ namespace Khd.Core.Wcs.Wcs
WcsCmd ? wcsCmd = dbContext . WcsCmd . FirstOrDefault ( t = > t . taskId = = item . objid ) ;
if ( wcsCmd ! = null )
{
if ( wcsCmd . cmdStatus = = 3 )
{
var agvTask = new RequestAGVTaskDto
@ -586,6 +594,7 @@ namespace Khd.Core.Wcs.Wcs
ReponseMessage ? reponseMessage = JsonConvert . DeserializeObject < ReponseMessage > ( result ) ;
if ( reponseMessage ! = null & & reponseMessage . message = = "成功" )
{
LogManager . Info ( "五楼Agv下发继续任务成功: " + message ) ;
wcsCmd . cmdStatus = 4 ;
dbContext . WcsCmd . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmd ( ) { cmdStatus = 4 } ) ;
dbContext . Update ( wcsCmd ) ;
@ -596,6 +605,9 @@ namespace Khd.Core.Wcs.Wcs
}
else if ( wcsCmd . cmdStatus = = 5 )
{
LogManager . Info ( "五楼叉车线程完成任务" + wcsCmd . objid ) ;
Console . WriteLine ( DateTime . Now + ":五楼背负式AGV线程完成任务" + wcsCmd . currPointNo + "," + wcsCmd . nextPointNo ) ;
LogManager . Info ( "五楼Agv完成任务成功: " + wcsCmd . ToJsonString ( ) ) ;
if ( item . taskType = = 49 )
{
WmsBaseLocation fromBaseLocation = dbContext . WmsBaseLocation . First ( t = > t . locationId = = item . currPointId ) ;
@ -619,6 +631,10 @@ namespace Khd.Core.Wcs.Wcs
dbContext . Update ( wmsProductStock ) ;
}
}
dbContext . Remove ( wcsCmd ) ;
dbContext . Remove ( item ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog ( ) { taskStatus = 6 } ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog ( ) { cmdStatus = 6 } ) ;
dbContext . Update ( fromBaseLocation ) ;
dbContext . Update ( toBaseLocation ) ;
dbContext . SaveChanges ( ) ;
@ -664,8 +680,8 @@ namespace Khd.Core.Wcs.Wcs
}
else if ( item . taskType = = 38 ) //出库
{
var wmsProductOutstockDetails = dbContext . WmsProductOutstockDetail . Where ( t = > t . productOutstockId = = item . orderId ) ;
var wmsProductOutstockDetail = wmsProductOutstockDetails . FirstOrDefault ( t = > t . executeStatus = = "1" & & t . locationCode = = item . currPointNo ) ;
var wmsProductOutstockDetails = dbContext . WmsProductOutstockDetail . Where ( t = > t . productOutstockId = = item . orderId ) ;
var wmsProductOutstockDetail = wmsProductOutstockDetails . FirstOrDefault ( t = > t . executeStatus = = "1" & & t . locationCode = = item . currPointNo ) ;
var wmsProductOutstock = dbContext . WmsProductOutstock . FirstOrDefault ( t = > t . productOutstockId = = item . orderId ) ;
if ( wmsProductOutstockDetail ! = null & & wmsProductOutstock ! = null )
{
@ -687,20 +703,25 @@ namespace Khd.Core.Wcs.Wcs
dbContext . Update ( wmsBaseLocation ) ;
dbContext . WmsProductStock . Where ( t = > t . locationCode = = wmsBaseLocation . locationCode ) . Delete ( ) ;
BaseEquip floorLineEquip = StaticData . BaseEquip . First ( t = > t . equipType = = 1 & & t . floorNo = = 5 ) ;
item . nextPointId = floorLineEquip . objid ;
item . nextPointNo = floorLineEquip . equipNo ;
item . fromFloorNo = 5 ;
item . floorNo = 1 ;
item . taskStatus = 6 ;
WcsTask newTask = CoreMapper . Map < WcsTask > ( item ) ;
newTask . createTime = DateTime . Now ;
newTask . nextPointId = floorLineEquip . objid ;
newTask . nextPointNo = floorLineEquip . equipNo ;
newTask . fromFloorNo = 5 ;
newTask . floorNo = 1 ;
newTask . taskStatus = 6 ;
newTask . objid = StaticData . SnowId . NextId ( ) ;
lineEquip . equipStatus = 0 ;
dbContext . Update ( lineEquip ) ;
dbContext . Update ( item ) ;
dbContext . Add ( newTask ) ;
WcsTaskLog wcsTaskLog = CoreMapper . Map < WcsTaskLog > ( newTask ) ;
dbContext . Add ( wcsTaskLog ) ;
dbContext . Remove ( item ) ;
dbContext . WcsCmd . Remove ( wcsCmd ) ;
dbContext . SaveChanges ( ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 , nextPointId = floorLineEquip . objid , nextPointNo = floorLineEquip . equipNo , fromFloorNo = 5 , floorNo = 1 } ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
dbContext . WcsCmd . Where ( t = > t . objid = = wcsCmd . objid ) . Delete ( ) ;
dbContext . SaveChanges ( ) ;
}
}
else if ( item . taskType = = 33 ) //原材料到背板安装
{
@ -712,11 +733,11 @@ namespace Khd.Core.Wcs.Wcs
wmsBaseLocation . updateBy = "WCS" ;
dbContext . Update ( wmsBaseLocation ) ;
dbContext . WmsRawStock . Where ( t = > t . locationCode = = wmsBaseLocation . locationCode ) . Delete ( ) ;
dbContext . WcsCmd . Where ( t = > t . objid = = wcsCmd . objid ) . Delete ( ) ;
dbContext . WcsTask . Where ( t = > t . objid = = item . objid ) . Delete ( ) ;
dbContext . WcsCmd . Remove ( wcsCmd ) ;
dbContext . WcsTask . Remove ( item ) ;
dbContext . SaveChanges ( ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 } ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
dbContext . SaveChanges ( ) ;
}
else if ( item . taskType = = 34 ) //半成品入库
{
@ -768,8 +789,8 @@ namespace Khd.Core.Wcs.Wcs
dbContext . Update ( startEquip ) ;
dbContext . Add ( wmsProductStock ) ;
dbContext . Update ( wmsBaseLocation ) ;
dbContext . WcsCmd . Where( t = > t . objid = = wcsCmd . objid ) . Delete ( ) ;
dbContext . WcsTask . Where( t = > t . objid = = item . objid ) . Delete ( ) ;
dbContext . WcsCmd . Remove( wcsCmd ) ;
dbContext . WcsTask . Remove( item ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 } ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
dbContext . SaveChanges ( ) ;
@ -779,7 +800,6 @@ namespace Khd.Core.Wcs.Wcs
}
else if ( item . taskType = = 46 ) //该任务结束后, 立刻生成一个新的返库任务, 但是是否使用标志未0, 等待mes通知
{
WcsTask newTask = CoreMapper . Map < WcsTask > ( item ) ;
WmsBaseLocation wmsBaseLocation = dbContext . WmsBaseLocation . First ( t = > t . locationId = = item . startPointId ) ;
wmsBaseLocation . outstockFlag = "0" ;
wmsBaseLocation . instockFlag = "1" ;
@ -795,24 +815,26 @@ namespace Khd.Core.Wcs.Wcs
wmsRawStock . updateBy = "WCS" ;
dbContext . Update ( wmsRawStock ) ;
dbContext . Update ( wmsBaseLocation ) ;
dbContext. WcsTask . Where ( t = > t . objid = = item . objid ) . Delete ( ) ;
dbContext. WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 } ) ;
dbContext. WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
dbContext. WcsCmd . Where ( t = > t . objid = = wcsCmd . objid ) . Delete ( ) ;
item. objid = StaticData . SnowId . NextId ( ) ;
item. currPointId = item . endPointId ;
item. currPointNo = item . endPointNo ;
item. endPointId = item . startPointId ;
item. endPointNo = item . start PointNo;
item. startPointId = item . currPointId ;
item. startPointNo = item . currPointNo ;
item. taskType = 28 ;
item. taskStatus = 0 ;
item. useFlag = 0 ;
dbContext. Add ( item ) ;
WcsTaskLog wcsTaskLog = CoreMapper . Map < WcsTaskLog > ( item ) ;
WcsTask newTask = CoreMapper . Map < WcsTask > ( item ) ;
newTask. objid = StaticData . SnowId . NextId ( ) ;
newTask. currPointId = item . endPointId ;
newTask. currPointNo = item . endPointNo ;
newTask. endPointId = item . startPointId ;
newTask. endPointNo = item . startPointNo ;
newTask. startPointId = item . currPointId ;
newTask. createTime = DateTime . Now ;
newTask. startPointNo = item . curr PointNo;
newTask. taskType = 28 ;
newTask. taskStatus = 0 ;
newTask. useFlag = 0 ;
dbContext. Remove ( item ) ;
dbContext. Remove ( wcsCmd ) ;
WcsTaskLog wcsTaskLog = CoreMapper . Map < WcsTaskLog > ( newTask ) ;
dbContext. Add ( newTask ) ;
dbContext . Add ( wcsTaskLog ) ;
dbContext . SaveChanges ( ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 } ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
}
}
@ -837,13 +859,12 @@ namespace Khd.Core.Wcs.Wcs
dbContext . Update ( startEquip ) ;
dbContext . Update ( wmsRawStock ) ;
dbContext . Update ( wmsBaseLocation ) ;
dbContext . WcsTask . Where ( t = > t . objid = = item . objid ) . Delete ( ) ;
dbContext . Remove ( item ) ;
dbContext . Remove ( wcsCmd ) ;
dbContext . SaveChanges ( ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 } ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
dbContext . WcsCmd . Where ( t = > t . objid = = wcsCmd . objid ) . Delete ( ) ;
dbContext . SaveChanges ( ) ;
}
}
else if ( item . taskType = = 47 )
{
@ -883,11 +904,11 @@ namespace Khd.Core.Wcs.Wcs
} ;
dbContext . Add ( wmsRawStock ) ;
dbContext . Add ( wmsBaseLocation ) ;
dbContext . WcsCmd . Where ( t = > t . objid = = wcsCmd . objid ) . Delete ( ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
dbContext . WcsTask . Where ( t = > t . objid = = item . objid ) . Delete ( ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 } ) ;
dbContext . Remove ( item ) ;
dbContext . Remove ( wcsCmd ) ;
dbContext . SaveChanges ( ) ;
dbContext . WcsCmdLog . Where ( t = > t . objid = = wcsCmd . objid ) . Update ( t = > new WcsCmdLog { cmdStatus = 6 } ) ;
dbContext . WcsTaskLog . Where ( t = > t . objid = = item . objid ) . Update ( t = > new WcsTaskLog { taskStatus = 6 } ) ;
}
}
}