complete rollcallCase history details by employee

This commit is contained in:
2026-01-11 17:25:56 +03:30
parent 05d860795e
commit 8f6007835c
5 changed files with 136 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ namespace _0_Framework.Application;
public class PagedResult<T> where T : class
{
public int TotalCount { get; set; }
public List<T> List { get; set; }
public List<T> List { get; set; } = [];
}
public class PagedResult<T,TMeta>:PagedResult<T> where T : class
{

View File

@@ -139,7 +139,7 @@ namespace CompanyManagment.App.Contracts.RollCall
public TimeSpan TotalWorkingTime { get; set; }
public List<RollCallCaseHistoryDetailRecord> Records { get; set; }
public RollCallRecordStatus Status { get; set; }
public long EmployeeId { get; set; }
}
public enum RollCallRecordStatus

View File

@@ -17,7 +17,9 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using _0_Framework.Exceptions;
namespace CompanyManagment.EFCore.Repository;
@@ -777,6 +779,46 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
}
}
private TimeSpan CalculateExitTimeDifferencesTimeSpan(TimeSpan early, TimeSpan late)
{
if (early == TimeSpan.Zero && late == TimeSpan.Zero)
{
return TimeSpan.Zero;
}
if (late != TimeSpan.Zero)
{
return late * 1;
}
if (early != TimeSpan.Zero)
{
return early * -1;
}
return TimeSpan.Zero;
}
private TimeSpan CalculateEntryTimeDifferencesTimeSpan(TimeSpan early, TimeSpan late)
{
if (early == TimeSpan.Zero && late == TimeSpan.Zero)
{
return TimeSpan.Zero;
}
if (late != TimeSpan.Zero)
{
return late * -1;
}
if (early != TimeSpan.Zero)
{
return early*1;
}
return TimeSpan.Zero;
}
//Without Paginate, With EndDate==null, without undefined, Ordered Descending By StartDate
public List<RollCallViewModel> GetEmployeeRollCallsHistoryAllInDates(long workshopId, long employeeId,
DateTime start, DateTime end)
@@ -2202,7 +2244,7 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
dates = dates
.Where(x => x.Date == date.Date).ToList();
}
else if (!string.IsNullOrWhiteSpace(searchModel.StartDate)
else if (!string.IsNullOrWhiteSpace(searchModel.StartDate)
&& !string.IsNullOrWhiteSpace(searchModel.EndDate))
{
var start = searchModel.StartDate.ToGeorgianDateTime();
@@ -2243,8 +2285,95 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
return res;
}
public Task<PagedResult<RollCallCaseHistoryDetail>> GetCaseHistoryDetails(long workshopId, string titleId, RollCallCaseHistorySearchModel searchModel)
public async Task<PagedResult<RollCallCaseHistoryDetail>> GetCaseHistoryDetails(long workshopId, string titleId,
RollCallCaseHistorySearchModel searchModel)
{
throw new NotImplementedException();
var query = _context.RollCallEmployeesStatus
.Include(x => x.RollCallEmployee)
.Where(x => x.RollCallEmployee.WorkshopId == workshopId);
//این برای این هست که اگر بر اساس پرسنل جستجو شده بود و در titleId اگر به فرمت YYYY_MM اومد به این معنی هست که باید بر طبق ماه فیلتر بشه نه به صورت روزانه
if (searchModel.EmployeeId is > 0)
{
//TODO: set correct regex.
// if (!Regex.IsMatch(titleId, ""))
// throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است");
var splitDate = titleId.Split("_");
var year = Convert.ToInt32(splitDate.First());
var month = Convert.ToInt32(splitDate.Last());
var startDateFa = $"{year:D4}/{month:D2}/01";
var endDateFa = startDateFa.FindeEndOfMonth();
var startDate = startDateFa.ToGeorgianDateTime();
var endDate = endDateFa.ToGeorgianDateTime();
query = query.Where(x => x.StartDate <= endDate && x.EndDate >= startDate
&& x.RollCallEmployee.EmployeeId == searchModel.EmployeeId);
var employeeIds =await query.Select(x => x.RollCallEmployee.EmployeeId).ToListAsync();
var rollCalls =await _context.RollCalls
.Where(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId)
&& startDate <= x.ShiftDate && endDate >= x.ShiftDate).ToListAsync();
var leaves =await _context.LeaveList.Where(x => x.WorkshopId == workshopId
&& employeeIds.Contains(x.EmployeeId) &&
x.StartLeave >= endDate && x.EndLeave <= startDate).ToListAsync();
var dateRange = (int)(endDate - startDate).TotalDays + 1;
var dates = Enumerable.Range(0, dateRange).Select(x => startDate.AddDays(x)).ToList();
var employees = await _context.Employees.Where(x => employeeIds
.Contains(x.id)).ToListAsync();
var personnelCodes =await _context.PersonnelCodeSet
.Where(x => x.WorkshopId == workshopId
&& employeeIds.Contains(x.EmployeeId)).ToListAsync();
var res = new PagedResult<RollCallCaseHistoryDetail>();
foreach (var date in dates)
{
var rollCallInDate = rollCalls
.Where(x => x.ShiftDate.Date == date.Date).ToList();
foreach (var employeeId in employeeIds)
{
var leave = leaves.FirstOrDefault(y => y.EmployeeId == employeeId);
var employeeRollCallsForDate = rollCallInDate
.Where(y => y.EmployeeId == employeeId).ToList();
var employee = employees.FirstOrDefault(x => x.id == employeeId);
var item = new RollCallCaseHistoryDetail()
{
EmployeeFullName = employee?.FullName ?? "",
EmployeeId = employee?.id ?? 0,
Records = employeeRollCallsForDate.OrderBy(r => r.StartDate).Select(y =>
new RollCallCaseHistoryDetailRecord()
{
EndTime = y.EndDate!.Value.ToString("HH:mm"),
StartTime = y.StartDate!.Value.ToString("HH:mm"),
EntryTimeDifference =
CalculateEntryTimeDifferencesTimeSpan(y.EarlyEntryDuration, y.LateEntryDuration),
ExitTimeDifference =
CalculateExitTimeDifferencesTimeSpan(y.EarlyExitDuration, y.LateExitDuration)
}).ToList(),
Status = employeeRollCallsForDate.Any() ? RollCallRecordStatus.Worked
: leave != null ? RollCallRecordStatus.Leaved
: RollCallRecordStatus.Absent,
TotalWorkingTime =
new TimeSpan(
employeeRollCallsForDate.Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)),
PersonnelCode = personnelCodes.FirstOrDefault(y => y.EmployeeId == employeeId)?.PersonnelCode
.ToString(),
};
res.List.Add(item);
}
}
return res;
}
return new PagedResult<RollCallCaseHistoryDetail>();
}
}

View File

@@ -24,7 +24,7 @@ public class CaseHistoryController:ClientBaseController
}
[HttpGet("{titleId}")]
public async Task<IActionResult> GetDetails(string titleId, RollCallCaseHistorySearchModel searchModel)
public async Task<ActionResult<PagedResult<RollCallCaseHistoryDetail>>> GetDetails(string titleId, RollCallCaseHistorySearchModel searchModel)
{
return await _rollCallApplication.GetCaseHistoryDetails(_workshopId, titleId, searchModel);
}

View File

@@ -19,7 +19,7 @@
"sqlDebugging": true,
"dotnetRunMessages": "true",
"nativeDebugging": true,
"applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.0.117:5006",
"applicationUrl": "https://localhost:5004;http://localhost:5003;",
"jsWebView2Debugging": false,
"hotReloadEnabled": true
},