From 440dfe14126460770f8244e3dc8817c1a6b6c3bb Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 30 三月 2026 18:06:56 +0800
Subject: [PATCH] yys 1.设备备件字段补全
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 153 +++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 143 insertions(+), 10 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..f69bfd9 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;
@@ -20,6 +27,8 @@
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
+import com.ruoyi.procurementrecord.dto.SimplePP;
+import com.ruoyi.procurementrecord.service.ProcurementPriceManagementService;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.purchase.dto.PurchaseLedgerDto;
@@ -42,15 +51,18 @@
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;
+import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
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 +78,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 +104,10 @@
private final StringRedisTemplate redisTemplate;
+ private final IApproveProcessService approveProcessService;
+
+ private final ProcurementPriceManagementService procurementPriceManagementService;
+
@Value("${file.upload-dir}")
private String uploadDir;
@@ -105,6 +121,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException {
SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId());
@@ -125,12 +142,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. 澶勭悊瀛愯〃鏁版嵁
@@ -144,6 +190,26 @@
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;
}
@@ -151,7 +217,7 @@
if (products == null || products.isEmpty()) {
throw new BaseException("浜у搧淇℃伅涓嶅瓨鍦�");
}
-
+ PurchaseLedger ledger = purchaseLedgerMapper.selectById(salesLedgerId);
// 鎻愬墠鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑ID
Set<Long> productIds = products.stream()
.map(SalesLedgerProduct::getProductId)
@@ -197,7 +263,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,10 +276,35 @@
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);
}
}
+
+ updateList.addAll(insertList);
+ updateList.forEach(it->{
+ SimplePP simplePP = new SimplePP();
+ simplePP.setProductId(it.getProductId());
+ simplePP.setSupplierName(ledger.getSupplierName());
+ simplePP.setSupplierId(ledger.getSupplierId());
+ simplePP.setUnit(it.getUnit());
+ simplePP.setProductName(it.getProductCategory());
+ simplePP.setSpecification(it.getSpecificationModel());
+ simplePP.setFinalPrice(it.getTaxInclusiveUnitPrice().divide(
+ BigDecimal.ONE.add(it.getTaxRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP)),
+ 2, // 淇濈暀4浣嶏紙鍙牴鎹笟鍔¤皟鏁达級
+ RoundingMode.HALF_UP
+ ));
+ simplePP.setRemark(
+ "绯荤粺鏍规嵁閲囪喘鎻愪氦鑷姩鐢熸垚銆傞噰璐悎鍚屽彿涓�:" + purchaseLedger.getPurchaseContractNumber() + "銆�"
+ );
+ procurementPriceManagementService.autoCreateRecord(simplePP);
+ });
+
+
// 璁$畻鎬诲惈绋庨噾棰�
BigDecimal totalTaxInclusiveAmount = products.stream()
@@ -270,12 +361,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 +411,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 +584,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