🐛 条件查询全部物料
All checks were successful
Release / Release (push) Successful in 43s

This commit is contained in:
my_ong 2025-03-08 20:21:18 +08:00
parent 76b9b901ea
commit 18f67ef62a
5 changed files with 54 additions and 6 deletions

View File

@ -78,14 +78,13 @@ public class MaterialController {
return result;
}
@GetMapping("material/list")
@PostMapping("material/list")
@Operation(summary = "查询所有物料列表")
public List<Material> all(@Parameter(description = "类型") @RequestParam(required = false, defaultValue = "") String type) {
List<Material> all = materialService.list(Wrappers.<Material>lambdaQuery()
.likeRight(StringUtils.isNotBlank(type), Material::getType, type));
all.forEach(item -> item.setTypeName(typeService.getTypeName(item.getType())));
return all;
String[] types = StringUtils.isNotBlank(type) ? type.split(",") : new String[0];
List<Material> materials = materialService.queryLikeRight(List.of(types));
materials.forEach(item -> item.setTypeName(typeService.getTypeName(item.getType())));
return materials;
}
@GetMapping("material/{id}")

View File

@ -1,11 +1,15 @@
package tech.riemann.ims.mapper.material;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import tech.riemann.ims.entity.material.Material;
import java.util.List;
/**
* @author mayong
* @since 2024/11/27 15:42
*/
public interface MaterialMapper extends BaseMapper<Material> {
List<Material> queryLikeRight( @Param("types") List<String> types);
}

View File

@ -4,9 +4,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.nutz.spring.boot.service.interfaces.IdNameEntityService;
import tech.riemann.ims.entity.material.Material;
import java.util.List;
/**
* @author mayong
* @since 2024/11/27 15:40
*/
public interface IMaterialService extends IService<Material>, IdNameEntityService<Material> {
List<Material> queryLikeRight(List<String> types);
}

View File

@ -8,6 +8,8 @@ import tech.riemann.ims.entity.material.Material;
import tech.riemann.ims.mapper.material.MaterialMapper;
import tech.riemann.ims.service.material.IMaterialService;
import java.util.List;
/**
* @author mayong
* @since 2024/11/27 15:41
@ -21,4 +23,9 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
public Dao dao() {
return dao;
}
@Override
public List<Material> queryLikeRight(List<String> types) {
return baseMapper.queryLikeRight(types);
}
}

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="tech.riemann.ims.mapper.material.MaterialMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="tech.riemann.ims.entity.material.Material">
</resultMap>
<select id="queryLikeRight" resultType="tech.riemann.ims.entity.material.Material">
SELECT
id,
m_code AS `code`,
m_name AS `name`,
m_assign_rule AS `assignRule`,
m_type AS `type`,
m_price AS `price`,
m_spec AS `spec`,
m_stock AS `stock`,
m_description AS `description`,
created_time,
updated_time,
created_by,
updated_by
FROM
t_material
<where>
<foreach collection="types" item="item" separator="or">
( m_type like concat(#{item},'%') )
</foreach>
</where>
</select>
</mapper>