From 9f3a45da6d1dc9c71187f15131665eb9806f5588 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期二, 28 十月 2025 15:58:03 +0800
Subject: [PATCH] yys 1.修改配置文件 2.增加模板
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 509 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 500 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 a209ccb..79041dc 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -1,15 +1,66 @@
package com.ruoyi.purchase.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+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;
+import com.ruoyi.other.mapper.TempFileMapper;
+import com.ruoyi.other.pojo.TempFile;
+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.ProductRecordMapper;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
+import com.ruoyi.purchase.mapper.TicketRegistrationMapper;
+import com.ruoyi.purchase.pojo.ProductRecord;
import com.ruoyi.purchase.pojo.PurchaseLedger;
+import com.ruoyi.purchase.pojo.TicketRegistration;
import com.ruoyi.purchase.service.IPurchaseLedgerService;
-import lombok.AllArgsConstructor;
+import com.ruoyi.sales.mapper.*;
+import com.ruoyi.sales.pojo.CommonFile;
+import com.ruoyi.sales.pojo.InvoiceRegistrationProduct;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+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.util.Arrays;
-import java.util.List;
+import java.io.IOException;
+import java.math.BigDecimal;
+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;
+import java.util.stream.Collectors;
/**
* 閲囪喘鍙拌处Service涓氬姟灞傚鐞�
@@ -18,27 +69,467 @@
* @date 2025-05-09
*/
@Service
-@AllArgsConstructor
+@RequiredArgsConstructor
+@Slf4j
public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService {
+ private final AccountExpenseService accountExpenseService;
+ private final PurchaseLedgerMapper purchaseLedgerMapper;
- private PurchaseLedgerMapper purchaseLedgerMapper;
+ private final SalesLedgerMapper salesLedgerMapper;
+ private final SalesLedgerProductMapper salesLedgerProductMapper;
+
+ private final SysUserMapper userMapper;
+
+ private final TempFileMapper tempFileMapper;
+
+ private final CommonFileMapper commonFileMapper;
+
+ private final SupplierManageMapper supplierManageMapper;
+
+ private final ProductMapper productMapper;
+
+ private final ProductModelMapper productModelMapper;
+
+ private final TicketRegistrationMapper ticketRegistrationMapper;
+
+ private final ProductRecordMapper productRecordMapper;
+
+ private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+
+ private final StringRedisTemplate redisTemplate;
+
+ @Value("${file.upload-dir}")
+ private String uploadDir;
@Override
public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) {
- return purchaseLedgerMapper.selectList(new LambdaQueryWrapper<>());
+ LambdaQueryWrapper<PurchaseLedger> queryWrapper = new LambdaQueryWrapper<>();
+ if (StringUtils.isNotBlank(purchaseLedger.getPurchaseContractNumber())) {
+ queryWrapper.like(PurchaseLedger::getPurchaseContractNumber, purchaseLedger.getPurchaseContractNumber());
+ }
+ return purchaseLedgerMapper.selectList(queryWrapper);
}
@Override
- public int addOrEditPurchase(PurchaseLedger purchaseLedger) {
+ @Transactional(rollbackFor = Exception.class)
+ public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException {
+
+ SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId());
+ //褰曞叆浜�
+ SysUser sysUser = userMapper.selectUserById(purchaseLedgerDto.getRecorderId());
+
+ SupplierManage supplierManage = supplierManageMapper.selectById(purchaseLedgerDto.getSupplierId());
+
+ // DTO杞珽ntity
+ PurchaseLedger purchaseLedger = new PurchaseLedger();
+ BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger);
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if(ObjectUtils.isNotEmpty(loginUser) && null != loginUser.getTenantId()) {
+ purchaseLedger.setTenantId(loginUser.getTenantId());
+ }
+ purchaseLedger.setSalesContractNo(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getSalesContractNo() : null);
+ 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) {
- return purchaseLedgerMapper.insert(purchaseLedger);
+ purchaseLedgerMapper.insert(purchaseLedger);
+// accountIncomeService.save(accountIncome);
+ accountExpenseService.save(accountExpense);
} else {
- return purchaseLedgerMapper.updateById(purchaseLedger);
+ 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. 澶勭悊瀛愯〃鏁版嵁
+ List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData();
+ if (productList != null && !productList.isEmpty()) {
+ handleSalesLedgerProducts(purchaseLedger.getId(), productList, purchaseLedgerDto.getType());
+ }
+
+ // 5. 杩佺Щ涓存椂鏂囦欢鍒版寮忕洰褰�
+ if (purchaseLedgerDto.getTempFileIds() != null && !purchaseLedgerDto.getTempFileIds().isEmpty()) {
+ migrateTempFilesToFormal(purchaseLedger.getId(), purchaseLedgerDto.getTempFileIds());
+ }
+
+ return 1;
+ }
+
+ private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) {
+ if (products == null || products.isEmpty()) {
+ throw new BaseException("浜у搧淇℃伅涓嶅瓨鍦�");
+ }
+
+ // 鎻愬墠鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑ID
+ Set<Long> productIds = products.stream()
+ .map(SalesLedgerProduct::getProductId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ Set<Long> modelIds = products.stream()
+ .map(SalesLedgerProduct::getProductModelId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+
+ // 涓�娆℃�ф煡璇骇鍝佸拰鍨嬪彿淇℃伅
+ Map<Long, String> productMap = new HashMap<>();
+ if (!productIds.isEmpty()) {
+ List<Product> productList = productMapper.selectBatchIds(productIds);
+ productList.forEach(p -> productMap.put(p.getId(), p.getProductName()));
+ }
+
+ Map<Long, String> modelMap = new HashMap<>();
+ if (!modelIds.isEmpty()) {
+ List<ProductModel> modelList = productModelMapper.selectBatchIds(modelIds);
+ modelList.forEach(m -> modelMap.put(m.getId(), m.getModel()));
+ }
+
+ // 璁剧疆瀛楁
+ for (SalesLedgerProduct product : products) {
+ product.setSalesLedgerId(salesLedgerId);
+
+ Long productId = product.getProductId();
+ if (productId != null && productMap.containsKey(productId)) {
+ product.setProductCategory(productMap.get(productId));
+ }
+
+ Long productModelId = product.getProductModelId();
+ if (productModelId != null && modelMap.containsKey(productModelId)) {
+ product.setSpecificationModel(modelMap.get(productModelId));
+ }
+ }
+
+ // 鍒嗙粍澶勭悊
+ Map<Boolean, List<SalesLedgerProduct>> partitionedProducts = products.stream()
+ .collect(Collectors.partitioningBy(p -> p.getId() != null));
+
+ List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
+ List<SalesLedgerProduct> insertList = partitionedProducts.get(false);
+ PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(salesLedgerId);
+
+ // 鎵ц鏇存柊鎿嶄綔
+ if (!updateList.isEmpty()) {
+ for (SalesLedgerProduct product : updateList) {
+ product.setType(type);
+ salesLedgerProductMapper.updateById(product);
+ }
+ }
+ // 鎵ц鎻掑叆鎿嶄綔
+ 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);
+ }
+ }
+
+ // 璁$畻鎬诲惈绋庨噾棰�
+ BigDecimal totalTaxInclusiveAmount = products.stream()
+ .map(SalesLedgerProduct::getTaxInclusiveTotalPrice)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ // 鏇存柊涓昏〃鐨勬�婚噾棰濆瓧娈�
+ if (salesLedgerId != null) {
+ // 鐩存帴鏇存柊鎸囧畾ID鐨勮褰曠殑contractAmount瀛楁涓簍otalTaxInclusiveAmount
+ purchaseLedgerMapper.updateContractAmountById(salesLedgerId, totalTaxInclusiveAmount);
+ }
+ }
+
+ /**
+ * 灏嗕复鏃舵枃浠惰縼绉诲埌姝e紡鐩綍
+ *
+ * @param businessId 涓氬姟ID锛堥攢鍞彴璐D锛�
+ * @param tempFileIds 涓存椂鏂囦欢ID鍒楄〃
+ * @throws IOException 鏂囦欢鎿嶄綔寮傚父
+ */
+ private void migrateTempFilesToFormal(Long businessId, List<String> tempFileIds) throws IOException {
+ if (CollectionUtils.isEmpty(tempFileIds)) {
+ return;
+ }
+
+ // 鏋勫缓姝e紡鐩綍璺緞锛堟寜涓氬姟绫诲瀷鍜屾棩鏈熷垎缁勶級
+ String formalDir = uploadDir + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
+
+ Path formalDirPath = Paths.get(formalDir);
+
+ // 纭繚姝e紡鐩綍瀛樺湪锛堥�掑綊鍒涘缓锛�
+ if (!Files.exists(formalDirPath)) {
+ Files.createDirectories(formalDirPath);
+ }
+
+ for (String tempFileId : tempFileIds) {
+ // 鏌ヨ涓存椂鏂囦欢璁板綍
+ TempFile tempFile = tempFileMapper.selectById(tempFileId);
+ if (tempFile == null) {
+ log.warn("涓存椂鏂囦欢涓嶅瓨鍦紝璺宠繃澶勭悊: {}", tempFileId);
+ continue;
+ }
+
+ // 鏋勫缓姝e紡鏂囦欢鍚嶏紙鍖呭惈涓氬姟ID鍜屾椂闂存埑锛岄伩鍏嶅啿绐侊級
+ String originalFilename = tempFile.getOriginalName();
+ String fileExtension = FilenameUtils.getExtension(originalFilename);
+ String formalFilename = businessId + "_" +
+ System.currentTimeMillis() + "_" +
+ UUID.randomUUID().toString().substring(0, 8) +
+ (StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
+
+ Path formalFilePath = formalDirPath.resolve(formalFilename);
+
+ try {
+ // 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
+// 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锛�
+ CommonFile fileRecord = new CommonFile();
+ fileRecord.setCommonId(businessId);
+ fileRecord.setName(originalFilename);
+ fileRecord.setUrl(formalFilePath.toString());
+ fileRecord.setCreateTime(LocalDateTime.now());
+ fileRecord.setType(FileNameType.PURCHASE.getValue());
+ commonFileMapper.insert(fileRecord);
+
+ // 鍒犻櫎涓存椂鏂囦欢璁板綍
+ tempFileMapper.deleteById(tempFile);
+
+ log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
+ } catch (IOException e) {
+ log.error("鏂囦欢杩佺Щ澶辫触: {}", tempFile.getTempPath(), e);
+ // 鍙�夋嫨鍥炴粴浜嬪姟鎴栬褰曞け璐ユ枃浠�
+ throw new IOException("鏂囦欢杩佺Щ寮傚父", e);
+ }
}
}
@Override
public int deletePurchaseLedgerByIds(Long[] ids) {
+ if (ids == null || ids.length == 0) {
+ throw new BaseException("璇烽�変腑鑷冲皯涓�鏉℃暟鎹�");
+ }
+ // 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︿骇鍝�
+ LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, ids)
+ .eq(SalesLedgerProduct::getType, 2);
+ salesLedgerProductMapper.delete(queryWrapper);
+ // 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︾殑鏉ョエ鐧昏
+ LambdaQueryWrapper<TicketRegistration> ticketRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getSalesLedgerId,ids);
+ ticketRegistrationMapper.delete(ticketRegistrationLambdaQueryWrapper);
+ // 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︾殑鏉ョエ鐧昏璁板綍
+ LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ productRecordLambdaQueryWrapper.in(ProductRecord::getPurchaseLedgerId,ids);
+ productRecordMapper.delete(productRecordLambdaQueryWrapper);
+ // 鎵归噺鍒犻櫎閲囪喘鍙拌处
return purchaseLedgerMapper.deleteBatchIds(Arrays.asList(ids));
}
+
+ @Override
+ public PurchaseLedgerDto getPurchaseById(PurchaseLedgerDto purchaseLedgerDto) {
+ // 1. 鏌ヨ涓昏〃
+ PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(purchaseLedgerDto.getId());
+ if (purchaseLedger == null) {
+ throw new BaseException("閲囪喘鍙拌处涓嶅瓨鍦�");
+ }
+
+ // 2. 鏌ヨ瀛愯〃
+ LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
+ productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId())
+ .eq(SalesLedgerProduct::getType, purchaseLedgerDto.getType());
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper);
+
+ // 3.鏌ヨ涓婁紶鏂囦欢
+ LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
+ salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId());
+ List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
+
+ // 4. 杞崲 DTO
+ PurchaseLedgerDto resultDto = new PurchaseLedgerDto();
+ BeanUtils.copyProperties(purchaseLedger, resultDto);
+ if (!products.isEmpty()) {
+ resultDto.setHasChildren(true);
+ resultDto.setProductData(products);
+ resultDto.setSalesLedgerFiles(salesLedgerFiles);
+ }
+ return resultDto;
+ }
+
+ @Override
+ public List getProduct(PurchaseLedgerDto purchaseLedgerDto) {
+ LambdaQueryWrapper<PurchaseLedger> queryWrapper = Wrappers.lambdaQuery();
+ queryWrapper.select(PurchaseLedger::getId, PurchaseLedger::getPurchaseContractNumber);
+
+ // 鑾峰彇鍘熷鏌ヨ缁撴灉
+ List<Map<String, Object>> result = purchaseLedgerMapper.selectMaps(queryWrapper);
+
+ // 灏嗕笅鍒掔嚎鍛藉悕杞崲涓洪┘宄板懡鍚�
+ return result.stream().map(map -> map.entrySet().stream()
+ .collect(Collectors.toMap(
+ entry -> underlineToCamel(entry.getKey()),
+ Map.Entry::getValue))
+ ).collect(Collectors.toList());
+ }
+
+ @Override
+ public PurchaseLedgerDto getInfo(PurchaseLedgerDto purchaseLedgerDto) {
+ PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(purchaseLedgerDto.getId());
+ if (purchaseLedger == null) {
+ throw new BaseException("閲囪喘鍙拌处涓嶅瓨鍦�");
+ }
+ // 鍒涘缓骞跺~鍏匘TO
+ PurchaseLedgerDto resultDto = new PurchaseLedgerDto();
+ resultDto.setSalesLedgerId(purchaseLedger.getSalesLedgerId());
+ resultDto.setSalesContractNoId(purchaseLedger.getSalesLedgerId());
+ resultDto.setSalesContractNo(purchaseLedger.getSalesContractNo());
+ resultDto.setSupplierName(purchaseLedger.getSupplierName());
+ resultDto.setProjectName(purchaseLedger.getProjectName());
+
+ // 鏌ヨ骞惰缃叧鑱斾骇鍝�
+ LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId())
+ .eq(SalesLedgerProduct::getType, 2);
+ List<SalesLedgerProduct> productList = salesLedgerProductMapper.selectList(queryWrapper);
+ productList.forEach(product -> {
+ product.setFutureTickets(product.getFutureTickets() != null ? product.getFutureTickets() : product.getQuantity());
+ product.setFutureTicketsAmount(product.getFutureTicketsAmount() != null ? product.getFutureTicketsAmount() : product.getTaxInclusiveTotalPrice());
+ product.setTicketsNum(null);
+ product.setTicketsAmount(null);
+ product.setTempFutureTickets(product.getFutureTickets());
+ product.setTempFutureTicketsAmount(product.getFutureTicketsAmount());
+ });
+ resultDto.setProductData(productList);
+ return resultDto;
+ }
+
+ @Override
+ public List getPurchasesNo() {
+ LambdaQueryWrapper<PurchaseLedger> queryWrapper = Wrappers.lambdaQuery();
+ queryWrapper.select(PurchaseLedger::getId, PurchaseLedger::getPurchaseContractNumber, PurchaseLedger::getSupplierId);
+
+ // 鑾峰彇鍘熷鏌ヨ缁撴灉
+ List<Map<String, Object>> result = purchaseLedgerMapper.selectMaps(queryWrapper);
+
+ // 灏嗕笅鍒掔嚎鍛藉悕杞崲涓洪┘宄板懡鍚�
+ return result.stream().map(map -> map.entrySet().stream()
+ .collect(Collectors.toMap(
+ entry -> underlineToCamel(entry.getKey()),
+ Map.Entry::getValue))
+ ).collect(Collectors.toList());
+ }
+
+ @Override
+ 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) {
+// purchaseLedgerDto.setInvoiceNumber(ticketRegistration.getInvoiceNumber());
+// purchaseLedgerDto.setInvoiceAmount(ticketRegistration.getInvoiceAmount());
+// purchaseLedgerDto.setTicketRegistrationId(ticketRegistration.getId());
+// }
+ return purchaseLedgerDto;
+ }
+
+ @Override
+ 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
+ public List<InvoiceRegistrationProduct> getProductBySalesNo(Long id) {
+ List<InvoiceRegistrationProduct> invoiceRegistrationProducts = invoiceRegistrationProductMapper.selectList(new LambdaQueryWrapper<InvoiceRegistrationProduct>()
+ .select(InvoiceRegistrationProduct::getId, InvoiceRegistrationProduct::getProductCategory, InvoiceRegistrationProduct::getSpecificationModel,
+ InvoiceRegistrationProduct::getUnit, InvoiceRegistrationProduct::getQuantity)
+ .eq(InvoiceRegistrationProduct::getSalesLedgerId, id));
+ if (invoiceRegistrationProducts.isEmpty()) {
+ return new ArrayList<>();
+ }
+ 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);
+ }
+
+ /**
+ * 涓嬪垝绾垮懡鍚嶈浆椹煎嘲鍛藉悕
+ */
+ private String underlineToCamel(String param) {
+ if (param == null || "".equals(param.trim())) {
+ return "";
+ }
+ int len = param.length();
+ StringBuilder sb = new StringBuilder(len);
+ for (int i = 0; i < len; i++) {
+ char c = param.charAt(i);
+ if (c == '_') {
+ if (++i < len) {
+ sb.append(Character.toUpperCase(param.charAt(i)));
+ }
+ } else {
+ sb.append(Character.toLowerCase(c));
+ }
+ }
+ return sb.toString();
+ }
}
--
Gitblit v1.9.3