| | |
| | | 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; |
| | | |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | } |