|
|
|
|
|
using AngleSharp.Css.Dom;
|
|
|
|
|
|
using Castle.Core.Logging;
|
|
|
|
|
|
using Khd.Core.Domain.Dto.webapi;
|
|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Khd.Core.Library.Mapper;
|
|
|
|
|
|
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;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 五楼CTU调度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FiveFloorCTU
|
|
|
|
|
|
{
|
|
|
|
|
|
List<BasePlcpoint> ScanPoint { get; set; }//点位信息
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
private Plc.S7.Plc _plc;
|
|
|
|
|
|
private readonly BasePlcpoint LineRFID;
|
|
|
|
|
|
private readonly BasePlcpoint isarrive;
|
|
|
|
|
|
private readonly BasePlcpoint isput;
|
|
|
|
|
|
private bool isWait = false;
|
|
|
|
|
|
private bool isSendWait = false;
|
|
|
|
|
|
int FloorNo { get; set; }
|
|
|
|
|
|
string EquipNo = "";
|
|
|
|
|
|
int CTUID = 11;
|
|
|
|
|
|
public FiveFloorCTU(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.Contains("RFID5001"));
|
|
|
|
|
|
this.isarrive = this.ScanPoint.First(t => t.plcpointNo.Contains("isarrive"));
|
|
|
|
|
|
this.isput = this.ScanPoint.First(t => t.plcpointNo.Contains("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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动上件扫描监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void StartPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
|
|
|
|
|
|
FlowPointThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
Thread FlowCTUInWareThread = new Thread(MonitorInWare);
|
|
|
|
|
|
FlowCTUInWareThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
Thread CtuWaitThread = new Thread(CtuWaitLogic);
|
|
|
|
|
|
CtuWaitThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":五楼CTU上件扫描监听启动");
|
|
|
|
|
|
LogManager.Info("五楼CTU上件扫描监听启动");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MonitorInWare(object? obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
rfid = rfid[rfid.IndexOf('C')..];
|
|
|
|
|
|
WcsTask? task = dbContext.WcsTask.FirstOrDefault(t => t.containerNo == rfid);
|
|
|
|
|
|
if (task == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//根据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,
|
|
|
|
|
|
nextPointNo = ctuEquip.equipNo,
|
|
|
|
|
|
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";
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
//WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
//dbContext.WcsTaskLog.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 预执行任务下发
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
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<ReponseMessage>(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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 监控上件扫描点位
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void MonitorInLocatorPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<int?> taskType = new() { 1, 3, 5, 7 };
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == CTUID);
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
var taskList = dbContext.WcsTask.Where(t => t.nextPointId == CTUID).OrderBy(t => t.createTime).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)//出库任务
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == item.endPointId);
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId);
|
|
|
|
|
|
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",
|
|
|
|
|
|
currPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = wmsBaseLocation.agvPositionCode,
|
|
|
|
|
|
nextPointId = endEquip.objid,
|
|
|
|
|
|
nextPointNo = endEquip.agvPositionCode,
|
|
|
|
|
|
taskCode = null
|
|
|
|
|
|
};
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.currPointNo,
|
|
|
|
|
|
type = "05"
|
|
|
|
|
|
},
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.nextPointNo,
|
|
|
|
|
|
type = "00"
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
ctnrTyp = "1",
|
|
|
|
|
|
taskTyp = "F504"
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
|
|
|
|
|
|
var reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.code == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
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<WcsCmdLog>(wcsCmd);
|
|
|
|
|
|
dbContext.Add(wcsCmdLog);
|
|
|
|
|
|
WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
|
|
|
|
|
|
wcsOutstockLock.qty = wcsOutstockLock.qty + 1;
|
|
|
|
|
|
dbContext.Update(wcsOutstockLock);
|
|
|
|
|
|
dbContext.WcsCmd.Add(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("CTU下发出库任务失败:" + reponseMessage?.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
var agvTask = new
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.currPointNo,
|
|
|
|
|
|
type = "05"
|
|
|
|
|
|
},
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.nextPointNo,
|
|
|
|
|
|
type = "05"
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
ctnrTyp = "1",
|
|
|
|
|
|
taskTyp = "F503"
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
|
|
|
|
|
|
var reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.code == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsCmd.taskCode = reponseMessage.data;
|
|
|
|
|
|
wcsCmd.cmdStatus = 1;
|
|
|
|
|
|
item.taskStatus = 1;
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 });
|
|
|
|
|
|
WcsCmdLog wcsCmdLog = CoreMapper.Map<WcsCmdLog>(wcsCmd);
|
|
|
|
|
|
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当前任务数量很多,取消预执行任务
|
|
|
|
|
|
{
|
|
|
|
|
|
ExecuteInTask(baseEquip);
|
|
|
|
|
|
wcsOutstockLock.qty = 0;
|
|
|
|
|
|
wcsOutstockLock.boxStatus = 0;
|
|
|
|
|
|
dbContext.Update(wcsOutstockLock);
|
|
|
|
|
|
isWait = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("CTU下发入库任务失败:" + reponseMessage?.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.taskId == item.objid);
|
|
|
|
|
|
if (wcsCmd != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wcsCmd.cmdStatus == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.taskType == 30)
|
|
|
|
|
|
{
|
|
|
|
|
|
var canOut = this._plc.Read(isput.plcpointAddress);
|
|
|
|
|
|
if (canOut != null && Convert.ToInt64(canOut) == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
var agvTask = new
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
taskCode = wcsCmd.taskCode,
|
|
|
|
|
|
type = 2
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/boxApplyPass", message);
|
|
|
|
|
|
ReponseMessage? reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.code == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 });
|
|
|
|
|
|
dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 4 });
|
|
|
|
|
|
dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 });
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 });
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("CTU第一次下发继续任务失败:" + reponseMessage?.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.taskType == 29)
|
|
|
|
|
|
{
|
|
|
|
|
|
var agvTask = new
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
taskCode = wcsCmd.taskCode,
|
|
|
|
|
|
type = 1
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/boxApplyPass", message);
|
|
|
|
|
|
ReponseMessage? reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.code == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 });
|
|
|
|
|
|
dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 4 });
|
|
|
|
|
|
dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 });
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 });
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("CTU第二次下发继续任务失败:" + reponseMessage?.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (wcsCmd.cmdStatus == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.taskType == 30)//出库任务
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation
|
|
|
|
|
|
.First(t => t.locationId == item.startPointId && t.warehouseFloor == 5);
|
|
|
|
|
|
wmsBaseLocation.outstockFlag = "0";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "1";
|
|
|
|
|
|
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.WcsTaskLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsTaskLog() { taskStatus = 6 });
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.taskType == 29)//入库任务
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation
|
|
|
|
|
|
.First(t => t.locationId == item.endPointId && t.warehouseFloor == 5);
|
|
|
|
|
|
wmsBaseLocation.instockFlag = "0";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "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 });
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 通知CTU取消预执行任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="baseEquip"></param>
|
|
|
|
|
|
/// <param name="wcsCmd"></param>
|
|
|
|
|
|
private void ExecuteInTask(BaseEquip baseEquip)
|
|
|
|
|
|
{
|
|
|
|
|
|
//while (isWait)
|
|
|
|
|
|
{
|
|
|
|
|
|
var executeTask = new
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
positionCode = "CTU_IN",
|
|
|
|
|
|
nextTask = -1
|
|
|
|
|
|
};
|
|
|
|
|
|
string executeMessage = JsonConvert.SerializeObject(executeTask);
|
|
|
|
|
|
string executeResult = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genPreScheduleTask", executeMessage);
|
|
|
|
|
|
var executeReponse = JsonConvert.DeserializeObject<ReponseMessage>(executeResult);
|
|
|
|
|
|
if (executeReponse != null && executeReponse.code == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("下发CTU执行入库任务成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("下发CTU执行入库任务失败");
|
|
|
|
|
|
Console.WriteLine($"{DateTime.Now}:下发CTU执行入库任务失败" + executeReponse?.message);
|
|
|
|
|
|
ExecuteInTask(baseEquip);
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|