Laservall_manager_system/VOL.HR/Services/DeptShip/Partial/HR_DeptShipService.cs

68 lines
2.5 KiB
C#
Raw Normal View History

2025-09-26 13:35:45 +08:00
/*
*HR_DeptShip类的业务代码应在此处编写
*使repository.EF/Dapper等信息
*使repository.DbContextBeginTransaction
*使DBServerProvider.
*使UserContext.Current操作
*HR_DeptShipService对增ServiceFunFilter
*/
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using VOL.DingTalk.Models.Biz;
using VOL.DingTalk.Services.Biz;
using VOL.HR.IRepositories;
using VOL.YSErp.Models.Biz;
using VOL.YSErp.Services.Biz;
namespace VOL.HR.Services
{
public partial class HR_DeptShipService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IHR_DeptShipRepository _repository;//访问数据库
private readonly DingTalkService _dingTalkService;
private readonly YSERPService _ysService;
[ActivatorUtilitiesConstructor]
private readonly Core.CacheManager.ICacheService _cacheService;
[ActivatorUtilitiesConstructor]
public HR_DeptShipService(
IHR_DeptShipRepository dbRepository,
IHttpContextAccessor httpContextAccessor,
Core.CacheManager.ICacheService cacheService
)
: base(dbRepository)
{
_httpContextAccessor = httpContextAccessor;
_repository = dbRepository;
//多租户会用到这init代码其他情况可以不用
//base.Init(dbRepository);
_cacheService = cacheService;
_dingTalkService = new DingTalkService(new DingTalk.Models.SystemToken(), new DingTalk.Models.DingTalkConfig());
_ysService = new YSERPService(new YSErp.Models.SystemToken(), new YSErp.Models.YSConfig());
}
public Task<List<YSERPDepartment>> GetYSERPDepartments()
{
if (_cacheService.Exists("YS_DEPT_CACHE"))
{
return Task.FromResult(_cacheService.Get<List<YSERPDepartment>>("YS_DEPT_CACHE"));
}
else
{
var depts = _ysService.GetAllDepartmentsAsync();
if (depts != null)
{
_cacheService.Add("YS_DEPT_CACHE", JsonConvert.SerializeObject(depts.Result), 600);
}
return depts;
}
}
}
}