<?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.yijia.integral.mapper.IntegralShopPicMapper">
    
    <resultMap type="IntegralShopPic" id="IntegralShopPicResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="url"    column="url"    />
        <result property="imgStatus"    column="img_status"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="parentId"    column="parent_id"    />
    </resultMap>

    <sql id="selectIntegralShopPicVo">
        select id, name, url, img_status, station_id, station_name, parent_id from integral_shop_pic
    </sql>

    <select id="selectIntegralShopPicList" parameterType="IntegralShopPic" resultMap="IntegralShopPicResult">
        <include refid="selectIntegralShopPicVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="imgStatus != null  and imgStatus != ''"> and img_status = #{imgStatus}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by  id desc
    </select>
    
    <select id="selectIntegralShopPicById" parameterType="Long" resultMap="IntegralShopPicResult">
        <include refid="selectIntegralShopPicVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertIntegralShopPic" parameterType="IntegralShopPic" useGeneratedKeys="true" keyProperty="id">
        insert into integral_shop_pic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="url != null">url,</if>
            <if test="imgStatus != null">img_status,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
            <if test="parentId != null">parent_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="url != null">#{url},</if>
            <if test="imgStatus != null">#{imgStatus},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="parentId != null">#{parentId},</if>
         </trim>
    </insert>

    <update id="updateIntegralShopPic" parameterType="IntegralShopPic">
        update integral_shop_pic
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="url != null">url = #{url},</if>
            <if test="imgStatus != null">img_status = #{imgStatus},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIntegralShopPicById" parameterType="Long">
        delete from integral_shop_pic where id = #{id}
    </delete>

    <delete id="deleteIntegralShopPicByIds" parameterType="String">
        delete from integral_shop_pic where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteIntegralShopPic" parameterType="IntegralShopPic">
        delete from integral_shop_pic
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="imgStatus != null  and imgStatus != ''"> and img_status = #{imgStatus}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
        </where>
    </delete>
</mapper>