Files
jinko.yikatong/Src/Dlhis.External/OpenApi/Services/Implements/GainfoService.cs

87 lines
3.2 KiB
C#

using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums;
using Dlhis.External.OpenApi.Request;
using Dlhis.External.OpenApi.Response;
using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
namespace Dlhis.External.OpenApi.Services.Implements;
public class GainfoService : IGainfoService
{
private readonly IDbContext _dbContext;
public GainfoService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<List<GainfoOpenResponse>> GetAllGainfosAsync()
{
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()
{
return await _dbContext.Queryable<DepartmentEntity>()
.Select(x => new DepartmentOpenResponse
{
Name = x.Name,
No = x.No,
PNo = x.PNo
}).ToListAsync();
}
public async Task<Pagination<DeviceUploadLogResponse>> GetAttendanceRecordPageAsync(DeviceUploadLogMyRecordRequest request)
{
return await _dbContext.Queryable<DeviceUploadLogEntity>()
.LeftJoin<DeviceEntity>((log, d) => log.DeviceUniqueNo == d.UniqueNo)
.Where(log => log.UserUniqueNo == request.UserCode)
.WhereIF(request.DateTimePeriod.HasValue(), log => log.RaiseDateTime >= request.DateTimePeriod.Start && log.RaiseDateTime <= request.DateTimePeriod.End)
.Where((log, d) => d.Type == DeviceTypeEnumType.Attendance || (d.Type == DeviceTypeEnumType.Door && d.AsAttendance))
.OrderBy(log => log.RaiseDateTime)
.Select((log, d) => new DeviceUploadLogResponse
{
DeviceUniqueNo = log.DeviceUniqueNo,
Id = log.Id,
RaiseDateTime = log.RaiseDateTime,
SerialNo = log.SerialNo,
DeployPlace = d.DeployPlace,
Sync = log.Sync,
Status = log.Status
})
.ToPageListAsync(request);
}
}