kazelee
7 天以前 00aaf49a223be04fc58f6f7c09d95ce4b22ef087
api/DebugController.cs
@@ -100,155 +100,25 @@
            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();
        [Route("CreateDatabase")]
        public string CreateDatabase() {
            try {
                using (var tran = db.UseTran()) {
                    LogHelper.Info("LogCntrCg:" + JsonConvert.SerializeObject(locCntrCg));
                    if (string.IsNullOrEmpty(locCntrCg.LocCode)) {
                        return "参数非法";
                    }
                var db = new SqlHelper<object>().GetInstance();
                    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 ?? ""
                        };
                var entityTypes = new Type[] { };
                        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 "插入数据成功";
                //db.CodeFirst.InitTables(entityTypes);
            }
            catch (Exception ex) {
                return $"{ex.Message}";
                LogHelper.Info($"发生了异常");
                return "初始化数据库错误" + ex.Message;
            }
            return "成功";
        }
        /// <summary>
@@ -310,14 +180,6 @@
        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>
@@ -334,10 +196,6 @@
        /// AGV 下一个状态
        /// </summary>
        public int NextState { set; get; }
    }
    public class CoverInfo {
        public bool IsCover { set; get; } = true;
    }
    public class SetTaskWeightInfo {