| | |
| | | package com.ruoyi.cwgl.controller; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.cwgl.domain.ReceivableBillCustomerSummary; |
| | | import com.ruoyi.cwgl.domain.vo.ReceivableBillAccountAnalysisVo; |
| | | import com.ruoyi.cwgl.domain.vo.ReceivableBillAgingAnalysisVo; |
| | |
| | | import java.util.Objects; |
| | | import com.ruoyi.cwgl.domain.InvoiceManage; |
| | | import com.ruoyi.cwgl.domain.ReceivableBillManagement; |
| | | import com.ruoyi.cwgl.domain.ReceivableBillManagementLog; |
| | | import com.ruoyi.cwgl.domain.ReceivableInvoiceBusiness; |
| | | import com.ruoyi.cwgl.domain.dto.BillAuditDto; |
| | | import com.ruoyi.cwgl.domain.dto.ReceivableAuditLog; |
| | | import com.ruoyi.cwgl.service.IInvoiceManageService; |
| | | import com.ruoyi.cwgl.service.IReceivableBillManagementLogService; |
| | | import com.ruoyi.cwgl.service.IReceivableBillManagementService; |
| | | import com.ruoyi.cwgl.service.IReceivableInvoiceBusinessService; |
| | | import com.ruoyi.cwgl.service.ITmsAuditLogPushService; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private IReceivableInvoiceBusinessService receivableInvoiceBusinessService; |
| | | |
| | | @Autowired |
| | | private ITmsAuditLogPushService tmsAuditLogPushService; |
| | | |
| | | @Autowired |
| | | private IReceivableBillManagementLogService receivableBillManagementLogService; |
| | | |
| | | |
| | | |
| | |
| | | receivableBillManagementService.accountAnalysisExport(receivableBillManagement,exportKey); |
| | | return AjaxResult.success("导出请求成功,请稍后点击下载...!"); |
| | | } |
| | | |
| | | /** |
| | | * 应收账单审核接口 |
| | | * @param billAuditDto 审核数据传输对象 |
| | | * @return 审核结果 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('cwgl:receivableBillManagement:audit')") |
| | | @Log(title = "应收账单管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/audit") |
| | | public AjaxResult auditReceivableBill(@RequestBody BillAuditDto billAuditDto) { |
| | | try { |
| | | // 1. 查询应收账单 |
| | | ReceivableBillManagement bill = receivableBillManagementService.selectReceivableBillManagementById(billAuditDto.getBillId()); |
| | | if (bill == null) { |
| | | return AjaxResult.error("应收账单不存在,ID:" + billAuditDto.getBillId()); |
| | | } |
| | | |
| | | // 2. 记录审核前状态 |
| | | Integer beforeAuditStatus = bill.getAuditStatus(); |
| | | |
| | | // 3. 更新审核状态 |
| | | bill.setAuditStatus(billAuditDto.getAuditResult()); |
| | | bill.setUpdateTime(new java.util.Date()); |
| | | bill.setUpdateBy(getUsername()); |
| | | |
| | | // 4. 更新账单 |
| | | int rows = receivableBillManagementService.updateReceivableBillManagement(bill); |
| | | if (rows <= 0) { |
| | | return AjaxResult.error("更新应收账单审核状态失败"); |
| | | } |
| | | |
| | | // 5. 记录审核日志 |
| | | saveReceivableAuditLog(billAuditDto, bill, beforeAuditStatus); |
| | | |
| | | // 6. 如果来源系统是TMS,推送审核日志到TMS |
| | | if (tmsAuditLogPushService.isReceivableBillFromTms(bill.getSystemNo())) { |
| | | try { |
| | | ReceivableAuditLog auditLog = createReceivableAuditLog(billAuditDto, bill, beforeAuditStatus); |
| | | tmsAuditLogPushService.pushReceivableAuditLog(auditLog); |
| | | } catch (Exception e) { |
| | | logger.error("推送应收账单审核日志到TMS失败,账单ID:{}", bill.getId(), e); |
| | | // 推送失败不影响主流程,只记录日志 |
| | | } |
| | | } |
| | | |
| | | return AjaxResult.success("应收账单审核成功"); |
| | | |
| | | } catch (Exception e) { |
| | | return AjaxResult.error("应收账单审核失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存应收账单审核日志 |
| | | */ |
| | | private void saveReceivableAuditLog(BillAuditDto billAuditDto, ReceivableBillManagement bill, Integer beforeAuditStatus) { |
| | | try { |
| | | ReceivableBillManagementLog log = new ReceivableBillManagementLog(); |
| | | log.setBillId(bill.getId()); |
| | | log.setSourceSystemId(bill.getSourceSystemId()); // 设置来源系统ID |
| | | log.setCreateBy(getUsername()); |
| | | log.setCreateTime(new Date()); |
| | | |
| | | // 构建操作说明 |
| | | String operation = String.format("应收账单审核 - 账单编号:%s,审核前状态:%s,审核结果:%s,审核意见:%s", |
| | | bill.getSystemNo(), |
| | | getAuditStatusText(beforeAuditStatus), |
| | | getAuditResultText(billAuditDto.getAuditResult()), |
| | | billAuditDto.getAuditComment() != null ? billAuditDto.getAuditComment() : "无"); |
| | | log.setOperation(operation); |
| | | |
| | | // 保存到数据库 |
| | | receivableBillManagementLogService.insertReceivableBillManagementLog(log); |
| | | |
| | | logger.info("应收账单审核日志保存成功 - 账单ID:{},来源系统ID:{}", bill.getId(), bill.getSourceSystemId()); |
| | | |
| | | } catch (Exception e) { |
| | | logger.error("保存应收账单审核日志失败,账单ID:{}", bill.getId(), e); |
| | | // 日志保存失败不影响主流程,只记录错误日志 |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取审核状态文本 |
| | | */ |
| | | private String getAuditStatusText(Integer auditStatus) { |
| | | switch (auditStatus) { |
| | | case 0: return "待审核"; |
| | | case 1: return "审核通过"; |
| | | case 2: return "审核驳回"; |
| | | default: return "未知状态"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取审核结果文本 |
| | | */ |
| | | private String getAuditResultText(Integer auditResult) { |
| | | switch (auditResult) { |
| | | case 1: return "通过"; |
| | | case 2: return "驳回"; |
| | | default: return "未知结果"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建应收账单审核日志对象 |
| | | */ |
| | | private ReceivableAuditLog createReceivableAuditLog(BillAuditDto billAuditDto, ReceivableBillManagement bill, Integer beforeAuditStatus) { |
| | | ReceivableAuditLog auditLog = new ReceivableAuditLog(); |
| | | auditLog.setHeadId(bill.getSourceSystemId()); |
| | | auditLog.setCreateBy(getUsername()); |
| | | auditLog.setCreateTime(new Date()); |
| | | |
| | | String opertion = ""; |
| | | if (billAuditDto.getAuditResult() != null&& billAuditDto.getAuditResult().equals(1)) { |
| | | opertion = "审核通过"; |
| | | if (StringUtils.isNotEmpty(billAuditDto.getAuditComment())){ |
| | | opertion += ",审核意见 :" + billAuditDto.getAuditComment(); |
| | | } |
| | | }else { |
| | | opertion = "审核驳回"; |
| | | if (StringUtils.isNotEmpty(billAuditDto.getAuditComment())){ |
| | | opertion += ",审核意见:" + billAuditDto.getAuditComment(); |
| | | } |
| | | } |
| | | auditLog.setOperation(opertion); |
| | | return auditLog; |
| | | } |
| | | |
| | | } |