From ce40df5daffae0d17b4e9fa7cb6d677afaa4d66f Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 17 十月 2025 11:20:30 +0800
Subject: [PATCH] 更新最新程序,ERP代码,MES代码等
---
项目代码/WCS/WCSServices/WIDESEAWCS_Tasks/成品仓/AGV_CPExtend.cs | 322 +++++++++++++++++++----------------------------------
1 files changed, 116 insertions(+), 206 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/AGV_CPExtend.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/AGV_CPExtend.cs"
index 8909902..ff74879 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/AGV_CPExtend.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/AGV_CPExtend.cs"
@@ -1,4 +1,5 @@
-锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+锘縰sing Microsoft.IdentityModel.Tokens;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -21,7 +22,7 @@
{
try
{
- var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()|| x.TaskState == TaskStatusEnum.New.ObjToInt()) && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode) && x.TaskType!=999).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
+ var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()|| x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.DeviceCode=="AGV").ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
if (newTasks.Count>0)
{
@@ -29,53 +30,127 @@
{
try
{
- if (task.TaskType == TaskTypeEnum.OutProduct.ObjToInt())
- task.CurrentAddress = GetAGVAddress(task.CurrentAddress);
- else
- task.NextAddress = GetAGVAddress(task.NextAddress);
- AgvTaskDTO taskDTO = new AgvTaskDTO()
+ Guid guid = Guid.NewGuid();
+ AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO()
{
- TaskCode = task.AgvTaskNum,
- ReqCode = DateTime.Now.ToString("yyyyMMdd") + task.AgvTaskNum,
- TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "CPC" : "CPR",
- ctnrCode = task.PalletCode,
- PositionCodePath = new List<CodePath>()
- {
- new CodePath()
- {
- type = "05",
- positionCode = task.CurrentAddress
- },
- new CodePath()
- {
- type = "05",
- positionCode = task.NextAddress
- }
- }
+ SysToken=guid.ToString().Replace("-",""),
+ ReceiveTaskID=task.TaskNum.ToString(),
+ MapCode="01",
+ Variables=new List<PointDetail>()
};
- if (taskDTO.TaskTyp== "CPC")
+ Dt_StationManger stationMangerStart = _stationMangerRepository.QueryFirst(x=>x.StationCode==task.CurrentAddress);
+ Dt_StationManger stationMangerEnd = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress);
+ //娣诲姞浠诲姟璺緞鍙婇珮搴�
+ if (stationMangerStart !=null && stationMangerEnd != null)
{
- taskDTO.Priority = task.Grade.ToString();
+ PointDetail pointDetail1 = new PointDetail()
+ {
+ Code= "GoodPoint",
+ Value=stationMangerStart.AGVStationCode
+ };
+ //鍒ゆ柇鏄惁鏈夊墠缃偣
+ if (!string.IsNullOrEmpty(stationMangerStart.AGVFrontCode))
+ {
+ PointDetail pointDetail2 = new PointDetail()
+ {
+ Code = "CostPoint",
+ Value = stationMangerStart.AGVFrontCode
+ };
+ agvTaskSend.Variables.Add(pointDetail2);
+ }
+ PointDetail pointDetail3 = new PointDetail()
+ {
+ Code = "PointB",
+ Value = stationMangerEnd.AGVStationCode
+ };
+ //鍒ゆ柇鏄惁鏈夊墠缃偣
+ if (!string.IsNullOrEmpty(stationMangerEnd.AGVFrontCode))
+ {
+ PointDetail pointDetail4 = new PointDetail()
+ {
+ Code = "PointA",
+ Value = stationMangerEnd.AGVFrontCode
+ };
+ agvTaskSend.Variables.Add(pointDetail4);
+ }
+ PointDetail pointDetail5 = new PointDetail()
+ {
+ Code = "QUQTH",
+ Value = stationMangerStart.AGVStationHeight.ToString()
+ };
+ PointDetail pointDetail6 = new PointDetail()
+ {
+ Code = "FHMH",
+ Value = stationMangerEnd.AGVStationHeight.ToString()
+ };
+ agvTaskSend.Variables.Add(pointDetail1);
+ agvTaskSend.Variables.Add(pointDetail3);
+ agvTaskSend.Variables.Add(pointDetail5);
+ agvTaskSend.Variables.Add(pointDetail6);
}
- if (task.GroupId.IsNotEmptyOrNull())
+ else
{
- taskDTO.GroupId=task.GroupId;
+ throw new Exception("鏈壘鍒癆GV绔欑偣");
}
+ //鍙栨斁浠诲姟妯$増
+ if (stationMangerStart.StationCode.Contains("PNT") && !stationMangerEnd.StationCode.Contains("PNT"))//璇锋眰鏀�
+ {
+ agvTaskSend.TaskCode = "DUIGAO1";
+ if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//娼滀紡椤跺崌杞�
+ {
+ agvTaskSend.TaskCode = "DUOLUN1";
+ }
+ }
+ else if (!stationMangerStart.StationCode.Contains("PNT") && stationMangerEnd.StationCode.Contains("PNT"))//璇锋眰鍙�
+ {
+ agvTaskSend.TaskCode = "DUIGAO2";
+ if (stationMangerStart.StationType==998 || stationMangerEnd.StationType == 998)//娼滀紡椤跺崌杞�
+ {
+ agvTaskSend.TaskCode = "DUOLUN2";
+ }
+ }
+ else if (!stationMangerStart.StationCode.Contains("PNT") && !stationMangerEnd.StationCode.Contains("PNT"))//璇锋眰鍙栨斁
+ {
+ agvTaskSend.TaskCode = "DUIGAO3";
+ if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//娼滀紡椤跺崌杞�
+ {
+ agvTaskSend.TaskCode = "DUOLUN3";
+ }
+ }
+ else if (stationMangerStart.StationCode.Contains("PNT") && stationMangerEnd.StationCode.Contains("PNT"))//鏃犺姹�
+ {
+ agvTaskSend.TaskCode = "DUIGAO4";
+ if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//娼滀紡椤跺崌杞�
+ {
+ agvTaskSend.TaskCode = "DUOLUN4";
+ }
+ }
+ if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//娼滀紡椤跺崌杞�
+ {
+ agvTaskSend.Variables.FirstOrDefault(x => x.Code == "FHMH").Value = "0";
+ agvTaskSend.Variables.FirstOrDefault(x => x.Code == "GoodPoint").Value = "";
+ //涓嬪彂浠诲姟AGV浠诲姟闆嗙兢
+ agvTaskSend.AgvGroupCode = "QianF";
+ PointDetail pointDetail2 = new PointDetail()
+ {
+ Code = "CostPoint",
+ Value = stationMangerStart.AGVStationCode
+ };
+ agvTaskSend.Variables.Add(pointDetail2);
+ }
+ if (task.TaskType==TaskTypeEnum.OutCarton.ObjToInt())
+ {
+ agvTaskSend.AgvGroupCode = "GAOc";
+ }
+ //寤舵椂
+ Thread.Sleep(500);
//鍙戦�丄GV浠诲姟
- WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask);
+ WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask);
if (!content.Status)
throw new Exception(content.Message);
- if (taskDTO.TaskTyp == "CPC")
- {
- task.Dispatchertime = DateTime.Now;
- _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
- }
- else
- {
- task.Dispatchertime = DateTime.Now;
- _taskService.UpdateTask(task, TaskStatusEnum.AGV_Takeing);
- }
- Thread.Sleep(500);
+ task.Dispatchertime = DateTime.Now;
+ _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
+ Thread.Sleep(200);
}
catch (Exception ex)
{
@@ -83,182 +158,17 @@
task.ExceptionMessage = ex.Message;
}
}
+ //鏇存柊浠诲姟
if (newTasks.Count > 0)
{
_taskService.UpdateData(newTasks);
}
}
- var newTasksLocations = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.New.ObjToInt() && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode) && x.Remark == "娴嬭瘯绌烘").ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
- if (newTasksLocations.Count>0)
- {
- foreach (var task in newTasksLocations)
- {
- try
- {
- string CurrentAddress = GetAGVAddress(task.CurrentAddress);
- string NextAddress = GetAGVAddress(task.NextAddress);
- AgvTaskDTO taskDTO = new AgvTaskDTO()
- {
- TaskCode = task.AgvTaskNum,
- ReqCode = DateTime.Now.ToString("yyyyMMdd") + task.AgvTaskNum,
- TaskTyp = "CP",
- ctnrCode = task.PalletCode,
- PositionCodePath = new List<CodePath>()
- {
- new CodePath()
- {
- type="05",
- positionCode=CurrentAddress
- },
- new CodePath()
- {
- type="05",
- positionCode=NextAddress
- }
- },
- };
- //鍙戦�丄GV浠诲姟
- WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask);
- if (!content.Status)
- throw new Exception(content.Message);
- task.TaskState = TaskStatusEnum.AGV_Takeing.ObjToInt();
- task.CurrentAddress = CurrentAddress;
- task.NextAddress = NextAddress;
- _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
- }
- catch (Exception ex)
- {
- task.TaskState = TaskStatusEnum.Exception.ObjToInt();
- task.ExceptionMessage = ex.Message;
- }
- }
- }
}
catch (Exception ex)
{
WriteError(nameof(AGV_CPJob), ex.Message, ex);
}
- }
- /// <summary>
- /// AGV鍙栨斁璐у洖璋�
- /// </summary>
- public void ContinueAGVTask()
- {
- try
- {
- //鑾峰彇鏄惁鏈夊畨鍏ㄧ敵璇蜂腑鐨勪换鍔�
- var continueTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt()) && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
- foreach (var continueTask in continueTasks)
- {
- //鍙栬揣鍥炶皟
- if (continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
- {
- Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == continueTask.CurrentAddress || x.StationCode == continueTask.CurrentAddress);
- if (stationManger == null)
- {
- continue;
- }
- IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
- if (device == null)
- {
- continue;
- }
- OtherDevice otherDevice = (OtherDevice)device;
- short canTake = otherDevice.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanTake, stationManger.StationCode);
- if (canTake != 1)
- {
- continue;
- }
- }
- else//鏀捐揣鍥炶皟
- {
- Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == continueTask.NextAddress);
- if (stationManger == null)
- {
- continue;
- }
- IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
- if (device == null)
- {
- continue;
- }
- OtherDevice otherDevice = (OtherDevice)device;
- short canPut = otherDevice.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanPut, stationManger.StationCode);
- if (canPut != 1)
- {
- continue;
- }
- }
- //鑾峰彇璋冨叆鍙傛暟
- AGVBoxApplyPassDTO boxApplyPassDTO = new AGVBoxApplyPassDTO()
- {
- ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
- ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- TaskCode = continueTask.AgvTaskNum
- };
- if (continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
- {
- boxApplyPassDTO.Type = "1";
- }
- else
- {
- boxApplyPassDTO.Type = "2";
- }
- //璇锋眰鏂欑鍥炶皟鎺ュ彛
- WebResponseContent content = _taskService.AgvBoxApplyPass(boxApplyPassDTO);
- if (content.Status && continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && boxApplyPassDTO.TaskCode == continueTask.AgvTaskNum)
- {
- _taskService.UpdateTask(continueTask, TaskStatusEnum.AGV_Executing);
- }
- else if (content.Status && continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && boxApplyPassDTO.TaskCode== continueTask.AgvTaskNum)
- {
- _taskService.UpdateTask(continueTask, TaskStatusEnum.AGV_Puting);
- }
- else
- {
- continueTask.ExceptionMessage = content.Message;
- _taskService.UpdateTask(continueTask, TaskStatusEnum.Exception);
- }
- }
-
- }
- catch (Exception ex)
- {
- WriteError(nameof(AGV_CPJob), ex.Message, ex);
- }
- }
- /// <summary>
- /// 鑾峰彇AGV鍦板潃
- /// </summary>
- /// <param name="Address"></param>
- /// <returns></returns>
- public static string GetAGVAddress(string Address)
- {
- string[] targetCodes = Address.Split("-");
- if (targetCodes.Length == 5)
- {
- var Row = Convert.ToInt16(targetCodes[1]);
- var Column = Convert.ToInt16(targetCodes[2]);
- var Layer = Convert.ToInt16(targetCodes[3]);
- var a = Row switch
- {
- 1 => "A",
- 2 => "B",
- 3 => "C",
- 4 => "D",
- 5 => "E",
- _ => throw new Exception($"鏈畾涔夌殑鎺�,鍦板潃:銆恵Address}銆�"),
- };
- var b = Layer > 9 ? "" + Layer : "0" + Layer;
- var c = Column > 9 ? "" + Column : "0" + Column;
- if (Column == 10) c = "010";
- Address = a + b + c;
- }
- else
- {
- throw new Exception($"鍦板潃鏈夎,鍦板潃:銆恵Address}銆�");
- }
- return Address;
}
}
}
--
Gitblit v1.9.3