刘磊
2025-06-25 2de09bec5cc05bf875543fa8956167ca7db73021
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/AGV/Partial/genAgvSchedulingTask.cs
@@ -1,20 +1,16 @@
using MailKit;
using Mapster;
using Masuit.Tools;
using Masuit.Tools.Security;
using Masuit.Tools;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using WIDESEA_Comm;
using WIDESEA_Comm.WCSInterface.Requst;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_IStoragIntegrationServices;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_Model.Models;
using WIDESEA_StorageTaskRepository;
namespace WIDESEA_StoragIntegrationServices
{
@@ -25,40 +21,93 @@
        /// </summary>
        /// <param name="jsondata"></param>
        /// <returns></returns>
        public WebResponseContent genAgvSchedulingTask(Dt_Task taskinfo)
        public WebResponseContent genAgvSchedulingTask(RequestTaskDto input)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (string.IsNullOrEmpty(input.Position)) { return content.Error($"agv任务下发申请目标地址为空!!!请检查"); }
                //查找当前在车轴线末端需要agv搬运的车轴
                List<Dt_CZInfo_mes> CZInfotlist = _task_CZInfoRepository.QueryData(x => x.CurrentStatue == "3" || x.CurrentStatue == "4" || x.CurrentStatue == "5" || x.CurrentStatue == "13");
                if (CZInfotlist.Count >= 2) { return content.Error($"已有agv任务正在进行中,下发失败!!!"); }
                Dt_CZInfo_mes CZInfot = CZInfotlist.FirstOrDefault(x => x.CurrentStatue == "3" || x.CurrentStatue == "13");
                if (CZInfot == null) { return content.Error($"未找到现有输送线完成的车轴信息"); }
                CZInfot.CurrentStatue = "4";
                //查找车轴对应的车轮信息
                List<Dt_Task> tasks=_taskRepository.QueryData(x => x.task_CZInfo == CZInfot.CZH).ToList();
                if (tasks.Count > 0)
                {
                    foreach (var task in tasks)
                    {
                        task.Towhereabouts = input.Position;
                    }
                }
                string agvtarget = "F1";
                if (input.Position == "2033")
                {
                    agvtarget = "F2";
                }
                //agv参数调取
                genAgvSchedulingTask schedulingTask = new genAgvSchedulingTask
                {
                    reqCode = Guid.NewGuid().ToString().Replace("-", ""),
                    clientCode = "WMS",
                    //taskTyp = tasktype,
                    ctnrTyp = "2",
                    taskTyp = "BY",
                    ctnrTyp = "1",
                    //data = taskinfo.task_barcode,
                    positionCodePath = new List<position>
                       {
                            new position { positionCode = taskinfo.SourceAddress, type = "05" },
                            new position { positionCode = taskinfo.TargetAddress, type = "05" },
                            new position { positionCode = "Q", type = "00" },
                            new position { positionCode = agvtarget, type = "00" },         //地址待更改为   F1  å·¦è¾¹   F2 å³è¾¹
                       },
                    priority = "1",   //优先级
                    agvCode = "",//agvcode,
                    //taskCode = taskinfo.task_id.ToString(),
                };
                CZInfot.AGVaddres = input.Position;
                LogFactory.GetLog("下发AGV任务").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("下发AGV任务").Info(true, taskinfo.ToJsonString());
                //编写调取agv接口
                string ipaddress = AGV_Interface;
                var requestBindInfo = schedulingTask.ToDictionary();
                var respon = HttpHelper.Post(ipaddress, JsonConvert.SerializeObject(schedulingTask));
                var responBase = JsonConvert.DeserializeObject<AGVResponBase>(respon);
                if (responBase.code == "0")
                {
                    _task_CZInfoRepository.UpdateData(CZInfot);
                    if (tasks.Count > 0)
                    {
                        _taskRepository.UpdateData(tasks);
                    }
                    LogFactory.GetLog("下发AGV任务").Info(true, $"调取agv任务成功,修改了车轴条码:{CZInfot.CZTM}的状态改至:{CZInfot.CurrentStatue}");
                    content.OK($"agv任务下发成功.");
                return content;
                }
                else
                {
                    LogFactory.GetLog("下发AGV任务").Error(true, $"调取agv任务失败,返回信息:{responBase.message}");
                    return content.Error($"请求异常:{responBase.message}");
                }
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("下发AGV任务").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("下发AGV任务").Info(true, ex.Message);
                LogFactory.GetLog("下发AGV任务").Error(true, ex.Message);
                return content.Error($"请求异常:{ex.Message}");
            }
        }