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.

166 lines
6.7 KiB

  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 UserList = service.FindEntity(t => t.F_Account == userEntity.F_Account && t.F_Location == userEntity.F_Location);
  58. if (UserList != null)
  59. {
  60. throw new Exception("该用户已在站点:" + userEntity.F_Location + "存在!");
  61. }
  62. userEntity.Create();
  63. }
  64. service.SubmitForm(userEntity, userLogOnEntity, keyValue);
  65. }
  66. public void UpdateForm(UserEntity userEntity)
  67. {
  68. service.Update(userEntity);
  69. }
  70. public UserEntity CheckLogin(string username, string password, string WorkPoint)
  71. {
  72. UserEntity userEntity = service.FindEntity(t => t.F_Account == username && t.F_Location== WorkPoint);
  73. if (userEntity != null)
  74. {
  75. if (userEntity.F_EnabledMark == true)
  76. {
  77. UserLogOnEntity userLogOnEntity = userLogOnApp.GetForm(userEntity.F_Id);
  78. string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
  79. if (dbPassword == userLogOnEntity.F_UserPassword)
  80. {
  81. DateTime lastVisitTime = DateTime.Now;
  82. int LogOnCount = (userLogOnEntity.F_LogOnCount).ToInt() + 1;
  83. if (userLogOnEntity.F_LastVisitTime != null)
  84. {
  85. userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate();
  86. }
  87. userLogOnEntity.F_LastVisitTime = lastVisitTime;
  88. userLogOnEntity.F_LogOnCount = LogOnCount;
  89. userLogOnApp.UpdateForm(userLogOnEntity);
  90. return userEntity;
  91. }
  92. else
  93. {
  94. throw new Exception("密码不正确,请重新输入");
  95. }
  96. }
  97. else
  98. {
  99. throw new Exception("账户被系统锁定,请联系管理员");
  100. }
  101. }
  102. else
  103. {
  104. throw new Exception("账户不存在,请重新输入");
  105. }
  106. }
  107. public void AgentUserAndVenCode()
  108. {
  109. string sql = @"SELECT UserCode,UserName,WorkPointCode FROM dbo.Sys_User
  110. WHERE UserCode NOT IN (SELECT F_Account FROM dbo.Sys_SRM_User)";
  111. DataTable dtUser = SqlHelper.GetDataTableBySql(sql);
  112. foreach (DataRow dr in dtUser.Rows)
  113. {
  114. string sqlUser = string.Empty;
  115. string NewGuid = Common.GuId();
  116. sqlUser = @"INSERT INTO dbo.Sys_SRM_User
  117. ( F_Id ,F_Account ,F_RealName ,F_NickName ,
  118. F_RoleId ,F_IsAdministrator , F_EnabledMark ,
  119. F_CreatorTime ,F_CreatorUserId ,F_Location ,
  120. F_VenCode)
  121. SELECT '"+ NewGuid + @"',UserCode,UserName,UserName,
  122. '5130ce87-a5ed-409f-b035-9277f65e1d7f',0,1,
  123. GETDATE(),'9f2ec079-7d0f-4fe2-90ab-8b09a8302aba','"+dr["WorkPointCode"].ToString() +@"',''
  124. FROM dbo.Sys_User WHERE UserCode='"+dr["UserCode"].ToString()+ "' and WorkPointCode='" + dr["WorkPointCode"].ToString() + @"'";
  125. try
  126. {
  127. SqlHelper.ExecuteNonQuery(sqlUser);
  128. }
  129. catch (Exception ex)
  130. {
  131. throw new Exception(ex.Message);
  132. }
  133. string UserSecretkey = Md5.md5(Common.CreateNo(), 16).ToLower();
  134. string pwd = Md5.md5(DESEncrypt.Encrypt(Md5.md5("123456", 32).ToLower(), UserSecretkey).ToLower(), 32).ToLower();
  135. sqlUser = @"INSERT INTO dbo.Sys_SRM_UserLogOn
  136. ( F_Id ,F_UserId ,F_UserPassword ,F_UserSecretkey
  137. )
  138. VALUES ( '" + NewGuid + @"','" + NewGuid + @"','"+ pwd + "','" + UserSecretkey + "')";
  139. try
  140. {
  141. SqlHelper.ExecuteNonQuery(sqlUser);
  142. }
  143. catch (Exception ex)
  144. {
  145. throw new Exception(ex.Message);
  146. }
  147. }
  148. }
  149. }
  150. }