Skip to content

Commit

Permalink
商品浏览功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Q-1515 committed Jul 23, 2022
1 parent cf15b56 commit 0e43a99
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.reggie.controller.user;

import com.reggie.entity.Category;
import com.reggie.result.R;
import com.reggie.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController("userCategoryController")
@RequestMapping("/user/category")
@Api(tags = "C端-分类接口")
public class CategoryController {

@Autowired
private CategoryService categoryService;

/**
* 查询分类
* @param type
* @return
*/
@GetMapping("/list")
@ApiOperation("查询分类")
public R<List<Category>> list(Integer type) {
List<Category> list = categoryService.list(type);
return R.success(list);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.reggie.controller.user;

import com.reggie.entity.Dish;
import com.reggie.result.R;
import com.reggie.service.DishService;
import com.reggie.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController("userDishController")
@RequestMapping("/user/dish")
@Slf4j
@Api(tags = "C端-菜品浏览接口")
public class DishController {
@Autowired
private DishService dishService;

/**
* 根据分类id查询菜品
*
* @param categoryId
* @return
*/
@GetMapping("/list")
@ApiOperation("根据分类id查询菜品")
public R<List<DishVO>> list(Long categoryId) {
Dish dish = new Dish();
dish.setCategoryId(categoryId);
dish.setStatus(Dish.ON);

List<DishVO> list = dishService.listWithFlavor(dish);

return R.success(list);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.reggie.controller.user;

import com.reggie.entity.Setmeal;
import com.reggie.result.R;
import com.reggie.service.SetmealService;
import com.reggie.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "C端-套餐浏览接口")
public class SetmealController {
@Autowired
private SetmealService setmealService;

/**
* 条件查询
*
* @param categoryId
* @return
*/
@GetMapping("/list")
@ApiOperation("根据分类id查询套餐")
public R<List<Setmeal>> list(Long categoryId) {
Setmeal setmeal = new Setmeal();
setmeal.setCategoryId(categoryId);
setmeal.setStatus(Setmeal.ON);

List<Setmeal> list = setmealService.list(setmeal);
return R.success(list);
}

/**
* 根据套餐id查询包含的菜品列表
*
* @param id
* @return
*/
@GetMapping("/dish/{id}")
@ApiOperation("根据套餐id查询包含的菜品列表")
public R<List<DishItemVO>> dishList(@PathVariable("id") Long id) {
List<DishItemVO> list = setmealService.getDishItemById(id);
return R.success(list);
}
}
10 changes: 10 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 @@ -5,6 +5,7 @@
import com.reggie.constant.AutoFillConstant;
import com.reggie.dto.DishPageQueryDTO;
import com.reggie.entity.Dish;
import com.reggie.vo.DishItemVO;
import com.reggie.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;

Expand Down Expand Up @@ -41,4 +42,13 @@ public interface DishMapper {

//根据套餐id查询菜品
List<Dish> getBySetmealId(Long setmealId);


//动态条件查询菜品和口味
List<DishVO> listWithFlavor(Dish dish);

//根据套餐id查询菜品选项
List<DishItemVO> getDishItemBySetmealId(Long setmealId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ public interface SetmealMapper {

//id查询套餐查询所有套餐关联数据
SetmealVO getByIdWithDish(Long id);

//动态条件查询套餐
List<Setmeal> list(Setmeal setmeal);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ public interface DishService {

//根据分类id查询菜品
List<Dish> list(Long categoryId, String name);

// 条件查询菜品和口味
List<DishVO> listWithFlavor(Dish dish);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.reggie.dto.SetmealDTO;
import com.reggie.dto.SetmealPageQueryDTO;
import com.reggie.entity.Setmeal;
import com.reggie.result.PageResult;
import com.reggie.vo.DishItemVO;
import com.reggie.vo.SetmealVO;

import java.util.List;
Expand All @@ -29,4 +31,11 @@ public interface SetmealService {

//套餐 启用禁用
void startOrStop(Integer status, Long id);


//条件查询
List<Setmeal> list(Setmeal setmeal);

//根据id查询菜品选项
List<DishItemVO> getDishItemById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,17 @@ public List<Dish> list(Long categoryId, String name) {
}
return dishMapper.list(dish);
}


/**
* 条件查询菜品和口味
* @param dish 菜品
* @return 菜品和口味
*/
public List<DishVO> listWithFlavor(Dish dish) {
List<DishVO> list = dishMapper.listWithFlavor(dish);
return list;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.reggie.mapper.SetmealMapper;
import com.reggie.result.PageResult;
import com.reggie.service.SetmealService;
import com.reggie.vo.DishItemVO;
import com.reggie.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
Expand Down Expand Up @@ -175,4 +176,26 @@ public void startOrStop(Integer status, Long id) {
setmealMapper.updatesByIds(setmeal);

}

/**
* 条件查询
*
* @param setmeal
* @return
*/
public List<Setmeal> list(Setmeal setmeal) {
List<Setmeal> list = setmealMapper.list(setmeal);
return list;
}

/**
* 根据id查询菜品选项
*
* @param id
* @return
*/
public List<DishItemVO> getDishItemById(Long id) {
return dishMapper.getDishItemBySetmealId(id);
}

}
37 changes: 37 additions & 0 deletions reggie_server/src/main/resources/mapper/DishMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,41 @@
where sd.setmeal_id = #{setmealId}
</select>

<!--动态条件查询菜品和口味-->
<select id="listWithFlavor" parameterType="Dish" resultMap="DishVOMap">
select
a.*,b.name fname,b.value
from
dish a
left join
dish_flavor b
on
a.id = b.dish_id
<where>
<if test="name != null">
and a.name like '%${name}%'
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
<if test="status != null">
and status = #{status}
</if>
</where>
</select>

<!--根据套餐id查询菜品选项-->
<select id="getDishItemBySetmealId" resultType="com.reggie.vo.DishItemVO">
select sd.name,
sd.copies,
d.image,
d.description
from setmeal_dish sd
left join
dish d
on
sd.dish_id = d.id
where sd.setmeal_id = #{setmealId}
</select>

</mapper>
16 changes: 16 additions & 0 deletions reggie_server/src/main/resources/mapper/SetmealMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,21 @@
where setmeal.id = #{id}
</select>

<!--动态条件查询套餐-->
<select id="list" parameterType="Setmeal" resultType="Setmeal">
select * from setmeal
<where>
<if test="name != null">
and name like '%${name}%'
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
<if test="status != null">
and status = #{status}
</if>
</where>
</select>


</mapper>

0 comments on commit 0e43a99

Please sign in to comment.