删除套餐业务功能开发

master
hahameng 8 months ago
parent f02eb2ef94
commit c2df9afd45

@ -10,6 +10,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
@ -39,4 +41,28 @@ public class SetmealController {
PageResult pageResult=setmealService.pageQuery(setmealPageQueryDTO);
return Result.success(pageResult);
}
/**
*
* @param ids
* @return
*/
@DeleteMapping
public Result delete(@RequestParam List<Long> ids){
setmealService.delete(ids);
return Result.success();
}
}

@ -2,6 +2,7 @@ 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;
@ -25,4 +26,11 @@ public interface SetmealDishMapper {
* @param setmealDishes
*/
void insertBatch(List<SetmealDish> setmealDishes);
/**
* id
* @param setmealId
*/
@Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
void deleteBySetmealId(Long setmealId);
}

@ -7,6 +7,7 @@ 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;
@ -43,4 +44,21 @@ public interface SetmealMapper {
* @return
*/
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
/**
* id
* @param id
* @return
*/
@Select("select * from setmeal where id = #{id}")
Setmeal getById(Long id);
/**
* id
* @param id
*/
@Delete("delete from setmeal where id =#{id}")
void deleteById(Long id);
}

@ -4,6 +4,8 @@ import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import java.util.List;
public interface SetmealService {
/**
@ -18,4 +20,10 @@ public interface SetmealService {
* @return
*/
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
/**
*
* @param ids
*/
void delete(List<Long> ids);
}

@ -2,10 +2,13 @@ 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.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealDishMapper;
import com.sky.mapper.SetmealMapper;
@ -15,6 +18,7 @@ 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;
@ -65,4 +69,27 @@ public class SetmealServiceImpl implements SetmealService {
Page<SetmealVO> page = setmealMapper.pageQuery(setmealPageQueryDTO);
return new PageResult(page.getTotal(), page.getResult());
}
/**
*
* @param ids
*/
@Transactional
@Override
public void delete(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(id -> {
//删除套餐表中的数据
setmealMapper.deleteById(id);
//删除套餐菜品关系表中的数据
setmealDishMapper.deleteBySetmealId(id);
});
}
}

Loading…
Cancel
Save