OrderSendBackAuditApplication.cs 2.7 KB

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