| | |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | .likeIfPresent(ErpFinancePaymentDO::getAccountName, reqVO.getAccountName()) |
| | | .eqIfPresent(ErpFinancePaymentDO::getStatus, reqVO.getStatus()) |
| | | .likeIfPresent(ErpFinancePaymentDO::getRemark, reqVO.getRemark()) |
| | | .eqIfPresent(ErpFinancePaymentDO::getSourceType, reqVO.getSourceType()) |
| | | .likeIfPresent(ErpFinancePaymentDO::getSourceNo, reqVO.getSourceNo()) |
| | | .orderByDesc(ErpFinancePaymentDO::getId); |
| | | if (reqVO.getBizNo() != null) { |
| | | query.leftJoin(ErpFinancePaymentItemDO.class, ErpFinancePaymentItemDO::getPaymentId, ErpFinancePaymentDO::getId) |
| | |
| | | * @return key 为来票编号,value 为已付款金额 |
| | | */ |
| | | default Map<Long, BigDecimal> selectPaymentPriceMapByInvoiceId(Collection<Long> invoiceIds) { |
| | | return selectPaymentPriceMapByInvoiceIdAndStatus(invoiceIds, List.of( |
| | | ErpAuditStatus.PROCESS.getStatus(), ErpAuditStatus.APPROVING.getStatus(), |
| | | ErpAuditStatus.APPROVE.getStatus())); |
| | | } |
| | | |
| | | default Map<Long, BigDecimal> selectPaymentPriceMapByInvoiceIdAndStatus( |
| | | Collection<Long> invoiceIds, Collection<Integer> statuses) { |
| | | if (CollUtil.isEmpty(invoiceIds)) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | // SQL sum 查询 |
| | | List<Map<String, Object>> result = selectMaps(new QueryWrapper<ErpFinancePaymentDO>() |
| | | .select("invoice_id, SUM(payment_price) AS total_payment_price") |
| | | .in("status", ErpAuditStatus.PROCESS.getStatus(), // 未审核 + 审批中 + 已审核 |
| | | ErpAuditStatus.APPROVING.getStatus(), ErpAuditStatus.APPROVE.getStatus()) |
| | | .in("status", statuses) |
| | | .groupBy("invoice_id") |
| | | .in("invoice_id", invoiceIds)); |
| | | // 获得金额 |
| | | return convertMap(result, obj -> (Long) obj.get("invoice_id"), obj -> (BigDecimal) obj.get("total_payment_price")); |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * 按供应商与付款时间范围查询付款单(供应商往来) |
| | | */ |
| | | default List<ErpFinancePaymentDO> selectListBySupplierIdAndPaymentTimeBetween(Long supplierId, |
| | | LocalDateTime beginTime, |
| | | LocalDateTime endTime, |
| | | Collection<Integer> statuses) { |
| | | return selectList(new LambdaQueryWrapperX<ErpFinancePaymentDO>() |
| | | .eq(ErpFinancePaymentDO::getSupplierId, supplierId) |
| | | .geIfPresent(ErpFinancePaymentDO::getPaymentTime, beginTime) |
| | | .leIfPresent(ErpFinancePaymentDO::getPaymentTime, endTime) |
| | | .inIfPresent(ErpFinancePaymentDO::getStatus, statuses) |
| | | .orderByAsc(ErpFinancePaymentDO::getPaymentTime) |
| | | .orderByAsc(ErpFinancePaymentDO::getId)); |
| | | } |
| | | |
| | | /** |
| | | * 按付款时间范围查询全部供应商的付款单(供应商往来汇总) |
| | | */ |
| | | default List<ErpFinancePaymentDO> selectListByPaymentTimeBetween(LocalDateTime beginTime, |
| | | LocalDateTime endTime, |
| | | Collection<Integer> statuses) { |
| | | return selectList(new LambdaQueryWrapperX<ErpFinancePaymentDO>() |
| | | .geIfPresent(ErpFinancePaymentDO::getPaymentTime, beginTime) |
| | | .leIfPresent(ErpFinancePaymentDO::getPaymentTime, endTime) |
| | | .inIfPresent(ErpFinancePaymentDO::getStatus, statuses)); |
| | | } |
| | | |
| | | } |