using AutoMapper; using OASystem.Domain; using OASystem.Domain.AesEncryption; using OASystem.Domain.Entities.System; using OASystem.Domain.ViewModels.System; using SqlSugar; using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OASystem.Infrastructure.Repositories.System { public class UsersRepository : BaseRepository { public UsersRepository(SqlSugarClient sqlSugar) : base(sqlSugar){} /// /// 用户查询列表 /// /// /// public async Task GetUserList(int portType,string sqlWhere) { Result result = new Result() { Code = -2, Msg = "暂无数据!" }; string userSqlWhere = string.Format(@"Select su.CompanyId, sc.CompanyName,su.DepId,sd.DepName,su.JobPostId,sjp.JobName, su.Id UserId,su.CnName,su.Number,su.Ext,su.Phone,su.UrgentPhone,su.Email From Sys_Users su Inner Join Sys_Company sc On su.CompanyId = sc.Id Inner Join Sys_Department sd On su.DepId = sd.Id Inner Join Sys_JobPost sjp On su.JobPostId = sjp.Id Where su.IsDel = 0"); var _userList = await _sqlSugar.SqlQueryable(userSqlWhere).ToListAsync(); if (portType == 1 || portType == 2 || portType == 3) //web、Android、ios { //解密 foreach (var user in _userList) EncryptionProcessor.DecryptProperties(user); if (_userList.Count != 0) { result.Code = 0; result.Msg = "成功!"; result.Data = _userList; } } return result; } /// /// 用户查询列表 /// /// /// public async Task GetUserNameList(int portType) { Result result = new Result() { Code = -2 }; if (portType == 1 || portType == 2) //web { string sql = string.Format(@"Select Id,CnName From Sys_Users Where Isdel=0 And HrAudit = 1"); var _userList = await _sqlSugar.SqlQueryable(sql).ToListAsync(); if (_userList.Count != 0) { result.Code = 0; result.Msg = "成功!"; result.Data = _userList; } else { result.Msg = "暂无数据!"; } } else if (portType == 2) //Android { } else if (portType == 3) //IOS { } else { result.Msg = "暂无数据!"; } return result; } public async Task> QueryUser(string sqlWhere) { string sql = string.Format(@"Select sc.CompanyName,sd.DepName,sjp.JobName,su.* From Sys_Users su left Join Sys_Company sc On su.CompanyId = sc.Id left Join Sys_Department sd On su.DepId = sd.Id left Join Sys_JobPost sjp On su.JobPostId = sjp.Id {0}", sqlWhere); return await _sqlSugar.SqlQueryable(sql).ToListAsync(); } /// /// 员工简略信息 /// /// /// public async Task GetUserBriefInfo(int id) { var info = await _sqlSugar .Queryable() .LeftJoin((u, jp) => u.JobPostId == jp.Id) .Where((u, jp) => u.Id == id) .Select((u, jp) => new UserBriefInfo() { Id = u.Id, Name = u.CnName, Job = jp.JobName, Telephone = u.Ext, ExtensionNumber = u.Ext, Tel = u.Phone, Email = u.Email, }) .FirstAsync(); info.Tel = AesEncryptionHelper.Decrypt(info.Tel); return info; } } }