完成套餐管理功能
This commit is contained in:
parent
73a57857e0
commit
1dd0b6fe93
@ -2,6 +2,7 @@ package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
@ -91,4 +92,30 @@ public class DishController {
|
||||
dishService.updateWithFlavor(dishDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用、禁用菜品
|
||||
* @param status
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("启用禁用分菜品")
|
||||
public Result<String> startOrStop(@PathVariable("status") Integer status, Long id){
|
||||
dishService.startOrStop(status,id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类ID查询菜品列表
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类ID查询菜品列表")
|
||||
public Result<List<Dish>> list(Long categoryId) {
|
||||
log.info("根据分类ID查询菜品列表:{}", categoryId);
|
||||
List<Dish> list = dishService.list(categoryId);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.SetmealVO;
|
||||
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.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 套餐管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/setmeal")
|
||||
@Api(tags = "套餐管理相关接口")
|
||||
@Slf4j
|
||||
public class SetmealController {
|
||||
|
||||
@Autowired
|
||||
private SetmealService setmealService;
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmealDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增套餐")
|
||||
public Result save(@RequestBody SetmealDTO setmealDTO) {
|
||||
log.info("新增套餐:{}", setmealDTO);
|
||||
setmealService.saveWithDish(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询套餐
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页查询套餐")
|
||||
public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping
|
||||
@ApiOperation("批量删除套餐")
|
||||
public Result delete(@RequestParam List<Long> ids){
|
||||
setmealService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询套餐
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("根据id查询套餐")
|
||||
public Result<SetmealVO> getById(@PathVariable Long id) {
|
||||
log.info("根据id查询套餐:{}", id);
|
||||
SetmealVO setmealVO = setmealService.getByIdWithDish(id);
|
||||
return Result.success(setmealVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
* @param setmealDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("修改套餐")
|
||||
public Result update(@RequestBody SetmealDTO setmealDTO) {
|
||||
log.info("修改套餐:{}", setmealDTO);
|
||||
setmealService.update(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用停售套餐
|
||||
* @param status
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("启用停售套餐")
|
||||
public Result startOrStop(@PathVariable Integer status, Long id) {
|
||||
log.info("启用停售套餐:status={}, id={}", status, id);
|
||||
setmealService.startOrStop(status, id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
package com.sky.handler;
|
||||
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.exception.BaseException;
|
||||
import com.sky.result.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
|
||||
/**
|
||||
* 全局异常处理器,处理项目中抛出的业务异常
|
||||
*/
|
||||
@ -23,4 +26,25 @@ public class GlobalExceptionHandler {
|
||||
log.error("异常信息:{}", ex.getMessage());
|
||||
return Result.error(ex.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 捕获SQL异常
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler
|
||||
public Result exceptionHandler(SQLIntegrityConstraintViolationException ex){
|
||||
String message = ex.getMessage();
|
||||
//重复的键值对
|
||||
if (message.contains("Duplicate entry")) {
|
||||
String[] split = message.split(" ");
|
||||
String name = split[2];
|
||||
String msg = name + MessageConstant.ALREADY_EXISTS;
|
||||
return Result.error(msg);
|
||||
}
|
||||
else {
|
||||
return Result.error(MessageConstant.UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -64,4 +64,20 @@ public interface DishMapper {
|
||||
*/
|
||||
@AutoFill(value = OperationType.UPDATE)
|
||||
void update(Dish dish);
|
||||
|
||||
/**
|
||||
* 动态条件查询菜品列表
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
List<Dish> list(Dish dish);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询菜品列表
|
||||
* @param setmealId
|
||||
* @return
|
||||
*/
|
||||
@Select("select d.* from dish d left join setmeal_dish sd on d.id = sd.dish_id" +
|
||||
" where sd.setmeal_id = #{setmealId}")
|
||||
List<Dish> getBySetmealId(Long setmealId);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.SetmealDish;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -13,4 +15,31 @@ public interface SetmealDishMapper {
|
||||
* @return
|
||||
*/
|
||||
List<Long> getSetmealIdsByDishIds(List<Long> dishIds);
|
||||
|
||||
/**
|
||||
* 批量插入套餐与菜品关联数据
|
||||
* @param setmealDishes
|
||||
*/
|
||||
void insertBatch(List<SetmealDish> setmealDishes);
|
||||
|
||||
/**
|
||||
* 根据套餐id列表批量删除关联数据
|
||||
* @param setmealIds
|
||||
*/
|
||||
void deleteBySetmealIds(List<Long> setmealIds);
|
||||
|
||||
/**
|
||||
* 根据套餐id获取关联的菜品列表
|
||||
* @param setmealId
|
||||
* @return List<SetmealDish>
|
||||
*/
|
||||
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
List<SetmealDish> getBySetmealId(Long setmealId);
|
||||
|
||||
/**
|
||||
* 根据套餐id删除关联的菜品数据
|
||||
* @param setmealId
|
||||
*/
|
||||
@Select("delete from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
void deleteBySetmealId(Long setmealId);
|
||||
}
|
||||
|
@ -1,8 +1,18 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealMapper {
|
||||
|
||||
@ -14,4 +24,47 @@ public interface SetmealMapper {
|
||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
||||
Integer countByCategoryId(Long id);
|
||||
|
||||
/**
|
||||
* 插入套餐
|
||||
* @param setmeal
|
||||
*/
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据套餐名称查询套餐
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from setmeal where name = #{name}")
|
||||
Setmeal getByName(String name);
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询套餐
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据id查询套餐
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from setmeal where id = #{id}")
|
||||
Setmeal getById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
* @param ids
|
||||
*/
|
||||
void deleteByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 动态更新套餐
|
||||
* @param setmeal
|
||||
*/
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Setmeal setmeal);
|
||||
}
|
||||
|
@ -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,18 @@ public interface DishService {
|
||||
* @param dishDTO
|
||||
*/
|
||||
void updateWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品列表
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
List<Dish> list(Long categoryId);
|
||||
|
||||
/**
|
||||
* 启用或禁用菜品
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
}
|
||||
|
49
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
49
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.SetmealVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SetmealService {
|
||||
/**
|
||||
* 保存套餐及菜品信息
|
||||
* @param setmealDTO
|
||||
*/
|
||||
void saveWithDish(SetmealDTO setmealDTO);
|
||||
|
||||
/**
|
||||
* 分页查询套餐信息
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 批量删除套餐信息
|
||||
* @param ids
|
||||
*/
|
||||
void deleteBatch(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询套餐及菜品信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
SetmealVO getByIdWithDish(Long id);
|
||||
|
||||
/**
|
||||
* 更新套餐信息
|
||||
* @param setmealDTO
|
||||
*/
|
||||
void update(SetmealDTO setmealDTO);
|
||||
|
||||
/**
|
||||
* 启用或停用套餐
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
}
|
@ -46,7 +46,6 @@ public class DishServiceImpl implements DishService {
|
||||
@Transactional
|
||||
public void saveWithFlavor(DishDTO dishDTO) {
|
||||
Dish dish = new Dish();
|
||||
|
||||
BeanUtils.copyProperties(dishDTO, dish);
|
||||
|
||||
//向菜品表插入一条数据
|
||||
@ -123,7 +122,6 @@ public class DishServiceImpl implements DishService {
|
||||
|
||||
/**
|
||||
* 根据id查询菜品和对应的口味
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ -144,7 +142,6 @@ public class DishServiceImpl implements DishService {
|
||||
|
||||
/**
|
||||
* 更新菜品和对应的口味
|
||||
*
|
||||
* @param dishDTO
|
||||
*/
|
||||
@Transactional
|
||||
@ -168,6 +165,32 @@ public class DishServiceImpl implements DishService {
|
||||
//向口味表查入n条数据
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品列表
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
public List<Dish> list(Long categoryId) {
|
||||
Dish dish = Dish.builder()
|
||||
.categoryId(categoryId)
|
||||
.status(StatusConstant.ENABLE)
|
||||
.build();
|
||||
return dishMapper.list(dish);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用或禁用菜品
|
||||
* @param status
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
Dish dish = Dish.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.build();
|
||||
dishMapper.update(dish);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import com.sky.exception.PasswordErrorException;
|
||||
import com.sky.mapper.EmployeeMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.EmployeeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -26,6 +27,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@Autowired
|
||||
@ -72,13 +74,6 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
* @param employeeDTO
|
||||
*/
|
||||
public void save(EmployeeDTO employeeDTO) {
|
||||
String username = employeeDTO.getUsername();
|
||||
|
||||
//判断用户是否存在
|
||||
if (employeeMapper.getByUsername(username) != null) {
|
||||
throw new BaseException(username + MessageConstant.ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
Employee employee = new Employee();
|
||||
|
||||
//对象属性拷贝
|
||||
|
@ -0,0 +1,178 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.SetmealDish;
|
||||
import com.sky.exception.BaseException;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
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.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SetmealServiceImpl implements SetmealService {
|
||||
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
|
||||
/**
|
||||
* 保存套餐及菜品信息
|
||||
* @param setmealDTO
|
||||
*/
|
||||
@Transactional
|
||||
public void saveWithDish(SetmealDTO setmealDTO) {
|
||||
Setmeal setmeal = new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||
|
||||
//向套餐表插入数据
|
||||
setmealMapper.insert(setmeal);
|
||||
|
||||
//获取生成的套餐id
|
||||
Long setmealId = setmeal.getId();
|
||||
|
||||
//为套餐中的每个菜品设置套餐id
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
setmealDishes.forEach(setmealDish -> {
|
||||
setmealDish.setSetmealId(setmealId);
|
||||
});
|
||||
|
||||
//保存套餐和菜品的关联信息
|
||||
setmealDishMapper.insertBatch(setmealDishes);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询套餐列表
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
//获取页码和每页数量
|
||||
int pageNum = setmealPageQueryDTO.getPage();
|
||||
int pageSize = setmealPageQueryDTO.getPageSize();
|
||||
|
||||
//分页查询
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
Page<SetmealVO> page = setmealMapper.pageQuery(setmealPageQueryDTO);
|
||||
|
||||
//封装分页结果
|
||||
return new PageResult(page.getTotal(), page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
* @param ids
|
||||
*/
|
||||
public void deleteBatch(List<Long> ids) {
|
||||
//加入套餐正在起售中,不能删除
|
||||
ids.forEach(id -> {
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
if (StatusConstant.ENABLE == setmeal.getStatus()) {
|
||||
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
|
||||
}
|
||||
});
|
||||
|
||||
//删除套餐,及其套餐菜品表中关联的菜品信息
|
||||
//根据菜品id集合批量删除菜品数据
|
||||
setmealMapper.deleteByIds(ids);
|
||||
|
||||
//根据菜品id集合批量删除菜品口味数据
|
||||
setmealDishMapper.deleteBySetmealIds(ids);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询套餐及其菜品信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public SetmealVO getByIdWithDish(Long id) {
|
||||
//查询套餐
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
//查询套餐关联的菜品
|
||||
List<SetmealDish> setmealDishes = setmealDishMapper.getBySetmealId(id);
|
||||
|
||||
//封装套餐及菜品信息
|
||||
SetmealVO setmealVO = new SetmealVO();
|
||||
BeanUtils.copyProperties(setmeal, setmealVO);
|
||||
setmealVO.setSetmealDishes(setmealDishes);
|
||||
|
||||
return setmealVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新套餐信息
|
||||
* @param setmealDTO
|
||||
*/
|
||||
@Transactional
|
||||
public void update(SetmealDTO setmealDTO) {
|
||||
Setmeal setmeal = new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||
|
||||
//修改套餐表
|
||||
setmealMapper.update(setmeal);
|
||||
|
||||
//获取修改的套餐id
|
||||
Long setmealId = setmeal.getId();
|
||||
|
||||
//删除原有的套餐菜品关联信息,在插入新的关联信息
|
||||
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||
//为套餐中的每个菜品设置套餐id
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
setmealDishes.forEach(setmealDish -> {
|
||||
setmealDish.setSetmealId(setmealId);
|
||||
});
|
||||
//保存新的套餐菜品的关联信息
|
||||
setmealDishMapper.insertBatch(setmealDishes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用或停用套餐
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
//判断套餐内是否有停售菜品,有则不能起售
|
||||
if (status == StatusConstant.ENABLE) {
|
||||
//查询套餐关联的菜品
|
||||
List<Dish> dishes = dishMapper.getBySetmealId(id);
|
||||
//遍历检查是否有停售菜品
|
||||
if (dishes != null && dishes.size() > 0) {
|
||||
dishes.forEach(dish -> {
|
||||
if (StatusConstant.DISABLE == dish.getStatus()) {
|
||||
throw new BaseException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//修改套餐状态
|
||||
Setmeal setmeal = Setmeal.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.build();
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
}
|
@ -46,4 +46,19 @@
|
||||
</where>
|
||||
order by d.create_time desc
|
||||
</select>
|
||||
<select id="list" resultType="com.sky.entity.Dish">
|
||||
select * from dish
|
||||
<where>
|
||||
<if test="name!= null and name!= ''">
|
||||
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>
|
||||
|
@ -2,6 +2,21 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.SetmealDishMapper">
|
||||
<insert id="insertBatch">
|
||||
insert into setmeal_dish
|
||||
(setmeal_id, dish_id, name, price, copies)
|
||||
values
|
||||
<foreach collection="setmealDishes" item="sd" separator=",">
|
||||
(#{sd.setmealId}, #{sd.dishId}, #{sd.name}, #{sd.price}, #{sd.copies})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteBySetmealIds">
|
||||
delete from setmeal_dish where setmeal_id in
|
||||
<foreach collection="setmealIds" item="setmealId" separator="," open="(" close=")">
|
||||
#{setmealId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
|
||||
select setmeal_id from setmeal_dish where dish_id in
|
||||
|
51
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
51
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.SetmealMapper">
|
||||
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into setmeal
|
||||
(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user)
|
||||
values
|
||||
(#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update setmeal
|
||||
<set>
|
||||
<if test="categoryId!= null">category_id = #{categoryId},</if>
|
||||
<if test="name!= null and name!= ''">name = #{name},</if>
|
||||
<if test="price!= null">price = #{price},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="image != null">image = #{image},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="updateUser != null">update_user = #{updateUser},</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteByIds">
|
||||
delete from setmeal where id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="pageQuery" resultType="com.sky.vo.SetmealVO">
|
||||
select s.*, c.name categoty_name from setmeal s left join category c on s.category_id = c.id
|
||||
<where>
|
||||
<if test="name!= null and name!= ''">
|
||||
and s.name like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and s.status = #{status}
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
and s.category_id = #{categoryId}
|
||||
</if>
|
||||
</where>
|
||||
order by s.create_time desc
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user