| | |
| | | import com.ruoyi.business.service.InputInventoryRecordService; |
| | | import com.ruoyi.business.service.InventorySummaryService; |
| | | import com.ruoyi.business.service.PendingInventoryService; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | 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 CoalFieldMapper coalFieldMapper; |
| | | |
| | | private final CoalInfoMapper coalInfoMapper; |
| | | |
| | | private final SysUserMapper sysUserMapper; |
| | | |
| | | private final InputInventoryRecordService inputInventoryRecordService; |
| | | |
| | |
| | | coalInfoMap = new HashMap<>(); |
| | | } |
| | | |
| | | // 5. 批量查询登记人id |
| | | List<Long> registrantIds = pendingInventoryPage.getRecords().stream() |
| | | .map(PendingInventory::getRegistrantId) |
| | | .distinct() |
| | | .toList(); |
| | | // 批量查询登记人 |
| | | Map<Long, SysUser> sysUserMap; |
| | | if (!registrantIds.isEmpty()) { |
| | | List<SysUser> sysUsers = sysUserMapper.selectList(registrantIds); |
| | | sysUserMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity())); |
| | | } else { |
| | | sysUserMap = new HashMap<>(); |
| | | } |
| | | |
| | | // 批量查询正式库存信息 |
| | | Map<Long, Long> pendingToOfficialMap = getOfficialInventoryMap(pendingIds); |
| | | |
| | |
| | | CoalInfo coalInfo = coalInfoMap.get(record.getCoalId()); |
| | | if (coalInfo != null) { |
| | | dto.setCoal(coalInfo.getCoal()); |
| | | } |
| | | |
| | | // 设置登记人 |
| | | SysUser sysUser = sysUserMap.get(record.getRegistrantId()); |
| | | if (sysUser != null) { |
| | | dto.setRegistrant(sysUser.getNickName()); |
| | | } |
| | | |
| | | // 从预加载的Map中获取officialId |
| | |
| | | BigDecimal left = pendingInventory.getInventoryQuantity().subtract(quantity); |
| | | if (left.compareTo(BigDecimal.ZERO) > 0) { |
| | | pendingInventory.setInventoryQuantity(left); |
| | | pendingInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId()); |
| | | pendingInventoryMapper.updateById(pendingInventory); |
| | | } else { |
| | | pendingInventoryMapper.deleteById(pendingInventoryDto.getPId()); |
| | |
| | | OfficialInventory officialInventory = new OfficialInventory(); |
| | | BeanUtils.copyProperties(pendingInventory, officialInventory); |
| | | officialInventory.setId(null); |
| | | officialInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId()); |
| | | officialInventory.setPendingId(pendingInventoryDto.getPId()); |
| | | officialInventory.setInventoryQuantity(quantity); |
| | | officialInventory.setRegistrantId(1L); |
| | | officialInventory.setSupplierId(pendingInventoryDto.getSupplierId()); |
| | | officialInventoryMapper.insert(officialInventory); |
| | | } else { |
| | | OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId()); |