kazelee
2025-05-22 bb09e7affb602791af4064cda8cddcfae8b3f3aa
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
 
using HH.WCS.Mobox3.AnGang.dispatch;
using HH.WCS.Mobox3.AnGang.wms;
using HH.WCS.Mobox3.AnGang.models;
 
using Newtonsoft.Json;
 
using static HH.WCS.Mobox3.AnGang.api.ApiModel;
using HH.WCS.Mobox3.AnGang.util;
 
namespace HH.WCS.Mobox3.AnGang.api {
    /// <summary>
    /// 测试用,如果项目中要和设备对接,前期设备无法测试,用接口模拟
    /// </summary>
    [RoutePrefix("api")]
    public class DebugController : System.Web.Http.ApiController
    {
        /// <summary>
        /// AGV状态一键回报1462-国自
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("AGVSeriesReports")]
        public GzResults AGVSeriesReports(UpdateTaskState model) {
            GzResults gzResults = new GzResults();
            gzResults.GzResultList = new List<GzResult>();
            var orderStatus = new orderStatusReportParme() {
                orderName = model.TaskID,
                agvIDList = model.ForkliftNo,
                orderStatus = "waiting",
            };
            var temp1 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp1);
 
            orderStatus.orderStatus = "source_finish";
            var temp2 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp2);
 
            orderStatus.orderStatus = "dest_finish";
            var temp3 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp3);
 
            orderStatus.orderStatus = "finish";
            var temp4 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp4);
 
            return gzResults;
        }
 
        /// <summary>
        /// AGV状态一键回报14-国自
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("AGVSeriesReports-14")]
        public GzResults AGVSeriesReports14(UpdateTaskState model) {
            GzResults gzResults = new GzResults();
            gzResults.GzResultList = new List<GzResult>();
            var orderStatus = new orderStatusReportParme() {
                orderName = model.TaskID,
                agvIDList = model.ForkliftNo,
                orderStatus = "waiting",
            };
            var temp1 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp1);
 
            orderStatus.orderStatus = "source_finish";
            var temp2 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp2);
 
            return gzResults;
        }
 
        /// <summary>
        /// AGV状态一键回报62-国自
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("AGVSeriesReports-62")]
        public GzResults AGVSeriesReports62(UpdateTaskState model) {
            GzResults gzResults = new GzResults();
            gzResults.GzResultList = new List<GzResult>();
            var orderStatus = new orderStatusReportParme() {
                orderName = model.TaskID,
                agvIDList = model.ForkliftNo,
                orderStatus = "dest_finish",
            };
 
            var temp3 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp3);
 
            orderStatus.orderStatus = "finish";
            var temp4 = GZRobot.orderStatusReport(orderStatus);
            gzResults.GzResultList.Add(temp4);
 
            return gzResults;
        }
 
        ///// <summary>
        ///// 初始化数据库
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost]
        //[Route("CreateDatabase")]
        //public string CreateDatabase(CoverInfo model) {
        //    try {
        //        var db = new SqlHelper<object>().GetInstance();
        //        var cover = model.IsCover;
 
        //        var entityTypes = new Type[] {
        //            typeof(TN_CAR_IN),
        //            typeof(TN_CG_Detail),
        //            typeof(TN_Container),
        //            typeof(TN_Loc_Container),
        //            typeof(TN_Location),
        //            typeof(TN_Task),
        //            typeof(TN_Task_Action),
        //            typeof(SYSHelper.OI_SYS_MAXID),
 
        //            typeof(TN_Count_Plan),
        //            typeof(TN_Count_Order),
        //            typeof(TN_Count_CG_Detail),
        //            typeof(TN_Count_Diff),
        //        };
 
        //        using (var tran = db.Ado.UseTran()) {
        //            if (cover) {
        //                // 删除所有表(按依赖关系倒序)
        //                var tables = db.DbMaintenance.GetTableInfoList();
        //                foreach (var table in tables.OrderByDescending(t => t.Name)) {
        //                    db.DbMaintenance.DropTable(table.Name);
        //                }
 
        //                // 创建新表
        //                db.CodeFirst.InitTables(entityTypes);
 
        //                //db.CodeFirst.BackupTable().InitTables(entityTypes);
        //            }
        //            else {
        //                db.CodeFirst.InitTables(entityTypes);
        //            }
 
        //            tran.CommitTran();
        //        }
 
        //    }
        //    catch (Exception ex) {
        //        LogHelper.Info($"发生了异常");
        //        return "初始化数据库错误" + ex.Message;
        //    }
 
        //    return "成功";
        //}
 
        /// <summary>
        /// DEBUG:插入货位、容器、货品信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("InsertLocCntrCg")]
        public string InsertLocCntrCg(LocCntrCg locCntrCg) {
            var db = new SqlHelper<object>().GetInstance();
 
            try {
                using (var tran = db.UseTran()) {
                    LogHelper.Info("LogCntrCg:" + JsonConvert.SerializeObject(locCntrCg));
                    if (string.IsNullOrEmpty(locCntrCg.LocCode)) {
                        return "参数非法";
                    }
 
                    var loc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrCg.LocCode);
                    if (loc == null) {
                        var newLoc = new TN_Location {
                            S_CODE = locCntrCg.LocCode,
                            S_AREA_CODE = locCntrCg.LocArea ?? ""
                        };
 
                        if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) {
                            tran.RollbackTran();
                            LogHelper.Info($"插入位置{locCntrCg.LocCode}失败");
                            return "插入失败";
                        }
 
                        loc = newLoc;
                    }
 
                    //if (loc.N_CURRENT_NUM == 0) {
                    //    loc.N_CURRENT_NUM = 1;
                    //    if (db.Updateable<TN_Location>(loc).UpdateColumns(
                    //        it => new { it.N_CURRENT_NUM, it.T_MODIFY }).ExecuteCommand() <= 0) {
                    //        tran.RollbackTran();
                    //        LogHelper.Info($"修改位置{locCntrCg.LocCode}失败");
                    //        continue;
                    //    }
                    //}
 
                    if (string.IsNullOrEmpty(locCntrCg.CntrCode)) {
                        tran.CommitTran();
                        LogHelper.Info("容器号为空,不再读取后面的数据");
                        return "容器号为空,不再读取后面的数据";
                    }
 
                    var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_LOC_CODE == locCntrCg.LocCode
                        && a.S_CNTR_CODE == locCntrCg.CntrCode);
 
                    if (locCntrRel == null) {
                        var newLocCntrRel = new TN_Loc_Container {
                            S_LOC_CODE = locCntrCg.LocCode,
                            S_CNTR_CODE = locCntrCg.CntrCode
                        };
 
                        loc.N_CURRENT_NUM = 1;
 
                        if (db.Insertable<TN_Loc_Container>(newLocCntrRel).ExecuteCommand() <= 0
                            && db.Updateable<TN_Location>(loc).UpdateColumns(c => c.N_CURRENT_NUM).ExecuteCommand() <= 0) {
                            tran.RollbackTran();
                            LogHelper.Info($"插入位置托盘关系{locCntrCg.LocCode}-{locCntrCg.CntrCode}失败");
                            return "插入失败";
                        }
                    }
 
                    if (string.IsNullOrEmpty(locCntrCg.ItemCode)) {
                        tran.CommitTran();
                        LogHelper.Info("物料号为空,不再读取后面的数据");
                        return "物料号为空,不再读取后面的数据";
                    }
 
                    var cgDetail = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == locCntrCg.CntrCode
                        && a.S_ITEM_CODE == locCntrCg.ItemCode);
                    if (cgDetail == null) {
                        var locList = new List<TN_CG_Detail>();
                        locList.Add(new TN_CG_Detail { S_CNTR_CODE = locCntrCg.CntrCode, S_ITEM_CODE = locCntrCg.ItemCode, S_BATCH_NO = locCntrCg.BatchNo ?? "" });
                        if (db.Insertable<TN_CG_Detail>(locList).ExecuteCommand() <= 0) {
                            tran.RollbackTran();
                            LogHelper.Info($"插入托盘物料关系{locCntrCg.CntrCode}-{locCntrCg}失败");
                            return "插入失败";
                        }
                    }
                    tran.CommitTran();
                }
 
                return "插入数据成功";
 
            }
            catch (Exception ex) {
                return $"{ex.Message}";
            }
        }
 
        /// <summary>
        /// DEBUG:根据任务号设置物料重量
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("SetTaskWeight")]
        public string SetTaskWeight(SetTaskWeightInfo model) {
            var db = new SqlHelper<object>().GetInstance();
            var cgDetail = db.Queryable<TN_CG_Detail, TN_Task>((d, t) => d.S_CNTR_CODE == t.S_CNTR_CODE)
                .Where((d, t) => t.S_CODE == model.TaskNo).First();
 
            if (cgDetail == null) {
                return "找不到对应的物料信息";
            }
 
            cgDetail.F_QTY = model.Weight;
 
            try {
                if (db.Updateable<TN_CG_Detail>(cgDetail).UpdateColumns(it => it.F_QTY)
                    .ExecuteCommand() <= 0) {
                    return "修改失败";
                }
                return "修改成功";
 
            }
            catch (Exception ex) {
 
                return ex.Message;
            }
        }
    }
 
    public class ReturnResults {
        public List<ReturnResult> ResultList { set; get; }
    }
 
    public class GzResults {
        public List<GzResult> GzResultList { set; get; }
    }
 
    public class LocCntrCg {
        public string LocCode { get; set; }
        public string LocArea { get; set; }
        public string CntrCode { get; set; }
        public string ItemCode { get; set; }
        public string BatchNo { get; set; }
    }
 
    /// <summary>
    /// 模拟 AGV 传递信号,用于更改任务状态
    /// </summary>
    public class UpdateTaskState {
        /// <summary>
        /// 任务ID
        /// </summary>
        public string TaskID { set; get; }
        /// <summary>
        /// AGV 小车号
        /// </summary>
        public string ForkliftNo { set; get; }
        /// <summary>
        /// AGV 下一个状态
        /// </summary>
        public int NextState { set; get; }
    }
 
    public class CoverInfo {
        public bool IsCover { set; get; } = true;
    }
 
    public class SetTaskWeightInfo {
        public string TaskNo { set; get; }
        public float Weight { set; get; }
    }
}