From 0010b446cb0f747f4995355b468f9a32244e57dc Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期五, 26 十二月 2025 15:47:37 +0800
Subject: [PATCH] 新增发票管理
---
service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 204 insertions(+), 18 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 29695ec..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()); // 璁剧疆鏇存柊鏃堕棿
});
// 璋冪敤鎵归噺鎻掑叆鏂规硶
@@ -368,23 +385,52 @@
SysConfig sysConfig = sysConfigMapper.selectConfig(new SysConfig() {{
setConfigKey("sys.hk.rmb.rate");
}});
- // 璁$畻鎬诲簲鏀堕噾棰�
- BigDecimal totalReceivableAmount = receivableFeeList.stream()
- .map(ReceivableFeeManagement::getReceivableAmount)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
+ // 璁$畻鎬诲簲鏀堕噾棰濓紙鎸夊竵绉嶅垎鍒绠楋級
+ BigDecimal totalAmountRmb = BigDecimal.ZERO;
+ BigDecimal totalAmountHkd = BigDecimal.ZERO;
-
+ // 鑾峰彇鎵�鏈夊簲鏀惰垂鐢ㄦ槑缁嗭紝鎸夊竵绉嶆眹鎬�
+ if (!receivableFeeList.isEmpty()) {
+ // 鑾峰彇鎵�鏈夊簲鏀惰垂鐢↖D
+ Integer[] feeIds = receivableFeeList.stream()
+ .map(ReceivableFeeManagement::getId)
+ .toArray(Integer[]::new);
+
+ // 鏌ヨ鎵�鏈夋槑缁嗚褰�
+ List<ReceivableFeeDetail> allDetails = receivableFeeDetailService.selectReceivableFeeDetailByReceivableFeeIds(feeIds);
+
+ // 鎸夊竵绉嶆眹鎬婚噾棰�
+ for (ReceivableFeeDetail detail : allDetails) {
+ if (detail.getBillingAmount() != null && detail.getCurrency() != null) {
+ if ("RMB".equals(detail.getCurrency())) {
+ totalAmountRmb = totalAmountRmb.add(detail.getBillingAmount());
+ } else if ("HKD".equals(detail.getCurrency())) {
+ totalAmountHkd = totalAmountHkd.add(detail.getBillingAmount());
+ }
+ }
+ }
+ }
+
BigDecimal exchangeRate = new BigDecimal(sysConfig.getConfigValue());
- BigDecimal totalAmountHkd = totalReceivableAmount.divide(exchangeRate, 2, RoundingMode.HALF_UP);
+
+ // 璁$畻浜烘皯甯佹�婚噾棰濓紙浜烘皯甯侀噾棰� + 娓竵鎹㈢畻鎴愪汉姘戝竵锛�
+ BigDecimal totalAmountRmbWithConversion = totalAmountRmb.add(
+ totalAmountHkd.multiply(exchangeRate).setScale(2, RoundingMode.HALF_UP)
+ );
+
+ // 璁$畻娓竵鎬婚噾棰濓紙娓竵閲戦 + 浜烘皯甯佹崲绠楁垚娓竵锛�
+ BigDecimal totalAmountHkdWithConversion = totalAmountHkd.add(
+ totalAmountRmb.divide(exchangeRate, 2, RoundingMode.HALF_UP)
+ );
// 缁勮杩斿洖缁撴灉
ReceivableFeeStatisticsVo result = new ReceivableFeeStatisticsVo();
result.setDocumentCount(documentCount);
result.setRate(exchangeRate);
- result.setTotalReceivableAmount(totalReceivableAmount);
- result.setTotalAmountRmb(totalReceivableAmount);
- result.setTotalAmountHkd(totalAmountHkd);
+ result.setTotalReceivableAmount(totalAmountRmbWithConversion); // 榛樿浣跨敤浜烘皯甯佹�婚噾棰�
+ result.setTotalAmountRmb(totalAmountRmbWithConversion);
+ result.setTotalAmountHkd(totalAmountHkdWithConversion);
result.setIds(ids);
return result;
@@ -422,12 +468,13 @@
billManagement.setCreateTime(DateUtils.getNowDate());
billManagement.setBillName(billCreateVo.getBillName());
billManagement.setCustomerName(billCreateVo.getCustomerName());
+ billManagement.setCreateBy(SecurityUtils.getUsername());
billManagement.setIsInternalSettlement(billCreateVo.getIsInternalSettlement());
billManagement.setInternalSettlementUnit(billCreateVo.getInternalSettlementUnit());
// 3. 鏍规嵁璐﹀崟绫诲瀷璁剧疆甯佺鍜屾�婚噾棰�
if (billType == 0) {
// 浜烘皯甯佽处鍗�
- billManagement.setCurrency("CNY");
+ billManagement.setCurrency("RMB");
billManagement.setTotalAmount(statisticsVo.getTotalAmountRmb());
} else if (billType == 1) {
// 娓竵璐﹀崟
@@ -436,6 +483,7 @@
} else {
throw new IllegalArgumentException("鏃犳晥鐨勮处鍗曠被鍨嬶細" + billType);
}
+ billManagement.setPendingAmount(billManagement.getTotalAmount());
String noByKey = systemDataNoService.getNoByKey(SystemDataNoEnum.YSZD);
billManagement.setSystemNo(noByKey);
// 4. 淇濆瓨涓昏处鍗曡褰�
@@ -501,7 +549,7 @@
Map<String, BigDecimal> currencyAmountMap = new HashMap<>();
for (ReceivableFeeDetail detail : detailList) {
String currency = detail.getCurrency();
- BigDecimal billingAmount = detail.getBillingAmount();
+ BigDecimal billingAmount = detail.getActualAmount();
if (currency != null && billingAmount != null) {
currencyAmountMap.merge(currency, billingAmount, BigDecimal::add);
@@ -531,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