From 6b81cbcf4f364eb5b48e0f39309034034df9ceda Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期一, 22 十二月 2025 11:22:30 +0800
Subject: [PATCH] 应收费用新增系统编号
---
service/src/main/java/com/ruoyi/cwgl/service/impl/ReceivableFeeManagementServiceImpl.java | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 166 insertions(+), 2 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 73ced5b..a5ed886 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,9 +1,22 @@
package com.ruoyi.cwgl.service.impl;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
+import com.ruoyi.common.enums.SystemDataNoEnum;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
+
+import com.ruoyi.cwgl.domain.ReceivableFeeDetail;
+import com.ruoyi.cwgl.domain.vo.ReceivableFeeStatisticsVo;
+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;
import org.springframework.scheduling.annotation.Async;
@@ -17,7 +30,13 @@
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.service.IReceivableFeeDetailService;
import com.ruoyi.cwgl.service.IReceivableFeeManagementService;
+import com.ruoyi.cwgl.service.IReceivableBillManagementService;
+import com.ruoyi.cwgl.service.IReceivableBillSettlementDetailService;
+import com.ruoyi.cwgl.domain.vo.ReceivableBillCreateVo;
import com.ruoyi.common.core.text.Convert;
/**
@@ -33,7 +52,21 @@
protected final Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private ReceivableFeeManagementMapper receivableFeeManagementMapper;
+
+ @Autowired
+ private IReceivableFeeDetailService receivableFeeDetailService;
+ @Resource
+ private SysConfigMapper sysConfigMapper;
+
+ @Autowired
+ private IReceivableBillManagementService receivableBillManagementService;
+
+ @Autowired
+ private IReceivableBillSettlementDetailService receivableBillSettlementDetailService;
+
+ @Autowired
+ ISystemDataNoService systemDataNoService;
/**
* 鏌ヨ搴旀敹璐圭敤绠$悊
@@ -103,7 +136,28 @@
public int insertReceivableFeeManagement(ReceivableFeeManagement receivableFeeManagement)
{
receivableFeeManagement.setCreateTime(DateUtils.getNowDate());
- return receivableFeeManagementMapper.insertReceivableFeeManagement(receivableFeeManagement);
+ String noByKey = systemDataNoService.getNoByKey(SystemDataNoEnum.YS);
+ receivableFeeManagement.setSystemNo(noByKey);
+
+ // 淇濆瓨涓昏〃淇℃伅
+ int result = receivableFeeManagementMapper.insertReceivableFeeManagement(receivableFeeManagement);
+
+ // 鑾峰彇涓昏〃ID
+ Integer receivableFeeId = receivableFeeManagement.getId();
+
+ // 鎵归噺淇濆瓨鏄庣粏鍒楄〃
+ if (receivableFeeManagement.getReceivableFeeDetailList() != null && !receivableFeeManagement.getReceivableFeeDetailList().isEmpty()) {
+ // 璁剧疆姣忎釜鏄庣粏鐨勫簲鏀惰垂鐢ㄧ鐞咺D
+ receivableFeeManagement.getReceivableFeeDetailList().forEach(detail -> {
+ detail.setReceivableFeeId(receivableFeeId);
+ detail.setCreateTime(DateUtils.getNowDate()); // 璁剧疆鍒涘缓鏃堕棿
+ });
+
+ // 璋冪敤鎵归噺鎻掑叆鏂规硶
+ receivableFeeDetailService.insertReceivableFeeDetailBatch(receivableFeeManagement.getReceivableFeeDetailList());
+ }
+
+ return result;
}
/**
@@ -179,4 +233,114 @@
{
return receivableFeeManagementMapper.deleteReceivableFeeManagementById(id);
}
-}
+
+ /**
+ * 鏍规嵁搴旀敹璐圭敤ID鏁扮粍鏌ヨ缁熻淇℃伅鍜屾槑缁�
+ *
+ * @param ids 搴旀敹璐圭敤ID鏁扮粍
+ * @return 鍖呭惈缁熻淇℃伅鍜屾槑缁嗙殑缁撴灉
+ */
+ @DataSource(DataSourceType.SLAVE)
+ @Override
+ public ReceivableFeeStatisticsVo getReceivableFeeStatistics(Integer[] ids)
+ {
+ // 鏌ヨ搴旀敹璐圭敤涓昏〃璁板綍
+ List<ReceivableFeeManagement> receivableFeeList = receivableFeeManagementMapper.selectReceivableFeeManagementByIds(ids);
+
+ // 妫�鏌ユ墍鏈夎褰曟槸鍚﹀睘浜庡悓涓�涓鎴�
+ if (!receivableFeeList.isEmpty()) {
+ Integer firstCustomerId = receivableFeeList.get(0).getCustomerId();
+ boolean allSameCustomer = receivableFeeList.stream()
+ .allMatch(item -> Objects.equals(item.getCustomerId(), firstCustomerId));
+
+ if (!allSameCustomer) {
+ throw new ServiceException("鎵�閫夎褰曞寘鍚笉鍚屽鎴风殑鏁版嵁锛屾棤娉曡繘琛岀粺璁�");
+ }
+ }
+
+ // 璁$畻鍗曟嵁鏁伴噺
+ int documentCount = receivableFeeList.size();
+ SysConfig sysConfig = sysConfigMapper.selectConfig(new SysConfig() {{
+ setConfigKey("sys.hk.rmb.rate");
+ }});
+ // 璁$畻鎬诲簲鏀堕噾棰�
+ BigDecimal totalReceivableAmount = receivableFeeList.stream()
+ .map(ReceivableFeeManagement::getReceivableAmount)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+
+ BigDecimal exchangeRate = new BigDecimal(sysConfig.getConfigValue());
+ BigDecimal totalAmountHkd = totalReceivableAmount.divide(exchangeRate, 2, RoundingMode.HALF_UP);
+
+ // 鏌ヨ搴旀敹璐圭敤鏄庣粏
+ List<ReceivableFeeDetail> detailList = receivableFeeDetailService.selectReceivableFeeDetailByReceivableFeeIds(ids);
+
+ // 缁勮杩斿洖缁撴灉
+ ReceivableFeeStatisticsVo result = new ReceivableFeeStatisticsVo();
+ result.setDocumentCount(documentCount);
+ result.setRate(exchangeRate);
+ result.setTotalReceivableAmount(totalReceivableAmount);
+ result.setTotalAmountRmb(totalReceivableAmount);
+ result.setTotalAmountHkd(totalAmountHkd);
+ result.setDetailList(detailList);
+ result.setIds(ids);
+
+ return result;
+ }
+
+ /**
+ * 鏍规嵁缁熻鏁版嵁鍒涘缓搴旀敹璐﹀崟
+ *
+ * @param billCreateVo 鍖呭惈缁熻鏁版嵁鍜岃处鍗曠被鍨嬬殑璇锋眰瀵硅薄
+ * @return 鍒涘缓鐨勫簲鏀惰处鍗旾D
+ */
+ @Override
+ public Integer createReceivableBill(ReceivableBillCreateVo billCreateVo) {
+ // 1. 鍑嗗鏁版嵁
+ ReceivableFeeStatisticsVo statisticsVo = billCreateVo.getStatisticsData();
+ Integer billType = billCreateVo.getBillType();
+
+ // 2. 鍒涘缓搴旀敹璐﹀崟涓昏褰�
+ ReceivableBillManagement billManagement = new ReceivableBillManagement();
+ billManagement.setDocumentCount(statisticsVo.getDocumentCount());
+ billManagement.setExchangeRate(statisticsVo.getRate());
+ billManagement.setStatus("DRAFT"); // 榛樿鑽夌鐘舵��
+ billManagement.setCreateTime(DateUtils.getNowDate());
+
+ // 3. 鏍规嵁璐﹀崟绫诲瀷璁剧疆甯佺鍜屾�婚噾棰�
+ if (billType == 0) {
+ // 浜烘皯甯佽处鍗�
+ billManagement.setCurrency("CNY");
+ billManagement.setTotalAmount(statisticsVo.getTotalAmountRmb());
+ } else if (billType == 1) {
+ // 娓竵璐﹀崟
+ billManagement.setCurrency("HKD");
+ billManagement.setTotalAmount(statisticsVo.getTotalAmountHkd());
+ } else {
+ throw new IllegalArgumentException("鏃犳晥鐨勮处鍗曠被鍨嬶細" + billType);
+ }
+
+ // 4. 淇濆瓨涓昏处鍗曡褰�
+ int i = receivableBillManagementService.insertReceivableBillManagement(billManagement);
+
+ // 5. 鏇存柊搴旀敹璐圭敤涓昏〃鐨勫叧鑱旇处鍗曠紪鍙�
+ if (statisticsVo.getIds() != null && statisticsVo.getIds().length > 0) {
+ // 鑾峰彇鐢熸垚鐨勮处鍗曠郴缁熺紪鍙�
+ String billSystemNo = billManagement.getSystemNo();
+
+ // 鎵归噺鏇存柊搴旀敹璐圭敤涓昏〃鐨勫叧鑱旇处鍗曠紪鍙�
+ List<ReceivableFeeManagement> feeManagements = new ArrayList<>();
+ for (Integer feeId : statisticsVo.getIds()) {
+ ReceivableFeeManagement feeManagement = new ReceivableFeeManagement();
+ feeManagement.setId(feeId);
+ feeManagement.setRelatedBillNo(billSystemNo);
+ feeManagements.add(feeManagement);
+ }
+
+ // 璋冪敤鎵归噺鏇存柊鏂规硶
+ updateReceivableFeeManagementBatch(feeManagements);
+ }
+
+ return i;
+ }
+}
\ No newline at end of file
--
Gitblit v1.8.0