| | |
| | | package cn.iocoder.yudao.module.erp.dal.mysql.finance; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.payment.ErpFinancePaymentPageReqVO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.finance.ErpFinancePaymentDO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.finance.ErpFinancePaymentItemDO; |
| | | import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | 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; |
| | | import java.util.Map; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | | |
| | | /** |
| | | * ERP 付款单 Mapper |
| | |
| | | return selectOne(ErpFinancePaymentDO::getNo, no); |
| | | } |
| | | |
| | | default List<ErpFinancePaymentDO> selectListByInvoiceIdAndStatus(Long invoiceId, Collection<Integer> statuses) { |
| | | return selectList(new LambdaQueryWrapperX<ErpFinancePaymentDO>() |
| | | .eq(ErpFinancePaymentDO::getInvoiceId, invoiceId) |
| | | .in(ErpFinancePaymentDO::getStatus, statuses)); |
| | | } |
| | | |
| | | /** |
| | | * 统计每张来票已付款金额(未审核 + 审批中 + 已审核,排除作废),用于校验剩余可付金额 |
| | | * |
| | | * @param invoiceIds 来票编号列表 |
| | | * @return key 为来票编号,value 为已付款金额 |
| | | */ |
| | | default Map<Long, BigDecimal> selectPaymentPriceMapByInvoiceId(Collection<Long> invoiceIds) { |
| | | 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()) |
| | | .groupBy("invoice_id") |
| | | .in("invoice_id", invoiceIds)); |
| | | // 获得金额 |
| | | return convertMap(result, obj -> (Long) obj.get("invoice_id"), obj -> (BigDecimal) obj.get("total_payment_price")); |
| | | } |
| | | |
| | | /** |
| | | * 提交审批:置为审批中,并清空上一轮审核结果 |
| | | * |
| | | * 用 UpdateWrapper 而非 updateById:MyBatis-Plus 默认更新策略忽略 null, |
| | | * 直接 updateById 无法把审核不通过后残留的审核人/审核时间/审核意见清空。 |
| | | */ |
| | | default int submitAndResetAuditInfo(Long id, Integer status) { |
| | | return update(null, new LambdaUpdateWrapper<ErpFinancePaymentDO>() |
| | | .eq(ErpFinancePaymentDO::getId, id) |
| | | .set(ErpFinancePaymentDO::getStatus, status) |
| | | .set(ErpFinancePaymentDO::getReviewerId, null) |
| | | .set(ErpFinancePaymentDO::getReviewerName, null) |
| | | .set(ErpFinancePaymentDO::getReviewTime, null) |
| | | .set(ErpFinancePaymentDO::getReviewRemark, null)); |
| | | } |
| | | |
| | | /** |
| | | * 审核(通过 / 不通过):写入审核结果、审核人与审核意见 |
| | | */ |
| | | default int auditFinancePayment(Long id, Integer status, Long reviewerId, |
| | | String reviewerName, String reviewRemark) { |
| | | return update(null, new LambdaUpdateWrapper<ErpFinancePaymentDO>() |
| | | .eq(ErpFinancePaymentDO::getId, id) |
| | | .set(ErpFinancePaymentDO::getStatus, status) |
| | | .set(ErpFinancePaymentDO::getReviewerId, reviewerId) |
| | | .set(ErpFinancePaymentDO::getReviewerName, reviewerName) |
| | | .set(ErpFinancePaymentDO::getReviewTime, LocalDateTime.now()) |
| | | .set(ErpFinancePaymentDO::getReviewRemark, reviewRemark)); |
| | | } |
| | | |
| | | } |