111
cjs
2025-06-06 b754b0d966600a3b12f7c6d2449e5bcb00e34779
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
using SqlSugar;
using System;
using System.Collections.Generic;
 
using Hanhe.iWCS.Common;
 
namespace Hanhe.iWCS.TaizhouGEMTwoProtocol
{
    public class MoboxHelper
    {
        static MoboxHelper() {
        }
 
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="lineNo"></param>
        /// <returns></returns>
        public WorkOrder GetWorkOrder(string lineNo) {
            var order = new SqlHelper<WorkOrder>().Get(a => a.SQL_PLineNo == lineNo && (a.SQL_State == "执行中" || a.SQL_State == "已完成"), a => a.T_CREATE);
            if (order == null) Console.WriteLine($"SQLSERVER Error:未获取到当前条件的相关数据!当前查询条件:{lineNo}");
            return order;
        }
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="orderno"></param>
        /// <returns></returns>
        public bool AddNewData(string data)
        {
            var result = false;
            new SqlHelper<WorkOrder>().ExecuteSql($"insert into dbo.TN_0004(S_ID,SQL_PLineNo) Values('{Guid.NewGuid()}','33333')");
            return result;
        }
        /// <summary>
        /// 更新车号
        /// </summary>
        /// <param name="taskNo"></param>
        /// <param name="endBit"></param>
        public static bool UpdateEndBit(string taskNo, string agvNo)
        {
            var result = false;
            try
            {
                CMMLog.Info($"SQLServer 更新任务车号:任务号:{taskNo},更改车号:{agvNo}");
                result = new SqlHelper<SQL_TN_I_TASK_MST>().ExecuteSql($"update dbo.tn_am_task_mst set CN_N_AGV_NO='{agvNo}' where CN_S_TASK_NO='{taskNo}'");
            }
            catch(Exception ex)
            {
                CMMLog.Error($"SQLServer 更新任务车号异常:{ex.Message}");
            }
            
            return result;
        }
 
        public static bool UpdateTaskState(string taskNo, int state)
        {
            var result = false;
            try
            {
                string taskState = state == 3 ? "开始取货" : state == 4 ? "取货完成" : state == 5 ? "开始卸货" : state == 6 ? "卸货完成" : state == 2 ? "完成" : "";
                CMMLog.Info($"SQLServer 更新任务状态:任务号:{taskNo},更改状态:{taskState}");
                if (!string.IsNullOrEmpty(taskState)) result = new SqlHelper<SQL_TN_I_TASK_MST>().ExecuteSql($"update dbo.tn_am_task_mst set CN_S_STATUS='{taskState}' where CN_S_TASK_NO='{taskNo}'");
            }
            catch (Exception ex)
            {
                CMMLog.Error($"SQLServer 更新任务状态异常:{ex.Message}");
            }
 
            return result;
        }
 
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="orderno"></param>
        /// <returns></returns>
        public bool DelData(string orderno)
        {
            var result = false;
            new SqlHelper<WorkOrder>().ExecuteSql($"delete dbo.TN_0004 where SQL_PLineNo='2222222'");
            return result;
        }
 
        public static void AddRecordNew(WorkOrder record)
        {
            var helper = new SqlHelper<WorkOrder>();
            var old = helper.Get(a => a.SQL_PLineNo == record.SQL_PLineNo);
            if (old != null)
            {
                helper.Deleteable(a => a.SQL_PLineNo == record.SQL_PLineNo);
                helper.Insert(record);
            }
            else
            {
                //更新数据
                //if (old != null)
                //{
                //    old.TransportStatus = record.TransportStatus;
                //    old.HasBeenReceived = record.HasBeenReceived;
                //    var cols = new List<string>() { "TransportStatus", "HasBeenReceived" };
                //    if (record.TransportStatus == 2)
                //    {
                //        cols.Add("ExecutionTime");
                //        old.ExecutionTime = record.ExecutionTime;
                //    }
                //    if (record.TransportStatus == 4 || record.TransportStatus == 12 || record.TransportStatus == 13 || record.TransportStatus == 6)
                //    {
                //        cols.Add("CompleteTime");
                //        old.CompleteTime = record.CompleteTime;
                //    }
                //    if (!string.IsNullOrEmpty(record.AgvNo))
                //    {
                //        cols.Add("AgvNo");
                //        old.AgvNo = record.AgvNo;
                //    }
                //    helper.Update(old, cols.ToArray());
                //}
            }
        }
 
        /// <summary>
        /// 工单表
        /// 梅坪现场工单表名:"dbo.TN_0001"
        /// 模拟测试工单表名:"dbo.TN_0004"
        /// </summary>
        [SugarTable("dbo.TN_0004")]
        public class WorkOrder
        {
            public string S_ID { get; set; } = "";
            public string S_STATE { get; set; } = "";
            public string S_CREATOR_ID { get; set; } = "";
            public string S_CREATOR_NAME { get; set; } = "";
            public DateTime T_CREATE { get; set; } = DateTime.MinValue;
            public string S_DEPART_ID { get; set; } = "";
            public string S_DEPART_NAME { get; set; } = "";
            public string S_MODIFIER_ID { get; set; } = "";
            public string S_MODIFIER_NAME { get; set; } = "";
            public DateTime T_MODIFY { get; set; } = DateTime.MinValue;
            public int N_CREATEMETHOD { get; set; } = 0;
            public string G_SOURCE_OBJ { get; set; } = "";
            /// <summary>
            /// 工单号
            /// </summary>
            public string SQL_WorkNo { get; set; } = "";
            /// <summary>
            /// 产线号
            /// </summary>
            public string SQL_PLineNo { get; set; } = "";
            /// <summary>
            /// 即产即用
            /// </summary>
            public string SQL_UsingNo { get; set; } = "";
            /// <summary>
            /// 工单类型
            /// </summary>
            public string SQL_ORDER_TYPE { get; set; } = "";
            /// <summary>
            /// 工单状态
            /// </summary>
            public string SQL_State { get; set; } = "";
            /// <summary>
            /// 批次号
            /// </summary>
            public string SQL_BatchNo { get; set; } = "";
            /// <summary>
            /// 物料编码
            /// </summary>
            public string SQL_ItemCode { get; set; } = "";
            /// <summary>
            /// 物料名称
            /// </summary>
            public string SQL_ItemName { get; set; } = "";
            /// <summary>
            /// 总数
            /// </summary>
            public string SQL_Total { get; set; } = "";
            /// <summary>
            /// 库区或者列或者排编号
            /// </summary>
            public string SQL_Area { get; set; } = "";
            /// <summary>
            /// 固定每批运输数量
            /// </summary>
            public string SQL_PCNumber { get; set; } = "";
            /// <summary>
            /// 计数(已执行数量)
            /// </summary>
            public string SQL_Current { get; set; } = "";
            /// <summary>
            /// 当前工单执行时间
            /// </summary>
            public string SQL_Modify { get; set; } = "";
            /// <summary>
            /// 当前工单结束时间
            /// </summary>
            public string SQL_PLAN_END { get; set; } = "";
            /// <summary>
            /// 连接产线号
            /// </summary>
            public string SQL_LinkLineNO { get; set; } = "";
            /// <summary>
            /// 是否栈板
            /// </summary>
            public string SQL_PaperBox { get; set; } = "";
        }
        /// <summary>
        /// SQL-AMS任务主表
        /// </summary>
        [SugarTable("dbo.tn_am_task_mst")]
        public class SQL_TN_I_TASK_MST
        {
            public string CN_S_BATCH_NO { get; set; }
            public int CN_S_ORDER_NO { get; set; }
            public string CN_S_TASK_NO { get; set; }
            public string CN_S_SOURCE_SYS { get; set; }
            public string CN_S_SOURCE_NO { get; set; }
            public string CN_S_PROCESS_CODE { get; set; }
            public string CN_S_TASK_TYPE { get; set; }
            public string CN_S_START_AREA { get; set; }
            public string CN_S_START_AREA_NAME { get; set; }
            public string CN_S_START_BIT { get; set; }
            public int CN_N_START_AGVBIT { get; set; }
            public string CN_S_END_AREA { get; set; }
            public string CN_S_END_AREA_NAME { get; set; }
            public string CN_S_END_BIT { get; set; }
            public int CN_N_END_AGVBIT { get; set; }
            public string CN_S_STATUS { get; set; }
            public string CN_S_BEF_STATUS { get; set; }
            public string CN_S_BEFORE_NO { get; set; }
            public string CN_S_AFTER_NO { get; set; }
            public string CN_T_START_WORKING { get; set; }
            public string CN_T_END_WORKING { get; set; }
            public int CN_N_PRIORITY { get; set; }
            public int CN_N_CUR_STEP { get; set; }
            public string CN_S_CREATOR { get; set; }
            public string CN_S_CREATOR_NAME { get; set; }
            public string CN_T_CREATE { get; set; }
            public string CN_S_MENDER { get; set; }
            public string CN_S_MODIFY_NAME { get; set; }
            public string CN_T_MODIFY { get; set; }
            public string CN_S_TASK_MODEL { get; set; }
            public string CN_S_EXT1 { get; set; }
            public string CN_S_EXT2 { get; set; }
            public string CN_S_EXT3 { get; set; }
            public string CN_N_AGV_NO { get; set; }
            public string CN_S_TRANSPORT_INFO { get; set; }
        }
 
        /// <summary>
        /// SQL-MOBOX任务主表
        /// </summary>
        [SugarTable("dbo.TN_0001")]
        public class Mobox_MST_TASK
        {
            public string S_ID { get; set; }//g
            public string S_STATE { get; set; }
            public string S_CREATOR_ID { get; set; }
            public string S_CREATOR_NAME { get; set; }
            public DateTime T_CREATE { get; set; }
            public string S_DEPART_ID { get; set; }//g
            public string S_DEPART_NAME { get; set; }
            public string S_MODIFIER_ID { get; set; }
            public string S_MODIFIER_NAME { get; set; }
            public DateTime T_MODIFY { get; set; }
            public int N_CREATEMETHOD { get; set; }
            public string G_SOURCE_OBJ { get; set; }//g
 
 
            public string CN_S_BATCH_NO { get; set; }
            public string CN_S_TASK_NO { get; set; }
            public string CN_S_SOURCE_NO { get; set; }
            public string CN_S_START_BIT { get; set; }
            public string CN_S_END_BIT { get; set; }
            public string CN_S_STATUS { get; set; }
            public int CN_N_PRIORITY { get; set; }
            public string CN_T_MODIFY { get; set; }
        }
 
 
        public class BaseModel
        {
            [SugarColumn(IsPrimaryKey = true)]
            public string S_ID { get; set; } = Guid.NewGuid().ToString("D");
            public string S_CREATOR_ID { get; set; } = "sa";
            public string S_CREATOR_NAME { get; set; } = "超级用户";
            public DateTime T_CREATE { get; set; } = DateTime.Now;
            public DateTime T_MODIFY { get; set; } = DateTime.Now;
        }
 
        /// <summary>
        /// 设备报警信息表
        /// </summary>
        [SugarTable("dbo.TN_0081")]
        public class CallWcsWarningTable : BaseModel
        {
            /// <summary>
            /// 请求编号,每个请求都要一个唯一编号, 同一个请求重复提交, 使用同一编号。由上层系统提供
            /// </summary>
            public string requestPK { get; set; }
            /// <summary>
            /// 故障代码
            /// </summary>
            public string errorNO { get; set; }
            /// <summary>
            /// 故障描述
            /// </summary>
            public string errorDes { get; set; }
            /// <summary>
            /// 任务编码
            /// </summary>
            public string taskCode { get; set; }
            /// <summary>
            /// 设备编码
            /// </summary>
            public string dvcNo { get; set; }
            /// <summary>
            /// 操作人
            /// </summary>
            public string @operator { get; set; }
            /// <summary>
            /// 操作时间
            /// </summary>
            public DateTime operationTime { get; set; }
        }
 
        /// <summary>
        /// 海康报警信息表
        /// </summary>
        [SugarTable("dbo.TN_0082")]
        public class WarnCallbackTable : BaseModel
        {
            /// <summary>
            /// 请求编号,每个请求都要一个唯一编号,同一个请求重复提交,使用同一编号。
            /// </summary>
            public string reqCode { get; set; }
            /// <summary>
            /// 请求时间戳,格式: “yyyy-MM-dd HH:mm:ss”。
            /// </summary>
            public string reqTime { get; set; }
            /// <summary>
            /// 客户端编号,如 PDA,HCWMS 等。
            /// </summary>
            public string clientCode { get; set; }
            /// <summary>
            /// 令牌号,由调度系统颁发。
            /// </summary>
            public string tokenCode { get; set; }
            /// <summary>
            /// 车号
            /// </summary>
            public string robotCode { get; set; }
            /// <summary>
            /// 告警开始时间
            /// </summary>
            public string beginTime { get; set; }
            /// <summary>
            /// 告警内容
            /// </summary>
            public string warnContent { get; set; }
            /// <summary>
            /// 任务号
            /// </summary>
            public string taskCode { get; set; }
        }
    }
}