导入商品浏览-未完成
This commit is contained in:
parent
567f60ce66
commit
d8b0a8a391
|
@ -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,55 @@
|
|||
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 javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController("userSetmealController")
|
||||
@RequestMapping("/user/setmeal")
|
||||
@Api(tags = "C端-套餐浏览接口")
|
||||
public class SetmealController {
|
||||
@Resource
|
||||
private SetmealService setmealService;
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
*
|
||||
* @param categoryId Long
|
||||
* @return Result<List<Setmeal>>
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -62,4 +62,6 @@ public interface DishMapper {
|
|||
*/
|
||||
@AutoFill(value = OperationType.UPDATE)
|
||||
void update(Dish dish);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -8,8 +11,18 @@ import java.util.List;
|
|||
public interface SetMealDishMapper {
|
||||
/**
|
||||
* 查询对应套餐id
|
||||
*
|
||||
* @param dishIds List<Long>
|
||||
* @return List<Long>
|
||||
*/
|
||||
List<Long> getSetMealDishIds(List<Long> dishIds);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询菜品选项
|
||||
*
|
||||
* @param setmealId LongLong
|
||||
* @return List<DishItemVO>
|
||||
*/
|
||||
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,32 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealMapper {
|
||||
|
||||
/**
|
||||
* 根据分类id查询套餐的数量
|
||||
* @param id Long
|
||||
* @return Integer
|
||||
*/
|
||||
Integer countByCategoryId(Long id);
|
||||
|
||||
/**
|
||||
* 动态条件查询套餐
|
||||
* @param setmeal Setmeal
|
||||
* @return List<Setmeal>
|
||||
*/
|
||||
List<Setmeal> list(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询菜品选项
|
||||
* @param setmealId
|
||||
* @return
|
||||
*/
|
||||
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.sky.service;
|
|||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.DishVO;
|
||||
|
||||
|
@ -40,4 +41,11 @@ public interface DishService {
|
|||
* @param dishDTO DishDTO
|
||||
*/
|
||||
void updateWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
List<DishVO> listWithFlavor(Dish dish);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
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;
|
||||
|
||||
public interface SetmealService {
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param setmeal
|
||||
* @return
|
||||
*/
|
||||
List<Setmeal> list(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据id查询菜品选项
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<DishItemVO> getDishItemById(Long id);
|
||||
|
||||
}
|
|
@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
@ -145,4 +146,28 @@ public class DishServiceImpl implements DishService {
|
|||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetMealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 套餐业务实现
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SetmealServiceImpl implements SetmealService {
|
||||
|
||||
@Resource
|
||||
private SetmealMapper setmealMapper;
|
||||
@Resource
|
||||
private SetMealDishMapper setmealDishMapper;
|
||||
@Resource
|
||||
private DishMapper dishMapper;
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
*
|
||||
* @param setmeal Setmeal
|
||||
* @return List<Setmeal>
|
||||
*/
|
||||
public List<Setmeal> list(Setmeal setmeal) {
|
||||
return setmealMapper.list(setmeal);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询菜品选项
|
||||
*
|
||||
* @param id Long
|
||||
* @return List<DishItemVO>
|
||||
*/
|
||||
public List<DishItemVO> getDishItemById(Long id) {
|
||||
return setmealMapper.getDishItemBySetmealId(id);
|
||||
}
|
||||
}
|
|
@ -10,4 +10,12 @@
|
|||
#{dishId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!-- 根据套餐id查询菜品选项 -->
|
||||
<select id="getDishItemBySetmealId" resultType="com.sky.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>
|
||||
|
|
|
@ -8,4 +8,28 @@
|
|||
from setmeal
|
||||
where category_id = #{categoryId}
|
||||
</select>
|
||||
|
||||
<!-- 动态条件查询套餐 -->
|
||||
<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>
|
||||
|
||||
<!-- 根据套餐id查询菜品选项 -->
|
||||
<select id="getDishItemBySetmealId" resultType="com.sky.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>
|
||||
|
|
Loading…
Reference in New Issue