AGVManager.cs 3.4 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AGVControl;
using Model;

namespace AGVControl
{
    public class AGVManager
    {
        private static string Addr_updateDeviceAlarmMsg = "/rest/api/qisda/device/updateDeviceAlarmMsg";
        /// <summary>
        /// 异常看板
        /// </summary>
        /// <param name="msgList"></param>
        /// <returns></returns>
        public static string updateDeviceAlarmMsg(List<AlarmMsg> msgList)
        {
            string msg = "";
            try
            {
                Dictionary<string, string> paramMap = new Dictionary<string, string>();
                string msgListStr = JsonHelper.SerializeObject(msgList);
                paramMap.Add("deviceAlarmList", msgListStr);
                string server = GetAddr(Addr_updateDeviceAlarmMsg, paramMap);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Post(server, "");
                Common.log.Debug("updateDeviceAlarmMsg    " + "  【" + server + "】【" + resultStr + "】");

                RfidData data = JsonHelper.DeserializeJsonToObject<RfidData>(resultStr);

                if (data == null)
                {
                    return msg = " updateDeviceAlarmMsg 没有收到服务器反馈";
                }
                else if (data.code.Equals(0).Equals(false))
                {
                    return msg = " updateDeviceAlarmMsg   【" + server + "】【" + resultStr + "】" + data.msg;
                }
                return "";
            }
            catch (Exception ex)
            {
                Common.log.Error("updateDeviceAlarmMsg",ex);
            }
            return msg;
        }
        private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
        {
            string server = "http://10.85.199.25/myproject/";
            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 AlarmMsg
    {

        //>>>name :  异常位置名称
        public string name = "";
        //>>>msgKey :  异常信息唯一标识
        public string msgKey = "";
        //>>>msgValue :  异常信息
        public string msgValue = "";

        public int type;
        /// <summary>
        /// 异常信息
        /// </summary>
        /// <param name="name">异常位置名称</param>
        /// <param name="key">异常信息唯一标识</param>
        /// <param name="value">异常信息</param>
        public AlarmMsg(string name, string key, string value,int type=0)
        {
            this.name = name;
            this.msgKey = key;
            this.msgValue = value;
            this.type = type;
        }
    }
    public class RfidData
    {
        //{"code":0,"msg":"ok","data":"7"} 
        public int code { get; set; }

        public string msg { get; set; }

        public Dictionary<string, string> data { get; set; }
    }
}