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> 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() .LeftJoin((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().AS("GainfoLeave") .LeftJoin((x, d) => x.DepartmentNo == d.No) .Where(x => x.Factory == "2401") .Where(x => SqlFunc.Subqueryable() .Where(p => p.Factory == "2401") .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(); } /// public async Task> GetGainfosAsync(string factory) { var gainfos = await _dbContext.Queryable() .LeftJoin((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> GetDepartmentsAsync() { return await _dbContext.Queryable() .Select(x => new DepartmentOpenResponse { Name = x.Name, No = x.No, PNo = x.PNo }).ToListAsync(); } public async Task> GetAttendanceRecordPageAsync(DeviceUploadLogMyRecordRequest request) { return await _dbContext.Queryable() .LeftJoin((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); } }