liding
10 小时以前 94509204d25f7c0ad213ae2322be2bd5bfd17424
main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
@@ -26,7 +26,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -330,4 +332,67 @@
        }
    }
    @Override
    public List<OfficialInventoryDto> coalBlendingList() {
        // 1. 查询基础库存数据
        List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null);
        // 2. 收集所有需要查询的ID
        Set<Long> coalIds = new HashSet<>();
        Set<Long> supplierIds = new HashSet<>();
        Set<Long> planIds = new HashSet<>();
        officialInventories.forEach(inventory -> {
            coalIds.add(inventory.getCoalId());
            supplierIds.add(inventory.getSupplierId());
            planIds.add(inventory.getCoalPlanId());
        });
        // 3. 批量查询关联数据
        Map<Long, CoalInfo> coalInfoMap = coalInfoMapper.selectByIds(coalIds).stream()
                .collect(Collectors.toMap(CoalInfo::getId, Function.identity()));
        Map<Long, Supply> supplyMap = supplyMapper.selectByIds(supplierIds).stream()
                .collect(Collectors.toMap(Supply::getId, Function.identity()));
        List<CoalValue> coalValues = coalValueMapper.selectList(
                new LambdaQueryWrapper<CoalValue>().in(CoalValue::getPlanId, planIds));
        // 4. 组装DTO
        return officialInventories.stream()
                .map(inventory -> {
                    OfficialInventoryDto dto = new OfficialInventoryDto();
                    BeanUtils.copyProperties(inventory, dto);
                    // 设置煤种信息
                    CoalInfo coalInfo = coalInfoMap.get(inventory.getCoalId());
                    Supply supply = supplyMap.get(inventory.getSupplierId());
                    if (coalInfo != null && supply != null) {
                        dto.setSupplierCoal(supply.getSupplierName() + " - " + coalInfo.getCoal());
                    }
                    // 设置煤质数据
                    dto.setCoalValues(coalValues);
                    return dto;
                })
                .collect(Collectors.toList());
    }
    @Override
    public Map<String, BigDecimal> selectOfficialAllInfo() {
        // 1. 查询 official_inventory 表数据
        List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null);
        // 用于存储最终结果,key 为煤种名称,value 为库存数量拼接“吨”
        Map<String, BigDecimal> resultMap = new LinkedHashMap<>();
        // 2. 遍历查询结果,关联 coalInfo 获取煤种名称并组装数据
        for (OfficialInventory inventory : officialInventories) {
            Long coalId = inventory.getCoalId();
            // 根据 coalId 到 coalInfoMapper 查询煤种名称
            CoalInfo coalInfo = coalInfoMapper.selectById(coalId);
            if (coalInfo != null) {
                String coalName = coalInfo.getCoal(); // 假设 CoalInfo 有 getCoalName 方法获取煤种名称
                BigDecimal quantity = inventory.getInventoryQuantity();
                resultMap.put(coalName, quantity);
            }
        }
        return resultMap;
    }
}