118 lines
4.3 KiB
C#
118 lines
4.3 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;
|
|
using SqlSugar;
|
|
|
|
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 factories = new[] { "2401", "301", "302", "303", "304", "305", "306", "307" };
|
|
|
|
var gainfos = await _dbContext.Queryable<GainfoEntity>()
|
|
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
|
.Where(x => factories.Contains(x.Factory))
|
|
.Select((x, d) => new GainfoOpenResponse
|
|
{
|
|
Code = x.Code,
|
|
DepartmentNo = x.DepartmentNo,
|
|
DepartmentName = d.Name,
|
|
Name = x.Name,
|
|
Gender = x.Gender,
|
|
Factory = x.Factory,
|
|
Status = GainfoStatusEnumType.Working,
|
|
})
|
|
.ToListAsync();
|
|
|
|
var gainfoLeaves = await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
|
|
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
|
.Where(x => factories.Contains(x.Factory))
|
|
.Where(x => SqlFunc.Subqueryable<GainfoEntity>()
|
|
.Where(p => factories.Contains(p.Factory))
|
|
.Where(p => p.Code == x.Code)
|
|
.NotAny()
|
|
)
|
|
.Select((x, d) => new GainfoOpenResponse
|
|
{
|
|
Code = x.Code,
|
|
DepartmentNo = x.DepartmentNo,
|
|
DepartmentName = d.Name,
|
|
Name = x.Name,
|
|
Gender = x.Gender,
|
|
Factory = x.Factory,
|
|
Status = GainfoStatusEnumType.Leave,
|
|
})
|
|
.ToListAsync();
|
|
|
|
return gainfos.Concat(gainfoLeaves).ToList();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<GainfoOpenResponse>> GetGainfosAsync(string factory)
|
|
{
|
|
var gainfos = await _dbContext.Queryable<GainfoEntity>()
|
|
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
|
.Where(x => x.Factory == factory)
|
|
.Select((x, d) => new GainfoOpenResponse
|
|
{
|
|
Code = x.Code,
|
|
DepartmentNo = x.DepartmentNo,
|
|
DepartmentName = d.Name,
|
|
Name = x.Name,
|
|
Gender = x.Gender,
|
|
Factory = x.Factory,
|
|
Status = GainfoStatusEnumType.Working,
|
|
})
|
|
.ToListAsync();
|
|
|
|
return gainfos;
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |