Compare commits

..

No commits in common. "39640025affb1d2b2c8b560d107483cf2c3639bf" and "e9bdc8baeb5656c18b1ef0b87110743467802652" have entirely different histories.

16 changed files with 28 additions and 451 deletions

View File

@ -1,13 +1,17 @@
package com.sky.config; package com.sky.config;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
import javax.annotation.Resource;
@Configuration @Configuration
@Slf4j @Slf4j
public class RedisConfiguration { public class RedisConfiguration {

View File

@ -1,9 +1,12 @@
package com.sky.config; package com.sky.config;
import ch.qos.logback.classic.pattern.MessageConverter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sky.interceptor.JwtTokenAdminInterceptor; import com.sky.interceptor.JwtTokenAdminInterceptor;
import com.sky.interceptor.JwtTokenUserInterceptor; import com.sky.interceptor.JwtTokenUserInterceptor;
import com.sky.json.JacksonObjectMapper; import com.sky.json.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
@ -44,7 +47,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
.addPathPatterns("/admin/**") .addPathPatterns("/admin/**")
.excludePathPatterns("/admin/employee/login"); .excludePathPatterns("/admin/employee/login");
registry.addInterceptor(jwtTokenUserInterceptor) registry.addInterceptor(jwtTokenAdminInterceptor)
.addPathPatterns("/user/**") .addPathPatterns("/user/**")
.excludePathPatterns("/user/user/login") .excludePathPatterns("/user/user/login")
.excludePathPatterns("/user/shop/status"); .excludePathPatterns("/user/shop/status");

View File

@ -10,12 +10,10 @@ import com.sky.vo.DishVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Set;
@RestController @RestController
@RequestMapping("/admin/dish") @RequestMapping("/admin/dish")
@ -24,8 +22,6 @@ import java.util.Set;
public class DishController { public class DishController {
@Resource @Resource
private DishService dishService; private DishService dishService;
@Resource
private RedisTemplate redisTemplate;
/** /**
* 新增菜品和口味 * 新增菜品和口味
@ -38,10 +34,6 @@ public class DishController {
public Result<String> save(@RequestBody DishDTO dishDTO) { public Result<String> save(@RequestBody DishDTO dishDTO) {
log.info("新增菜品:{}", dishDTO); log.info("新增菜品:{}", dishDTO);
dishService.saveWithFlavor(dishDTO); dishService.saveWithFlavor(dishDTO);
// 修改新增清理Redis数据
String key = "dish_" + dishDTO.getCategoryId();
redisTemplate.delete(key);
return Result.success(); return Result.success();
} }
@ -70,9 +62,6 @@ public class DishController {
public Result<String> delete(@RequestParam List<Long> ids) { public Result<String> delete(@RequestParam List<Long> ids) {
log.info("菜品批量删除:{}", ids); log.info("菜品批量删除:{}", ids);
dishService.deleteBatch(ids); dishService.deleteBatch(ids);
// 以dish_开头全部删除
cleanRedisCache();
return Result.success(); return Result.success();
} }
@ -101,9 +90,6 @@ public class DishController {
public Result<String> update(@RequestBody DishDTO dishDTO) { public Result<String> update(@RequestBody DishDTO dishDTO) {
log.info("修改菜品:{}", dishDTO); log.info("修改菜品:{}", dishDTO);
dishService.updateWithFlavor(dishDTO); dishService.updateWithFlavor(dishDTO);
// 如果修改了就将所有的缓存数据全部删除
cleanRedisCache();
return Result.success(); return Result.success();
} }
@ -133,14 +119,4 @@ public class DishController {
List<Dish> list = dishService.list(categoryId); List<Dish> list = dishService.list(categoryId);
return Result.success(list); return Result.success(list);
} }
/**
* 如果修改了就将所有的缓存数据全部删除
*/
private void cleanRedisCache() {
Set keys = redisTemplate.keys("dish_*");
if (keys != null && !keys.isEmpty()) {
redisTemplate.delete(keys);
}
}
} }

View File

@ -1,20 +1,19 @@
package com.sky.controller.admin; package com.sky.controller.admin;
import com.sky.dto.SetmealDTO; import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result; import com.sky.result.Result;
import com.sky.service.SetmealService; import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
@RestController("adminRestController") @RestController
@RequestMapping("/admin/setmeal") @RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口") @Api(tags = "套餐相关接口")
@Slf4j @Slf4j
@ -34,70 +33,4 @@ public class SetmealController {
setmealService.saveWithDish(setmealDTO); setmealService.saveWithDish(setmealDTO);
return Result.success(); return Result.success();
} }
/**
* 分页查询
*
* @param setmealPageQueryDTO 请求参数
* @return 返回数据
*/
@ApiOperation("分页查询")
@GetMapping("page")
public Result<PageResult> pageResultResult(SetmealPageQueryDTO setmealPageQueryDTO) {
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
return Result.success(pageResult);
}
/**
* 套餐起售停售
*
* @param status Integer
* @param id Long
* @return Result
*/
@ApiOperation("套餐起售停售")
@PostMapping("status/{status}")
public Result startOrStop(@PathVariable Integer status, Long id) {
setmealService.startOrStop(status, id);
return Result.success();
}
/**
* 批量删除套餐
*
* @param ids 删除集合
* @return Null
*/
@ApiOperation("批量删除套餐")
@DeleteMapping("")
public Result delete(@RequestParam List<Long> ids) {
setmealService.delete(ids);
return Result.success();
}
/**
* 根据id查询套餐
*
* @param id Long
* @return Result
*/
@ApiOperation("根据id查询套餐")
@GetMapping("{id}")
public Result getById(@PathVariable Long id) {
SetmealVO setmealVO = setmealService.getById(id);
return Result.success(setmealVO);
}
/**
* 修改套餐
*
* @param setmealDTO SetmealDTO
* @return Result
*/
@ApiOperation("修改套餐")
@PutMapping()
public Result update(@RequestBody SetmealDTO setmealDTO) {
setmealService.update(setmealDTO);
return Result.success();
}
} }

View File

@ -5,11 +5,10 @@ import com.sky.result.Result;
import com.sky.service.CategoryService; import com.sky.service.CategoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; 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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
@RestController("userCategoryController") @RestController("userCategoryController")
@ -17,16 +16,15 @@ import java.util.List;
@Api(tags = "C端-分类接口") @Api(tags = "C端-分类接口")
public class CategoryController { public class CategoryController {
@Resource @Autowired
private CategoryService categoryService; private CategoryService categoryService;
/** /**
* 查询分类 * 查询分类
* * @param type
* @param type Integer * @return
* @return Result<List < Category>>
*/ */
@GetMapping("list") @GetMapping("/list")
@ApiOperation("查询分类") @ApiOperation("查询分类")
public Result<List<Category>> list(Integer type) { public Result<List<Category>> list(Integer type) {
List<Category> list = categoryService.list(type); List<Category> list = categoryService.list(type);

View File

@ -1,6 +1,5 @@
package com.sky.controller.user; package com.sky.controller.user;
import com.alibaba.fastjson.JSON;
import com.sky.constant.StatusConstant; import com.sky.constant.StatusConstant;
import com.sky.entity.Dish; import com.sky.entity.Dish;
import com.sky.result.Result; import com.sky.result.Result;
@ -9,52 +8,35 @@ import com.sky.vo.DishVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
@RestController("userDishController") @RestController("userDishController")
@RequestMapping("/user/dish") @RequestMapping("/user/dish")
@Slf4j @Slf4j
@Api(tags = "C端-菜品浏览接口") @Api(tags = "C端-菜品浏览接口")
public class DishController { public class DishController {
@Resource @Autowired
private DishService dishService; private DishService dishService;
@Resource
private RedisTemplate redisTemplate;
/** /**
* 根据分类id查询菜品 * 根据分类id查询菜品
* *
* @param categoryId Long * @param categoryId
* @return Result<List < DishVO>> * @return
*/ */
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("根据分类id查询菜品") @ApiOperation("根据分类id查询菜品")
public Result<List<DishVO>> list(@RequestParam Long categoryId) { public Result<List<DishVO>> list(Long categoryId) {
// 设置Redis中key
String key = "dish_" + categoryId;
// 查询Redis中数据
List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);
// 如果不为空返回集合
if (list != null && !list.isEmpty()) {
return Result.success(list);
}
// 如果Redis中没有将值放入
Dish dish = new Dish(); Dish dish = new Dish();
dish.setCategoryId(categoryId); dish.setCategoryId(categoryId);
dish.setStatus(StatusConstant.ENABLE);// 查询起售中的菜品 dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品
// 将这个数据保存到redis中
list = dishService.listWithFlavor(dish); List<DishVO> list = dishService.listWithFlavor(dish);
redisTemplate.opsForValue().set(key, JSON.toJSON(list), 7, TimeUnit.DAYS);
// 如果Redis中没有返回这个数据并保存这个数据
return Result.success(list); return Result.success(list);
} }

View File

@ -74,12 +74,4 @@ public interface DishMapper {
* @return List<Dish> * @return List<Dish>
*/ */
List<Dish> list(Dish dish); List<Dish> list(Dish dish);
/**
* 起售套餐时判断套餐内是否有停售菜品有停售菜品提示"套餐内包含未启售菜品,无法启售"
*
* @param id Long
* @return List<Dish>
*/
List<Dish> getBySetmealId(Long id);
} }

View File

@ -1,13 +1,10 @@
package com.sky.mapper; package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill; import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal; import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish; import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType; import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO; import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@ -44,27 +41,4 @@ public interface SetMealDishMapper {
* @param setmealDishes List<SetmealDish> * @param setmealDishes List<SetmealDish>
*/ */
void insertBatch(List<SetmealDish> setmealDishes); void insertBatch(List<SetmealDish> setmealDishes);
/**
* 分页查询
*
* @param setmealPageQueryDTO SetmealPageQueryDTO
* @return Page<SetmealVO>
*/
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
/**
* 根据套餐id删除套餐和菜品的关联关系
*
* @param setmealId Long
*/
void deleteBySetmealId(Long setmealId);
/**
* 根据套餐id查询套餐和菜品的关联关系
*
* @param id Long
* @return List<SetmealDish>
*/
List<SetmealDish> getBySetmealId(Long id);
} }

View File

@ -41,28 +41,4 @@ public interface SetmealMapper {
*/ */
@AutoFill(OperationType.INSERT) @AutoFill(OperationType.INSERT)
void insert(Setmeal setmeal); void insert(Setmeal setmeal);
/**
* 套餐起售停售
*
* @param setmeal Setmeal
*/
@AutoFill(OperationType.UPDATE)
void update(Setmeal setmeal);
/**
* 根据id获取套餐
*
* @param id Long
* @return Setmeal
*/
Setmeal getById(Long id);
/**
* 删除套餐表中的数据
*
* @param setmealId Long
*/
void deleteById(Long setmealId);
} }

View File

@ -1,11 +1,8 @@
package com.sky.service; package com.sky.service;
import com.sky.dto.SetmealDTO; import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal; import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.vo.DishItemVO; import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import java.util.List; import java.util.List;
@ -34,42 +31,4 @@ public interface SetmealService {
* @param setmealDTO SetmealDTO * @param setmealDTO SetmealDTO
*/ */
void saveWithDish(SetmealDTO setmealDTO); void saveWithDish(SetmealDTO setmealDTO);
/**
* 分页查询
*
* @param setmealPageQueryDTO SetmealPageQueryDTO
* @return PageResult
*/
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
/**
* 套餐起售停售
*
* @param status Integer
* @param id Long
*/
void startOrStop(Integer status, Long id);
/**
* 批量删除套餐
*
* @param ids List<Long>
*/
void delete(List<Long> ids);
/**
* 根据id查询套餐
*
* @param id Long
* @return SetmealVO
*/
SetmealVO getById(Long id);
/**
* 修改套餐
*
* @param setmealDTO SetmealDTO
*/
void update(SetmealDTO setmealDTO);
} }

View File

@ -18,7 +18,6 @@ import com.sky.service.DishService;
import com.sky.vo.DishVO; import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -35,8 +34,6 @@ public class DishServiceImpl implements DishService {
private DishFlavorMapper dishFlavorMapper; private DishFlavorMapper dishFlavorMapper;
@Resource @Resource
private SetMealDishMapper setMealDishMapper; private SetMealDishMapper setMealDishMapper;
@Resource
private RedisTemplate redisTemplate;
/** /**
* 新增菜品和口味 * 新增菜品和口味
@ -198,10 +195,6 @@ public class DishServiceImpl implements DishService {
} }
} }
} }
// 停售时将Redis缓存清除
dish = dishMapper.getById(id);
String key = "dish_" + dish.getCategoryId();
redisTemplate.delete(key);
} }
/** /**

View File

@ -1,23 +1,13 @@
package com.sky.service.impl; 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.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal; import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish; import com.sky.entity.SetmealDish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.exception.SetmealEnableFailedException;
import com.sky.mapper.DishMapper; import com.sky.mapper.DishMapper;
import com.sky.mapper.SetMealDishMapper; import com.sky.mapper.SetMealDishMapper;
import com.sky.mapper.SetmealMapper; import com.sky.mapper.SetmealMapper;
import com.sky.result.PageResult;
import com.sky.service.SetmealService; import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO; import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -80,110 +70,4 @@ public class SetmealServiceImpl implements SetmealService {
// 保存套餐和菜品的关联关系 // 保存套餐和菜品的关联关系
setmealDishMapper.insertBatch(setmealDishes); setmealDishMapper.insertBatch(setmealDishes);
} }
/**
* 分页查询
*
* @param setmealPageQueryDTO SetmealPageQueryDTO
* @return PageResult
*/
@Override
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
int pageNum = setmealPageQueryDTO.getPage();
int pageSize = setmealPageQueryDTO.getPageSize();
PageHelper.startPage(pageNum, pageSize);
Page<SetmealVO> page = setmealDishMapper.pageQuery(setmealPageQueryDTO);
return new PageResult(page.getTotal(), page.getResult());
}
/**
* 套餐起售停售
*
* @param status Integer
* @param id Long
*/
@Override
public void startOrStop(Integer status, Long id) {
// 起售套餐时判断套餐内是否有停售菜品有停售菜品提示"套餐内包含未启售菜品,无法启售"
if (status.equals(StatusConstant.ENABLE)) {
List<Dish> dishList = dishMapper.getBySetmealId(id);
if (dishList != null && !dishList.isEmpty()) {
dishList.forEach(dish -> {
if (dish.getStatus().equals(StatusConstant.DISABLE)) {
throw new SetmealEnableFailedException(MessageConstant.SETMEAL_ENABLE_FAILED);
}
});
}
}
Setmeal setmeal = Setmeal.builder().id(id).status(status).build();
setmealMapper.update(setmeal);
}
/**
* 批量删除套餐
*
* @param ids List<Long>
*/
@Override
public void delete(List<Long> ids) {
ids.forEach(id -> {
// 根据id获取套餐
Setmeal setmeal = setmealMapper.getById(id);
// 起售中商品不能删除
if (setmeal.getStatus().equals(StatusConstant.ENABLE)) {
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
}
});
ids.forEach(setmealId -> {
// 删除套餐表中的数据
setmealMapper.deleteById(setmealId);
// 删除套餐菜品关系表中的数据
setmealDishMapper.deleteBySetmealId(setmealId);
});
}
/**
* 根据id查询套餐
*
* @param id Long
* @return SetmealVO
*/
@Override
public SetmealVO getById(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 SetmealDTO
*/
@Override
public void update(SetmealDTO setmealDTO) {
Setmeal setmeal = new Setmeal();
BeanUtils.copyProperties(setmealDTO, setmeal);
// 1修改套餐表执行update
setmealMapper.update(setmeal);
// 套餐id
Long setmealId = setmealDTO.getId();
// 2删除套餐和菜品的关联关系操作setmeal_dish表执行delete
setmealDishMapper.deleteBySetmealId(setmealId);
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
setmealDishes.forEach(setmealDish -> {
setmealDish.setSetmealId(setmealId);
});
// 3重新插入套餐和菜品的关联关系操作setmeal_dish表执行insert
setmealDishMapper.insertBatch(setmealDishes);
}
} }

View File

@ -21,6 +21,7 @@ spring:
port: ${sky.redis.port} port: ${sky.redis.port}
password: ${sky.redis.password} password: ${sky.redis.password}
database: ${sky.redis.database} database: ${sky.redis.database}
timeout: 5000
mybatis: mybatis:

View File

@ -108,12 +108,4 @@
</where> </where>
order by create_time desc order by create_time desc
</select> </select>
<!-- 起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售" -->
<select id="getBySetmealId" resultType="com.sky.entity.Dish">
select a.*
from dish a
left join setmeal_dish b on a.id = b.dish_id
where b.setmeal_id = #{id}
</select>
</mapper> </mapper>

View File

@ -44,13 +44,6 @@
where id = #{id} where id = #{id}
</update> </update>
<!-- 根据套餐id删除套餐和菜品的关联关系 -->
<delete id="deleteBySetmealId">
delete
from setmeal_dish
where setmeal_id = #{setmealId}
</delete>
<!-- 查询对应套餐id --> <!-- 查询对应套餐id -->
<select id="getSetMealDishIds" resultType="java.lang.Long"> <select id="getSetMealDishIds" resultType="java.lang.Long">
select * select *
@ -67,35 +60,4 @@
left join dish d on sd.dish_id = d.id left join dish d on sd.dish_id = d.id
where sd.setmeal_id = #{setmealId} where sd.setmeal_id = #{setmealId}
</select> </select>
<!-- 分页查询 -->
<select id="pageQuery" resultType="com.sky.vo.SetmealVO">
select
s.*,c.name categoryName
from
setmeal s
left join
category c
on
s.category_id = c.id
<where>
<if test="name != null">
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>
<!-- 根据套餐id查询套餐和菜品的关联关系 -->
<select id="getBySetmealId" resultType="com.sky.entity.SetmealDish">
select *
from setmeal_dish
where setmeal_id = #{setmealId}
</select>
</mapper> </mapper>

View File

@ -10,51 +10,6 @@
#{createUser}, #{updateUser}) #{createUser}, #{updateUser})
</insert> </insert>
<!-- 套餐起售停售 -->
<update id="update">
update setmeal
<set>
<if test="categoryId != null">
category_id = #{categoryId},
</if>
<if test="name != null">
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="createTime != null">
create_time = #{createTime},
</if>
<if test="createUser != null">
create_user = #{createUser},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="updateUser != null">
update_user = #{updateUser},
</if>
</set>
where id = #{id};
</update>
<!-- 根据套餐id删除套餐和菜品的关联关系 -->
<delete id="deleteById">
delete
from setmeal
where id = #{id}
</delete>
<!-- 根据分类id查询套餐的数量 --> <!-- 根据分类id查询套餐的数量 -->
<select id="countByCategoryId" resultType="java.lang.Integer"> <select id="countByCategoryId" resultType="java.lang.Integer">
select count(id) select count(id)
@ -85,11 +40,4 @@
left join dish d on sd.dish_id = d.id left join dish d on sd.dish_id = d.id
where sd.setmeal_id = #{setmealId} where sd.setmeal_id = #{setmealId}
</select> </select>
<!-- 根据id获取套餐 -->
<select id="getById" resultType="com.sky.entity.Setmeal">
select *
from setmeal
where id = #{id}
</select>
</mapper> </mapper>