店铺营业状态设计
This commit is contained in:
parent
75175519ac
commit
743427a8a9
2
pom.xml
2
pom.xml
@ -98,7 +98,6 @@
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>${aliyun.sdk.oss}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
@ -122,6 +121,7 @@
|
||||
<artifactId>wechatpay-apache-httpclient</artifactId>
|
||||
<version>0.4.8</version>
|
||||
</dependency>
|
||||
<!--redis-->
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
@ -123,6 +123,10 @@
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.sky.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RedisConfiguration {
|
||||
@Bean
|
||||
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
|
||||
log.info("开始创建redis模板对象");
|
||||
RedisTemplate redisTemplate=new RedisTemplate();
|
||||
//设置redis的连接工厂对象 连接工厂负责创建与 Redis 服务器的连接
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
//设置redis key的序列化器 这意味着所有通过这个RedisTemplate实例存储的键都将被转换为字符串格式存储在Redis中
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
@ -47,21 +47,37 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
public Docket docket1() {
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("苍穹外卖项目接口文档")
|
||||
.version("2.0")
|
||||
.description("苍穹外卖项目接口文档")
|
||||
.build();
|
||||
Docket docket = 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();
|
||||
return docket;
|
||||
}
|
||||
@Bean
|
||||
public Docket docket2() {
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("苍穹外卖项目接口文档")
|
||||
.version("2.0")
|
||||
.description("苍穹外卖项目接口文档")
|
||||
.build();
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("用户端")
|
||||
.apiInfo(apiInfo)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.user"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
return docket;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置静态资源映射
|
||||
* @param registry
|
||||
|
@ -12,6 +12,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/dish")
|
||||
@Slf4j
|
||||
@ -51,4 +53,17 @@ public class DishController {
|
||||
dishService.update(dishDTO);
|
||||
return Result.success();
|
||||
}
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("菜品起售/停售")
|
||||
public Result startOrStop(@PathVariable("status") Integer status, Long id){
|
||||
dishService.startOrStop(status,id);
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询菜品")
|
||||
public Result<List<Dish>> list(Long categoryId){
|
||||
List<Dish> dishList=dishService.list(categoryId);
|
||||
return Result.success(dishList);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api("套餐相关接口")
|
||||
@RequestMapping("/admin/setmeal")
|
||||
public class SetmealController {
|
||||
@Autowired
|
||||
private SetmealService setmealService;
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("新增套餐")
|
||||
public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
|
||||
log.info("新增套餐");
|
||||
setmealService.addSetmeal(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("套餐分页查询")
|
||||
public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
|
||||
PageResult pageResult=setmealService.pageQuery(setmealPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
@DeleteMapping
|
||||
@ApiOperation("删除套餐")
|
||||
public Result deleteByIds(@RequestParam Long[] ids){
|
||||
log.info("删除套餐");
|
||||
setmealService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("根据id查询套餐")
|
||||
public Result<SetmealVO> getById(@PathVariable Long id) {
|
||||
SetmealVO setmealVO = setmealService.getByIdWithDish(id);
|
||||
return Result.success(setmealVO);
|
||||
}
|
||||
@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,34 @@
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController("adminShopController")
|
||||
@RequestMapping("/admin/shop")
|
||||
@Api(tags = "店铺相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
public static final String KEY="SHOP_STATUS";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
@PutMapping("/{status}")
|
||||
@ApiOperation("设置店铺营业状态")
|
||||
public Result setStatus(@PathVariable Integer status){
|
||||
log.info("设置店铺的营业状态:{}",status==1? "营业中":"打烊中");
|
||||
redisTemplate.opsForValue().set(KEY,status);
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping("/status")
|
||||
@ApiOperation("获取店铺营业状态")
|
||||
public Result<Integer> getStatus(){
|
||||
Integer status= (Integer) redisTemplate.opsForValue().get(KEY);
|
||||
log.info("获取店铺的营业状态:{}",status==1? "营业中":"打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController("userShopController")
|
||||
@RequestMapping("/user/shop")
|
||||
@Api(tags = "店铺相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
public static final String KEY="SHOP_STATUS";
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@GetMapping("/status")
|
||||
@ApiOperation("获取店铺营业状态")
|
||||
public Result<Integer> getStatus(){
|
||||
Integer status= (Integer) redisTemplate.opsForValue().get(KEY);
|
||||
log.info("获取店铺的营业状态:{}",status==1? "营业中":"打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
}
|
@ -16,11 +16,21 @@ public interface DishMapper {
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Dish dish);
|
||||
|
||||
/**
|
||||
* 分类查询
|
||||
* @param dishPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
List<DishVO> list(DishPageQueryDTO dishPageQueryDTO);
|
||||
|
||||
@Select("select * from dish where id=#{id}")
|
||||
Dish queryById(Long id);
|
||||
@Delete("delete from dish where id=#{id}")
|
||||
void deleteById(Long id);
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Dish dish);
|
||||
@Select("select * from dish where category_id=#{categoryId}")
|
||||
List<Dish> listByType(Long categoryId);
|
||||
@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 setmealId);
|
||||
}
|
||||
|
26
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
Normal file
26
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
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.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealMapper {
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Setmeal setmeal);
|
||||
|
||||
List<SetmealVO> queryByCond(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
@Select("select * from setmeal where id=#{id}")
|
||||
Setmeal getById(Long id);
|
||||
@Delete("delete from setmeal where id=#{id};")
|
||||
void deleteById(Long id);
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Setmeal setmeal);
|
||||
}
|
@ -1,11 +1,21 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.SetmealDish;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface Setmeal_dishMapper {
|
||||
@Select("select * from setmeal_dish where dish_id=#{id}")
|
||||
SetmealDish queryByDishId(Long id);
|
||||
@Select("select setmeal_id from setmeal_dish where dish_id=#{id}")
|
||||
List<Long> queryByDishId(Long id);
|
||||
|
||||
void add(SetmealDish setmealDish);
|
||||
@Delete("delete from setmeal_dish where setmeal_id=#{id}")
|
||||
void deleteByDishId(Long id);
|
||||
|
||||
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
List<SetmealDish> getBySetmealId(Long setmealId);
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ 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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DishService {
|
||||
void addDish(DishDTO dishDTO);
|
||||
|
||||
@ -15,4 +18,8 @@ public interface DishService {
|
||||
DishVO queryByIdWithFlavor(Long id);
|
||||
|
||||
void update(DishDTO dishDTO);
|
||||
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
List<Dish> list(Long categoryId);
|
||||
}
|
||||
|
25
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
25
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.SetmealVO;
|
||||
|
||||
public interface SetmealService {
|
||||
void addSetmeal(SetmealDTO setmealDTO);
|
||||
|
||||
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
void deleteBatch(Long[] ids);
|
||||
|
||||
SetmealVO getByIdWithDish(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
* @param setmealDTO
|
||||
*/
|
||||
void update(SetmealDTO setmealDTO);
|
||||
|
||||
void startOrStop(Integer status, Long id);
|
||||
}
|
@ -8,10 +8,13 @@ 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.entity.SetmealDish;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.exception.SetmealEnableFailedException;
|
||||
import com.sky.mapper.DishFlavorMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.mapper.Setmeal_dishMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.DishService;
|
||||
@ -31,6 +34,8 @@ public class DishServiceImpl implements DishService {
|
||||
private DishFlavorMapper dishFlavorMapper;
|
||||
@Autowired
|
||||
private Setmeal_dishMapper setmeal_dishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
@Override
|
||||
public void addDish(DishDTO dishDTO) {
|
||||
Dish dish=new Dish();
|
||||
@ -61,8 +66,8 @@ public class DishServiceImpl implements DishService {
|
||||
if(dish.getStatus()== StatusConstant.ENABLE)
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
|
||||
else{
|
||||
SetmealDish setmealDish=setmeal_dishMapper.queryByDishId(id);
|
||||
if(setmealDish!=null)
|
||||
List<Long> setmealids=setmeal_dishMapper.queryByDishId(id);
|
||||
if(setmealids!=null && setmealids.size() > 0)
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
|
||||
else {
|
||||
dishMapper.deleteById(id);
|
||||
@ -97,4 +102,28 @@ public class DishServiceImpl implements DishService {
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
Dish dish=new Dish();
|
||||
dish.setId(id);
|
||||
dish.setStatus(status);
|
||||
if(status==StatusConstant.DISABLE){ //如果菜品停售,正在起售的套餐也要停售
|
||||
List<Long> setmealids=setmeal_dishMapper.queryByDishId(id);
|
||||
for(Long setmealid:setmealids){
|
||||
Setmeal setmeal=setmealMapper.getById(setmealid);
|
||||
if(StatusConstant.ENABLE == setmeal.getStatus()){ //若菜品停售,则套餐起售失败!
|
||||
setmeal.setStatus(StatusConstant.DISABLE);
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
}
|
||||
}
|
||||
dishMapper.update(dish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dish> list(Long categoryId) {
|
||||
List<Dish> dishList=dishMapper.listByType(categoryId);
|
||||
return dishList;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,129 @@
|
||||
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.SetmealMapper;
|
||||
import com.sky.mapper.Setmeal_dishMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.SetmealVO;
|
||||
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
|
||||
public class SetmealServiceImpl implements SetmealService {
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
@Autowired
|
||||
private Setmeal_dishMapper setmeal_dishMapper;
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
@Override
|
||||
public void addSetmeal(SetmealDTO setmealDTO) {
|
||||
Setmeal setmeal=new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO,setmeal);
|
||||
setmealMapper.insert(setmeal);
|
||||
List<SetmealDish> setmealDishList =setmealDTO.getSetmealDishes();
|
||||
for(SetmealDish setmealDish:setmealDishList){
|
||||
setmealDish.setSetmealId(setmeal.getId());
|
||||
setmeal_dishMapper.add(setmealDish);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
PageHelper.startPage(setmealPageQueryDTO.getPage(),setmealPageQueryDTO.getPageSize());
|
||||
List<SetmealVO> setmealVOList=setmealMapper.queryByCond(setmealPageQueryDTO);
|
||||
Page<SetmealVO> p= (Page<SetmealVO>) setmealVOList;
|
||||
PageResult pageResult=new PageResult(p.getTotal(),p.getResult());
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteBatch(Long[] ids) {
|
||||
for(Long id:ids){
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
if(StatusConstant.ENABLE == setmeal.getStatus()){
|
||||
//起售中的套餐不能删除
|
||||
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
|
||||
}
|
||||
else{
|
||||
Long setmealId=id;
|
||||
setmealMapper.deleteById(id);
|
||||
setmeal_dishMapper.deleteByDishId(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetmealVO getByIdWithDish(Long id) {
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
List<SetmealDish> setmealDishes = setmeal_dishMapper.getBySetmealId(id);
|
||||
SetmealVO setmealVO = new SetmealVO();
|
||||
BeanUtils.copyProperties(setmeal, setmealVO);
|
||||
setmealVO.setSetmealDishes(setmealDishes);
|
||||
|
||||
return setmealVO;
|
||||
}
|
||||
|
||||
@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
|
||||
setmeal_dishMapper.deleteByDishId(setmealId);
|
||||
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
setmealDishes.forEach(setmealDish -> {
|
||||
setmealDish.setSetmealId(setmealId);
|
||||
});
|
||||
//3、重新插入套餐和菜品的关联关系,操作setmeal_dish表,执行insert
|
||||
for(SetmealDish setmealDish:setmealDishes){
|
||||
setmeal_dishMapper.add(setmealDish);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
if(dishList != null && dishList.size() > 0){
|
||||
dishList.forEach(dish -> {
|
||||
if(StatusConstant.DISABLE == dish.getStatus()){ //若菜品停售,则套餐起售失败!
|
||||
throw new SetmealEnableFailedException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Setmeal setmeal = Setmeal.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.build();
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
}
|
@ -6,6 +6,11 @@ sky:
|
||||
database: sky_take_out
|
||||
username: root
|
||||
password: 123456
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
auth: 123456
|
||||
database: 0
|
||||
|
||||
alioss:
|
||||
access-key-id: LTAI5tR43XPATPy2NwTSiTqY
|
||||
|
@ -12,6 +12,11 @@ spring:
|
||||
url: jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: ${sky.datasource.username}
|
||||
password: ${sky.datasource.password}
|
||||
redis:
|
||||
host: ${sky.redis.host}
|
||||
port: ${sky.redis.port}
|
||||
auth: ${sky.redis.auth}
|
||||
database: ${sky.redis.database}
|
||||
|
||||
mybatis:
|
||||
#mapper配置文件
|
||||
|
32
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
32
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.SetmealMapper">
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into setmeal (name, category_id, price, image ,description, create_time, update_time, create_user,update_user, status)
|
||||
values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{status})
|
||||
</insert>
|
||||
<update id="update">
|
||||
update setmeal
|
||||
<set>
|
||||
<if test="name !='' and 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>
|
||||
<select id="queryByCond" resultType="com.sky.vo.SetmealVO">
|
||||
select c.*,d.name from setmeal as c left outer join category as d on c.category_id=d.id
|
||||
<where>
|
||||
<if test="categoryId!=null">and c.category_id=#{categoryId}</if>
|
||||
<if test="name!=null and name!=''">and c.name like concat('%',#{name},'%')</if>
|
||||
<if test="status!=null">and c.status=#{status}</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
10
sky-server/src/main/resources/mapper/Setmeal_dishMapper.xml
Normal file
10
sky-server/src/main/resources/mapper/Setmeal_dishMapper.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?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.Setmeal_dishMapper">
|
||||
|
||||
<insert id="add">
|
||||
insert into setmeal_dish (setmeal_id,dish_id,name,price,copies)
|
||||
values (#{setmealId},#{dishId},#{name},#{price},#{copies})
|
||||
</insert>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user