diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs index 851a65fc..c6194545 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs @@ -2,6 +2,7 @@ using BMA.EHR.Application.Messaging; using BMA.EHR.Domain.Models.Leave.TimeAttendants; using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants @@ -51,6 +52,31 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants } } + #endregion + + #region " Methods " + + public async Task> GetListByProfileIdAsync(Guid profileId) + { + var data = await _dbContext.Set().AsQueryable() + .Include(x => x.DutyTime) + .Where(x => x.ProfileId == profileId) + .ToListAsync(); + + return data; + } + + public async Task GetExist(Guid profileId,DateTime effectiveDate) + { + var data = await _dbContext.Set() + .Where(x => x.ProfileId == profileId) + .Where(x => x.EffectiveDate == effectiveDate) + .FirstOrDefaultAsync(); + + return data; + } + + #endregion } } diff --git a/BMA.EHR.Domain/Models/Leave/TimeAttendants/UserDutyTime.cs b/BMA.EHR.Domain/Models/Leave/TimeAttendants/UserDutyTime.cs index a5d9e373..7dfc1ecd 100644 --- a/BMA.EHR.Domain/Models/Leave/TimeAttendants/UserDutyTime.cs +++ b/BMA.EHR.Domain/Models/Leave/TimeAttendants/UserDutyTime.cs @@ -12,6 +12,8 @@ namespace BMA.EHR.Domain.Models.Leave.TimeAttendants [Required, Comment("รหัสรอบการลงเวลา")] public Guid DutyTimeId { get; set; } = Guid.Empty; + public DutyTime DutyTime { get; set; } + [Comment("วันที่มีผล")] public DateTime? EffectiveDate { get; set; } diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs index 80ada993..c43e5323 100644 --- a/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs +++ b/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs @@ -101,7 +101,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("DutyTimes"); + b.ToTable("DutyTimes", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.ProcessUserTimeStamp", b => @@ -238,7 +238,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("ProcessUserTimeStamps"); + b.ToTable("ProcessUserTimeStamps", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => @@ -310,7 +310,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("UserDutyTimes"); + b.ToTable("UserDutyTimes", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b => @@ -438,7 +438,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("UserTimeStamps"); + b.ToTable("UserTimeStamps", (string)null); }); #pragma warning restore 612, 618 } diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs index 93f89083..c310b214 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs @@ -1,4 +1,5 @@ -using BMA.EHR.Application.Repositories; +using Amazon.S3.Model.Internal.MarshallTransformations; +using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Leaves.TimeAttendants; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Models.Leave.TimeAttendants; @@ -13,6 +14,7 @@ using Swashbuckle.AspNetCore.Annotations; using System.ComponentModel.DataAnnotations; using System.Security.Claims; using System.Security.Permissions; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace BMA.EHR.Leave.Service.Controllers { @@ -390,7 +392,7 @@ namespace BMA.EHR.Leave.Service.Controllers { // validate duplicate check in var currentCheckIn = await _userTimeStampRepository.GetTimestampByDateAsync(Guid.Parse(UserId), currentDate); - + if (currentCheckIn != null) @@ -638,7 +640,7 @@ namespace BMA.EHR.Leave.Service.Controllers [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] [AllowAnonymous] - public async Task> GetTimeRecordAsync([Required] DateTime startDate, [Required] DateTime endDate, int page = 1, int pageSize = 10,string status = "NORMAL", string keyword = "") + public async Task> GetTimeRecordAsync([Required] DateTime startDate, [Required] DateTime endDate, int page = 1, int pageSize = 10, string status = "NORMAL", string keyword = "") { if (startDate.Date > endDate.Date) { @@ -691,7 +693,7 @@ namespace BMA.EHR.Leave.Service.Controllers }) .Where(x => x.CheckInStatus == status || x.CheckOutStatus == status) .ToList(); - + return Success(new { data = data, total = count }); } @@ -736,7 +738,7 @@ namespace BMA.EHR.Leave.Service.Controllers FullName = $"{p.Prefix.Name}{p.FirstName} {p.LastName}", StartTimeMorning = round != null ? round.StartTimeMorning : defaultRound.StartTimeMorning, LeaveTimeAfterNoon = round != null ? round.EndTimeAfternoon : defaultRound.EndTimeAfternoon, - EffectiveDate = p.DutyTimeEffectiveDate + EffectiveDate = p.DutyTimeEffectiveDate }; resultSet.Add(res); } @@ -744,7 +746,7 @@ namespace BMA.EHR.Leave.Service.Controllers return Success(new { data = resultSet, total = profile.Count }); } - // + /// /// LV1_014 - เปลี่ยนรอบการลงเวลา (ADMIN) /// /// @@ -756,9 +758,20 @@ namespace BMA.EHR.Leave.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - [AllowAnonymous] public async Task> CreateChangeRoundAsync([FromBody] CreateChangeRoundDto req) { + if (req.EffectiveDate.Date < DateTime.Now.Date) + { + return Error(new Exception("วันมีผลต้องมากกว่าหรือเท่ากับวันที่ปัจจุบัน"), (int)StatusCodes.Status400BadRequest); + } + + var old = await _userDutyTimeRepository.GetExist(req.ProfileId, req.EffectiveDate); + + if (old != null) + { + return Error(new Exception("ไม่สามารถทำรายการได้ เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), (int)StatusCodes.Status400BadRequest); + } + var data = new UserDutyTime { ProfileId = req.ProfileId, @@ -772,6 +785,50 @@ namespace BMA.EHR.Leave.Service.Controllers return Success(); } + + /// + ///LV1_015 - ประวัติการเปลี่ยนรอบการลงเวลา (ADMIN) + /// + /// + /// + /// เมื่อทำรายการสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("round/{id:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [AllowAnonymous] + public async Task> GetChangeRoundHistoryByProfileIdAsync(Guid id, int page = 1, int pageSize = 10, string keyword = "") + { + var data = await _userDutyTimeRepository.GetListByProfileIdAsync(id); + + var resultSet = new List(); + + if (data != null) + { + resultSet = data + .GroupBy(item => item.ProfileId) + .SelectMany(group => group + .OrderBy(item => item.EffectiveDate) // เรียงลำดับตาม property ที่คุณต้องการ + .Select((item, index) => new ChangeRoundHistoryDto + { + Round = index + 1, + StartTimeMorning = item.DutyTime.StartTimeMorning, + LeaveTimeAfternoon = item.DutyTime.EndTimeAfternoon, + EffectiveDate = item.EffectiveDate.Value, + Remark = item.Remark + })) + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToList(); + + } + + return Success(new { data = resultSet, total = data.Count }); + } + + #endregion #endregion diff --git a/BMA.EHR.Leave.Service/DTOs/ChangeRound/ChangeRoundHistoryDto.cs b/BMA.EHR.Leave.Service/DTOs/ChangeRound/ChangeRoundHistoryDto.cs new file mode 100644 index 00000000..7dd1e122 --- /dev/null +++ b/BMA.EHR.Leave.Service/DTOs/ChangeRound/ChangeRoundHistoryDto.cs @@ -0,0 +1,16 @@ +namespace BMA.EHR.Leave.Service.DTOs.ChangeRound +{ + public class ChangeRoundHistoryDto + { + + public int Round { get; set; } + + public string StartTimeMorning { get; set; } + + public string LeaveTimeAfternoon { get; set; } + + public DateTime EffectiveDate { get; set; } + + public string Remark { get; set; } + } +}