liding
昨天 f29c8786807015d78b9be8a33397f69478d92a76
main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
@@ -6,18 +6,24 @@
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;
@@ -29,6 +35,7 @@
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;
@@ -36,6 +43,7 @@
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
 * <p>
@@ -65,32 +73,32 @@
    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 (StringUtils.isNotBlank(pendingInventoryDto.getSearchAll())) {
            String searchValue = pendingInventoryDto.getSearchAll();
            // 1. 先尝试作为日期查询
            try {
                LocalDate RegistrationDate = LocalDate.parse(searchValue);
                queryWrapper.eq(PendingInventory::getRegistrationDate, RegistrationDate);
            } catch (DateTimeParseException e) {
                // 2. 如果不是日期,则作为煤种名称查询
                LambdaQueryWrapper<CoalInfo> coalQueryWrapper = new LambdaQueryWrapper<>();
                coalQueryWrapper.like(CoalInfo::getCoal, searchValue);
                List<CoalInfo> coalInfos = coalInfoMapper.selectList(coalQueryWrapper);
                if (!coalInfos.isEmpty()) {
                    // 提取所有匹配的煤种ID
                    List<Long> coalIds = coalInfos.stream()
                            .map(CoalInfo::getId)
                            .collect(Collectors.toList());
                    // 使用in查询匹配任意一个煤种ID
                    queryWrapper.in(PendingInventory::getCoalId, coalIds);
                } else {
                    // 3. 如果找不到煤种,可以返回空结果
                    queryWrapper.eq(PendingInventory::getCoalId, "-1"); // 使用不可能存在的ID
                }
        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
            }
        }
@@ -286,4 +294,10 @@
        }
        return i;
    }
    @Override
    @Transactional
    public int addPending(PendingInventoryDto pendingInventoryDto) {
      return 1;
    }
}