From 3f4013e9283d1fe29ef40cc8b4d7ee7a590a1590 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期二, 17 十月 2023 09:26:40 +0800
Subject: [PATCH] 最新代码
---
DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs | 314 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 292 insertions(+), 22 deletions(-)
diff --git a/DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs b/DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs
index 565e374..be334f5 100644
--- a/DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs
+++ b/DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs
@@ -1,8 +1,14 @@
-锘縰sing DocumentServiceAPI.Application.UserAndLogin.Services.Interfaces;
+锘縰sing DocumentServiceAPI.Application.Repository;
+using DocumentServiceAPI.Application.UserAndLogin.Services.Interfaces;
using DocumentServiceAPI.Application.UserAndLogin.ViewMode;
using DocumentServiceAPI.Model;
using DocumentServiceAPI.Model.cyDocumentModel;
+using DocumentServiceAPI.Model.Permissions;
using DocumentServiceAPI.Model.UserInfoModel;
+using DocumentServiceAPI.Services.IService;
+using DocumentServiceAPI.Utility;
+using Furion.Logging.Extensions;
+using MapsterMapper;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
@@ -13,15 +19,27 @@
namespace DocumentServiceAPI.Application.UserAndLogin.Services
{
+
/// <summary>
/// 鐧诲綍楠岃瘉鏈嶅姟
/// </summary>
- public class UserService : ILoginVerifyService, IScoped
+ public class UserService : IUserService, IScoped
{
+ /// <summary>
+ /// TenantPermissions鍦≧edis涓殑閿��
+ /// </summary>
+ public const string TenantPermissions_RedisKey = "TenantPermissionsKen:";
private ISqlSugarClient _db { get; set; }
- public UserService(ISqlSugarClient db)
+ private EmployeeRepository _employeeRepository{ get; set; }
+ private IMapper _mapper { get; set; }
+ private IRedisCacheService _cacheService { get; set; }
+
+ public UserService(ISqlSugarClient db, EmployeeRepository employeeRepository, IMapper mapper , IRedisCacheService cacheService)
{
_db = db;
+ _employeeRepository = employeeRepository;
+ _mapper = mapper;
+ _cacheService = cacheService;
}
/// <summary>
/// 鍛樺伐璇︽儏
@@ -55,16 +73,17 @@
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();
+ jwtInfo.TEID = App.User?.FindFirstValue("teid")?.ObjToInt();
var guid = App.User?.FindFirstValue("jid");
- jwtInfo.JID = string.IsNullOrEmpty(guid) ? new Guid(guid) : null;
+ jwtInfo.JID = string.IsNullOrEmpty(guid) ? null: new Guid(guid);
return jwtInfo;
}
+
/// <summary>
/// 鑾峰彇鍗曚綅鍒楄〃
/// </summary>
/// <returns></returns>
- public async Task<List<UnitVM>> GetUserUnitInfo(int tid )
+ public async Task<List<UnitVM>> GetUserUnitList(int tid )
{
var list = await _db.Queryable<DocumentServiceAPI.Model.cyDocumentModel.Document_TenderUnit>()
@@ -75,7 +94,7 @@
UnitName = tu.UnitName,
Remark = tu.Remark,
UnitLogo = tu.UnitLogo,
- })
+ }).WithCache(10)
.ToListAsync();
return list;
}
@@ -109,22 +128,22 @@
TenderId = ti.Id
}
- ).ToListAsync();
+ ).WithCache( 10).ToListAsync();
+ //涓嶅啀閫夋嫨绉熸埛
+ //var ten = await _db.Queryable<TenantInfo>().Where(x => x.IsEn == true && x.IsDel != true && x.ItCode == ItCode)
+ // .Select(x => new TenderVM
+ // {
- var ten = await _db.Queryable<TenantInfo>().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
- Description = x.Description,
- ItCode = ItCode,
- Name = x.Name,
- TenderId = x.Id,
- IsTender = true
-
- }
- ).ToListAsync() ;
- ten.AddRange(tentlist);
- return ten;
+ // }
+ // ).WithCache(10).ToListAsync() ;
+ //ten.AddRange(tentlist);
+ return tentlist;
}
@@ -166,7 +185,258 @@
}
-
+ /// <summary>
+ /// 鑾峰彇鐢ㄦ埛璇︽儏锛屽寘鎷憳宸ヤ俊鎭紝绉熸埛淇℃伅锛屽崟浣嶄俊鎭�
+ /// </summary>
+ /// <param name="TenantID"> 绉熸埛ID</param>
+ /// <param name="EmployeeID">鍛樺伐ID </param>
+ /// <param name="UnitID">鍗曚綅ID</param>
+ /// <returns></returns>
+ public async Task<RetUserInfo> GetUserInfo(int? TenantID,int? EmployeeID,int? UnitID)
+ {
+ TenderInfoVM Tenant = null;
+ EmployeeInfoVM Employee = null;
+ if (TenantID != null)
+ Tenant = await _db.Queryable<TenantInfo>().Where(x => x.Id == TenantID)
+ .Select(x => new TenderInfoVM
+ {
+ Description = x.Description,
+ Id = x.Id,
+ ItCode = x.ItCode,
+ Name = x.Name,
+ ReMark = x.ReMark,
+ }).WithCache(20).FirstAsync();
+ if (EmployeeID != null)
+ Employee = await _db.Queryable<Document_EmployeeInfo>().Where(x => x.EmployeeId == EmployeeID)
+ .Select(x => new EmployeeInfoVM
+ { AdviseFlag = x.AdviseFlag,
+ CardPositive = x.CardPositive,
+ CardPositiveSize = x.CardPositiveSize,
+ CardPositiveVersionNo = x.CardPositiveVersionNo,
+ EmployeeId = x.EmployeeId,
+ EmployeeName = x.EmployeeName,
+ Job = x.Job,
+ LastUpdateName = x.LastUpdateName,
+ UserName = x.UserName,
+ IsLogin = x.IsLogin,
+
+
+ }).WithCache(20).FirstAsync();
+ UnitInfoVM Unit = null;
+ if (UnitID != null)
+ Unit = await _db.Queryable<Model.cyDocumentModel.Document_TenderUnit>().Where(x => x.UnitId == UnitID)
+ .Select(x => new UnitInfoVM
+ {
+ FirmQualificationLevel = x.FirmQualificationLevel,
+ Fax = x.Fax,
+ CorporaterTechnicalPost= x.CorporaterTechnicalPost,
+ LastUpdateName= x.LastUpdateName,
+ Address = x.Address,
+ AdviseFlag = x.AdviseFlag, BankNum = x.BankNum,
+ BusinessContent = x.BusinessContent,
+ BusinessLicense = x.BusinessLicense,
+ CardPositive= x.CardPositive,
+ CardPositiveSize= x.CardPositiveSize,
+ CardPositiveVersionNo= x.CardPositiveVersionNo,
+ ContactPerson= x.ContactPerson,
+ ContactPhone= x.ContactPhone,
+ CorporatePhone= x.CorporatePhone,
+ Corporater= x.Corporater,
+ CorporaterPost= x.CorporaterPost,
+ CreatTime= x.CreatTime,
+ Mechanicer= x.Mechanicer,
+ MiddleStaff= x.MiddleStaff,
+ OpenBank= x.OpenBank,
+ OrgStructure= x.OrgStructure,
+ PrimaryStaff= x.PrimaryStaff,
+ ProjectManager= x.ProjectManager,
+ RegMoney= x.RegMoney,
+ Remark= x.Remark,
+ UnitId= x.UnitId,
+ TechnicalLeader= x.TechnicalLeader,
+ SeniorStaff= x.SeniorStaff,
+ StaffCount= x.StaffCount,
+ TechnicalPhone= x.TechnicalPhone,
+ TechnicalPost= x.TechnicalPost,
+ UnitLogo= x.UnitLogo,
+ UnitLogoSize= x.UnitLogoSize,
+ UnitLogoVersionNo= x.UnitLogoVersionNo,
+ UnitName= x.UnitName,
+ UnitType= x.UnitType,
+ WebUrl= x.WebUrl,
+ ZipCode= x.ZipCode,
+
+
+
+
+ }).WithCache(20).FirstAsync();
+
+
+ return new RetUserInfo
+ {
+ EmployeeInfo = Employee,
+ TenderInfo = Tenant,
+ UnitInfo = Unit
+ };
+ }
+
+ /// <summary>
+ /// 鑾峰彇鍛樺伐鍒楄〃
+ /// </summary>
+ /// <param name="_businessService"></param>
+ /// <param name="page"></param>
+ /// <returns></returns>
+ public async Task<PageResult<EmployeeInfoVM>> postEmployeeList( EmployeePageSearch page)
+ {
+ var a = GetJwtInfo();
+ if(a.EID!=null)
+ throw Oops.Oh($"娌℃湁鏉冮檺");
+ SqlSugar.PageModel pg = new SqlSugar.PageModel();
+ pg.PageSize = page.PageSize;
+ pg.PageIndex = page.PageIndex;
+ RefAsync<int> total = 0;
+ PageResult<EmployeeInfoVM> result = new PageResult<EmployeeInfoVM>();
+ result.Items = await _db.Queryable<EmployeeAtTenant, Document_EmployeeInfo>((et, ei) =>
+ new JoinQueryInfos(JoinType.Left, et.EmployeeID==ei.EmployeeId
+ )).Where((ei,et)=>ei.TenantID==a.TEID)
+ .Select((ei,et)=>new EmployeeInfoVM
+ {
+ EmployeeId = et.EmployeeId,
+ AdviseFlag=et.AdviseFlag,
+ CardPositive=et.CardPositive,
+ CardPositiveSize=et.CardPositiveSize,
+ CardPositiveVersionNo=et.CardPositiveVersionNo,
+ EmployeeName=et.EmployeeName,
+ IsWork=et.IsWork,
+ Job=et.Job,
+ LeaveTime=et.LeaveTime,
+ Phone=et.Phone,
+ UserId=et.UserId,
+ UserName=et.UserName,
+
+
+
+
+
+ }).MergeTable().OrderBy(x=>x.EmployeeId).ToPageListAsync(page.PageIndex,page.PageSize, total);
+
+ result.TotalCount = pg.TotalCount;
+ return result;
+ }
+
+
+
+
+ public async Task<bool > UpEmployee(EmployeeInfoVM vm)
+ {
+
+ var jwtinfo = GetJwtInfo();
+
+ if (jwtinfo.EID != null)
+ throw Oops.Oh($"娌℃湁鏉冮檺");
+ var info = await GetUserInfo(jwtinfo.TEID, null, null);
+ Document_EmployeeInfo a = _mapper.Map<Document_EmployeeInfo>(vm);
+
+ a.LastUpdateName = info.EmployeeInfo.UserName;
+ a.LastUpdateTime = DateTime.Now;
+
+ return await _employeeRepository.UpdateAsync(a);
+
+ }
+
+ public async Task<bool> InEmployee(EmployeeInfoVM vm)
+ {
+ var jwtinfo = GetJwtInfo();
+ if (jwtinfo.EID != null)
+ throw Oops.Oh($"娌℃湁鏉冮檺");
+ Document_EmployeeInfo a = _mapper.Map<Document_EmployeeInfo>(vm);
+
+ var info = await GetUserInfo(jwtinfo.TEID, null, null);
+ EmployeeAtTenant elt = new EmployeeAtTenant
+ {
+ CreatBy = info.TenderInfo.ItCode,
+ CreatTime = DateTime.Now,
+ TenantID = info.TenderInfo.Id,
+
+
+
+ };
+ try
+ {
+ await _employeeRepository.AsTenant().BeginTranAsync();
+ var jwtId= await _employeeRepository.InsertReturnIdentityAsync(a);
+ elt.EmployeeID = jwtId;
+ await _db.Insertable(elt).ExecuteCommandAsync();
+
+ await _employeeRepository.AsTenant().CommitTranAsync();
+
+ }
+ catch (Exception e)
+ {
+
+ await _employeeRepository.AsTenant().RollbackTranAsync();
+ //鍐欐棩蹇�
+ $" 鎻掑叆鏂板憳宸ュけ璐ワ紝 閿欒娑堟伅锛歿e.Message} \r\n 鍫嗘爤閿欒锛歿e.StackTrace}" .LogInformation();
+ throw Oops.Oh("鏂板澶辫触");
+ }
+
+ return await _employeeRepository.InsertAsync(a);
+
+
+
+
+
+ }
+
+ /// <summary>
+ /// 绉熸埛鏄惁宸茬粡瓒呮椂杩囨湡
+ /// </summary>
+ /// <param name="TenderID">绉熸埛ID</param>
+ /// <returns> true 浠h〃娌℃湁瓒呮椂鏈夋潈闄愪娇鐢紝false 浠h〃娌℃湁鏉冮檺浣跨敤浜�</returns>
+ public async Task<bool> TenderHasPermissions( int TenderID)
+ {
+ var Key = TenantPermissions_RedisKey + TenderID.ToString();
+ var tp= _cacheService.Get<TenantPermissions>(TenantPermissions_RedisKey+ TenderID.ToString());
+ if(tp == null )
+ {
+ tp= await _db.Queryable<TenantPermissions>().Where(x=>x.TenantId == TenderID).FirstAsync();
+ if (tp != null)
+ _cacheService.Add<TenantPermissions>(Key, tp, 300);
+ else
+ return false;
+ }
+ if (tp.OverTime > DateTime.Now)
+ return true;
+ return false;
+
+ }
+ /// <summary>
+ /// 绉熸埛鏄惁宸茬粡瓒呮椂杩囨湡 鏍规嵁token涓寘鍚殑TID 璇嗗埆鏄惁鏈夋潈闄�
+ /// </summary>
+ /// <returns> true 浠h〃娌℃湁瓒呮椂鏈夋潈闄愪娇鐢紝false 浠h〃娌℃湁鏉冮檺浣跨敤浜�</returns>
+ public async Task<bool> TenderHasPermissions()
+ {
+ var jwtinfo= GetJwtInfo();
+ if(jwtinfo != null&&jwtinfo.TEID!=null )
+ {
+ var Key = TenantPermissions_RedisKey + jwtinfo.TEID.ToString();
+ var tp = _cacheService.Get<TenantPermissions>(TenantPermissions_RedisKey + jwtinfo.TEID.ToString());
+ if (tp == null)
+ {
+ tp = await _db.Queryable<TenantPermissions>().Where(x => x.TenantId == jwtinfo.TEID).FirstAsync();
+ if (tp == null)
+ _cacheService.Add<TenantPermissions>(Key, tp, 300);
+ else
+ return false;
+ }
+
+ if (tp.OverTime > DateTime.Now)
+ return true;
+ return false;
+ }
+ return false;
+ }
+
}
--
Gitblit v1.9.1