fix: hoist nullable filters so SqlSugar can translate warehouse rent bill list
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
52df7307f6
commit
ae0444b226
@ -50,9 +50,10 @@ public class WarehouseRentService : ApplicationService
|
|||||||
var keyword = input.Keyword?.Trim();
|
var keyword = input.Keyword?.Trim();
|
||||||
var hasKeyword = !string.IsNullOrWhiteSpace(keyword);
|
var hasKeyword = !string.IsNullOrWhiteSpace(keyword);
|
||||||
var hasStatus = input.Status.HasValue && input.Status.Value != EnableStatus.None;
|
var hasStatus = input.Status.HasValue && input.Status.Value != EnableStatus.None;
|
||||||
|
var statusValue = input.Status.GetValueOrDefault();
|
||||||
Expression<Func<CWarehouseRentRate, bool>> predicate = x =>
|
Expression<Func<CWarehouseRentRate, bool>> predicate = x =>
|
||||||
(!hasKeyword || x.RateName.Contains(keyword!))
|
(!hasKeyword || x.RateName.Contains(keyword!))
|
||||||
&& (!hasStatus || x.Status == input.Status!.Value);
|
&& (!hasStatus || x.Status == statusValue);
|
||||||
|
|
||||||
var pageIndex = OmsDocHelper.NormalizePage(input.PageIndex);
|
var pageIndex = OmsDocHelper.NormalizePage(input.PageIndex);
|
||||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||||
@ -176,15 +177,22 @@ public class WarehouseRentService : ApplicationService
|
|||||||
var hasKeyword = !string.IsNullOrWhiteSpace(keyword);
|
var hasKeyword = !string.IsNullOrWhiteSpace(keyword);
|
||||||
var status = input.Status?.Trim();
|
var status = input.Status?.Trim();
|
||||||
var hasStatus = !string.IsNullOrWhiteSpace(status);
|
var hasStatus = !string.IsNullOrWhiteSpace(status);
|
||||||
var from = input.BillDateFrom?.Date;
|
var hasCustomer = input.CustomerId is > 0;
|
||||||
var to = input.BillDateTo?.Date;
|
var customerId = input.CustomerId.GetValueOrDefault();
|
||||||
|
var hasWarehouse = input.WarehouseId is > 0;
|
||||||
|
var warehouseId = input.WarehouseId.GetValueOrDefault();
|
||||||
|
var hasFrom = input.BillDateFrom.HasValue;
|
||||||
|
var from = input.BillDateFrom.GetValueOrDefault().Date;
|
||||||
|
var hasTo = input.BillDateTo.HasValue;
|
||||||
|
var to = input.BillDateTo.GetValueOrDefault().Date;
|
||||||
|
|
||||||
|
// SqlSugar 不能翻译 input.Xxx.HasValue / .Value,必须先拆成局部变量
|
||||||
Expression<Func<CWarehouseRentBill, bool>> predicate = x =>
|
Expression<Func<CWarehouseRentBill, bool>> predicate = x =>
|
||||||
(!input.CustomerId.HasValue || x.CustomerId == input.CustomerId.Value)
|
(!hasCustomer || x.CustomerId == customerId)
|
||||||
&& (!input.WarehouseId.HasValue || x.WarehouseId == input.WarehouseId.Value)
|
&& (!hasWarehouse || x.WarehouseId == warehouseId)
|
||||||
&& (!hasStatus || x.Status == status)
|
&& (!hasStatus || x.Status == status)
|
||||||
&& (!from.HasValue || x.BillDate >= from.Value)
|
&& (!hasFrom || x.BillDate >= from)
|
||||||
&& (!to.HasValue || x.BillDate <= to.Value)
|
&& (!hasTo || x.BillDate <= to)
|
||||||
&& (!hasKeyword || x.BillNo.Contains(keyword!));
|
&& (!hasKeyword || x.BillNo.Contains(keyword!));
|
||||||
|
|
||||||
var pageIndex = OmsDocHelper.NormalizePage(input.PageIndex);
|
var pageIndex = OmsDocHelper.NormalizePage(input.PageIndex);
|
||||||
@ -512,8 +520,10 @@ public class WarehouseRentService : ApplicationService
|
|||||||
|
|
||||||
private async Task EnsureRateNameUniqueAsync(string rateName, int? excludeId)
|
private async Task EnsureRateNameUniqueAsync(string rateName, int? excludeId)
|
||||||
{
|
{
|
||||||
|
var hasExclude = excludeId is > 0;
|
||||||
|
var exclude = excludeId.GetValueOrDefault();
|
||||||
var exists = await RateRepository.FirstOrDefaultAsync(x =>
|
var exists = await RateRepository.FirstOrDefaultAsync(x =>
|
||||||
x.RateName == rateName && (!excludeId.HasValue || x.Id != excludeId.Value));
|
x.RateName == rateName && (!hasExclude || x.Id != exclude));
|
||||||
if (exists != null)
|
if (exists != null)
|
||||||
{
|
{
|
||||||
throw new BusinessException("费率名称已存在");
|
throw new BusinessException("费率名称已存在");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user