wangxinhui
2026-03-26 ad05ef2341fe19a4220f7ada1987636f9ec4a1a9
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using HslCommunication.WebSocket;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Text;
using WIDESEA_External.Model;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseController;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Tasks.DBNames;
 
namespace WIDESEAWCS_WCSServer.Controllers.Task
{
    [Route("api/Task")]
    [ApiController]
    public class TaskController : ApiBaseController<ITaskService, Dt_Task>
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IRouterExtension _routerExtension;
        private readonly IStationMangerRepository _stationMangerRepository;
 
        public TaskController(ITaskService service, IHttpContextAccessor httpContextAccessor, IRouterExtension routerExtension, IStationMangerRepository stationMangerRepository) : base(service)
        {
            _httpContextAccessor = httpContextAccessor;
            _routerExtension = routerExtension;
            _stationMangerRepository=stationMangerRepository;
        }
 
        [HttpPost, Route("ReceiveTask"), AllowAnonymous]
        public WMSReceiveTaskContent ReceiveWMSTask([FromBody] WMSTaskDTO taskDTO)
        {
            return Service.ReceiveWMSTask(taskDTO);
        }
 
 
        [HttpPost, HttpGet, Route("UpdateTaskExceptionMessage")]
        public WebResponseContent UpdateTaskExceptionMessage(int taskNum, string message)
        {
            return Service.UpdateTaskExceptionMessage(taskNum, message);
        }
 
        [HttpPost, HttpGet, Route("TaskStatusRecovery")]
        public WebResponseContent TaskStatusRecovery(int taskNum)
        {
            return Service.TaskStatusRecovery(taskNum);
        }
 
        [HttpPost, HttpGet, Route("RollbackTaskStatusToLast")]
        public WebResponseContent RollbackTaskStatusToLast(int taskNum)
        {
            return Service.RollbackTaskStatusToLast(taskNum);
        }
        private static object lock_containerFlow = new object();
        /// <summary>
        /// 容器流动接口
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("ContainerFlow"), AllowAnonymous]
        public WebResponseContent ContainerFlow([FromBody] ContainerFlowDTO containerFlowDTO)
        {
            lock (lock_containerFlow)
            {
                WebResponseContent content = new WebResponseContent();
                try
                {
                    Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.PickStationCode == containerFlowDTO.SlotCode) ?? throw new Exception($"{containerFlowDTO.SlotCode}拣选位置不存在");
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                    if (device == null)
                    {
                        return WebResponseContent.Instance.Error($"未找到对应设备{stationManger.StationDeviceCode}");
                    }
                    if (stationManger.StationDeviceCode == "CL1" || stationManger.StationDeviceCode == "CL2")
                    {
                        OtherDevice commonConveyorLine = (OtherDevice)device;
                        byte[] bytesPick = commonConveyorLine.Communicator.Read("2", 5);
                        string PickBarCode = Encoding.UTF8.GetString(bytesPick).Replace("\0", "").Replace("\\0", "");
                        if (containerFlowDTO.ContainerCode != PickBarCode) throw new Exception($"传入料箱码{containerFlowDTO.ContainerCode},输送料箱码{PickBarCode}数据错误");
                        //if (containerFlowDTO.Direction == "100")
                        //{
                        //    WebResponseContent responseContent = Service.ContainerFlow(containerFlowDTO, stationManger.StationDeviceCode, stationManger.PickStationCode);
                        //    if (!responseContent.Status) throw new Exception(responseContent.Message);
                        //}
                        WriteLog.Write_Log("一期容器流动入库接口", "任务信息", $"返回输送线{stationManger.PickStationCode}", $"返回给输送线的任务信息:{containerFlowDTO.ToJson()}");
                        commonConveyorLine.Communicator.Write("22", (containerFlowDTO.Direction == "100" ? new byte[] { 1, 0 } : new byte[] { 2, 0 }));
                    }
                    else
                    {
         
                        CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                        string PickBarCode = commonConveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_PickBarCode, stationManger.StationCode).Trim();
 
                        if (containerFlowDTO.ContainerCode != PickBarCode) throw new Exception($"传入料箱码{containerFlowDTO.ContainerCode},输送料箱码{PickBarCode}数据错误");
                        
                        if (containerFlowDTO.Direction == "100")
                        {
                            short W_PickToHode = commonConveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.W_PickToHode, stationManger.StationCode);
                            if (W_PickToHode == 300)
                            {
                                WebResponseContent responseContent = Service.ContainerFlow(containerFlowDTO, stationManger.StationDeviceCode, stationManger.PickStationCode);
                                if (!responseContent.Status) throw new Exception(responseContent.Message);
                            }
                            else
                            {
                                throw new Exception($"传入料箱码{containerFlowDTO.ContainerCode},输送料状态:{W_PickToHode},不满足入库条件");
                            }
                        }
                        WriteLog.Write_Log("二期容器流动入库接口", "任务信息", $"返回输送线{stationManger.PickStationCode}", $"返回给输送线的任务信息:{containerFlowDTO.ToJson()}");
                        commonConveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)containerFlowDTO.Direction.ObjToInt(), stationManger.StationCode);
                    }
                    content.OK();
                }
                catch (Exception ex)
                {
                    content.Error(ex.Message);
                }
                return content;
            }
        }
        /// <summary>
        /// 播种墙初始化
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("InitLight"), AllowAnonymous]
        public WebResponseContent InitLight()
        {
            return Service.InitLight();
        }
        /// <summary>
        /// 播种墙结束作业
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("EndLight"), AllowAnonymous]
        public WebResponseContent EndLight()
        {
            return Service.EndLight();
        }
        /// <summary>
        /// 播种墙亮灯
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("SendLight"), AllowAnonymous]
        public WebResponseContent SendLight([FromBody] TaskSendLight taskSendLight)
        {
            return Service.SendLight(taskSendLight);
        }
        /// <summary>
        /// 申请入库
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("RequestInTask"), AllowAnonymous]
        public WebResponseContent RequestInTask(string stationCode, string barCode)
        {
            return Service.RequestInTask(stationCode, barCode);
        }
        [HttpPost, HttpGet, Route("GetRouteEndPoint"), AllowAnonymous]
        public WebResponseContent GetRouteEndPoint(string startPoint, int routeType)
        {
            return WebResponseContent.Instance.OK(data: _routerExtension.GetEndPoint(startPoint, routeType));
        }
        /// <summary>
        /// WMS任务完成同步
        /// </summary>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("RecTaskCompleted"), AllowAnonymous]
        public WebResponseContent RecTaskCompleted(int taskNum)
        {
            return Service.TaskCompleted(taskNum);
        }
        /// <summary>
        /// 人工手动取消指定任务
        /// </summary>
        /// <param name="taskNum">任务编号</param>
        /// <returns>操作结果</returns>
        [HttpPost, HttpGet, Route("ManualTaskCancellation"), AllowAnonymous]
        public WebResponseContent ManualTaskCancellation(int taskNum)
        {
            return Service.ManualTaskCancellation(taskNum);
        }
        /// WMS任务取消同步
        /// </summary>
        /// <param name="taskCancels"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("CancelTask"), AllowAnonymous]
        public WebResponseContent CancelTask([FromBody] List<TaskCancel> taskCancels)
        {
            return Service.TaskCancel(taskCancels); ;
        }
 
        /// <summary>
        /// 把任务异常900修改为AGV执行中300
        /// </summary>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("ResetAllExceptionTask"), AllowAnonymous]
        public WebResponseContent ResetAllExceptionTask(int taskNum)
        {
            return Service.ResetAllExceptionTask(taskNum);
        }
 
        /// <summary>
        /// WMS异常恢复
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("WmsRecovery"), AllowAnonymous]
        public WebResponseContent WmsRecovery()
        {
            return Service.WmsRecovery();
        }
    }
}