using DocumentServiceAPI.Application.UserAndLogin.Services.Interfaces; using DocumentServiceAPI.Application.UserAndLogin.ViewMode; using DocumentServiceAPI.Model; using DocumentServiceAPI.Model.cyDocumentModel; using DocumentServiceAPI.Model.UserInfoModel; using SqlSugar.Extensions; using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Text; using System.Threading.Tasks; namespace DocumentServiceAPI.Application.UserAndLogin.Services { /// /// 登录验证服务 /// public class UserService : ILoginVerifyService, IScoped { private ISqlSugarClient _db { get; set; } public UserService(ISqlSugarClient db) { _db = db; } /// /// 员工详情 /// /// /// /// public async Task GetEmployeeInfo(int ID, int TenantID) { var ret = await _db.Queryable((ei, eiat, ti) => new JoinQueryInfos( JoinType.Right, ei.Id == eiat.EmployeeID, //左连接 左链接 左联 JoinType.Right, ti.Id == eiat.TenantID )).Where((ei, eiat, ti) => ei.Id == ID && TenantID == ti.Id) .Select(expression: (ei, eiat, ti) => new EmployeeTenantInfo { _employeeInfo = ei, _tenantInfo = ti }).SingleAsync(); return ret; } /// /// 获取Jwt相关信息 /// public JwtInfo GetJwtInfo() { JwtInfo jwtInfo = new JwtInfo(); jwtInfo.LogInSource = (LogInFrom)(App.User?.FindFirstValue("loginfrom")?.ObjToInt() ?? 0); jwtInfo.EID = App.User?.FindFirstValue("eid")?.ObjToInt(); jwtInfo.UID = App.User?.FindFirstValue("uid")?.ObjToInt(); jwtInfo.TID = App.User?.FindFirstValue("tid")?.ObjToInt(); var guid = App.User?.FindFirstValue("jid"); jwtInfo.JID = string.IsNullOrEmpty(guid) ? new Guid(guid) : null; return jwtInfo; } /// /// 获取单位列表 /// /// public async Task> GetUserUnitInfo(int tid ) { var list = await _db.Queryable() .Where((tu) => tu.TenantId == tid && tu.IsEn == true && tu.IsDeled != true) .Select((tu) => new UnitVM { UnitID = tu.UnitId, UnitName = tu.UnitName, Remark = tu.Remark, UnitLogo = tu.UnitLogo, }) .ToListAsync(); return list; } /// /// 根据账号获取 Tender 列表 /// /// /// public async Task> GetUserTenderList(string ItCode) { var tentlist= await _db.Queryable((ti, et, ei) => new JoinQueryInfos ( JoinType.Right, ti.Id == et.TenantID, //左连接 左链接 左联 JoinType.Right, ei.EmployeeId == et.EmployeeID ) ) .Where((ti, et, ei) => ( ei.UserName == ItCode) && (ti.IsEn == true) && (ti.IsDel != true) && (ei.IsWork == null || ei.IsWork == 1)) .Select((ti, et, ei) => new TenderVM { EmployeeID = ei.EmployeeId, Description = ti.Description, ItCode = ItCode, Name = ti.Name, TenderId = ti.Id } ).ToListAsync(); var ten = await _db.Queryable().Where(x => x.IsEn == true && x.IsDel != true && x.ItCode == ItCode) .Select(x => new TenderVM { Description = x.Description, ItCode = ItCode, Name = x.Name, TenderId = x.Id, IsTender = true } ).ToListAsync() ; ten.AddRange(tentlist); return ten; } /// /// 检查密码是否登录 /// /// 租户ID /// 员工ID /// 密码 /// public async Task CheckPsw(int TenantID, int? employeeID, string PsW) { if (employeeID == null) { var psw = await _db.Queryable().Where(x => x.Id == TenantID).Select(x => x.PsW).SingleAsync(); if (PsW == psw) return true; } else { var psw = await _db.Queryable((ei, et, ti) => new JoinQueryInfos ( JoinType.Left, ei.EmployeeId == et.EmployeeID, //左连接 左链接 左联 JoinType.Left, ti.Id == et.TenantID ) ).Where((ei, et, ti) => ei.EmployeeId == employeeID && ti.Id == TenantID ) .Select((ei, et, ti) => ei.UserPassWord) .SingleAsync(); if (PsW == psw) return true; } return false; } } }