删除菜品业务代码优化

This commit is contained in:
zvv
2026-03-27 21:56:54 +08:00
parent 0a6eff7714
commit 2e6fdeec25
5 changed files with 38 additions and 2 deletions

View File

@@ -23,4 +23,11 @@ public interface DishFlavorMapper {
*/
@Delete("delete from dish_flavor where dish_id = #{dishId}")
void deleteByDishId(Long dishId);
/**
* 根据菜品id集合批量删除对应的口味数据
* @param dishIds
*/
void deleteByDishIds(List<Long> dishIds);
}

View File

@@ -10,6 +10,8 @@ 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 DishMapper {
@@ -53,4 +55,11 @@ public interface DishMapper {
*/
@Delete("delete from dish where id = #{id}")
void deleteById(Long id);
/**
* 根据菜品id集合批量删除菜品
* @param ids
*/
void deleteByIds(List<Long> ids);
}

View File

@@ -101,12 +101,17 @@ public class DishServiceImpl implements DishService {
}
//删除菜品表中的菜品数据
for (Long id : ids) {
/* for (Long id : ids) {
dishMapper.deleteById(id);
//删除菜品关联的口味数据
dishFlavorMapper.deleteByDishId(id);
}
}*/
//sql:delete from dish where id in (?, ?, ?)
//根据菜品id集合批量删除菜品数据和关联的口味数据
dishMapper.deleteByIds(ids);
dishFlavorMapper.deleteByDishIds(ids);
}
}

View File

@@ -9,4 +9,11 @@
(#{df.dishId}, #{df.name}, #{df.value} )
</foreach>
</insert>
<delete id="deleteByDishIds">
delete from dish_flavor where dish_id in
<foreach collection="dishIds" item="dishId" separator="," open="(" close=")">
#{dishId}
</foreach>
</delete>
</mapper>

View File

@@ -11,6 +11,14 @@
</insert>
<delete id="deleteByIds">
delete from dish where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<select id="pageQuery" resultType="com.sky.vo.DishVO">
select d.*, c.name as categoryName from dish d left outer join category c on d.category_id = c.id
<where>