| | |
| | | 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.entity.CoalInfo; |
| | | import com.ruoyi.basic.mapper.CoalInfoMapper; |
| | | import com.ruoyi.business.dto.ProductionMasterDto; |
| | | import com.ruoyi.business.entity.*; |
| | | 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; |
| | |
| | | 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); |