刘磊
2025-06-25 2de09bec5cc05bf875543fa8956167ca7db73021
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using AngleSharp.Io;
using Mapster;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.AGVTask;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEA_Model.Models;
using WIDESEA_StorageBasicRepository;
using WIDESEA_StorageTaskRepository;
 
namespace WIDESEA_StoragIntegrationServices
{
    public partial class ToAGVService
    {
        /// <summary>
        /// AGV回调接口
        /// </summary>
        /// <param name="taskRespon"></param>
        /// <returns></returns>
        public AGVResponBase agvCallback(object taskRespon)
        {
           
            AGVResponBase response = null;
 
            ContainerTask task = new ContainerTask();
            try
            {
                task = JsonConvert.DeserializeObject<ContainerTask>(taskRespon.ToString());
                
                if (task == null)
                {
                    LogFactory.GetLog("AGV任务回调").Info(true, $"回调失败,未能读取到agv调取参数");
                }
 
 
                if (task.method.ToString() == "outbin2")   //AGV取料完成
                {
                    Dt_CZInfo_mes CZInfotlist = _task_CZInfoRepository.QueryFirst(x => x.CurrentStatue == "4");
                    if (CZInfotlist != null)
                    {
                        CZInfotlist.CurrentStatue = "5";
                        _task_CZInfoRepository.UpdateData(CZInfotlist);
                    }
                    
                    WCS_Set("3022");  //不管是否有写入成功,都完成agv任务
                    return response = new AGVResponBase
                    {
                        code = "0",
                        message = "成功",
                        reqCode = task.reqCode
                    };
 
                }
 
                if (task.method.ToString() == "end") //AGV任务结束反馈
                {
                    //并进行修改任务为完成
                    Dt_CZInfo_mes CZInfotlist = _task_CZInfoRepository.QueryFirst(x => x.CurrentStatue == "5");
 
                    //调取输送线接口,反馈输送线完成信号
                    WCS_Set(CZInfotlist.AGVaddres);
 
                    
                    if(CZInfotlist != null)
                    {
                        CZInfotlist.CurrentStatue = "6";
                        _task_CZInfoRepository.UpdateData(CZInfotlist);
 
                        Dt_CZInfo_mes_hty stockInfo_Hty = CZInfotlist.Adapt<Dt_CZInfo_mes_hty>();
                        _CZInfo_Mes_HtyRepository.AddData(stockInfo_Hty);
                        _task_CZInfoRepository.DeleteData(CZInfotlist);
                    }
 
                   
 
                    //回调
                    return response = new AGVResponBase
                    {
                        code = "0",
                        message = "成功",
                        reqCode = task.reqCode
                    };
                }
 
                LogFactory.GetLog("AGV任务回调").Info(true, $"回调成功");
                return response;
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("AGV任务回调").Info(true, $"回调失败,错误信息:{ex.Message}");
                return response = new AGVResponBase
                 {
                     code = "1",
                     message = $"失败,原因:{ex.Message}",
                     reqCode = task.reqCode
                 };
            }
        }
 
        public bool WCS_Set(string CutAddress)
        {
            try
            {
                //调取wcs接口,写入输送线信号  SetPlcResponState
                var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
                var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.SetPlcResponState)?.ConfigValue;
                if (ReceiveByWMSTask == null || ipAddress == null)
                {
                    throw new Exception("WMS IP 未配置");
                }
                var wmsIpAddrss = ipAddress + ReceiveByWMSTask;
 
                var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(CutAddress));   //http://localhost:9291/api/Task/ReceiveTask,
 
               if (respon != null)
                {
                    WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString());
                    if (respone.Status)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
 
            }
            catch (Exception ex)
            {
                return false;
                throw;
            }
        }
 
    }
}