* Added required methods to services

This commit is contained in:
2025-04-03 09:27:32 +02:00
parent 94c4586c35
commit d7f49829a2
7 changed files with 41 additions and 27 deletions

View File

@@ -11,6 +11,11 @@ namespace FaKrosnoEfDataModel.Queries
.Include(x => x.ScheduleOrderDetails).ThenInclude(x => x.ScheduleOrderDetailDetails) .Include(x => x.ScheduleOrderDetails).ThenInclude(x => x.ScheduleOrderDetailDetails)
.ThenInclude(x => x.ScheduleOrderDetailDetailMiscs).Include(x => x.ScheduleOrderMiscs)); .ThenInclude(x => x.ScheduleOrderDetailDetailMiscs).Include(x => x.ScheduleOrderMiscs));
public static readonly Func<FaKrosnoDbContext, int, IEnumerable<ScheduleOrder?>> GetEntitiesByPurchaser =
EF.CompileQuery((FaKrosnoDbContext context, int purchaser) => context.ScheduleOrders
.Include(x => x.Recipient).ThenInclude(x => x.Purchaser).Include(x => x.ScheduleOrderDetails)
.ThenInclude(x => x.ScheduleOrderDetailMiscs).Where(x => x.Recipient.Purchaser.ID == purchaser));
public static readonly Func<FaKrosnoDbContext, DateTime, IEnumerable<ScheduleOrder?>> GetEntitiesByDate = public static readonly Func<FaKrosnoDbContext, DateTime, IEnumerable<ScheduleOrder?>> GetEntitiesByDate =
EF.CompileQuery((FaKrosnoDbContext context, DateTime fromDate) => context.ScheduleOrders EF.CompileQuery((FaKrosnoDbContext context, DateTime fromDate) => context.ScheduleOrders
.Include(x => x.Recipient).ThenInclude(x => x.Purchaser).Include(x => x.ScheduleOrderDetails) .Include(x => x.Recipient).ThenInclude(x => x.Purchaser).Include(x => x.ScheduleOrderDetails)

View File

@@ -11,7 +11,7 @@ namespace FaKrosnoEfDataModel.Services
{ {
Task<IEnumerable<ScheduleOrderDetailDto>?> GetScheduleOrderDetailsAsync(int scheduleOrderId); Task<IEnumerable<ScheduleOrderDetailDto>?> GetScheduleOrderDetailsAsync(int scheduleOrderId);
Task<IEnumerable<ScheduleOrderDetailMiscDto>?> GetScheduleOrderDetailMiscsAsync( Task<IEnumerable<ScheduleOrderDetailDetailDto>> GetScheduleOrderDetailsDetailsByIdAsync(
IList<int> scheduleOrderDetailIds, string miscName); int scheduleOrderDetailId);
} }
} }

View File

@@ -12,7 +12,7 @@ namespace FaKrosnoEfDataModel.Services
Task<IEnumerable<ScheduleOrderDto?>> GetEntities(); Task<IEnumerable<ScheduleOrderDto?>> GetEntities();
Task<ScheduleOrderDto?> GetById(int id); Task<ScheduleOrderDto?> GetById(int id);
Task<IEnumerable<ScheduleOrderDto?>> GetByRecipientId(int recipientId); Task<IEnumerable<ScheduleOrderDto?>> GetByRecipientId(int recipientId);
Task<IList<ScheduleOrderDto>> GetByPurchaserId(int purchaserId); Task<IEnumerable<ScheduleOrderDto>> GetByPurchaserId(int purchaserId);
Task<IEnumerable<ScheduleOrderDto?>> GetEntitiesByLastUpdateDate(DateTime date); Task<IEnumerable<ScheduleOrderDto?>> GetEntitiesByLastUpdateDate(DateTime date);
Task<IEnumerable<ScheduleOrderDto?>> GetByRecipientAndLastUpdateDate(int recipientId, DateTime date); Task<IEnumerable<ScheduleOrderDto?>> GetByRecipientAndLastUpdateDate(int recipientId, DateTime date);
} }

View File

@@ -1,9 +1,4 @@
using System; using AutoMapper;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions; using AutoMapper.QueryableExtensions;
using FaKrosnoEfDataModel.Dtos; using FaKrosnoEfDataModel.Dtos;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -22,10 +17,10 @@ namespace FaKrosnoEfDataModel.Services
.ProjectTo<ScheduleOrderDetailDto>(Mapper.ConfigurationProvider).ToListAsync(); .ProjectTo<ScheduleOrderDetailDto>(Mapper.ConfigurationProvider).ToListAsync();
} }
public async Task<IEnumerable<ScheduleOrderDetailMiscDto>?> GetScheduleOrderDetailMiscsAsync(IList<int> scheduleOrderDetailIds, string miscName) public async Task<IEnumerable<ScheduleOrderDetailDetailDto>> GetScheduleOrderDetailsDetailsByIdAsync(int scheduleOrderDetailId)
{ {
return await Context.ScheduleOrderDetailMiscs.Where(x => x.ID == scheduleOrderDetailIds.First()) return await Context.ScheduleOrderDetailDetails.Where(x => x.ScheduleOrderDetailID == scheduleOrderDetailId)
.ProjectTo<ScheduleOrderDetailMiscDto>(Mapper.ConfigurationProvider).ToListAsync(); .ProjectTo<ScheduleOrderDetailDetailDto>(Mapper.ConfigurationProvider).ToListAsync();
} }
} }
} }

View File

@@ -26,13 +26,12 @@ namespace FaKrosnoEfDataModel.Services
return scheduleOrders.Where(x => x?.RecipientID == recipientId); return scheduleOrders.Where(x => x?.RecipientID == recipientId);
} }
public async Task<IList<ScheduleOrderDto>> GetByPurchaserId(int purchaserId) public async Task<IEnumerable<ScheduleOrderDto>> GetByPurchaserId(int purchaserId)
{ {
return await Context.ScheduleOrders.Include(x => x.Recipient).ThenInclude(x => x.Purchaser) IEnumerable<ScheduleOrder?> scheduleOrders =
.Include(x => x.ScheduleOrderDetails).ThenInclude(x => x.ScheduleOrderDetailMiscs) (await Task.FromResult(ScheduleOrderQueries.GetEntitiesByPurchaser(Context, purchaserId))).ToList();
.Include(x => x.ScheduleOrderDetails).ThenInclude(x => x.ScheduleOrderDetailDetails)
.Where(x => x.Recipient.Purchaser.ID == purchaserId).Select(x => Mapper.Map<ScheduleOrderDto>(x)) return scheduleOrders.Select(x => Mapper.Map<ScheduleOrderDto>(x));
.ToListAsync();
} }
public async Task<IEnumerable<ScheduleOrderDto?>> GetByRecipientAndLastUpdateDate(int recipientId, DateTime date) public async Task<IEnumerable<ScheduleOrderDto?>> GetByRecipientAndLastUpdateDate(int recipientId, DateTime date)

View File

@@ -6,6 +6,6 @@ public interface IMaterialTransactionService
{ {
Task<IEnumerable<MaterialTransactionDto>> GetAll(); Task<IEnumerable<MaterialTransactionDto>> GetAll();
Task<MaterialTransactionDto?> GetByWzNumber(string wzNumber); Task<MaterialTransactionDto?> GetByWzNumber(string wzNumber);
Task<IEnumerable<MaterialTransactionDto?>> GetByWzNumbers(ISet<string> wzNumbers); Task<IEnumerable<MaterialTransactionDto>> GetByWzNumbers(ISet<string> wzNumbers);
Task<IEnumerable<MaterialTransactionDto?>> GetByOrderNumber(string orderNumber); Task<IEnumerable<MaterialTransactionDto>> GetByOrderNumber(string orderNumber);
} }

View File

@@ -1,6 +1,7 @@
using AutoMapper; using AutoMapper;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SytelineSaAppEfDataModel.Dtos; using SytelineSaAppEfDataModel.Dtos;
using SytelineSaAppEfDataModel.Entities;
namespace SytelineSaAppEfDataModel.Services; namespace SytelineSaAppEfDataModel.Services;
@@ -18,16 +19,30 @@ public class MaterialTransactionService(SytelineSaAppDbContext context, IMapper
.Select(x => mapper.Map<MaterialTransactionDto>(x)).FirstOrDefaultAsync(); .Select(x => mapper.Map<MaterialTransactionDto>(x)).FirstOrDefaultAsync();
} }
public async Task<IEnumerable<MaterialTransactionDto?>> GetByWzNumbers(ISet<string> wzNumbers) public async Task<IEnumerable<MaterialTransactionDto>> GetByWzNumbers(ISet<string> wzNumbers)
{ {
return await context.MaterialTransactions if (!wzNumbers.Any())
.Where(x => !string.IsNullOrWhiteSpace(x.MTGroupNum) && wzNumbers.Contains(x.MTGroupNum)) return Enumerable.Empty<MaterialTransactionDto>();
.Select(x => mapper.Map<MaterialTransactionDto>(x)).ToListAsync();
var wzNumbersList = string.Join(",", wzNumbers.Select(w => $"'{w}'"));
var sql = $@"
SELECT z.*
FROM ZPL_InternalNum_Matltran z
WHERE z.MTGroupNum <> ''
AND z.MTGroupNum IN ({wzNumbersList})";
IList<MaterialTransaction> result = await context.MaterialTransactions
.FromSqlRaw(sql)
.AsNoTracking()
.ToListAsync();
return result.Select(mapper.Map<MaterialTransactionDto>);
} }
public async Task<IEnumerable<MaterialTransactionDto?>> GetByOrderNumber(string orderNumber) public async Task<IEnumerable<MaterialTransactionDto>> GetByOrderNumber(string orderNumber)
{ {
return await context.MaterialTransactions.Where(x => x.RefNum == orderNumber) return await context.MaterialTransactions.Where(x => x.RefNum == orderNumber).OrderByDescending(x => x.TransDate)
.Select(x => mapper.Map<MaterialTransactionDto>(x)).ToListAsync(); .Select(x => mapper.Map<MaterialTransactionDto>(x)).ToListAsync();
} }
} }