111
cjs
2025-06-26 1a0c5192cd1269a1aa2c0af94fc2bcb5fcc9a056
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
using HH.WCS.Mobox3.NFLZ.device;
using HH.WCS.Mobox3.NFLZ.process;
using HH.WCS.Mobox3.NFLZ.util;
using HH.WCS.Mobox3.NFLZ.wms;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static HH.WCS.Mobox3.NFLZ.wms.WMSHelper.AddChangeModel;
using static System.Runtime.CompilerServices.RuntimeHelpers;
 
namespace HH.WCS.Mobox3.NFLZ.core
{
    /// <summary>
    /// 定时轮询任务
    /// </summary>
    internal class Monitor
    {
        internal static void CheckThirdOutWork() {
            //第三方读中间表
            //var db= new SqlHelper<object>().GetInstance("中间表的sql连接字符串");
            // db.Queryable<object>
 
            //读到了出库单,插入到我们的表
 
 
        }
 
        internal static void CheckOutWork() {
            //读自己的中间表,我们自己的表有表有个字段计数,计数小于最大值,继续出库,一次生成一条任务
 
        }
 
 
        internal static void CheckDevice() {
            //检测输送线状态
 
            S7Helper.ReadStr("plc1", 100, 1, 8);
            S7Helper.ReadBit("plc1", 101, 1, 2);
            S7Helper.ReadInt("plc1", 102, 1, 6);
            //1 设备plc的ip deviceNo 自动建立连接
            //2 设备对应的通讯项和线体类型(输送线入口、输送线出口、提升机的入口。。。。)起始读的偏移地址,写的偏移地址
            //{ "deviceNo":"5","code":"9001","location":"F1CJ-SSX1-01","writeAddr900":0,"writeAddr905":-1,"writeAddr710":0,"readAddr901":2,"readAddr902":0,"lineType":1},
            //3 通讯项自动读plc,读到的数据根据lineType做处理,自动创建任务或者更新任务状态(创建一个设备动作或任务动作,如果是任务动作有个线程去读)
        }
 
        /// <summary>
        /// 转运任务
        /// </summary>
        internal static void BottleBlankTransportation()
        {
            var db = new SqlHelper<object>().GetInstance();
            #region 瓶盖满托入库
            var areaInfo = Settings.areaInfos.Where(a => a.areaName == "瓶盖入库接驳" && a.enable == 1).FirstOrDefault();
            if (areaInfo != null)
            {
                var locInfo = db.Queryable<Location>().Where(a => a.S_AREA_CODE == areaInfo.areaCode && a.N_CURRENT_NUM > 0 && a.S_LOCK_STATE == "无").Includes(a => a.LocCntrRel).First();
                if (locInfo != null)
                {
                    LogHelper.Info($"【瓶盖满托转运】瓶坯接驳位查询到需入库的瓶坯,货位编码:{locInfo.S_CODE}");
                    string cntrCode = getCntrCode(db, locInfo);
                    if (string.IsNullOrEmpty(cntrCode))
                    {
                        //创建作业
                        WMSHelper.CreateOpTask(locInfo.S_CODE, "", "入库", "接驳位入库", cntrCode, "瓶盖");
                    }
                    else
                    {
                        LogHelper.Info($"【瓶盖满托转运】当前货位未绑定托盘码,货位编码:{locInfo.S_CODE}");
                    }
                }
            }
            else
            {
                LogHelper.Info("【瓶盖满托转运】瓶盖入库接驳 未配置");
            }
            #endregion
 
            #region 瓶盖空托入库
            areaInfo = Settings.areaInfos.Where(a => a.areaName == "瓶盖非即产空框" && a.enable == 1).FirstOrDefault();
            if(areaInfo != null)
            {
                var locInfo = db.Queryable<Location>().Where(a => a.S_AREA_CODE == areaInfo.areaCode && a.N_CURRENT_NUM == a.N_CAPACITY && a.S_LOCK_STATE == "无").First();
                if(locInfo != null)
                {
                    string cntrCode = getCntrCode(db, locInfo);
                    if (string.IsNullOrEmpty(cntrCode))
                    {
                        //创建作业
                        WMSHelper.CreateOpTask(locInfo.S_CODE, "", "入库", "瓶盖空托入库", cntrCode, "瓶盖");
                    }
                    else
                    {
                        LogHelper.Info($"【瓶盖空托转运】当前货位未绑定托盘码,货位编码:{locInfo.S_CODE}");
                    }
                }
            }
            else
            {
                LogHelper.Info("【瓶盖空托转运】瓶盖非即产空框 未配置");
            }
            #endregion
 
            #region 瓶坯满托入库
            areaInfo = Settings.areaInfos.Where(a => a.areaName == "瓶坯入库接驳" && a.enable == 1).FirstOrDefault();
            if (areaInfo != null)
            {
                var locInfo = db.Queryable<Location>().Where(a => a.S_AREA_CODE == areaInfo.areaCode && a.N_CURRENT_NUM == a.N_CAPACITY && a.S_LOCK_STATE == "无").First();
                if (locInfo != null)
                {
                    string cntrCode = getCntrCode(db, locInfo);
                    if (!string.IsNullOrEmpty(cntrCode))
                    {
                        //创建作业
                        WMSHelper.CreateOpTask(locInfo.S_CODE, "", "入库", "接驳位入库", cntrCode, "瓶坯");
                    }
                    else
                    {
                        LogHelper.Info($"【瓶坯满托转运】当前货位未绑定托盘码,货位编码:{locInfo.S_CODE}");
                    }
                }
            }
            else
            {
                LogHelper.Info("【瓶坯满托转运】瓶坯入库接驳 未配置");
            }
 
            #endregion
        }
 
        /// <summary>
        /// 瓶坯翻斗机非急产满框区补满托
        /// </summary>
        internal static void PPFDFullIn()
        {
            //产线号 : 农夫林芝-1号瓶坯翻斗机
            var db = new SqlHelper<object>().GetInstance();
            var bcpWorkList = db.Queryable<LinZhiBCPWorkOrder>().Where(a => a.S_PLineNo.Contains("瓶坯翻斗机") && a.S_UsingNow == "N" && a.S_WorkState == "执行中").ToList();
            if(bcpWorkList.Count > 0)
            {
                bcpWorkList.ForEach(a => 
                {
                    string areaName = a.S_PLineNo.Split('-')[1].Substring(0, 1) + "号瓶坯翻斗机非即产满框";
                    LogHelper.Info($"PPFDFullIn area:{areaName}");
                    var areaInfo = Settings.areaInfos.Where(b => b.areaName == areaName && b.enable == 1).FirstOrDefault();
                    if(areaInfo != null)
                    {
                        var locInfo = db.Queryable<Location>().Where(b => b.S_AREA_CODE == areaInfo.areaCode && b.N_CURRENT_NUM == 0 && b.S_LOCK_STATE == "无").First();
                        if(locInfo != null)
                        {
                            //生成任务
                            Location location = TaskProcess.BCPInOrOut(db, false, "瓶坯库区", a.S_ItemCode);
                            if(location != null)
                            {
                                string cntrCode = getCntrCode(db,location);
                                //创建作业
                                WMSHelper.CreateOpTask(location.S_CODE, locInfo.S_CODE, "入库", "瓶坯非急产补满框", cntrCode, "瓶坯");
                            }
                        }
                    }
                    else
                    {
                        LogHelper.Info($"{areaName}未配置");
                    }
                });
            }
        }
 
        private static string getCntrCode(SqlSugar.SqlSugarClient db, Location location)
        {
            string cntr = "";
            var cntrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == location.S_CODE).OrderBy(a => a.T_CREATE).ToList();
            if(cntrList.Count > 0)
            {
                foreach(var a in cntrList)
                {
                    cntr = cntr + a.S_CNTR_CODE + ",";
                }
            }
            cntr = cntr.TrimEnd(',');
            return cntr;
        }
 
        internal static void PGFDFullIn()
        {
            //产线号 : 农夫林芝-1号瓶盖翻斗机
            //瓶盖翻斗机共用一个库区,需要区分几种情况(注:现场已确认,三个翻斗机不会有三种物料)
            //1、如果三个翻斗机物料相同,则 瓶盖非即产满框 有空货位就补
            //2、如果三个翻斗机有两种不同的物料,则 瓶盖非即产满框 有空位的补充 改库区没有的物料
            var db = new SqlHelper<object>().GetInstance();
            string itemList = "";
            var bcpWorkList = db.Queryable<LinZhiBCPWorkOrder>().Where(a => a.S_PLineNo.Contains("瓶盖翻斗机") && a.S_UsingNow == "N" && a.S_WorkState == "执行中").ToList();
            if (bcpWorkList.Count > 0)
            {
                bcpWorkList.ForEach(a =>
                {
                    if (string.IsNullOrEmpty(itemList))
                    {
                        itemList = itemList + a.S_ItemCode + ",";
                    }
                    else
                    {
                        if (!itemList.Contains(a.S_ItemCode))
                        {
                            itemList = itemList + a.S_ItemCode + ",";
                        }
                    }
                });
            }
            if (!string.IsNullOrEmpty(itemList))
            {
                itemList = itemList.TrimEnd(',');
                List<string> itemCount = itemList.Split(',').ToList();
                if(itemCount.Count > 0)
                {
                    var areaInfo = Settings.areaInfos.Where(b => b.areaName == "瓶盖非即产满框" && b.enable == 1).FirstOrDefault();
                    if (areaInfo != null)
                    {
                        var locInfo = db.Queryable<Location>().Where(b => b.S_AREA_CODE == areaInfo.areaCode && b.N_CURRENT_NUM == 0 && b.S_LOCK_STATE == "无").First();
                        if (locInfo != null)
                        {
                            if (itemCount.Count == 1)
                            {
                                //只有一种物料
                                //生成任务
                                Location location = TaskProcess.BCPInOrOut(db, false, "瓶盖库区", itemCount[0]);
                                if (location != null)
                                {
                                    string cntrCode = getCntrCode(db, location);
                                    //创建作业
                                    WMSHelper.CreateOpTask(location.S_CODE, locInfo.S_CODE, "入库", "瓶盖非急产补满框", cntrCode, "瓶盖");
                                }
                            }
                            if (itemCount.Count == 2)
                            {
                                //两种物料
 
                                //判断库区是否有货位数量大于0或者有入库锁的,如果有,则判断物料,如果没有,则生成第一个物料的任务
                                var locInfo2 = db.Queryable<Location>().Where(b => b.S_AREA_CODE == areaInfo.areaCode && (b.N_CURRENT_NUM > 0 || b.S_LOCK_STATE == "入库锁")).First();
                                if(locInfo2 != null)
                                {
                                    string itemCode = "";
                                    if(locInfo2.N_CURRENT_NUM > 0)
                                    {
                                        var cntrInfo = db.Queryable<LocCntrRel>().Where(b => b.S_LOC_CODE == locInfo2.S_CODE).First();
                                        if(cntrInfo != null)
                                        {
                                            var itemInfo = db.Queryable<CntrItemRel>().Where(b => b.S_CNTR_CODE == cntrInfo.S_CNTR_CODE).First();
                                            if(itemInfo != null)
                                            {
                                                itemCode = itemInfo.S_ITEM_CODE;
                                            }
                                        }
                                    }
                                    if(locInfo2.S_LOCK_STATE == "入库锁")
                                    {
                                        var taskInfo = db.Queryable<WMSTask>().Where(b => b.S_END_LOC == locInfo2.S_CODE && b.S_STATE != "完成" && b.S_STATE != "取消").First();
                                        if(taskInfo != null)
                                        {
                                            string cntrCode = taskInfo.S_CNTR_CODE.Split(',')[0];
                                            var itemInfo = db.Queryable<CntrItemRel>().Where(b => b.S_CNTR_CODE == cntrCode).First();
                                            if (itemInfo != null)
                                            {
                                                itemCode = itemInfo.S_ITEM_CODE;
                                            }
                                        }
                                    }
 
                                    if (itemCode != "")
                                    {
                                        itemCode = itemCode == itemCount[0] ? itemCount[1] : itemCount[0];
                                        Location location = TaskProcess.BCPInOrOut(db, false, "瓶盖库区", itemCode);
                                        if (location != null)
                                        {
                                            string cntrCode = getCntrCode(db, location);
                                            //创建作业
                                            WMSHelper.CreateOpTask(location.S_CODE, locInfo.S_CODE, "入库", "瓶盖非急产补满框", cntrCode, "瓶盖");
                                        }
                                    }
                                }
                                else
                                {
                                    Location location = TaskProcess.BCPInOrOut(db, false, "瓶盖库区", itemCount[0]);
                                    if (location != null)
                                    {
                                        string cntrCode = getCntrCode(db, location);
                                        //创建作业
                                        WMSHelper.CreateOpTask(location.S_CODE, locInfo.S_CODE, "入库", "瓶盖非急产补满框", cntrCode, "瓶盖");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        LogHelper.Info($"瓶盖非即产满框 未配置");
                    }
                }
            }
        }
 
        /// <summary>
        /// 瓶坯非即产即用库托库区补空托
        /// </summary>
        internal static void PPFDFullInEmpty()
        {
            var db = new SqlHelper<object>().GetInstance();
            var workInfo = db.Queryable<LinZhiBCPWorkOrder>().Where(a => a.S_PLineNo == "农夫林芝-瓶坯机" && a.S_UsingNow == "N" && a.S_WorkState == "执行中").First();
            if(workInfo != null)
            {
                var areaInfo = Settings.areaInfos.Where(a => a.areaName == "瓶坯非即产空框" && a.enable == 1).FirstOrDefault();
                if(areaInfo != null)
                {
                    var locInfo = db.Queryable<Location>().Where(a => a.S_AREA_CODE == areaInfo.areaCode && a.N_CURRENT_NUM == 0 && a.S_LOCK_STATE == "无").First();
                    if(locInfo != null)
                    {
                        //生成任务
                        Location location = TaskProcess.BCPInOrOut(db, false, "瓶坯库区", "");
                        if (location != null)
                        {
                            string cntrCode = getCntrCode(db, location);
                            //创建作业
                            WMSHelper.CreateOpTask(location.S_CODE, locInfo.S_CODE, "入库", "瓶坯非急产补空框", cntrCode, "瓶坯");
                        }
                    }
                }
                else
                {
                    LogHelper.Info("瓶坯非即产空框 未配置");
                }
            }
        }
    }
}