SServerManager.cs 17.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
using OnlineStore.Common;
using System;
using System.Collections.Generic;

namespace OnlineStore.DeviceLibrary
{
    public class SServerManager
    {
        private static string serverAddr = ConfigAppSettings.GetValue(Setting_Init.http_server);
        private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
        {

            if (serverAddr.EndsWith("/"))
            {
                serverAddr = serverAddr.Substring(0, serverAddr.Length - 1);
            }
            string path = serverAddr + 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;
        }
        #region 立臻料仓接口
        static string Addr_UploadLocInfo = "/service/store/innerBox/updateLocInfo";
        /// <summary>
        /// A 出库更新任务状态 -OK
        /// </summary>
        /// <param name="barcode">料盘条码</param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static BoxTaskInfo UploadLocInfo(string barcode, string status, string loc = "")
        {
            try
            {
                string msg = "";
                Dictionary<string, string> map = new Dictionary<string, string>();
                map.Add("barcode", barcode);
                map.Add("status", status);
                map.Add("loc", loc);
                string server = GetAddr(Addr_UploadLocInfo, map);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Get(server);
                ServerData1 serverResult = JsonHelper.DeserializeJsonToObject<ServerData1>(resultStr);
                if (serverResult == null)
                {
                    msg = $"UploadStationInfo【{barcode}】【{status}】" + "没有收到服务器反馈";
                }
                else if (serverResult.code.Equals(0).Equals(false))
                {
                    // code: 0为正常,其他为异常, msg: 消息, data: 为空
                    msg = $" UploadStationInfo 【{barcode}】【{status}】【{JsonHelper.SerializeObject(serverResult)}】";
                    LogUtil.error(msg);
                    return null;

                }
                else
                {
                    msg = $" UploadStationInfo 【{barcode}】【{status}】【{JsonHelper.SerializeObject(serverResult)}】";
                    LogUtil.info(msg);
                    return serverResult.data;
                }

            }
            catch (Exception ex)
            {
                LogUtil.error("UploadLocInfo", ex);
            }
            return null;
        }

        static string Addr_GetBoxStatusInfo = "/service/store/innerBox/getBoxStatusInfo";
        /// <summary>
        /// 获取料箱状态信息
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="status"></param>
        /// <param name="rfid"></param>
        /// <returns></returns>
        public static BoxTaskInfo GetBoxStatusInfo(string cid, string rfid)
        {
            try
            {
                string msg = "";
                Dictionary<string, string> map = new Dictionary<string, string>();
                map.Add("cid", cid);
                map.Add("rfid", rfid);
                string server = GetAddr(Addr_GetBoxStatusInfo, map);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Get(server);
                ServerData1 serverResult = JsonHelper.DeserializeJsonToObject<ServerData1>(resultStr);
                if (serverResult == null)
                {
                    msg = $"GetBoxStatusInfo【{cid}】【{rfid}】" + "没有收到服务器反馈";
                }
                else if (serverResult.code.Equals(0).Equals(false))
                {
                    // code: 0为正常,其他为异常, msg: 消息, data: 为空
                    msg = $" GetBoxStatusInfo 【{cid}】【{rfid}】【{JsonHelper.SerializeObject(serverResult)}】";
                    if (!msg.Equals(""))
                    {
                        LogUtil.error(msg);
                        return null;
                    }
                }
                else
                {
                    msg = $" GetBoxStatusInfo 【{cid}】【{rfid}】【{JsonHelper.SerializeObject(serverResult)}】";
                    LogUtil.debug(msg);
                    return serverResult.data;
                }

            }
            catch (Exception ex)
            {
                LogUtil.error("GetBoxStatusInfo", ex);
            }
            return null;
        }
        static string Addr_boxTakeAway = "/service/store/innerBox/boxTakeAway";
        /// <summary>
        /// 清除料箱与工单的绑定
        /// </summary>
        /// <param name="rfid"></param>
        /// <returns></returns>
        public static bool BoxTakeAway(string rfid)
        {
            try
            {
                string msg = "";
                Dictionary<string, string> map = new Dictionary<string, string>();
                map.Add("rfid", rfid);
                string server = GetAddr(Addr_boxTakeAway, map);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Get(server);
                RfidData serverResult = JsonHelper.DeserializeJsonToObject<RfidData>(resultStr);
                if (serverResult == null)
                {
                    msg = $"BoxTakeAway【{rfid}】" + "没有收到服务器反馈";
                    LogUtil.error(msg);
                }
                else if (serverResult.code.Equals(0))
                {
                    // code: 0为正常,其他为异常, msg: 消息, data: 为空
                    msg = $" BoxTakeAway【{rfid}】【{JsonHelper.SerializeObject(serverResult)}】";
                    LogUtil.info(msg);
                    return true;
                }

            }
            catch (Exception ex)
            {
                LogUtil.error("BoxTakeAway", ex);
            }
            return false;
        }

        static string Addr_GetFeederInfo = "/service/store/innerBox/getFeederInfo";
        /// <summary>
        /// 贴标前获取站位信息
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public static Label_LZ GetFeederInfo(string barcode)
        {
            try
            {
                string msg = "";
                Dictionary<string, string> map = new Dictionary<string, string>();
                map.Add("barcode", barcode);
                string server = GetAddr(Addr_GetFeederInfo, map);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Get(server);
                ServerData2 serverResult = JsonHelper.DeserializeJsonToObject<ServerData2>(resultStr);
                if (serverResult == null)
                {
                    msg = $"GetFeederInfo【{barcode}】" + "没有收到服务器反馈";
                }
                else if (!serverResult.code.Equals(0))
                {
                    // code: 0为正常,其他为异常, msg: 消息, data: 为空
                    msg = $" GetFeederInfo 【{barcode}】【{resultStr}】";
                    LogUtil.error(msg);
                    return null;
                }
                else
                {
                    msg = $" GetFeederInfo 【{barcode}】【{resultStr}】";
                    LogUtil.debug(msg);
                    return serverResult.data;
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("GetFeederInfo", ex);
            }
            return null;
        }
        #region 料架打印机接口
        static string Addr_GetPrintInfo = ConfigAppSettings.GetValue("Addr_GetPrintInfo", "/service/store/innerBox/rack/getPrintInfo");
        public static Label_LZ GetPrintInfo(string cid)
        {
            try
            {
                string msg = "";
                Dictionary<string, string> map = new Dictionary<string, string>();
                map.Add("cid", cid);
                string server = GetAddr(Addr_GetPrintInfo, map);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Get(server);
                ServerData3 serverResult = JsonHelper.DeserializeJsonToObject<ServerData3>(resultStr);
                if (serverResult == null)
                {
                    msg = $"GetPrintInfo " + "没有收到服务器反馈";
                }
                else if (!serverResult.code.Equals(0))
                {
                    // code: 0为正常,其他为异常, msg: 消息, data: 为空
                    msg = $" GetPrintInfo 【{resultStr}】";
                    return null;
                }
                else
                {
                    msg = $" GetPrintInfo【{resultStr}】";
                    LogUtil.info(msg);
                    if (string.IsNullOrEmpty(serverResult.data.pn)) return null;
                    else
                        return serverResult.data;
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("GetPrintInfo", ex);
            }
            return null;
        }

        static string Addr_FinishPrint = ConfigAppSettings.GetValue("Addr_FinishPrint", "/service/store/innerBox/rack/finishPrint");
        public static bool FinishPrint(string cid)
        {
            try
            {
                string msg = "";
                Dictionary<string, string> map = new Dictionary<string, string>();
                 map.Add("cid", cid);
                string server = GetAddr(Addr_FinishPrint, map);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Get(server);
                ServerData serverResult = JsonHelper.DeserializeJsonToObject<ServerData>(resultStr);
                if (serverResult == null)
                {
                    msg = $"FinishPrint" + "没有收到服务器反馈";
                    LogUtil.error (msg);
                    return false;
                }
                else if (serverResult.code.Equals(0))
                {
                    // code: 0为正常,其他为异常, msg: 消息, data: 为空
                    msg = $" FinishPrint 【{resultStr}】";
                    LogUtil.info(msg);
                    return true;
                }
                else
                {
                    msg = $" FinishPrint【{resultStr}】";
                    LogUtil.error(msg);
                    return false;
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("FinishPrint", ex);
            }
            return false;
        }
        static string Addr_GetNIOutInfo = "/service/store/innerBox/getNIOutInfo";
        /// <summary>
        /// 获取料架单独的出库任务
        /// </summary>
        /// <returns></returns>
        public static bool GetNIOutInfo(out string line)
        {
            line = "";
            try
            {
                string msg = "";
                Dictionary<string, string> map = new Dictionary<string, string>();
                // map.Add("barcode", barcode);
                string server = GetAddr(Addr_GetNIOutInfo, map);
                DateTime startTime = DateTime.Now;
                string resultStr = HttpHelper.Get(server);
                ServerData4 serverResult = JsonHelper.DeserializeJsonToObject<ServerData4>(resultStr);
                if (serverResult == null)
                {
                    msg = $"GetNIOutInfo" + "没有收到服务器反馈";
                }
                else if (serverResult.code.Equals(0))
                {
                    // code: 0为正常,其他为异常, msg: 消息, data: 为空
                    msg = $" GetNIOutInfo 【{resultStr}】";
                    LogUtil.debug(msg);
                    line = serverResult.data.line;
                    return true;
                }
                else
                {
                    msg = $" GetNIOutInfo【{resultStr}】";
                    LogUtil.debug(msg);
                    return false;
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("GetNIOutInfo", ex);
            }
            return false;
        }
        #endregion

        #endregion
    }

    /// <summary>
    /// 箱子剩余数量
    /// </summary>
    public class BoxTaskInfo
    {
        /// <summary>
        /// 所属需求单剩余当前料仓未完成任务数
        /// </summary>
        public int remainTaskCount { get; set; } = -1;
        /// <summary>
        /// 所属需求单剩余料架任务数
        /// </summary>
        public int rackTaskCount { get; set; } = -1;
        /// <summary>
        /// 需求单号
        /// </summary>
        public string hSerial { get; set; } = "";
        /// <summary>
        /// 目的地
        /// </summary>
        public string line { get; set; } = "";
        /// <summary>
        /// 当前料箱隔口内侧已放入
        /// </summary>
        public int inCount { get; set; } = -1;
        public int outCount { get; set; } = -1;
        //public bool IsValid()
        //{
        //    if (bigEmpty != -1 && smallEmpty != -1)
        //    {
        //        return true;
        //    }
        //    return false;
        //}

        public string ToStr()
        {
            return $"内侧格口已有数量:{inCount},外侧格口已有数量;{outCount}; 需求单:{hSerial},剩余任务数={remainTaskCount}," +
                $"剩余料架数:{rackTaskCount},目的地:{line}";
        }
    }
    public class AlarmMsg
    {

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

        public AlarmMsg(string n, string key, string value)
        {
            this.name = n;
            this.msgKey = key;
            this.msgValue = value;
        }
    }
    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; }
    }
    public class CancelData
    {
        //{"code":0,"msg":"ok","data":"7"} 
        public int code { get; set; }

        public string msg { get; set; }

        public object data { get; set; }
    }
    //public class LocStatus
    //{
    //    /// <summary>
    //    /// 料盘位置:移栽 = MOVING
    //    /// </summary>
    //    public static string MOVING = "MOVING";
    //    /// <summary>
    //    /// 料盘位置:流水线 = INLINE
    //    /// </summary>
    //    public static string INLINE = "INLINE";
    //    /// <summary>
    //    /// 料盘位置:皮带线 = INBELT
    //    /// </summary>
    //    public static string INBELT = "INBELT";
    //}
    public class ServerData
    {
        //{"code":0,"msg":"ok","data":"7"} 
        public int code { get; set; }

        public string msg { get; set; }

        public string data { get; set; }
    }

    public class ServerData1
    {
        public int code { get; set; }

        public string msg { get; set; }

        public BoxTaskInfo data { get; set; }
    }
    public class ServerData2
    {
        public int code { get; set; }

        public string msg { get; set; }

        public Label_LZ data { get; set; }
    }
    public class ServerData3
    {
        public int code { get; set; }

        public string msg { get; set; }

        public Label_LZ data { get; set; }
    }
    public class ServerData4
    {
        //{"code":0,"msg":"ok","data":"7"} 
        public int code { get; set; }

        public string msg { get; set; }

        public NIOutInfo data { get; set; }
    }
    public class NIOutInfo
    {
        public string line { get; set; }
    }
    public class AfterPutData
    {
        //>>` {"code": 0, "msg":"ok", "data":{"cutPackageTask":"0","urgentPackageTask":"20","cutTask":"21","urgentTask":"22"}} `
        //>>
        //>> - code: 0为正常,其他为异常, 
        //>> - msg:消息, 
        //>> - data:为包装料仓的空闲仓位数(key为与客户端一致的料仓标识, value为空闲仓位)
        //>> - cutPackageTask: 表示当前包装仓的分盘任务数
        //>> - urgentPackageTask: 表示当前包装仓的紧急料任务数
        //>> - cutTask: 表示流水线分盘任务数
        //>> - urgentTask: 表示流水线紧急料任务数
        public int code { get; set; }

        public string msg { get; set; }

        public TaskData data { get; set; }
    }
    public class TaskData
    {
        /// <summary>
        /// urgentPackageTask: 表示当前包装仓的紧急料任务数
        /// </summary>
        public int urgentPackageTask { get; set; }
        /// <summary>
        /// cutPackageTask: 表示当前包装仓的分盘任务数
        /// </summary>
        public int cutPackageTask { get; set; }
        /// <summary>
        /// cutTask: 表示流水线分盘任务数
        /// </summary>
        public int cutTask { get; set; }
        /// <summary>
        /// urgentTask: 表示流水线紧急料任务数
        /// </summary>
        public int urgentTask { get; set; }

        public string ToStr()
        {
            return "[分盘料=" + cutTask + "][紧急料=" + urgentTask + "]";
        }

    }
}