ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
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
using Admin.NET.Application;
using Admin.NET.Core.EnterWareHouseModule;
using Admin.NET.Core.EnterWareHouseModule.Enum;
using Admin.NET.Core.TaskModule.Enum;
using iWareCommon.Utils;
using iWareModel;
using iWareModel.EnumType.AoSinPublicCommon;
using iWareSql.DbOrm;
using iWareSql.Orm;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace iWareCC
{
    public class MoveTaskHandle
    {
        public static LogType currentLogType = LogType.MainTaskCompleteHandle;
        public static string host = ConfigHelper.GetConfigString("WMSHost");
        public static string confirm = ConfigHelper.GetConfigString("confirm");
        /// <summary>
        /// 任务完成后处理单据状态
        /// </summary>
        public static void HandlerMainTaskStatus()
        {
            List<ware_device_wareing> list = new List<ware_device_wareing>();
            while (true)
            {
                try
                {
                    using (DbOrm dbOrm = new DbOrm())
                    {
                        DateTime nowDate = DateTime.Now;
                        list = dbOrm.ware_device_wareing.Where(u => u.DeviceCode == "1099" && u.Status == 0 && (DbFunctions.DiffSeconds(u.UpdatedTime,nowDate) > 20 || u.UpdatedTime == null)).ToList();
                        foreach (var item in list)
                        {
                            item.UpdatedTime = nowDate;
                            item.UpdatedUserName = "WMS";
                            item.Status = 1; //状态(0:新建 1:已处理)
                            item.StatusName = "已处理";
                            item.CloseContent = "WMS关闭";
                            item.FinishTime = nowDate;
                            item.OperationRemark = "关闭报警";
                            var msg = "";
                            GetTimeDiffer(item.CreatedTime?.DateTime, nowDate, ref msg);
                            item.DurationTime = msg;
                        }
                        dbOrm.SaveChanges();
                        
                        //var list = dbOrm.v_ware_inventory_by_container.AsNoTracking().Where(u => u.WareLocationCode != u.RealLocationCode && u.StockStatus == 2 && !string.IsNullOrEmpty(u.RealLocationCode)).ToList();
 
                        //if (list != null)
                        //{
                        //    if (list.Count > 0)
                        //    {
                        //        string str = list[0].WareContainerCode;
                        //        string toLocation = "";
                        //        //查看目标库位是不是第2排
                        //        //if (list[0].RealLocationCode.Substring(2).StartsWith("02"))
                        //        //{
                        //        //    //查看该1排是否有货
                        //        //    var arr = list[0].RealLocationCode.Split('-');
                        //        //    string newstr = arr[0] + "-" + "01" + "-" + arr[2] + "-"+ arr[3];
                        //        //    var lvc = dbOrm.ware_location_vs_container.AsNoTracking().Where(u => u.WareLocationCode == newstr).FirstOrDefault();
                        //        //    if (lvc == null)
                        //        //    {
 
 
                        //        //        //目标库位修改为1排
                        //        //        toLocation = newstr;
 
                        //        //        var container = dbOrm.wms_container.Where(u => u.ContainerCode == str).FirstOrDefault();
                        //        //        container.RealLocationCode = toLocation;
                        //        //    }
                        //        //    else
                        //        //    {
                        //        //        toLocation = list[0].RealLocationCode;
                        //        //    }
                        //        //}
                        //        //else
                        //        //{
                        //        //    toLocation = list[0].RealLocationCode;
                        //        //}
                        //        toLocation = list[0].RealLocationCode;
                        //        //查看同一个伸位是否有任务
                        //        if (toLocation.Substring(2).StartsWith("01"))
                        //        {
                        //            //查看该1排是否有货
                        //            var arr = toLocation.Split('-');
                        //            string newstr = arr[0] + "-" + "02" + "-" + arr[2] + "-" + arr[3];
                        //            var isExist = dbOrm.ware_task.Any(u => u.ToLocationCode == newstr || u.FromLocationCode == newstr || u.MoveFromLocation == newstr || u.MoveToLocation == newstr);
                        //            if (isExist)
                        //            {
                        //                Thread.Sleep(3000);//休眠2秒
                        //                continue;
                        //            }
                        //        }
                        //        if (toLocation.Substring(2).StartsWith("02"))
                        //        {
                        //            //查看该1排是否有货
                        //            var arr = toLocation.Split('-');
                        //            string newstr = arr[0] + "-" + "01" + "-" + arr[2] + "-" + arr[3];
                        //            var isExist = dbOrm.ware_task.Any(u => u.ToLocationCode == newstr || u.FromLocationCode == newstr || u.MoveFromLocation == newstr || u.MoveToLocation == newstr);
                        //            if (isExist)
                        //            {
                        //                Thread.Sleep(3000);//休眠2秒
                        //                continue;
                        //            }
                        //        }
                        //        //创建移库任务,每次只处理一条
                        //        var cvm = dbOrm.ware_container_vs_material.Where(u => u.WareContainerCode == str ).FirstOrDefault();
                        //        var tasknew = new ware_task
                        //        {
                        //            //OrderNo = input.OrderNo,
                        //            TaskNo = DateTime.Now.ToString("yyyyMMddhhmmssfff"),
                        //            //TaskName = wcsTask.TaskName,
                        //            //TaskCategory = wcsTask.TaskType,
                        //            TaskCategory = (int)TaskCategoryEnum.MoveStock,
                        //            TaskDescribe = "",
                        //            TaskPriority = 99,
                        //            //TaskState = 0,
                        //            TaskState = (int)TaskStateEnum.未执行,
                        //            //TaskType = wcsTask.TaskType,
                        //            FromLocationCode = list[0].WareLocationCode,
                        //            ToLocationCode = toLocation,
                        //            ContainerCode = list[0].WareContainerCode,
                        //            Lane = list[0].Lane,
                        //            ContainerType = 0,
                        //        };
                        //        cvm.StockStatus = (int)StockStatusEnum.移库中;
                        //        dbOrm.ware_task.Add(tasknew);
                        //        dbOrm.SaveChanges();
                        //    }
                        //}
                    }
                }
                catch (Exception ex)
                {
                    Log4NetHelper.WriteErrorLog(currentLogType, "HandlerMainTaskStatus处理库存状态异常" + ex.Message);
                }
                Thread.Sleep(5000);//休眠2秒
            }
        }
 
        public static int GetTimeDiffer(DateTime? startTime, DateTime? endTime, ref string msg)
        {
            if (startTime == null || endTime == null)
            {
                return 0;
            }
            TimeSpan ts = ((DateTime)endTime - (DateTime)startTime);
            msg = "";
            if (ts.Days != 0)
            {
                msg += ts.Days + "天";
            }
            if (ts.Hours != 0)
            {
                msg += ts.Hours + "小时";
            }
            if (ts.Minutes != 0)
            {
                msg += ts.Minutes + "分钟";
            }
            if (ts.Seconds != 0)
            {
                msg += ts.Seconds + "秒";
            }
            return (int)ts.TotalSeconds;
        }
    }
}