| | |
| | | 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 com.ruoyi.business.entity.PendingInventory; |
| | | import com.ruoyi.business.mapper.OfficialInventoryMapper; |
| | | import com.ruoyi.business.mapper.PendingInventoryMapper; |
| | | import com.ruoyi.business.service.InputInventoryRecordService; |
| | | import com.ruoyi.business.service.InventorySummaryService; |
| | | import com.ruoyi.business.service.PendingInventoryService; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | private final CoalFieldMapper coalFieldMapper; |
| | | |
| | | private final CoalInfoMapper coalInfoMapper; |
| | | |
| | | private final InputInventoryRecordService inputInventoryRecordService; |
| | | |
| | | private final InventorySummaryService inventorySummaryService; |
| | | |
| | | @Override |
| | | public IPage<PendingInventoryDto> selectPendingInventoryList(Page page, PendingInventoryDto pendingInventoryDto) { |
| | | // 1. 构建主查询 |
| | |
| | | .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) { |
| | |
| | | coalValue.setCoalValue(value); |
| | | coalValue.setFields(key); |
| | | coalValue.setFieldName(fieldName); |
| | | coalValue.setType(String.valueOf(1)); |
| | | i = coalValueMapper.insert(coalValue); |
| | | } |
| | | } |
| | |
| | | officialInventory.setPendingId(pendingInventoryDto.getPId()); |
| | | officialInventory.setInventoryQuantity(quantity); |
| | | officialInventoryMapper.insert(officialInventory); |
| | | }else { |
| | | } else { |
| | | OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId()); |
| | | officialInventory.setInventoryQuantity(quantity.add(officialInventory.getInventoryQuantity())); |
| | | officialInventoryMapper.updateById(officialInventory); |