2023-12-09 09:54:34 +03:30
|
|
|
|
using Brizco.Domain.Entities.Task;
|
2023-12-11 14:32:29 +03:30
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Brizco.Domain.Entities.Routine;
|
|
|
|
|
|
using Brizco.Domain.Entities.Shift;
|
|
|
|
|
|
using Task = Brizco.Domain.Entities.Task.Task;
|
2023-12-09 09:54:34 +03:30
|
|
|
|
|
|
|
|
|
|
namespace Brizco.Core.CoreServices;
|
|
|
|
|
|
|
|
|
|
|
|
public class PageService : IPageService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ICurrentUserService _currentUserService;
|
|
|
|
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
2023-12-11 14:32:29 +03:30
|
|
|
|
private readonly RoleManager<ApplicationRole> _roleManager;
|
2023-12-09 09:54:34 +03:30
|
|
|
|
|
2023-12-11 14:32:29 +03:30
|
|
|
|
public PageService(
|
|
|
|
|
|
ICurrentUserService currentUserService,
|
|
|
|
|
|
IRepositoryWrapper repositoryWrapper,
|
|
|
|
|
|
RoleManager<ApplicationRole> roleManager)
|
2023-12-09 09:54:34 +03:30
|
|
|
|
{
|
|
|
|
|
|
_currentUserService = currentUserService;
|
|
|
|
|
|
_repositoryWrapper = repositoryWrapper;
|
2023-12-11 14:32:29 +03:30
|
|
|
|
_roleManager = roleManager;
|
2023-12-09 09:54:34 +03:30
|
|
|
|
}
|
|
|
|
|
|
public async Task<AppDashboardPageDto> GetAppDashboardAsync(CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_currentUserService.UserId == null)
|
|
|
|
|
|
throw new AppException("User id is null ");
|
2024-04-25 02:33:17 +03:30
|
|
|
|
if (!Guid.TryParse(_currentUserService.UserId, out Guid userId))
|
2023-12-09 09:54:34 +03:30
|
|
|
|
throw new AppException("User id is wrong");
|
2024-04-25 02:33:17 +03:30
|
|
|
|
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
|
2023-12-11 14:32:29 +03:30
|
|
|
|
throw new AppException("Complex id is wrong");
|
2023-12-09 09:54:34 +03:30
|
|
|
|
|
|
|
|
|
|
var todayTasks = await _repositoryWrapper.SetRepository<Activity>()
|
|
|
|
|
|
.TableNoTracking
|
2024-04-25 16:56:15 +03:30
|
|
|
|
.Where(a => a.ComplexId == complexId && a.SetFor.Date == DateTime.Today.Date)
|
2023-12-09 09:54:34 +03:30
|
|
|
|
.ToListAsync(cancellationToken);
|
2024-04-25 02:33:17 +03:30
|
|
|
|
var todayShiftPlans = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
|
|
|
|
|
.TableNoTracking
|
2024-04-25 16:56:15 +03:30
|
|
|
|
.Where(a => a.PlanFor.Date == DateTime.Today.Date && a.ComplexId == complexId)
|
2024-04-25 02:33:17 +03:30
|
|
|
|
.Select(ShiftPlanMapper.ProjectToSDto)
|
|
|
|
|
|
.ToListAsync(cancellationToken);
|
|
|
|
|
|
var names = new List<string>();
|
|
|
|
|
|
names.AddRange(todayShiftPlans.SelectMany(sp => sp.Users).Select(s => s.UserFullName).ToList());
|
2023-12-11 14:32:29 +03:30
|
|
|
|
var page = new AppDashboardPageDto
|
2023-12-09 09:54:34 +03:30
|
|
|
|
{
|
|
|
|
|
|
DoneActivitiesToday = todayTasks.Count(t => t.IsDone),
|
|
|
|
|
|
TotalActivitiesToday = todayTasks.Count,
|
2024-04-25 02:33:17 +03:30
|
|
|
|
UnDoneActivitiesToday = todayTasks.Count(t => t.IsDone!),
|
|
|
|
|
|
TotalShiftToday = todayShiftPlans.Count,
|
|
|
|
|
|
TodayStaffNames = names,
|
|
|
|
|
|
TotalStaffToday = todayShiftPlans.SelectMany(sp => sp.Users).Count()
|
2023-12-09 09:54:34 +03:30
|
|
|
|
};
|
2024-04-25 02:33:17 +03:30
|
|
|
|
|
2023-12-11 14:32:29 +03:30
|
|
|
|
if (_currentUserService.Permissions != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int totalStepCount = 0;
|
|
|
|
|
|
int completeStepCount = 0;
|
|
|
|
|
|
string currentStep = string.Empty;
|
|
|
|
|
|
if (_currentUserService.Permissions.Exists(s => s == ApplicationPermission.ManageRoutines))
|
|
|
|
|
|
{
|
|
|
|
|
|
totalStepCount++;
|
|
|
|
|
|
var hasRoutine = await _repositoryWrapper.SetRepository<Routine>()
|
|
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.AnyAsync(r=>r.ComplexId== complexId, cancellationToken);
|
|
|
|
|
|
if(hasRoutine)
|
|
|
|
|
|
completeStepCount++;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentStep.IsNullOrEmpty())
|
|
|
|
|
|
currentStep = "تکمیل بخش روتین ها";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentUserService.Permissions.Exists(s => s == ApplicationPermission.ManageSections))
|
|
|
|
|
|
{
|
|
|
|
|
|
totalStepCount++;
|
|
|
|
|
|
var hasSection = await _repositoryWrapper.SetRepository<Section>()
|
|
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.AnyAsync(r => r.ComplexId == complexId, cancellationToken);
|
|
|
|
|
|
if (hasSection)
|
|
|
|
|
|
completeStepCount++;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentStep.IsNullOrEmpty())
|
|
|
|
|
|
currentStep = "تکمیل بخش سکشن ها";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentUserService.Permissions.Exists(s => s == ApplicationPermission.ManagePositions))
|
|
|
|
|
|
{
|
|
|
|
|
|
totalStepCount++;
|
|
|
|
|
|
var hasPosition = await _repositoryWrapper.SetRepository<Position>()
|
|
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.AnyAsync(r => r.ComplexId == complexId, cancellationToken);
|
|
|
|
|
|
if (hasPosition)
|
|
|
|
|
|
completeStepCount++;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentStep.IsNullOrEmpty())
|
|
|
|
|
|
currentStep = "تکمیل بخش پوزیشن ها";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentUserService.Permissions.Exists(s => s == ApplicationPermission.ManageStaffs))
|
|
|
|
|
|
{
|
|
|
|
|
|
totalStepCount++;
|
|
|
|
|
|
var hasStaff = await _repositoryWrapper.SetRepository<ComplexUser>()
|
|
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.AnyAsync(r => r.ComplexId == complexId, cancellationToken);
|
|
|
|
|
|
if (hasStaff)
|
|
|
|
|
|
completeStepCount++;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentStep.IsNullOrEmpty())
|
|
|
|
|
|
currentStep = "تکمیل بخش کاربر ها";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentUserService.Permissions.Exists(s => s == ApplicationPermission.ManageShifts))
|
|
|
|
|
|
{
|
|
|
|
|
|
totalStepCount++;
|
|
|
|
|
|
var hasShift = await _repositoryWrapper.SetRepository<Shift>()
|
|
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.AnyAsync(r => r.ComplexId == complexId, cancellationToken);
|
|
|
|
|
|
if (hasShift)
|
|
|
|
|
|
completeStepCount++;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentStep.IsNullOrEmpty())
|
|
|
|
|
|
currentStep = "تکمیل بخش شیفت ها";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentUserService.Permissions.Exists(s => s == ApplicationPermission.ManageTasks))
|
|
|
|
|
|
{
|
|
|
|
|
|
totalStepCount++;
|
|
|
|
|
|
var hasTask = await _repositoryWrapper.SetRepository<Task>()
|
|
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.AnyAsync(r => r.ComplexId == complexId, cancellationToken);
|
|
|
|
|
|
if (hasTask)
|
|
|
|
|
|
completeStepCount++;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentStep.IsNullOrEmpty())
|
|
|
|
|
|
currentStep = "تکمیل بخش تسک ها";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_currentUserService.Permissions.Exists(s => s == ApplicationPermission.ManageShiftPlans))
|
|
|
|
|
|
{
|
|
|
|
|
|
totalStepCount++;
|
|
|
|
|
|
var hasStaff = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
|
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.AnyAsync(r => r.ComplexId == complexId, cancellationToken);
|
|
|
|
|
|
if (hasStaff)
|
|
|
|
|
|
completeStepCount++;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentStep.IsNullOrEmpty())
|
|
|
|
|
|
currentStep = "تکمیل بخش شیفت بندی ها";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
page.SignUpCompletePercent = ((totalStepCount * 100) / completeStepCount);
|
|
|
|
|
|
page.CurrentSignUpStep = currentStep;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return page;
|
2023-12-09 09:54:34 +03:30
|
|
|
|
}
|
|
|
|
|
|
}
|