From 667d59e59a94fdbcb168904fbf40a011e15acc98 Mon Sep 17 00:00:00 2001 From: liyong <18434998025@163.com> Date: 星期二, 24 六月 2025 17:33:05 +0800 Subject: [PATCH] 2025-06-23 付款方式字段添加, 附件上传接口对接完成 --- src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 63 ++++++++++++++++++++++++++----- 1 files changed, 52 insertions(+), 11 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 94066bb..d8518a3 100644 --- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java +++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java @@ -12,6 +12,7 @@ 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.SecurityUtils; import com.ruoyi.common.utils.StringUtils; @@ -28,10 +29,9 @@ import com.ruoyi.purchase.pojo.PurchaseLedger; import com.ruoyi.purchase.pojo.TicketRegistration; import com.ruoyi.purchase.service.IPurchaseLedgerService; -import com.ruoyi.sales.mapper.CommonFileMapper; -import com.ruoyi.sales.mapper.SalesLedgerMapper; -import com.ruoyi.sales.mapper.SalesLedgerProductMapper; +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; @@ -39,6 +39,7 @@ 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 java.io.IOException; @@ -51,6 +52,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -85,6 +87,10 @@ private final ProductRecordMapper productRecordMapper; + private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper; + + private final StringRedisTemplate redisTemplate; + @Value("${file.upload-dir}") private String uploadDir; @@ -111,7 +117,7 @@ BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger); LoginUser loginUser = SecurityUtils.getLoginUser(); if(ObjectUtils.isNotEmpty(loginUser) && null != loginUser.getTenantId()) { - purchaseLedger.setTenantId(loginUser.getTenantId().longValue()); + purchaseLedger.setTenantId(loginUser.getTenantId()); } purchaseLedger.setSalesContractNo(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getSalesContractNo() : null); purchaseLedger.setSupplierName(supplierManage.getSupplierName()); @@ -275,7 +281,7 @@ fileRecord.setName(originalFilename); fileRecord.setUrl(formalFilePath.toString()); fileRecord.setCreateTime(LocalDateTime.now()); - fileRecord.setType("2"); + fileRecord.setType(FileNameType.PURCHASE.getValue()); commonFileMapper.insert(fileRecord); // 鍒犻櫎涓存椂鏂囦欢璁板綍 @@ -298,7 +304,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<>(); @@ -366,6 +372,7 @@ } // 鍒涘缓骞跺~鍏匘TO PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); + resultDto.setSalesLedgerId(purchaseLedger.getSalesLedgerId()); resultDto.setSalesContractNoId(purchaseLedger.getSalesLedgerId()); resultDto.setSalesContractNo(purchaseLedger.getSalesContractNo()); resultDto.setSupplierName(purchaseLedger.getSupplierName()); @@ -408,6 +415,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) { @@ -419,12 +427,45 @@ } @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()); + 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 purchaseLedgerMapper.selectPage(ipage, queryWrapper); + 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