Merge branch 'master' of http://ldj:3000/root/ldj
This commit is contained in:
		
						commit
						05795ba223
					
				|  | @ -4,6 +4,7 @@ using System.Data; | ||||||
| using System.Collections; | using System.Collections; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
|  | using WcfServiceAuthentication; | ||||||
| 
 | 
 | ||||||
| namespace DeiNiu.wms.Logical | namespace DeiNiu.wms.Logical | ||||||
| { | { | ||||||
|  | @ -241,6 +242,8 @@ namespace DeiNiu.wms.Logical | ||||||
|                 em.AuthSpecials = getAuthObjLst(em.ID, "细分权限"); |                 em.AuthSpecials = getAuthObjLst(em.ID, "细分权限"); | ||||||
|                 |                 | ||||||
|             } |             } | ||||||
|  |             AuthenticationInspector.checkRestrictUsers(em.ID); | ||||||
|  | 
 | ||||||
|             return em; |             return em; | ||||||
|             |             | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -121,6 +121,10 @@ | ||||||
|       <Project>{151F88A4-82D0-4E30-A9B5-AB0B0ADA1FBD}</Project> |       <Project>{151F88A4-82D0-4E30-A9B5-AB0B0ADA1FBD}</Project> | ||||||
|       <Name>Utils</Name> |       <Name>Utils</Name> | ||||||
|     </ProjectReference> |     </ProjectReference> | ||||||
|  |     <ProjectReference Include="..\WcfServiceAuthentication\WcfServiceAuthentication.csproj"> | ||||||
|  |       <Project>{ca44f42f-4376-4bc6-9ea4-821db704c75d}</Project> | ||||||
|  |       <Name>WcfServiceAuthentication</Name> | ||||||
|  |     </ProjectReference> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> |     <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> | ||||||
|  |  | ||||||
|  | @ -327,6 +327,14 @@ namespace DeiNiu.wms.Data.Model | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |         private string _extrMsg = ""; | ||||||
|  | 
 | ||||||
|  |         public string extrMsg | ||||||
|  |         { | ||||||
|  |             get { return _extrMsg; } | ||||||
|  |             set { _extrMsg = value; } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,7 +7,10 @@ namespace DeiNiu.Utils | ||||||
| { | { | ||||||
|     public struct WmsConstants |     public struct WmsConstants | ||||||
|     { |     { | ||||||
| 
 |         public static bool IS_ONLINE_RESTRICT = false; // 是否限制在线人数 | ||||||
|  |         public static int MAX_ONLINE_USERS = 1; | ||||||
|  |         public static string SYSTEM_VALID_DATE = "2024-05-25"; | ||||||
|  |         public static int SYSTEM_VALID_LEFT_DAYS = 0; | ||||||
|         public static bool IS_INITIALED = false; |         public static bool IS_INITIALED = false; | ||||||
|         public static string SQL_CONN_WMS = ""; |         public static string SQL_CONN_WMS = ""; | ||||||
|         public static string SQL_CONN_PLATFORM = ""; |         public static string SQL_CONN_PLATFORM = ""; | ||||||
|  |  | ||||||
|  | @ -282,10 +282,14 @@ namespace DeiNiu.Wcf | ||||||
| 
 | 
 | ||||||
|         public FormatedResult login(string account, string passwd) |         public FormatedResult login(string account, string passwd) | ||||||
|         { |         { | ||||||
|  |               | ||||||
|  | 
 | ||||||
|             LAuthority auth = new LAuthority(); |             LAuthority auth = new LAuthority(); | ||||||
|             Employee em = auth.login(account, passwd); |             Employee em = auth.login(account, passwd); | ||||||
|             AuthenticationInspector.authCach[em.ID] = em.token; |             AuthenticationInspector.authCach[em.ID] = em.token; | ||||||
| 
 | 
 | ||||||
|  |         | ||||||
|  | 
 | ||||||
|             List<string> tmp = new List<string>(); |             List<string> tmp = new List<string>(); | ||||||
| 
 | 
 | ||||||
|             foreach (Authority au in em.AuthSpecials) |             foreach (Authority au in em.AuthSpecials) | ||||||
|  | @ -296,6 +300,25 @@ namespace DeiNiu.Wcf | ||||||
|             ConstAuthourity.setSpecialAuths(em.ID, tmp); |             ConstAuthourity.setSpecialAuths(em.ID, tmp); | ||||||
| 
 | 
 | ||||||
|             //  return new FormatedResult(JsonConvert.SerializeObject(em)); |             //  return new FormatedResult(JsonConvert.SerializeObject(em)); | ||||||
|  |            // em.extrMsg = "this is test"; | ||||||
|  |             | ||||||
|  | 
 | ||||||
|  |             if (WmsConstants.IS_ONLINE_RESTRICT) | ||||||
|  |             { | ||||||
|  |                 if(WmsConstants.SYSTEM_VALID_LEFT_DAYS <= 0) | ||||||
|  |                 { | ||||||
|  |                     em = new Employee(); | ||||||
|  |                 }else if(  WmsConstants.SYSTEM_VALID_LEFT_DAYS <20) | ||||||
|  |                 {  | ||||||
|  |                     log.Debug(string.Format("Warrning is expiring... IS_ONLINE_RESTRICT: {0}, SYSTEM_VALID_LEFT_DAYS: {1}, SYSTEM_VALID_DATE {2} ", | ||||||
|  |                 WmsConstants.IS_ONLINE_RESTRICT, WmsConstants.SYSTEM_VALID_LEFT_DAYS, WmsConstants.SYSTEM_VALID_DATE)); | ||||||
|  |                     em.extrMsg = String.Format("警告:系统将在{0}天后到期停用, 请及时缴费", WmsConstants.SYSTEM_VALID_LEFT_DAYS); | ||||||
|  |                 } | ||||||
|  |   | ||||||
|  |               //  log.Debug("login user " + em.ToString()); | ||||||
|  |             } | ||||||
|  |             | ||||||
|  | 
 | ||||||
|             return new FormatedResult(em); |             return new FormatedResult(em); | ||||||
| 
 | 
 | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -2454,6 +2454,11 @@ namespace DeiNiu.wms.Logical | ||||||
|             enumReceiveStockDetailStatus nextState = enumReceiveStockDetailStatus.待验收; |             enumReceiveStockDetailStatus nextState = enumReceiveStockDetailStatus.待验收; | ||||||
| 
 | 
 | ||||||
|             WmsGoods wg = new WmsGoods(epd.goods_id); |             WmsGoods wg = new WmsGoods(epd.goods_id); | ||||||
|  |             if (wg.ID == 0) | ||||||
|  |             { | ||||||
|  |                 log.Error(epd.goods_id + " is not exists in wms"); | ||||||
|  |                 throw new Exception("未知商品" ); | ||||||
|  |             } | ||||||
|             if (!wg.isQc) |             if (!wg.isQc) | ||||||
|             { |             { | ||||||
|                 nextState = enumReceiveStockDetailStatus.已验收; |                 nextState = enumReceiveStockDetailStatus.已验收; | ||||||
|  | @ -3415,6 +3420,7 @@ namespace DeiNiu.wms.Logical | ||||||
|                     catch (Exception er) |                     catch (Exception er) | ||||||
|                     { |                     { | ||||||
|                         logIn.Error(er); |                         logIn.Error(er); | ||||||
|  |                         throw er; | ||||||
|                     } |                     } | ||||||
|                     //    scope.Complete(); |                     //    scope.Complete(); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  | @ -311,6 +311,10 @@ namespace DeiNiu.wms.Logical | ||||||
|                  { |                  { | ||||||
|                      return false; |                      return false; | ||||||
|                  } |                  } | ||||||
|  |                 if (string.IsNullOrEmpty(batch)) | ||||||
|  |                 { | ||||||
|  |                     batch = _obj.getDateTime(); | ||||||
|  |                 } | ||||||
|                  _obj.skuCode = sku.skuCode; |                  _obj.skuCode = sku.skuCode; | ||||||
|                  _obj.productDate = String.IsNullOrEmpty( sku.ProductDate)?batch:sku.ProductDate ; |                  _obj.productDate = String.IsNullOrEmpty( sku.ProductDate)?batch:sku.ProductDate ; | ||||||
|                  _obj.validDate = String.IsNullOrEmpty(sku.ValidDate) ? batch : sku.ValidDate; |                  _obj.validDate = String.IsNullOrEmpty(sku.ValidDate) ? batch : sku.ValidDate; | ||||||
|  |  | ||||||
|  | @ -74,6 +74,30 @@ namespace DeiNiu.wms.Logical | ||||||
|             ts = ts1.Subtract(new TimeSpan(DateTime.Now.Ticks)).Duration(); |             ts = ts1.Subtract(new TimeSpan(DateTime.Now.Ticks)).Duration(); | ||||||
|            return ts.Days; |            return ts.Days; | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         protected int getLeftDays(string endDateStr) | ||||||
|  |         { | ||||||
|  |             DateTime endDate = Util.pareseDateString(endDateStr); | ||||||
|  |             DateTime validDate = DateTime.Now; | ||||||
|  | 
 | ||||||
|  |             log.Debug(string.Format("endDate {0}, currentdate {1}", endDate, validDate)); | ||||||
|  |             if (endDate < validDate) | ||||||
|  |             { | ||||||
|  |                 log.Debug(string.Format("expired ....")); | ||||||
|  |                 return 0; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |            // TimeSpan ts1 = new TimeSpan(validDate.Ticks); | ||||||
|  |             TimeSpan ts2 = new TimeSpan(endDate.Ticks); | ||||||
|  |           //  TimeSpan ts = ts1.Subtract(ts2).Duration(); | ||||||
|  | 
 | ||||||
|  |            // int expDays = ts.Days; | ||||||
|  | 
 | ||||||
|  |             TimeSpan ts = ts2.Subtract(new TimeSpan(DateTime.Now.Ticks)).Duration(); | ||||||
|  |             return ts.Days+1; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|         public void initialConstants() |         public void initialConstants() | ||||||
|        { |        { | ||||||
|            if (WmsConstants.IS_INITIALED) |            if (WmsConstants.IS_INITIALED) | ||||||
|  | @ -97,12 +121,43 @@ namespace DeiNiu.wms.Logical | ||||||
|                    case 1: |                    case 1: | ||||||
|                        WmsConstants.LOG_SQL_ON = n.isOn; |                        WmsConstants.LOG_SQL_ON = n.isOn; | ||||||
|                        break; |                        break; | ||||||
|  |                     case 3: | ||||||
|  |                         WmsConstants.IS_ONLINE_RESTRICT = n.isOn; | ||||||
|  |                         break; | ||||||
| 
 | 
 | ||||||
|                     default: break; |                     default: break; | ||||||
|                } |                } | ||||||
| 
 | 
 | ||||||
|            } |            } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |             dv.RowFilter = "parentId=" + 196; | ||||||
|  |             foreach (DataRowView dr in dv) | ||||||
|  |             { | ||||||
|  |                 Node n = new Node(dr.Row); | ||||||
|  |                 try | ||||||
|  |                 { | ||||||
|  |                     switch (n.flag) | ||||||
|  |                     { | ||||||
|  | 
 | ||||||
|  |                          | ||||||
|  |                         case 6: | ||||||
|  |                             WmsConstants.SYSTEM_VALID_DATE = Util.getShortDateString( n.value); | ||||||
|  |                             WmsConstants.SYSTEM_VALID_LEFT_DAYS = getLeftDays(WmsConstants.SYSTEM_VALID_DATE); | ||||||
|  | 
 | ||||||
|  |                             break; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 catch | ||||||
|  |                 { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|             //   dtSetup = new Node().QueryByFlag(1007);  //JOBS   |             //   dtSetup = new Node().QueryByFlag(1007);  //JOBS   | ||||||
|             dv.RowFilter = "parentId=" + 13373; |             dv.RowFilter = "parentId=" + 13373; | ||||||
|            foreach (DataRowView dr in dv) |            foreach (DataRowView dr in dv) | ||||||
|  | @ -407,7 +462,11 @@ namespace DeiNiu.wms.Logical | ||||||
|                         WmsConstants.STOCK_HIS_KEEP_DAYS = v; |                         WmsConstants.STOCK_HIS_KEEP_DAYS = v; | ||||||
| 
 | 
 | ||||||
|                         break; |                         break; | ||||||
|  |                     case 6: | ||||||
| 
 | 
 | ||||||
|  |                         WmsConstants.MAX_ONLINE_USERS = v; | ||||||
|  | 
 | ||||||
|  |                         break; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -46,7 +46,7 @@ | ||||||
|           <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --> |           <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --> | ||||||
|           <serviceDebug includeExceptionDetailInFaults="false"/> |           <serviceDebug includeExceptionDetailInFaults="false"/> | ||||||
|           <!-- 开发调试引用服务时不需要权限拦截 |           <!-- 开发调试引用服务时不需要权限拦截 | ||||||
|           <AuthenticationBehavior/>--> |           --><AuthenticationBehavior/> | ||||||
|         </behavior> |         </behavior> | ||||||
|         <behavior name="serviceBehaviorNoAuthor"> |         <behavior name="serviceBehaviorNoAuthor"> | ||||||
|           <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 --> |           <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 --> | ||||||
|  |  | ||||||
|  | @ -17,9 +17,11 @@ namespace WcfServiceAuthentication | ||||||
|         public static int testUserId = 0; |         public static int testUserId = 0; | ||||||
|         public static Dictionary<int, string> authCach = new Dictionary<int, string>(); |         public static Dictionary<int, string> authCach = new Dictionary<int, string>(); | ||||||
|         public static Dictionary<int, int> tmpCodes = new Dictionary<int, int>(); |         public static Dictionary<int, int> tmpCodes = new Dictionary<int, int>(); | ||||||
|  |         public static List<int> restrictUsers = new List<int>(); | ||||||
| 
 | 
 | ||||||
|         static string[] publicServices = { "/Login.svc", "/PortalService.svc", "/MobileService.svc", "/ScheduledService.svc", "/android.svc/login" };       |         static string[] publicServices = { "/Login.svc", "/PortalService.svc", "/MobileService.svc", "/ScheduledService.svc", "/android.svc/login" };       | ||||||
| 
 | 
 | ||||||
|  |       | ||||||
|         public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext) |         public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext) | ||||||
|         { |         { | ||||||
|             //注意引用 System.Runtime.Serialization |             //注意引用 System.Runtime.Serialization | ||||||
|  | @ -82,7 +84,7 @@ namespace WcfServiceAuthentication | ||||||
| 
 | 
 | ||||||
|             if (!validUser(userId, token)) // not in cache  |             if (!validUser(userId, token)) // not in cache  | ||||||
|             { |             { | ||||||
|                 LogHelper.debug("svr AuthenticationInspector auth error", string.Format("request: {2},set UserId : {0},set token: {1}", userId, token, request.ToString())); |                 LogHelper.debug("svr AuthenticationInspector auth error", string.Format("request: {2}, UserId : {0}, token: {1}", userId, token, request.ToString())); | ||||||
|                 throw new DeiNiuTimeOutException(WmsConstants.WCF_UN_AUTH_MESSAGE);  |                 throw new DeiNiuTimeOutException(WmsConstants.WCF_UN_AUTH_MESSAGE);  | ||||||
|             } |             } | ||||||
|             if (tmpToken > 0) |             if (tmpToken > 0) | ||||||
|  | @ -100,33 +102,16 @@ namespace WcfServiceAuthentication | ||||||
| 
 | 
 | ||||||
|         public static bool validUser(int userId, string token) |         public static bool validUser(int userId, string token) | ||||||
|         { |         { | ||||||
|          //   |             if (WmsConstants.IS_ONLINE_RESTRICT && restrictUsers.Count>=WmsConstants.MAX_ONLINE_USERS && !restrictUsers.Contains(userId)) | ||||||
|             if (authCach.ContainsKey(userId)) //检查内存 |  | ||||||
|             { |  | ||||||
|                //  LogHelper.debug("AuthenticationInspector", string.Format("get userId {0} in the cache checking token {1},token match? {2}", userId, token, authCach[userId].Equals(token))); |  | ||||||
| #if DEBUG |  | ||||||
| 
 |  | ||||||
|                  if (!authCach[userId].Equals(token)) |  | ||||||
|                  { |  | ||||||
|                      Employee em1 = new Employee(); |  | ||||||
|                      try |  | ||||||
|                      { |  | ||||||
|                          if (em1.login(token) && em1.ID == userId) |  | ||||||
|                          { |  | ||||||
|                              LogHelper.debug("AuthenticationInspector", string.Format("valid token {0} in the db and token match ", token)); |  | ||||||
|                              authCach[userId] = token; |  | ||||||
|                              return true; |  | ||||||
|                          } |  | ||||||
|                      } |  | ||||||
|                      catch |  | ||||||
|             { |             { | ||||||
|  |                 LogHelper.debug("AuthenticationInspector", string.Format(" userId {0} is not in the allowed list, current list size {1}, maxSize {2} ", userId, restrictUsers.Count, WmsConstants.MAX_ONLINE_USERS)); | ||||||
|                 return false; |                 return false; | ||||||
|             } |             } | ||||||
|                  } |          //   | ||||||
| #endif |             if (!authCach.ContainsKey(userId)) //检查内存 | ||||||
|                 return authCach[userId].Equals(token); |             { | ||||||
| 
 |                   LogHelper.debug("AuthenticationInspector", | ||||||
|             } |                       string.Format("userId {0} NOT in the cache, to check db...", userId)   ); | ||||||
|                 |                 | ||||||
|                 //检查db |                 //检查db | ||||||
|                  Employee em = new Employee(); |                  Employee em = new Employee(); | ||||||
|  | @ -134,18 +119,72 @@ namespace WcfServiceAuthentication | ||||||
|                 { |                 { | ||||||
|                     if (em.login(token) && em.ID == userId) |                     if (em.login(token) && em.ID == userId) | ||||||
|                     { |                     { | ||||||
|                    LogHelper.debug("AuthenticationInspector", string.Format("valid token {0} in the db and token match ",  token )); |                         LogHelper.debug("AuthenticationInspector", string.Format("valid token {0} in the db and token match ", token)); | ||||||
|                         authCach[userId] = token; |                         authCach[userId] = token; | ||||||
|                     return true; | 
 | ||||||
|  |                     } | ||||||
|  |                     else | ||||||
|  |                     { | ||||||
|  |                         LogHelper.debug("AuthenticationInspector", | ||||||
|  |                       string.Format("userId {0} and token NOT match db...return false ", userId)); | ||||||
|  |                         return false; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 catch |                 catch | ||||||
|                 { |                 { | ||||||
|                 return false; |                     LogHelper.debug("AuthenticationInspector", | ||||||
|             } |                       string.Format(" exception happened ...return false ", userId)); | ||||||
|                     return false; |                     return false; | ||||||
|                 }   |                 }   | ||||||
| 
 | 
 | ||||||
|  |             } | ||||||
|  |             if(authCach[userId] == token) | ||||||
|  |             { | ||||||
|  |                 if (WmsConstants.IS_ONLINE_RESTRICT) | ||||||
|  |                 { | ||||||
|  |                     checkRestrictUsers(userId); | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return false; | ||||||
|  |            | ||||||
|  |            | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public static void checkRestrictUsers(int userId) | ||||||
|  |         { | ||||||
|  |             if (userId <= 0) | ||||||
|  |             { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |            // LogHelper.debug("1 checkRestrictUsers", string.Format(" checking ..userId {0}  , current list size {1}, maxSize {2} ", userId, restrictUsers.Count, WmsConstants.MAX_ONLINE_USERS)); | ||||||
|  |             if (!AuthenticationInspector.restrictUsers.Contains(userId)) | ||||||
|  |             { | ||||||
|  |                 if (AuthenticationInspector.restrictUsers.Count >= WmsConstants.MAX_ONLINE_USERS) | ||||||
|  |                 { | ||||||
|  |                     LogHelper.debug("checkRestrictUsers", string.Format(" to remove ..userId {0}   ", AuthenticationInspector.restrictUsers[0])); | ||||||
|  | 
 | ||||||
|  |                     AuthenticationInspector.restrictUsers.RemoveAt(0); | ||||||
|  |                 } | ||||||
|  |                 AuthenticationInspector.restrictUsers.Add(userId); | ||||||
|  | 
 | ||||||
|  |                 foreach (int i in AuthenticationInspector.restrictUsers) | ||||||
|  |                 { | ||||||
|  |                     LogHelper.debug("checkRestrictUsers", string.Format(" active userId {0}   ", i)); | ||||||
|  | 
 | ||||||
|  |                 } | ||||||
|  |             }  | ||||||
|  |             /* | ||||||
|  |             LogHelper.debug("2 checkRestrictUsers", string.Format(" checking ..userId {0}  , current list size {1}, maxSize {2} ", userId, restrictUsers.Count, WmsConstants.MAX_ONLINE_USERS)); | ||||||
|  | 
 | ||||||
|  |             foreach(int i in AuthenticationInspector.restrictUsers) | ||||||
|  |             { | ||||||
|  |                 LogHelper.debug("checkRestrictUsers", string.Format(" active userId {0}   ", i)); | ||||||
|  | 
 | ||||||
|  |             } | ||||||
|  |             */ | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -23,7 +23,6 @@ using DeiNiu.wms.win.utils; | ||||||
| using System.Deployment.Application; | using System.Deployment.Application; | ||||||
| 
 | 
 | ||||||
|   |   | ||||||
| 
 |  | ||||||
| namespace DeiNiu.wms.win | namespace DeiNiu.wms.win | ||||||
| { | { | ||||||
|     public partial class main : BasicRibbonForm |     public partial class main : BasicRibbonForm | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue