add new metod
This commit is contained in:
@@ -5,6 +5,7 @@ using _0_Framework.Application;
|
||||
using _0_Framework.Domain;
|
||||
using CompanyManagment.App.Contracts.LeftWork;
|
||||
using CompanyManagment.App.Contracts.PersonnleCode;
|
||||
using CompanyManagment.App.Contracts.Workshop.DTOs;
|
||||
|
||||
namespace Company.Domain.LeftWorkAgg;
|
||||
|
||||
@@ -46,4 +47,11 @@ public interface ILeftWorkRepository : IRepository<long, LeftWork>
|
||||
|
||||
Task<LeftWork> GetLastLeftWork(long employeeId, long workshopId);
|
||||
List<LeftWorkViewModel> SearchCreateContract(LeftWorkSearchModel searchModel);
|
||||
|
||||
/// <summary>
|
||||
/// دریافت اطلاعات کارگاه و پرسنل برای ایجاد قرارداد
|
||||
/// </summary>
|
||||
/// <param name="workshopId"></param>
|
||||
/// <returns></returns>
|
||||
AutoExtensionDto AutoExtentionEmployees(long workshopId);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using CompanyManagment.App.Contracts.PersonnleCode;
|
||||
using CompanyManagment.App.Contracts.Workshop.DTOs;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.LeftWork;
|
||||
@@ -30,4 +31,10 @@ public interface ILeftWorkApplication
|
||||
OperationResult CreateLeftWorkByLeftWorkGroups(string employeeFullName, long commandEmployeeId, List<PersonnelCodeViewModel> commandPersonnelCode, List<LeftWorkGroup> leftWorkGroups);
|
||||
OperationResult CheckDeleteLeftWork(long workshopId, long employeeId, string date, int type);
|
||||
OperationResult CheckEditLeftWork(long workshopId, long employeeId, string date, int type);
|
||||
/// <summary>
|
||||
/// دریافت اطلاعات کارگاه و پرسنل برای ایجاد قرارداد
|
||||
/// </summary>
|
||||
/// <param name="workshopId"></param>
|
||||
/// <returns></returns>
|
||||
AutoExtensionDto AutoExtentionEmployees(long workshopId);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ using CompanyManagment.App.Contracts.PersonnleCode;
|
||||
using CompanyManagment.App.Contracts.RollCallEmployee;
|
||||
using CompanyManagment.App.Contracts.WorkingHours;
|
||||
using CompanyManagment.App.Contracts.WorkingHoursItems;
|
||||
using CompanyManagment.App.Contracts.Workshop.DTOs;
|
||||
using PersianTools.Core;
|
||||
|
||||
namespace CompanyManagment.Application;
|
||||
@@ -600,6 +601,11 @@ public class LeftWorkApplication : ILeftWorkApplication
|
||||
return _leftWorkRepository.CheckEditLeftWork(workshopId, employeeId, date.ToGeorgianDateTime(), type);
|
||||
}
|
||||
|
||||
public AutoExtensionDto AutoExtentionEmployees(long workshopId)
|
||||
{
|
||||
return _leftWorkRepository.AutoExtentionEmployees(workshopId);
|
||||
}
|
||||
|
||||
#region Pooya
|
||||
//این متد ترک کار های کارمند را با فعالیت حضور غیاب یکپارچه می کند
|
||||
private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId)
|
||||
|
||||
@@ -738,44 +738,112 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
|
||||
{
|
||||
if (workshopId == 0)
|
||||
return new AutoExtensionDto();
|
||||
|
||||
|
||||
var query = _context.LeftWorkList.Include(x => x.Employee).Include(w=>w.Workshop)
|
||||
var query = _context.LeftWorkList
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Workshop)
|
||||
.Where(x => x.WorkshopId == workshopId)
|
||||
.Join(_context.PersonnelCodeSet.AsSplitQuery().Where(p => p.WorkshopId == workshopId),
|
||||
|
||||
// Left Join با PersonnelCodeSet
|
||||
.GroupJoin(_context.PersonnelCodeSet.Where(p => p.WorkshopId == workshopId),
|
||||
leftList => leftList.EmployeeId,
|
||||
personnelCode => personnelCode.EmployeeId,
|
||||
(leftList, personnelCode) =>
|
||||
new { leftList, personnelCode })
|
||||
.Join(_context.Jobs,
|
||||
left => left.leftList.JobId,
|
||||
(leftList, personnelCodes) => new { leftList, personnelCodes })
|
||||
.SelectMany(
|
||||
x => x.personnelCodes.DefaultIfEmpty(),
|
||||
(x, personnelCode) => new { x.leftList, personnelCode })
|
||||
|
||||
// Left Join با Jobs
|
||||
.GroupJoin(_context.Jobs,
|
||||
x => x.leftList.JobId,
|
||||
job => job.id,
|
||||
(left, job) => new { left, job })
|
||||
.Join(_context.EmployeeComputeOptionsSet.Where(o=>o.WorkshopId == workshopId),
|
||||
leftResult => leftResult.left.leftList.EmployeeId,
|
||||
options => options.EmployeeId,
|
||||
(leftResult, options) => new { leftResult, options })
|
||||
.Select(result => new AutoExtensionEmployeeListDto()
|
||||
(x, jobs) => new { x.leftList, x.personnelCode, jobs })
|
||||
.SelectMany(
|
||||
x => x.jobs.DefaultIfEmpty(),
|
||||
(x, job) => new { x.leftList, x.personnelCode, job })
|
||||
|
||||
// Left Join با EmployeeComputeOptionsSet
|
||||
.GroupJoin(_context.EmployeeComputeOptionsSet.Where(o => o.WorkshopId == workshopId),
|
||||
x => x.leftList.EmployeeId,
|
||||
option => option.EmployeeId,
|
||||
(x, options) => new { x.leftList, x.personnelCode, x.job, options })
|
||||
.SelectMany(
|
||||
x => x.options.DefaultIfEmpty(),
|
||||
(x, option) => new { x.leftList, x.personnelCode, x.job, option })
|
||||
|
||||
.Select(result => new AutoExtensionEmployeeListDto
|
||||
{
|
||||
EmployeeId = result.leftList.EmployeeId,
|
||||
EmployeeName = result.leftList.EmployeeFullName,
|
||||
PersonnelCode = result.personnelCode != null ? result.personnelCode.PersonnelCode : 0,
|
||||
JobType = result.job != null ? result.job.JobName : "نامشخص",
|
||||
JobTypeId = result.job != null ? result.job.id : 0,
|
||||
EmployeeHasCreateContract = result.option != null
|
||||
? result.option.CreateContract
|
||||
: result.leftList.Workshop.CreateContract
|
||||
}).GroupBy(x => x.EmployeeId)
|
||||
.Select(g => g.First())
|
||||
.ToList();
|
||||
|
||||
|
||||
EmployeeId = result.leftResult.left.leftList.EmployeeId,
|
||||
EmployeeName = result.leftResult.left.leftList.EmployeeFullName,
|
||||
PersonnelCode = result.leftResult.left.personnelCode == null ? 0 : result.leftResult.left.personnelCode.PersonnelCode,
|
||||
|
||||
JobType = result.leftResult.job.JobName,
|
||||
JobTypeId = result.leftResult.job.id,
|
||||
EmployeeHasCreateContract = result.options == null ? result.leftResult.left.leftList.Workshop.CreateContract : result.options.CreateContract
|
||||
//var query = _context.LeftWorkList.Include(x => x.Employee).Include(w => w.Workshop)
|
||||
// .Where(x => x.WorkshopId == workshopId)
|
||||
// .Join(_context.PersonnelCodeSet.AsSplitQuery().Where(p => p.WorkshopId == workshopId),
|
||||
// leftList => leftList.EmployeeId,
|
||||
// personnelCode => personnelCode.EmployeeId,
|
||||
// (leftList, personnelCode) =>
|
||||
// new { leftList, personnelCode })
|
||||
// .Join(_context.Jobs,
|
||||
// left => left.leftList.JobId,
|
||||
// job => job.id,
|
||||
// (left, job) => new { left, job })
|
||||
// .Join(_context.EmployeeComputeOptionsSet.Where(o => o.WorkshopId == workshopId),
|
||||
// leftResult => leftResult.left.leftList.EmployeeId,
|
||||
// options => options.EmployeeId,
|
||||
// (leftResult, options) => new { leftResult, options })
|
||||
// .Select(result => new AutoExtensionEmployeeListDto()
|
||||
// {
|
||||
|
||||
|
||||
}).ToList();
|
||||
// EmployeeId = result.leftResult.left.leftList.EmployeeId,
|
||||
// EmployeeName = result.leftResult.left.leftList.EmployeeFullName,
|
||||
// PersonnelCode = result.leftResult.left.personnelCode == null ? 0 : result.leftResult.left.personnelCode.PersonnelCode,
|
||||
|
||||
// JobType = result.leftResult.job.JobName,
|
||||
// JobTypeId = result.leftResult.job.id,
|
||||
// EmployeeHasCreateContract = result.options == null ? result.leftResult.left.leftList.Workshop.CreateContract : result.options.CreateContract
|
||||
|
||||
|
||||
// }).ToList();
|
||||
var result = new AutoExtensionDto();
|
||||
var workshop = _context.Workshops.FirstOrDefault(x => x.id == workshopId);
|
||||
var employerId = _context.WorkshopEmployers.FirstOrDefault(x => x.WorkshopId == workshopId)!.EmployerId;
|
||||
|
||||
if (query.Count > 0 && workshop != null)
|
||||
var employer = _context.Employers.FirstOrDefault(x => x.id == employerId);
|
||||
var employerWarning = false;
|
||||
var employerWarningMessage = "";
|
||||
|
||||
|
||||
if (employer != null && employer.IsLegal == "حقوقی")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(employer.NationalId) || string.IsNullOrWhiteSpace(employer.RegisterId))
|
||||
{
|
||||
employerWarning = true;
|
||||
employerWarningMessage = "شناسه ملی ، شماره ثبت کارفرمای این کارگاه را بررسی کنید";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(employer.Nationalcode) || string.IsNullOrWhiteSpace(employer.Gender))
|
||||
{
|
||||
employerWarning = true;
|
||||
employerWarningMessage = "کد ملی ، جنسیت کارفرمای این کارگاه را بررسی گنید";
|
||||
}
|
||||
}
|
||||
if (query.Any() && workshop != null)
|
||||
{
|
||||
|
||||
var result = new AutoExtensionDto()
|
||||
result = new AutoExtensionDto()
|
||||
{
|
||||
WorkshopId = workshopId,
|
||||
HavingPersonel = true,
|
||||
@@ -783,6 +851,9 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
|
||||
ArchiveCode = workshop.ArchiveCode,
|
||||
WAddress1 = workshop.Address,
|
||||
CreateContract = workshop.CreateContract,
|
||||
EmployerId = employerId,
|
||||
EmployerWarning = employerWarning,
|
||||
EmployerWarningMessage = employerWarningMessage,
|
||||
EmployeeList = query.Select(x => new AutoExtensionEmployeeListDto()
|
||||
{
|
||||
EmployeeId = x.EmployeeId,
|
||||
@@ -800,7 +871,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = new AutoExtensionDto()
|
||||
result = new AutoExtensionDto()
|
||||
{
|
||||
WorkshopId = workshopId,
|
||||
HavingPersonel = false,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using _0_Framework.Application;
|
||||
using Company.Domain.ContractAgg;
|
||||
@@ -82,6 +83,8 @@ public class AutoExtensionModel : PageModel
|
||||
|
||||
public void OnGet(long id)
|
||||
{
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
var selctedWorkshop = _workshopApplication.GetDetails(id);
|
||||
workshopName = selctedWorkshop?.WorkshopFullName;
|
||||
YearlyList =
|
||||
@@ -159,6 +162,12 @@ public class AutoExtensionModel : PageModel
|
||||
WorkshopAddress1 = selctedWorkshop.Address
|
||||
}).OrderBy(x => x.PersonnelCode).ToList();
|
||||
EmployeeSelectList = new SelectList(personelList, "EmployeeId", "EmployeeFullName");
|
||||
|
||||
Console.WriteLine(" old : " + watch.Elapsed);
|
||||
watch.Reset();
|
||||
watch.Start();
|
||||
var res = _leftWorkApplication.AutoExtentionEmployees(id);
|
||||
Console.WriteLine(" new : " + watch.Elapsed);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user