From 0f2e0147e8990e913d16d99bc1b94fb6bc53abd7 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期四, 03 十二月 2020 15:35:42 +0800
Subject: [PATCH] 2020-12-03-1

---
 HDL_ON/DAL/Server/IMessageCommon.cs |  152 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 117 insertions(+), 35 deletions(-)

diff --git a/HDL_ON/DAL/Server/IMessageCommon.cs b/HDL_ON/DAL/Server/IMessageCommon.cs
index 26e742c..5b9e64d 100644
--- a/HDL_ON/DAL/Server/IMessageCommon.cs
+++ b/HDL_ON/DAL/Server/IMessageCommon.cs
@@ -9,6 +9,7 @@
     /// </summary>
     public class IMessageCommon
     {
+
         /// <summary>
         /// 鎺ュ彛绫荤殑杩斿洖淇℃伅
         /// </summary>
@@ -29,15 +30,21 @@
                 return m_Current;
             }
         }
+
+        /// <summary>
+        /// 鏄惁鍦ㄨ幏鍙杢oken
+        /// </summary>
+        public bool isGetingToken;
+
         /// <summary>
         /// 鏃犺閿欒(璁块棶浜戠鏃讹紝姝ゆ搷浣滃皢涓嶄細寮瑰嚭閿欒)
         /// </summary>
         public bool IgnoreError = false;
 
-        /// <summary>
-        /// 鍏ㄩ儴淇℃伅
-        /// </summary>
-        private Dictionary<string, Dictionary<string, int>> dicMsg = null;
+        ///// <summary>
+        ///// 鍏ㄩ儴淇℃伅
+        ///// </summary>
+        //private Dictionary<string, Dictionary<string, int>> dicMsg = null;
 
         /// <summary>
         /// 閫氱敤閿欒鐮�
@@ -50,7 +57,7 @@
         /// </summary>
         public void InitAllMsg()
         {
-            dicMsg = new Dictionary<string, Dictionary<string, int>>();
+            //dicMsg = new Dictionary<string, Dictionary<string, int>>();
             #region 鍏遍�氶敊璇爜
             stateCodeDic = new Dictionary<string, int>();
             //涓庢湇鍔″櫒閫氳澶辫触
@@ -59,18 +66,25 @@
             stateCodeDic["DATA_EXCEPTION"] = HDL_ON.StringId.DataExceptionPleaseTryAgain;
 
             #region 鍩虹鏈嶅姟 鏂伴敊璇爜
-            ////鏈嶅姟鍣ㄦ鍦ㄥ崌绾�
-            //stateCodeDic["2"] = HDL_ON.StringId.FailureToServer;
-            ////楠岃瘉鐮佹牎楠屽け璐�
-            //stateCodeDic["14"] = HDL_ON.StringId.ValidatorCode_ValidCodeAndPhoneNoEqual;
-            ////浼氳瘽瓒呮椂锛岃鏇存柊token
-            //stateCodeDic["10001"] = HDL_ON.StringId.uOperationFailed;
-
+            //绯荤粺缁存姢涓瓇璇风◢鍚庡啀璇晘
+            stateCodeDic["2"] = HDL_ON.StringId.SystemMaintenance;
+            //绛惧悕閿欒
+            stateCodeDic["4"] = HDL_ON.StringId.SignatureError;
+            //楠岃瘉鐮佹牎楠屽け璐�
+            stateCodeDic["14"] = HDL_ON.StringId.VerificationCodeWrong;
+            //楠岃瘉鐮佸彂閫侀绻侊紝璇风◢鍚庡啀璇曪紒
+            stateCodeDic["15"] = HDL_ON.StringId.VerificationCodeSentFrequently;
+            //浼氳瘽瓒呮椂锛岃鏇存柊token
+            stateCodeDic[StateCode.TOKEN_EXPIRED] = HDL_ON.StringId.NotLogin;
             ////鐧诲綍澶辫触锛岃处鍙锋垨鑰呭瘑鐮侀敊璇�
-            //stateCodeDic["10008"] = HDL_ON.StringId.Accountorpassworderro;
-            ////璐﹀彿涓嶅瓨鍦�
-            //stateCodeDic["10010"] = HDL_ON.StringId.uNoLogin;
-            //#endregion
+            stateCodeDic["10008"] = HDL_ON.StringId.LoginFailed_AccountOrPasswordError;
+            //璐﹀彿涓嶅瓨鍦�
+            stateCodeDic[StateCode.ACCOUNT_NOT_EXIST] = HDL_ON.StringId.AccountNotExist;
+            //璐﹀彿宸插瓨鍦�
+            stateCodeDic["10012"] = HDL_ON.StringId.AccountExist;
+            ////璋冪敤鐢ㄦ埛妯″潡鎺ュ彛澶辫触
+            //stateCodeDic["10213"] = HDL_ON.StringId;
+            #endregion
 
             ////return;
             //#region 2020-09-18 鏂板鎺ラ敊璇爜
@@ -178,7 +192,6 @@
 
             #endregion
 
-            #endregion
 
         }
 
@@ -189,7 +202,7 @@
         /// <param name="revertObj">浜戠杩斿洖鐨勬暟鎹�</param>
         /// <param name="pra">璇锋眰鍙傛暟</param>
         /// <returns></returns>
-        public string GetMsgByRequestName(string requestName, string statuCode)
+        public string GetMsgByRequestName(string statuCode)
         {
             if (IgnoreError == true)
             {
@@ -203,11 +216,11 @@
                 return Language.StringByID(stateCodeDic[statuCode]);
             }
 
-            if (dicMsg.ContainsKey(requestName) == true && dicMsg[requestName].ContainsKey(statuCode) == true)
-            {
-                //鍦ㄥ唽鐨凪sg
-                return Language.StringByID(dicMsg[requestName][statuCode]);
-            }
+            //if (dicMsg.ContainsKey(requestName) == true && dicMsg[requestName].ContainsKey(statuCode) == true)
+            //{
+            //    //鍦ㄥ唽鐨凪sg
+            //    return Language.StringByID(dicMsg[requestName][statuCode]);
+            //}
 
             return Language.StringByID(HDL_ON.StringId.FailedRequestServer) + "\n(" + statuCode + ")";
         }
@@ -220,28 +233,97 @@
         /// <param name="statuCode"></param>
         /// <param name="isTipStyle"></param>
         /// <param name="tipStr">琛ュ厖鐨勯敊璇彁绀�</param>
-        public void ShowErrorInfoAlter(string requestName, string statuCode, bool isTipStyle = false, string tipStr = "")
+        public void ShowErrorInfoAlter(string statuCode, bool isTipStyle = true, int closeTime = 2, string tipStr = "")
         {
             try
             {
-                string mes = GetMsgByRequestName(requestName, statuCode);
-                if (mes == null) return;
-                if (!string.IsNullOrEmpty(tipStr))
+                //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken
+                if (statuCode == StateCode.TOKEN_EXPIRED)
                 {
-                    mes = tipStr + "\n" + mes;
-                }
-                if (isTipStyle)
-                {
-                    //MainPage.AddTip(mes);
+                    StartRefreshToken();
                 }
                 else
                 {
-                    Application.RunOnMainThread(() => {
-                        new Alert("", mes, Language.StringByID(HDL_ON.StringId.Close)).Show();
-                    });
+                    string mes = GetMsgByRequestName(statuCode);
+                    if (mes == null) return;
+                    if (!string.IsNullOrEmpty(tipStr))
+                    {
+                        mes = tipStr + "\n" + mes;
+                    }
+                    if (isTipStyle)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            var tip = new Tip()
+                            {
+                                Text = mes,
+                                CloseTime = closeTime,
+                                Direction = AMPopTipDirection.None
+                            };
+                            tip.Show(MainPage.BaseView);
+                        });
+                    }
+                    else
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            new Alert("", mes, Language.StringByID(HDL_ON.StringId.Close)).Show();
+                        });
+                    }
                 }
             }
             catch { }
         }
+
+        /// <summary>
+        /// StartRefreshToken
+        /// </summary>
+        public void StartRefreshToken()
+        {
+            if (isGetingToken) return;
+
+            new System.Threading.Thread(() =>
+            {
+                isGetingToken = true;
+
+                try
+                {
+                    var success = new HttpServerRequest().RefreshToken();
+                    if (success) {
+                        Utlis.WriteLine("RefreshToken success");
+                    }
+                }
+                catch
+                {
+                }
+                finally
+                {
+                    isGetingToken = false;
+                }
+            })
+            { IsBackground = true }.Start();
+
+        }
+    }
+
+    /// <summary>
+    /// 甯哥敤鐘舵�佺爜绠$悊
+    /// </summary>
+    public class StateCode
+    {
+        /// <summary>
+        /// 璇锋眰鎴愬姛鐨勭姸鎬佺爜
+        /// </summary>
+        public const string SUCCESS = "0";
+        /// <summary>
+        /// 浼氳瘽瓒呮椂锛岃鏇存柊token
+        /// </summary>
+        public const string TOKEN_EXPIRED = "10001";
+        /// <summary>
+        /// 璐﹀彿涓嶅瓨鍦ㄧ殑閿欒鐮�
+        /// </summary>
+        public const string ACCOUNT_NOT_EXIST = "10010";
+
+
     }
 }

--
Gitblit v1.8.0