fix defect

This commit is contained in:
Suphonchai Phoonsawat 2023-12-18 15:50:42 +07:00
parent c798439c19
commit 0a080b09e4
4 changed files with 57 additions and 12 deletions

View file

@ -70,8 +70,8 @@ namespace BMA.EHR.Application.Repositories.Leaves
{
if (entity is EntityBase)
{
(entity as EntityBase).LastUpdateUserId = UserId!;
(entity as EntityBase).LastUpdateFullName = FullName!;
(entity as EntityBase).LastUpdateUserId = UserId ?? "";
(entity as EntityBase).LastUpdateFullName = FullName ?? "System Administrator";
(entity as EntityBase).LastUpdatedAt = DateTime.Now;
}

View file

@ -67,7 +67,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
foreach (var d in data)
{
var result = _userProfileRepository.UpdateDutyTimeAsync(d.ProfileId, d.DutyTimeId, d.EffectiveDate.Value.Date).Result;
d.IsProcess = true;
d.LastUpdateFullName = "Automation System";
d.LastUpdateUserId = UserId ?? "";
d.LastUpdatedAt = DateTime.Now;
var result = UpdateAsync(d).Result;
//var result = _userProfileRepository.UpdateDutyTimeAsync(d.ProfileId, d.DutyTimeId, d.EffectiveDate.Value.Date).Result;
}
}
catch
@ -86,7 +91,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
return data;
}
public async Task<UserDutyTime?> GetExist(Guid profileId,DateTime effectiveDate)
public async Task<UserDutyTime?> GetExist(Guid profileId, DateTime effectiveDate)
{
var data = await _dbContext.Set<UserDutyTime>()
.Where(x => x.ProfileId == profileId)
@ -96,6 +101,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
return data;
}
public async Task<UserDutyTime?> GetLastEffectRound(Guid profileId)
{
var data = await _dbContext.Set<UserDutyTime>()
.Where(x => x.ProfileId == profileId)
.Where(x => x.IsProcess)
.OrderByDescending(x => x.EffectiveDate)
.FirstOrDefaultAsync();
return data;
}
#endregion
}

View file

@ -51,13 +51,20 @@ namespace BMA.EHR.Application.Repositories
{
try
{
var profile = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.Id == profileId);
var profile = await _dbContext.Set<Profile>()
.AsQueryable()
.Include(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == profileId);
if (profile == null)
{
throw new Exception(GlobalMessages.DataNotFound);
}
else
{
var fullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}";
Console.WriteLine(fullName);
profile.DutyTimeId = roundId;
profile.DutyTimeEffectiveDate = effectiveDate;

View file

@ -525,7 +525,9 @@ namespace BMA.EHR.Leave.Service.Controllers
return Error("ไม่พบรอบการลงเวลาทำงาน Default", StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
// TODO : รอดุึงรอบที่ผูกกับ user
var duty = userRound ?? defaultRound;
@ -684,7 +686,10 @@ namespace BMA.EHR.Leave.Service.Controllers
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var duty = userRound ?? defaultRound;
@ -759,7 +764,10 @@ namespace BMA.EHR.Leave.Service.Controllers
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var duty = userRound ?? defaultRound;
@ -850,6 +858,8 @@ namespace BMA.EHR.Leave.Service.Controllers
var roundId = p.DutyTimeId ?? Guid.Empty;
var round = await _dutyTimeRepository.GetByIdAsync(roundId);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
var res = new SearchProfileResultDto
{
ProfileId = p.Id,
@ -857,7 +867,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 = effectiveDate == null ? null : effectiveDate.EffectiveDate.Value.Date
};
resultSet.Add(res);
}
@ -1014,7 +1024,12 @@ namespace BMA.EHR.Leave.Service.Controllers
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var checkInData = await _userTimeStampRepository.GetTimestampByDateAsync(data.KeycloakUserId, data.CheckDate);
var duty = userRound ?? getDefaultRound;
@ -1240,7 +1255,10 @@ namespace BMA.EHR.Leave.Service.Controllers
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var duty = userRound ?? defaultRound;
@ -1314,7 +1332,11 @@ namespace BMA.EHR.Leave.Service.Controllers
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var checkInData = await _userTimeStampRepository.GetTimestampByDateAsync(data.KeycloakUserId, data.CheckDate);
var duty = userRound ?? getDefaultRound;