wujianwei
2025-12-24 2aaa32f860d4f3fbda01eded1b20a7cab9d3a393
service/src/main/java/com/ruoyi/cwgl/service/impl/PayableBillManagementServiceImpl.java
@@ -4,6 +4,11 @@
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
import com.ruoyi.cwgl.mapper.PayableFeeManagementMapper;
import com.ruoyi.cwgl.service.IPayableBillManagementLogService;
import com.ruoyi.cwgl.service.IPayableFeeManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.Async;
@@ -33,7 +38,10 @@
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private PayableBillManagementMapper payableBillManagementMapper;
    @Autowired
    private IPayableBillManagementLogService logService;
    @Resource
    private PayableFeeManagementMapper payableFeeManagementMapper;
    /**
     * 查询应付账单管理
@@ -179,4 +187,41 @@
    {
        return payableBillManagementMapper.deletePayableBillManagementById(id);
    }
    /**
     * 作废应付账单管理记录
     *
     * @param id 应付账单管理ID
     * @return 结果
     */
    @Override
    public int voidPayableBillManagement(Integer id)
    {
        // 查询账单信息
        PayableBillManagement bill = selectPayableBillManagementById(id);
        if (bill == null) {
            throw new RuntimeException("应付账单不存在");
        }
        // 检查账单状态,只有状态为"0"(未结算)的账单可以作废
        if (!"0".equals(bill.getStatus())) {
            throw new RuntimeException("只能作废状态为未结算的应付账单");
        }
        // 更新账单状态为"2"(作废)
        bill.setStatus("2");
        bill.setUpdateTime(DateUtils.getNowDate());
        int result = updatePayableBillManagement(bill);
        if (result > 0) {
            // 作废应付账单后,需要将关联的应付费用记录恢复为待生成账单状态
            String relatedBillNo = bill.getSystemNo();
            if (relatedBillNo != null && !relatedBillNo.isEmpty()) {
                payableFeeManagementMapper.updatePayableFeeManagementByRelatedBillNo(relatedBillNo);
            }
        }
        return result;
    }
}