src/main/java/com/ruoyi/production/controller/ProductMaterialSkuController.java
@@ -38,8 +38,8 @@ @GetMapping("/list") @ApiOperation("物料规格数据集合") @Log(title = "物料规格数据集合", businessType = BusinessType.OTHER) public AjaxResult productMaterialSkuList(Page<ProductMaterialSku> page, ProductMaterialSkuDto dto) { Page<ProductMaterialSkuDto> list = productMaterialSkuService.productMaterialSkuList(page, dto); public AjaxResult productMaterialSkuList(Page<ProductMaterialSkuDto> page, ProductMaterialSkuDto dto, @RequestParam(value = "type", required = false) Integer type) { Page<ProductMaterialSkuDto> list = productMaterialSkuService.productMaterialSkuList(page, dto, type); return AjaxResult.success(list); } src/main/java/com/ruoyi/production/mapper/ProductMaterialSkuMapper.java
@@ -1,7 +1,10 @@ package com.ruoyi.production.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.production.dto.ProductMaterialSkuDto; import com.ruoyi.production.pojo.ProductMaterialSku; import org.apache.ibatis.annotations.Param; /** * <br> @@ -13,4 +16,10 @@ * @since 2026/03/12 10:04 */ public interface ProductMaterialSkuMapper extends BaseMapper<ProductMaterialSku> { } /** * 连表查询物料和规格 */ Page<ProductMaterialSkuDto> selectSkuWithMaterialPage(@Param("page") Page<ProductMaterialSkuDto> page, @Param("dto") ProductMaterialSkuDto dto, @Param("type") Integer type); } src/main/java/com/ruoyi/production/service/ProductMaterialSkuService.java
@@ -18,7 +18,7 @@ * @since 2026/03/12 10:04 */ public interface ProductMaterialSkuService extends IService<ProductMaterialSku> { Page<ProductMaterialSkuDto> productMaterialSkuList(Page<ProductMaterialSku> page, ProductMaterialSkuDto dto); Page<ProductMaterialSkuDto> productMaterialSkuList(Page<ProductMaterialSkuDto> page, ProductMaterialSkuDto dto, Integer type); void addProductMaterialSku(ProductMaterialSku productMaterialSku); src/main/java/com/ruoyi/production/service/impl/ProductMaterialSkuServiceImpl.java
@@ -39,9 +39,7 @@ */ @Slf4j @Service public class ProductMaterialSkuServiceImpl extends ServiceImpl<ProductMaterialSkuMapper, ProductMaterialSku> implements ProductMaterialSkuService { public class ProductMaterialSkuServiceImpl extends ServiceImpl<ProductMaterialSkuMapper, ProductMaterialSku> implements ProductMaterialSkuService { @Autowired private ProductMaterialMapper productMaterialMapper; @@ -50,43 +48,8 @@ * 查询物料规格列表 */ @Override public Page<ProductMaterialSkuDto> productMaterialSkuList(Page<ProductMaterialSku> page, ProductMaterialSkuDto dto) { LambdaQueryWrapper<ProductMaterialSku> queryWrapper = new LambdaQueryWrapper<>(); if (dto != null && dto.getMaterialId() != null) { queryWrapper.eq(ProductMaterialSku::getMaterialId, dto.getMaterialId()) .like(StringUtils.isNotBlank(dto.getSpecification()), ProductMaterialSku::getSpecification, dto.getSpecification()) .like(StringUtils.isNotBlank(dto.getMaterialCode()), ProductMaterialSku::getMaterialCode, dto.getMaterialCode()) .orderByAsc(ProductMaterialSku::getId); } Page<ProductMaterialSku> skuPage = this.page(page, queryWrapper); List<ProductMaterialSku> skuList = skuPage.getRecords(); if (skuList == null || skuList.isEmpty()) { return new Page<>(); } ProductMaterial material = productMaterialMapper.selectById(dto.getMaterialId()); String materialName = material != null ? material.getMaterialName() : null; String baseUnit = material != null ? material.getBaseUnit() : null; List<ProductMaterialSkuDto> result = new ArrayList<>(skuList.size()); for (ProductMaterialSku sku : skuList) { ProductMaterialSkuDto productMaterialSkuDto = new ProductMaterialSkuDto(); productMaterialSkuDto.setMaterialId(dto.getMaterialId()); productMaterialSkuDto.setMaterialName(materialName); productMaterialSkuDto.setMaterialCode(sku.getMaterialCode()); productMaterialSkuDto.setBaseUnit(baseUnit); productMaterialSkuDto.setSkuId(sku.getId()); productMaterialSkuDto.setSpecification(sku.getSpecification()); productMaterialSkuDto.setSupplyType(sku.getSupplyType()); result.add(productMaterialSkuDto); } Page<ProductMaterialSkuDto> dtoPage = new Page<>(); dtoPage.setCurrent(skuPage.getCurrent()); dtoPage.setSize(skuPage.getSize()); dtoPage.setTotal(skuPage.getTotal()); dtoPage.setRecords(result); return dtoPage; public Page<ProductMaterialSkuDto> productMaterialSkuList(Page<ProductMaterialSkuDto> page, ProductMaterialSkuDto dto, Integer type) { return baseMapper.selectSkuWithMaterialPage(page, dto, type); } /** src/main/resources/mapper/production/ProductMaterialSkuMapper.xml
@@ -19,4 +19,33 @@ <result property="updateTime" column="update_time"/> </resultMap> <select id="selectSkuWithMaterialPage" resultType="com.ruoyi.production.dto.ProductMaterialSkuDto"> SELECT sku.id AS skuId, sku.material_id AS materialId, sku.material_code AS materialCode, sku.specification AS specification, sku.supply_type AS supplyType, m.material_name AS materialName, m.base_unit AS baseUnit FROM product_material_sku sku LEFT JOIN product_material m ON sku.material_id = m.id <where> <if test="dto.materialId != null"> AND sku.material_id = #{dto.materialId} </if> <if test="dto.specification != null and dto.specification != ''"> AND sku.specification LIKE CONCAT('%', #{dto.specification}, '%') </if> <if test="dto.materialCode != null and dto.materialCode != ''"> AND sku.material_code LIKE CONCAT('%', #{dto.materialCode}, '%') </if> <if test="type != null and type == 1 and dto.materialName != null and dto.materialName != ''"> AND m.material_name LIKE CONCAT('%', #{dto.materialName}, '%') </if> </where> ORDER BY sku.id ASC </select> </mapper>