| | |
| | | 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.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; |
| | |
| | | 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; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | private final ProductRecordMapper productRecordMapper; |
| | | |
| | | private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper; |
| | | |
| | | private final StringRedisTemplate redisTemplate; |
| | | |
| | | @Value("${file.upload-dir}") |
| | | private String uploadDir; |
| | | |
| | |
| | | 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()); |
| | |
| | | return purchaseLedgerDto; |
| | | } |
| | | |
| | | @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()); |
| | | } |
| | | return purchaseLedgerMapper.selectPage(ipage, queryWrapper); |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | | * 下划线命名转驼峰命名 |
| | | */ |