From 5a423dfede4ee5caa88adf95ec52d35a85072321 Mon Sep 17 00:00:00 2001 From: buhuazhen <hua100783@gmail.com> Date: 星期三, 27 八月 2025 14:35:29 +0800 Subject: [PATCH] Merge branch 'feature/0826' into pim-jlmy --- main-business/src/main/java/com/ruoyi/business/service/impl/DuePayableServiceImpl.java | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 114 insertions(+), 0 deletions(-) diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/DuePayableServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/DuePayableServiceImpl.java new file mode 100644 index 0000000..2ede66f --- /dev/null +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/DuePayableServiceImpl.java @@ -0,0 +1,114 @@ +package com.ruoyi.business.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.basic.entity.dto.SimpleStorageDto; +import com.ruoyi.basic.service.StorageBlobService; +import com.ruoyi.business.dto.DuePayableDto; +import com.ruoyi.business.entity.DuePayable; +import com.ruoyi.business.mapper.DuePayableMapper; +import com.ruoyi.business.service.DuePayableService; +import com.ruoyi.business.vo.DuePayableVo; +import com.ruoyi.business.vo.SearchDuePurchaseVo; +import com.ruoyi.common.utils.StringUtils; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author buhuazhen + * @description 閽堝琛ㄣ�恉ue_payable(搴斾粯娆捐〃)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇 + * @createDate 2025-08-26 16:12:56 + */ +@Service +@RequiredArgsConstructor +public class DuePayableServiceImpl extends ServiceImpl<DuePayableMapper, DuePayable> + implements DuePayableService { + private final StorageBlobService storageBlobService; + private final DuePayableMapper duePayableMapper; + + @Getter + @Value("${minio.default-bucket}") + private String defaultBucket; + + @Override + public int addDuePayable(DuePayableDto dto) { + DuePayable duePayable = new DuePayable(); + duePayable.setPayableType(dto.getPayableType()); + duePayable.setAttachUpload(dto.getAttachUpload()); + duePayable.setPurchaseRegistrationId(dto.getPurchaseRegistrationId()); + duePayable.setPaymentAmount(new BigDecimal(dto.getPaymentAmount())); + duePayable.setTicketNo(dto.getTicketNo()); + duePayable.setId(dto.getId()); + + if (Objects.isNull(dto.getId())) { + return duePayableMapper.insert(duePayable); + } + + return duePayableMapper.updateById(duePayable); + } + + @Override + public IPage<DuePayableVo> selectPayableList(Page<DuePayable> page, SearchDuePurchaseVo vo) { + LambdaQueryWrapper<DuePayable> queryWrapper = new LambdaQueryWrapper<>(); + // todo 鎼滅储鏉′欢鏆傛椂涓嶇煡閬撴槸浠�涔堭煠� + queryWrapper.orderByDesc(DuePayable::getCreateTime); + + Page<DuePayable> duePayablePage = duePayableMapper.selectPage(page, queryWrapper); + /** + * 鏌ヨ鍑洪檮浠秈d 鐢变簬鍚庣画璇︾粏 + */ + Map<Long, List<Long>> attachMap = duePayablePage.getRecords().stream() + .collect(Collectors.toMap( + DuePayable::getId, + it -> { + if (StringUtils.isNotBlank(it.getAttachUpload())) { + return Arrays.stream(it.getAttachUpload().split(",")) + .map(Long::parseLong) + .collect(Collectors.toList()); + } else { + return List.of(); + } + } + )); + /** + * 鏍规嵁涓婇潰鐨刬ds 鏌ヨ鍑哄叿浣撲俊鎭� + */ + Map<Long,SimpleStorageDto> storageMap = storageBlobService.findStorageByIds(attachMap.values().stream().flatMap(List::stream).toList(), getDefaultBucket()).stream().collect(Collectors.toMap(SimpleStorageDto::getId,it->it)); + + + List<DuePayableVo> convertedList = duePayablePage.getRecords().stream().map(it -> { + DuePayableVo dueVo = new DuePayableVo(it.getId(), it.getTicketNo(), it.getPurchaseRegistrationId(), it.getPayableType(), it.getPaymentAmount(),Long.parseLong(it.getCreateBy()),it.getCreateTime().toLocalDate()); + // 鏂囦欢淇℃伅 + List<Long> storageIds = attachMap.get(it.getId()); + dueVo.setAttachFileList( + storageIds.stream() + .map(storageMap::get) // O(1) 鑾峰彇 + .filter(Objects::nonNull) + .toList() + ); + return dueVo; + }).toList(); + + IPage<DuePayableVo> voPage = new Page<>(); + voPage.setCurrent(duePayablePage.getCurrent()); + voPage.setSize(duePayablePage.getSize()); + voPage.setTotal(duePayablePage.getTotal()); + voPage.setRecords(convertedList); + return voPage; + } +} + + + + -- Gitblit v1.9.3