kazelee
2025-05-28 de8cd5585ba690902333cf4ce9aa5dbc7eb9acf6
api/DebugController.cs
@@ -66,9 +66,11 @@
        /// <returns></returns>
        [HttpPost]
        [Route("CreateDatabase")]
        public string CreateDatabase(CoverInfo model) {
            var cover = model.IsCover;
        public string CreateDatabase(FalseOk model) {
            try {
                if (model.JumpOut) {
                    return "跳出";
                }
                var db = new SqlHelper<object>().GetInstance();
                var entityTypes = new Type[] { 
@@ -82,41 +84,92 @@
                    //typeof(SysHelper.OI_SYS_MAXID),
                    //typeof(TN_Inbound_Order),
                    typeof(TN_Check_Detail),
                    //typeof(TN_Check_Detail),
                    //typeof(TN_Check_Order),
                    //typeof(TN_CNTR_ITEM),
                    //typeof(TN_Outbound_Detail),
                    //typeof(TN_Outbound_Order),
                    //typeof(TN_Shift_Order),
                    //typeof(TN_Shift_Detail)
                    //typeof(TN_Container_Item),
                };
                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);
                        //}
                //var areaNameList = new List<string>();
                //foreach (var area in Settings.Areas) {
                //    areaNameList.AddRange(area.Codes);
                //}
                        // 创建新表
                        db.CodeFirst.InitTables(entityTypes);
                //var locationList = new List<TN_Location>();
                //foreach (var area in areaNameList) {
                //    int i = 0;
                //    int j = 0;
                //    int k = 0;
                        //db.CodeFirst.BackupTable().InitTables(entityTypes);
                    }
                    else {
                        db.CodeFirst.InitTables(entityTypes);
                    }
                //    if (area == "KXHJQ" || area == "MTHJQ" || area == "MXHJQ") {
                //        for (i = 1; i <= 4; i++) {
                //            for (j = 1; j <= 5; j++) {
                //                for (k = 1; k <= 3; k++) {
                //                    locationList.Add(new TN_Location() {
                //                        N_ROW = i,
                //                        N_COL = j,
                //                        N_LAYER = k,
                //                        S_AREA_CODE = area,
                //                        S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}" +
                //                        $"-{k.ToString().PadLeft(2, '0')}"
                //                    });
                //                }
                //            }
                //        }
                //        continue;
                //    }
                    tran.CommitTran();
                }
                //    if (area == "BZQ") {
                //        for (i = 1; i <= 2; i++) {
                //            for (j = 1; j <= 2; j++) {
                //                locationList.Add(new TN_Location() {
                //                    N_ROW = i,
                //                    N_COL = j,
                //                    S_AREA_CODE = area,
                //                    S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}"
                //                });
                //            }
                //        }
                //        continue;
                //    }
                //    i = 1;
                //    for (j = 1; j <= 5; j++) {
                //        locationList.Add(new TN_Location() {
                //            N_ROW = i,
                //            N_COL = j,
                //            S_AREA_CODE = area,
                //            S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}"
                //        });
                //    }
                //}
                //using (var tran = db.Ado.UseTran()) {
                //    //db.CodeFirst.InitTables(entityTypes);
                //    if (db.Insertable<TN_Location>(locationList).ExecuteCommand() <= 0) {
                //        tran.RollbackTran();
                //        return "失败";
                //    }
                //    tran.CommitTran();
                //}
            }
            catch (Exception ex) {
                LogHelper.Info($"发生了异常");
                return "初始化数据库错误" + ex.Message;
            }
            return "成功";
        }
@@ -203,6 +256,68 @@
                return $"Error reading CSV file: {ex.Message}";
            }
        }
        /// <summary>
        /// DEBUG:根据容器物料信息表,插入容器物料登记信息表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("InsertContainerItemByCgDetail")]
        public string InsertContainerItemByCgDetail(FalseOk _) {
            var db = new SqlHelper<object>().GetInstance();
            try {
                var cgDetailList = db.Queryable<TN_CG_Detail>().ToList();
                var cntrItemList = new List<TN_Container_Item>();
                foreach (var cgDetail in cgDetailList) {
                    if (db.Queryable<TN_Container_Item>().Where(i => i.S_CNTR_CODE == cgDetail.S_CNTR_CODE).Any()) {
                        continue;
                    }
                    cntrItemList.Add(new TN_Container_Item {
                        S_CNTR_CODE = cgDetail.S_CNTR_CODE,
                        S_ITEM_CODE = cgDetail.S_ITEM_CODE,
                    });
                }
                if (db.Insertable<TN_Container_Item>(cntrItemList).ExecuteCommand() <= 0) {
                    return "插入失败";
                }
                return "插入成功";
            }
            catch (Exception ex) {
                LogHelper.InfoEx(ex);
                return ex.Message;
            }
        }
        /// <summary>
        /// DEBUG:根据容器物料信息表,插入容器物料登记信息表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("InsertContainerItem")]
        public string InsertContainerItem(InsertCntrItemInfo cgDetail) {
            var db = new SqlHelper<object>().GetInstance();
            try {
                var cntrItem = new TN_Container_Item {
                    S_CNTR_CODE = cgDetail.Cntr,
                    S_ITEM_CODE = cgDetail.Item,
                };
                if (db.Insertable<TN_Container_Item>(cntrItem).ExecuteCommand() <= 0) {
                    return "插入失败";
                }
                return "插入成功";
            }
            catch (Exception ex) {
                LogHelper.InfoEx(ex);
                return ex.Message;
            }
        }
    }
    /// <summary>
@@ -223,8 +338,13 @@
        public int NextState { set; get; }
    }
    public class CoverInfo {
        public bool IsCover { set; get; } = false;
    public class FalseOk {
        public bool JumpOut { set; get; } = true;
    }
    public class InsertCntrItemInfo {
        public string Cntr { set; get; }
        public string Item { set; get; }
    }
    /// <summary>