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 针对表【due_payable(应付款表)】的数据库操作Service实现
|
* @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);
|
/**
|
* 查询出附件id 由于后续详细
|
*/
|
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();
|
}
|
}
|
));
|
/**
|
* 根据上面的ids 查询出具体信息
|
*/
|
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;
|
}
|
}
|