155 lines
5.9 KiB
C#
155 lines
5.9 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[]
|
|
{
|
|
"1201", "1701", "1801",
|
|
"1901", "1902", "201",
|
|
"2001", "2301", "2401",
|
|
"301", "302", "303",
|
|
"304", "305", "306",
|
|
"307", "401", "501",
|
|
"502", "503", "504",
|
|
"505", "701", "601",
|
|
"1601"
|
|
};
|
|
|
|
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,
|
|
Type = SqlFunc.IIF(x.Type == GainfoUserTypeEnumType.SecurityWhite, GainfoUserTypeEnumType.Normal, x.Type),
|
|
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 => x.Factory == "2401")
|
|
.Where(x => SqlFunc.Subqueryable<GainfoEntity>()
|
|
.Where(p => p.Code == x.Code)
|
|
.NotAny()
|
|
)
|
|
.Select((x, d) => new GainfoOpenResponse
|
|
{
|
|
Code = x.Code,
|
|
Type = SqlFunc.IIF(x.Type == GainfoUserTypeEnumType.SecurityWhite, GainfoUserTypeEnumType.Normal, x.Type),
|
|
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,
|
|
Type = SqlFunc.IIF(x.Type == GainfoUserTypeEnumType.SecurityWhite, GainfoUserTypeEnumType.Normal, x.Type),
|
|
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);
|
|
}
|
|
|
|
public async Task<Pagination<GainfoOpenResponse>> GetGainfoLeavePageAsync(GainfoArchivePageRequest request)
|
|
{
|
|
return await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
|
|
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
|
.Where(x => x.Factory == request.Factory)
|
|
.WhereIF(request.ModifiedTime.HasValue, x => x.ModifiedTime >= request.ModifiedTime)
|
|
.Where(x => SqlFunc.Subqueryable<GainfoEntity>()
|
|
.Where(p => p.Code == x.Code)
|
|
.NotAny()
|
|
)
|
|
.Select((x, d) => new GainfoOpenResponse
|
|
{
|
|
Code = x.Code,
|
|
Type = SqlFunc.IIF(x.Type == GainfoUserTypeEnumType.SecurityWhite, GainfoUserTypeEnumType.Normal, x.Type),
|
|
DepartmentNo = x.DepartmentNo,
|
|
DepartmentName = d.Name,
|
|
Name = x.Name,
|
|
Gender = x.Gender,
|
|
Factory = x.Factory,
|
|
Status = GainfoStatusEnumType.Leave,
|
|
})
|
|
.ToPageListAsync(request);
|
|
}
|
|
} |