From 0b76c560a27c89df168271d7210ab6bf9de28f7d Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期一, 05 一月 2026 16:55:50 +0800
Subject: [PATCH] 新增字段
---
service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 162 insertions(+), 7 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 71ec58b..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
@@ -1,20 +1,29 @@
package com.ruoyi.cwgl.service.impl;
+import java.io.File;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
+import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.enums.SystemDataNoEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
-import com.ruoyi.cwgl.domain.ReceivableFeeDetail;
-import com.ruoyi.cwgl.domain.ReceivableFeeManagementLog;
+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.*;
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;
@@ -26,15 +35,17 @@
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.core.service.BaseService;
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.exception.UtilException;
+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;
import javax.annotation.Resource;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
/**
* 搴旀敹璐圭敤绠$悊Service涓氬姟灞傚鐞�
@@ -66,6 +77,12 @@
@Autowired
private IReceivableFeeManagementLogService logService;
+
+ @Autowired
+ private RedisCache redisCache;
+
+ @Autowired
+ private ITmsCustomerInfoService tmsCustomerInfoService;
/**
* 鏌ヨ搴旀敹璐圭敤绠$悊
@@ -151,7 +168,7 @@
String receivableAmountStr = calculateReceivableAmountStr(receivableFeeManagement.getReceivableFeeDetailList());
receivableFeeManagement.setReceivableAmountStr(receivableAmountStr);
}
-
+ receivableFeeManagement.setCreateBy(SecurityUtils.getUsername());
// 淇濆瓨涓昏〃淇℃伅
int result = receivableFeeManagementMapper.insertReceivableFeeManagement(receivableFeeManagement);
@@ -215,7 +232,7 @@
// 璁剧疆姣忎釜鏄庣粏鐨勫簲鏀惰垂鐢ㄧ鐞咺D
receivableFeeManagement.getReceivableFeeDetailList().forEach(detail -> {
detail.setReceivableFeeId(receivableFeeId);
- detail.setUpdateTime(DateUtils.getNowDate()); // 璁剧疆鏇存柊鏃堕棿
+ detail.setCreateTime(DateUtils.getNowDate()); // 璁剧疆鏇存柊鏃堕棿
});
// 璋冪敤鎵归噺鎻掑叆鏂规硶
@@ -562,4 +579,142 @@
return sb.toString();
}
+
+ /**
+ * 瀵煎叆搴旀敹璐圭敤绠$悊鏁版嵁锛堝寘鍚槑缁嗘暟鎹級
+ *
+ * @param receivableFeeList 搴旀敹璐圭敤绠$悊鏁版嵁鍒楄〃锛堝寘鍚槑缁嗘暟鎹級
+ * @param operName 鎿嶄綔鐢ㄦ埛
+ * @return 缁撴灉
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public String importReceivableFee(List<ReceivableFeeManagement> receivableFeeList, String operName) {
+ if (receivableFeeList == null || receivableFeeList.isEmpty()) {
+ throw new ServiceException("瀵煎叆搴旀敹璐圭敤鏁版嵁涓嶈兘涓虹┖锛�");
+ }
+ int successNum = 0;
+ int failureNum = 0;
+ StringBuilder successMsg = new StringBuilder();
+ StringBuilder failureMsg = new StringBuilder();
+
+ // 鑾峰彇褰撳墠鏃ユ湡
+ Date now = DateUtils.getNowDate();
+
+ for (ReceivableFeeManagement receivableFee : receivableFeeList) {
+ try {
+ // 鑷姩鐢熸垚绯荤粺缂栧彿锛堝拰鏂板鍔熻兘涓�鏍凤級
+ String noByKey = systemDataNoService.getNoByKey(SystemDataNoEnum.YS);
+ receivableFee.setSystemNo(noByKey);
+
+ // 璁剧疆鍒涘缓鏃堕棿鍜屽垱寤轰汉
+ 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");
+ }
+
+ // 鎻掑叆涓昏〃鏁版嵁
+ receivableFeeManagementMapper.insertReceivableFeeManagement(receivableFee);
+
+ // 澶勭悊鏄庣粏鏁版嵁锛堝鏋滄湁锛�
+ if (receivableFee.getReceivableFeeDetailList() != null && !receivableFee.getReceivableFeeDetailList().isEmpty()) {
+ for (ReceivableFeeDetail detail : receivableFee.getReceivableFeeDetailList()) {
+ detail.setReceivableFeeId(receivableFee.getId());
+ detail.setCreateBy(operName);
+ detail.setCreateTime(now);
+ receivableFeeDetailService.insertReceivableFeeDetail(detail);
+ }
+ }
+
+ successNum++;
+ successMsg.append("<br/>" + successNum + ".搴旀敹璐圭敤 " + receivableFee.getSystemNo() + " 瀵煎叆鎴愬姛");
+ } catch (Exception e) {
+ failureNum++;
+ String msg = "<br/>" + failureNum + ".搴旀敹璐圭敤 " + receivableFee.getSystemNo() + " 瀵煎叆澶辫触锛�";
+ failureMsg.append(msg + e.getMessage());
+ logger.error(msg, e);
+ }
+ }
+
+ if (failureNum > 0) {
+ failureMsg.insert(0, "寰堟姳姝夛紝瀵煎叆澶辫触锛佸叡 " + failureNum + " 鏉℃暟鎹牸寮忎笉姝g‘锛岄敊璇涓嬶細");
+ throw new ServiceException(failureMsg.toString());
+ } else {
+ successMsg.insert(0, "鎭枩鎮紝鏁版嵁宸插叏閮ㄥ鍏ユ垚鍔燂紒鍏� " + successNum + " 鏉★紝鏁版嵁濡備笅锛�");
+ }
+ return successMsg.toString();
+ }
+
+ /**
+ * 涓嬭浇瀵煎叆妯℃澘锛堝寘鍚玈heet1涓昏〃鍜孲heet2鏄庣粏琛級
+ *
+ * @param exportKey 瀵煎嚭鍔熻兘鐨勫敮涓�鏍囪瘑
+ */
+ @DataSource(DataSourceType.SLAVE)
+ @Async
+ @Override
+ public void importTemplate(String exportKey) {
+ String fileName = ExcelUtil.encodeFileName("搴旀敹璐圭敤瀵煎叆妯℃澘");
+
+ // 璁剧疆褰撳墠浠诲姟涓�"涓嬭浇涓�"鐘舵��
+ DownloadExportUtil.deleteDownloadFile(redisCache, exportKey, ExprotStatus.XZZ.getStatus());
+
+ try {
+ // 鍒涘缓绌哄垪琛ㄧ敤浜庣敓鎴愭ā鏉匡紙鍙渶瑕佽〃澶达級
+ 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);
+ logger.info("瀵煎叆妯℃澘瀵煎嚭瀹屾垚: {}, file: {}", exportKey, fileName);
+ } catch (Exception e) {
+ logger.error("瀵煎叆妯℃澘瀵煎嚭澶辫触: {}, error: {}", exportKey, e.getMessage(), e);
+ DownloadExportUtil.deleteDownloadFile(redisCache, exportKey, ExprotStatus.XZYC.getStatus()); // 璁剧疆澶辫触鐘舵��
+ throw e;
+ }
+ }
+
+ // 鍒犻櫎涓嶅啀闇�瑕佺殑鏂规硶
+ /**
+ * 鑾峰彇鏂囦欢鐨勭粷瀵硅矾寰�
+ */
+ private File getAbsoluteFile(String fileName) {
+ String downloadPath = RuoYiConfig.getDownloadPath();
+ return new File(downloadPath + fileName);
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0