fix 改用db查询

This commit is contained in:
2024-06-22 13:17:50 +08:00
parent cf7e757b7d
commit cf04fb01ad

View File

@@ -1,28 +1,60 @@
using Dlhis.External.OpenApi.Response;
using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.External.OpenApi.Response;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
namespace Dlhis.External.OpenApi.Services.Implements;
public class GainfoService : IGainfoService
{
private readonly RedisCache _redisCache;
private readonly IDbContext _dbContext;
public GainfoService(RedisCache redisCache)
public GainfoService(IDbContext dbContext)
{
_redisCache = redisCache;
_dbContext = dbContext;
}
public async Task<List<GainfoOpenResponse>> GetAllGainfosAsync()
{
var data = await _redisCache.ListRangeAsync("gainfo:shanxi");
return data.Select(x => x.ToString().ToObject<GainfoOpenResponse>()).ToList();
var gainfos = await _dbContext.Queryable<GainfoEntity>()
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
.Where(x => x.Factory == "2401")
.Select((x, d) => new GainfoOpenResponse
{
Code = x.Code,
DepartmentNo = x.DepartmentNo,
DepartmentName = d.Name,
Name = x.Name,
Gender = x.Gender,
Status = GainfoStatusEnumType.Working,
})
.ToListAsync();
var gainfoLeaves = await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
.Where(x => x.Factory == "2401")
.Select((x, d) => new GainfoOpenResponse
{
Code = x.Code,
DepartmentNo = x.DepartmentNo,
DepartmentName = d.Name,
Name = x.Name,
Gender = x.Gender,
Status = GainfoStatusEnumType.Leave,
})
.ToListAsync();
return gainfos.Concat(gainfoLeaves).ToList();
}
public async Task<List<DepartmentOpenResponse>> GetDepartmentsAsync()
{
var departmentKey = "department:all";
var data = await _redisCache.ListRangeAsync(departmentKey);
return data.Select(x => x.ToString().ToObject<DepartmentOpenResponse>()).ToList();
return await _dbContext.Queryable<DepartmentEntity>()
.Select(x => new DepartmentOpenResponse
{
Name = x.Name,
No = x.No,
PNo = x.PNo
}).ToListAsync();
}
}
}