¶Ô±ÈÐÂÎļþ |
| | |
| | | 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.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.pojo.PaymentRegistration; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | 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 com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 仿¬¾ç»è®°Serviceä¸å¡å±å¤ç |
| | | * |
| | | * @author ruoyi |
| | | * @date 2025-05-15 |
| | | */ |
| | | @Service |
| | | 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; |
| | | |
| | | @Autowired |
| | | private SalesLedgerProductMapper salesLedgerProductMapper; |
| | | |
| | | /** |
| | | * æ¥è¯¢ä»æ¬¾ç»è®° |
| | | * |
| | | * @param id 仿¬¾ç»è®°ä¸»é® |
| | | * @return 仿¬¾ç»è®° |
| | | */ |
| | | @Override |
| | | public PaymentRegistration selectPaymentRegistrationById(Long id) { |
| | | return paymentRegistrationMapper.selectPaymentRegistrationById(id); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢ä»æ¬¾ç»è®°å表 |
| | | * |
| | | * @param paymentRegistrationDto 仿¬¾ç»è®° |
| | | * @return 仿¬¾ç»è®° |
| | | */ |
| | | @Override |
| | | public List<PaymentRegistrationDto> selectPaymentRegistrationList(PaymentRegistrationDto paymentRegistrationDto) { |
| | | List<PaymentRegistrationDto> list = paymentRegistrationMapper.selectPaymentRegistrationList(paymentRegistrationDto); |
| | | for (PaymentRegistrationDto registrationDto : list) { |
| | | List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() |
| | | .eq("invoice_purchase_id", registrationDto.getInvoicePurchaseId())); |
| | | BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | registrationDto.setUnPaymentAmount(registrationDto.getInvoiceAmount().subtract(total)); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢ä»æ¬¾ç»è®° |
| | | * |
| | | * @param paymentRegistration 仿¬¾ç»è®° |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertPaymentRegistration(PaymentRegistration paymentRegistration) { |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(paymentRegistration.getPurchaseLedgerId()); |
| | | SalesLedger salesLedger = salesLedgerMapper.selectOne(new QueryWrapper<SalesLedger>(). |
| | | eq("sales_contract_no", purchaseLedger.getSalesContractNo())); |
| | | if (salesLedger == null) { |
| | | throw new RuntimeException("å
³èéå®ååå·ä¸åå¨"); |
| | | } |
| | | |
| | | 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) { |
| | | 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())); |
| | | BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(invoicePurchases.get(0).getInvoiceAmount()) > 0) { |
| | | throw new RuntimeException("仿¬¾éé¢è¶
åºå票éé¢"); |
| | | } |
| | | |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | Integer tenantId = loginUser.getTenantId(); |
| | | paymentRegistration.setTenantId(tenantId.longValue()); |
| | | paymentRegistration.setCreateTime(DateUtils.getNowDate()); |
| | | paymentRegistration.setUpdateTime(DateUtils.getNowDate()); |
| | | return paymentRegistrationMapper.insert(paymentRegistration); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä»æ¬¾ç»è®° |
| | | * |
| | | * @param paymentRegistration 仿¬¾ç»è®° |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updatePaymentRegistration(PaymentRegistration paymentRegistration) { |
| | | InvoicePurchase invoicePurchase = invoicePurchaseMapper.selectById(paymentRegistration.getInvoicePurchaseId()); |
| | | |
| | | List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() |
| | | .eq("invoice_purchase_id", paymentRegistration.getInvoicePurchaseId()).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) { |
| | | throw new RuntimeException("仿¬¾éé¢è¶
åºå票éé¢"); |
| | | } |
| | | |
| | | paymentRegistration.setUpdateTime(DateUtils.getNowDate()); |
| | | return paymentRegistrationMapper.updateById(paymentRegistration); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤ä»æ¬¾ç»è®° |
| | | * |
| | | * @param ids éè¦å é¤ç仿¬¾ç»è®°ä¸»é® |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deletePaymentRegistrationByIds(Long[] ids) { |
| | | return paymentRegistrationMapper.delete(new QueryWrapper<PaymentRegistration>().in("id", ids)); |
| | | } |
| | | |
| | | @Override |
| | | public PaymentRegistration selectPaymentRegistrationByPurchaseId(Long id) { |
| | | PaymentRegistrationDto paymentRegistrationDto = new PaymentRegistrationDto(); |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(id); |
| | | paymentRegistrationDto.setSalesContractNo(purchaseLedger.getSalesContractNo()); |
| | | 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()); |
| | | } |
| | | 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<SalesLedger> salesLedgers = salesLedgerMapper.selectList(new QueryWrapper<SalesLedger>().eq("customer_id", supplierManage.getId())); |
| | | if (salesLedgers != null && salesLedgers.size() > 0) { |
| | | List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>() |
| | | .in("sales_ledger_id", salesLedgers.stream().map(SalesLedger::getId).collect(Collectors.toList()))); |
| | | // åºä»éé¢ |
| | | payableAmount = salesLedgerProducts.stream().map(SalesLedgerProduct::getTaxInclusiveTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | } |
| | | |
| | | // å¼ç¥¨éé¢ |
| | | BigDecimal invoiceAmount = salesLedgers.stream().map(SalesLedger::getContractAmount).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("voteCount", 1); // 票æ°ï¼æªç¥æ°æ®æºï¼ææ¶ç¨1 |
| | | detail.put("paymentAmount", paymentRegistration.getCurrentPaymentAmount()); // 仿¬¾éé¢ |
| | | InvoicePurchase invoicePurchase = invoicePurchaseMapper.selectById(paymentRegistration.getInvoicePurchaseId()); |
| | | detail.put("payableAmount", invoicePurchase.getInvoiceAmount()); // åºä»éé¢ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String formattedDate = sdf.format(paymentRegistration.getPaymentDate()); |
| | | detail.put("createTime", formattedDate); // åçæ¶é´ |
| | | details.add(detail); |
| | | } |
| | | |
| | | res.put("details", paymentRegistrations); |
| | | |
| | | result.add(res); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | } |