苍穹外卖--导入用户端商品浏览功能代码
This commit is contained in:
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RestController("adminDishController")
|
||||
@Slf4j
|
||||
@Api(tags = "菜品相关接口")
|
||||
@RequestMapping("/admin/dish")
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
/**
|
||||
* 套餐管理
|
||||
*/
|
||||
@RestController
|
||||
@RestController("adminSetmealController")
|
||||
@RequestMapping("/admin/setmeal")
|
||||
@Api(tags = "套餐相关接口")
|
||||
@Slf4j
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.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 Result<List<Category>> list(Integer type) {
|
||||
List<Category> list = categoryService.list(type);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.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 Result<List<DishVO>> list(Long categoryId) {
|
||||
Dish dish = new Dish();
|
||||
dish.setCategoryId(categoryId);
|
||||
dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品
|
||||
|
||||
List<DishVO> list = dishService.listWithFlavor(dish);
|
||||
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.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 Result<List<Setmeal>> list(Long categoryId) {
|
||||
Setmeal setmeal = new Setmeal();
|
||||
setmeal.setCategoryId(categoryId);
|
||||
setmeal.setStatus(StatusConstant.ENABLE);
|
||||
|
||||
List<Setmeal> list = setmealService.list(setmeal);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据套餐id查询包含的菜品列表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/dish/{id}")
|
||||
@ApiOperation("根据套餐id查询包含的菜品列表")
|
||||
public Result<List<DishItemVO>> dishList(@PathVariable("id") Long id) {
|
||||
List<DishItemVO> list = setmealService.getDishItemById(id);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,14 @@ import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealMapper {
|
||||
|
||||
@@ -55,4 +58,21 @@ public interface SetmealMapper {
|
||||
* @param setmeal
|
||||
*/
|
||||
void update(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 动态条件查询套餐
|
||||
* @param setmeal
|
||||
* @return
|
||||
*/
|
||||
List<Setmeal> list(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询菜品选项
|
||||
* @param setmealId
|
||||
* @return
|
||||
*/
|
||||
@Select("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}")
|
||||
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
||||
}
|
||||
|
||||
@@ -53,4 +53,11 @@ public interface DishService {
|
||||
* @return
|
||||
*/
|
||||
List<Dish> list(Long categoryId);
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
List<DishVO> listWithFlavor(Dish dish);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.sky.service;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -47,4 +49,18 @@ public interface SetmealService {
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param setmeal
|
||||
* @return
|
||||
*/
|
||||
List<Setmeal> list(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据id查询菜品选项
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<DishItemVO> getDishItemById(Long id);
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -161,4 +162,28 @@ public class DishServiceImpl implements DishService {
|
||||
.build();
|
||||
return dishMapper.list(dish);
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
public List<DishVO> listWithFlavor(Dish dish) {
|
||||
List<Dish> dishList = dishMapper.list(dish);
|
||||
|
||||
List<DishVO> dishVOList = new ArrayList<>();
|
||||
|
||||
for (Dish d : dishList) {
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(d,dishVO);
|
||||
|
||||
//根据菜品id查询对应的口味
|
||||
List<DishFlavor> flavors = dishFlavorMapper.getByDishId(d.getId());
|
||||
|
||||
dishVO.setFlavors(flavors);
|
||||
dishVOList.add(dishVO);
|
||||
}
|
||||
|
||||
return dishVOList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -168,4 +169,23 @@ public class SetmealServiceImpl implements SetmealService {
|
||||
.build();
|
||||
setmealMapper.update(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 setmealMapper.getDishItemBySetmealId(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,19 @@
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="list" parameterType="Setmeal" resultType="Setmeal">
|
||||
select * from setmeal
|
||||
<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>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user