From 47768d890fbfc1a5f3e93ca26137847361415e9e Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期二, 28 十月 2025 10:54:16 +0800
Subject: [PATCH] Merge branch 'master' into pim_meet
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 101 +++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 86 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
index ac9691b..79041dc 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -6,13 +6,19 @@
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.account.pojo.AccountExpense;
+import com.ruoyi.account.pojo.AccountIncome;
+import com.ruoyi.account.service.AccountExpenseService;
+import com.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.mapper.SupplierManageMapper;
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.pojo.SupplierManage;
+import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.security.LoginUser;
@@ -38,7 +44,9 @@
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.math.BigDecimal;
@@ -48,8 +56,10 @@
import java.nio.file.StandardCopyOption;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
+import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -62,7 +72,7 @@
@RequiredArgsConstructor
@Slf4j
public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService {
-
+ private final AccountExpenseService accountExpenseService;
private final PurchaseLedgerMapper purchaseLedgerMapper;
private final SalesLedgerMapper salesLedgerMapper;
@@ -86,6 +96,8 @@
private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+ private final StringRedisTemplate redisTemplate;
+
@Value("${file.upload-dir}")
private String uploadDir;
@@ -99,6 +111,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException {
SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId());
@@ -119,12 +132,39 @@
purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId());
purchaseLedger.setRecorderName(sysUser.getNickName());
purchaseLedger.setPhoneNumber(sysUser.getPhonenumber());
+ // 2. 澶勭悊璐︽埛鏀跺叆
+ AccountExpense accountExpense = new AccountExpense();
+ accountExpense.setExpenseDate(purchaseLedger.getEntryDate());
+ accountExpense.setExpenseType("0");
+ accountExpense.setSupplierName(purchaseLedger.getSupplierName());
+ accountExpense.setExpenseMoney(purchaseLedger.getContractAmount());
+ accountExpense.setExpenseDescribed("閲囪喘鍚堝悓锛�" + purchaseLedger.getPurchaseContractNumber());
+ accountExpense.setExpenseMethod("0");
+ accountExpense.setInvoiceNumber(purchaseLedger.getPurchaseContractNumber());
+ accountExpense.setInputTime(new Date());
+ accountExpense.setInputUser(loginUser.getNickName());
+
// 3. 鏂板鎴栨洿鏂颁富琛�
if (purchaseLedger.getId() == null) {
purchaseLedgerMapper.insert(purchaseLedger);
+// accountIncomeService.save(accountIncome);
+ accountExpenseService.save(accountExpense);
} else {
purchaseLedgerMapper.updateById(purchaseLedger);
+ PurchaseLedger purchaseLedgerDB = purchaseLedgerMapper.selectById(purchaseLedger.getId());
+ AccountExpense accountExpenseDB = accountExpenseService.getByInvoiceNumber(purchaseLedger.getPurchaseContractNumber());
+ if (ObjectUtils.isEmpty(accountExpenseDB)) {
+ throw new BaseException("鏀嚭绠$悊鏃犺閲囪喘鍚堝悓鐨勬敮鍑鸿褰�");
+ }
+ accountExpenseDB.setExpenseDate(purchaseLedgerDB.getEntryDate());
+ accountExpenseDB.setExpenseType("0");
+ accountExpenseDB.setSupplierName(purchaseLedgerDB.getSupplierName());
+ accountExpenseDB.setExpenseMoney(purchaseLedgerDB.getContractAmount());
+ accountExpenseDB.setExpenseDescribed("閲囪喘鍚堝悓锛�" + purchaseLedgerDB.getPurchaseContractNumber());
+ accountExpenseDB.setExpenseMethod("0");
+ accountExpenseDB.setInvoiceNumber(purchaseLedgerDB.getPurchaseContractNumber());
+ accountExpenseService.updateById(accountExpenseDB);
}
// 4. 澶勭悊瀛愯〃鏁版嵁
@@ -191,6 +231,7 @@
List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
List<SalesLedgerProduct> insertList = partitionedProducts.get(false);
+ PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(salesLedgerId);
// 鎵ц鏇存柊鎿嶄綔
if (!updateList.isEmpty()) {
@@ -203,6 +244,10 @@
if (!insertList.isEmpty()) {
for (SalesLedgerProduct salesLedgerProduct : insertList) {
salesLedgerProduct.setType(type);
+ Date entryDate = purchaseLedger.getEntryDate();
+
+ LocalDateTime localDateTime = entryDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
+ salesLedgerProduct.setRegisterDate(localDateTime);
salesLedgerProductMapper.insert(salesLedgerProduct);
}
}
@@ -262,12 +307,15 @@
try {
// 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
- Files.move(
- Paths.get(tempFile.getTempPath()),
- formalFilePath,
- StandardCopyOption.REPLACE_EXISTING,
- StandardCopyOption.ATOMIC_MOVE
- );
+// Files.move(
+// Paths.get(tempFile.getTempPath()),
+// formalFilePath,
+// StandardCopyOption.REPLACE_EXISTING,
+// StandardCopyOption.ATOMIC_MOVE
+// );
+ // 鍘熷瓙绉诲姩澶辫触锛屼娇鐢ㄥ鍒�+鍒犻櫎
+ Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
+ Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
// 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛�
@@ -276,7 +324,7 @@
fileRecord.setName(originalFilename);
fileRecord.setUrl(formalFilePath.toString());
fileRecord.setCreateTime(LocalDateTime.now());
- fileRecord.setType("2");
+ fileRecord.setType(FileNameType.PURCHASE.getValue());
commonFileMapper.insert(fileRecord);
// 鍒犻櫎涓存椂鏂囦欢璁板綍
@@ -299,7 +347,7 @@
// 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︿骇鍝�
LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, ids)
- .eq(SalesLedgerProduct::getType, "2");
+ .eq(SalesLedgerProduct::getType, 2);
salesLedgerProductMapper.delete(queryWrapper);
// 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︾殑鏉ョエ鐧昏
LambdaQueryWrapper<TicketRegistration> ticketRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -367,6 +415,7 @@
}
// 鍒涘缓骞跺~鍏匘TO
PurchaseLedgerDto resultDto = new PurchaseLedgerDto();
+ resultDto.setSalesLedgerId(purchaseLedger.getSalesLedgerId());
resultDto.setSalesContractNoId(purchaseLedger.getSalesLedgerId());
resultDto.setSalesContractNo(purchaseLedger.getSalesContractNo());
resultDto.setSupplierName(purchaseLedger.getSupplierName());
@@ -409,6 +458,7 @@
public PurchaseLedgerDto getPurchaseNoById(Long id) {
PurchaseLedgerDto purchaseLedgerDto = new PurchaseLedgerDto();
PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(id);
+
BeanUtils.copyProperties(purchaseLedger, purchaseLedgerDto);
// TicketRegistration ticketRegistration = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getPurchaseLedgerId, id));
// if (ticketRegistration != null) {
@@ -420,12 +470,13 @@
}
@Override
- public IPage<PurchaseLedger> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedger purchaseLedger) {
- LambdaQueryWrapper<PurchaseLedger> queryWrapper = new LambdaQueryWrapper<>();
- if (StringUtils.isNotBlank(purchaseLedger.getPurchaseContractNumber())) {
- queryWrapper.like(PurchaseLedger::getPurchaseContractNumber, purchaseLedger.getPurchaseContractNumber());
- }
- return purchaseLedgerMapper.selectPage(ipage, queryWrapper);
+ public IPage<PurchaseLedgerDto> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedgerDto purchaseLedger) {
+ IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger);
+ purchaseLedgerDtoIPage.getRecords().forEach(purchaseLedgerDto -> {
+ List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, purchaseLedgerDto.getId()).eq(CommonFile::getType, FileNameType.PURCHASELEDGER.getValue()));
+ purchaseLedgerDto.setSalesLedgerFiles(commonFiles);
+ });
+ return purchaseLedgerDtoIPage;
}
@Override
@@ -440,6 +491,26 @@
return invoiceRegistrationProducts;
}
+ @Override
+ public String getPurchaseNo() {
+ // 鐢熸垚鏃ユ湡鍓嶇紑锛堜緥濡傦細CG20250405锛�
+ String purchaseNo = "CG" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
+
+ // 鏋勫缓 Redis Key锛堟寜澶╁垎闅旓級
+ String redisKey = "purchase_no:" + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
+
+ // 鑾峰彇褰撳墠搴忓彿骞堕�掑锛堝師瀛愭搷浣滐級
+ Long sequence = redisTemplate.opsForValue().increment(redisKey);
+
+ // 璁剧疆杩囨湡鏃堕棿锛堟鏃ュけ鏁堬紝闃叉鍐椾綑鏁版嵁锛�
+ if (sequence == 1) {
+ redisTemplate.expire(redisKey, 1, TimeUnit.DAYS);
+ }
+
+ // 杩斿洖瀹屾暣缂栧彿锛堝 CG202504050001锛�
+ return purchaseNo + String.format("%03d", sequence);
+ }
+
/**
* 涓嬪垝绾垮懡鍚嶈浆椹煎嘲鍛藉悕
*/
--
Gitblit v1.9.3