From b166c0f80252ab4e1af4136789cb976364b779b2 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期一, 21 十一月 2022 15:12:04 +0800
Subject: [PATCH] 大岛的登陆接口存redis加企业区分

---
 VueWebApi/Controllers/LoginController.cs |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/VueWebApi/Controllers/LoginController.cs b/VueWebApi/Controllers/LoginController.cs
index 5006a59..2e40033 100644
--- a/VueWebApi/Controllers/LoginController.cs
+++ b/VueWebApi/Controllers/LoginController.cs
@@ -1,6 +1,7 @@
 锘縰sing Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
+using System.Configuration;
 using System.Data;
 using System.Linq;
 using System.Net;
@@ -20,6 +21,8 @@
         //瀹氫箟鍏ㄥ眬淇℃伅杩斿洖鍙橀噺
         ToMessage mes = new ToMessage();
         RedisHelper redis = new RedisHelper();
+        //鑾峰彇浼佷笟閰嶇疆Enterprise
+        private static readonly string Enterprise = ConfigurationManager.AppSettings["Enterprise"];
 
         #region[PC鐢ㄦ埛鐧诲綍]
         /// <summary>
@@ -46,17 +49,18 @@
                     ms.username = dt.Rows[0]["USERNAME"].ToString();
                     ms.password = dt.Rows[0]["PASSWORD"].ToString();
                     ms.usertype = usertype;
+                    ms.rediskey = Enterprise+"LoginUserID" + ms.usertype + ms.userid;
                     mss.Add(ms);
                     HttpContext.Current.Session.Clear(); //浠庝細璇濈姸鎬侀泦鍚堜腑鍒犻櫎鎵�鏈夌殑閿��
                     //HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
                     //User loginUser = JsonConvert.DeserializeObject<User>(HttpContext.Current.Session["User"].ToString());
                     User loginUser = JsonConvert.DeserializeObject<User>(JsonConvert.SerializeObject(ms));
                     //濡傛灉redis鐧诲綍鐢ㄦ埛涓笉瀛樺湪褰撳墠鐢ㄦ埛
-                    if (redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0) == null)
+                    if (redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 0) == null)
                     {
                         //redis.Remove("LoginUserID" + ms.userid, 0);
                         //鍐欏叆redis(娉ㄦ剰锛歳edis绫婚噷闈㈢殑澶辨晥鏃堕棿蹇呴』鍦╧ey鍒涘缓瀹屾垚涔嬪悗鎵嶇敓鏁�)
-                        redis.Set<User>("LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 0);
+                        redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 0);
                         //鐧诲綍淇℃伅鍐欏叆session
                         HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
                         //鍐欏叆鐧诲綍鎿嶄綔璁板綍
@@ -68,7 +72,7 @@
                     else //濡傛灉瀛樺湪
                     {
                         //鑾峰彇redis涓綋鍓嶇敤鎴蜂俊鎭�
-                        User r_loginUser = redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0);
+                        User r_loginUser = redis.Get<User>(Enterprise + "LoginUserID" + ms.usertype + ms.userid, 0);
                         //濡傛灉session涓殑鐢ㄦ埛usercode鍜宺edis涓殑鐢ㄦ埛usercode鍖归厤
                         if ((r_loginUser.usercode + r_loginUser.usertype).Equals(loginUser.usercode + loginUser.usertype))
                         {
@@ -79,11 +83,12 @@
                         else
                         {
                             //閲嶇疆杩囨湡鏃堕棿(娉ㄦ剰锛歳edis绫婚噷闈㈢殑澶辨晥鏃堕棿蹇呴』鍦╧ey鍒涘缓瀹屾垚涔嬪悗鎵嶇敓鏁�)
-                            redis.Set<User>("LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 0);
+                            redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 0);
                             //鐧诲綍淇℃伅鍐欏叆session
                             HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
                             //鍐欏叆鐧诲綍鎿嶄綔璁板綍
                             mes = LoginBLL.LoginBas(ms.usercode, ms.usertype);
+                            mes.data = ms;
                             mes.code = "200";
                             mes.Message = "鐧诲綍鎴愬姛!";
                         }
@@ -127,7 +132,7 @@
         {
             try
             {
-                redis.Remove("LoginUserID" + usertype + userid, 0); //鍒犻櫎redis
+                redis.Remove(Enterprise+"LoginUserID" + usertype + userid, 0); //鍒犻櫎redis
                 mes.code = "200";
                 mes.count = 0;
                 mes.Message = "寮哄埗涓嬬嚎鎴愬姛!";
@@ -271,5 +276,24 @@
             return mes.ResponseMess(mes);
         }
         #endregion
+
+        #region[App鐧诲綍鏌ヨ瀹夌伅鍛煎彨淇℃伅]
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="userid">鐢ㄦ埛id</param>
+        /// <param name="usercode">鐢ㄦ埛缂栫爜</param>
+        /// <param name="username">鐢ㄦ埛鍚嶇О</param>
+        /// <param name="usertype">鎿嶄綔绔疨C/APP</param>
+        /// <returns></returns>
+        [Route(template: "LoginAppAnDonMessage")]
+        [HttpPost]
+        public HttpResponseMessage LoginAppAnDonMessage(int userid, string usercode, string username, string usertype)
+        {
+            mes = LoginBLL.LoginAppAnDonMessage(userid, usercode, username, usertype);
+            return TJson.toJson(mes);
+            //return mes.ResponseMess(mes);
+        }
+        #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3