using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; using Khd.Core.Plc.S7; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs { /// /// 四楼接驳位 /// public class FourthFloorPoint { private readonly int Floor; private readonly Plc.S7.Plc _plc; private readonly IHost host; private readonly BasePlcpoint LineRFID; private readonly BasePlcpoint LineSignal; private readonly BasePlcpoint WcsRun; public FourthFloorPoint(int floor, Plc.S7.Plc plc, IHost host) { Floor = floor; _plc = plc; this.host = host; this.LineRFID = StaticData.BasePlcpointList.First(t => t.floorNo == 4 && t.plcpointNo.Contains("RFID")); this.LineSignal = StaticData.BasePlcpointList.First(t => t.floorNo == 4 && t.plcpointNo.Contains("signal")); this.WcsRun = StaticData.BasePlcpointList.First(t => t.floorNo == 4 && t.plcpointNo.Contains("wcsrun")); } public void StartPoint() { Thread MonitorInLocatorPointThread=new Thread(MonitorInLocatorPoint); MonitorInLocatorPointThread.Start(); } private void MonitorInLocatorPoint() { List Itpyes = new() { 1, 3, 5, 7 }; using var scope = host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); while (true) { try { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); var RFID004Value = this._plc.Read(this.LineRFID.plcpointAddress); //一楼RFID 读 var linesignal04Value = this._plc.Read(this.LineSignal.plcpointAddress); //到位信号 读 var wcsrun04Value = this._plc.Read(this.WcsRun.plcpointAddress); //去向 写 //正常读到plc值 if (linesignal04Value != null && RFID004Value != null) { //正常托盘到位 if (Convert.ToInt32(linesignal04Value) == 1) { //判断task表里没有该rfid的未完成的入库信息,未下发去向 var task = dbContext.WcsTask.Where(t => t.containerNo == RFID004Value.ToString() && t.taskStatus < 1).FirstOrDefault(); if (task == null) { //入库 //根据托盘号获取物料码 var material = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID004Value.ToString()).FirstOrDefault(); if (material != null) { var warehouseId = dbContext.WmsWarehouseMaterial.Where(t => t.storageType == "1" && t.storageId == material.materialId).FirstOrDefault()?.warehouseId; if (warehouseId != null) { var TargetFloor = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == warehouseId).FirstOrDefault(); if (TargetFloor != null) { //插入task表 var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "I" && t.dicField == TargetFloor.warehouseInstockType).FirstOrDefault(); if (dic != null) { var newTask = new WcsTask() { objid = StaticData.SnowId.NextId(), serialNo = 1235, equipmentNo = "F04", taskType = Convert.ToInt32(dic.dicValue), taskStatus = 0, containerNo = RFID004Value.ToString(), materialNo = material.materialCode, materialId = material.materialId, qty = Convert.ToInt32(material.bindAmount), startPointId = 4, startPointNo = "F04", currPointId = 4, currPointNo = "F04", nextPointId = 6, nextPointNo = "T01", endPointId = warehouseId, fromFloorNo = 4, floorNo = TargetFloor.warehouseFloor, useFlag = 1, createBy = "四楼接驳位", createTime = DateTime.Now, remark = "四楼创建入库任务" }; dbContext.Add(newTask); } } } } } else if (Itpyes.Contains(task.taskType)) { if (task.nextPointId != 6) { task.currPointId = 4; task.currPointNo = "F04"; task.nextPointId = 6; task.nextPointNo = "T01"; task.taskStatus = 0; task.updateBy = "四楼接驳位线程"; task.updateTime = DateTime.Now; task.remark = "四楼创建入库任务"; dbContext.WcsTask.Update(task); dbContext.SaveChanges(); } } //出库 else { } } } } catch (Exception ex) { LogManager.Error(ex); } Thread.Sleep(1000); } } } }