kazelee
3 天以前 1b6bf29ff7daa1987de65940af52f452cabd6881
优化AGV任务部分日志、货位绑定内部方法
9个文件已修改
5个文件已删除
204 ■■■■ 已修改文件
.gitignore 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/8f40c4eb-5494-4624-8837-7798ba225e13.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/a42b25e2-c082-4566-872c-fb64d2329cec.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/b33d2c5b-1765-4994-b034-1c71a27c4905.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/de1cdb9f-9ed9-418c-ad35-f953526016d4.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/read.lock 补丁 | 查看 | 原始文档 | blame | 历史
HH.WCS.Mobox3.DSZSH.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/ApiModel.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/DebugController.cs 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
core/WCSCore.cs 75 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/ProductionLineDevice.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
process/TaskProcess.cs 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
util/LogHelper.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
wms/LocationHelper.cs 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -185,3 +185,6 @@
# Microsoft Fakes
FakesAssemblies/
/.vs/HH.WCS.Mobox3.DSZSH/CopilotIndices/17.14.794.21998/
/.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/
/.vs/HH.WCS.Mobox3.DSZSH/v17/
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/8f40c4eb-5494-4624-8837-7798ba225e13.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/a42b25e2-c082-4566-872c-fb64d2329cec.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/b33d2c5b-1765-4994-b034-1c71a27c4905.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/de1cdb9f-9ed9-418c-ad35-f953526016d4.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.DSZSH/FileContentIndex/read.lock
HH.WCS.Mobox3.DSZSH.csproj
@@ -293,6 +293,7 @@
    <None Include="packages.config" />
  </ItemGroup>
  <ItemGroup>
    <Content Include=".gitignore" />
    <Content Include="readme.md" />
    <EmbeddedResource Include="swagger.js">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
api/ApiModel.cs
@@ -79,7 +79,8 @@
            public string ResultMsg { get; set; }
        }
        public static ReturnResult NewReturnResult(int code, string message) {
        public static ReturnResult NewReturnResult(int code, string message, bool log = true) {
            if (log) { LogHelper.Info(message); }
            return new ReturnResult { ResultCode = code, ResultMsg = message };
        }
api/DebugController.cs
@@ -400,10 +400,6 @@
        /// AGV 小车号
        /// </summary>
        public string ForkliftNo { set; get; }
        ///// <summary>
        ///// AGV 下一个状态
        ///// </summary>
        //public int NextState { set; get; }
    }
    public class AgvReportsInfo {
@@ -421,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>
@@ -437,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; }
    }
}
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)) {
@@ -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}");
            }
        }
device/ProductionLineDevice.cs
@@ -51,20 +51,6 @@
        /// </summary>
        public int AllowAgvPlacePallet { get; set; }
        //private int _agvPicking;
        //private int _agvPlacingPallet;
        ///// <summary>
        ///// AGV 正在取货:下线AGV写入1,取货完成后恢复0
        ///// </summary>
        //public int AgvPicking {
        //    get => _agvPicking;
        //    set {
        //        var isOk = ModbusHelper.WriteSingleRegister(10, value, Ip, Port);
        //        _agvPicking = isOk ? value : throw new Exception($"修改 [AGV 正在取货] 为 '{value}' 失败");
        //    }
        //}
        /// <summary>
        /// AGV 正在取货:下线AGV写入1,取货完成后恢复0
        /// </summary>
@@ -83,17 +69,6 @@
            AgvPicking = value;
            return true;
        }
        ///// <summary>
        ///// AGV 正在放托盘垛:上线AGV写入1,放托完成后恢复0
        ///// </summary>
        //public int AgvPlacingPallet {
        //    get => _agvPlacingPallet;
        //    set {
        //        var isOk = ModbusHelper.WriteSingleRegister(11, value, Ip, Port);
        //        _agvPlacingPallet = isOk ? value : throw new Exception($"修改 [AGV 正在放托盘垛] 为 '{value}' 失败");
        //    }
        //}
        /// <summary>
        /// AGV 正在放托盘垛:上线AGV写入1,放托完成后恢复0
@@ -124,8 +99,6 @@
            CallPallet = readArray[2];
            AllowAgvPlacePallet = readArray[3];
            // 可写地址数据
            //_agvPicking = readArray[10];
            //_agvPlacingPallet = readArray[11];
            AgvPicking = readArray[10];
            AgvPlacingPallet = readArray[11];
process/TaskProcess.cs
@@ -18,7 +18,7 @@
        /// </summary>
        /// <param name="mst"></param>
        /// <param name="load"></param>
        internal static void CacheBitUpdate(TN_Task mst, bool load) {
        internal static void BufferLocUpdate(TN_Task mst, bool load) {
            //var trayCarryCount = mst.N_CNTR_COUNT > 0 ? mst.N_CNTR_COUNT : 1;
            if (load) {
                Console.WriteLine($"任务{mst.S_CODE} 货位{mst.S_START_LOC}取货完成,起点解绑容器{mst.S_CNTR_CODE}");
@@ -37,12 +37,12 @@
        /// 任务取消,缓存位状态更新
        /// </summary>
        /// <param name="mst"></param>
        internal static void CacheBitCancelUpdate(TN_Task mst) {
        internal static void BufferLocCancelUpdate(TN_Task mst) {
            //任务取消,取货完成前的,起点的loadingCount和终点unLoadingCount都清除,取货完成的只处理终点
            if (WCSHelper.CheckActionRecordExist(mst.S_CODE, 4)) {
                //根据客户现场要求,如果取货完成任务失败人工拉到终点,我们就当卸货完成处理;如果是人工拉走到其它区域,我们就解锁终点,删除托盘。
                //终点绑定
                CacheBitUpdate(mst, false);
                BufferLocUpdate(mst, false);
                LocationHelper.UnLockLoc(mst.S_END_LOC);
            }
            else {
@@ -62,14 +62,14 @@
        /// <param name="state"></param>
        internal static void OperateStatus(TN_Task mst, int state) {
            if (state == 4) {
                CacheBitUpdate(mst, true);
                BufferLocUpdate(mst, true);
            }
            if (state == 6)//卸货完成
            {
                CacheBitUpdate(mst, false);
                BufferLocUpdate(mst, false);
            }
            if (state == 7) {
                CacheBitCancelUpdate(mst);
                BufferLocCancelUpdate(mst);
            }
        }
util/LogHelper.cs
@@ -80,7 +80,7 @@
        }
        public static void InfoHostToAGV(string taskName, object model) {
            Info($"AGV任务:" + JsonConvert.SerializeObject(model), "HosttoagvTask");
            Info($"AGV任务:{taskName}" + JsonConvert.SerializeObject(model), "HosttoagvTask");
        }
        #endregion
wms/LocationHelper.cs
@@ -98,22 +98,6 @@
                        {
                            site = Location.S_AGV_SITE;
                        }
                        //if (Location.N_CURRENT_NUM == 1)
                        //{
                        //    site = Location.S_AGV_SITE2;
                        //}
                        //if (Location.N_CURRENT_NUM == 2)
                        //{
                        //    site = Location.S_AGV_SITE3;
                        //}
                        //if (Location.N_CURRENT_NUM == 3)
                        //{
                        //    site = Location.S_AGV_SITE4;
                        //}
                        //if (Location.N_CURRENT_NUM == 4)
                        //{
                        //    site = Location.S_AGV_SITE5;
                        //}
                    }
                }
            }
@@ -180,30 +164,8 @@
                    location.S_LOCK_STATE = "无";
                    location.N_LOCK_STATE = 0;
                    //var containerList = new List<TN_Container>();
                    //foreach (var item in lcrList) {
                    //    // 针对容器类型添加的新逻辑
                    //    var cntr = db.Queryable<TN_Container>()
                    //        .Where(c => c.S_CODE == item.S_CNTR_CODE).First();
                    //    if (cntr == null) {
                    //        LogHelper.Info($"货位解绑时,容器{item.S_CNTR_CODE}没有在容器信息表中查到,这里根据货位容器关系添加");
                    //        containerList.Add(new TN_Container {
                    //            S_CODE = item.S_CNTR_CODE,
                    //            S_TYPE = item.S_CNTR_TYPE,
                    //        });
                    //    }
                    //}
                    using (var tran = db.Ado.UseTran())
                    {
                        //if (containerList.Count > 0) {
                        //    if (db.Insertable<TN_Container>(containerList).ExecuteCommand() <= 0) {
                        //        LogHelper.Info($"插入容器信息表失败" + JsonConvert.SerializeObject(containerList));
                        //        tran.RollbackTran();
                        //        return "货位解绑容器失败," + logs;
                        //    }
                        //}
                        if (db.Deleteable<TN_Loc_Container>().Where(it => cntrs.Contains(it.S_CNTR_CODE) && it.S_LOC_CODE == loc).ExecuteCommand() > 0)
                        {
                            LogHelper.Info($"删除货位容器关系表成功,{log}");
@@ -259,20 +221,16 @@
            var logs = $"货位:{loc},容器:{JsonConvert.SerializeObject(cntrs)}";
            try
            {
                // 删除已经绑定过的容器记录
                var lcrList = db.Queryable<TN_Loc_Container>().Where(a => cntrs.Contains(a.S_CNTR_CODE) && a.S_LOC_CODE == loc).ToList();
                if (lcrList.Count > 0)
                {
                if (lcrList.Count > 0) {
                    cntrs = cntrs.Except(lcrList.Select(a => a.S_CNTR_CODE).ToList()).ToList();
                }
                var bindLocCntList = new List<TN_Loc_Container>();
                foreach (var item in cntrs)
                {
                foreach (var item in cntrs) {
                    // 针对容器类型添加的新逻辑
                    var cntr = db.Queryable<TN_Container>()
                        .Where(c => c.S_CODE == item)
                        .First();
                    var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == item).First();
                    if (cntr == null) {
                        LogHelper.Info($"货位解绑时,容器{item}没有在容器信息表中查到,不记录容器类型");
@@ -287,16 +245,12 @@
                using (var tran = db.Ado.UseTran())
                {
                    if (db.Insertable<TN_Loc_Container>(bindLocCntList).ExecuteCommand() > 0)
                    {
                        LogHelper.Info($"插入货位容器关系表成功,{log}");
                    }
                    else
                    {
                    if (db.Insertable<TN_Loc_Container>(bindLocCntList).ExecuteCommand() <= 0) {
                        db.RollbackTran();
                        LogHelper.Info($"插入货位容器关系表失败,{log}");
                        return "货位绑定容器失败," + logs;
                    }
                    LogHelper.Info($"插入货位容器关系表成功,{log}");
                    var location = db.Queryable<TN_Location>().First(a => a.S_CODE == loc);
                    if (location != null)