套餐起售、停售
This commit is contained in:
parent
ac4e7d8108
commit
a914b2dc00
|
@ -45,4 +45,18 @@ public class SetmealController {
|
||||||
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||||
return Result.success(pageResult);
|
return Result.success(pageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
*
|
||||||
|
* @param status Integer
|
||||||
|
* @param id Long
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@ApiOperation("套餐起售停售")
|
||||||
|
@PostMapping("status/{status}")
|
||||||
|
public Result startOrStop(@PathVariable Integer status, Long id) {
|
||||||
|
setmealService.startOrStop(status, id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,4 +74,12 @@ public interface DishMapper {
|
||||||
* @return List<Dish>
|
* @return List<Dish>
|
||||||
*/
|
*/
|
||||||
List<Dish> list(Dish dish);
|
List<Dish> list(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售"
|
||||||
|
*
|
||||||
|
* @param id Long
|
||||||
|
* @return List<Dish>
|
||||||
|
*/
|
||||||
|
List<Dish> getBySetmealId(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,4 +41,12 @@ public interface SetmealMapper {
|
||||||
*/
|
*/
|
||||||
@AutoFill(OperationType.INSERT)
|
@AutoFill(OperationType.INSERT)
|
||||||
void insert(Setmeal setmeal);
|
void insert(Setmeal setmeal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
*
|
||||||
|
* @param setmeal Setmeal
|
||||||
|
*/
|
||||||
|
@AutoFill(OperationType.UPDATE)
|
||||||
|
void update(Setmeal setmeal);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,4 +41,12 @@ public interface SetmealService {
|
||||||
* @return PageResult
|
* @return PageResult
|
||||||
*/
|
*/
|
||||||
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
*
|
||||||
|
* @param status Integer
|
||||||
|
* @param id Long
|
||||||
|
*/
|
||||||
|
void startOrStop(Integer status, Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,14 @@ package com.sky.service.impl;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.sky.constant.MessageConstant;
|
||||||
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.dto.SetmealDTO;
|
import com.sky.dto.SetmealDTO;
|
||||||
import com.sky.dto.SetmealPageQueryDTO;
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.entity.Dish;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
import com.sky.entity.SetmealDish;
|
import com.sky.entity.SetmealDish;
|
||||||
|
import com.sky.exception.SetmealEnableFailedException;
|
||||||
import com.sky.mapper.DishMapper;
|
import com.sky.mapper.DishMapper;
|
||||||
import com.sky.mapper.SetMealDishMapper;
|
import com.sky.mapper.SetMealDishMapper;
|
||||||
import com.sky.mapper.SetmealMapper;
|
import com.sky.mapper.SetmealMapper;
|
||||||
|
@ -91,4 +95,28 @@ public class SetmealServiceImpl implements SetmealService {
|
||||||
Page<SetmealVO> page = setmealDishMapper.pageQuery(setmealPageQueryDTO);
|
Page<SetmealVO> page = setmealDishMapper.pageQuery(setmealPageQueryDTO);
|
||||||
return new PageResult(page.getTotal(), page.getResult());
|
return new PageResult(page.getTotal(), page.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
*
|
||||||
|
* @param status Integer
|
||||||
|
* @param id Long
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void startOrStop(Integer status, Long id) {
|
||||||
|
// 起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售"
|
||||||
|
if (status.equals(StatusConstant.ENABLE)) {
|
||||||
|
List<Dish> dishList = dishMapper.getBySetmealId(id);
|
||||||
|
if (dishList != null && !dishList.isEmpty()) {
|
||||||
|
dishList.forEach(dish -> {
|
||||||
|
if (dish.getStatus().equals(StatusConstant.DISABLE)) {
|
||||||
|
throw new SetmealEnableFailedException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Setmeal setmeal = Setmeal.builder().id(id).status(status).build();
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,4 +108,12 @@
|
||||||
</where>
|
</where>
|
||||||
order by create_time desc
|
order by create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售" -->
|
||||||
|
<select id="getBySetmealId" resultType="com.sky.entity.Dish">
|
||||||
|
select a.*
|
||||||
|
from dish a
|
||||||
|
left join setmeal_dish b on a.id = b.dish_id
|
||||||
|
where b.setmeal_id = ?
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -10,6 +10,44 @@
|
||||||
#{createUser}, #{updateUser})
|
#{createUser}, #{updateUser})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<!-- 套餐起售停售 -->
|
||||||
|
<update id="update">
|
||||||
|
update setmeal
|
||||||
|
<set>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
category_id = #{categoryId},
|
||||||
|
</if>
|
||||||
|
<if test="name != null">
|
||||||
|
name = #{name},
|
||||||
|
</if>
|
||||||
|
<if test="price != null">
|
||||||
|
price = #{price},
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
status = #{status},
|
||||||
|
</if>
|
||||||
|
<if test="description != null">
|
||||||
|
description = #{description},
|
||||||
|
</if>
|
||||||
|
<if test="image != null">
|
||||||
|
image = #{image},
|
||||||
|
</if>
|
||||||
|
<if test="createTime != null">
|
||||||
|
create_time = #{createTime},
|
||||||
|
</if>
|
||||||
|
<if test="createUser != null">
|
||||||
|
create_user = #{createUser},
|
||||||
|
</if>
|
||||||
|
<if test="updateTime != null">
|
||||||
|
update_time = #{updateTime},
|
||||||
|
</if>
|
||||||
|
<if test="updateUser != null">
|
||||||
|
update_user = #{updateUser},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id};
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- 根据分类id查询套餐的数量 -->
|
<!-- 根据分类id查询套餐的数量 -->
|
||||||
<select id="countByCategoryId" resultType="java.lang.Integer">
|
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||||
select count(id)
|
select count(id)
|
||||||
|
|
Loading…
Reference in New Issue