LV1_015 - ประวัติการเปลี่ยนรอบการลงเวลา (ADMIN)

This commit is contained in:
Suphonchai Phoonsawat 2023-11-23 17:04:45 +07:00
parent 2bf43a52b5
commit 1e556db01a
5 changed files with 112 additions and 11 deletions

View file

@ -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<List<UserDutyTime>> GetListByProfileIdAsync(Guid profileId)
{
var data = await _dbContext.Set<UserDutyTime>().AsQueryable()
.Include(x => x.DutyTime)
.Where(x => x.ProfileId == profileId)
.ToListAsync();
return data;
}
public async Task<UserDutyTime?> GetExist(Guid profileId,DateTime effectiveDate)
{
var data = await _dbContext.Set<UserDutyTime>()
.Where(x => x.ProfileId == profileId)
.Where(x => x.EffectiveDate == effectiveDate)
.FirstOrDefaultAsync();
return data;
}
#endregion
}
}

View file

@ -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; }

View file

@ -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
}

View file

@ -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<ActionResult<ResponseObject>> GetTimeRecordAsync([Required] DateTime startDate, [Required] DateTime endDate, int page = 1, int pageSize = 10,string status = "NORMAL", string keyword = "")
public async Task<ActionResult<ResponseObject>> 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 });
}
// <summary>
/// <summary>
/// LV1_014 - เปลี่ยนรอบการลงเวลา (ADMIN)
/// </summary>
/// <returns>
@ -756,9 +758,20 @@ namespace BMA.EHR.Leave.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[AllowAnonymous]
public async Task<ActionResult<ResponseObject>> 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();
}
/// <summary>
///LV1_015 - ประวัติการเปลี่ยนรอบการลงเวลา (ADMIN)
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("round/{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[AllowAnonymous]
public async Task<ActionResult<ResponseObject>> GetChangeRoundHistoryByProfileIdAsync(Guid id, int page = 1, int pageSize = 10, string keyword = "")
{
var data = await _userDutyTimeRepository.GetListByProfileIdAsync(id);
var resultSet = new List<ChangeRoundHistoryDto>();
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

View file

@ -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; }
}
}