<?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.ycwl.basic.mapper.PriceConfigMapper">

    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
        insert into price_config (scenic_id, type, goods_ids, price, slash_price, create_time, update_time)
        values (#{scenicId}, #{type}, #{goodsIds}, #{price}, #{slashPrice}, now(), now())
    </insert>

    <update id="update">
        update price_config
        <set>
            <if test="scenicId != null">scenic_id = #{scenicId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="goodsIds != null">goods_ids = #{goodsIds},</if>
            <if test="price != null">price = #{price},</if>
            <if test="slashPrice != null">slash_price = #{slashPrice},</if>
            update_time = now()
        </set>
        where id = #{id}
    </update>

    <delete id="deleteById">
        delete from price_config where id = #{id}
    </delete>

    <select id="getById" resultType="com.ycwl.basic.model.pc.price.resp.PriceConfigRespVO">
        select p.*, s.name as scenic_name from price_config p
        left join scenic s on s.id = p.scenic_id
        where p.id = #{id}
    </select>

    <select id="listByCondition" resultType="com.ycwl.basic.model.pc.price.resp.PriceConfigRespVO">
        select p.*, s.name as scenic_name from price_config p
        left join scenic s on s.id = p.scenic_id
        <where>
            <if test="req.scenicId != null">
                and p.scenic_id = #{req.scenicId}
            </if>
            <if test="req.type != null">
                and p.type = #{req.type}
            </if>
            <if test="req.goodsId != null">
                and p.goods_ids like concat('%', #{req.goodsId}, '%')
            </if>
        </where>
    </select>
    <select id="getPriceByScenicTypeGoods" resultType="com.ycwl.basic.model.pc.price.entity.PriceConfigEntity">
        select * from price_config
        where scenic_id = #{scenicId}
        and type = #{type}
        <if test="goodsId != null and goodsId != ''">
        and goods_ids like concat('%', #{goodsId}, '%')
        </if>
    </select>
</mapper>