kazelee
1 天以前 74ca5a83f24c53c48ad7e6f5b7739649fb411546
core/WCSCore.cs
@@ -22,29 +22,20 @@
namespace HH.WCS.Mobox3.DSZSH.core {
    public class WCSCore {
        public static ReturnResult OperateAgvTaskStatus(AgvTaskState model) {
            var result = new ReturnResult();
            const string preLog = "AGV:任务状态回报:";
            try {
                if (model.state > 0) {
                    // AGV 执行任务的逻辑处理
                    if (!AgvTaskProcessOk(model)) {
                        // 执行不OK,说明没有找到任务
                        result.ResultCode = 1;
                        result.ResultMsg = $"根据Model.No未找到对应的任务,{model.task_no}";
                        LogHelper.Info(result.ResultMsg, "API");
                        return result;
                        return NewReturnResult(1, preLog + $"根据任务号'{model.task_no}'未找到对应的任务!");
                    }
                }
                result.ResultCode = 0;
                result.ResultMsg = "success";
                LogHelper.Info(result.ResultMsg, "API");
                return result;
                return NewReturnResult(0, "success"); // 不返回详细成功日志,避免NDC以msg=success作为成功判定(参考国自)
            }
            catch (Exception ex) {
                result.ResultCode = -1;
                result.ResultMsg = $"发生了异常:{ex.Message}";
                LogHelper.Info(result.ResultMsg, "Error");
                return result;
                return NewReturnResult(-1, $"发生了异常:{ex.Message}\n{ex.StackTrace}");
            }
        }
@@ -147,7 +138,7 @@
                var isInbound = false; // 入库类型的任务(包括移库类任务)
                var inboundTasks = new List<string> {
                    ETask.M满托下线入库.Name(), ETask.K空箱入库.Name(), ETask.M满托下线入库.Name(), ETask.K空托入库.Name(),
                    ETask.M满托下线入库.Name(), ETask.M满箱下线入库.Name(), ETask.K空托入库.Name(), ETask.K空箱入库.Name(),
                    ETask.C抽检合格回库.Name(), ETask.C抽检不合格移库.Name(), ETask.Y移库.Name()
                };
                if (inboundTasks.Contains(task.S_TYPE)) {
@@ -183,7 +174,7 @@
                };
                // 数据库操作
                if (db.Insertable<TN_Record_Table>(record).ExecuteCommand() <= 0) {
                if (db.Insertable(record).ExecuteCommand() <= 0) {
                    info = "插入出入库记录表失败:" + JsonConvert.SerializeObject(record);
                    LogHelper.Info(info);
                    return;
@@ -204,7 +195,7 @@
        /// <returns></returns>
        public static ReturnResult SafetyInteraction(SafetyInteractionInfo model) {
            var db = new SqlHelper<object>().GetInstance();
            var info = "";
            const string preLog = "AGV:产线安全交互:";
            try {
                ModbusHelper.Relink();
@@ -214,24 +205,18 @@
                    .Where(l => BZQ.Contains(l.S_AREA_CODE) && l.S_AGV_SITE == model.station_name).First();
                if (loc == null) {
                    info = $"AGV 站点{model.station_name}不是合法的产线接驳位站点";
                    LogHelper.Info(info);
                    return NewReturnResult(1, info);
                    return NewReturnResult(1, preLog + $"AGV 站点{model.station_name}不是合法的产线接驳位站点");
                }
                if (!Settings.LocProdIdMap.TryGetValue(loc.S_CODE, out var prodIndex)) {
                    info = $"AGV 站点{model.station_name}不是合法的产线接驳位站点";
                    LogHelper.Info(info);
                    return NewReturnResult(1, info);
                    return NewReturnResult(1, preLog + $"AGV 站点{model.station_name}不是合法的产线接驳位站点");
                }
                var prodLineInfo = Settings.ProductionLines[prodIndex];
                var prodLineDevice = new ProductionLineDevice(prodLineInfo);
                if (!prodLineDevice.LoadDeviceStateOk()) {
                    info = "与产线设备通讯失败";
                    LogHelper.Info(info);
                    return NewReturnResult(2, info);
                    return NewReturnResult(2, preLog + "与产线设备通讯失败");
                }
                //var tn_task = db.Queryable<TN_Task>().First(a => a.S_CODE == model.task_no);
@@ -248,56 +233,40 @@
                //}
                if (prodLineDevice.SystemState != 1) {
                    info = $"当前产线无法与AGV联动:状态{prodLineDevice.SystemState}";
                    LogHelper.Info(info);
                    return NewReturnResult(3, info);
                    return NewReturnResult(3, preLog + $"当前产线无法与AGV联动:状态{prodLineDevice.SystemState}");
                }
                if (model.apply_code == "5") { // 请求取货
                // 请求取货
                if (model.apply_code == "5") {
                    if (prodLineDevice.FullOffline != 1) {
                        info = $"当前输送线满料下线信号不为1,无法取货";
                        LogHelper.Info(info);
                        return NewReturnResult(4, info);
                        return NewReturnResult(4, preLog + $"当前输送线满料下线信号不为1,无法取货");
                    }
                    
                    if (!prodLineDevice.SetAgvPicking(1)) {
                        info = $"向输送线写入允许取货信号失败";
                        LogHelper.Info(info);
                        return NewReturnResult(5, info);
                        return NewReturnResult(5, preLog + $"向输送线写入允许取货信号失败");
                    }
                    
                    info = $"向输送线写入允许取货信号成功";
                    LogHelper.Info(info);
                    return NewReturnResult(0, info);
                    return NewReturnResult(0, preLog + $"向输送线写入允许取货信号成功");
                }
                else if (model.apply_code == "1") { // 请求卸货
                // 请求卸货
                else if (model.apply_code == "1") {
                    if (prodLineDevice.AllowAgvPlacePallet != 1) {
                        info = $"当前输送线允许放托盘信号不为1,无法放货";
                        LogHelper.Info(info);
                        return NewReturnResult(6, info);
                        return NewReturnResult(6, preLog + $"当前输送线允许放托盘信号不为1,无法放货");
                    }
                    if (!prodLineDevice.SetAgvPlacingPallet(1)) {
                        info = $"向输送线写入允许放货信号失败";
                        LogHelper.Info(info);
                        return NewReturnResult(7, info);
                        return NewReturnResult(7, preLog + $"向输送线写入允许放货信号失败");
                    }
                    info = $"向输送线写入允许放货信号成功";
                    LogHelper.Info(info);
                    return NewReturnResult(0, info);
                    return NewReturnResult(0, preLog + $"向输送线写入允许放货信号成功");
                }
                else {
                    info = $"当前AGV请求码不为 5取货 或 1卸货";
                    LogHelper.Info(info);
                    return NewReturnResult(8, info);
                    return NewReturnResult(8, preLog + $"当前AGV请求码不为 5取货 或 1卸货");
                }
            }
            catch (Exception ex) {
                info = $"发生了异常:{ex.Message}";
                LogHelper.InfoEx(ex);
                return NewReturnResult(1, info);
                return NewReturnResult(1, preLog + $"发生了异常:{ex.Message}\n{ex.StackTrace}");
            }
        }
@@ -315,7 +284,7 @@
            using (var tran = db.Ado.UseTran()) {
                detail.N_B_STATE = spotStateCode;
                if (db.Updateable<TN_Outbound_Detail>(detail).UpdateColumns(it => it.N_B_STATE).ExecuteCommand() <= 0) {
                if (db.Updateable(detail).UpdateColumns(it => it.N_B_STATE).ExecuteCommand() <= 0) {
                    tran.RollbackTran();
                    LogHelper.Info($"{taskName}:AGV取货:修改明细单状态为【3任务执行完成】失败!");
                    return;
@@ -432,7 +401,7 @@
                plan.SFJS = model.sfjs;
                plan.SFSL = model.sfsl;
                plan.HWZT = model.hwzt;
                var success = db.Updateable<TN_Outbound_Plan>(plan).UpdateColumns(p => new { p.SFJS, p.SFSL, p.HWZT }).ExecuteCommand() > 0;
                var success = db.Updateable(plan).UpdateColumns(p => new { p.SFJS, p.SFSL, p.HWZT }).ExecuteCommand() > 0;
                info = "更新出库计划单记录表" + (success ? "成功" : "失败");
                LogHelper.Info(info);
            }
@@ -578,12 +547,12 @@
                var cntId = locCntrRel.S_CNTR_CODE;
                var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName);
                LocationHelper.LockStartLoc(ref startLoc); // 起点出库锁
                LocationHelper.LockEndLoc(ref endLoc); // 终点入库锁
                WCSHelper.LockStartLoc(ref startLoc); // 起点出库锁
                WCSHelper.LockEndLoc(ref endLoc); // 终点入库锁
                using (var tran = db.Ado.UseTran()) {
                    if (locCntrRelOld != null) {
                        if (db.Deleteable<TN_Loc_Container>(locCntrRelOld).ExecuteCommand() <= 0 &&
                        if (db.Deleteable(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}";
@@ -592,14 +561,14 @@
                        }
                    }
                    if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) {
                    if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        info = $"插入货位容器关系表失败:货位编码{locCntrRel.S_LOC_CODE},容器编码{locCntrRel.S_CNTR_CODE}";
                        LogHelper.Info(info);
                        return new Result<bool>(false, info);
                    }
                    if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new {
                    if (db.Updateable(startLoc).UpdateColumns(it => new {
                        it.N_LOCK_STATE,
                        it.S_LOCK_STATE,
                        it.S_LOCK_OP,
@@ -612,7 +581,7 @@
                        return new Result<bool>(false, info);
                    }
                    if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new {
                    if (db.Updateable(endLoc).UpdateColumns(it => new {
                        it.N_LOCK_STATE,
                        it.S_LOCK_STATE,
                        it.S_LOCK_OP,
@@ -624,7 +593,7 @@
                        return new Result<bool>(false, info);
                    }
                    if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) {
                    if (db.Insertable(task).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        info = $"生成任务'{taskName}'失败,任务号={task.S_CODE},容器号={cntId},起点={startLoc.S_CODE},终点={endLoc.S_CODE}";
                        LogHelper.Info(info);
@@ -638,11 +607,15 @@
                }
            }
            catch (Exception ex) {
                LogHelper.InfoEx(ex);
                return new Result<bool>(false, ex.Message);
                return NewResult(false, ex.Message);
            }
        }
        private static Result<bool> NewResult(bool res, string msg, bool log = true) {
            if (log) { LogHelper.Info(msg); }
            return new Result<bool>(res, msg);
        }
    }
    public class ProductCompletedMessage {