UsersRepository.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Entities.System;
  4. using OASystem.Domain.ViewModels.System;
  5. using SqlSugar;
  6. using StackExchange.Redis;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OASystem.Infrastructure.Repositories.System
  13. {
  14. public class UsersRepository : BaseRepository<UserInfo, UserInfoWebView>
  15. {
  16. public UsersRepository(SqlSugarClient sqlSugar) : base(sqlSugar){}
  17. /// <summary>
  18. /// 用户查询列表
  19. /// </summary>
  20. /// <param name="_userRep"></param>
  21. /// <returns></returns>
  22. public async Task<Result> GetUserList(int portType,string sqlWhere)
  23. {
  24. Result result = new Result() { Code = -2 };
  25. //List<UserInfoWebView> _userList = _sqlSugar.Queryable<Sys_Users>()
  26. // .InnerJoin<Sys_Company>((u, c) => u.CompanyId == c.Id) //若是多个条件 用 &&
  27. // .InnerJoin<Sys_Department>((u, c, d) => u.DepId == d.Id)
  28. // .InnerJoin<Sys_JobPost>((u, c, d, j) => u.JobPostId == j.Id)
  29. // .Where((u) => u.Id == 208)
  30. // .Select
  31. // ((u, c, d, j) => new UserInfoWebView
  32. // {
  33. // Number = u.Number,
  34. // CompanyId = u.CompanyId,
  35. // CompanyName = c.CompanyName,
  36. // DepId=u.DepId,
  37. // DepName = d.DepName,
  38. // JobPostId = u.JobPostId,
  39. // JobName = j.JobName,
  40. // Id = u.Id,
  41. // CnName = u.CnName,
  42. // Phone = u.Phone,
  43. // UrgentPhone = u.UrgentPhone,
  44. // Ext =u.Ext,
  45. // Email = u.Email,
  46. // })
  47. // .ToList();
  48. if (portType == 1) //web
  49. {
  50. string userSqlWhere = string.Format(@"Select su.CompanyId, sc.CompanyName,su.DepId,sd.DepName,su.JobPostId,sjp.JobName,
  51. su.Id UserId,su.CnName,su.CnName,su.Number,su.Ext,su.Phone,su.UrgentPhone,su.Email
  52. From Sys_Users su
  53. Inner Join Sys_Company sc On su.CompanyId = sc.Id
  54. Inner Join Sys_Department sd On su.DepId = sd.Id
  55. Inner Join Sys_JobPost sjp On su.JobPostId = sjp.Id Where su.IsDel = 0");
  56. var _userList = await _sqlSugar.SqlQueryable<UserInfoWebView>(userSqlWhere).ToListAsync();
  57. if (_userList.Count != 0)
  58. {
  59. result.Code = 0;
  60. result.Msg = "成功!";
  61. result.Data = _userList;
  62. }
  63. else
  64. {
  65. result.Msg = "暂无数据!";
  66. }
  67. }
  68. else if (portType == 2) //Android
  69. {
  70. string userSqlWhere = string.Format(@"Select su.CompanyId, sc.CompanyName,su.DepId,sd.DepName,su.JobPostId,sjp.JobName,
  71. su.Id UserId,su.CnName,su.CnName,su.Number,su.Ext,su.Phone,su.UrgentPhone,su.Email
  72. From Sys_Users su
  73. Inner Join Sys_Company sc On su.CompanyId = sc.Id
  74. Inner Join Sys_Department sd On su.DepId = sd.Id
  75. Inner Join Sys_JobPost sjp On su.JobPostId = sjp.Id ");
  76. var _userList = await _sqlSugar.SqlQueryable<UserInfoWebView>(userSqlWhere).ToListAsync();
  77. if (_userList.Count != 0)
  78. {
  79. result.Code = 0;
  80. result.Msg = "成功!";
  81. result.Data = _userList;
  82. }
  83. else
  84. {
  85. result.Msg = "暂无数据!";
  86. }
  87. }
  88. else if (portType == 3) //IOS
  89. {
  90. }
  91. else
  92. {
  93. result.Msg = "暂无数据!";
  94. }
  95. return result;
  96. }
  97. /// <summary>
  98. /// 用户查询列表
  99. /// </summary>
  100. /// <param name="_userRep"></param>
  101. /// <returns></returns>
  102. public async Task<Result> GetUserNameList(int portType)
  103. {
  104. Result result = new Result() { Code = -2 };
  105. if (portType == 1 || portType == 2) //web
  106. {
  107. string sql = string.Format(@"Select Id,CnName From Sys_Users Where Isdel=0 And HrAudit = 1");
  108. var _userList = await _sqlSugar.SqlQueryable<UserNameView>(sql).ToListAsync();
  109. if (_userList.Count != 0)
  110. {
  111. result.Code = 0;
  112. result.Msg = "成功!";
  113. result.Data = _userList;
  114. }
  115. else
  116. {
  117. result.Msg = "暂无数据!";
  118. }
  119. }
  120. else if (portType == 2) //Android
  121. {
  122. }
  123. else if (portType == 3) //IOS
  124. {
  125. }
  126. else
  127. {
  128. result.Msg = "暂无数据!";
  129. }
  130. return result;
  131. }
  132. public async Task<List<UserInfo>> QueryUser(string sqlWhere)
  133. {
  134. string sql = string.Format(@"Select sc.CompanyName,sd.DepName,sjp.JobName,su.* From Sys_Users su
  135. left Join Sys_Company sc On su.CompanyId = sc.Id
  136. left Join Sys_Department sd On su.DepId = sd.Id
  137. left Join Sys_JobPost sjp On su.JobPostId = sjp.Id {0}", sqlWhere);
  138. return await _sqlSugar.SqlQueryable<UserInfo>(sql).ToListAsync();
  139. }
  140. }
  141. }