Skip to content

Commit

Permalink
根据分类id或者菜名 动态查询菜品
Browse files Browse the repository at this point in the history
  • Loading branch information
Q-1515 committed Jul 22, 2022
1 parent 6e494c4 commit 6dc19a1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.reggie.dto.DishDTO;
import com.reggie.dto.DishPageQueryDTO;
import com.reggie.entity.Dish;
import com.reggie.result.PageResult;
import com.reggie.result.R;
import com.reggie.service.DishService;
Expand Down Expand Up @@ -111,4 +112,23 @@ public R<String> startOrStop(@PathVariable Integer status, Long id) {
}


/**
* 根据分类id || 菜名 查询菜品
*
* @param categoryId 分类id
* @param name 菜名
* @return 菜品
*/
@GetMapping("/list")
@ApiOperation("根据分类id || 菜名 查询菜品接口")
public R<List<Dish>> list(Long categoryId, String name) {
log.info("根据菜名查询菜品接口:{}", name);
List<Dish> list = dishService.list(categoryId, name);
return R.success(list);
}





}
4 changes: 4 additions & 0 deletions reggie_server/src/main/java/com/reggie/mapper/DishMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.reggie.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface DishMapper {

Expand All @@ -34,4 +36,6 @@ public interface DishMapper {
@AutoFill(type = AutoFillConstant.UPDATE)
void update(Dish dish);

//根据分类id,状态码,菜品名 查询菜品信息
List<Dish> list(Dish dish);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.reggie.dto.DishDTO;
import com.reggie.dto.DishPageQueryDTO;
import com.reggie.entity.Dish;
import com.reggie.result.PageResult;
import com.reggie.vo.DishVO;

Expand All @@ -26,4 +27,7 @@ public interface DishService {

//菜品起售、停售
void startOrStop(Integer status, Long id);

//根据分类id查询菜品
List<Dish> list(Long categoryId,String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,24 @@ public void startOrStop(Integer status, Long id) {
}
}
}

/**
* 根据分类id || 菜名 查询菜品
*
* @param categoryId 分类id
* @param name 菜名
* @return 菜品集合
*/
public List<Dish> list(Long categoryId, String name) {
Dish dish = new Dish();
//设置菜品起售状态才能被查
dish.setStatus(StatusConstant.ENABLE);
//判断查分类id还是查菜品名
if (categoryId == null) {
dish.setName(name);
} else {
dish.setCategoryId(categoryId);
}
return dishMapper.list(dish);
}
}
17 changes: 17 additions & 0 deletions reggie_server/src/main/resources/mapper/DishMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,21 @@
where id = #{id}
</update>

<!--根据分类id,状态码,菜品名 查询菜品信息-->
<select id="list" resultType="com.reggie.entity.Dish">
select * from dish
<where>
<if test="name != null">
and name like concat('%',#{name},'%')
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
<if test="status != null">
and status = #{status}
</if>
</where>
order by create_time desc
</select>

</mapper>

0 comments on commit 6dc19a1

Please sign in to comment.