| | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.CoalFieldDto; |
| | | 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.CoalPlanMapper; |
| | | import com.ruoyi.basic.mapper.CoalValueMapper; |
| | | import com.ruoyi.basic.service.CoalFieldService; |
| | | import com.ruoyi.basic.service.CoalPlanService; |
| | | import com.ruoyi.business.dto.PendingInventoryDto; |
| | | import com.ruoyi.business.entity.OfficialInventory; |
| | | import com.ruoyi.business.entity.PendingInventory; |
| | | import com.ruoyi.business.entity.SalesRecord; |
| | | import com.ruoyi.business.mapper.InventorySummaryMapper; |
| | | import com.ruoyi.business.mapper.OfficialInventoryMapper; |
| | | import com.ruoyi.business.mapper.PendingInventoryMapper; |
| | | import com.ruoyi.business.mapper.SalesRecordMapper; |
| | | 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.StringUtils; |
| | | 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; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | private final CoalInfoMapper coalInfoMapper; |
| | | |
| | | private final SysUserMapper sysUserMapper; |
| | | |
| | | private final InputInventoryRecordService inputInventoryRecordService; |
| | | |
| | | private final InventorySummaryService inventorySummaryService; |
| | | |
| | | private final CoalFieldService coalFieldService; |
| | | |
| | | private final CoalPlanService coalPlanService; |
| | | |
| | | @Override |
| | | public IPage<PendingInventoryDto> selectPendingInventoryList(Page page, PendingInventoryDto pendingInventoryDto) { |
| | | // 1. 构建主查询 |
| | | LambdaQueryWrapper<PendingInventory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | if (pendingInventoryDto.getRegistrationDate() != null) { |
| | | queryWrapper.eq(PendingInventory::getRegistrationDate, pendingInventoryDto.getRegistrationDate()); |
| | | } |
| | | |
| | | // 按煤种名称查询 |
| | | if (StringUtils.isNotBlank(pendingInventoryDto.getCoal())) { |
| | | LambdaQueryWrapper<CoalInfo> coalQueryWrapper = new LambdaQueryWrapper<>(); |
| | | coalQueryWrapper.like(CoalInfo::getCoal, pendingInventoryDto.getCoal()); |
| | | List<CoalInfo> coalInfos = coalInfoMapper.selectList(coalQueryWrapper); |
| | | |
| | | if (!coalInfos.isEmpty()) { |
| | | List<Long> coalIds = coalInfos.stream() |
| | | .map(CoalInfo::getId) |
| | | .collect(Collectors.toList()); |
| | | queryWrapper.in(PendingInventory::getCoalId, coalIds); |
| | | } else { |
| | | // 如果没有匹配的煤种,直接返回空结果 |
| | | queryWrapper.eq(PendingInventory::getCoalId, -1L); // 使用不可能存在的ID |
| | | } |
| | | } |
| | | |
| | | queryWrapper.orderByDesc(PendingInventory::getCreateTime); |
| | | |
| | | // 2. 执行主表分页查询 |
| | |
| | | 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()); |
| | |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public int addPending(PendingInventoryDto pendingInventoryDto) { |
| | | return 1; |
| | | } |
| | | } |