From 93939937551483578205f1e260f2e390d379fdaa Mon Sep 17 00:00:00 2001 From: SamSys Date: Tue, 20 May 2025 22:15:06 +0330 Subject: [PATCH] Recovery Data Completed --- .../InsurancJobAgg/IInsuranceJobRepositpry.cs | 1 + .../IInsuranceJobItemRepositpry.cs | 3 +- .../InsuranceJob/IInsuranceJobApplication.cs | 1 + .../InsuranceJobApplication.cs | 5 ++ .../InsuranceListApplication.cs | 2 +- .../Repository/InsuranceJobItemRepository.cs | 5 +- .../Repository/InsuranceJobRepository.cs | 63 ++++++++++++++++++- CompanyManagment.EFCore/TestDbContext.cs | 39 ++++++++++++ .../TestDbBootStrapper.cs | 21 +++++++ .../Pages/Company/InsuranceJob/Index.cshtml | 13 +++- .../Company/InsuranceJob/Index.cshtml.cs | 26 +++++--- .../Company/InsuranceJobItem/Index.cshtml.cs | 26 ++++---- ServiceHost/Program.cs | 2 + ServiceHost/appsettings.Development.json | 5 +- 14 files changed, 181 insertions(+), 31 deletions(-) create mode 100644 CompanyManagment.EFCore/TestDbContext.cs create mode 100644 PersonalContractingParty.Config/TestDbBootStrapper.cs diff --git a/Company.Domain/InsurancJobAgg/IInsuranceJobRepositpry.cs b/Company.Domain/InsurancJobAgg/IInsuranceJobRepositpry.cs index 052084b5..27a906a7 100644 --- a/Company.Domain/InsurancJobAgg/IInsuranceJobRepositpry.cs +++ b/Company.Domain/InsurancJobAgg/IInsuranceJobRepositpry.cs @@ -20,6 +20,7 @@ public interface IInsuranceJobRepositpry:IRepository OperationResult CreateInsuranceJob(CreateInsuranceJob command); List<(long id, string date)> GetOldYersInsuranceItemIds(); OperationResult CopyFromLastYear(CopyFromLastYearViewModel command); + OperationResult RecoveryOldData1403(); OperationResult Remove(long id); OperationResult EditInsuranceJob(EditInsuranceJob command); diff --git a/Company.Domain/InsuranceJobItemAgg/IInsuranceJobItemRepositpry.cs b/Company.Domain/InsuranceJobItemAgg/IInsuranceJobItemRepositpry.cs index c1df4b41..5d3df675 100644 --- a/Company.Domain/InsuranceJobItemAgg/IInsuranceJobItemRepositpry.cs +++ b/Company.Domain/InsuranceJobItemAgg/IInsuranceJobItemRepositpry.cs @@ -16,6 +16,7 @@ public interface IInsuranceJobItemRepositpry : IRepository GetInsuranceJobItemByInsuranceJobId(long Id, string year, string month); List Search(InsuranceJobItemSearchModel searchModel); - InsuranceJobItemViewModel GetInsuranceJobItemByInsuranceJobIdForFixedSalary(long insuranceJobId, long jobId); + InsuranceJobItemViewModel GetInsuranceJobItemByInsuranceJobIdForFixedSalary(long insuranceJobId, long jobId, + string year, string month); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceJob/IInsuranceJobApplication.cs b/CompanyManagment.App.Contracts/InsuranceJob/IInsuranceJobApplication.cs index 7d0015ac..5f1132d7 100644 --- a/CompanyManagment.App.Contracts/InsuranceJob/IInsuranceJobApplication.cs +++ b/CompanyManagment.App.Contracts/InsuranceJob/IInsuranceJobApplication.cs @@ -12,6 +12,7 @@ public interface IInsuranceJobApplication { List<(long id, string date)> GetOldYersInsuranceItemIds(); OperationResult CopyFromLastYear(CopyFromLastYearViewModel command); + OperationResult RecoveryOldData1403(); OperationResult Create(CreateInsuranceJob command); OperationResult Edit(EditInsuranceJob command); EditInsuranceJob GetDetails(long id,string year, string month); diff --git a/CompanyManagment.Application/InsuranceJobApplication.cs b/CompanyManagment.Application/InsuranceJobApplication.cs index 99f85b97..b45bc3bd 100644 --- a/CompanyManagment.Application/InsuranceJobApplication.cs +++ b/CompanyManagment.Application/InsuranceJobApplication.cs @@ -29,6 +29,11 @@ public class InsuranceJobApplication: IInsuranceJobApplication return _insuranceJobRepositpry.CopyFromLastYear(command); } + public OperationResult RecoveryOldData1403() + { + return _insuranceJobRepositpry.RecoveryOldData1403(); + } + public OperationResult Create(CreateInsuranceJob command) { var opration = new OperationResult(); diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 63e7186f..50b040e2 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -1718,7 +1718,7 @@ public class InsuranceListApplication: IInsuranceListApplication var searchModel = new InsuranceJobItemSearchModel(); searchModel.InsuranceJobId = (long)insuranceJobId; - var JobItem = _insuranceJobItemRepository.GetInsuranceJobItemByInsuranceJobIdForFixedSalary((long)insuranceJobId, jobId); + var JobItem = _insuranceJobItemRepository.GetInsuranceJobItemByInsuranceJobIdForFixedSalary((long)insuranceJobId, jobId, year, month); if (JobItem != null && JobItem.Id != 0) { diff --git a/CompanyManagment.EFCore/Repository/InsuranceJobItemRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceJobItemRepository.cs index 180b7e01..a0734ec6 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceJobItemRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceJobItemRepository.cs @@ -124,10 +124,11 @@ public class InsuranceJobItemRepository : RepositoryBase } - public InsuranceJobItemViewModel GetInsuranceJobItemByInsuranceJobIdForFixedSalary(long insuranceJobId, long jobId) + public InsuranceJobItemViewModel GetInsuranceJobItemByInsuranceJobIdForFixedSalary(long insuranceJobId, long jobId, string year, string month) { + var searcheDate = ($"{year}/{month}/01").ToGeorgianDateTime(); var insuranceJobItemViewModel = new InsuranceJobItemViewModel(); - var insuranceJobItems = _context.InsuranceJobItems.Where(x => x.InsuranceJobId == insuranceJobId).ToList(); + var insuranceJobItems = _context.InsuranceJobItems.Where(i => i.InsuranceJobId == insuranceJobId && i.StartDate <= searcheDate && i.EndDate >= searcheDate).ToList(); var insuranceJobItemIds = insuranceJobItems.Select(x => x.id).ToList(); var jobAndJob = _context.InsuranceJobAndJobsSet .Where(x => insuranceJobItemIds.Contains(x.InsuranceJobItemId) && x.JobId == jobId).FirstOrDefault(); diff --git a/CompanyManagment.EFCore/Repository/InsuranceJobRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceJobRepository.cs index dadba359..18771f63 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceJobRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceJobRepository.cs @@ -20,13 +20,15 @@ namespace CompanyManagment.EFCore.Repository; public class InsuranceJobRepository : RepositoryBase, IInsuranceJobRepositpry { private readonly CompanyContext _context; + private readonly TestDbContext _testDbContext; private readonly IInsuranceJobItemRepositpry _insuranceJobItemRepositpry; private readonly IPercentageRepository _percentageRepository; - public InsuranceJobRepository(CompanyContext context, IInsuranceJobItemRepositpry insuranceJobItemRepositpry, IPercentageRepository percentageRepository) : base(context) + public InsuranceJobRepository(CompanyContext context, IInsuranceJobItemRepositpry insuranceJobItemRepositpry, IPercentageRepository percentageRepository, TestDbContext testDbContext) : base(context) { _context = context; _insuranceJobItemRepositpry = insuranceJobItemRepositpry; _percentageRepository = percentageRepository; + _testDbContext = testDbContext; } public EditInsuranceJob GetDetails(long id, string year, string month) @@ -274,6 +276,65 @@ public class InsuranceJobRepository : RepositoryBase, IInsur } + public OperationResult RecoveryOldData1403() + { + + OperationResult result = new OperationResult(); + using (var transaction = _context.Database.BeginTransaction()) + { + try + { + var res = _testDbContext.InsuranceJobItems.Include(x => x.InsuranceJobAndJobs).ToList(); + foreach (var item in res) + { + var createItem = new InsuranceJobItem(item.PercentageLessThan, 0, item.PercentageMoreThan, 0, + item.InsuranceJobId, item.StartDate, item.EndDate); + _context.InsuranceJobItems.Add(createItem); + _context.SaveChanges(); + + List insuranceJobAndJobsList = new List(); + foreach (var jobItem in item.InsuranceJobAndJobs) + { + var insuranceJobAndJobsObj = new InsuranceJobAndJobs(); + insuranceJobAndJobsObj.JobId = jobItem.JobId; + insuranceJobAndJobsObj.InsuranceJobItemId = createItem.id; + insuranceJobAndJobsList.Add(insuranceJobAndJobsObj); + } + _context.InsuranceJobAndJobsSet.AddRange(insuranceJobAndJobsList); + _context.SaveChanges(); + + + if (!_percentageRepository.Exists(x => x.Percent == item.PercentageLessThan)) + { + var percentage = new Percentage(item.PercentageLessThan); + _percentageRepository.Create(percentage); + } + + if (!_percentageRepository.Exists(x => x.Percent == item.PercentageMoreThan)) + { + var percentage2 = new Percentage(item.PercentageMoreThan); + _percentageRepository.Create(percentage2); + } + + _percentageRepository.SaveChanges(); + + } + + transaction.Commit(); + result.IsSuccedded = true; + result.Message = "حذف اطلاعات با موفقیت انجام شد"; + } + catch (Exception ex) + { + transaction.Rollback(); + result.Failed("ثبت اطلاعات با خطا مواجه شد"); + } + } + + return result; + + + } public OperationResult Remove(long id) { OperationResult result = new OperationResult(); diff --git a/CompanyManagment.EFCore/TestDbContext.cs b/CompanyManagment.EFCore/TestDbContext.cs new file mode 100644 index 00000000..83a8ff96 --- /dev/null +++ b/CompanyManagment.EFCore/TestDbContext.cs @@ -0,0 +1,39 @@ +using Company.Domain.InsuranceJobItemAgg; +using Company.Domain.InsurancJobAgg; +using Company.Domain.RollCallAgg; +using CompanyManagment.EFCore.Mapping; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CompanyManagment.EFCore +{ + public class TestDbContext : DbContext + { + public DbSet InsuranceJobItems { get; set; } + public DbSet InsuranceJobs { get; set; } + + public TestDbContext(DbContextOptions options) : base(options) + { + + } + + + public TestDbContext() + { + + } + + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + var assembly = typeof(PersonalContractingpartyMapping).Assembly; + modelBuilder.ApplyConfigurationsFromAssembly(assembly); + base.OnModelCreating(modelBuilder); + + } + } +} diff --git a/PersonalContractingParty.Config/TestDbBootStrapper.cs b/PersonalContractingParty.Config/TestDbBootStrapper.cs new file mode 100644 index 00000000..a326df20 --- /dev/null +++ b/PersonalContractingParty.Config/TestDbBootStrapper.cs @@ -0,0 +1,21 @@ +using Company.Domain.InsuranceJobItemAgg; +using Company.Domain.InsurancJobAgg; +using CompanyManagment.App.Contracts.InsuranceJob; +using CompanyManagment.Application; +using CompanyManagment.EFCore; +using CompanyManagment.EFCore.Repository; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace PersonalContractingParty.Config; + +public class TestDbBootStrapper +{ + public static void Configure(IServiceCollection services, string connectionString) + { + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddDbContext(x => x.UseSqlServer(connectionString)); + } +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml b/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml index 7f476910..c7698937 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml @@ -10,11 +10,20 @@ @* ثبت اطلاعات مقطوع *@

-

+

- کپی از اصناف سال قبل + کپی از اصناف سال قبل @* ثبت اطلاعات مقطوع *@

+ +

+ + ریکاوری دیتای سال 1403 + @* ثبت اطلاعات مقطوع *@ +

+ + +
diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml.cs index b8b5001a..c0cb3c25 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceJob/Index.cshtml.cs @@ -82,17 +82,23 @@ public class IndexModel : PageModel return new JsonResult(res); } - //public async Task OnPostJobListByText(string textSearch) - //{ - // var jobs = _jobApplication.GetJobListByText(textSearch); - // return new JsonResult(new - // { - // IsSuccedded = true, - // mylist = jobs, - // }); - //} + public IActionResult OnGetOldDataRecovery1403() + { + var res = _insuranceJobApplication.RecoveryOldData1403(); - public IActionResult OnPostJobListByText(string textSearch) + return new JsonResult(res); + } + //public async Task OnPostJobListByText(string textSearch) + //{ + // var jobs = _jobApplication.GetJobListByText(textSearch); + // return new JsonResult(new + // { + // IsSuccedded = true, + // mylist = jobs, + // }); + //} + + public IActionResult OnPostJobListByText(string textSearch) { var jobs = _jobApplication.GetJobListByText(textSearch); diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceJobItem/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/InsuranceJobItem/Index.cshtml.cs index bb569b99..059cf6f1 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceJobItem/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceJobItem/Index.cshtml.cs @@ -65,20 +65,20 @@ public class IndexModel : PageModel var searchModelPercentage = new PercentageSearchModel(); var percentageList = _percentageApplication.Search(searchModelPercentage); - var percentagIds = dateSalaryItems.Select(x => x.PercentageId).ToList(); - var percentages = percentageList.Where(x => !percentagIds.Contains(x.Id)).ToList(); + //var percentagIds = dateSalaryItems.Select(x => x.PercentageId).ToList(); + //var percentages = percentageList.Where(x => !percentagIds.Contains(x.Id)).ToList(); - foreach (var item in percentages) - { - var obj = new DateSalaryItemViewModel(); - obj.Percent = item.Percent; - obj.PercentageId = item.Id; - obj.Salary = null; - obj.DateSalaryId = id; - obj.Id = 0; - obj.StrSalary = ""; - dateSalaryItems.Add(obj); - } + //foreach (var item in percentages) + //{ + // var obj = new DateSalaryItemViewModel(); + // obj.Percent = item.Percent; + // obj.PercentageId = item.Id; + // obj.Salary = null; + // obj.DateSalaryId = id; + // obj.Id = 0; + // obj.StrSalary = ""; + // dateSalaryItems.Add(obj); + //} var list = new CreateDateSalaryForInsuranceJob(); list.EndDateFa = dateSalary.EndDateFa; diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index 13626482..c93a4c77 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -34,7 +34,9 @@ builder.Services.AddRazorPages() builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpClient("holidayApi", c => c.BaseAddress = new System.Uri("https://api.github.com")); var connectionString = builder.Configuration.GetConnectionString("MesbahDb"); +var connectionStringTestDb = builder.Configuration.GetConnectionString("TestDb"); PersonalBootstrapper.Configure(builder.Services, connectionString); +TestDbBootStrapper.Configure(builder.Services, connectionStringTestDb); AccountManagementBootstrapper.Configure(builder.Services, connectionString); WorkFlowBootstrapper.Configure(builder.Services, connectionString); QueryBootstrapper.Configure(builder.Services); diff --git a/ServiceHost/appsettings.Development.json b/ServiceHost/appsettings.Development.json index 3e31959e..b86caf6b 100644 --- a/ServiceHost/appsettings.Development.json +++ b/ServiceHost/appsettings.Development.json @@ -15,11 +15,14 @@ //"MesbahDb": "Data Source=171.22.24.15;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]is[3019]#@ATt;TrustServerCertificate=true;" //local - "MesbahDb": "Data Source=.;Initial Catalog=mesbah_db;Integrated Security=True;TrustServerCertificate=true;" + "MesbahDb": "Data Source=.;Initial Catalog=mesbah_db;Integrated Security=True;TrustServerCertificate=true;", + + "TestDb": "Data Source=.;Initial Catalog=TestDb;Integrated Security=True;TrustServerCertificate=true;" //mahan Docker //"MesbahDb": "Data Source=localhost,5069;Initial Catalog=mesbah_db;User ID=sa;Password=YourPassword123;TrustServerCertificate=True;" }, + "GoogleRecaptchaV3": { "SiteKey": "6Lfhp_AnAAAAAB79WkrMoHd1k8ir4m8VvfjE7FTH", "SecretKey": "6Lfhp_AnAAAAANjDDY6DPrbbUQS7k6ZCRmrVP5Lb"