dengjunjie
2025-04-19 9e579eda4601ed7b492b9d19a24e8146f6ebdf8d
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.WMSInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ProductionLineJob;
 
namespace WIDESEAWCS_Tasks
{
    public partial class CommonProductionLineJob
    {
        /// <summary>
        /// 入库产线
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <returns></returns>
        public void ProductionLineIn(OtherDevice ProductionLine)
        {
            foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
            {
                var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request, item.Key);
                if (request == 1)
                {
                    var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType, item.Key);
                    var content = Request(ProductionLine, traytype, item.Key);
 
                    if (content.Status) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
                }
            }
        }
        /// <summary>
        /// 出库产线
        /// </summary>
        /// <param name="ProductionLine"></param>
        public void ProductionLineOut(OtherDevice ProductionLine)
        {
            foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
            {
                var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request, item.Key);
                if (request == 1)
                {
                    bool ok = false;
                    var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType, item.Key);
                    if (traytype == 2 || traytype == 4 || traytype == 6)
                        ok = Request(ProductionLine, traytype, item.Key).Status;
                    else
                    {
                        var task = _taskService.QuertOutProductionLineTask(true);
                        if (task != null)
                        {
                            //if (task.Remark.ObjToInt() == traytype)
                            if (!string.IsNullOrEmpty(task.Remark) && traytype == 5)
                            {
                                task.TargetAddress = item.Key;
                                task.NextAddress = item.Key;
                                ok = _taskService.UpdateData(task).Status;
                            }
                        }
                    }
                    if (ok) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
                }
            }
        }
        /// <summary>
        /// 申请
        /// </summary>
        /// <param name="ProductionLine">产线</param>
        /// <param name="traytype">托盘类型</param>
        /// <param name="station">站台号</param>
        /// <returns></returns>
        public WebResponseContent Request(OtherDevice ProductionLine, short traytype, string station)
        {
            WebResponseContent response = new WebResponseContent();
            ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO();
            try
            {
                switch (traytype)
                {
                    case 1://放空托
                    case 3://放空盒
                           //case 5://放满盒
                        {
                            MaterielGroupDTO.stationCode = station;
                            MaterielGroupDTO.traytype = traytype;
                        }
                        break;
                    case 2://取空托
                    case 4://取满盒
                    case 6://取空盒
                        {
                            MaterielGroupDTO.Barcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode, station);
                            MaterielGroupDTO.stationCode = station;
                            MaterielGroupDTO.traytype = traytype;
                            if (traytype == 4)
                            {
                                #region 读取数量
                                //var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
                                //var productQty = ProductionLine.Communicator.Read<short>(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
                                //#endregion
 
                                //#region 写入数量
                                //var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
                                //ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
                                #endregion
 
                                MaterielGroupDTO.batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo, station);
                                //MaterielGroupDTO.productQty = string.Join(",", productQty);
                            }
                        }
                        break;
                    #region MyRegion
                    //case 3://放空盒
                    //    {
                    //        MaterielGroupDTO.stationCode = station;
                    //        MaterielGroupDTO.traytype = traytype;
                    //    }
                    //    break; 
                    //case 4://取满盒
                    //    {
                    //        //var productQty = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.productQty, station);
                    //        #region 读取数量
                    //        var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
                    //        var productQty = ProductionLine.Communicator.Read<short>(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
                    //        #endregion
 
                    //        #region 写入数量
                    //        var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
                    //        ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
                    //        #endregion
 
                    //        var batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo, station);
                    //        var trayBarcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode, station);
 
                    //        MaterielGroupDTO.batchNo = batchNo;
                    //        MaterielGroupDTO.Barcode = trayBarcode;
                    //        MaterielGroupDTO.stationCode = station;
                    //        MaterielGroupDTO.traytype = traytype;
                    //        MaterielGroupDTO.productQty = string.Join(",", productQty);
                    //    }
                    //    break;
                    //case 5://放满盒
                    //    {
                    //        MaterielGroupDTO.stationCode = station;
                    //        MaterielGroupDTO.traytype = traytype;
                    //    }
                    //    break; 
                    //case 6://取空盒
                    //    {
 
                    //    }
                    //    break;
                    #endregion
                    default:
                        throw new Exception("未定义托盘类型");
                }
 
                response = ProductionLineToWMSRequest(MaterielGroupDTO);
            }
            catch (Exception ex)
            {
                response.Error(ex.Message);
            }
            return response;
        }
 
        public WebResponseContent ProductionLineToWMSRequest(ProductionLineDTO MaterielGroupDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var ResultData = HttpHelper.PostAsync(WMSInterfaceAddress.ProductionlineRequest, MaterielGroupDTO.ToJson(), headers: new Dictionary<string, string>());
                if (ResultData.Result == null) throw new Exception($"产线向WMS请求超时");
 
                content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
 
                #region 产线申请入库任务
                if (content != null && content.Status)//任务转换
                {
                    var task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToJson());
                    if (task != null)
                    {
                        List<int> TaskNums = new List<int>();
                        List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.TargetAddress);
                        if (routers.Count > 0)
                        {
                            task.NextAddress = routers.FirstOrDefault().ChildPosi;
                        }
                        task.WMSId = task.TaskId;
                        task.Creater = "WMS";
                        task.Dispatchertime = null;
                        task.CreateDate = DateTime.Now;
                        content = _taskService.AddData(task);
                        TaskNums.Add(task.TaskNum);
                        _taskExecuteDetailService.AddTaskExecuteDetail(TaskNums, "接收WMS任务");
                    }
                }
                #endregion
 
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}