| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.account.service.impl.purchase; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.xiaoymin.knife4j.core.util.CollectionUtils; |
| | | import com.ruoyi.account.bean.dto.purchase.AccountPurchasePaymentDto; |
| | | import com.ruoyi.account.bean.vo.purchase.AccountPurchasePaymentVo; |
| | | import com.ruoyi.account.mapper.AccountStatementDetailsMapper; |
| | | import com.ruoyi.account.mapper.purchase.AccountPaymentApplicationMapper; |
| | | import com.ruoyi.account.mapper.purchase.AccountPurchasePaymentMapper; |
| | | import com.ruoyi.account.pojo.AccountStatementDetails; |
| | | import com.ruoyi.account.pojo.purchase.AccountPaymentApplication; |
| | | import com.ruoyi.account.pojo.purchase.AccountPurchasePayment; |
| | | import com.ruoyi.account.service.purchase.AccountPurchasePaymentService; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * <p> |
| | | * è´¢å¡ç®¡ç--仿¬¾å æå¡å®ç°ç±» |
| | | * </p> |
| | | * |
| | | * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå
¬å¸ |
| | | * @since 2026-05-19 04:14:51 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class AccountPurchasePaymentServiceImpl extends ServiceImpl<AccountPurchasePaymentMapper, AccountPurchasePayment> implements AccountPurchasePaymentService { |
| | | |
| | | private static final DateTimeFormatter CODE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss"); |
| | | private final AccountPurchasePaymentMapper accountPurchasePaymentMapper; |
| | | private final AccountStatementDetailsMapper accountStatementDetailsMapper; |
| | | private final AccountPaymentApplicationMapper accountPaymentApplicationMapper; |
| | | |
| | | @Override |
| | | public IPage<AccountPurchasePaymentVo> listPageAccountPurchasePayment(Page page, AccountPurchasePaymentDto accountPurchasePaymentDto) { |
| | | return accountPurchasePaymentMapper.listPageAccountPurchasePayment(page, accountPurchasePaymentDto); |
| | | } |
| | | |
| | | @Override |
| | | public boolean addAccountPurchasePayment(AccountPurchasePayment accountPurchasePayment) { |
| | | if (StringUtils.isEmpty(accountPurchasePayment.getPaymentNumber())) { |
| | | accountPurchasePayment.setPaymentNumber(genAccountPurchasePaymentNo()); |
| | | } |
| | | //æ ¡éªç´¯è®¡ä»æ¬¾éé¢ä¸è½è¶
è¿ç³è¯·éé¢ |
| | | AccountPaymentApplication accountPaymentApplication = accountPaymentApplicationMapper.selectById(accountPurchasePayment.getAccountPaymentApplicationId()); |
| | | List<AccountPurchasePayment> accountPurchasePayments = accountPurchasePaymentMapper.selectList(Wrappers.<AccountPurchasePayment>lambdaQuery().eq(AccountPurchasePayment::getAccountPaymentApplicationId, accountPurchasePayment.getAccountPaymentApplicationId())); |
| | | BigDecimal totalPaymentAmount = accountPurchasePayments.stream().map(AccountPurchasePayment::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (accountPaymentApplication.getPaymentAmount().compareTo(totalPaymentAmount) < 0) { |
| | | throw new ServiceException("ç´¯è®¡ä»æ¬¾éé¢ä¸è½è¶
è¿ç³è¯·éé¢"); |
| | | } |
| | | return save(accountPurchasePayment); |
| | | } |
| | | |
| | | @Override |
| | | public void exportAccountPurchasePayment(HttpServletResponse response, AccountPurchasePaymentDto accountPurchasePaymentDto) { |
| | | List<AccountPurchasePaymentVo> list = accountPurchasePaymentMapper.listPageAccountPurchasePayment(new Page(1,-1),accountPurchasePaymentDto).getRecords(); |
| | | ExcelUtil<AccountPurchasePaymentVo> util = new ExcelUtil<>(AccountPurchasePaymentVo.class); |
| | | util.exportExcel(response, list , "仿¬¾å"); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteAccountPurchasePayment(List<Long> ids) { |
| | | //å¦æè¯¥ä»æ¬¾åå·²ç»çæå¯¹è´¦ååæ æ³å é¤ |
| | | List<AccountPurchasePayment> accountPurchasePayments = accountPurchasePaymentMapper.selectByIds(ids); |
| | | List<String> strings = accountPurchasePayments.stream().map(AccountPurchasePayment::getPaymentNumber).toList(); |
| | | List<AccountStatementDetails> accountStatementDetails = accountStatementDetailsMapper.selectList(Wrappers.<AccountStatementDetails>lambdaQuery() |
| | | .in(AccountStatementDetails::getReceiptNumber, strings)); |
| | | if (CollectionUtils.isNotEmpty(accountStatementDetails)){ |
| | | throw new ServiceException("è¯¥ä»æ¬¾åå·²ç»çæå¯¹è´¦åï¼æ æ³å é¤"); |
| | | } |
| | | return removeByIds(ids); |
| | | } |
| | | |
| | | private String genAccountPurchasePaymentNo() { |
| | | return "SK" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10); |
| | | } |
| | | } |