liding
2 天以前 6733a32d4bcd7ad3ec3f109da0f3d2524766f7bb
main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
@@ -19,9 +19,11 @@
import com.ruoyi.business.mapper.OfficialInventoryMapper;
import com.ruoyi.business.service.OfficialInventoryService;
import com.ruoyi.business.vo.OfficialInventoryVo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -54,9 +56,11 @@
    private final SupplyMapper supplyMapper;
    private final SysUserMapper sysUserMapper;
    @Override
    public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page page, OfficialInventoryDto officialInventoryDto) {
    public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page<OfficialInventory> page, OfficialInventoryDto officialInventoryDto) {
        //  先查出原始数据(OfficialInventory)
        LambdaQueryWrapper<OfficialInventory> queryWrapper = new LambdaQueryWrapper<>();
@@ -73,6 +77,10 @@
                .map(OfficialInventory::getSupplierId)
                .toList();
        List<Long> registrantIds = entityPage.getRecords().stream()
                .map(OfficialInventory::getRegistrantId)
                .toList();
        Map<Long, Supply> supplyMap;
        if (!supplierIds.isEmpty()) {
            List<Supply> infos = supplyMapper.selectList(new LambdaQueryWrapper<Supply>().in(Supply::getId, supplierIds));
@@ -81,19 +89,27 @@
            supplyMap = new HashMap<>();
        }
        //登记人
        Map<Long, SysUser> userMap;
        if (!registrantIds.isEmpty()) {
            List<SysUser> sysUsers = sysUserMapper.selectList(registrantIds);
            userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity()));
        }else {
            userMap = new HashMap<>();
        }
        //  查询所有可用字段(CoalField)
        List<CoalField> coalFields = coalFieldMapper.selectList(null);
        List<String> allFieldNames = coalFields.stream()
                .map(CoalField::getFields)
                .distinct()
                .collect(Collectors.toList());
                .toList();
        //查询煤种ids
        List<Long> coalIds = entityPage.getRecords().stream()
                .map(OfficialInventory::getCoalId)
                .distinct()
                .collect(Collectors.toList());
                .toList();
        // 批量查询CoalInfo
        Map<Long, CoalInfo> coalInfoMap;
@@ -113,6 +129,12 @@
            Supply supply = supplyMap.get(entity.getSupplierId());
            if (supply != null) {
                dto.setSupplierName(supply.getSupplierName());
            }
            // 登记人
            SysUser sysUser = userMap.get(entity.getRegistrantId());
            if (sysUser != null) {
                dto.setRegistrant(sysUser.getNickName());
            }
            List<CoalValue> coalValues;
@@ -333,6 +355,49 @@
    }
    @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()));
        Map<Long, List<CoalValue>> coalValuesMap = coalValueMapper.selectList(
                        new LambdaQueryWrapper<CoalValue>().in(CoalValue::getPlanId, planIds))
                .stream()
                .collect(Collectors.groupingBy(CoalValue::getPlanId));
        // 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(coalValuesMap.getOrDefault(inventory.getCoalPlanId(), Collections.emptyList()));
                    return dto;
                })
                .collect(Collectors.toList());
    }
    @Override
    public Map<String, BigDecimal> selectOfficialAllInfo() {
        // 1. 查询 official_inventory 表数据
        List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null);