From acfe8943be0bb1440e0e6ba27ad9e694859e835e Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期一, 12 一月 2026 14:45:20 +0800
Subject: [PATCH] 修改发票新增
---
service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java | 231 ++++++++++-----------------------------------------------
1 files changed, 42 insertions(+), 189 deletions(-)
diff --git a/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java b/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java
index 4df87cb..67e9d76 100644
--- a/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java
+++ b/service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java
@@ -17,13 +17,13 @@
import com.ruoyi.common.utils.file.DownloadExportUtil;
import com.ruoyi.common.utils.file.DownloadExportUtil.ExprotStatus;
import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.cwgl.domain.ReceivableFeeDetail;
-import com.ruoyi.cwgl.domain.ReceivableFeeManagementLog;
+import com.ruoyi.cwgl.domain.*;
import com.ruoyi.cwgl.domain.vo.ReceivableFeeStatisticsVo;
import com.ruoyi.cwgl.service.*;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISystemDataNoService;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
@@ -40,9 +40,6 @@
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.cwgl.mapper.ReceivableFeeManagementMapper;
-import com.ruoyi.cwgl.domain.ReceivableFeeManagement;
-import com.ruoyi.cwgl.domain.ReceivableBillManagement;
-import com.ruoyi.cwgl.domain.ReceivableBillSettlementDetail;
import com.ruoyi.cwgl.domain.vo.ReceivableBillCreateVo;
import com.ruoyi.common.core.text.Convert;
@@ -83,6 +80,9 @@
@Autowired
private RedisCache redisCache;
+
+ @Autowired
+ private ITmsCustomerInfoService tmsCustomerInfoService;
/**
* 鏌ヨ搴旀敹璐圭敤绠$悊
@@ -611,10 +611,30 @@
receivableFee.setCreateTime(now);
receivableFee.setCreateBy(operName);
+ // 鏍规嵁瀹㈡埛鍚嶇О鏌ヨ瀹㈡埛ID
+ if (receivableFee.getCustomerName() != null && !receivableFee.getCustomerName().isEmpty()) {
+ TmsCustomerInfo customerQuery = new TmsCustomerInfo();
+ customerQuery.setCustomerFullName(receivableFee.getCustomerName());
+ List<TmsCustomerInfo> customerList = tmsCustomerInfoService.selectTmsCustomerInfoList(customerQuery);
+ if (customerList != null && !customerList.isEmpty()) {
+ // 鍙栫涓�涓尮閰嶇殑瀹㈡埛
+ TmsCustomerInfo customer = customerList.get(0);
+ receivableFee.setCustomerId(customer.getId());
+ } else {
+ // 濡傛灉娌℃湁鎵惧埌鍖归厤鐨勫鎴凤紝鍙互璁板綍鏃ュ織鎴栨姏鍑哄紓甯�
+ logger.warn("鏈壘鍒板鎴峰悕绉颁负 '{}' 鐨勫鎴蜂俊鎭紝customerId灏嗚缃负null", receivableFee.getCustomerName());
+ }
+ }
+
// 璁$畻搴旀敹閲戦瀛楃涓叉弿杩�
if (receivableFee.getReceivableFeeDetailList() != null && !receivableFee.getReceivableFeeDetailList().isEmpty()) {
String receivableAmountStr = calculateReceivableAmountStr(receivableFee.getReceivableFeeDetailList());
receivableFee.setReceivableAmountStr(receivableAmountStr);
+ }
+
+ // 璁剧疆榛樿鐘舵�佷负寰呯敓鎴愯处鍗曪紙0锛�
+ if (receivableFee.getStatus() == null || receivableFee.getStatus().isEmpty()) {
+ receivableFee.setStatus("0");
}
// 鎻掑叆涓昏〃鏁版嵁
@@ -664,8 +684,20 @@
DownloadExportUtil.deleteDownloadFile(redisCache, exportKey, ExprotStatus.XZZ.getStatus());
try {
- // 鍒涘缓澶歋heet瀵煎叆妯℃澘
- createMultiSheetImportTemplate(exportKey,fileName);
+ // 鍒涘缓绌哄垪琛ㄧ敤浜庣敓鎴愭ā鏉匡紙鍙渶瑕佽〃澶达級
+ List<ReceivableFeeManagement> mainList = new ArrayList<>();
+ List<ReceivableFeeDetail> detailList = new ArrayList<>();
+
+ // 浣跨敤鎴戜滑鏂板疄鐜扮殑exportMultiSheetData鏂规硶鍒涘缓鍙宻heet妯℃澘
+ exportMultiSheetData(
+ ReceivableFeeManagement.class,
+ ReceivableFeeDetail.class,
+ fileName,
+ "搴旀敹璐圭敤涓昏〃",
+ "搴旀敹璐圭敤鏄庣粏",
+ mainList,
+ detailList
+ );
// 璁剧疆涓嬭浇瀹屾垚鐘舵��
DownloadExportUtil.setDownloadFile(redisCache, exportKey, fileName);
@@ -676,192 +708,13 @@
throw e;
}
}
-
- /**
- * 鍒涘缓澶歋heet瀵煎叆妯℃澘
- * 鍖呭惈Sheet1锛氬簲鏀惰垂鐢ㄤ富琛ㄦā鏉�
- * 鍖呭惈Sheet2锛氬簲鏀惰垂鐢ㄦ槑缁嗚〃妯℃澘
- *
- * @param exportKey 瀵煎嚭鍔熻兘鐨勫敮涓�鏍囪瘑
- * @param fileName
- */
- private void createMultiSheetImportTemplate(String exportKey, String fileName) {
-
- try {
- // 鍒涘缓鏂扮殑宸ヤ綔绨匡紝鍖呭惈涓や釜Sheet
- SXSSFWorkbook workbook = new SXSSFWorkbook(1000);
-
- // 鍒涘缓涓昏〃Sheet
- Sheet mainSheet = workbook.createSheet("搴旀敹璐圭敤涓昏〃");
- createMainSheetTemplateWithExcelUtil(mainSheet);
-
- // 鍒涘缓鏄庣粏琛⊿heet
- Sheet detailSheet = workbook.createSheet("搴旀敹璐圭敤鏄庣粏");
- createDetailSheetTemplateWithExcelUtil(detailSheet);
-
- // 淇濆瓨宸ヤ綔绨垮埌鏂囦欢
- try (OutputStream out = Files.newOutputStream(Paths.get(getAbsoluteFile(fileName)))) {
- workbook.write(out);
- }
-
- workbook.close();
-
- } catch (Exception e) {
- logger.error("鍒涘缓澶歋heet瀵煎叆妯℃澘澶辫触: {}", e.getMessage(), e);
- throw new UtilException("瀵煎叆妯℃澘鐢熸垚澶辫触锛�");
- }
- }
-
- /**
- * 浣跨敤ExcelUtil鍒涘缓涓昏〃Sheet妯℃澘
- *
- * @param sheet Sheet瀵硅薄
- */
- private void createMainSheetTemplateWithExcelUtil(Sheet sheet) {
- try {
- // 浣跨敤ExcelUtil鍒涘缓涓昏〃妯℃澘
- ExcelUtil<ReceivableFeeManagement> mainSheetUtil = new ExcelUtil<>(ReceivableFeeManagement.class);
-
- // 鍒濆鍖朎xcelUtil
- mainSheetUtil.initialize("搴旀敹璐圭敤涓昏〃", "搴旀敹璐圭敤涓昏〃瀵煎叆妯℃澘锛堣鍕夸慨鏀瑰簭鍙峰垪锛�", Excel.Type.EXPORT);
-
- // 閫氳繃鍙嶅皠鑾峰彇workbook瀛楁
- Field workbookField = ExcelUtil.class.getDeclaredField("workbook");
- workbookField.setAccessible(true);
- SXSSFWorkbook excelUtilWorkbook = (SXSSFWorkbook) workbookField.get(mainSheetUtil);
-
- // 鑾峰彇ExcelUtil鐢熸垚鐨凷heet
- Sheet generatedSheet = excelUtilWorkbook.getSheetAt(0);
-
- // 澶嶅埗鏍囬琛屽埌鐩爣Sheet
- copyRow(generatedSheet.getRow(0), sheet.createRow(0));
-
- // 澶嶅埗琛ㄥご琛屽埌鐩爣Sheet
- copyRow(generatedSheet.getRow(1), sheet.createRow(1));
-
- // 娣诲姞璇存槑琛�
- Row instructionRow = sheet.createRow(2);
- Cell instructionCell = instructionRow.createCell(0);
- instructionCell.setCellValue("璇存槑锛氬簭鍙风敤浜庡叧鑱斾富琛ㄥ拰鏄庣粏琛紝璇风‘淇濅富琛ㄥ拰鏄庣粏琛ㄤ腑鐨勫簭鍙蜂竴鑷�");
-
- // 璁剧疆鍒楀
- for (int i = 0; i < generatedSheet.getRow(1).getLastCellNum(); i++) {
- sheet.setColumnWidth(i, generatedSheet.getColumnWidth(i));
- }
-
- } catch (Exception e) {
- logger.error("浣跨敤ExcelUtil鍒涘缓涓昏〃妯℃澘澶辫触: {}", e.getMessage(), e);
- throw new UtilException("涓昏〃妯℃澘鐢熸垚澶辫触锛�");
- }
- }
-
- /**
- * 浣跨敤ExcelUtil鍒涘缓鏄庣粏琛⊿heet妯℃澘
- *
- * @param sheet Sheet瀵硅薄
- */
- private void createDetailSheetTemplateWithExcelUtil(Sheet sheet) {
- try {
- // 浣跨敤ExcelUtil鍒涘缓鏄庣粏琛ㄦā鏉�
- ExcelUtil<ReceivableFeeDetail> detailSheetUtil = new ExcelUtil<>(ReceivableFeeDetail.class);
-
- // 鍒濆鍖朎xcelUtil
- detailSheetUtil.initialize("搴旀敹璐圭敤鏄庣粏", "搴旀敹璐圭敤鏄庣粏琛ㄥ鍏ユā鏉匡紙搴忓彿涓庝富琛ㄥ搴旓級", Excel.Type.EXPORT);
-
- // 閫氳繃鍙嶅皠鑾峰彇workbook瀛楁
- Field workbookField = ExcelUtil.class.getDeclaredField("workbook");
- workbookField.setAccessible(true);
- SXSSFWorkbook excelUtilWorkbook = (SXSSFWorkbook) workbookField.get(detailSheetUtil);
-
- // 鑾峰彇ExcelUtil鐢熸垚鐨凷heet
- Sheet generatedSheet = excelUtilWorkbook.getSheetAt(0);
-
- // 澶嶅埗鏍囬琛屽埌鐩爣Sheet
- copyRow(generatedSheet.getRow(0), sheet.createRow(0));
-
- // 澶嶅埗琛ㄥご琛屽埌鐩爣Sheet
- copyRow(generatedSheet.getRow(1), sheet.createRow(1));
-
- // 娣诲姞璇存槑琛�
- Row instructionRow = sheet.createRow(2);
- Cell instructionCell = instructionRow.createCell(0);
- instructionCell.setCellValue("璇存槑锛氬簭鍙峰繀椤讳笌涓昏〃涓殑搴忓彿涓�鑷达紝鐢ㄤ簬鍏宠仈涓昏〃鍜屾槑缁嗚〃鏁版嵁");
-
- // 璁剧疆鍒楀
- for (int i = 0; i < generatedSheet.getRow(1).getLastCellNum(); i++) {
- sheet.setColumnWidth(i, generatedSheet.getColumnWidth(i));
- }
-
- } catch (Exception e) {
- logger.error("浣跨敤ExcelUtil鍒涘缓鏄庣粏琛ㄦā鏉垮け璐�: {}", e.getMessage(), e);
- throw new UtilException("鏄庣粏琛ㄦā鏉跨敓鎴愬け璐ワ紒");
- }
- }
-
- /**
- * 澶嶅埗琛屽唴瀹�
- *
- * @param sourceRow 婧愯
- * @param targetRow 鐩爣琛�
- */
- private void copyRow(Row sourceRow, Row targetRow) {
- if (sourceRow == null) return;
-
- targetRow.setHeight(sourceRow.getHeight());
-
- for (int i = 0; i < sourceRow.getLastCellNum(); i++) {
- Cell sourceCell = sourceRow.getCell(i);
- if (sourceCell != null) {
- Cell targetCell = targetRow.createCell(i);
- copyCell(sourceCell, targetCell);
- }
- }
- }
-
- /**
- * 澶嶅埗鍗曞厓鏍煎唴瀹瑰拰鏍峰紡
- *
- * @param sourceCell 婧愬崟鍏冩牸
- * @param targetCell 鐩爣鍗曞厓鏍�
- */
- private void copyCell(Cell sourceCell, Cell targetCell) {
- // 澶嶅埗鍗曞厓鏍兼牱寮�
- targetCell.setCellStyle(sourceCell.getCellStyle());
-
- // 澶嶅埗鍗曞厓鏍煎��
- switch (sourceCell.getCellType()) {
- case STRING:
- targetCell.setCellValue(sourceCell.getStringCellValue());
- break;
- case NUMERIC:
- targetCell.setCellValue(sourceCell.getNumericCellValue());
- break;
- case BOOLEAN:
- targetCell.setCellValue(sourceCell.getBooleanCellValue());
- break;
- case FORMULA:
- targetCell.setCellFormula(sourceCell.getCellFormula());
- break;
- default:
- targetCell.setCellValue(sourceCell.getStringCellValue());
- }
- }
-
+ // 鍒犻櫎涓嶅啀闇�瑕佺殑鏂规硶
/**
* 鑾峰彇鏂囦欢鐨勭粷瀵硅矾寰�
- *
- * @param fileName 鏂囦欢鍚�
- * @return 缁濆璺緞
*/
- private String getAbsoluteFile(String fileName) {
+ private File getAbsoluteFile(String fileName) {
String downloadPath = RuoYiConfig.getDownloadPath();
- File desc = new File(downloadPath + File.separator + fileName);
- if (!desc.exists()) {
- if (!desc.getParentFile().exists()) {
- desc.getParentFile().mkdirs();
- }
- }
- return desc.getAbsolutePath();
+ return new File(downloadPath + fileName);
}
}
\ No newline at end of file
--
Gitblit v1.8.0