From 27aa4dd460ebd996f190315c9f9052b0646b6460 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期三, 25 三月 2026 15:31:43 +0800
Subject: [PATCH] 采购销售审批功能迁移
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 124 ++++++++++++++++++++++++++++++++++++++---
1 files changed, 115 insertions(+), 9 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 46a5033..7305a75 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -6,6 +6,13 @@
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.approve.pojo.ApproveProcess;
+import com.ruoyi.approve.service.IApproveProcessService;
+import com.ruoyi.approve.vo.ApproveProcessVO;
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.mapper.SupplierManageMapper;
@@ -42,6 +49,7 @@
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;
@@ -51,6 +59,7 @@
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;
@@ -66,7 +75,7 @@
@RequiredArgsConstructor
@Slf4j
public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService {
-
+ private final AccountExpenseService accountExpenseService;
private final PurchaseLedgerMapper purchaseLedgerMapper;
private final SalesLedgerMapper salesLedgerMapper;
@@ -92,6 +101,8 @@
private final StringRedisTemplate redisTemplate;
+ private final IApproveProcessService approveProcessService;
+
@Value("${file.upload-dir}")
private String uploadDir;
@@ -105,6 +116,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException {
SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId());
@@ -125,12 +137,41 @@
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());
+ List<AccountExpense> accountExpenseDBs = accountExpenseService.getByInvoiceNumberList(purchaseLedger.getPurchaseContractNumber());
+ if (!CollectionUtils.isEmpty(accountExpenseDBs)) {
+ accountExpenseDBs.forEach(accountExpenseDB ->{
+ 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. 澶勭悊瀛愯〃鏁版嵁
@@ -142,6 +183,26 @@
// 5. 杩佺Щ涓存椂鏂囦欢鍒版寮忕洰褰�
if (purchaseLedgerDto.getTempFileIds() != null && !purchaseLedgerDto.getTempFileIds().isEmpty()) {
migrateTempFilesToFormal(purchaseLedger.getId(), purchaseLedgerDto.getTempFileIds());
+ }
+
+ //6.閲囪喘闇�瑕佸鎵�
+ //鏂板瀹℃壒鏁版嵁approve_proces
+ ApproveProcessVO approveProcessVO = new ApproveProcessVO();
+ approveProcessVO.setApproveDeptId(purchaseLedger.getTenantId());
+ //瀹℃壒鐞嗙敱鏄噰璐悎鍚屽彿鐢ㄨ繖涓潵鍏宠仈
+ approveProcessVO.setApproveReason(purchaseLedger.getPurchaseContractNumber());
+ DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ approveProcessVO.setApproveTime(LocalDate.now().format(dateFormat));
+ //5鏄噰璐敵璇�
+ approveProcessVO.setApproveType(5);
+ //褰曞叆浜�=鐢宠浜�
+ approveProcessVO.setApproveUser(purchaseLedger.getRecorderId());
+ //瀹℃壒浜�
+ approveProcessVO.setApproveUserIds(purchaseLedgerDto.getApproveUserIds());
+ try {
+ approveProcessService.addApprove(approveProcessVO);
+ } catch (Exception e) {
+ e.printStackTrace();
}
return 1;
@@ -197,7 +258,7 @@
List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
List<SalesLedgerProduct> insertList = partitionedProducts.get(false);
- SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerId);
+ PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(salesLedgerId);
// 鎵ц鏇存柊鎿嶄綔
if (!updateList.isEmpty()) {
@@ -210,7 +271,10 @@
if (!insertList.isEmpty()) {
for (SalesLedgerProduct salesLedgerProduct : insertList) {
salesLedgerProduct.setType(type);
- salesLedgerProduct.setRegisterDate(salesLedger.getEntryDate().toString());
+ Date entryDate = purchaseLedger.getEntryDate();
+
+ LocalDateTime localDateTime = entryDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
+ salesLedgerProduct.setRegisterDate(localDateTime);
salesLedgerProductMapper.insert(salesLedgerProduct);
}
}
@@ -270,12 +334,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锛�
@@ -317,6 +384,25 @@
LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
productRecordLambdaQueryWrapper.in(ProductRecord::getPurchaseLedgerId,ids);
productRecordMapper.delete(productRecordLambdaQueryWrapper);
+
+ // 鍒犻櫎鍏宠仈鐨勫鎵硅〃
+ List<String> strings = purchaseLedgerMapper.selectBatchIds(Arrays.asList(ids)).stream()
+ .map(PurchaseLedger::getPurchaseContractNumber)
+ .distinct()
+ .collect(Collectors.toList());
+ List<ApproveProcess> list = approveProcessService.list(Wrappers.<ApproveProcess>lambdaQuery().eq(ApproveProcess::getApproveType, 5) .in(ApproveProcess::getApproveReason, strings));
+ if (CollectionUtils.isNotEmpty(list)){
+ List<String> approveIds = list.stream()
+ .map(ApproveProcess::getApproveId)
+ .distinct()
+ .collect(Collectors.toList());
+ Long[] ides = approveIds.stream()
+ .filter(s -> s != null && !s.isEmpty())
+ .map(Long::valueOf)
+ .toArray(Long[]::new);
+ approveProcessService.delApprove(ides);
+ }
+
// 鎵归噺鍒犻櫎閲囪喘鍙拌处
return purchaseLedgerMapper.deleteBatchIds(Arrays.asList(ids));
}
@@ -471,6 +557,26 @@
return purchaseNo + String.format("%03d", sequence);
}
+ @Override
+ public PurchaseLedgerDto getPurchaseByCode(PurchaseLedgerDto purchaseLedgerDto) {
+ // 1. 鏌ヨ涓昏〃
+ PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>() .eq(PurchaseLedger::getPurchaseContractNumber, purchaseLedgerDto.getPurchaseContractNumber()) .last("LIMIT 1"));
+ if (purchaseLedger == null) {
+ throw new BaseException("閲囪喘鍙拌处涓嶅瓨鍦�");
+ }
+ // 2. 鏌ヨ瀛愯〃
+ LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
+ productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) .eq(SalesLedgerProduct::getType, 2);
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper);
+ // 4. 杞崲 DTO
+ PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); BeanUtils.copyProperties(purchaseLedger, resultDto);
+ if (!products.isEmpty()) {
+ resultDto.setHasChildren(true);
+ resultDto.setProductData(products);
+ }
+ return resultDto;
+ }
+
/**
* 涓嬪垝绾垮懡鍚嶈浆椹煎嘲鍛藉悕
*/
--
Gitblit v1.9.3