1
huanghongfeng
2025-06-25 b1c2dd1869a51b8f0e4acb9ddeb148f796db147f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using Masuit.Tools;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using WIDESEA_Comm;
using WIDESEA_Comm.WCSInterface.Requst;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_Model.Models;
using WIDESEA_StorageTaskRepository;
 
 
namespace WIDESEA_StoragIntegrationServices
{
    public partial class ToAGVService
    {
        /// <summary>
        /// 下发AGV任务 --待测试完善
        /// </summary>
        /// <param name="jsondata"></param>
        /// <returns></returns>
        public WebResponseContent genAgvSchedulingTask(RequestTaskDto input)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (input.RequestType == "999")
                {
                    int CZInfotli = _task_CZInfoRepository.QueryData(x => x.CurrentStatue == "3").Count();
                    if (CZInfotli == 0)
                    {
                        return content.Error($"没有自动取轴任务,无自动任务");
                    }
                }
 
                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 = $"{DateTime.Now:yyyyMMddHHmmss}",
                    clientCode = "WMS",
                    taskTyp = "BY",
                    ctnrTyp = "1",
                    //data = taskinfo.task_barcode,
                    positionCodePath = new List<position>
                       {
                            new position { positionCode = "Q", type = "00" },
                            new position { positionCode = agvtarget, type = "00" },         //地址待更改为   F1  左边   F2 右边
                       },
                };
 
                CZInfot.AGVaddres = input.Position;
 
                //编写调取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任务").Error(true, ex.Message);
                return content.Error($"下发任务接口异常:{ex.Message}");
            }
        }
    }
}