AGVManager.cs 4.3 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AGVControl;
using System.Web.Script.Serialization;

namespace BLL
{
    public class AGVManager
    {
        private static string Addr_getShelfLockInfo = "/rest/api/qisda/device/getShelfLockInfo"; //包装仓获取料架锁定状态地址

        public static bool GetShelfLockInfo(string rfid, out List<string> shelfLockNodeNames)
        {
            string msg = "";
            shelfLockNodeNames = null;
            try
            {
                Dictionary<string, string> paramMap = new Dictionary<string, string>();
                paramMap.Add("rfid", rfid);

                string server = GetAddr(Addr_getShelfLockInfo, paramMap);
                DateTime startTime = DateTime.Now;

                string resultStr = HttpHelper.Post(server, "");

                Common.log.OutInfo( "料架锁定状态 "  + " 【" + server + "】【" + resultStr + "】");

                ShelfLockInfo serverResult = JsonHelper.DeserializeJsonToObject<ShelfLockInfo>(resultStr);
                if (serverResult == null)
                {
                    msg =  " 没有收到服务器反馈";
                    Common.log.OutInfo(msg);
                    return false;
                }

                if (serverResult.data.Count == 0) //该料架未锁定
                {
                    msg = " 料架【" + rfid + "】 没有锁定库位的料";
                    Common.log.OutInfo(msg);
                    return false;
                }
                else //该料架存在锁定库位的料
                {
                    shelfLockNodeNames = new List<string>();
                    foreach (ShelfLockData item in serverResult.data)
                    {                      
                        if(!shelfLockNodeNames.Contains(Common.webService[item.cid]))
                        {
                            shelfLockNodeNames.Add(Common.webService[item.cid]);
                            Common.log.OutInfo("锁定的CID=" + item.cid + ";节点名称=" + Common.webService[item.cid]);
                        }
                    }
                    Common.log.OutInfo("获取料架上的料仓信息完成");
                    return true;
                }
            }
            catch (Exception ex)
            {
                Common.log.OutInfo( ex.Message);
            }
            return false;
        }

        private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
        {
            string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
            if (server.EndsWith("/"))
            {
                server = server.Substring(0, server.Length - 1);
            }
            string path = server + addr.Trim() + "?";
            foreach (string paramName in paramsMap.Keys)
            {
                string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
                path += paramName + "=" + par + "&";
            }
            path = path.Substring(0, path.Length - 1);
            return path;
        }
    }
    public class ShelfLockInfo
    {
        //返回: {"code":0,"msg":"ok","data":
        //[{"barcode":"S20052301213","cid":"packing-20","rfid":"A12","rfidLoc":"3","lockPos":"4D2001AA0006","lockPosId":"1231"}]}
        /// <summary>
        /// 返回码,0为正常,其他为异常
        /// </summary>
        public int code { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string msg { get; set; }

        public List<ShelfLockData> data { get; set; }
    }

    public class ShelfLockData
    {
        /// <summary>
        /// 库位中料盘的条码
        /// </summary>
        public string barcode { get; set; }
        /// <summary>
        /// 库位中料盘的锁定库位对应的料仓编
        /// </summary>
        public string cid { get; set; }
        /// <summary>
        /// 料架RFID
        /// </summary>
        public string rfid { get; set; }
        /// <summary>
        /// 料架的库位
        /// </summary>
        public int rfidLoc { get; set; }
        /// <summary>
        /// 库位中料盘的锁定库位
        /// </summary>
        public string lockPos { get; set; }

    }
}