| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.stream.CollectorUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.mapper.CustomerFollowUpFileMapper; |
| | | import com.ruoyi.basic.pojo.CustomerFollowUpFile; |
| | | import com.ruoyi.basic.service.CustomerFollowUpFileService; |
| | | import com.ruoyi.basic.service.CustomerFollowUpService; |
| | | import com.ruoyi.common.vo.SimpleFileVo; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.function.BiConsumer; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <br> |
| | |
| | | * @since 2026/03/04 14:53 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class CustomerFollowUpFileServiceImpl extends ServiceImpl<CustomerFollowUpFileMapper, CustomerFollowUpFile> implements CustomerFollowUpFileService { |
| | | |
| | | private final CustomerFollowUpService customerFollowUpService; |
| | | |
| | | |
| | | @Override |
| | | public <T> void fillAttachment(List<T> list, Function<T, String> getAttachmentIds, BiConsumer<T, List<SimpleFileVo>> setAttachmentList) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return; |
| | | } |
| | | // 收集所有文件ID |
| | | Set<Long> ids = list.stream() |
| | | .map(getAttachmentIds) |
| | | .filter(StrUtil::isNotBlank) |
| | | .flatMap(s -> Arrays.stream(s.split(","))) |
| | | .map(Long::valueOf) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | List<CustomerFollowUpFile> followUpFilesByIds = customerFollowUpService.getFollowUpFilesByIds(ids); |
| | | if (CollUtil.isEmpty(followUpFilesByIds)) { |
| | | return; |
| | | } |
| | | Map<Long, SimpleFileVo> collectMap = followUpFilesByIds.stream().map(SimpleFileVo::convert).collect(Collectors.toMap( |
| | | SimpleFileVo::getId, |
| | | Function.identity() |
| | | )); |
| | | list.forEach(t -> { |
| | | String attachmentIds = getAttachmentIds.apply(t); |
| | | if (StrUtil.isNotBlank(attachmentIds)) { |
| | | List<SimpleFileVo> fileVos = Arrays.stream(attachmentIds.split(",")) |
| | | .map(Long::valueOf) |
| | | .map(it->collectMap.getOrDefault(it, (SimpleFileVo) Collections.emptyList())) |
| | | .collect(Collectors.toList()); |
| | | setAttachmentList.accept(t, fileVos); |
| | | } |
| | | }); |
| | | } |
| | | } |