| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.entity.CoalField; |
| | | import com.ruoyi.basic.entity.CoalInfo; |
| | | import com.ruoyi.basic.entity.CoalValue; |
| | | import com.ruoyi.basic.mapper.CoalFieldMapper; |
| | | import com.ruoyi.basic.mapper.CoalInfoMapper; |
| | | import com.ruoyi.basic.mapper.CoalValueMapper; |
| | | import com.ruoyi.business.dto.PendingInventoryDto; |
| | | import com.ruoyi.business.entity.OfficialInventory; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private final CoalValueMapper coalValueMapper; |
| | | |
| | | private final CoalFieldMapper coalFieldMapper; |
| | | |
| | | private final CoalInfoMapper coalInfoMapper; |
| | | |
| | | private final InputInventoryRecordService inputInventoryRecordService; |
| | | |
| | |
| | | .map(PendingInventory::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 5. 批量查询关联的正式库存信息 |
| | | // 5. 批量查询关联的煤炭信息和正式库存信息 |
| | | List<Long> coalIds = pendingInventoryPage.getRecords().stream() |
| | | .map(PendingInventory::getCoalId) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 批量查询CoalInfo |
| | | Map<Long, CoalInfo> coalInfoMap; |
| | | if (!coalIds.isEmpty()) { |
| | | List<CoalInfo> coalInfos = coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds)); |
| | | coalInfoMap = coalInfos.stream().collect(Collectors.toMap(CoalInfo::getId, Function.identity())); |
| | | } else { |
| | | coalInfoMap = new HashMap<>(); |
| | | } |
| | | |
| | | // 批量查询正式库存信息 |
| | | Map<Long, Long> pendingToOfficialMap = getOfficialInventoryMap(pendingIds); |
| | | |
| | | // 6. 使用MyBatis-Plus的convert方法转换DTO |
| | | // 6. 转换DTO并设置相关字段 |
| | | return pendingInventoryPage.convert(record -> { |
| | | PendingInventoryDto dto = new PendingInventoryDto(); |
| | | BeanUtils.copyProperties(record, dto); |
| | | |
| | | // 设置Coal信息 |
| | | CoalInfo coalInfo = coalInfoMap.get(record.getCoalId()); |
| | | if (coalInfo != null) { |
| | | dto.setCoal(coalInfo.getCoal()); |
| | | } |
| | | |
| | | // 从预加载的Map中获取officialId |
| | | dto.setOfficialId(pendingToOfficialMap.getOrDefault(record.getId(), null)); |
| | | |
| | | return dto; |
| | | }); |
| | | } |
| | | |
| | | |
| | | // 批量获取待处理库存与正式库存的映射关系 |
| | | private Map<Long, Long> getOfficialInventoryMap(List<Long> pendingIds) { |
| | | if (CollectionUtils.isEmpty(pendingIds)) { |