Skip to content

Commit

Permalink
套餐 起售停售
Browse files Browse the repository at this point in the history
  • Loading branch information
Q-1515 committed Jul 22, 2022
1 parent e02e8f1 commit aa1647b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,24 @@ public R<SetmealVO> getById(@PathVariable Long id) {
*/
@PutMapping
@ApiOperation("修改套餐")
public R update(@RequestBody SetmealDTO setmealDTO) {
public R<String> update(@RequestBody SetmealDTO setmealDTO) {
log.info("修改套餐:{}", setmealDTO);
setmealService.update(setmealDTO);
return R.success();
return R.success("套餐修改成功");
}

/**
* 套餐 启用禁用
*
* @param status 套餐状态
* @param id 套餐id
* @return success
*/
@PostMapping("/status/{status}")
public R<String> startOrStop(@PathVariable Integer status, Long id) {
log.info("修改套餐:{}", status);
setmealService.startOrStop(status,id);
return R.success("状态修改成功");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public interface DishMapper {
//根据分类id查询对应的菜品数量
Long cuntByCategoryId(Long id);

//插入数据到菜品表
@AutoFill(type = AutoFillConstant.INSERT)
//插入数据到菜品表
void insert(Dish dish);

//菜品信息分页查询
Expand All @@ -38,4 +38,7 @@ public interface DishMapper {

//根据分类id,状态码,菜品名 查询菜品信息
List<Dish> list(Dish dish);

//根据套餐id查询菜品
List<Dish> getBySetmealId(Long setmealId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ public interface SetmealService {

//修改套餐
void update(SetmealDTO setmealDTO);

//套餐 启用禁用
void startOrStop(Integer status, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import com.reggie.constant.StatusConstant;
import com.reggie.dto.SetmealDTO;
import com.reggie.dto.SetmealPageQueryDTO;
import com.reggie.entity.Dish;
import com.reggie.entity.Setmeal;
import com.reggie.entity.SetmealDish;
import com.reggie.exception.DeletionNotAllowedException;
import com.reggie.exception.SetmealEnableFailedException;
import com.reggie.mapper.DishMapper;
import com.reggie.mapper.SetmealDishMapper;
import com.reggie.mapper.SetmealMapper;
import com.reggie.result.PageResult;
Expand All @@ -35,6 +38,9 @@ public class SetmealServiceImpl implements SetmealService {
@Autowired
private SetmealDishMapper setmealDishMapper; //套餐菜品关系 DAO

@Autowired
private DishMapper dishMapper; //菜品DAO

/**
* 新增套餐
*
Expand Down Expand Up @@ -114,7 +120,7 @@ public SetmealVO getById(Long id) {
*
* @param setmealDTO 修改的套餐信息
*/
@Override
@Transactional
public void update(SetmealDTO setmealDTO) {
//拷贝套餐信息
Setmeal setmeal = new Setmeal();
Expand All @@ -137,4 +143,36 @@ public void update(SetmealDTO setmealDTO) {
//3、重新插入套餐和菜品的关联关系,操作setmeal_dish表,执行insert
setmealDishMapper.insertBatch(setmealDishes);
}

/**
* 套餐 启用禁用
*
* @param status 套餐状态
* @param id 套餐id
*/
public void startOrStop(Integer status, Long id) {
//起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售"
if (StatusConstant.DISABLE == status) {
//根据套餐id查询菜品
List<Dish> dishList = dishMapper.getBySetmealId(id);
if (dishList != null && dishList.size() > 0) {
dishList.forEach(dish -> {
//判断菜品书否是未启动
if (dish.getStatus() == StatusConstant.DISABLE) {
//套餐启动失败,套餐包未起售菜品
throw new SetmealEnableFailedException(MessageConstant.SETMEAL_ENABLE_FAILED);
}
}
);
}
}

//起售状态的话直接更新为停售
Setmeal setmeal = Setmeal.builder()
.id(id)
.status(status)
.build();
setmealMapper.updatesByIds(setmeal);

}
}
8 changes: 8 additions & 0 deletions reggie_server/src/main/resources/mapper/DishMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,12 @@
order by create_time desc
</select>

<!--根据套餐id查询菜品-->
<select id="getBySetmealId" resultType="com.reggie.entity.Dish">
select dish.*
from dish
left join setmeal_dish sd on dish.id = sd.dish_id
where sd.id = #{setmealId}
</select>

</mapper>

0 comments on commit aa1647b

Please sign in to comment.