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.Generic; | ||||
| using System.Linq; | ||||
| using WcfServiceAuthentication; | ||||
| 
 | ||||
| namespace DeiNiu.wms.Logical | ||||
| { | ||||
|  | @ -241,6 +242,8 @@ namespace DeiNiu.wms.Logical | |||
|                 em.AuthSpecials = getAuthObjLst(em.ID, "细分权限"); | ||||
|                 | ||||
|             } | ||||
|             AuthenticationInspector.checkRestrictUsers(em.ID); | ||||
| 
 | ||||
|             return em; | ||||
|             | ||||
|         } | ||||
|  |  | |||
|  | @ -121,6 +121,10 @@ | |||
|       <Project>{151F88A4-82D0-4E30-A9B5-AB0B0ADA1FBD}</Project> | ||||
|       <Name>Utils</Name> | ||||
|     </ProjectReference> | ||||
|     <ProjectReference Include="..\WcfServiceAuthentication\WcfServiceAuthentication.csproj"> | ||||
|       <Project>{ca44f42f-4376-4bc6-9ea4-821db704c75d}</Project> | ||||
|       <Name>WcfServiceAuthentication</Name> | ||||
|     </ProjectReference> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> | ||||
|  |  | |||
|  | @ -326,7 +326,15 @@ namespace DeiNiu.wms.Data.Model | |||
|             return al; | ||||
|         } | ||||
| 
 | ||||
|          | ||||
| 
 | ||||
|         private string _extrMsg = ""; | ||||
| 
 | ||||
|         public string extrMsg | ||||
|         { | ||||
|             get { return _extrMsg; } | ||||
|             set { _extrMsg = value; } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -7,7 +7,10 @@ namespace DeiNiu.Utils | |||
| { | ||||
|     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 string SQL_CONN_WMS = ""; | ||||
|         public static string SQL_CONN_PLATFORM = ""; | ||||
|  |  | |||
|  | @ -282,10 +282,14 @@ namespace DeiNiu.Wcf | |||
| 
 | ||||
|         public FormatedResult login(string account, string passwd) | ||||
|         { | ||||
|               | ||||
| 
 | ||||
|             LAuthority auth = new LAuthority(); | ||||
|             Employee em = auth.login(account, passwd); | ||||
|             AuthenticationInspector.authCach[em.ID] = em.token; | ||||
| 
 | ||||
|         | ||||
| 
 | ||||
|             List<string> tmp = new List<string>(); | ||||
| 
 | ||||
|             foreach (Authority au in em.AuthSpecials) | ||||
|  | @ -296,6 +300,25 @@ namespace DeiNiu.Wcf | |||
|             ConstAuthourity.setSpecialAuths(em.ID, tmp); | ||||
| 
 | ||||
|             //  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); | ||||
| 
 | ||||
|         } | ||||
|  |  | |||
|  | @ -2454,6 +2454,11 @@ namespace DeiNiu.wms.Logical | |||
|             enumReceiveStockDetailStatus nextState = enumReceiveStockDetailStatus.待验收; | ||||
| 
 | ||||
|             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) | ||||
|             { | ||||
|                 nextState = enumReceiveStockDetailStatus.已验收; | ||||
|  | @ -3415,6 +3420,7 @@ namespace DeiNiu.wms.Logical | |||
|                     catch (Exception er) | ||||
|                     { | ||||
|                         logIn.Error(er); | ||||
|                         throw er; | ||||
|                     } | ||||
|                     //    scope.Complete(); | ||||
|                 } | ||||
|  |  | |||
|  | @ -311,6 +311,10 @@ namespace DeiNiu.wms.Logical | |||
|                  { | ||||
|                      return false; | ||||
|                  } | ||||
|                 if (string.IsNullOrEmpty(batch)) | ||||
|                 { | ||||
|                     batch = _obj.getDateTime(); | ||||
|                 } | ||||
|                  _obj.skuCode = sku.skuCode; | ||||
|                  _obj.productDate = String.IsNullOrEmpty( sku.ProductDate)?batch:sku.ProductDate ; | ||||
|                  _obj.validDate = String.IsNullOrEmpty(sku.ValidDate) ? batch : sku.ValidDate; | ||||
|  |  | |||
|  | @ -74,7 +74,31 @@ namespace DeiNiu.wms.Logical | |||
|             ts = ts1.Subtract(new TimeSpan(DateTime.Now.Ticks)).Duration(); | ||||
|            return ts.Days; | ||||
|         } | ||||
|       public void initialConstants() | ||||
| 
 | ||||
|         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() | ||||
|        { | ||||
|            if (WmsConstants.IS_INITIALED) | ||||
|            { | ||||
|  | @ -97,14 +121,45 @@ namespace DeiNiu.wms.Logical | |||
|                    case 1: | ||||
|                        WmsConstants.LOG_SQL_ON = n.isOn; | ||||
|                        break; | ||||
|                     | ||||
|                    default: break; | ||||
|                     case 3: | ||||
|                         WmsConstants.IS_ONLINE_RESTRICT = n.isOn; | ||||
|                         break; | ||||
| 
 | ||||
|                     default: break; | ||||
|                } | ||||
| 
 | ||||
|            } | ||||
| 
 | ||||
|         //   dtSetup = new Node().QueryByFlag(1007);  //JOBS   | ||||
|            dv.RowFilter = "parentId=" + 13373; | ||||
| 
 | ||||
|             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   | ||||
|             dv.RowFilter = "parentId=" + 13373; | ||||
|            foreach (DataRowView dr in dv) | ||||
|            { | ||||
|                Node n = new Node(dr.Row); | ||||
|  | @ -407,7 +462,11 @@ namespace DeiNiu.wms.Logical | |||
|                         WmsConstants.STOCK_HIS_KEEP_DAYS = v; | ||||
| 
 | ||||
|                         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 以避免泄漏异常信息 --> | ||||
|           <serviceDebug includeExceptionDetailInFaults="false"/> | ||||
|           <!-- 开发调试引用服务时不需要权限拦截 | ||||
|           <AuthenticationBehavior/>--> | ||||
|           --><AuthenticationBehavior/> | ||||
|         </behavior> | ||||
|         <behavior name="serviceBehaviorNoAuthor"> | ||||
|           <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 --> | ||||
|  |  | |||
|  | @ -17,9 +17,11 @@ namespace WcfServiceAuthentication | |||
|         public static int testUserId = 0; | ||||
|         public static Dictionary<int, string> authCach = new Dictionary<int, string>(); | ||||
|         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" };       | ||||
| 
 | ||||
|       | ||||
|         public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext) | ||||
|         { | ||||
|             //注意引用 System.Runtime.Serialization | ||||
|  | @ -82,7 +84,7 @@ namespace WcfServiceAuthentication | |||
| 
 | ||||
|             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);  | ||||
|             } | ||||
|             if (tmpToken > 0) | ||||
|  | @ -100,52 +102,89 @@ namespace WcfServiceAuthentication | |||
| 
 | ||||
|         public static bool validUser(int userId, string token) | ||||
|         { | ||||
|          //   | ||||
|             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 | ||||
|                      { | ||||
|                          return false; | ||||
|                      } | ||||
|                  } | ||||
| #endif | ||||
|                 return authCach[userId].Equals(token); | ||||
| 
 | ||||
|             } | ||||
| 
 | ||||
|             //检查db | ||||
|             Employee em = new Employee(); | ||||
|             try | ||||
|             { | ||||
|                 if (em.login(token) && em.ID == userId) | ||||
|                 { | ||||
|                    LogHelper.debug("AuthenticationInspector", string.Format("valid token {0} in the db and token match ",  token )); | ||||
|                     authCach[userId] = token; | ||||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|             catch | ||||
|             if (WmsConstants.IS_ONLINE_RESTRICT && restrictUsers.Count>=WmsConstants.MAX_ONLINE_USERS && !restrictUsers.Contains(userId)) | ||||
|             { | ||||
|                 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; | ||||
|             } | ||||
|          //   | ||||
|             if (!authCach.ContainsKey(userId)) //检查内存 | ||||
|             { | ||||
|                   LogHelper.debug("AuthenticationInspector", | ||||
|                       string.Format("userId {0} NOT in the cache, to check db...", userId)   ); | ||||
|                 | ||||
|                 //检查db | ||||
|                  Employee em = new Employee(); | ||||
|                 try | ||||
|                 { | ||||
|                     if (em.login(token) && em.ID == userId) | ||||
|                     { | ||||
|                         LogHelper.debug("AuthenticationInspector", string.Format("valid token {0} in the db and token match ", token)); | ||||
|                         authCach[userId] = token; | ||||
| 
 | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         LogHelper.debug("AuthenticationInspector", | ||||
|                       string.Format("userId {0} and token NOT match db...return false ", userId)); | ||||
|                         return false; | ||||
|                     } | ||||
|                 } | ||||
|                 catch | ||||
|                 { | ||||
|                     LogHelper.debug("AuthenticationInspector", | ||||
|                       string.Format(" exception happened ...return false ", userId)); | ||||
|                     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)); | ||||
| 
 | ||||
|             } | ||||
|             */ | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -21,9 +21,8 @@ using System.Runtime.InteropServices; | |||
| using DeiNiu.Utils; | ||||
| using DeiNiu.wms.win.utils; | ||||
| using System.Deployment.Application; | ||||
| 
 | ||||
|   | ||||
| 
 | ||||
| 
 | ||||
| namespace DeiNiu.wms.win | ||||
| { | ||||
|     public partial class main : BasicRibbonForm | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue