From 78c0d6c79dcd5a8e2e2f99199dbcf5504fe8687b Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期六, 24 五月 2025 15:45:56 +0800 Subject: [PATCH] 采购管理模块 --- src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java | 152 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 124 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java index b14b4f2..2d78a62 100644 --- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java +++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java @@ -1,26 +1,34 @@ package com.ruoyi.purchase.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.basic.mapper.SupplierManageMapper; +import com.ruoyi.basic.pojo.SupplierManage; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.framework.security.LoginUser; +import com.ruoyi.purchase.dto.PaymentLedgerDto; import com.ruoyi.purchase.dto.PaymentRegistrationDto; -import com.ruoyi.purchase.mapper.InvoicePurchaseMapper; -import com.ruoyi.purchase.mapper.PaymentRegistrationMapper; -import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; -import com.ruoyi.purchase.pojo.InvoicePurchase; +import com.ruoyi.purchase.mapper.*; import com.ruoyi.purchase.pojo.PaymentRegistration; +import com.ruoyi.purchase.pojo.ProductRecord; import com.ruoyi.purchase.pojo.PurchaseLedger; +import com.ruoyi.purchase.pojo.TicketRegistration; import com.ruoyi.purchase.service.IPaymentRegistrationService; import com.ruoyi.sales.mapper.SalesLedgerMapper; +import com.ruoyi.sales.mapper.SalesLedgerProductMapper; import com.ruoyi.sales.pojo.SalesLedger; -import org.springframework.beans.factory.annotation.Autowired; +import com.ruoyi.sales.pojo.SalesLedgerProduct; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import java.math.BigDecimal; -import java.util.List; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; /** * 浠樻鐧昏Service涓氬姟灞傚鐞� @@ -29,21 +37,23 @@ * @date 2025-05-15 */ @Service +@AllArgsConstructor public class PaymentRegistrationServiceImpl extends ServiceImpl<PaymentRegistrationMapper, PaymentRegistration> implements IPaymentRegistrationService { - @Autowired private PaymentRegistrationMapper paymentRegistrationMapper; - @Autowired private PurchaseLedgerMapper purchaseLedgerMapper; - @Autowired private InvoicePurchaseMapper invoicePurchaseMapper; - @Autowired private SalesLedgerMapper salesLedgerMapper; - @Autowired private SupplierManageMapper supplierManageMapper; + + private SalesLedgerProductMapper salesLedgerProductMapper; + + private TicketRegistrationMapper ticketRegistrationMapper; + + private ProductRecordMapper productRecordMapper; /** * 鏌ヨ浠樻鐧昏 @@ -67,7 +77,7 @@ List<PaymentRegistrationDto> list = paymentRegistrationMapper.selectPaymentRegistrationList(paymentRegistrationDto); for (PaymentRegistrationDto registrationDto : list) { List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() - .eq("invoice_purchase_id", registrationDto.getInvoicePurchaseId())); + .eq("ticket_registration_id", registrationDto.getTicketRegistrationId())); BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); registrationDto.setUnPaymentAmount(registrationDto.getInvoiceAmount().subtract(total)); } @@ -92,25 +102,24 @@ paymentRegistration.setSaleLedgerId(salesLedger.getId()); paymentRegistration.setSupplierId(purchaseLedger.getSupplierId()); - List<InvoicePurchase> invoicePurchases = invoicePurchaseMapper.selectList(new QueryWrapper<InvoicePurchase>(). - eq("purchase_contract_no", purchaseLedger.getPurchaseContractNumber())); - if (invoicePurchases == null || invoicePurchases.size() == 0) { + TicketRegistration tr = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getId, paymentRegistration.getTicketRegistrationId())); + + if (tr == null) { throw new RuntimeException("鍏宠仈鍙戠エ涓嶅瓨鍦�"); } - paymentRegistration.setInvoicePurchaseId(invoicePurchases.get(0).getId()); List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() - .eq("invoice_purchase_id", invoicePurchases.get(0).getId())); + .eq("ticket_registration_id", tr.getId())); BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); - if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(invoicePurchases.get(0).getInvoiceAmount()) > 0) { + if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(tr.getInvoiceAmount()) > 0) { throw new RuntimeException("浠樻閲戦瓒呭嚭鍙戠エ閲戦"); } - LoginUser loginUser = SecurityUtils.getLoginUser(); Integer tenantId = loginUser.getTenantId(); paymentRegistration.setTenantId(tenantId.longValue()); + paymentRegistration.setRegistrantId(loginUser.getUserId()); paymentRegistration.setCreateTime(DateUtils.getNowDate()); paymentRegistration.setUpdateTime(DateUtils.getNowDate()); return paymentRegistrationMapper.insert(paymentRegistration); @@ -124,13 +133,13 @@ */ @Override public int updatePaymentRegistration(PaymentRegistration paymentRegistration) { - InvoicePurchase invoicePurchase = invoicePurchaseMapper.selectById(paymentRegistration.getInvoicePurchaseId()); + TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()); List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() - .eq("invoice_purchase_id", paymentRegistration.getInvoicePurchaseId()).ne("id", paymentRegistration.getId())); + .eq("ticket_registration_id", paymentRegistration.getTicketRegistrationId()).ne("id", paymentRegistration.getId())); BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); - if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(invoicePurchase.getInvoiceAmount()) > 0) { + if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(ticketRegistration.getInvoiceAmount()) > 0) { throw new RuntimeException("浠樻閲戦瓒呭嚭鍙戠エ閲戦"); } @@ -157,13 +166,100 @@ paymentRegistrationDto.setSupplierName(purchaseLedger.getSupplierName()); paymentRegistrationDto.setSupplierId(purchaseLedger.getSupplierId()); - List<InvoicePurchase> invoicePurchaseList = invoicePurchaseMapper.selectList(new QueryWrapper<InvoicePurchase>() - .eq("purchase_contract_no", purchaseLedger.getPurchaseContractNumber())); - if (invoicePurchaseList != null && invoicePurchaseList.size() > 0) { - paymentRegistrationDto.setInvoiceNumber(invoicePurchaseList.get(0).getInvoiceNumber()); - paymentRegistrationDto.setInvoiceAmount(invoicePurchaseList.get(0).getInvoiceAmount()); - paymentRegistrationDto.setTaxRate(invoicePurchaseList.get(0).getTaxRate()); + List<TicketRegistration> ticketRegistrations = ticketRegistrationMapper.selectList(new QueryWrapper<TicketRegistration>() + .eq("purchase_contract_number", purchaseLedger.getPurchaseContractNumber())); + if (ticketRegistrations != null && ticketRegistrations.size() > 0) { + paymentRegistrationDto.setInvoiceNumber(ticketRegistrations.get(0).getInvoiceNumber()); + paymentRegistrationDto.setInvoiceAmount(ticketRegistrations.get(0).getInvoiceAmount()); } return paymentRegistrationDto; } + + @Override + public List<Map<String, Object>> selectPaymentLedgerList(PaymentLedgerDto paymentLedgerDto) { + List<Map<String, Object>> result = new ArrayList<>(); + LambdaQueryWrapper<SupplierManage> queryWrapper = new LambdaQueryWrapper<>(); + Optional.ofNullable(paymentLedgerDto) + .ifPresent(dto -> { + if (StringUtils.hasText(dto.getSupplierName())) { + queryWrapper.like(SupplierManage::getSupplierName, dto.getSupplierName()); + } + }); + + List<SupplierManage> supplierManages = supplierManageMapper.selectList(queryWrapper); + + for (SupplierManage supplierManage : supplierManages) { + Map<String, Object> res = new HashMap<>(); + res.put("supplierName", supplierManage.getSupplierName()); + + // 搴斾粯閲戦 + BigDecimal payableAmount = BigDecimal.ZERO; + List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(new QueryWrapper<PurchaseLedger>().eq("supplier_id", supplierManage.getId())); + if (purchaseLedgers != null && purchaseLedgers.size() > 0) { + List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>() + .in("sales_ledger_id", purchaseLedgers.stream().map(PurchaseLedger::getId).collect(Collectors.toList()))); + // 搴斾粯閲戦 + payableAmount = salesLedgerProducts.stream().map(SalesLedgerProduct::getTaxInclusiveTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add); + + } + + BigDecimal invoiceAmount = BigDecimal.ZERO; + List<TicketRegistration> ticketRegistrations = Collections.emptyList(); + + // 澧炲姞绌哄�兼鏌ワ紝閬垮厤NullPointerException + if (CollectionUtils.isNotEmpty(purchaseLedgers)) { + Long[] ids = purchaseLedgers.stream() + .map(PurchaseLedger::getId) + .toArray(Long[]::new); + + // 妫�鏌ユ暟缁勬槸鍚︽湁鍏冪礌 + if (ids.length > 0) { + ticketRegistrations = ticketRegistrationMapper.selectList( + new LambdaQueryWrapper<TicketRegistration>() + .in(TicketRegistration::getPurchaseLedgerId, ids) + ); + } + } + if (ticketRegistrations != null && ticketRegistrations.size() > 0) { + // 鏉ョエ閲戦 + invoiceAmount = ticketRegistrations.stream().map(TicketRegistration::getInvoiceAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + } + // 浠樻閲戦 + List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() + .eq("supplier_id", supplierManage.getId())); + + BigDecimal paymentAmount = BigDecimal.ZERO; + if (paymentRegistrations != null && paymentRegistrations.size() > 0) { + paymentAmount = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + } + + res.put("invoiceAmount", invoiceAmount); + res.put("payableAmount", payableAmount); + res.put("paymentAmount", paymentAmount); + + // 璇︽儏 + List<Map<String, Object>> details = new ArrayList<>(); + for (PaymentRegistration paymentRegistration : paymentRegistrations) { + Map<String, Object> detail = new HashMap<>(); + detail.put("paymentAmount", paymentRegistration.getCurrentPaymentAmount()); // 浠樻閲戦 + TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()); + detail.put("payableAmount", ticketRegistration.getInvoiceAmount()); // 搴斾粯閲戦 + BigDecimal voteCount = productRecordMapper.selectList( + new LambdaQueryWrapper<ProductRecord>() + .eq(ProductRecord::getTicketRegistrationId, ticketRegistration.getId())) + .stream() + .map(ProductRecord::getTicketsNum) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + detail.put("voteCount", voteCount); // 绁ㄦ暟 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String formattedDate = sdf.format(paymentRegistration.getPaymentDate()); + detail.put("paymentDate", formattedDate); // 鍙戠敓鏃堕棿 + details.add(detail); + } + res.put("details", details); + result.add(res); + } + return result; + } } -- Gitblit v1.9.3