缓存菜品业务代码开发 + 菜品的起售停售代码修正
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.sky.config;
|
||||
|
||||
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
||||
import com.sky.interceptor.JwtTokenUserInterceptor;
|
||||
import com.sky.json.JacksonObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,6 +30,8 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
|
||||
@Autowired
|
||||
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
||||
@Autowired
|
||||
private JwtTokenUserInterceptor jwtTokenUserInterceptor;
|
||||
|
||||
/**
|
||||
* 注册自定义拦截器
|
||||
@@ -40,6 +43,12 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
registry.addInterceptor(jwtTokenAdminInterceptor)
|
||||
.addPathPatterns("/admin/**")
|
||||
.excludePathPatterns("/admin/employee/login");
|
||||
|
||||
registry.addInterceptor(jwtTokenUserInterceptor)
|
||||
.addPathPatterns("/user/**")
|
||||
.excludePathPatterns("/user/user/login")
|
||||
.excludePathPatterns("/user/shop/status");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.sky.controller.admin;
|
||||
|
||||
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
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;
|
||||
@@ -12,9 +14,11 @@ 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.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,6 +34,8 @@ public class DishController {
|
||||
|
||||
@Autowired
|
||||
private DishService dishService;
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,6 +48,11 @@ public class DishController {
|
||||
public Result save(@RequestBody DishDTO dishDTO) {
|
||||
log.info("新增菜品:{}", dishDTO);
|
||||
dishService.saveWithFlavor(dishDTO);
|
||||
|
||||
//清理缓存数据
|
||||
String key = "dish" + dishDTO.getCategoryId();
|
||||
cleanCache(key);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@@ -74,6 +85,9 @@ public class DishController {
|
||||
|
||||
dishService.deleteBatch(ids);
|
||||
|
||||
//将所有菜品的缓存数据删除
|
||||
cleanCache("dish*");
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@@ -107,6 +121,42 @@ public class DishController {
|
||||
|
||||
dishService.updateWithFlavor(dishDTO);
|
||||
|
||||
//将所有缓存数据清理
|
||||
cleanCache("dish*");
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询菜品")
|
||||
public Result<List<Dish>> list(Long categoryId){
|
||||
List<Dish> list = dishService.list(categoryId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("菜品起售停售")
|
||||
public Result startOrStop(@PathVariable Integer status, Long id){
|
||||
dishService.startOrStop(status, id);
|
||||
|
||||
//将缓存清空
|
||||
cleanCache("dish*");
|
||||
/* Set keys = redisTemplate.keys("dish_*");
|
||||
redisTemplate.delete(keys);*/
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清理缓存数据
|
||||
* @param pattern
|
||||
*/
|
||||
private void cleanCache(String pattern){
|
||||
Set keys = redisTemplate.keys(pattern);
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
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.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Api(tags = "套餐相关接口")
|
||||
@RequestMapping ("/admin/setmeal")
|
||||
@Slf4j
|
||||
public class SetmealController {
|
||||
|
||||
|
||||
@Autowired
|
||||
SetmealService setmealService;
|
||||
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmealDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增套餐")
|
||||
public Result save(@RequestBody SetmealDTO 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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
*/
|
||||
@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){
|
||||
SetmealVO setmealVO = setmealService.getByIdWithDish(id);
|
||||
return Result.success(setmealVO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
* @param setmealDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("修改套餐")
|
||||
public Result update(@RequestBody SetmealDTO setmealDTO){
|
||||
setmealService.update(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("套餐起售停售")
|
||||
public Result startOrStop(@PathVariable Integer status, Long id){
|
||||
setmealService.startOrStop(status, id);
|
||||
return Result.success();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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,78 @@
|
||||
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.data.redis.core.RedisTemplate;
|
||||
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;
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
// /**
|
||||
// * 根据分类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);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 根据分类的id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询菜品")
|
||||
public Result<List<DishVO>> list(Long categoryId){
|
||||
|
||||
//构造redis当中的key dish_动态id
|
||||
String key = "dish" + categoryId;
|
||||
|
||||
//查询Redis中是否存在菜品数据
|
||||
List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);
|
||||
if(list != null && list.size() > 0){
|
||||
//如果存在 直接返回 无须查询数据
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
//如果不存在 查询数据库 将查询到的数据放入redis中
|
||||
Dish dish = new Dish();
|
||||
dish.setCategoryId(categoryId);
|
||||
dish.setStatus(StatusConstant.ENABLE); //查询起售中的菜品
|
||||
list = dishService.listWithFlavor(dish);
|
||||
|
||||
redisTemplate.opsForValue().set(key, list);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.UserService;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import com.sky.vo.UserLoginVO;
|
||||
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.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/user")
|
||||
@Api(tags = "c端用户相关接口")
|
||||
@Slf4j
|
||||
public class UserController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private JwtProperties jwtProperties;
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("微信登录")
|
||||
public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) throws Exception {
|
||||
|
||||
log.info("微信用户登录:{}", userLoginDTO.getCode());
|
||||
|
||||
//微信登陆
|
||||
User user = userService.wxLogin(userLoginDTO);
|
||||
|
||||
//为微信用户生成jwt令牌
|
||||
Map<String,Object> Claims = new HashMap<>();
|
||||
Claims.put(JwtClaimsConstant.USER_ID,user.getId());
|
||||
String token = JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), Claims);
|
||||
|
||||
|
||||
UserLoginVO userLoginVO = UserLoginVO.builder()
|
||||
.id(user.getId())
|
||||
.openid(user.getOpenid())
|
||||
.token(token)
|
||||
.build();
|
||||
|
||||
return Result.success(userLoginVO);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.sky.interceptor;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* jwt令牌校验的拦截器
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JwtTokenUserInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private JwtProperties jwtProperties;
|
||||
|
||||
/**
|
||||
* 校验jwt
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param handler
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
//判断当前拦截到的是Controller的方法还是其他资源
|
||||
if (!(handler instanceof HandlerMethod)) {
|
||||
//当前拦截到的不是动态方法,直接放行
|
||||
return true;
|
||||
}
|
||||
|
||||
//1、从请求头中获取令牌
|
||||
String token = request.getHeader(jwtProperties.getUserTokenName());
|
||||
|
||||
//2、校验令牌
|
||||
try {
|
||||
log.info("jwt校验:{}", token);
|
||||
Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token);
|
||||
Long userId = Long.valueOf(claims.get(JwtClaimsConstant.USER_ID).toString());
|
||||
log.info("当前用户id:", userId);
|
||||
|
||||
//线程的局部变量
|
||||
BaseContext.setCurrentId(userId);
|
||||
//3、通过,放行
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
//4、不通过,响应401状态码
|
||||
response.setStatus(401);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,4 +70,21 @@ public interface DishMapper {
|
||||
*/
|
||||
@AutoFill(value = OperationType.UPDATE)
|
||||
void update(Dish dish);
|
||||
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
List<Dish> list(Dish dish);
|
||||
|
||||
|
||||
/**
|
||||
* 根据套餐id获得菜品
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
|
||||
List<Dish> getBySetmealId(Long id);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.SetmealDish;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Result;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,10 +17,30 @@ import java.util.List;
|
||||
public interface SetmealDishMapper {
|
||||
|
||||
|
||||
void insertBatch(List<SetmealDish> setmealDishes);
|
||||
|
||||
/**
|
||||
* 根据菜品id查询多个套餐id
|
||||
* @param dishIds
|
||||
* @return
|
||||
*/
|
||||
List<Long> getSetmealIdsByDishIds(List<Long> dishIds);
|
||||
|
||||
|
||||
/**
|
||||
* 根据套餐id删除套餐和菜品的关联关系
|
||||
* @param setmealId
|
||||
*/
|
||||
@Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
void deleteBySetmealId(Long setmealId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id查询套餐和关联的菜品数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
List<SetmealDish> getBySetmealId(Long id);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
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.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealMapper {
|
||||
|
||||
@@ -14,4 +25,63 @@ public interface SetmealMapper {
|
||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
||||
Integer countByCategoryId(Long id);
|
||||
|
||||
/**
|
||||
* 动态条件查询套餐
|
||||
* @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);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmeal
|
||||
*/
|
||||
@AutoFill(value = OperationType.INSERT)
|
||||
void insert(Setmeal setmeal);
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
|
||||
/**
|
||||
*根据id删除套餐
|
||||
* @param setmealId
|
||||
*/
|
||||
@Delete("delete from setmeal where id = #{id}")
|
||||
void deleteById(Long setmealId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id查询套餐
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from setmeal where id = #{id}")
|
||||
Setmeal getById(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 修改套餐表
|
||||
* @param setmeal
|
||||
*/
|
||||
@AutoFill(value = OperationType.UPDATE)
|
||||
void update(Setmeal setmeal);
|
||||
}
|
||||
|
||||
25
sky-server/src/main/java/com/sky/mapper/UserMapper.java
Normal file
25
sky-server/src/main/java/com/sky/mapper/UserMapper.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
|
||||
import com.sky.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
/**
|
||||
* 根据openid查询用户
|
||||
*
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from user where openid = #{openid}")
|
||||
User getByOpenid(String openid);
|
||||
|
||||
|
||||
/**
|
||||
* 插入新用户
|
||||
* @param user
|
||||
*/
|
||||
void insert(User user);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -45,4 +46,30 @@ public interface DishService {
|
||||
* @param dishDTO
|
||||
*/
|
||||
void updateWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
*/
|
||||
List<DishVO> listWithFlavor(Dish dish);
|
||||
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
List<Dish> list(Long categoryId);
|
||||
|
||||
|
||||
/**
|
||||
* 起售停售菜品
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
}
|
||||
|
||||
71
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
71
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
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);
|
||||
|
||||
|
||||
/**
|
||||
* 新增套餐,同时需要保存套餐和菜品的关联关系
|
||||
* @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);
|
||||
}
|
||||
15
sky-server/src/main/java/com/sky/service/UserService.java
Normal file
15
sky-server/src/main/java/com/sky/service/UserService.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
* @param userLoginDTO
|
||||
* @return
|
||||
*/
|
||||
User wxLogin(UserLoginDTO userLoginDTO);
|
||||
}
|
||||
@@ -8,10 +8,12 @@ import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.DishFlavor;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.mapper.DishFlavorMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
@@ -20,6 +22,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.List;
|
||||
|
||||
|
||||
@@ -33,6 +36,9 @@ public class DishServiceImpl implements DishService {
|
||||
private DishFlavorMapper dishFlavorMapper;
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 新增菜品和对应的口味数据
|
||||
@@ -162,4 +168,79 @@ public class DishServiceImpl implements DishService {
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
*/
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Dish> list(Long categoryId) {
|
||||
Dish dish = Dish.builder()
|
||||
.status(StatusConstant.ENABLE)
|
||||
.categoryId(categoryId)
|
||||
.build();
|
||||
|
||||
return dishMapper.list(dish);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 起售停售套餐
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
|
||||
Dish dish = Dish.builder()
|
||||
.status(status)
|
||||
.id(id)
|
||||
.build();
|
||||
dishMapper.update(dish);
|
||||
|
||||
//如果是停售 那么将包含此菜品的套餐都停售
|
||||
if(status == StatusConstant.DISABLE){
|
||||
List<Long> dishIds = new ArrayList<>();
|
||||
dishIds.add(id);
|
||||
|
||||
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(dishIds);
|
||||
if (setmealIds != null && setmealIds.size() > 0) {
|
||||
for(Long setmealId : setmealIds){
|
||||
Setmeal setmeal = Setmeal.builder()
|
||||
.id(setmealId)
|
||||
.status(StatusConstant.DISABLE)
|
||||
.build();
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
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.DeletionNotAllowedException;
|
||||
import com.sky.exception.SetmealEnableFailedException;
|
||||
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.DishItemVO;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* 套餐业务实现
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SetmealServiceImpl implements SetmealService {
|
||||
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增套餐,同时需要保存套餐和菜品的关联关系
|
||||
* @param setmealDTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveWithDish(SetmealDTO setmealDTO) {
|
||||
|
||||
Setmeal setmeal = new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||
|
||||
//向套餐表插入数据
|
||||
setmealMapper.insert(setmeal);
|
||||
|
||||
//获取生成的套餐id
|
||||
Long setmealId = setmeal.getId();
|
||||
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
for (SetmealDish setmealDish : setmealDishes) {
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteBatch(List<Long> ids) {
|
||||
|
||||
//起售中的套餐不能删除
|
||||
ids.forEach(id -> {
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
if (setmeal.getStatus() == StatusConstant.ENABLE) {
|
||||
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
|
||||
}
|
||||
});
|
||||
|
||||
ids.forEach(setmealId -> {
|
||||
//删除套餐表中的数据
|
||||
setmealMapper.deleteById(setmealId);
|
||||
//删除套餐菜品关系表中的数据
|
||||
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id查询套餐和关联的菜品数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(SetmealDTO setmealDTO) {
|
||||
|
||||
Setmeal setmeal = new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||
|
||||
//修改套餐表
|
||||
setmealMapper.update(setmeal);
|
||||
|
||||
//获得套餐id
|
||||
Long setmealId = setmealDTO.getId();
|
||||
|
||||
//删除套餐和菜品的关联关系,操作setmeal_dish表,执行delete
|
||||
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||
|
||||
//拿到前端的菜品 设置新的套餐id
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
for(SetmealDish setmealDish : setmealDishes) {
|
||||
setmealDish.setSetmealId(setmealId);
|
||||
}
|
||||
|
||||
//重新插入套餐和菜品的关联关系,操作setmeal_dish表,执行insert
|
||||
setmealDishMapper.insertBatch(setmealDishes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 套餐起售停售
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
|
||||
//起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售"
|
||||
if (status == StatusConstant.ENABLE) {
|
||||
//获得套餐中的所有菜品
|
||||
//select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = ?
|
||||
List<Dish> dishList = dishMapper.getBySetmealId(id);
|
||||
|
||||
for(Dish dish : dishList) {
|
||||
if(dish.getStatus() == StatusConstant.DISABLE) {
|
||||
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Setmeal setmeal = Setmeal.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.build();
|
||||
setmealMapper.update(setmeal);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.oss.ServiceException;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
import com.sky.exception.LoginFailedException;
|
||||
import com.sky.mapper.UserMapper;
|
||||
import com.sky.properties.WeChatProperties;
|
||||
import com.sky.service.UserService;
|
||||
import com.sky.utils.HttpClientUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
|
||||
//微信服务接口地址
|
||||
public static final String WX_LOGIN="https://api.weixin.qq.com/sns/jscode2session";
|
||||
|
||||
|
||||
@Autowired
|
||||
private WeChatProperties weChatProperties;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 微信登陆
|
||||
* @param userLoginDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User wxLogin(UserLoginDTO userLoginDTO) {
|
||||
|
||||
String openid = getOpenid(userLoginDTO.getCode());
|
||||
|
||||
//判断openid是否为空 如果为空表示登录失败 抛出业务异常
|
||||
if(openid==null){
|
||||
throw new LoginFailedException(MessageConstant.LOGIN_FAILED);
|
||||
}
|
||||
|
||||
//判断当前用户是否为新用户
|
||||
User user = userMapper.getByOpenid(openid);
|
||||
|
||||
//如果是新用户 自动完成注册 返回用户对象
|
||||
if(user==null){
|
||||
user = User.builder()
|
||||
.openid(openid)
|
||||
.createTime(LocalDateTime.now())
|
||||
.build();
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 调用微信接口服务 获得当前微信用户的openid
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
private String getOpenid(String code){
|
||||
//调用微信接口服务 获得当前微信用户的openid
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("appid",weChatProperties.getAppid());
|
||||
map.put("secret",weChatProperties.getSecret());
|
||||
map.put("js_code", code);
|
||||
map.put("grant_type","authorization_code");
|
||||
String json = HttpClientUtil.doGet(WX_LOGIN, map);
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(json);
|
||||
String openid = jsonObject.getString("openid");
|
||||
|
||||
return openid;
|
||||
}
|
||||
}
|
||||
@@ -18,3 +18,7 @@ sky:
|
||||
port: 6379
|
||||
password: 123456
|
||||
database: 10
|
||||
|
||||
wechat:
|
||||
appid: wxc620c3c28c10ea02
|
||||
secret: 87b2f9904629aeda54fba44e6f249a58
|
||||
|
||||
@@ -42,12 +42,15 @@ sky:
|
||||
admin-ttl: 7200000
|
||||
# 设置前端传递过来的令牌名称
|
||||
admin-token-name: token
|
||||
|
||||
|
||||
|
||||
#阿里云配置
|
||||
alioss:
|
||||
endpoint: ${sky.alioss.endpoint}
|
||||
access-key-id: ${sky.alioss.access-key-id}
|
||||
access-key-secret: ${sky.alioss.access-key-secret}
|
||||
bucket-name: ${sky.alioss.bucket-name}
|
||||
user-secret-key: itheima
|
||||
user-token-name: authentication
|
||||
user-ttl: 7200000
|
||||
#阿里云配置
|
||||
alioss:
|
||||
endpoint: ${sky.alioss.endpoint}
|
||||
access-key-id: ${sky.alioss.access-key-id}
|
||||
access-key-secret: ${sky.alioss.access-key-secret}
|
||||
bucket-name: ${sky.alioss.bucket-name}
|
||||
wechat:
|
||||
appid: ${sky.wechat.appid}
|
||||
secret: ${sky.wechat.secret}
|
||||
|
||||
@@ -48,4 +48,21 @@
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="list" resultType="com.sky.entity.Dish" parameterType="Dish">
|
||||
select * from dish
|
||||
<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>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -10,4 +10,15 @@
|
||||
</foreach>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
</mapper>
|
||||
|
||||
66
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
66
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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">
|
||||
|
||||
<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>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into setmeal (category_id, name, price, description, image, create_time, update_time, create_user,
|
||||
update_user)
|
||||
values (#{categoryId}, #{name}, #{price}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser},
|
||||
#{updateUser})
|
||||
</insert>
|
||||
|
||||
|
||||
<select id="pageQuery" resultType="com.sky.vo.SetmealVO">
|
||||
select *, c.name categoryName
|
||||
from setmeal s
|
||||
left join category c on s.category_id = c.id
|
||||
<where>
|
||||
<if test="categoryId != null">
|
||||
and s.category_id = #{categoryId}
|
||||
</if>
|
||||
<if test="name != null">
|
||||
and s.name like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and s.status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
order by s.create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<!-- 修改套餐 -->
|
||||
<update id="update" parameterType="Setmeal">
|
||||
update setmeal
|
||||
<set>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="categoryId != null">category_id = #{categoryId},</if>
|
||||
<if test="price != null">price = #{price},</if>
|
||||
<if test="image != null">image = #{image},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="updateUser != null">update_user = #{updateUser},</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
12
sky-server/src/main/resources/mapper/UserMapper.xml
Normal file
12
sky-server/src/main/resources/mapper/UserMapper.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?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.UserMapper">
|
||||
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into user (openid, name, phone, sex, id_number, avatar, create_time)
|
||||
values
|
||||
(#{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})
|
||||
</insert>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user