Compare commits
7 Commits
821819ed5c
...
d8b0a8a391
Author | SHA1 | Date |
---|---|---|
|
d8b0a8a391 | |
|
567f60ce66 | |
|
78ffd28597 | |
|
d6171e842d | |
|
2a3d46113e | |
|
cf32a6bd8f | |
|
a3218d4b3a |
|
@ -0,0 +1,32 @@
|
|||
package com.sky.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RedisConfiguration {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||
// 设置key序列化为string
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
// 设置value序列化为JSON,使用GenericJackson2JsonRedisSerializer替换默认序列化
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ 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.JwtTokenUserInterceptor;
|
||||
import com.sky.json.JacksonObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -32,6 +33,8 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
|
||||
@Resource
|
||||
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
||||
@Resource
|
||||
private JwtTokenUserInterceptor jwtTokenUserInterceptor;
|
||||
|
||||
/**
|
||||
* 注册自定义拦截器
|
||||
|
@ -43,24 +46,53 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
registry.addInterceptor(jwtTokenAdminInterceptor)
|
||||
.addPathPatterns("/admin/**")
|
||||
.excludePathPatterns("/admin/employee/login");
|
||||
|
||||
registry.addInterceptor(jwtTokenAdminInterceptor)
|
||||
.addPathPatterns("/user/**")
|
||||
.excludePathPatterns("/user/user/login")
|
||||
.excludePathPatterns("/user/shop/status");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过knife4j生成接口文档
|
||||
* 管理后台文档
|
||||
*
|
||||
* @return Docket
|
||||
*/
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
public Docket docketAdmin() {
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("苍穹外卖项目接口文档")
|
||||
.version("2.0")
|
||||
.description("苍穹外卖项目接口文档")
|
||||
.build();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("管理端接口")
|
||||
.apiInfo(apiInfo)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过knife4j生成接口文档
|
||||
* 用户前台文档
|
||||
*
|
||||
* @return Docket
|
||||
*/
|
||||
@Bean
|
||||
public Docket docketUser() {
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("苍穹外卖项目接口文档")
|
||||
.version("2.0")
|
||||
.description("苍穹外卖项目接口文档")
|
||||
.build();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("用户端接口")
|
||||
.apiInfo(apiInfo)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.user"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
@ -86,6 +118,6 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
log.info("扩展消息转换器...");
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
converter.setObjectMapper(new JacksonObjectMapper());
|
||||
converters.add(0,converter);
|
||||
converters.add(0, converter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,4 +75,17 @@ public class DishController {
|
|||
DishVO dishVO = dishService.getByIdWithFlavor(id);
|
||||
return Result.success(dishVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改菜品
|
||||
* @param dishDTO DishDTO
|
||||
* @return Result<String>
|
||||
*/
|
||||
@ApiOperation("修改菜品")
|
||||
@PutMapping()
|
||||
public Result<String> update(@RequestBody DishDTO dishDTO) {
|
||||
log.info("修改菜品:{}", dishDTO);
|
||||
dishService.updateWithFlavor(dishDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController("adminShopController")
|
||||
@RequestMapping("/admin/shop")
|
||||
@Api(tags = "店铺相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
public static final String KEY = "SHOP_STATUS";
|
||||
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 设置店铺营业状态
|
||||
*
|
||||
* @param status 状态
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation("设置店铺营业状态")
|
||||
@PutMapping("/{status}")
|
||||
public Result<String> setStatus(@PathVariable Integer status) {
|
||||
log.info("设置店铺营业状态:{}", status == 1 ? "营业中" : "打样中");
|
||||
redisTemplate.opsForValue().set(KEY, status);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation(("获取店铺营业状态"))
|
||||
@GetMapping("/{status}")
|
||||
public Result<Integer> getStatus() {
|
||||
Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
|
||||
log.info("获取当前店铺营业状态:{}", status == 1 ? "营业中" : "打样中");
|
||||
|
||||
return Result.success(status);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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 javax.annotation.Resource;
|
||||
|
||||
@RestController("userShopController")
|
||||
@RequestMapping("/user/shop")
|
||||
@Api(tags = "店铺相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
public static final String KEY = "SHOP_STATUS";
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@ApiOperation("设置店铺营业状态")
|
||||
@GetMapping("status")
|
||||
public Result setStatus() {
|
||||
Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
|
||||
log.info("设置店铺营业状态:{}", status == 1 ? "营业中" : "打样中");
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
import com.sky.mapper.UserMapper;
|
||||
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.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 java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/user")
|
||||
@Api(tags = "C端用户相关接口")
|
||||
@Slf4j
|
||||
public class UserController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private JwtProperties jwtProperties;
|
||||
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*
|
||||
* @param userLoginDTO 用户传过来的数据
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation("微信登录")
|
||||
@PostMapping("/login")
|
||||
public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
|
||||
log.info("微信登录:{}", userLoginDTO.getCode());
|
||||
// 微信登录
|
||||
User user = userService.wxLogin(userLoginDTO);
|
||||
// 为用户生成jwt令牌
|
||||
HashMap<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,61 @@
|
|||
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.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* jwt令牌校验的拦截器
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JwtTokenUserInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Resource
|
||||
private JwtProperties jwtProperties;
|
||||
|
||||
/**
|
||||
* 校验jwt
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @param response HttpServletResponse
|
||||
* @param handler Object
|
||||
* @return boolean
|
||||
* @throws Exception 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,4 +55,13 @@ public interface DishMapper {
|
|||
* @param ids List<Long>
|
||||
*/
|
||||
void deleteByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 删除原有口味数据
|
||||
* @param dish Dish
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
/**
|
||||
* 根据用户id查询用户
|
||||
* @param openid String
|
||||
* @return User
|
||||
*/
|
||||
User getByOpenid(String openid);
|
||||
|
||||
/**
|
||||
* 如果为新用户自动完成注册
|
||||
* @param user 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;
|
||||
|
||||
|
@ -34,4 +35,17 @@ public interface DishService {
|
|||
* @return DishVO
|
||||
*/
|
||||
DishVO getByIdWithFlavor(Long id);
|
||||
|
||||
/**
|
||||
* 修改菜品
|
||||
* @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);
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
|
||||
public interface UserService {
|
||||
/**
|
||||
* 微信登录
|
||||
* @param userLoginDTO UserLoginDTO
|
||||
* @return User
|
||||
*/
|
||||
User wxLogin(UserLoginDTO userLoginDTO);
|
||||
}
|
|
@ -13,14 +13,18 @@ import com.sky.mapper.DishFlavorMapper;
|
|||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetMealDishMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
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
|
||||
|
@ -117,4 +121,53 @@ public class DishServiceImpl implements DishService {
|
|||
|
||||
return dishVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改菜品
|
||||
*
|
||||
* @param dishDTO DishDTO
|
||||
*/
|
||||
@Override
|
||||
public void updateWithFlavor(DishDTO dishDTO) {
|
||||
// 修改菜品基本信息
|
||||
Dish dish = new Dish();
|
||||
BeanUtils.copyProperties(dishDTO, dish);
|
||||
// 删除原有口味数据
|
||||
dishMapper.update(dish);
|
||||
// 重新插入口味数据
|
||||
dishFlavorMapper.deleteByDishId(dishDTO.getId());
|
||||
// 重新插入新的口味数据
|
||||
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||
if (flavors != null && !flavors.isEmpty()) {
|
||||
flavors.forEach(dishFlavor -> {
|
||||
dishFlavor.setDishId(dishDTO.getId());
|
||||
});
|
||||
// 向表中插入n条数据
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.sky.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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 org.apache.http.client.HttpClient;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
public static final String WX_LOGIN = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
@Resource
|
||||
private WeChatProperties weChatProperties;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*
|
||||
* @param userLoginDTO UserLoginDTO
|
||||
* @return User
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用微信接口服务
|
||||
* @param code Code
|
||||
* @return String
|
||||
*/
|
||||
private String getOpenid(String code) {
|
||||
// 调用微信接口服务,获得当前用户openiid
|
||||
HashMap<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);
|
||||
return jsonObject.getString("openid");
|
||||
}
|
||||
}
|
|
@ -11,4 +11,11 @@ sky:
|
|||
bucket-name: sky
|
||||
accessKey: "bunny"
|
||||
secretKey: "02120212"
|
||||
|
||||
redis:
|
||||
host: 106.15.251.123
|
||||
port: 6378
|
||||
password: "02120212"
|
||||
database: 1
|
||||
wechat:
|
||||
appid: wx18e5556d7539757b
|
||||
secret: ac06f1c49f90a2ed69f1a946d4981833
|
|
@ -16,6 +16,13 @@ spring:
|
|||
multipart:
|
||||
max-file-size: 10MB
|
||||
max-request-size: 10MB
|
||||
redis:
|
||||
host: ${sky.redis.host}
|
||||
port: ${sky.redis.port}
|
||||
password: ${sky.redis.password}
|
||||
database: ${sky.redis.database}
|
||||
timeout: 5000
|
||||
|
||||
|
||||
mybatis:
|
||||
#mapper配置文件
|
||||
|
@ -41,9 +48,15 @@ sky:
|
|||
admin-ttl: 66666666666666
|
||||
# 设置前端传递过来的令牌名称
|
||||
admin-token-name: token
|
||||
user-secret-key: itheima
|
||||
user-ttl: 66666666666666
|
||||
user-token-name: authentication
|
||||
|
||||
minio:
|
||||
endpointUrl: ${sky.minio.endpointUrl}
|
||||
accessKey: ${sky.minio.accessKey}
|
||||
secretKey: ${sky.minio.secretKey}
|
||||
bucket-name: ${sky.minio.bucket-name}
|
||||
wechat:
|
||||
appid: ${sky.wechat.appid}
|
||||
secret: ${sky.wechat.secret}
|
|
@ -10,6 +10,38 @@
|
|||
#{updateTime}, #{createUser}, #{updateUser});
|
||||
</insert>
|
||||
|
||||
<!-- 删除原有口味数据 -->
|
||||
<update id="update">
|
||||
update dish
|
||||
<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>
|
||||
|
||||
<!-- 删除菜品表中的菜品数据 -->
|
||||
<delete id="deleteById">
|
||||
delete
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?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">
|
||||
insert into user (openid, name, phone, sex, id_number, avatar, create_time)
|
||||
values (#{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime});
|
||||
</insert>
|
||||
|
||||
<!-- 根据用户id查询用户 -->
|
||||
<select id="getByOpenid" resultType="com.sky.entity.User">
|
||||
select *
|
||||
from user
|
||||
where openid = #{openid};
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue