liding
3 天以前 49e1bc66ebaf696ebd3fc3ed33d65c8795fd3cde
main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java
@@ -12,12 +12,14 @@
import com.ruoyi.business.mapper.*;
import com.ruoyi.business.service.ProductionMasterService;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@@ -49,6 +51,32 @@
    public IPage<ProductionMasterDto> selectPMList(Page page, ProductionMasterDto productionMasterDto) {
        // 1. 构建主表查询条件
        LambdaQueryWrapper<ProductionMaster> masterQueryWrapper = new LambdaQueryWrapper<>();
        String keyword = productionMasterDto.getSearchAll();
        if (StringUtils.isNotBlank(keyword)) {
            // 查询煤种名称中模糊匹配的coalId列表
            List<Long> matchedCoalIds = coalInfoMapper.selectList(
                            new LambdaQueryWrapper<CoalInfo>().like(CoalInfo::getCoal, keyword)
                    ).stream()
                    .map(CoalInfo::getId)
                    .toList();
            // 组装查询条件:煤种ID在匹配的列表中
            // 如果 matchedCoalIds 为空,直接返回 0 条数据(构造一个不可能成立的条件)
            if (matchedCoalIds.isEmpty()) {
                masterQueryWrapper.apply("1 = 0"); // 强制返回空结果
            }
            // 如果有匹配的 coalId,则按 coalId 查询
            else {
                String ids = matchedCoalIds.stream()
                        .map(String::valueOf)
                        .collect(Collectors.joining(","));
                masterQueryWrapper.apply(
                        "{0} = ANY(string_to_array(coal_id, ','))",
                        ids
                );
            }
        }
        // 2. 执行主表分页查询
        IPage<ProductionMaster> entityPage = productionMasterMapper.selectPage(page, masterQueryWrapper);
@@ -211,8 +239,6 @@
            coalIds.add(p.getCoalId());
        }
        List<CoalInfo> coalInfos = coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds));
        ProductionMaster master = new ProductionMaster();
        master.setProductionQuantity(totalQuantity);
        master.setTotalCost(totalCost);
@@ -263,7 +289,8 @@
            pending.setSupplierName("生产加工入库");
            pending.setTotalPriceIncludingTax(p.getTotalCost());
            pending.setPriceIncludingTax(p.getPurchasePrice());
            pending.setPriceIncludingTax(p.getPurchasePrice());
            pending.setRegistrantId(p.getProducerId());
            pending.setRegistrationDate(LocalDate.now());
            pendingInventoryMapper.insert(pending);
        }
    }