| | |
| | | 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; |
| | |
| | | |
| | | 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<>(); |
| | |
| | | .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)); |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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)); |
| | | 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 -> { |
| | |
| | | dto.setSupplierCoal(supply.getSupplierName() + " - " + coalInfo.getCoal()); |
| | | } |
| | | // 设置煤质数据 |
| | | dto.setCoalValues(coalValues); |
| | | dto.setCoalValues(coalValuesMap.getOrDefault(inventory.getCoalPlanId(), Collections.emptyList())); |
| | | return dto; |
| | | }) |
| | | .collect(Collectors.toList()); |