change the Admin monthly overview by figma - add tester
This commit is contained in:
@@ -4,5 +4,5 @@ public enum IsActive
|
|||||||
{
|
{
|
||||||
False,
|
False,
|
||||||
True,
|
True,
|
||||||
|
None
|
||||||
}
|
}
|
||||||
@@ -47,4 +47,9 @@ public class AdminMonthlyOverview:EntityBase
|
|||||||
}
|
}
|
||||||
Status -= 1;
|
Status -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetStatus(AdminMonthlyOverviewStatus status)
|
||||||
|
{
|
||||||
|
Status = status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,6 @@ namespace Company.Domain.AdminMonthlyOverviewAgg;
|
|||||||
|
|
||||||
public interface IAdminMonthlyOverviewRepository:IRepository<long, AdminMonthlyOverview>
|
public interface IAdminMonthlyOverviewRepository:IRepository<long, AdminMonthlyOverview>
|
||||||
{
|
{
|
||||||
Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopStatus(long accountId, int month, int year);
|
Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopStatus(AdminMonthlyOverviewSearchModel searchModel);
|
||||||
|
Task<AdminMonthlyOverViewCounterVm> GetCounter(int year, int month, long accountId);
|
||||||
}
|
}
|
||||||
@@ -9,11 +9,17 @@ public interface IAdminMonthlyOverviewApplication
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// نمایش لیست ماهانه کارگاه ها - درصورت وجود نداشتن اطلاعات در این ماه، یک رکورد جدید ایجاد میکند
|
/// نمایش لیست ماهانه کارگاه ها - درصورت وجود نداشتن اطلاعات در این ماه، یک رکورد جدید ایجاد میکند
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="accountId"></param>
|
|
||||||
/// <param name="month"></param>
|
|
||||||
/// <param name="year"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopsStatus(long accountId, int month, int year);
|
Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopListByStatus(AdminMonthlyOverviewSearchModel searchModel);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// شمارش تعداد هر تب
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="year"></param>
|
||||||
|
/// <param name="month"></param>
|
||||||
|
/// <param name="accountId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<AdminMonthlyOverViewCounterVm> GetCounter(int year, int month, long accountId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// رفتن به مرحله بعدی
|
/// رفتن به مرحله بعدی
|
||||||
@@ -30,10 +36,43 @@ public interface IAdminMonthlyOverviewApplication
|
|||||||
Task<OperationResult> Back(long id);
|
Task<OperationResult> Back(long id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AdminMonthlyOverViewCounterVm
|
||||||
|
{
|
||||||
|
public int CreateDocument { get; set; }
|
||||||
|
public int VisitPending { get; set; }
|
||||||
|
public int VisitInProgress { get; set; }
|
||||||
|
public int VisitCompleted { get; set; }
|
||||||
|
public int Archived { get; set; }
|
||||||
|
public int All { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AdminMonthlyOverviewSearchModel
|
||||||
|
{
|
||||||
|
public int Year { get; set; }
|
||||||
|
public int Month { get; set; }
|
||||||
|
public long WorkshopId { get; set; }
|
||||||
|
public long EmployerId { get; set; }
|
||||||
|
public long AdminAccountId { get; set; }
|
||||||
|
public IsActive ActivationStatus { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public class AdminMonthlyOverviewListViewModel
|
public class AdminMonthlyOverviewListViewModel
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public long WorkshopId { get; set; }
|
public long WorkshopId { get; set; }
|
||||||
public string WorkshopName { get; set; }
|
public string WorkshopName { get; set; }
|
||||||
|
public string WorkshopArchiveCode { get; set; }
|
||||||
|
public string Province { get; set; }
|
||||||
|
public string City { get; set; }
|
||||||
|
public string Address { get; set; }
|
||||||
|
public string AgentPhoneNumber { get; set; }
|
||||||
|
public string AdminFullName { get; set; }
|
||||||
|
public string EmployerName { get; set; }
|
||||||
|
public string EmployerPhoneNumber { get; set; }
|
||||||
|
public int EmployeeCount { get; set; }
|
||||||
public AdminMonthlyOverviewStatus Status { get; set; }
|
public AdminMonthlyOverviewStatus Status { get; set; }
|
||||||
|
public bool IsBlock { get; set; }
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ using CompanyManagment.App.Contracts.AdminMonthlyOverview;
|
|||||||
|
|
||||||
namespace CompanyManagment.Application;
|
namespace CompanyManagment.Application;
|
||||||
|
|
||||||
public class AdminMonthlyOverviewApplication:IAdminMonthlyOverviewApplication
|
public class AdminMonthlyOverviewApplication : IAdminMonthlyOverviewApplication
|
||||||
{
|
{
|
||||||
private readonly IAdminMonthlyOverviewRepository _adminMonthlyOverviewRepository;
|
private readonly IAdminMonthlyOverviewRepository _adminMonthlyOverviewRepository;
|
||||||
|
|
||||||
@@ -17,21 +17,26 @@ public class AdminMonthlyOverviewApplication:IAdminMonthlyOverviewApplication
|
|||||||
_adminMonthlyOverviewRepository = adminMonthlyOverviewRepository;
|
_adminMonthlyOverviewRepository = adminMonthlyOverviewRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopsStatus(long accountId, int month, int year)
|
public async Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopListByStatus(AdminMonthlyOverviewSearchModel searchModel)
|
||||||
{
|
{
|
||||||
return await _adminMonthlyOverviewRepository.GetWorkshopStatus(accountId, month, year);
|
return await _adminMonthlyOverviewRepository.GetWorkshopStatus(searchModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<AdminMonthlyOverViewCounterVm> GetCounter(int year, int month, long accountId)
|
||||||
|
{
|
||||||
|
return await _adminMonthlyOverviewRepository.GetCounter(year, month, accountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<OperationResult> Next(long id)
|
public async Task<OperationResult> Next(long id)
|
||||||
{
|
{
|
||||||
var operation= new OperationResult();
|
var operation = new OperationResult();
|
||||||
var monthlyOverview = _adminMonthlyOverviewRepository.Get(id);
|
var monthlyOverview = _adminMonthlyOverviewRepository.Get(id);
|
||||||
if (monthlyOverview == null)
|
if (monthlyOverview == null)
|
||||||
{
|
{
|
||||||
return operation.Failed("آیتم موردنظر یافت نشد");
|
return operation.Failed("آیتم موردنظر یافت نشد");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monthlyOverview.Status== AdminMonthlyOverviewStatus.CreateDocuments)
|
if (monthlyOverview.Status == AdminMonthlyOverviewStatus.CreateDocuments)
|
||||||
{
|
{
|
||||||
return operation.Failed("شما نمیتوانید تا زمانی که قرارداد و تصفیه را تنظیم نکردید به مرحله بعد بروید");
|
return operation.Failed("شما نمیتوانید تا زمانی که قرارداد و تصفیه را تنظیم نکردید به مرحله بعد بروید");
|
||||||
}
|
}
|
||||||
@@ -42,11 +47,11 @@ public class AdminMonthlyOverviewApplication:IAdminMonthlyOverviewApplication
|
|||||||
|
|
||||||
if (monthlyOverview.Status >= maxValue)
|
if (monthlyOverview.Status >= maxValue)
|
||||||
{
|
{
|
||||||
return operation.Failed("مرحله بعدی انتخاب شده نامعتبر است");
|
return operation.Failed("مرحله بعدی انتخاب شده نامعتبر است");
|
||||||
}
|
}
|
||||||
|
|
||||||
monthlyOverview.Next();
|
monthlyOverview.Next();
|
||||||
await _adminMonthlyOverviewRepository.SaveChangesAsync();
|
await _adminMonthlyOverviewRepository.SaveChangesAsync();
|
||||||
return operation.Succcedded();
|
return operation.Succcedded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +64,7 @@ public class AdminMonthlyOverviewApplication:IAdminMonthlyOverviewApplication
|
|||||||
return operation.Failed("آیتم موردنظر یافت نشد");
|
return operation.Failed("آیتم موردنظر یافت نشد");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monthlyOverview.Status == AdminMonthlyOverviewStatus.CreateDocuments+1)
|
if (monthlyOverview.Status == AdminMonthlyOverviewStatus.CreateDocuments + 1)
|
||||||
{
|
{
|
||||||
return operation.Failed("شما امکان برگشت به مرحله قبل را ندارید");
|
return operation.Failed("شما امکان برگشت به مرحله قبل را ندارید");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
|||||||
using _0_Framework.Application;
|
using _0_Framework.Application;
|
||||||
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
|
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
|
||||||
using _0_Framework.InfraStructure;
|
using _0_Framework.InfraStructure;
|
||||||
|
using AccountMangement.Infrastructure.EFCore;
|
||||||
using Company.Domain.AdminMonthlyOverviewAgg;
|
using Company.Domain.AdminMonthlyOverviewAgg;
|
||||||
using CompanyManagment.App.Contracts.AdminMonthlyOverview;
|
using CompanyManagment.App.Contracts.AdminMonthlyOverview;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
@@ -15,62 +16,167 @@ namespace CompanyManagment.EFCore.Repository;
|
|||||||
public class AdminMonthlyOverviewRepository : RepositoryBase<long, AdminMonthlyOverview>, IAdminMonthlyOverviewRepository
|
public class AdminMonthlyOverviewRepository : RepositoryBase<long, AdminMonthlyOverview>, IAdminMonthlyOverviewRepository
|
||||||
{
|
{
|
||||||
private readonly CompanyContext _companyContext;
|
private readonly CompanyContext _companyContext;
|
||||||
public AdminMonthlyOverviewRepository(CompanyContext companyContext) : base(companyContext)
|
private readonly AccountContext _accountContext;
|
||||||
|
public AdminMonthlyOverviewRepository(CompanyContext companyContext, AccountContext accountContext) : base(companyContext)
|
||||||
{
|
{
|
||||||
_companyContext = companyContext;
|
_companyContext = companyContext;
|
||||||
|
_accountContext = accountContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopStatus(long accountId, int month, int year)
|
public async Task<List<AdminMonthlyOverviewListViewModel>> GetWorkshopStatus(AdminMonthlyOverviewSearchModel searchModel)
|
||||||
{
|
{
|
||||||
if ($"{year:0000}/{month:00}/01".TryToGeorgianDateTime(out var dateTime) == false)
|
var year = searchModel.Year;
|
||||||
|
var month = searchModel.Month;
|
||||||
|
var accountId = searchModel.AdminAccountId;
|
||||||
|
// اگر تبدیل تاریخ به میلادی موفق نبود، لیست خالی برگردان
|
||||||
|
if ($"{year:0000}/{month:00}/01".TryToGeorgianDateTime(out var targetDate) == false)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
var contractingPartyIdsQuery = _companyContext.InstitutionContractSet
|
// دریافت اطلاعات ادمین
|
||||||
.Where(c => c.ContractStartGr <= dateTime && c.ContractEndGr >= dateTime && c.IsActiveString == "true")
|
var adminAccount = await _accountContext.Accounts.FirstOrDefaultAsync(x => x.id == searchModel.AdminAccountId);
|
||||||
.Select(c => c.ContractingPartyId);
|
|
||||||
|
|
||||||
var accountWorkshopIdsQuery = _companyContext.WorkshopAccounts
|
// اگر ادمین پیدا نشد، لیست خالی برگردان
|
||||||
|
if (adminAccount == null)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
// دریافت طرف حساب های معتبر برای تاریخ مورد نظر
|
||||||
|
var contractingPartyIds = await _companyContext.InstitutionContractSet.AsNoTracking()
|
||||||
|
.Where(c => c.ContractStartGr <= targetDate && c.ContractEndGr >= targetDate && c.IsActiveString == "true")
|
||||||
|
.Select(c => c.ContractingPartyId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
// دریافت کارگاههای مرتبط با اکانت
|
||||||
|
var accountWorkshopIds = await _companyContext.WorkshopAccounts
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Where(w => w.AccountId == accountId)
|
.Where(w => w.AccountId == accountId)
|
||||||
.Select(w => w.WorkshopId);
|
.Select(w => w.WorkshopId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var workshops = await _companyContext.PersonalContractingParties
|
// دریافت کارگاههای مربوط به طرف حساب و اکانت
|
||||||
.Include(p => p.Employers)
|
// Replace the selected code with the following to return a list of anonymous objects containing both workshop and contractingParty
|
||||||
.ThenInclude(e => e.WorkshopEmployers)
|
|
||||||
.ThenInclude(we => we.Workshop)
|
|
||||||
.Where(p => contractingPartyIdsQuery.Contains(p.id))
|
|
||||||
.SelectMany(p => p.Employers)
|
|
||||||
.SelectMany(e => e.WorkshopEmployers)
|
|
||||||
.Where(we => accountWorkshopIdsQuery.Contains(we.WorkshopId))
|
|
||||||
.Select(we => we.Workshop).ToListAsync();
|
|
||||||
|
|
||||||
var workshopIds = workshops.Select(x => x.id).ToList();
|
var workshopsWithContractingParty = await _companyContext.Workshops
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(w => accountWorkshopIds.Contains(w.id))
|
||||||
|
.Include(w => w.WorkshopEmployers)
|
||||||
|
.ThenInclude(we => we.Employer)
|
||||||
|
.ThenInclude(e => e.ContractingParty).AsSplitQuery()
|
||||||
|
.Where(w => w.WorkshopEmployers.Any(we =>
|
||||||
|
we.Employer != null &&
|
||||||
|
contractingPartyIds.Contains(we.Employer.ContractingPartyId)))
|
||||||
|
.Select(w => new
|
||||||
|
{
|
||||||
|
Workshop = w,
|
||||||
|
ContractingParty = w.WorkshopEmployers
|
||||||
|
.Where(we => we.Employer != null && contractingPartyIds.Contains(we.Employer.ContractingPartyId))
|
||||||
|
.Select(we => we.Employer.ContractingParty)
|
||||||
|
.FirstOrDefault()
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var adminMonthlyOverviewWorkshopIds = _companyContext.AdminMonthlyOverviews.Where(x =>
|
var workshopIds = workshopsWithContractingParty.Select(x => x.Workshop.id).ToList();
|
||||||
workshopIds.Contains(x.WorkshopId) && x.Month == month && x.Year == year).Select(x => x.WorkshopId).ToList();
|
|
||||||
|
|
||||||
|
// پیدا کردن کارگاههایی که قبلاً برای این ماه/سال AdminMonthlyOverview دارند
|
||||||
|
var adminMonthlyOverviewWorkshopIds = await _companyContext.AdminMonthlyOverviews
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(x => workshopIds.Contains(x.WorkshopId) && x.Month == month && x.Year == year)
|
||||||
|
.Select(x => x.WorkshopId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var notExistAdminMonthlyReviewsWorkshopIds = workshopIds.Where(x => !adminMonthlyOverviewWorkshopIds.Contains(x)).ToList();
|
// پیدا کردن کارگاههایی که نیاز به ایجاد AdminMonthlyOverview جدید دارند
|
||||||
|
var notExistAdminMonthlyReviewsWorkshopIds = workshopIds
|
||||||
|
.Except(adminMonthlyOverviewWorkshopIds)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
await CreateRangeAdminMonthlyOverview(notExistAdminMonthlyReviewsWorkshopIds, month, year);
|
// ایجاد رکوردهای AdminMonthlyOverview که وجود ندارند
|
||||||
|
if (notExistAdminMonthlyReviewsWorkshopIds.Any())
|
||||||
|
await CreateRangeAdminMonthlyOverview(notExistAdminMonthlyReviewsWorkshopIds, month, year);
|
||||||
|
|
||||||
|
// بهروزرسانی وضعیتها
|
||||||
await UpdateAdminMonthlyOverviewStatus(year, month, workshopIds);
|
await UpdateAdminMonthlyOverviewStatus(year, month, workshopIds);
|
||||||
|
|
||||||
|
// دریافت همه AdminMonthlyOverview برای این کارگاهها/ماه/سال
|
||||||
|
var adminMonthlyOverviewsQuery = _companyContext.AdminMonthlyOverviews
|
||||||
|
.Where(x => workshopIds.Contains(x.WorkshopId) && x.Month == month && x.Year == year);
|
||||||
|
|
||||||
var adminMonthlyOverViews = _companyContext.AdminMonthlyOverviews.Where(x =>
|
if (searchModel.WorkshopId > 0)
|
||||||
workshopIds.Contains(x.WorkshopId) && x.Month == month && x.Year == year).ToList().Select(x =>
|
|
||||||
{
|
{
|
||||||
var workshop = workshops.FirstOrDefault(w => w.id == x.WorkshopId);
|
adminMonthlyOverviewsQuery = adminMonthlyOverviewsQuery.Where(x => x.WorkshopId == searchModel.WorkshopId);
|
||||||
return new AdminMonthlyOverviewListViewModel()
|
}
|
||||||
|
|
||||||
|
if (searchModel.EmployerId > 0)
|
||||||
|
{
|
||||||
|
var searchWorkshopId = workshopsWithContractingParty.Where(x => x.Workshop.WorkshopEmployers.Any(e => e.EmployerId == searchModel.EmployerId)).Select(x => x.Workshop.id).ToList();
|
||||||
|
adminMonthlyOverviewsQuery = adminMonthlyOverviewsQuery.Where(x => searchWorkshopId.Contains(x.WorkshopId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var adminMonthlyOverviewsList = await adminMonthlyOverviewsQuery.ToListAsync();
|
||||||
|
var employeeCounts = _companyContext.LeftWorkList.Where(x =>
|
||||||
|
x.StartWorkDate < targetDate && x.LeftWorkDate > targetDate && workshopIds.Contains(x.WorkshopId))
|
||||||
|
.GroupBy(x => x.WorkshopId).Select(x => new { EmployeeCounts = x.Count(), WorkshopId = x.Key }).ToList();
|
||||||
|
|
||||||
|
// نگاشت به ViewModel
|
||||||
|
var adminMonthlyOverviewList = adminMonthlyOverviewsList.Select(x =>
|
||||||
|
{
|
||||||
|
var employeeCount = employeeCounts.FirstOrDefault(e => e.WorkshopId == x.WorkshopId);
|
||||||
|
var workshopWithContractingParty =
|
||||||
|
workshopsWithContractingParty.FirstOrDefault(w => w.Workshop.id == x.WorkshopId);
|
||||||
|
|
||||||
|
var workshop = workshopWithContractingParty?.Workshop;
|
||||||
|
var contractingParty = workshopWithContractingParty?.ContractingParty;
|
||||||
|
var employer = workshop?.WorkshopEmployers.FirstOrDefault()?.Employer;
|
||||||
|
return new AdminMonthlyOverviewListViewModel
|
||||||
{
|
{
|
||||||
WorkshopId = x.WorkshopId,
|
WorkshopId = x.WorkshopId,
|
||||||
Status = x.Status,
|
Status = x.Status,
|
||||||
Id = x.id,
|
Id = x.id,
|
||||||
WorkshopName = workshop?.WorkshopFullName ?? ""
|
WorkshopName = workshop?.WorkshopFullName ?? "",
|
||||||
|
WorkshopArchiveCode = workshop?.ArchiveCode ?? "",
|
||||||
|
Address = workshop?.Address ?? "",
|
||||||
|
City = workshop?.City ?? "",
|
||||||
|
Province = workshop?.State ?? "",
|
||||||
|
EmployerName = employer?.FullName ?? "",
|
||||||
|
EmployerPhoneNumber = employer?.Phone ?? "",
|
||||||
|
AdminFullName = adminAccount.Fullname,
|
||||||
|
EmployeeCount = employeeCount?.EmployeeCounts ?? 0,
|
||||||
|
AgentPhoneNumber = "",
|
||||||
|
IsBlock = contractingParty?.IsBlock == "true"
|
||||||
};
|
};
|
||||||
}).ToList();
|
}).OrderBy(x => x.IsBlock).ToList();
|
||||||
|
|
||||||
|
return adminMonthlyOverviewList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<AdminMonthlyOverViewCounterVm> GetCounter(int year, int month, long accountId)
|
||||||
|
{
|
||||||
|
var searchModel = new AdminMonthlyOverviewSearchModel()
|
||||||
|
{
|
||||||
|
AdminAccountId = accountId,
|
||||||
|
Month = month,
|
||||||
|
Year = year
|
||||||
|
};
|
||||||
|
var list = await GetWorkshopStatus(searchModel);
|
||||||
|
|
||||||
|
var allCount = list.Count;
|
||||||
|
var archivedCount = list.Count(x => x.Status == AdminMonthlyOverviewStatus.Archived);
|
||||||
|
var createDocCount = list.Count(x => x.Status == AdminMonthlyOverviewStatus.CreateDocuments);
|
||||||
|
var visitCompleteCount = list.Count(x => x.Status == AdminMonthlyOverviewStatus.VisitCompleted);
|
||||||
|
var visitInProgressCount = list.Count(x => x.Status == AdminMonthlyOverviewStatus.VisitInProgress);
|
||||||
|
var visitPendingCount = list.Count(x => x.Status == AdminMonthlyOverviewStatus.VisitPending);
|
||||||
|
|
||||||
|
return new AdminMonthlyOverViewCounterVm
|
||||||
|
{
|
||||||
|
All = allCount,
|
||||||
|
Archived = archivedCount,
|
||||||
|
VisitPending = visitPendingCount,
|
||||||
|
VisitInProgress = visitInProgressCount,
|
||||||
|
VisitCompleted = visitCompleteCount,
|
||||||
|
CreateDocument = createDocCount
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return adminMonthlyOverViews;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateAdminMonthlyOverviewStatus(int year, int month, List<long> workshopIds)
|
private async Task UpdateAdminMonthlyOverviewStatus(int year, int month, List<long> workshopIds)
|
||||||
@@ -78,50 +184,63 @@ public class AdminMonthlyOverviewRepository : RepositoryBase<long, AdminMonthlyO
|
|||||||
var targetDate = $"{year:0000}/{month:00}/01".ToGeorgianDateTime();
|
var targetDate = $"{year:0000}/{month:00}/01".ToGeorgianDateTime();
|
||||||
_ = $"{year:0000}/{month:00}/01".ToGeorgianDateTime().AddMonthsFa(1, out var nextMonth);
|
_ = $"{year:0000}/{month:00}/01".ToGeorgianDateTime().AddMonthsFa(1, out var nextMonth);
|
||||||
|
|
||||||
var workingEmployeeIds = (await _companyContext.LeftWorkList
|
|
||||||
|
var workingEmployeeIds = (await _companyContext.LeftWorkList.AsNoTracking()
|
||||||
.Where(x => workshopIds.Contains(x.WorkshopId) && x.StartWorkDate <= targetDate && x.LeftWorkDate >= targetDate)
|
.Where(x => workshopIds.Contains(x.WorkshopId) && x.StartWorkDate <= targetDate && x.LeftWorkDate >= targetDate)
|
||||||
.Select(x => new { x.WorkshopId, x.EmployeeId })
|
.Select(x => new { x.WorkshopId, x.EmployeeId })
|
||||||
.Distinct()
|
.ToListAsync()).Distinct();
|
||||||
.ToListAsync());
|
|
||||||
|
|
||||||
var contractKeys = await _companyContext.Contracts
|
var contractSet = (await _companyContext.Contracts.AsNoTracking()
|
||||||
.Where(x => x.ContarctStart <= nextMonth && x.ContractEnd >= nextMonth)
|
.Where(x => x.ContarctStart <= nextMonth && x.ContractEnd >= nextMonth)
|
||||||
.Select(x => new { WorkshopId = x.WorkshopIds, x.EmployeeId })
|
.Select(x => new { x.WorkshopIds, x.EmployeeId })
|
||||||
.ToListAsync();
|
.ToListAsync())
|
||||||
|
.Select(x => (x.WorkshopIds, x.EmployeeId))
|
||||||
|
.ToHashSet();
|
||||||
|
|
||||||
var contractSet = contractKeys.ToHashSet();
|
var checkoutSet = (await _companyContext.CheckoutSet.AsNoTracking()
|
||||||
|
|
||||||
var workshopsWithFullContracts = workingEmployeeIds
|
|
||||||
.GroupBy(x => x.WorkshopId)
|
|
||||||
.Where(group => group.All(emp => contractSet.Contains(new { emp.WorkshopId, emp.EmployeeId })))
|
|
||||||
.Select(group => group.Key)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
var checkoutKeys = await _companyContext.CheckoutSet
|
|
||||||
.Where(x => x.ContractStart <= targetDate && x.ContractEnd >= targetDate)
|
.Where(x => x.ContractStart <= targetDate && x.ContractEnd >= targetDate)
|
||||||
.Select(x => new { x.WorkshopId, x.EmployeeId })
|
.Select(x => new { x.WorkshopId, x.EmployeeId })
|
||||||
|
.ToListAsync())
|
||||||
|
.Select(x => (x.WorkshopId, x.EmployeeId))
|
||||||
|
.ToHashSet();
|
||||||
|
|
||||||
|
var grouped = workingEmployeeIds.GroupBy(x => x.WorkshopId).ToList();
|
||||||
|
|
||||||
|
var workshopsWithFullContracts = grouped
|
||||||
|
.Where(g => g.All(emp => contractSet.Contains((emp.WorkshopId, emp.EmployeeId))))
|
||||||
|
.Select(g => g.Key)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var workshopsWithFullCheckout = grouped
|
||||||
|
.Where(g => g.All(emp => checkoutSet.Contains((emp.WorkshopId, emp.EmployeeId))))
|
||||||
|
.Select(g => g.Key)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var fullyCoveredWorkshops = workshopsWithFullContracts.Intersect(workshopsWithFullCheckout).ToList();
|
||||||
|
|
||||||
|
var notFullyCoveredWorkshops = grouped
|
||||||
|
.Where(g => g.Any(emp =>
|
||||||
|
!contractSet.Contains((emp.WorkshopId, emp.EmployeeId)) ||
|
||||||
|
!checkoutSet.Contains((emp.WorkshopId, emp.EmployeeId))))
|
||||||
|
.Select(g => g.Key)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var adminMonthlyOverviews = _companyContext.AdminMonthlyOverviews
|
||||||
|
.Where(x => x.Month == month && x.Year == year);
|
||||||
|
|
||||||
|
var adminMonthlyOverviewsWithFullContracts = await adminMonthlyOverviews
|
||||||
|
.Where(x => fullyCoveredWorkshops.Contains(x.WorkshopId) && x.Status == AdminMonthlyOverviewStatus.CreateDocuments)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var checkoutSet = checkoutKeys.ToHashSet();
|
var adminMonthlyOverviewsWithNotFullContracts = await adminMonthlyOverviews
|
||||||
|
.Where(x => notFullyCoveredWorkshops.Contains(x.WorkshopId)&&x.Status != AdminMonthlyOverviewStatus.CreateDocuments)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var workshopsWithFullCheckout = workingEmployeeIds
|
foreach (var adminMonthlyOverview in adminMonthlyOverviewsWithFullContracts)
|
||||||
.GroupBy(x => x.WorkshopId)
|
adminMonthlyOverview.SetStatus(AdminMonthlyOverviewStatus.VisitPending);
|
||||||
.Where(group => group.All(emp => checkoutSet.Contains(new { emp.WorkshopId, emp.EmployeeId })))
|
|
||||||
.Select(group => group.Key)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
var fullyCoveredWorkshops = workshopsWithFullContracts
|
foreach (var adminMonthlyOverview in adminMonthlyOverviewsWithNotFullContracts)
|
||||||
.Intersect(workshopsWithFullCheckout)
|
adminMonthlyOverview.SetStatus(AdminMonthlyOverviewStatus.CreateDocuments);
|
||||||
.ToList();
|
|
||||||
|
|
||||||
|
|
||||||
var adminMonthlyOverviews = await _companyContext.AdminMonthlyOverviews.Where(x =>
|
|
||||||
fullyCoveredWorkshops.Contains(x.WorkshopId) && x.Month == month && x.Year == year && x.Status == AdminMonthlyOverviewStatus.CreateDocuments).ToListAsync();
|
|
||||||
|
|
||||||
foreach (var adminMonthlyOverview in adminMonthlyOverviews)
|
|
||||||
{
|
|
||||||
adminMonthlyOverview.Next();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _companyContext.SaveChangesAsync();
|
await _companyContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using ServiceHost.Hubs;
|
|||||||
using ServiceHost.MiddleWare;
|
using ServiceHost.MiddleWare;
|
||||||
using WorkFlow.Infrastructure.Config;
|
using WorkFlow.Infrastructure.Config;
|
||||||
using _0_Framework.Application.UID;
|
using _0_Framework.Application.UID;
|
||||||
|
using ServiceHost.Test;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@@ -49,6 +50,12 @@ builder.Services.AddTransient<IUidService, UidService>();
|
|||||||
//services.AddSingleton<IWorkingTest, WorkingTest>();
|
//services.AddSingleton<IWorkingTest, WorkingTest>();
|
||||||
//services.AddHostedService<JobWorker>();
|
//services.AddHostedService<JobWorker>();
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
builder.Services.AddTransient<Tester>();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
builder.Services.Configure<FormOptions>(options =>
|
builder.Services.Configure<FormOptions>(options =>
|
||||||
{
|
{
|
||||||
options.ValueCountLimit = int.MaxValue;
|
options.ValueCountLimit = int.MaxValue;
|
||||||
@@ -151,6 +158,15 @@ builder.Services.AddSignalR();
|
|||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
#region Mahan
|
#region Mahan
|
||||||
app.UseStatusCodePagesWithRedirects("/error/{0}");
|
app.UseStatusCodePagesWithRedirects("/error/{0}");
|
||||||
|
|
||||||
|
//the backend Tester
|
||||||
|
if (builder.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
using var scope = app.Services.CreateScope();
|
||||||
|
var tester = scope.ServiceProvider.GetRequiredService<Tester>();
|
||||||
|
await tester.Test();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
//Create Http Pipeline
|
//Create Http Pipeline
|
||||||
|
|
||||||
|
|||||||
38
ServiceHost/Test/Tester.cs
Normal file
38
ServiceHost/Test/Tester.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using CompanyManagment.App.Contracts.AdminMonthlyOverview;
|
||||||
|
using CompanyManagment.EFCore;
|
||||||
|
using ServiceHost.Areas.AdminNew.Pages.Company.RollCall;
|
||||||
|
|
||||||
|
namespace ServiceHost.Test;
|
||||||
|
|
||||||
|
public class Tester
|
||||||
|
{
|
||||||
|
private readonly IAdminMonthlyOverviewApplication _adminMonthlyOverviewApplication;
|
||||||
|
private readonly CompanyContext _companyContext;
|
||||||
|
public Tester(IAdminMonthlyOverviewApplication adminMonthlyOverviewApplication, CompanyContext companyContext)
|
||||||
|
{
|
||||||
|
_adminMonthlyOverviewApplication = adminMonthlyOverviewApplication;
|
||||||
|
_companyContext = companyContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Test()
|
||||||
|
{
|
||||||
|
|
||||||
|
await AdminMonthlyOverviewTest();
|
||||||
|
|
||||||
|
}
|
||||||
|
private async Task AdminMonthlyOverviewTest()
|
||||||
|
{
|
||||||
|
var acc = _companyContext.WorkshopAccounts.FirstOrDefault(x => x.AccountId == 322);
|
||||||
|
var searchModel = new AdminMonthlyOverviewSearchModel()
|
||||||
|
{
|
||||||
|
Year = 1403,
|
||||||
|
Month = 12,
|
||||||
|
AdminAccountId = 322
|
||||||
|
};
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
|
var workshopsStatus = await _adminMonthlyOverviewApplication.GetWorkshopListByStatus(searchModel);
|
||||||
|
Console.WriteLine(stopwatch.Elapsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user