sky-take-out/sky-server/src/main/resources/mapper/SetmealMapper.xml

96 lines
3.1 KiB
XML

<?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" parameterType="Setmeal" useGeneratedKeys="true" keyProperty="id">
insert into setmeal
(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user)
values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime},
#{createUser}, #{updateUser})
</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删除套餐和菜品的关联关系 -->
<delete id="deleteById">
delete
from setmeal
where id = #{id}
</delete>
<!-- 根据分类id查询套餐的数量 -->
<select id="countByCategoryId" resultType="java.lang.Integer">
select count(id)
from setmeal
where category_id = #{categoryId}
</select>
<!-- 动态条件查询套餐 -->
<select id="list" parameterType="Setmeal" resultType="Setmeal">
select * from setmeal
<where>
<if test="name != null">
and name like concat('%',#{name},'%')
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
<if test="status != null">
and status = #{status}
</if>
</where>
</select>
<!-- 根据套餐id查询菜品选项 -->
<select id="getDishItemBySetmealId" resultType="com.sky.vo.DishItemVO">
select sd.name, sd.copies, d.image, d.description
from setmeal_dish sd
left join dish d on sd.dish_id = d.id
where sd.setmeal_id = #{setmealId}
</select>
<!-- 根据id获取套餐 -->
<select id="getById" resultType="com.sky.entity.Setmeal">
select *
from setmeal
where id = #{id}
</select>
</mapper>