<?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.ruoyi.system.mapper.SiteDeliveryMapper">
    
    <resultMap type="SiteDelivery" id="SiteDeliveryResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="code"    column="code"    />
        <result property="sort"    column="sort"    />
        <result property="status"    column="status"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectSiteDeliveryVo">
        select id, title, code, sort, status, created_at, updated_at from site_delivery
    </sql>

    <select id="selectSiteDeliveryList" parameterType="SiteDelivery" resultMap="SiteDeliveryResult">
        <include refid="selectSiteDeliveryVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title like concat('%',#{title},'%')</if>
            <if test="code != null  and code != ''"> and code like concat('%',#{code},'%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectSiteDeliveryById" parameterType="Long" resultMap="SiteDeliveryResult">
        <include refid="selectSiteDeliveryVo"/>
        where id = #{id}
    </select>

    <insert id="insertSiteDelivery" parameterType="SiteDelivery" useGeneratedKeys="true" keyProperty="id">
        insert into site_delivery
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="code != null and code != ''">code,</if>
            <if test="sort != null">sort,</if>
            <if test="status != null">status,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="code != null and code != ''">#{code},</if>
            <if test="sort != null">#{sort},</if>
            <if test="status != null">#{status},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateSiteDelivery" parameterType="SiteDelivery">
        update site_delivery
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSiteDeliveryById" parameterType="Long">
        delete from site_delivery where id = #{id}
    </delete>

    <delete id="deleteSiteDeliveryByIds" parameterType="String">
        delete from site_delivery where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>