OrderSendBackAuditApplication.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Hotline.Orders;
  2. using Hotline.SeedData;
  3. using Hotline.Share.Dtos;
  4. using Hotline.Share.Dtos.Bi;
  5. using Hotline.Share.Dtos.Order;
  6. using Hotline.Share.Enums.Order;
  7. using SqlSugar;
  8. using XF.Domain.Authentications;
  9. using XF.Domain.Dependency;
  10. using XF.Domain.Repository;
  11. namespace Hotline.Application.Orders
  12. {
  13. public class OrderSendBackAuditApplication : IOrderSendBackAuditApplication, IScopeDependency
  14. {
  15. private readonly IRepository<OrderSendBackAudit> _orderSendBackAuditRepository;
  16. private readonly ISessionContext _sessionContext;
  17. public OrderSendBackAuditApplication(IRepository<OrderSendBackAudit> orderSendBackAuditRepository, ISessionContext sessionContext)
  18. {
  19. _orderSendBackAuditRepository = orderSendBackAuditRepository;
  20. _sessionContext = sessionContext;
  21. }
  22. public ISugarQueryable<OrderSendBackAudit> AuditList(SendBackListDto dto)
  23. {
  24. return _orderSendBackAuditRepository.Queryable()
  25. .Includes(x => x.Order)
  26. .WhereIF(!string.IsNullOrEmpty(dto.Keyword),
  27. d => d.Order.Title.Contains(dto.Keyword!) || d.Order.No.Contains(dto.Keyword!))
  28. .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Order.Title.Contains(dto.Title!))
  29. .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.Order.No.Contains(dto.No!))
  30. .WhereIF(!string.IsNullOrEmpty(dto.AcceptTypeCode), d => d.Order.AcceptTypeCode == dto.AcceptTypeCode)
  31. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), d => d.ApplyOrgName == dto.OrgName)
  32. .WhereIF(dto.DataScope is 1, d => d.CreatorId == _sessionContext.RequiredUserId)
  33. .WhereIF(dto.StartTime.HasValue, d => d.CreationTime >= dto.StartTime)
  34. .WhereIF(dto.EndTime.HasValue, d => d.CreationTime <= dto.EndTime)
  35. .WhereIF(dto.AuditState == 1, d => d.State == ESendBackAuditState.Apply)
  36. .WhereIF(dto is { AuditState: 2, State: null }, d => d.State > ESendBackAuditState.Apply)
  37. .WhereIF(dto.AuditState is 2 or 3 && dto.State.HasValue && dto.State != ESendBackAuditState.All, d => d.State == dto.State)
  38. .WhereIF(dto.AuditState == 3 && _sessionContext.RequiredOrgId != OrgSeedData.CenterId, x => x.ApplyOrgId.StartsWith(_sessionContext.OrgId))
  39. .WhereIF(_sessionContext.Roles.Contains("role_sysadmin") == false && dto.AuditState != 3, x => x.SendBackOrgId == _sessionContext.OrgId) // 123 系统管理员;
  40. .WhereIF(dto.ExpiredTimeStart.HasValue, x => x.Order.ExpiredTime >= dto.ExpiredTimeStart)
  41. .WhereIF(dto.ExpiredTimeEnd.HasValue, x => x.Order.ExpiredTime <= dto.ExpiredTimeEnd)
  42. .OrderByDescending(x => x.CreationTime);
  43. }
  44. }
  45. }