From a62b7e8c7a17a1f98b6caecd2912ad55baa2a6cd Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期一, 22 十二月 2025 16:31:51 +0800
Subject: [PATCH] 修改数据库
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 92 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 77 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 845b18d..9f9123f 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;
@@ -21,9 +27,11 @@
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.purchase.dto.PurchaseLedgerDto;
+import com.ruoyi.purchase.mapper.PaymentRegistrationMapper;
import com.ruoyi.purchase.mapper.ProductRecordMapper;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
import com.ruoyi.purchase.mapper.TicketRegistrationMapper;
+import com.ruoyi.purchase.pojo.PaymentRegistration;
import com.ruoyi.purchase.pojo.ProductRecord;
import com.ruoyi.purchase.pojo.PurchaseLedger;
import com.ruoyi.purchase.pojo.TicketRegistration;
@@ -40,6 +48,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;
@@ -49,6 +58,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;
@@ -64,7 +74,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 ProductRecordMapper productRecordMapper;
+ private final PaymentRegistrationMapper paymentRegistrationMapper;
+
private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
private final StringRedisTemplate redisTemplate;
@@ -103,6 +115,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException {
SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId());
@@ -118,17 +131,47 @@
if(ObjectUtils.isNotEmpty(loginUser) && null != loginUser.getTenantId()) {
purchaseLedger.setTenantId(loginUser.getTenantId());
}
- purchaseLedger.setSalesContractNo(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getSalesContractNo() : null);
+ purchaseLedger.setSalesContractNo(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getSalesContractNo() : "");
+ purchaseLedger.setSalesLedgerId(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getId() : -1);
purchaseLedger.setSupplierName(supplierManage.getSupplierName());
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. 澶勭悊瀛愯〃鏁版嵁
@@ -195,6 +238,7 @@
List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
List<SalesLedgerProduct> insertList = partitionedProducts.get(false);
+ PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(salesLedgerId);
// 鎵ц鏇存柊鎿嶄綔
if (!updateList.isEmpty()) {
@@ -207,6 +251,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);
}
}
@@ -266,12 +314,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锛�
@@ -280,7 +331,7 @@
fileRecord.setName(originalFilename);
fileRecord.setUrl(formalFilePath.toString());
fileRecord.setCreateTime(LocalDateTime.now());
- fileRecord.setType("2");
+ fileRecord.setType(FileNameType.PURCHASE.getValue());
commonFileMapper.insert(fileRecord);
// 鍒犻櫎涓存椂鏂囦欢璁板綍
@@ -303,16 +354,20 @@
// 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︿骇鍝�
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<>();
- ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getSalesLedgerId,ids);
+ ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getPurchaseLedgerId,ids);
ticketRegistrationMapper.delete(ticketRegistrationLambdaQueryWrapper);
// 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︾殑鏉ョエ鐧昏璁板綍
LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
productRecordLambdaQueryWrapper.in(ProductRecord::getPurchaseLedgerId,ids);
productRecordMapper.delete(productRecordLambdaQueryWrapper);
+ // 鎵归噺鍒犻櫎浠樻鐧昏
+ LambdaQueryWrapper<PaymentRegistration> paymentRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ paymentRegistrationLambdaQueryWrapper.in(PaymentRegistration::getPurchaseLedgerId,ids);
+ paymentRegistrationMapper.delete(paymentRegistrationLambdaQueryWrapper);
// 鎵归噺鍒犻櫎閲囪喘鍙拌处
return purchaseLedgerMapper.deleteBatchIds(Arrays.asList(ids));
}
@@ -333,7 +388,8 @@
// 3.鏌ヨ涓婁紶鏂囦欢
LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
- salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId());
+ salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId())
+ .eq(CommonFile::getType, FileNameType.PURCHASE.getValue());
List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
// 4. 杞崲 DTO
@@ -371,6 +427,7 @@
}
// 鍒涘缓骞跺~鍏匘TO
PurchaseLedgerDto resultDto = new PurchaseLedgerDto();
+ resultDto.setSalesLedgerId(purchaseLedger.getSalesLedgerId());
resultDto.setSalesContractNoId(purchaseLedger.getSalesLedgerId());
resultDto.setSalesContractNo(purchaseLedger.getSalesContractNo());
resultDto.setSupplierName(purchaseLedger.getSupplierName());
@@ -413,6 +470,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) {
@@ -424,9 +482,13 @@
}
@Override
- public IPage<PurchaseLedger> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedger purchaseLedger) {
-
- return purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger);
+ 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.PURCHASE.getValue()));
+ purchaseLedgerDto.setSalesLedgerFiles(commonFiles);
+ });
+ return purchaseLedgerDtoIPage;
}
@Override
--
Gitblit v1.9.3