222
schangxiang@126.com
2024-12-14 3eabfd8dfa2574efbe8ce8d4a64862c16ad04823
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
using Admin.NET.Application;
using iWareCC.Common.Helper;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DataAccess;
using iWareSql.WmsDBModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
 
namespace iWareCC.ThreadService
{
    /// <summary>
    /// 机器人缓存岛 人工强制待出库 处理
    /// </summary>
    public static class DataProcess_RobotBuffer_ForceOutbound
    {
        public static async void Handler()
        {
            var alertMsg = "";
            LogType logType = LogType.DataProcess_RobotBuffer_ForceOutbound;
            while (true)
            {
                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ForceOutbound = string.Empty;
                try
                {//SystemValue.isAllowRuning_DataProcess_RobotBuffer_AutoQiTaoOutbound && 
                    if (SystemValue.isStartedModel)
                    {
 
                        var rgvLocation = StationLocationEnum.BZ39.ToString();
                        if (FormCC.stationView == null)
                        {
                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ForceOutbound = $"{rgvLocation.ToString()}-获取PLC对象为null";
                            continue;
                        }
                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
                        if (obj.R_ForceOutboundMode == false)
                        {
                            alertMsg = "PLC不是强制出库模式";
                            continue;
                        }
                        using (WmsDBModel wmsDB = new WmsDBModel())
                        {
                            List<wms_stock_quan> qunList = wmsDB.wms_stock_quan.Where(x => x.StockStatus == (int)StockStatusEnum.人工强制待出库
                            ).OrderBy(x => x.PackageCode).ToList();
 
                            //按照包分组处理 
                            var groups = qunList.GroupBy(x => x.PackageCode);
                            foreach (var group in groups)
                            {
                                //注意:排序严格按照 次序 进行排序。 !!!!!!!!
                                var stockList = group.ToList().OrderBy(x => x.Shelf).ToList();
 
                                foreach (var x in stockList)
                                {
                                    x.StockStatus = (int)StockStatusEnum.人工强制任务已创建;
                                    x.StockStatusName = StockStatusEnum.人工强制任务已创建.ToString();
 
                                    //生成出库任务
                                    //记录任务
                                    var _id = Yitter.IdGenerator.YitIdHelper.NextId();
                                    var plcTaskNo = BusinessHelper.CreatePlcTaskId();
                                    plcTaskNo = MyExtendHelper.GetNewTaskNo(wmsDB, RbTaskTypeEnum.强制出库任务, plcTaskNo);
                                    var new_task = new wms_rbline_task()
                                    {
                                        Id = _id,
                                        TaskNo = plcTaskNo,
 
                                        Upi = x.Upi,
                                        Length = x.Length,
                                        Width = x.Width,
                                        Thk = x.Thk,
 
                                        PlanNo = x.PlanNo,
                                        OrderId = x.OrderId,
                                        PackageCode = x.PackageCode,
                                        PlaceCode = x.PlaceCode,
                                        RbTaskType = (int)RbTaskTypeEnum.强制出库任务,
                                        TaskStatus = (int)TaskStatusEnum.新建,
                                        TaskMsg = "人工强制待出库",
 
 
                                        CreateTime = DateTime.Now,
                                        CreateUserName = SysGloble.WCSSystem,
                                        UpdateTime = DateTime.Now,
                                        UpdateUserName = SysGloble.WCSSystem,
                                    };
 
                                    wmsDB.wms_rbline_task.Add(new_task);
 
                                    var place = StationHandler.GetPlaceByPlaceCode(x.PlaceCode, wmsDB);
                                    place.PlaceStatus = (int)PlaceStatusEnum.锁定;
 
                                    Thread.Sleep(100);
                                }
                            }
 
                            wmsDB.SaveChanges();
                        }
 
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_ForceOutbound += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
                }
            }
        }
 
    }
}