package com.ruoyi.cwgl.controller; import java.util.List; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.utils.file.DownloadExportUtil; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import java.math.BigDecimal; import java.util.List; import java.util.Objects; import com.ruoyi.cwgl.domain.InvoiceManage; import com.ruoyi.cwgl.domain.ReceivableBillManagement; import com.ruoyi.cwgl.domain.ReceivableInvoiceBusiness; import com.ruoyi.cwgl.service.IInvoiceManageService; import com.ruoyi.cwgl.service.IReceivableBillManagementService; import com.ruoyi.cwgl.service.IReceivableInvoiceBusinessService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; /** * 应收账单管理Controller * * @author ruoyi * @date 2025-12-17 */ @RestController @RequestMapping("/cwgl/receivableBillManagement") public class ReceivableBillManagementController extends BaseController { @Autowired private IReceivableBillManagementService receivableBillManagementService; @Autowired private IInvoiceManageService invoiceManageService; @Autowired private IReceivableInvoiceBusinessService receivableInvoiceBusinessService; /** * 查询应收账单管理列表 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:list')") @GetMapping("/list") public TableDataInfo list(ReceivableBillManagement receivableBillManagement) { startPage(); List list = receivableBillManagementService.selectReceivableBillManagementList(receivableBillManagement); return getDataTable(list); } /** * 导出应收账单管理列表 * @param receivableBillManagement 查询条件对象 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:export')") @Log(title = "应收账单管理", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(ReceivableBillManagement receivableBillManagement,String exportKey) { receivableBillManagementService.export(receivableBillManagement,exportKey); return AjaxResult.success("导出请求成功,请稍后点击下载...!"); } /** * 获取应收账单管理详细信息 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Integer id) { return AjaxResult.success(receivableBillManagementService.selectReceivableBillManagementById(id)); } /** * 新增应收账单管理 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:add')") @Log(title = "应收账单管理", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody ReceivableBillManagement receivableBillManagement) { return toAjax(receivableBillManagementService.insertReceivableBillManagement(receivableBillManagement)); } /** * 修改应收账单管理 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:edit')") @Log(title = "应收账单管理", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody ReceivableBillManagement receivableBillManagement) { return toAjax(receivableBillManagementService.updateReceivableBillManagement(receivableBillManagement)); } /** * 删除应收账单管理 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:remove')") @Log(title = "应收账单管理", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Integer[] ids) { return toAjax(receivableBillManagementService.deleteReceivableBillManagementByIds(ids)); } /** * 作废应收账单管理记录 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:void')") @Log(title = "应收账单管理", businessType = BusinessType.UPDATE) @PutMapping("/void/{id}") public AjaxResult voidReceivableBill(@PathVariable("id") Integer id) { return toAjax(receivableBillManagementService.voidReceivableBillManagement(id)); } /** * 应收账单申请开票 * @param invoiceManage 发票管理对象 * @param id 应收账单ID * @return 结果 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:invoice')") @Log(title = "应收账单管理", businessType = BusinessType.OTHER) @PostMapping("/invoice/{id}") public AjaxResult applyReceivableInvoice(@RequestBody InvoiceManage invoiceManage, @PathVariable("id") Integer id) { return invoiceManageService.applyReceivableInvoice(invoiceManage, id); } /** * 查询应收账单已开票金额 * @param id 应收账单ID * @return 已开票金额 */ @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:query')") @GetMapping("/invoice/amount/{id}") public AjaxResult getReceivableInvoicedAmount(@PathVariable("id") Integer id) { // 查询receivable_invoice_business表中status为1的记录 ReceivableInvoiceBusiness query = new ReceivableInvoiceBusiness(); query.setHeadId(id); query.setStatus(1); List invoices = receivableInvoiceBusinessService.selectReceivableInvoiceBusinessList(query); // 计算已开票金额 BigDecimal invoicedAmount = invoices.stream() .map(ReceivableInvoiceBusiness::getInvoicingAmount) .filter(Objects::nonNull) .reduce(BigDecimal.ZERO, BigDecimal::add); return AjaxResult.success(invoicedAmount); } }