diff --git a/src/Khd.Core.Application/WcsTaskApplication.cs b/src/Khd.Core.Application/WcsTaskApplication.cs
index 50473e8..9764269 100644
--- a/src/Khd.Core.Application/WcsTaskApplication.cs
+++ b/src/Khd.Core.Application/WcsTaskApplication.cs
@@ -70,19 +70,28 @@ namespace Khd.Core.Application
reponseagvCallbackDto.code = "0";
reponseagvCallbackDto.message = "成功";
}
- //已取货待放货
- if (agvCallbackDto.method.ToLower() == "continue")
+ if (agvCallbackDto.method.ToLower() == "con")
{
- wcscmd.cmdStatus = 3;
wcscmd.sendFlag = 1;
- wcsTask.taskStatus = 3;
+ wcscmd.cmdStatus = 4;
+ wcsTask.taskStatus = 4;
_dbContext.WcsCmd.Update(wcscmd);
- _dbContext.Update(wcsTask);
+ _dbContext.WcsTask.Update(wcsTask);
+ _dbContext.SaveChanges();
+ reponseagvCallbackDto.code = "0";
+ reponseagvCallbackDto.message = "成功";
+ }
+ //已取货待放货
+ if (agvCallbackDto.method.ToLower() == "continue")
+ {
+ wcscmd.sendFlag = 1;
+ wcscmd.cmdStatus = 3;
+ wcsTask.taskStatus = 3;
+ _dbContext.WcsCmd.Update(wcscmd);
+ _dbContext.WcsTask.Update(wcsTask);
_dbContext.SaveChanges();
reponseagvCallbackDto.code = "0";
reponseagvCallbackDto.message = "成功";
-
- //_dbContext.WcsTask.Where(t => t.objid == wcscmd.taskId).Update(t=>t.taskStatus==3);
}
//放货完成
if (agvCallbackDto.method.ToLower() == "end")
@@ -91,7 +100,7 @@ namespace Khd.Core.Application
wcscmd.sendFlag = 1;
wcsTask.taskStatus = 5;
_dbContext.WcsCmd.Update(wcscmd);
- _dbContext.Update(wcsTask);
+ _dbContext.WcsTask.Update(wcsTask);
_dbContext.SaveChanges();
reponseagvCallbackDto.code = "0";
reponseagvCallbackDto.message = "成功";
@@ -230,6 +239,7 @@ namespace Khd.Core.Application
_dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
WcsTask wcsTask = _dbContext.WcsTask
.Where(t => t.taskType == 28)
+ .Where(t=>t.startPointNo==taskReturn.PointNo)
.Where(t => t.materialId == taskReturn.materialId)
.FirstOrDefault();
if (wcsTask != null)
diff --git a/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs b/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs
index 20309c1..c73435e 100644
--- a/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs
+++ b/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs
@@ -17,11 +17,13 @@ namespace Khd.Core.Domain.Dto.webapi
public class TaskContinue
{
public long? materialId { get; set; }
+ public string PointNo { get; set; }
}
public class TaskReturn
{
public long? materialId { get; set; }
+ public string PointNo { get; set; }
}
public class AgvCompeletedResponse
diff --git a/src/Khd.Core.Domain/Models/MesBaseMaterialInfo.cs b/src/Khd.Core.Domain/Models/MesBaseMaterialInfo.cs
new file mode 100644
index 0000000..2687ece
--- /dev/null
+++ b/src/Khd.Core.Domain/Models/MesBaseMaterialInfo.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Khd.Core.Domain.Models
+{
+ [Table("mes_base_material_info")]
+ public class MesBaseMaterialInfo
+ {
+ [Key]
+ [Column("material_id")]
+ public long? MaterialId { get; set; }
+ [Column("erp_id")]
+ public long? ErpId { get; set; }
+ [Column("material_code")]
+ public string MaterialCode { get; set; }
+ [Column("old_material_code")]
+ public string OldMaterialCode { get; set; }
+ [Column("material_name")]
+ public string MaterialName { get; set; }
+ [Column("material_categories")]
+ public string MaterialCategories { get; set; }
+ [Column("material_subclass")]
+ public string MaterialSubclass { get; set; }
+ [Column("material_type_id")]
+ public string MaterialTypeId { get; set; }
+ [Column("batch_flag")]
+ public int? BatchFlag { get; set; }
+ [Column("batch_amount")]
+ public int? BatchAmount { get; set; }
+ [Column("material_unit_id")]
+ public long? MaterialUnitId { get; set; }
+ [Column("material_unit")]
+ public string MaterialUnit { get; set; }
+ [Column("material_matkl")]
+ public string MaterialMatkl { get; set; }
+ [Column("material_spec")]
+ public string MaterialSpec { get; set; }
+ [Column("net_weight")]
+ public decimal? NetWeight { get; set; }
+ [Column("gross_weight")]
+ public decimal? GrossWeight { get; set; }
+ [Column("bind_flag")]
+ public decimal? BindFlag { get; set; }
+ [Column("factory_id")]
+ public string FactoryId { get; set; }
+ [Column("create_org_id")]
+ public long? CreateOrgId { get; set; }
+ [Column("use_org_id")]
+ public long? UseOrgId { get; set; }
+ [Column("prodline_id")]
+ public int? ProdlineId { get; set; }
+ [Column("active_flag")]
+ public int? ActiveFlag { get; set; }
+ [Column("deleted_flag")]
+ public int? DeletedFlag { get; set; }
+ [Column("remark")]
+ public string Remark { get; set; }
+ [Column("purchase_price_unit_id")]
+ public long? PurchasePriceUnitId { get; set; }
+ [Column("create_by")]
+ public long? CreateBy { get; set; }
+ [Column("create_time")]
+ public DateTime? CreateTime { get; set; }
+ [Column("update_by")]
+ public long? UpdateBy { get; set; }
+ [Column("update_time")]
+ public DateTime? UpdateTime { get; set; }
+ [Column("approve_date")]
+ public DateTime? ApproveDate { get; set; }
+ [Column("erp_modify_date")]
+ public DateTime? ErpModifyDate { get; set; }
+ }
+}
diff --git a/src/Khd.Core.Domain/Models/WcsTask.cs b/src/Khd.Core.Domain/Models/WcsTask.cs
index 6ab1b5a..a62f9b8 100644
--- a/src/Khd.Core.Domain/Models/WcsTask.cs
+++ b/src/Khd.Core.Domain/Models/WcsTask.cs
@@ -204,7 +204,7 @@ namespace Khd.Core.Domain.Models
/// 备用字段3
///
[Column("ud1")]
- public string ud1 { get; set; }
+ public int? ud1 { get; set; }
///
/// 备用字段3
///
diff --git a/src/Khd.Core.Domain/Models/WcsTaskLog.cs b/src/Khd.Core.Domain/Models/WcsTaskLog.cs
index 8dd61de..8d6fa56 100644
--- a/src/Khd.Core.Domain/Models/WcsTaskLog.cs
+++ b/src/Khd.Core.Domain/Models/WcsTaskLog.cs
@@ -204,7 +204,7 @@ namespace Khd.Core.Domain.Models
/// 备用字段3
///
[Column("ud1")]
- public string ud1 { get; set; }
+ public int? ud1 { get; set; }
///
/// 备用字段3
///
diff --git a/src/Khd.Core.Domain/Models/WcsTaskManual.cs b/src/Khd.Core.Domain/Models/WcsTaskManual.cs
new file mode 100644
index 0000000..862d1fc
--- /dev/null
+++ b/src/Khd.Core.Domain/Models/WcsTaskManual.cs
@@ -0,0 +1,215 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Khd.Core.Domain.Models
+{
+ [Table("wcs_task_manual")]
+ public class WcsTaskManual
+ {
+ [Column("from_floor_no")]
+ public int? fromFloorNo { get; set; }
+
+ [Key]
+ [Column("objid")]
+ public long objid { get; set; }
+
+ ///
+ /// wcs_warehouse_order 主键id
+ ///
+ [Column("master_id")]
+ public long? masterId { get; set; }
+
+ ///
+ /// wms出入库记录表id
+ ///
+ [Column("order_id")]
+ public long? orderId { get; set; }
+
+ ///
+ /// 流水号
+ ///
+ [Column("serial_no")]
+ public long? serialNo { get; set; }
+
+ ///
+ /// 设备编号
+ ///
+ [Column("equipment_no")]
+ public string equipmentNo { get; set; }
+
+ ///
+ /// 容器号(托盘或者箱号)
+ ///
+ [Column("container_no")]
+ public string containerNo { get; set; }
+
+ ///
+ /// 任务类型,字典表
+ /// 27提升机输送线对接位-验收拆分区
+ /// 28验收拆分区-原材料周转区
+ /// 29回转输送线回库口-辅料库货架
+ /// 30辅料库货架-回转输送线出库口
+ /// 31回转输送线回库口-辅料库货架
+ /// 32物料分拣位-装配区领料工位
+ /// 33原材料周转区-背板安装区
+ /// 34背板安装区-半成品周转区
+ /// 35半成品周转区-检测台
+ /// 37检验台-成品区
+ /// 38成品区-提升机输送线对接点
+ /// 46原材料-柜体拆分区
+ /// 47接驳位-原材料周转区
+ ///
+ ///
+ ///
+ [Column("task_type")]
+ public int? taskType { get; set; }
+
+ ///
+ /// 任务状态,字典表
+ ///
+ [Column("task_status")]
+ public int? taskStatus { get; set; }
+
+ ///
+ /// 物料ID
+ ///
+ [Column("material_id")]
+ public long? materialId { get; set; }
+
+ ///
+ /// 物料号
+ ///
+ [Column("material_no")]
+ public string? materialNo { get; set; }
+
+ ///
+ /// 数量
+ ///
+ [Column("qty")]
+ public int? qty { get; set; }
+
+ ///
+ /// 起始点编号
+ ///
+ [Column("start_point_no")]
+ public string startPointNo { get; set; }
+
+ ///
+ /// 起始点id
+ ///
+ [Column("start_point_id")]
+ public long? startPointId { get; set; }
+
+ ///
+ /// 当前点编号
+ ///
+ [Column("curr_point_no")]
+ public string currPointNo { get; set; }
+
+ ///
+ /// 当前点id
+ ///
+ [Column("curr_point_id")]
+ public long? currPointId { get; set; }
+
+ ///
+ /// 下一点位id
+ ///
+ [Column("next_point_id")]
+ public long? nextPointId { get; set; }
+
+ ///
+ /// 下一点位编号
+ ///
+ [Column("next_point_no")]
+ public string nextPointNo { get; set; }
+
+ ///
+ /// 结束点编号
+ ///
+ [Column("end_point_no")]
+ public string endPointNo { get; set; }
+
+ ///
+ /// 结束点id
+ ///
+ [Column("end_point_id")]
+ public long? endPointId { get; set; }
+
+ ///
+ /// 所属楼层
+ ///
+ [Column("floor_no")]
+ public int? floorNo { get; set; }
+
+ ///
+ /// 是否可用 0:不可用 1:可用
+ ///
+ [Column("use_flag")]
+ public int? useFlag { get; set; }
+
+ ///
+ /// 创建者
+ ///
+ [Column("create_by")]
+ public string createBy { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ [Column("create_time")]
+ public DateTime? createTime { get; set; }
+
+ ///
+ /// 更新者
+ ///
+ [Column("update_by")]
+ public string updateBy { get; set; }
+
+ ///
+ /// 更新时间
+ ///
+ [Column("update_time")]
+ public DateTime? updateTime { get; set; }
+
+ ///
+ /// 备用字段1
+ ///
+ [Column("ctu_execute")]
+ public string CTUExecute { get; set; }
+
+ ///
+ /// 备用字段2
+ ///
+ [Column("is_empty")]
+ public string isEmpty { get; set; }
+
+ ///
+ /// 备用字段3
+ ///
+ [Column("ud3")]
+ public string ud3 { get; set; }
+ ///
+ /// 备用字段3
+ ///
+ [Column("ud1")]
+ public int? ud1 { get; set; }
+ ///
+ /// 备用字段3
+ ///
+ [Column("ud2")]
+ public string ud2 { get; set; }
+ ///
+ /// 备注
+ ///
+ [Column("remark")]
+ public string remark { get; set; }
+
+
+ }
+}
diff --git a/src/Khd.Core.Domain/Models/WmsRawReturn.cs b/src/Khd.Core.Domain/Models/WmsRawReturn.cs
index 5fcbd4b..df49622 100644
--- a/src/Khd.Core.Domain/Models/WmsRawReturn.cs
+++ b/src/Khd.Core.Domain/Models/WmsRawReturn.cs
@@ -56,11 +56,11 @@ namespace Khd.Core.Domain.Models
[Column("material_id")]
public long? materialId { get; set; }
- ///
- /// 物料批次
- ///
- [Column("material_batch")]
- public string materialBatch { get; set; }
+ /////
+ ///// 物料批次
+ /////
+ //[Column("material_batch")]
+ //public string materialBatch { get; set; }
///
/// 计划出库数量
diff --git a/src/Khd.Core.Domain/Models/WmsRawStock.cs b/src/Khd.Core.Domain/Models/WmsRawStock.cs
index 5ea7b32..5b48cdf 100644
--- a/src/Khd.Core.Domain/Models/WmsRawStock.cs
+++ b/src/Khd.Core.Domain/Models/WmsRawStock.cs
@@ -117,7 +117,8 @@ namespace Khd.Core.Domain.Models
///
[Column("create_by")]
public string createBy { get; set; }
-
+ [Column("safe_flag")]
+ public string safeFlag { get; set; }
///
/// 创建时间
///
diff --git a/src/Khd.Core.EntityFramework/DefaultDbContext.cs b/src/Khd.Core.EntityFramework/DefaultDbContext.cs
index 735daca..5047a3e 100644
--- a/src/Khd.Core.EntityFramework/DefaultDbContext.cs
+++ b/src/Khd.Core.EntityFramework/DefaultDbContext.cs
@@ -9,8 +9,9 @@ namespace Khd.Core.EntityFramework
public DefaultDbContext(DbContextOptions options) : base(options)
{
}
+ public DbSet MesBaseMaterialInfo { get; set; }
public DbSet WmsRawReturn { get; set; }
-
+ public DbSet WcsTaskManual { get; set; }
public DbSet BaseDictionary { get; set; }
public DbSet BaseEquip { get; set; }
diff --git a/src/Khd.Core.Plc/StaticPlcHelper.cs b/src/Khd.Core.Plc/StaticPlcHelper.cs
index eb75c16..bd5549a 100644
--- a/src/Khd.Core.Plc/StaticPlcHelper.cs
+++ b/src/Khd.Core.Plc/StaticPlcHelper.cs
@@ -76,6 +76,10 @@ namespace Khd.Core.Plc
{
return Convert.ToString(value);
}
+ if (len == "10")
+ {
+ return Convert.ToBoolean(value);
+ }
return 0;
}
}
diff --git a/src/Khd.Core.Wcs/MainCentralControl.cs b/src/Khd.Core.Wcs/MainCentralControl.cs
index 5c8d651..0faa19f 100644
--- a/src/Khd.Core.Wcs/MainCentralControl.cs
+++ b/src/Khd.Core.Wcs/MainCentralControl.cs
@@ -69,10 +69,11 @@ namespace Khd.Core.Wcs
StaticData.PlcDic.TryAdd(plcConfig.Code, plc);
}
}
-
- //////创建任务
- //CreateTaskByRecord createTaskByRecord = new(_host, StaticData.PlcDic[0], "");
- //createTaskByRecord.StartPoint();
+ //SystemTimer systemTimer = new SystemTimer(_host);
+ //systemTimer.Start();
+ //创建任务
+ CreateTaskByRecord createTaskByRecord = new(_host, "");
+ createTaskByRecord.StartPoint();
////一楼提升机以及接驳位
//FirstFloor firstFloor = new(_host, StaticData.PlcDic[0]);
@@ -113,14 +114,14 @@ namespace Khd.Core.Wcs
//FiveFloorLine fiveFloorLine = new(_host, StaticData.PlcDic[0], FiveFloorLineEquip.floorNo.Value, FiveFloorLineEquip.equipNo);
//fiveFloorLine.StartPoint();
- ////五层CTU
- //var FiveFloorCTUEquip = StaticData.BaseEquip.Where(t => t.floorNo == 5 && t.equipType == 6).First();
- //FiveFloorCTU fiveFloorCTU = new(_host, StaticData.PlcDic[1], FiveFloorCTUEquip.floorNo.Value, FiveFloorCTUEquip.equipNo);
- //fiveFloorCTU.StartPoint();
+ //五层CTU
+ var FiveFloorCTUEquip = StaticData.BaseEquip.Where(t => t.floorNo == 5 && t.equipType == 6).First();
+ FiveFloorCTU fiveFloorCTU = new(_host, StaticData.PlcDic[1], FiveFloorCTUEquip.floorNo.Value, FiveFloorCTUEquip.equipNo);
+ fiveFloorCTU.StartPoint();
////五层AGV
//var FifthFloorAgvEquip = StaticData.BaseEquip.Where(t => t.floorNo == 5 && t.equipType == 5).First();
- //FiveFloorAGV fifthFloorAGV = new(_host, StaticData.PlcDic[0], FifthFloorAgvEquip.floorNo.Value, FifthFloorAgvEquip.equipNo);
+ //FiveFloorAGV fifthFloorAGV = new(_host, StaticData.PlcDic[2], FifthFloorAgvEquip.floorNo.Value, FifthFloorAgvEquip.equipNo);
//fifthFloorAGV.StartPoint();
//var FifthFloorBearAgvEquip = StaticData.BaseEquip.Where(t => t.floorNo == 5 && t.equipType == 11).First();
diff --git a/src/Khd.Core.Wcs/SystemData.cs b/src/Khd.Core.Wcs/SystemData.cs
index c1c7b19..98c1f9e 100644
--- a/src/Khd.Core.Wcs/SystemData.cs
+++ b/src/Khd.Core.Wcs/SystemData.cs
@@ -9,9 +9,9 @@ namespace Khd.Core.Wcs
{
public class SystemData
{
- public static long _serialNo { get; set; } = 1;
+ private static long _serialNo { get; set; } = 1;
- public static object serialLock = new object();
+ private static object serialLock = new object();
public static long GetSerialNo(DefaultDbContext dbContext)
{
@@ -29,6 +29,6 @@ namespace Khd.Core.Wcs
return _serialNo;
}
}
-
+ public static object outStockLock = new object();
}
}
diff --git a/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs b/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs
index 3256aaf..acc46fd 100644
--- a/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs
+++ b/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs
@@ -22,7 +22,6 @@ namespace Khd.Core.Wcs.Wcs
public class CreateTaskByRecord
{
private readonly IHost _host;
- private readonly Plc.S7.Plc _plc;
List 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
///
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 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(wcs);
+ WcsTaskLog wcsTaskLog = CoreMapper.Map(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();
}
}
}
diff --git a/src/Khd.Core.Wcs/Wcs/FirstFloor.cs b/src/Khd.Core.Wcs/Wcs/FirstFloor.cs
index e956f23..eb11591 100644
--- a/src/Khd.Core.Wcs/Wcs/FirstFloor.cs
+++ b/src/Khd.Core.Wcs/Wcs/FirstFloor.cs
@@ -27,6 +27,7 @@ namespace Khd.Core.Wcs.Wcs
/// 一楼RFID 读
///
private readonly BasePlcpoint RFID001;
+ private readonly BasePlcpoint automatic;
///
/// 到位信号 读
///
@@ -74,6 +75,7 @@ namespace Khd.Core.Wcs.Wcs
//一楼提升机流水号 读
this.serialno06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("serialno06"));
+ this.automatic = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("automatic"));
//一楼提升机状态 读
this.equipstate06 = StaticData.BasePlcpointList.First(t => t.equipmentNo.Contains("Hoister") && t.plcpointNo.Contains("equipstate06"));
//一楼提升机任务状态 读
@@ -288,144 +290,148 @@ namespace Khd.Core.Wcs.Wcs
{
try
{
- using var scope = _host.Services.CreateScope();
- using var dbContext = scope.ServiceProvider.GetRequiredService();
- var serialno06Value = this._plc.Read(this.serialno06.plcpointAddress); //提升机流水号 读
- var equipstate06Value = this._plc.Read(this.equipstate06.plcpointAddress); //提升机状态 读
- var hoisterTrayIn06Value = this._plc.Read(this.hoistertrayin06.plcpointAddress); //提升机货物到位状态 读
- var currentfloor06Value = this._plc.Read(this.currentfloor06.plcpointAddress); //提升机当前楼层 读
- var targetfloor06Value = this._plc.Read(this.targetfloor06.plcpointAddress); //提升机目的楼层 写
- var reserialno06 = this._plc.Read(this.reserialno06.plcpointAddress); //反馈流水号
- var canwritewcsrun06value = this._plc.Read(this.canwritewcsrun06.plcpointAddress);
-
- //正常读到plc值
- if (targetfloor06Value != null && canwritewcsrun06value != null && serialno06Value != null && equipstate06Value != null && currentfloor06Value != null && reserialno06 != null && hoisterTrayIn06Value != null)
+ var automatic06Value = this._plc.Read(this.automatic.plcpointAddress);//提升机自动状态
+ if (automatic06Value != null && Convert.ToInt32(automatic06Value) == 1)
{
- //提升机空闲
- if (Convert.ToInt32(equipstate06Value) == 0)
+ using var scope = _host.Services.CreateScope();
+ using var dbContext = scope.ServiceProvider.GetRequiredService();
+ var serialno06Value = this._plc.Read(this.serialno06.plcpointAddress); //提升机流水号 读
+ var equipstate06Value = this._plc.Read(this.equipstate06.plcpointAddress); //提升机状态 读
+ var hoisterTrayIn06Value = this._plc.Read(this.hoistertrayin06.plcpointAddress); //提升机货物到位状态 读
+ var currentfloor06Value = this._plc.Read(this.currentfloor06.plcpointAddress); //提升机当前楼层 读
+ var targetfloor06Value = this._plc.Read(this.targetfloor06.plcpointAddress); //提升机目的楼层 写
+ var reserialno06 = this._plc.Read(this.reserialno06.plcpointAddress); //反馈流水号
+ var canwritewcsrun06value = this._plc.Read(this.canwritewcsrun06.plcpointAddress);
+
+ //正常读到plc值
+ if (targetfloor06Value != null && canwritewcsrun06value != null && serialno06Value != null && equipstate06Value != null && currentfloor06Value != null && reserialno06 != null && hoisterTrayIn06Value != null)
{
- var wcsTasks = dbContext.WcsTask.Where(t => t.nextPointId == T01).OrderBy(t => t.createTime).ToList();
- foreach (var wcsTask in wcsTasks)
+ //提升机空闲
+ if (Convert.ToInt32(equipstate06Value) == 0)
{
- if (wcsTasks.Where(t => t.taskStatus > 0).Where(t => t.objid != wcsTask.objid).Any())
+ var wcsTasks = dbContext.WcsTask.Where(t => t.nextPointId == T01).OrderBy(t => t.createTime).ToList();
+ foreach (var wcsTask in wcsTasks)
{
- LogManager.Info("提升机线程:有其他任务正在执行,跳过当前任务");
- continue;
- }
- BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo);
- if (wcsTask.taskStatus == 0 && Convert.ToInt32(hoisterTrayIn06Value) == 0)//创建状态,并且里面没有货物
- {
- if (lineEquip.equipStatus == 1)
+ if (wcsTasks.Where(t => t.taskStatus > 0).Where(t => t.objid != wcsTask.objid).Any())
{
- LogManager.Info("提升机线程:" + wcsTask.floorNo + "楼接驳位有AGV任务,跳过当前任务");
+ LogManager.Info("提升机线程:有其他任务正在执行,跳过当前任务");
continue;
}
- BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
- if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress))
+ BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo);
+ if (wcsTask.taskStatus == 0 && Convert.ToInt32(hoisterTrayIn06Value) == 0)//创建状态,并且里面没有货物
{
- if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)
+ if (lineEquip.equipStatus == 1)
{
- if (Convert.ToInt32(canwritewcsrun06value) == 0)
+ LogManager.Info("提升机线程:" + wcsTask.floorNo + "楼接驳位有AGV任务,跳过当前任务");
+ continue;
+ }
+ BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
+ if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress))
+ {
+ if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)
{
- wcsTask.taskStatus = 2;
+ if (Convert.ToInt32(canwritewcsrun06value) == 0)
+ {
+ wcsTask.taskStatus = 2;
+ wcsTask.updateBy = "提升机线程";
+ wcsTask.updateTime = DateTime.Now;
+ wcsTask.remark = "提升机任务执行中";
+ BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
+ this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
+ this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
+ dbContext.Update(wcsTask);
+ dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
+ lineEquip.equipStatus = 1;
+ dbContext.Update(lineEquip);
+ dbContext.SaveChanges();
+ }
+ }
+ else
+ {
+ wcsTask.taskStatus = 1;
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行中";
- BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
- this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
+ this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.fromFloorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层
this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
dbContext.Update(wcsTask);
- dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
+ dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 1, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
lineEquip.equipStatus = 1;
dbContext.Update(lineEquip);
dbContext.SaveChanges();
}
}
- else
- {
- wcsTask.taskStatus = 1;
- wcsTask.updateBy = "提升机线程";
- wcsTask.updateTime = DateTime.Now;
- wcsTask.remark = "提升机任务执行中";
- this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.fromFloorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层
- this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
- dbContext.Update(wcsTask);
- dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 1, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
- lineEquip.equipStatus = 1;
- dbContext.Update(lineEquip);
- dbContext.SaveChanges();
- }
}
- }
- if (wcsTask.taskStatus == 1 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
- {
- BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
- if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress))
+ if (wcsTask.taskStatus == 1 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
{
- if (Convert.ToInt32(canwritewcsrun06value) == 0)
+ BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
+ if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress))
{
- if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)//提升机当前楼层为初始地楼层
+ if (Convert.ToInt32(canwritewcsrun06value) == 0)
{
- wcsTask.taskStatus = 2;
- wcsTask.updateBy = "提升机线程";
- wcsTask.updateTime = DateTime.Now;
- wcsTask.remark = "提升机任务执行中";
- BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
- this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
- this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
- dbContext.Update(wcsTask);
- dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
- dbContext.SaveChanges();
+ if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)//提升机当前楼层为初始地楼层
+ {
+ wcsTask.taskStatus = 2;
+ wcsTask.updateBy = "提升机线程";
+ wcsTask.updateTime = DateTime.Now;
+ wcsTask.remark = "提升机任务执行中";
+ BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
+ this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString());
+ this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString());
+ dbContext.Update(wcsTask);
+ dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" });
+ dbContext.SaveChanges();
+ }
}
}
}
- }
- if (wcsTask.taskStatus == 2 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
- {
- if (Convert.ToInt32(hoisterTrayIn06Value) == 1)//托盘已经进提升机
+ if (wcsTask.taskStatus == 2 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
{
- wcsTask.taskStatus = 3;
+ if (Convert.ToInt32(hoisterTrayIn06Value) == 1)//托盘已经进提升机
+ {
+ wcsTask.taskStatus = 3;
+ wcsTask.updateBy = "提升机线程";
+ wcsTask.updateTime = DateTime.Now;
+ wcsTask.remark = "提升机任务执行完成";
+ this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.floorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层
+ dbContext.Update(wcsTask);
+ dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 3, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
+ dbContext.SaveChanges();
+ }
+ }
+ if (wcsTask.taskStatus == 3 && Convert.ToInt32(currentfloor06Value) == wcsTask.floorNo && Convert.ToInt32(reserialno06) == wcsTask.serialNo)//任务状态为3,且当前楼层为任务的目的楼层
+ {
+ if (Convert.ToInt32(canwritewcsrun06value) == 0)
+ {
+ wcsTask.taskStatus = 4;
+ wcsTask.updateBy = "提升机线程";
+ wcsTask.updateTime = DateTime.Now;
+ wcsTask.remark = "提升机任务执行完成";
+ BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
+ this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "2", basePlcpoint.plcpointLength.ToString());//去向为2,表示提升机已到达目的地,让货出去
+ dbContext.Update(wcsTask);
+ dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 4, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
+ dbContext.SaveChanges();
+ }
+ }
+ else if (wcsTask.taskStatus == 4)
+ {
+ BaseEquip floorEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo);
+ wcsTask.nextPointId = floorEquip.objid;
+ wcsTask.nextPointNo = floorEquip.equipNo;
+ wcsTask.taskStatus = 5;
wcsTask.updateBy = "提升机线程";
wcsTask.updateTime = DateTime.Now;
wcsTask.remark = "提升机任务执行完成";
- this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.floorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层
+ lineEquip.equipStatus = 0;
+ dbContext.Update(lineEquip);
+ dbContext.SaveChanges();
dbContext.Update(wcsTask);
- dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 3, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
+ dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 5, nextPointId = floorEquip.objid, nextPointNo = floorEquip.equipNo, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
dbContext.SaveChanges();
}
+ break;
}
- if (wcsTask.taskStatus == 3 && Convert.ToInt32(currentfloor06Value) == wcsTask.floorNo && Convert.ToInt32(reserialno06) == wcsTask.serialNo)//任务状态为3,且当前楼层为任务的目的楼层
- {
- if (Convert.ToInt32(canwritewcsrun06value) == 0)
- {
- wcsTask.taskStatus = 4;
- wcsTask.updateBy = "提升机线程";
- wcsTask.updateTime = DateTime.Now;
- wcsTask.remark = "提升机任务执行完成";
- BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun"));
- this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "2", basePlcpoint.plcpointLength.ToString());//去向为2,表示提升机已到达目的地,让货出去
- dbContext.Update(wcsTask);
- dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 4, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
- dbContext.SaveChanges();
- }
- }
- else if (wcsTask.taskStatus == 4)
- {
- BaseEquip floorEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo);
- wcsTask.nextPointId = floorEquip.objid;
- wcsTask.nextPointNo = floorEquip.equipNo;
- wcsTask.taskStatus = 5;
- wcsTask.updateBy = "提升机线程";
- wcsTask.updateTime = DateTime.Now;
- wcsTask.remark = "提升机任务执行完成";
- lineEquip.equipStatus = 0;
- dbContext.Update(lineEquip);
- dbContext.SaveChanges();
- dbContext.Update(wcsTask);
- dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 5, nextPointId = floorEquip.objid, nextPointNo = floorEquip.equipNo, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" });
- dbContext.SaveChanges();
- }
- break;
}
}
}
diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs
index d70e896..098de22 100644
--- a/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs
+++ b/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs
@@ -74,6 +74,7 @@ namespace Khd.Core.Wcs.Wcs
var taskList = dbContext.WcsTask
.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无任务");
@@ -87,6 +88,7 @@ namespace Khd.Core.Wcs.Wcs
}
if (item.taskStatus == 0)//下发任务
{
+ BaseDictionary baseDictionary = StaticData.BaseDictionary.First(t => t.objid == item.taskType);
if (item.taskType == 37)//入库任务
{
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
@@ -108,7 +110,7 @@ namespace Khd.Core.Wcs.Wcs
};
var agvTask = new RequestAGVTaskDto
{
- reqCode = item.objid.ToString(),
+ reqCode = wcsCmd.objid.ToString(),
positionCodePath = new List
{
new ()
@@ -122,6 +124,7 @@ namespace Khd.Core.Wcs.Wcs
type="00"
}
},
+ taskTyp= baseDictionary.dicValue,
ctnrTyp = "2",
};
string message = JsonConvert.SerializeObject(agvTask);
@@ -162,9 +165,9 @@ namespace Khd.Core.Wcs.Wcs
BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1);
WcsCmd wcsCmd = new()
{
- objid = item.objid,
+ objid = StaticData.SnowId.NextId(),
cmdStatus = 0,
- taskId = item.orderId,
+ taskId = item.objid,
useFlag = 1,
cmdType = item.taskType,
containerNo = item.containerNo,
@@ -177,7 +180,7 @@ namespace Khd.Core.Wcs.Wcs
};
RequestAGVTaskDto agvTask = new()
{
- reqCode = item.objid.ToString(),
+ reqCode = wcsCmd.objid.ToString(),
positionCodePath = new List
{
new ()
@@ -191,7 +194,7 @@ namespace Khd.Core.Wcs.Wcs
type="00"
}
},
- taskTyp = "",
+ taskTyp = baseDictionary.dicValue,
ctnrTyp = "2"
};
string message = JsonConvert.SerializeObject(agvTask);
@@ -222,9 +225,9 @@ namespace Khd.Core.Wcs.Wcs
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId);
WcsCmd wcsCmd = new()
{
- objid = item.objid,
+ objid = StaticData.SnowId.NextId(),
cmdStatus = 0,
- taskId = item.orderId,
+ taskId = item.objid,
useFlag = 1,
cmdType = item.taskType,
containerNo = item.containerNo,
@@ -232,12 +235,12 @@ namespace Khd.Core.Wcs.Wcs
createBy = FloorNo + "楼AGV",
currPointId = item.currPointId,
currPointNo = wmsBaseLocation.agvPositionCode,
- nextPointId = 30,
+ nextPointId = endEquip.objid,
nextPointNo = endEquip.agvPositionCode,
};
RequestAGVTaskDto agvTask = new()
{
- reqCode = item.objid.ToString(),
+ reqCode = wcsCmd.objid.ToString(),
positionCodePath = new List
{
new ()
@@ -251,7 +254,7 @@ namespace Khd.Core.Wcs.Wcs
type="00"
}
},
- taskTyp = "",
+ taskTyp = baseDictionary.dicValue,
ctnrTyp = "2"
};
string message = JsonConvert.SerializeObject(agvTask);
@@ -295,7 +298,7 @@ namespace Khd.Core.Wcs.Wcs
};
var agvTask = new RequestAGVTaskDto
{
- reqCode = item.objid.ToString(),
+ reqCode = wcsCmd.objid.ToString(),
positionCodePath = new List
{
new ()
@@ -309,6 +312,7 @@ namespace Khd.Core.Wcs.Wcs
type="00"
}
},
+ taskTyp= baseDictionary.dicValue,
ctnrTyp = "2",
};
string message = JsonConvert.SerializeObject(agvTask);
@@ -337,9 +341,9 @@ namespace Khd.Core.Wcs.Wcs
BaseEquip currentEquip = StaticData.BaseEquip.First(t => t.objid == 29);
WcsCmd wcsCmd = new()
{
- objid = item.objid,
+ objid = StaticData.SnowId.NextId(),
cmdStatus = 0,
- taskId = item.orderId,
+ taskId = item.objid,
useFlag = 1,
cmdType = item.taskType,
containerNo = item.containerNo,
@@ -352,7 +356,7 @@ namespace Khd.Core.Wcs.Wcs
};
RequestAGVTaskDto agvTask = new()
{
- reqCode = item.objid.ToString(),
+ reqCode = wcsCmd.objid.ToString(),
positionCodePath = new List
{
new ()
@@ -366,7 +370,7 @@ namespace Khd.Core.Wcs.Wcs
type="00"
}
},
- taskTyp = "",
+ taskTyp = baseDictionary.dicValue,
ctnrTyp = "2"
};
string message = JsonConvert.SerializeObject(agvTask);
@@ -395,9 +399,9 @@ namespace Khd.Core.Wcs.Wcs
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
WcsCmd wcsCmd = new()
{
- objid = item.objid,
+ objid = StaticData.SnowId.NextId(),
cmdStatus = 0,
- taskId = item.orderId,
+ taskId = item.objid,
useFlag = 1,
cmdType = item.taskType,
containerNo = item.containerNo,
@@ -410,7 +414,7 @@ namespace Khd.Core.Wcs.Wcs
};
RequestAGVTaskDto agvTask = new()
{
- reqCode = item.objid.ToString(),
+ reqCode = wcsCmd.objid.ToString(),
positionCodePath = new List
{
new()
@@ -423,7 +427,10 @@ namespace Khd.Core.Wcs.Wcs
positionCode = wcsCmd.nextPointNo,
type = "00"
}
- }
+ },
+ taskTyp= baseDictionary.dicValue,
+ ctnrTyp="2"
+
};
string message = JsonConvert.SerializeObject(agvTask);
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
@@ -466,7 +473,7 @@ namespace Khd.Core.Wcs.Wcs
};
var agvTask = new RequestAGVTaskDto
{
- reqCode = item.objid.ToString(),
+ reqCode = wcsCmd.objid.ToString(),
positionCodePath = new List
{
new ()
@@ -480,6 +487,65 @@ namespace Khd.Core.Wcs.Wcs
type="00"
}
},
+ taskTyp= baseDictionary.dicValue,
+ ctnrTyp = "2",
+ };
+ string message = JsonConvert.SerializeObject(agvTask);
+ string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
+ var reponseMessage = JsonConvert.DeserializeObject(result);
+ if (reponseMessage != null && reponseMessage.message == "成功")
+ {
+ wcsCmd.taskCode = reponseMessage.data;
+ wcsCmd.cmdStatus = 1;
+ item.taskStatus = 1;
+ dbContext.Update(item);
+ dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 });
+ WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd);
+ dbContext.Add(wcsCmdLog);
+ dbContext.Add(wcsCmd);
+ dbContext.SaveChanges();
+ }
+ else
+ {
+ LogManager.Info("五楼Agv下发任务失败" + item.taskType + message);
+ }
+ }
+ else if (item.taskType == 49)//移库
+ {
+ WmsBaseLocation fromBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.currPointId);
+ WmsBaseLocation toBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
+ WcsCmd wcsCmd = new()
+ {
+ objid = StaticData.SnowId.NextId(),
+ cmdStatus = 0,
+ taskId = item.objid,
+ useFlag = 1,
+ cmdType = item.taskType,
+ containerNo = item.containerNo,
+ createTime = DateTime.Now,
+ createBy = FloorNo + "楼AGV",
+ currPointId = item.currPointId,
+ currPointNo = fromBaseLocation.agvPositionCode,
+ nextPointId = item.endPointId,
+ nextPointNo = toBaseLocation.agvPositionCode,
+ };
+ var agvTask = new RequestAGVTaskDto
+ {
+ reqCode = wcsCmd.objid.ToString(),
+ positionCodePath = new List
+ {
+ new ()
+ {
+ positionCode=wcsCmd.currPointNo,
+ type="00"
+ },
+ new ()
+ {
+ positionCode=wcsCmd.nextPointNo,
+ type="00"
+ }
+ },
+ taskTyp = baseDictionary.dicValue,
ctnrTyp = "2",
};
string message = JsonConvert.SerializeObject(agvTask);
@@ -512,7 +578,7 @@ namespace Khd.Core.Wcs.Wcs
{
var agvTask = new RequestAGVTaskDto
{
- reqCode = item.objid.ToString(),
+ reqCode = StaticData.SnowId.NextId().ToString(),
taskCode = wcsCmd.taskCode
};
string message = JsonConvert.SerializeObject(agvTask);
@@ -530,7 +596,34 @@ namespace Khd.Core.Wcs.Wcs
}
else if (wcsCmd.cmdStatus == 5)
{
- if (item.taskType == 37)//入库
+ if (item.taskType == 49)
+ {
+ WmsBaseLocation fromBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.currPointId);
+ WmsBaseLocation toBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
+ fromBaseLocation.outstockFlag = "0";
+ fromBaseLocation.locationStatus = "1";
+ toBaseLocation.instockFlag = "0";
+ toBaseLocation.locationStatus = "1";
+ var wmsRawStock = dbContext.WmsRawStock.Where(t => t.locationCode == fromBaseLocation.locationCode).FirstOrDefault();
+ if (wmsRawStock != null)
+ {
+ wmsRawStock.locationCode = toBaseLocation.locationCode;
+ dbContext.Update(wmsRawStock);
+ }
+ else
+ {
+ var wmsProductStock = dbContext.WmsProductStock.FirstOrDefault(t => t.locationCode == fromBaseLocation.locationCode);
+ if (wmsProductStock != null)
+ {
+ wmsProductStock.locationCode = toBaseLocation.locationCode;
+ dbContext.Update(wmsProductStock);
+ }
+ }
+ dbContext.Update(fromBaseLocation);
+ dbContext.Update(toBaseLocation);
+ dbContext.SaveChanges();
+ }
+ else if (item.taskType == 37)//入库
{
//WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation
@@ -657,6 +750,9 @@ namespace Khd.Core.Wcs.Wcs
planDetailCode = wmsProductInstock.planDetailCode,
warehouseId = 512
};
+ BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId);
+ startEquip.emptyCount = 0;
+ dbContext.Update(startEquip);
dbContext.Add(wmsProductStock);
dbContext.Update(wmsBaseLocation);
dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete();
@@ -668,31 +764,42 @@ namespace Khd.Core.Wcs.Wcs
}
else if (item.taskType == 46)//该任务结束后,立刻生成一个新的返库任务,但是是否使用标志未0,等待mes通知
{
+ WcsTask newTask = CoreMapper.Map(item);
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId);
wmsBaseLocation.outstockFlag = "0";
wmsBaseLocation.instockFlag = "1";
- wmsBaseLocation.containerCode = "";
+ wmsBaseLocation.locationStatus = "2";
+ wmsBaseLocation.containerCode = null;
wmsBaseLocation.updateTime = DateTime.Now;
wmsBaseLocation.updateBy = "WCS";
- 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.startPointNo;
- item.startPointId = item.currPointId;
- item.startPointNo = item.currPointNo;
- item.taskType = 28;
- item.taskStatus = 0;
- item.useFlag = 0;
- dbContext.Add(item);
- WcsTaskLog wcsTaskLog = CoreMapper.Map(item);
- dbContext.Add(wcsTaskLog);
- dbContext.SaveChanges();
+ WmsRawStock? wmsRawStock = dbContext.WmsRawStock.Where(t => t.locationCode == wmsBaseLocation.locationCode).FirstOrDefault();
+ if(wmsRawStock != null)
+ {
+ wmsRawStock.completeFlag = "0";
+ wmsRawStock.updateDate = DateTime.Now;
+ 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.startPointNo;
+ item.startPointId = item.currPointId;
+ item.startPointNo = item.currPointNo;
+ item.taskType = 28;
+ item.taskStatus = 0;
+ item.useFlag = 0;
+ dbContext.Add(item);
+ WcsTaskLog wcsTaskLog = CoreMapper.Map(item);
+ dbContext.Add(wcsTaskLog);
+ dbContext.SaveChanges();
+ }
+
}
else if (item.taskType == 28)//柜体拆分到原材料
{
@@ -709,6 +816,10 @@ namespace Khd.Core.Wcs.Wcs
wmsRawStock.completeFlag = "0";
wmsRawStock.updateDate = DateTime.Now;
wmsRawStock.updateBy = "WCS";
+ wmsRawStock.occupyAmount = 0;
+ BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.currPointId);
+ startEquip.emptyCount = 0;
+ dbContext.Update(startEquip);
dbContext.Update(wmsRawStock);
dbContext.Update(wmsBaseLocation);
dbContext.WcsTask.Where(t => t.objid == item.objid).Delete();
diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs
index 2743182..07a973c 100644
--- a/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs
+++ b/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs
@@ -28,6 +28,9 @@ namespace Khd.Core.Wcs.Wcs
private readonly BasePlcpoint LineRFID;
private readonly BasePlcpoint isarrive;
private readonly BasePlcpoint isput;
+ private readonly BasePlcpoint canReceive;
+ private readonly BasePlcpoint ReceiveMaterial;
+ private readonly BasePlcpoint CtuLineWaring;
private bool isWait = false;
private bool isSendWait = false;
int FloorNo { get; set; }
@@ -43,7 +46,9 @@ namespace Khd.Core.Wcs.Wcs
this.LineRFID = this.ScanPoint.First(t => t.plcpointNo.Contains("RFID5001"));
this.isarrive = this.ScanPoint.First(t => t.plcpointNo.Contains("isarrive"));
this.isput = this.ScanPoint.First(t => t.plcpointNo.Contains("isput"));
-
+ this.canReceive = this.ScanPoint.First(t => t.plcpointNo.Contains("canReceive"));
+ this.ReceiveMaterial = this.ScanPoint.First(t => t.plcpointNo.Contains("ReceiveMaterial"));
+ this.CtuLineWaring = this.ScanPoint.First(t => t.plcpointNo.Contains("CTULineWaring"));
//var lineRFID = this._plc.Read(NodeSettingCarNo.plcpointAddress);
try
{
@@ -63,23 +68,51 @@ namespace Khd.Core.Wcs.Wcs
public void StartPoint()
{
- Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
- FlowPointThread.Start();
+ //Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
+ //FlowPointThread.Start();
- Thread FlowCTUInWareThread = new Thread(MonitorInWare);
- FlowCTUInWareThread.Start();
+ //Thread FlowCTUInWareThread = new Thread(MonitorInWare);
+ //FlowCTUInWareThread.Start();
- Thread CtuWaitThread = new Thread(CtuWaitLogic);
- CtuWaitThread.Start();
+ Thread HeartThread = new Thread(HeartLogic);
+ HeartThread.Start();
Console.WriteLine(DateTime.Now + ":五楼CTU上件扫描监听启动");
LogManager.Info("五楼CTU上件扫描监听启动");
}
+ private void HeartLogic(object? obj)
+ {
+ BasePlcpoint heartPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "CTUHeart");
+ bool flag = true;
+ while (true)
+ {
+ try
+ {
+ flag = !flag;
+ this._plc.WriteToPoint(heartPoint.plcpointAddress,flag.ToString(),heartPoint.plcpointLength.ToString());
+ }
+ catch
+ {
+ try
+ {
+ this._plc = new Plc.S7.Plc(this._plc.CPU,this._plc.IP, this._plc.Port, this._plc.Rack, this._plc.Slot);
+ this._plc.Open();
+ }
+ catch
+ {
+
+ }
+ }
+ Thread.Sleep(1000);
+ }
+ }
+
private void MonitorInWare(object? obj)
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService();
+ bool IsStart = false;
while (true)
{
try
@@ -87,8 +120,15 @@ namespace Khd.Core.Wcs.Wcs
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
var rfid = this._plc.ReadRFID(LineRFID.plcpointAddress);
var isArrive = this._plc.Read(isarrive.plcpointAddress);
- if (rfid != null && isArrive != null && Convert.ToInt32(isArrive) == 1)
+ var receiveMaterial = this._plc.Read(ReceiveMaterial.plcpointAddress);
+ var waring = this._plc.Read(CtuLineWaring.plcpointAddress);
+ bool haveAny = dbContext.WcsTask.Where(t => t.nextPointId == 11).Any();
+ if (rfid != null && isArrive != null && receiveMaterial != null && Convert.ToInt32(receiveMaterial) == 1 && Convert.ToInt32(isArrive) == 1)
{
+ if (Convert.ToBoolean(waring))
+ {
+ this._plc.WriteToPoint(CtuLineWaring.plcpointAddress, "false", CtuLineWaring.plcpointLength.ToString());
+ }
rfid = rfid[rfid.IndexOf('C')..];
WcsTask? task = dbContext.WcsTask.FirstOrDefault(t => t.containerNo == rfid);
if (task == null)
@@ -115,6 +155,7 @@ namespace Khd.Core.Wcs.Wcs
endPointNo = wmsBaseLocation.agvPositionCode,
taskType = 29,
taskStatus = 0,
+ useFlag = 1,
floorNo = 5,
containerNo = rfid.ToString(),
equipmentNo = baseEquip.equipNo,
@@ -123,14 +164,92 @@ namespace Khd.Core.Wcs.Wcs
};
wmsBaseLocation.instockFlag = "1";
wmsBaseLocation.locationStatus = "2";
+ wmsBaseLocation.updateTime = DateTime.Now;
dbContext.Update(wmsBaseLocation);
dbContext.Add(wcsTask);
- //WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask);
- //dbContext.WcsTaskLog.Add(wcsTaskLog);
+ WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask);
+ dbContext.Add(wcsTaskLog);
dbContext.SaveChanges();
}
}
}
+ else
+ {
+ if (task.taskType == 30)
+ {
+ dbContext.WcsTask.Where(t => t.objid == task.objid).Delete();
+ //根据rfid找到库位
+ //生成入库任务
+ var wmsBaseLocation = dbContext.WmsBaseLocation.FirstOrDefault(t => t.containerCode == rfid);
+ if (wmsBaseLocation != null)
+ {
+ BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.equipNo == "FL051");
+ BaseEquip ctuEquip = StaticData.BaseEquip.First(t => t.objid == 11);
+ if (wmsBaseLocation != null)
+ {
+ var wcsTask = new WcsTask()
+ {
+ objid = StaticData.SnowId.NextId(),
+ startPointId = baseEquip.objid,
+ startPointNo = baseEquip.agvPositionCode,
+ currPointId = baseEquip.objid,
+ currPointNo = baseEquip.agvPositionCode,
+ nextPointId = ctuEquip.objid,
+ useFlag = 1,
+ endPointId = wmsBaseLocation.locationId,
+ endPointNo = wmsBaseLocation.agvPositionCode,
+ taskType = 29,
+ taskStatus = 0,
+ floorNo = 5,
+ containerNo = rfid.ToString(),
+ equipmentNo = baseEquip.equipNo,
+ createBy = FloorNo + "楼CTU",
+ createTime = DateTime.Now,
+ };
+ wmsBaseLocation.instockFlag = "1";
+ wmsBaseLocation.locationStatus = "2";
+ wmsBaseLocation.updateTime = DateTime.Now;
+ dbContext.Update(wmsBaseLocation);
+ dbContext.Add(wcsTask);
+ WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask);
+ dbContext.Add(wcsTaskLog);
+ dbContext.SaveChanges();
+ }
+ }
+ }
+ }
+ }
+ else if(Convert.ToInt32(receiveMaterial) == 1 && Convert.ToInt32(isArrive) == 1 && string.IsNullOrEmpty(rfid))
+ {
+ if (!Convert.ToBoolean(waring))
+ {
+ this._plc.WriteToPoint(CtuLineWaring.plcpointAddress, "true", CtuLineWaring.plcpointLength.ToString());
+ }
+ }
+ else if (receiveMaterial != null && Convert.ToInt32(receiveMaterial) == 1)
+ {
+ if (!IsStart && !haveAny)
+ {
+ Task.Run(() =>
+ {
+ IsStart = true;
+ Thread.Sleep(10000);
+ lock (SystemData.outStockLock)
+ {
+ dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
+ WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
+ bool haveTask = dbContext.WcsTask.Where(t => t.nextPointId == 11).Any();
+ if (!haveTask && wcsOutstockLock.boxStatus == 1)
+ {
+ wcsOutstockLock.boxStatus = 0;
+ wcsOutstockLock.qty = 0;
+ dbContext.Update(wcsOutstockLock);
+ dbContext.SaveChanges();
+ }
+ IsStart = false;
+ }
+ });
+ }
}
}
catch (Exception ex)
@@ -147,6 +266,7 @@ namespace Khd.Core.Wcs.Wcs
}
}
+ LogManager.Error(ex);
}
Thread.Sleep(1000);
}
@@ -155,45 +275,75 @@ namespace Khd.Core.Wcs.Wcs
///
/// 预执行任务下发
///
- private void CtuWaitLogic()
+ //private void CtuWaitLogic()
+ //{
+ // BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == CTUID);
+ // BaseEquip Fl051 = StaticData.BaseEquip.First(t => t.objid == 19);//入库输送线
+ // while (true)
+ // {
+ // try
+ // {
+ // while (isWait)
+ // {
+ // var waitTask = new
+ // {
+ // reqCode = StaticData.SnowId.NextId().ToString(),
+ // positionCode = "CTU_IN",
+ // nextTask = 1200
+ // };
+ // string waitMessage = JsonConvert.SerializeObject(waitTask);
+ // string waitResult = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genPreScheduleTask", waitMessage);
+ // var waitReponse = JsonConvert.DeserializeObject(waitResult);
+ // if (waitReponse != null && waitReponse.code == "0")
+ // {
+ // isSendWait = true;
+ // }
+ // else
+ // {
+ // LogManager.Info("CTU下发预执行任务失败:\nwaitTask:" + waitMessage + "\nwaitResult:" + waitResult);
+ // }
+ // Thread.Sleep(1000 * 60 * 10);//每10分钟重新下发预执行任务
+ // }
+ // isSendWait = false;
+ // }
+ // catch (Exception ex)
+ // {
+ // LogManager.Error(ex);
+ // }
+ // Thread.Sleep(3000);
+ // }
+ //}
+ private bool CtuWaitLogic()
{
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == CTUID);
BaseEquip Fl051 = StaticData.BaseEquip.First(t => t.objid == 19);//入库输送线
- while (true)
+ try
{
- try
+ var waitTask = new
{
- while (isWait)
- {
- var waitTask = new
- {
- reqCode = StaticData.SnowId.NextId().ToString(),
- positionCode = "CTU_IN",
- nextTask = 1200
- };
- string waitMessage = JsonConvert.SerializeObject(waitTask);
- string waitResult = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genPreScheduleTask", waitMessage);
- var waitReponse = JsonConvert.DeserializeObject(waitResult);
- if (waitReponse != null && waitReponse.code == "0")
- {
- isSendWait = true;
- }
- else
- {
- LogManager.Info("CTU下发预执行任务失败:\nwaitTask:" + waitMessage + "\nwaitResult:" + waitResult);
- }
- Thread.Sleep(1000 * 60 * 10);//每10分钟重新下发预执行任务
- }
- isSendWait = false;
- }
- catch (Exception ex)
+ reqCode = StaticData.SnowId.NextId().ToString(),
+ positionCode = "CTU_IN",
+ nextTask = 120
+ };
+ string waitMessage = JsonConvert.SerializeObject(waitTask);
+ string waitResult = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genPreScheduleTask", waitMessage);
+ var waitReponse = JsonConvert.DeserializeObject(waitResult);
+ if (waitReponse != null && waitReponse.code == "0")
{
- LogManager.Error(ex);
+ return true;
+ }
+ else
+ {
+ LogManager.Info("CTU下发预执行任务失败:\nwaitTask:" + waitMessage + "\nwaitResult:" + waitResult);
}
- Thread.Sleep(3000);
}
+ catch (Exception ex)
+ {
+ LogManager.Error(ex);
+ return false;
+ }
+ return false;
}
-
///
/// 监控上件扫描点位
///
@@ -208,27 +358,15 @@ namespace Khd.Core.Wcs.Wcs
try
{
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
- var taskList = dbContext.WcsTask.Where(t => t.nextPointId == CTUID).OrderBy(t => t.createTime).ToList();
+ var taskList = dbContext.WcsTask
+ .Where(t => t.useFlag == 1)
+ .Where(t => t.nextPointId == CTUID).OrderByDescending(t => t.ud1).ToList();
if (taskList.Count == 0)
{
LogManager.Info(FloorNo + "楼CTU无任务");
}
foreach (var item in taskList)
{
- if (!taskList.Where(t => t.taskType == 29 && t.CTUExecute == "2").Any())
- {
- if (item.CTUExecute == "1")
- {
- ExecuteInTask(baseEquip);
- WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
- wcsOutstockLock.qty = 0;
- wcsOutstockLock.boxStatus = 0;
- dbContext.Update(wcsOutstockLock);
- isWait = false;
- item.CTUExecute = "2";
- dbContext.Update(item);
- }
- }
if (item.taskStatus == 0)//CTU会同时生成多个任务,生成就下发?
{
if (item.taskType == 30)//出库任务
@@ -283,7 +421,7 @@ namespace Khd.Core.Wcs.Wcs
WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd);
dbContext.Add(wcsCmdLog);
WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
- wcsOutstockLock.qty = wcsOutstockLock.qty + 1;
+ wcsOutstockLock.qty++;
dbContext.Update(wcsOutstockLock);
dbContext.WcsCmd.Add(wcsCmd);
dbContext.SaveChanges();
@@ -295,26 +433,27 @@ namespace Khd.Core.Wcs.Wcs
}
else if (item.taskType == 29)//入库任务
{
- BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId);
- WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
- var wcsCmd = new WcsCmd()
- {
- objid = StaticData.SnowId.NextId(),
- cmdStatus = 0,
- taskId = item.objid,
- useFlag = 1,
- cmdType = item.taskType,
- containerNo = item.containerNo,
- createTime = DateTime.Now,
- createBy = FloorNo + "楼CTU",
- nextPointId = wmsBaseLocation.locationId,
- nextPointNo = wmsBaseLocation.agvPositionCode,
- currPointId = startEquip.objid,
- currPointNo = startEquip.agvPositionCode,
- };
- isWait = true;
- if (isSendWait)
+ bool haveOut = taskList.Where(t => t.taskType == 30).Where(t => t.taskStatus != 6).Any();
+ if (!haveOut && CtuWaitLogic())
{
+ BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId);
+ WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
+ var wcsCmd = new WcsCmd()
+ {
+ objid = StaticData.SnowId.NextId(),
+ cmdStatus = 0,
+ taskId = item.objid,
+ useFlag = 1,
+ cmdType = item.taskType,
+ containerNo = item.containerNo,
+ createTime = DateTime.Now,
+ createBy = FloorNo + "楼CTU",
+ nextPointId = wmsBaseLocation.locationId,
+ nextPointNo = wmsBaseLocation.agvPositionCode,
+ currPointId = startEquip.objid,
+ currPointNo = startEquip.agvPositionCode,
+ };
+
var agvTask = new
{
reqCode = StaticData.SnowId.NextId().ToString(),
@@ -347,15 +486,18 @@ namespace Khd.Core.Wcs.Wcs
dbContext.Add(wcsCmdLog);
dbContext.Update(item);
dbContext.Add(wcsCmd);
- int ctuTaskCount = dbContext.WcsTask.Where(t => t.taskType == 29 || t.taskType == 30).Count();
- WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
- if (ctuTaskCount >= 6 || wcsOutstockLock.qty == ctuTaskCount)//如果CTU当前任务数量很多,取消预执行任务
+ int ctuTaskCount = dbContext.WcsTask.Where(t => t.taskType == 29).Count();
+ lock (SystemData.outStockLock)
{
- ExecuteInTask(baseEquip);
- wcsOutstockLock.qty = 0;
- wcsOutstockLock.boxStatus = 0;
- dbContext.Update(wcsOutstockLock);
- isWait = false;
+ WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
+ if (ctuTaskCount >= 6 || wcsOutstockLock.qty == ctuTaskCount)//如果CTU当前任务数量很多,取消预执行任务
+ {
+ ExecuteInTask(baseEquip);
+ wcsOutstockLock.qty = 0;
+ wcsOutstockLock.boxStatus = 0;
+ dbContext.Update(wcsOutstockLock);
+ isWait = false;
+ }
}
dbContext.SaveChanges();
}
@@ -376,7 +518,7 @@ namespace Khd.Core.Wcs.Wcs
if (item.taskType == 30)
{
var canOut = this._plc.Read(isput.plcpointAddress);
- if (canOut != null && Convert.ToInt64(canOut) == 1)
+ if (canOut != null && Convert.ToInt64(canOut) == 0)
{
var agvTask = new
{
@@ -434,13 +576,19 @@ namespace Khd.Core.Wcs.Wcs
.First(t => t.locationId == item.startPointId && t.warehouseFloor == 5);
wmsBaseLocation.outstockFlag = "0";
wmsBaseLocation.locationStatus = "1";
+ wmsBaseLocation.locationStatus = "2";
dbContext.Update(wmsBaseLocation);
dbContext.WmsRawOutstockDetail.Where(t => t.locationCode == wmsBaseLocation.locationCode).Update(t => new WmsRawOutstockDetail { executeStatus = "2" });
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.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Delete();
+ dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 6 });
dbContext.WcsTaskLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsTaskLog() { taskStatus = 6 });
dbContext.SaveChanges();
+ int wcsTaskCount = dbContext.WcsTask.Where(t => t.taskType == 30 && t.taskStatus != 6).Count();
+ if (wcsTaskCount == 0)
+ {
+ this._plc.WriteToPoint(this.canReceive.plcpointAddress, "1", this.canReceive.plcpointLength?.ToString());
+ }
}
else if (item.taskType == 29)//入库任务
{
@@ -448,11 +596,24 @@ namespace Khd.Core.Wcs.Wcs
.First(t => t.locationId == item.endPointId && t.warehouseFloor == 5);
wmsBaseLocation.instockFlag = "0";
wmsBaseLocation.locationStatus = "1";
+ wmsBaseLocation.locationStatus = "1";
+ wmsBaseLocation.ContainerStatus = "1";
dbContext.Update(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 == wcsCmd.objid).Update(t => new WcsTaskLog() { taskStatus = 6 });
+ lock (SystemData.outStockLock)
+ {
+ int wcsTaskCount = dbContext.WcsTask.Where(t => t.taskType == 29).Count();
+ if (wcsTaskCount == 0)
+ {
+ WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
+ wcsOutstockLock.qty = 0;
+ wcsOutstockLock.boxStatus = 0;
+ dbContext.Update(wcsOutstockLock);
+ }
+ }
dbContext.SaveChanges();
}
}
@@ -462,6 +623,18 @@ namespace Khd.Core.Wcs.Wcs
}
catch (Exception ex)
{
+ if (ex is PlcException)
+ {
+ try
+ {
+ this._plc = new Plc.S7.Plc(this._plc.CPU, this._plc.IP, this._plc.Port, this._plc.Rack, this._plc.Slot);
+ this._plc.Open();
+ }
+ catch
+ {
+
+ }
+ }
LogManager.Error(ex);
}
finally
diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorLine.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorLine.cs
deleted file mode 100644
index b6defab..0000000
--- a/src/Khd.Core.Wcs/Wcs/FiveFloorLine.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-//using Khd.Core.Domain.Dto.webapi;
-//using Khd.Core.Domain.Models;
-//using Khd.Core.EntityFramework;
-//using Khd.Core.Wcs.Global;
-//using Masuit.Tools.Logging;
-//using Microsoft.Extensions.DependencyInjection;
-//using Microsoft.Extensions.Hosting;
-//using Z.EntityFramework.Plus;
-
-//namespace Khd.Core.Wcs.Wcs
-//{
-// ///
-// /// 五楼人工分拣输送线
-// ///
-// public class FiveFloorLine
-// {
-// List ScanPoint { get; set; }//点位信息
-// private readonly IHost _host;
-// private readonly Plc.S7.Plc _plc;
-// private readonly BasePlcpoint LineRFID;
-// private readonly BasePlcpoint IsArrive;
-// private readonly BasePlcpoint IsPut;
-// int FloorNo { get; set; }
-// string EquipNo = "";
-// int CTUID = 11;
-// public FiveFloorLine(IHost host, Plc.S7.Plc plc, int floor, string equipNo)
-// {
-// this._host = host;
-// this._plc = plc;
-// FloorNo = floor;
-// EquipNo = equipNo;
-// this.ScanPoint = StaticData.BasePlcpointList.Where(t => t.floorNo == floor).ToList();//加载当前站点所对应的点位
-// this.LineRFID = this.ScanPoint.First(t => t.plcpointNo == "RFID5001");
-// this.IsArrive = this.ScanPoint.First(t => t.plcpointNo.Contains("isarrive"));
-// this.IsPut = this.ScanPoint.First(t => t.plcpointNo == "isput");
-
-// //var lineRFID = this._plc.Read(NodeSettingCarNo.plcpointAddress);
-// try
-// {
-// //默认启动,清理plc的上位机写入点位值
-// this._plc.Write(LineRFID.plcpointAddress, MainCentralControl.QingKongDianWei);
-// }
-// catch (Exception ex)
-// {
-// Console.WriteLine("楼层" + floor + " 初始化数据异常" + ex.Message);
-// LogManager.Error(ex);
-// }
-// }
-// ///
-// /// 启动上件扫描监听
-// ///
-// public void StartPoint()
-// {
-
-// Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
-// FlowPointThread.Start();
-// Console.WriteLine(DateTime.Now+":五楼人工分拣输送线启动成功");
-// LogManager.Info("五楼人工分拣输送线启动成功");
-// }
-
-// public void MonitorInLocatorPoint()
-// {
-// using var scope = _host.Services.CreateScope();
-// using var dbContext = scope.ServiceProvider.GetRequiredService();
-// while (true)
-// {
-// try
-// {
-// dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
-// var rfid = this._plc.Read(LineRFID.plcpointAddress);
-// var isarrive = this._plc.Read(IsArrive.plcpointAddress);
-// //获取条码信息
-// var palletNo = Convert.ToString(rfid);
-// var taskid = 0;
-// WcsToWms wcsToWms = new WcsToWms();
-// continueTaskDto agvtask = new continueTaskDto();
-// //入库:待取料
-// if (rfid != null && isarrive != null)
-// {
-// //正常读到输送线信息 有到位信号,并且有托盘,获取条码信息
-// if (Convert.ToInt32(isarrive) == 1)
-// {
-// var wcsTaskList = dbContext.WcsTask.Where(t => t.taskType == 7).ToList();
-// var cmd = dbContext.WcsCmd.Where(t => t.containerNo == rfid && t.cmdStatus == 14).FirstOrDefault();
-// if (cmd != null)
-// {
-// agvtask.reqCode = cmd.taskId.ToString();
-// //给ctu下发继续任务指令
-// wcsToWms.continueTask(agvtask);
-// }
-// }
-// }
-// //出库:取料完成待放料
-// if (IsPut != null)
-// {
-// var cmdList = dbContext.WcsCmd.Where(t => t.cmdStatus == 15).ToList();
-// if (cmdList == null) return;
-// foreach (var item in cmdList)
-// {
-// if (item != null)
-// {
-// agvtask.reqCode = item.taskId.ToString();
-// //给ctu下发继续任务指令
-// wcsToWms.continueTask(agvtask);
-// }
-// }
-// }
-// }
-// catch (Exception ex)
-// {
-// LogManager.Error(ex);
-// }
-// finally
-// {
-// Thread.Sleep(1000);
-// }
-// }
-// }
-// }
-//}
diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs
index 129ef39..9993765 100644
--- a/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs
+++ b/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs
@@ -95,12 +95,15 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.locationScrapType == "1")
.Where(t => t.instockFlag == "0")
.Where(t => t.outstockFlag == "0")
+ .Where(t=>t.warehouseId==511)
//.Where(t => t.locationStatus == "1")
//.Where(t => string.IsNullOrEmpty(t.containerCode))
.ToList();
if (wmsBaseLocations.Count > 0)
{
- List containerCodes = wmsBaseLocations.Where(t => t.locDeep == 1).Select(t => t.containerCode).ToList();//深库位的托盘
+ List containerCodes = wmsBaseLocations
+ .Where(t => t.locDeep == 1)
+ .Select(t => t.containerCode).ToList();//深库位的托盘
List mesBasePalletInfos = dbContext.MesBasePalletInfo
.Where(t => t.materialId == wcsTask.materialId)
.Where(t => containerCodes.Contains(t.palletInfoCode)).ToList();//深库位的托盘的物料等于当前任务的物料
@@ -138,31 +141,25 @@ namespace Khd.Core.Wcs.Wcs
wcsTask.nextPointNo = AgvEquip.equipNo;
wcsTask.endPointId = wmsBaseLocation.locationId;
wcsTask.endPointNo = wmsBaseLocation.locationCode;
- if (wmsBaseLocation.warehouseId == 531)
- {
- wcsTask.taskType = 37;
- wcsTask.useFlag = 1;
- }
- else if (wmsBaseLocation.warehouseId == 511 && wcsTask.fromFloorNo == 4)
- {
- wcsTask.taskType = 47;//?28?
- wcsTask.useFlag = 0;
- }
- else if (wmsBaseLocation.warehouseId == 511)
+
+ if(wcsTask.fromFloorNo != 1)
{
wcsTask.taskType = 47;
wcsTask.useFlag = 1;
}
else
{
- Console.WriteLine($"{DateTime.Now}:5楼接驳位查找入库类型失败");
- Thread.Sleep(1000);
- continue;
+ wcsTask.taskType = 47;//?28?
+ wcsTask.useFlag = 0;
}
+
wmsBaseLocation.instockFlag = "1";
wmsBaseLocation.locationStatus = "2";
dbContext.Update(wmsBaseLocation);
- dbContext.Update(wcsTask);
+ dbContext.WcsTask.Where(t => t.objid == wcsTask.objid).Delete();
+ wcsTask.objid = StaticData.SnowId.NextId();
+ wcsTask.createTime = DateTime.Now;
+ dbContext.Add(wcsTask);
WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask);
dbContext.Add(wcsTaskLog);
dbContext.SaveChanges();
@@ -178,7 +175,7 @@ namespace Khd.Core.Wcs.Wcs
else if (wcsTask.taskStatus == 6) //出库任务,小车任务是完成状态
{
int? floor = 0;
- var wmsProductOutstock = dbContext.WmsProductOutstock.FirstOrDefault(t => t.saleOrderId == wcsTask.orderId);
+ var wmsProductOutstock = dbContext.WmsProductOutstock.FirstOrDefault(t => t.productOutstockId == wcsTask.orderId);
if (wmsProductOutstock != null)
{
var endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsProductOutstock.endStationCode);
@@ -189,7 +186,7 @@ namespace Khd.Core.Wcs.Wcs
}
else
{
- var wmsRawOutstock = dbContext.WmsRawOutstock.FirstOrDefault(t => t.orderId == wcsTask.orderId);
+ var wmsRawOutstock = dbContext.WmsRawOutstock.FirstOrDefault(t => t.rawOutstockId == wcsTask.orderId);
if (wmsRawOutstock != null)
{
var endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsRawOutstock.endStationCode);
@@ -207,28 +204,21 @@ namespace Khd.Core.Wcs.Wcs
continue;
}
BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.equipType == 2);//提升机
+ dbContext.WcsTask.Where(t => t.objid == wcsTask.objid).Delete();
+ wcsTask.objid = StaticData.SnowId.NextId();
+ wcsTask.serialNo = SystemData.GetSerialNo(dbContext);
wcsTask.nextPointId = nextEquip.objid;
wcsTask.nextPointNo = nextEquip.equipNo;
wcsTask.currPointId = baseEquip.objid;
wcsTask.currPointNo = baseEquip.equipNo;
wcsTask.fromFloorNo = FloorNo;
wcsTask.taskType = 6;//成品出库
- wcsTask.floorNo = floor;//出库到一楼
+ wcsTask.floorNo = floor;//出库楼层
wcsTask.taskStatus = 0;
- wcsTask.updateTime = DateTime.Now;
- dbContext.Update(wcsTask);
- dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid)
- .Update(t => new WcsTaskLog
- {
- nextPointId = nextEquip.objid,
- nextPointNo = nextEquip.equipNo,
- currPointId = baseEquip.objid,
- currPointNo = baseEquip.equipNo,
- fromFloorNo = FloorNo,
- floorNo = floor,
- taskStatus = 0,
- updateTime = DateTime.Now,
- });
+ wcsTask.createTime = DateTime.Now;
+ dbContext.Add(wcsTask);
+ WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask);
+ dbContext.WcsTaskLog.Add(wcsTaskLog);
dbContext.SaveChanges();
}
}
diff --git a/src/Khd.Core.Wcs/Wcs/SystemTimer.cs b/src/Khd.Core.Wcs/Wcs/SystemTimer.cs
index 79b3a28..e78781c 100644
--- a/src/Khd.Core.Wcs/Wcs/SystemTimer.cs
+++ b/src/Khd.Core.Wcs/Wcs/SystemTimer.cs
@@ -5,6 +5,7 @@ using Khd.Core.Plc;
using Khd.Core.Plc.S7;
using Khd.Core.Wcs.Global;
using Masuit.Tools;
+using Masuit.Tools.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
@@ -20,8 +21,9 @@ namespace Khd.Core.Wcs.Wcs
{
private readonly IHost host;
private Plc.S7.Plc Plc30 = StaticData.PlcDic[0];
- private Plc.S7.Plc Plc31 = StaticData.PlcDic[0];
+ private Plc.S7.Plc Plc31 = StaticData.PlcDic[1];
private Plc.S7.Plc Plc220 = StaticData.PlcDic[2];
+
public SystemTimer(IHost host)
{
this.host = host;
@@ -29,13 +31,133 @@ namespace Khd.Core.Wcs.Wcs
public void Start()
{
- Thread messageSynchronousThread = new(MessageSynchronousLogic);
+ var messageSynchronousThread = new Thread(MessageSynchronousLogic)
+ {
+ IsBackground = true
+ };
messageSynchronousThread.Start();
- Thread baseEquipThread = new Thread(BaseEquipLogic);
- baseEquipThread.Start();
+ //var baseEquipThread = new Thread(BaseEquipLogic)
+ //{
+ // IsBackground = true
+ //};
+ //baseEquipThread.Start();
+
+ //var PlcHeartBeat30Thread = new Thread(PlcHeartBeat30Logic)
+ //{
+ // IsBackground = true
+ //};
+ //PlcHeartBeat30Thread.Start();
+
+ //var PlcHeartBeat31Thread = new Thread(PlcHeartBeat31Logic)
+ //{
+ // IsBackground = true
+ //};
+ //PlcHeartBeat31Thread.Start();
+
+ Console.WriteLine($"{DateTime.Now}: SystemTimer started");
}
+ ///
+ /// 定时发送心跳包
+ ///
+ ///
+ private void PlcHeartBeat30Logic(object? obj)
+ {
+ BasePlcpoint HeartBeat30 = StaticData.BasePlcpointList.First(t => t.plcpointNo == "HeartBeat30");
+ int heartBeatCount = 0;
+ while (true)
+ {
+ try
+ {
+ if (heartBeatCount == 0)
+ {
+ heartBeatCount = 1;
+ }
+ else
+ {
+ heartBeatCount = 0;
+ }
+ StaticData.PlcDic[0].WriteToPoint(HeartBeat30.plcpointAddress, heartBeatCount.ToString(), HeartBeat30.plcpointType?.ToString());
+ }
+ catch (Exception ex)
+ {
+ if (ex is PlcException)
+ {
+ try
+ {
+ foreach (var item in StaticData.PlcDic)
+ {
+ if (item.Value.IP == ex.Message)
+ {
+ StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
+ StaticData.PlcDic[item.Key].Open();
+ }
+ }
+ }
+ catch
+ {
+
+ }
+ }
+ LogManager.Error(ex);
+ }
+ Thread.Sleep(1000);
+ }
+ }
+
+ ///
+ /// 定时发送心跳包
+ ///
+ ///
+ private void PlcHeartBeat31Logic(object? obj)
+ {
+ BasePlcpoint HeartBeat31 = StaticData.BasePlcpointList.First(t => t.plcpointNo == "HeartBeat31");
+ int heartBeatCount = 0;
+ while(true)
+ {
+ try
+ {
+ if (heartBeatCount == 0)
+ {
+ heartBeatCount = 1;
+ }
+ else
+ {
+ heartBeatCount = 0;
+ }
+ StaticData.PlcDic[1].WriteToPoint(HeartBeat31.plcpointAddress, heartBeatCount.ToString(), HeartBeat31.plcpointType?.ToString());
+ }
+ catch (Exception ex)
+ {
+ if (ex is PlcException)
+ {
+ try
+ {
+ foreach (var item in StaticData.PlcDic)
+ {
+ if (item.Value.IP == ex.Message)
+ {
+ StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
+ StaticData.PlcDic[item.Key].Open();
+ }
+ }
+ }
+ catch
+ {
+
+ }
+ }
+ LogManager.Error(ex);
+ }
+ Thread.Sleep(1000);
+ }
+ }
+
+ ///
+ /// 定时更新基础设备信息
+ ///
+ ///
private void BaseEquipLogic(object? obj)
{
using var scope = host.Services.CreateScope();
@@ -65,44 +187,56 @@ namespace Khd.Core.Wcs.Wcs
}
}
+ ///
+ /// 定时同步消息
+ ///
+ ///
private void MessageSynchronousLogic(object? obj)
{
- try
- {
- using var scope = host.Services.CreateScope();
- using var dbContext = scope.ServiceProvider.GetRequiredService();
- HositerLogic();
- CtuLineLogic();
- ThirdAgvLogic(dbContext);
- SecondAgvLogic(dbContext);
- FiveAgvLogic(dbContext);
- FiveBearAgvLogic(dbContext);
- CtuCmdLogic(dbContext);
- }
- catch (Exception ex)
+ while (true)
{
try
{
- if (ex is PlcException)
+ using var scope = host.Services.CreateScope();
+ using var dbContext = scope.ServiceProvider.GetRequiredService();
+ dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
+ HositerLogic();
+ CtuLineLogic();
+ ThirdAgvLogic(dbContext);
+ FiveAgvLogic(dbContext);
+ FiveBearAgvLogic(dbContext);
+ CtuCmdLogic(dbContext);
+ //SecondAgvLogic(dbContext);
+ }
+ catch (Exception ex)
+ {
+ try
{
- foreach (var item in StaticData.PlcDic)
+ if (ex is PlcException)
{
- if (item.Value.IP == ex.Message)
+ foreach (var item in StaticData.PlcDic)
{
- StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
- StaticData.PlcDic[item.Key].Open();
+ if (item.Value.IP == ex.Message)
+ {
+ StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
+ StaticData.PlcDic[item.Key].Open();
+ }
}
}
}
- }
- catch
- {
+ catch
+ {
+ }
}
+ Thread.Sleep(5000);
}
- Thread.Sleep(5000);
}
+ ///
+ /// 定时更新三楼AGV信息
+ ///
+ ///
private void ThirdAgvLogic(DefaultDbContext dbContext)
{
var baseEquip = StaticData.BaseEquip.First(t => t.objid == 9);
@@ -127,6 +261,10 @@ namespace Khd.Core.Wcs.Wcs
}
}
+ ///
+ /// 定时更新二楼AGV信息
+ ///
+ ///
private void SecondAgvLogic(DefaultDbContext dbContext)
{
var baseEquip = StaticData.BaseEquip.First(t => t.objid == 8);
@@ -151,6 +289,10 @@ namespace Khd.Core.Wcs.Wcs
}
}
+ ///
+ /// 定时更新五楼AGV信息
+ ///
+ ///
private void FiveAgvLogic(DefaultDbContext dbContext)
{
var baseEquip = StaticData.BaseEquip.First(t => t.objid == 10);
@@ -213,6 +355,10 @@ namespace Khd.Core.Wcs.Wcs
}
}
+ ///
+ /// 定时更新五楼背负式AGV信息
+ ///
+ ///
private void FiveBearAgvLogic(DefaultDbContext dbContext)
{
var baseEquip = StaticData.BaseEquip.First(t => t.objid == 10);
@@ -241,6 +387,10 @@ namespace Khd.Core.Wcs.Wcs
}
}
+ ///
+ /// 定时更新五楼CTU信息
+ ///
+ ///
private void CtuCmdLogic(DefaultDbContext dbContext)
{
var baseEquip = StaticData.BaseEquip.First(t => t.objid == 11);
@@ -292,6 +442,9 @@ namespace Khd.Core.Wcs.Wcs
}
}
+ ///
+ /// 定时更新五楼U型线信息
+ ///
private void CtuLineLogic()
{
var basePlcpoints = StaticData.BasePlcpointList.ToList();
diff --git a/src/Khd.Core.Wcs/appsettings.json b/src/Khd.Core.Wcs/appsettings.json
index 1b7381e..c273bc0 100644
--- a/src/Khd.Core.Wcs/appsettings.json
+++ b/src/Khd.Core.Wcs/appsettings.json
@@ -6,14 +6,14 @@
//"DefaultConnection": "server=175.27.215.92;port=3306;database=hwjy-cloud;uid=kehaida;pwd=khd2024;charset='utf8';persistsecurityinfo=True;SslMode=None;Allow User Variables=True"
},
"PlcConfigs": [
- {
- "IP": "192.168.2.30",
- "Port": 102, //102是默认端口
- "CpuType": 40,
- "Rack": 0,
- "Slot": 1,
- "Code": 0
- },
+ //{
+ // "IP": "192.168.2.30",
+ // "Port": 102, //102是默认端口
+ // "CpuType": 40,
+ // "Rack": 0,
+ // "Slot": 1,
+ // "Code": 0
+ //},
{
"IP": "192.168.2.31",
"Port": 102, //102是默认端口
@@ -22,14 +22,14 @@
"Slot": 1,
"Code": 1
},
- {
- "IP": "192.168.2.220",
- "Port": 102, //102是默认端口
- "CpuType": 40,
- "Rack": 0,
- "Slot": 1,
- "Code": 2
- }
+ //{
+ // "IP": "192.168.2.220",
+ // "Port": 102, //102是默认端口
+ // "CpuType": 40,
+ // "Rack": 0,
+ // "Slot": 1,
+ // "Code": 2
+ //}
],
"PLCSetting": {
"Mode": "0",
diff --git a/src/Khd.Core.Wpf/App.xaml.cs b/src/Khd.Core.Wpf/App.xaml.cs
index 518b4b5..0768e79 100644
--- a/src/Khd.Core.Wpf/App.xaml.cs
+++ b/src/Khd.Core.Wpf/App.xaml.cs
@@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
@@ -14,6 +15,7 @@ namespace Khd.Core.Wpf
{
public App()
{
+
//UI线程未捕获异常处理事件(UI主线程)
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
diff --git a/src/Khd.Core.Wpf/Form/FormBoardT.xaml b/src/Khd.Core.Wpf/Form/FormBoardT.xaml
index 0da15dc..0d5c79f 100644
--- a/src/Khd.Core.Wpf/Form/FormBoardT.xaml
+++ b/src/Khd.Core.Wpf/Form/FormBoardT.xaml
@@ -441,7 +441,7 @@
-