纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.3 KiB

3 years ago
3 years ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemManage;
  3. using NFine.Domain.IRepository.SystemManage;
  4. using NFine.Repository.SystemManage;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Data;
  9. using System.Data.Common;
  10. using System.Text;
  11. using NFine.Data.Extensions;
  12. namespace NFine.Application.SystemManage
  13. {
  14. public class UserApp
  15. {
  16. private IUserRepository service = new UserRepository();
  17. private UserLogOnApp userLogOnApp = new UserLogOnApp();
  18. public List<UserEntity> GetList()
  19. {
  20. return service.IQueryable().OrderBy(t => t.F_CreatorTime).ToList();
  21. }
  22. public List<UserEntity> GetList(Pagination pagination, string keyword)
  23. {
  24. var expression = ExtLinq.True<UserEntity>();
  25. if (!string.IsNullOrEmpty(keyword))
  26. {
  27. expression = expression.And(t => t.F_Account.Contains(keyword));
  28. expression = expression.Or(t => t.F_RealName.Contains(keyword));
  29. expression = expression.Or(t => t.F_MobilePhone.Contains(keyword));
  30. }
  31. expression = expression.And(t => t.F_Account != "admin");
  32. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  33. {
  34. string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  35. expression = expression.And(t => t.F_Account== UserCode);
  36. }
  37. return service.FindList(expression, pagination);
  38. }
  39. public UserEntity GetForm(string keyValue)
  40. {
  41. if (keyValue == "SYS")
  42. keyValue = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
  43. return service.FindEntity(keyValue);
  44. }
  45. public void DeleteForm(string keyValue)
  46. {
  47. service.DeleteForm(keyValue);
  48. }
  49. public void SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
  50. {
  51. if (!string.IsNullOrEmpty(keyValue))
  52. {
  53. userEntity.Modify(keyValue);
  54. }
  55. else
  56. {
  57. userEntity.Create();
  58. }
  59. service.SubmitForm(userEntity, userLogOnEntity, keyValue);
  60. }
  61. public void UpdateForm(UserEntity userEntity)
  62. {
  63. service.Update(userEntity);
  64. }
  65. public UserEntity CheckLogin(string username, string password, string WorkPoint)
  66. {
  67. UserEntity userEntity = service.FindEntity(t => t.F_Account == username && t.F_Location== WorkPoint);
  68. if (userEntity != null)
  69. {
  70. if (userEntity.F_EnabledMark == true)
  71. {
  72. UserLogOnEntity userLogOnEntity = userLogOnApp.GetForm(userEntity.F_Id);
  73. string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
  74. if (dbPassword == userLogOnEntity.F_UserPassword)
  75. {
  76. DateTime lastVisitTime = DateTime.Now;
  77. int LogOnCount = (userLogOnEntity.F_LogOnCount).ToInt() + 1;
  78. if (userLogOnEntity.F_LastVisitTime != null)
  79. {
  80. userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate();
  81. }
  82. userLogOnEntity.F_LastVisitTime = lastVisitTime;
  83. userLogOnEntity.F_LogOnCount = LogOnCount;
  84. userLogOnApp.UpdateForm(userLogOnEntity);
  85. return userEntity;
  86. }
  87. else
  88. {
  89. throw new Exception("密码不正确,请重新输入");
  90. }
  91. }
  92. else
  93. {
  94. throw new Exception("账户被系统锁定,请联系管理员");
  95. }
  96. }
  97. else
  98. {
  99. throw new Exception("账户不存在,请重新输入");
  100. }
  101. }
  102. public void AgentUserAndVenCode()
  103. {
  104. string sql = @"SELECT UserCode,UserName,WorkPointCode FROM dbo.Sys_User
  105. WHERE UserCode NOT IN (SELECT F_Account FROM dbo.Sys_SRM_User)";
  106. DataTable dtUser = SqlHelper.GetDataTableBySql(sql);
  107. foreach (DataRow dr in dtUser.Rows)
  108. {
  109. string sqlUser = string.Empty;
  110. string NewGuid = Common.GuId();
  111. sqlUser = @"INSERT INTO dbo.Sys_SRM_User
  112. ( F_Id ,F_Account ,F_RealName ,F_NickName ,
  113. F_RoleId ,F_IsAdministrator , F_EnabledMark ,
  114. F_CreatorTime ,F_CreatorUserId ,F_Location ,
  115. F_VenCode)
  116. SELECT '"+ NewGuid + @"',UserCode,UserName,UserName,
  117. '5130ce87-a5ed-409f-b035-9277f65e1d7f',0,1,
  118. GETDATE(),'9f2ec079-7d0f-4fe2-90ab-8b09a8302aba','"+dr["WorkPointCode"].ToString() +@"',''
  119. FROM dbo.Sys_User WHERE UserCode='"+dr["UserCode"].ToString()+ "' and WorkPointCode='" + dr["WorkPointCode"].ToString() + @"'";
  120. try
  121. {
  122. SqlHelper.ExecuteNonQuery(sqlUser);
  123. }
  124. catch (Exception ex)
  125. {
  126. throw new Exception(ex.Message);
  127. }
  128. string UserSecretkey = Md5.md5(Common.CreateNo(), 16).ToLower();
  129. string pwd = Md5.md5(DESEncrypt.Encrypt(Md5.md5("123456", 32).ToLower(), UserSecretkey).ToLower(), 32).ToLower();
  130. sqlUser = @"INSERT INTO dbo.Sys_SRM_UserLogOn
  131. ( F_Id ,F_UserId ,F_UserPassword ,F_UserSecretkey
  132. )
  133. VALUES ( '" + NewGuid + @"','" + NewGuid + @"','"+ pwd + "','" + UserSecretkey + "')";
  134. try
  135. {
  136. SqlHelper.ExecuteNonQuery(sqlUser);
  137. }
  138. catch (Exception ex)
  139. {
  140. throw new Exception(ex.Message);
  141. }
  142. }
  143. }
  144. }
  145. }