kazelee
3 天以前 1b6bf29ff7daa1987de65940af52f452cabd6881
api/DebugController.cs
@@ -14,6 +14,8 @@
using SqlSugar;
using static HH.WCS.Mobox3.DSZSH.api.ApiModel;
using static HH.WCS.Mobox3.DSZSH.api.OtherModel;
using static HH.WCS.Mobox3.DSZSH.Config;
using static HH.WCS.Mobox3.DSZSH.core.Monitor;
namespace HH.WCS.Mobox3.DSZSH.api {
@@ -65,6 +67,12 @@
            return returnResult;
        }
        /// <summary>
        /// 模拟AGV回报任务状态(指定下一个状态,用于需要分段测试的场景)<br/>
        /// 性能相对较差,仅用于测试,一般不使用
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("AgvReports")]
        public ReturnResults AgvReports(AgvReportsInfo model) {
@@ -196,9 +204,9 @@
            try {
                var db = new SqlHelper<object>().GetInstance();
                var entityTypes = new Type[] {
                };
                var entityTypes = new Type[] { };
                //db.CodeFirst.InitTables(entityTypes);
            }
            catch (Exception ex) {
                LogHelper.Info($"发生了异常");
@@ -215,118 +223,150 @@
        [HttpPost]
        [Route("AddInboundTask")]
        public string AddInboundTask(AddInboundTaskInfo model) {
            return WCSCore.CreateInboundTask(model.StartLoc, model.CntrCode).Content;
        }
        /// <summary>
        /// DEBUG:模拟人工将料箱搬运到产线上线口(直接修改数据库)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GoodpackToProdLine")]
        public string GoodpackToProdLine(GoodpackToProdLineInfo model) {
            var db = new SqlHelper<object>().GetInstance();
            var info = "";
            const string taskName = TaskName.T托盘_满托下线入库;
            const string startAreaName = AreaName.B包装区;
            const string endAreaName = AreaName.M满托货架区;
            const string cntrType = "托盘";
            try {
                var cntrCode = model.CntrCode;
                var startLocCode = model.StartLoc;
                var startLoc = db.Queryable<TN_Location>()
                    .Where(l => l.S_CODE == startLocCode)
                    .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE))
                    .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y")
                    .Where(l => l.N_CURRENT_NUM == 0) // 绑定前
                    .First();
                // 查询起点货位:数量=0
                var startLoc = db.Queryable<TN_Location>().LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE)
                    .Where((l,c) => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && l.N_CURRENT_NUM == 1 && c.S_CNTR_CODE == model.CntrCode).First();
                if (startLoc == null) {
                    info = $"在'{startAreaName}'中没有找到起点货位'{startLocCode}',或不满足要求:未上锁、当前容器数量=0";
                    LogHelper.Info(info);
                    return info;
                    return $"没有找到起点货位'{model.StartLoc}'!要求:锁状态='无',当前容器数量=1";
                }
                var locCntrRelOld = db.Queryable<TN_Loc_Container>()
                    .Where(c => c.S_CNTR_CODE == cntrCode).First();
                // 绑定货位和容器号
                var locCntrRel = new TN_Loc_Container {
                    S_LOC_CODE = startLocCode,
                    S_CNTR_CODE = cntrCode,
                    S_CNTR_TYPE = cntrType,
                };
                startLoc.N_CURRENT_NUM = 1; // 绑定后
                var endLoc = db.Queryable<TN_Location>()
                    .Where(a => Settings.AreaMap[endAreaName].Contains(a.S_AREA_CODE))
                    .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无" && a.C_ENABLE == "Y") // 筛选:未上锁
                    .Where(a => a.N_CURRENT_NUM == 0) // 筛选:空货位
                    .OrderBy(l => l.N_LAYER)
                    .First();
                // 查询终点货位
                // Order:按货位层数,从小到大排列
                var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.N_CURRENT_NUM == 0).First();
                if (endLoc == null) {
                    info = $"在终点货区'{endAreaName}'中,没有找到合适的【终点货位】,需要满足要求:未上锁、当前容器数量=0";
                    LogHelper.Info(info);
                    return info;
                    return $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0";
                }
                var cntId = locCntrRel.S_CNTR_CODE;
                var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName);
                var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == model.CntrCode).First() ;
                if (locCntrRel == null) {
                    return $"该容器不存在绑定的货位!";
                }
                LocationHelper.LockStartLoc(ref startLoc); // 起点出库锁
                LocationHelper.LockEndLoc(ref endLoc); // 终点入库锁
                locCntrRel.S_LOC_CODE = model.StartLoc;
                startLoc.N_CURRENT_NUM = 0;
                endLoc.N_CURRENT_NUM = 1;
                using (var tran = db.Ado.UseTran()) {
                    if (locCntrRelOld != null) {
                        if (db.Deleteable<TN_Loc_Container>(locCntrRelOld).ExecuteCommand() <= 0 &&
                            db.Updateable<TN_Location>().SetColumns(l => l.N_CURRENT_NUM == 0).Where(l => l.S_CODE == locCntrRelOld.S_LOC_CODE).ExecuteCommand() <= 0) {
                            tran.RollbackTran();
                            info = $"删除旧货位容器关系表失败:货位编码{locCntrRelOld.S_LOC_CODE},容器编码{locCntrRelOld.S_CNTR_CODE}";
                            LogHelper.Info(info);
                            return info;
                        }
                    }
                    if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) {
                    if (db.Updateable<TN_Location>(startLoc).ExecuteCommand() <= 0 &&
                        db.Updateable<TN_Location>(endLoc).ExecuteCommand() <= 0 &&
                        db.Updateable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        info = $"插入货位容器关系表失败:货位编码{locCntrRel.S_LOC_CODE},容器编码{locCntrRel.S_CNTR_CODE}";
                        LogHelper.Info(info);
                        return info;
                        return "数据库操作失败!";
                    }
                    if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM }).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        info = $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败";
                        LogHelper.Info(info);
                        return info;
                    }
                    if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new {
                        it.N_LOCK_STATE,
                        it.S_LOCK_STATE,
                        it.S_LOCK_OP,
                        it.T_MODIFY
                    }).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        info = $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败";
                        LogHelper.Info(info);
                        return info;
                    }
                    if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        info = $"生成任务'{taskName}'失败,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}";
                        LogHelper.Info(info);
                        return info;
                    }
                    tran.CommitTran();
                    info = $"生成任务'{taskName}'成功,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}";
                    LogHelper.Info(info);
                    return info;
                    tran.CommitTran() ;
                    return "数据库操作成功";
                }
            }
            catch (Exception ex) {
                LogHelper.InfoEx(ex);
                return ex.Message;
            }
        }
        /// <summary>
        /// DEBUG:模拟Erp下发出库计划单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("TestErpSendOutboundPlan")]
        public ErpResult TestErpSendOutboundPlan(TestErpSendOutboundPlanInfo model) {
            var apiName = "ERP下发出库计划单";
            //LogHelper.InfoApi(apiName, model);
            var erpModel = new ErpSendOutboundPlanInfo();
            erpModel.jhdh = model.PlanNo;
            erpModel.cpdm = model.ItemCode;
            erpModel.pzjs = model.ItemNum;
            LogHelper.InfoApi(apiName, erpModel);
            return ApiHelper.ErpSendOutboundPlan(erpModel);
        }
        /// <summary>
        /// (内部方法请勿调用)模拟取货完成反馈Erp回报结果(默认为success)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("PickUpReturn")]
        public TestErpResult PickUpReturn(PickUpReturnErpInfo model) {
            if (model.sfjs == 0) {
                return new TestErpResult {
                    code = 1,
                    message = "实发件数未确定"
                };
            }
            return new TestErpResult {
                code = 0,
                message = "success"
            };
        }
        /// <summary>
        /// (内部方法请勿调用)模拟任务创建完成反馈Erp回报结果(默认为success)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CreateTaskReturn")]
        public TestErpResult CreateTaskReturn(CreateTaskReturnErpInfo model) {
            if (model.hw == "") {
                return new TestErpResult {
                    code = 1,
                    message = "货位信息未提供"
                };
            }
            return new TestErpResult {
                code = 0,
                message = "success"
            };
        }
    }
    public class GoodpackToProdLineInfo {
        public string CntrCode { get; set; }
        public string StartLoc { get; set; }
        public string EndLoc { get; set; }
    }
    public class TestErpSendOutboundPlanInfo {
        /// <summary>
        /// 出库计划单号(计划单号 jhdh)
        /// </summary>
        public string PlanNo { get; set; } = string.Empty;
        /// <summary>
        /// 物料编码(产品代码 cpdm)
        /// </summary>
        public string ItemCode { get; set; } = string.Empty;
        /// <summary>
        /// 物料数量(派装件数 pzjs)
        /// </summary>
        public float ItemNum { get; set; } = 0;
    }
    public class TestErpResult {
        public int code { get; set; }
        public string message { get; set; }
    }
    public class AddInboundTaskInfo {
@@ -360,10 +400,6 @@
        /// AGV 小车号
        /// </summary>
        public string ForkliftNo { set; get; }
        ///// <summary>
        ///// AGV 下一个状态
        ///// </summary>
        //public int NextState { set; get; }
    }
    public class AgvReportsInfo {
@@ -381,15 +417,6 @@
        public int NextState { set; get; } = 0;
    }
    public class FalseOk {
        public bool JumpOut { set; get; } = true;
    }
    public class InsertCntrItemInfo {
        public string Cntr { set; get; }
        public string Item { set; get; }
    }
    /// <summary>
    /// 
    /// </summary>
@@ -397,14 +424,4 @@
        public List<ReturnResult> ResultList { set; get; }
    }
    public class LocCntrCg {
        public string Note { get; set; } // 仅用于备注
        public string LocCode { get; set; }
        public string LocArea { get; set; }
        public string CntrCode { get; set; }
        public string CntrType { get; set; }
        public string ItemCode { get; set; }
        public string BatchNo { get; set; }
    }
}