<?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.miaxis.carousel.mapper.HomePageDataInfoMapper">

    <resultMap type="HomePageDataInfo" id="HomePageDataInfoResult">
        <result property="id"    column="id"    />
        <result property="pictureName"    column="picture_name"    />
        <result property="fileId"    column="file_id"    />
        <result property="jump_url"    column="jumpUrl"    />
        <result property="jump_url_type"    column="jumpUrlType"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="weight"    column="weight"    />
        <result property="dataType"    column="data_type"    />
        <result property="dataDescribe"    column="data_describe"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectHomePageDataInfoVo">
        select id, picture_name, file_id ,jump_url, jump_url_type, create_time, update_time, weight,data_type,data_describe, status from home_page_data_info
    </sql>

    <select id="selectHomePageDataInfoList" resultType="com.miaxis.carousel.vo.HomePageDataInfoVo">
        select
        ci.id,
        ci.file_id as fileId,
        ci.picture_name as pictureName,
        ci.jump_url as jumpUrl,
        ci.jump_url_type as jumpUrlType,
        f.file_url as fileUrl,
        ci.weight,
        ci.`data_type` as dataType,
        ci.`data_describe` as dataDescribe,
        ci.status
        from home_page_data_info ci
        LEFT JOIN file_info f on f.file_id = ci.file_id
        <where>
            <if test="pictureName != null  and pictureName != ''"> and picture_name like concat('%', #{pictureName}, '%')</if>
            <if test="fileId != null "> and file_id = #{fileId}</if>
            <if test="dataType != null and dataType != ''"> and data_type = #{dataType}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
        </where>
        ORDER BY ci.weight DESC
    </select>

    <select id="getHomePageDataById" resultType="com.miaxis.carousel.vo.HomePageDataInfoVo">
        select
        ci.id,
        ci.file_id as fileId,
        ci.picture_name as pictureName,
        ci.jump_url as jumpUrl,
        ci.jump_url_type as jumpUrlType,
        f.file_url as fileUrl,
        ci.weight,
        ci.`data_type` as dataType,
        ci.`data_describe` as dataDescribe,
        ci.status
        from home_page_data_info ci
        LEFT JOIN file_info f on f.file_id = ci.file_id
        where ci.id = #{id}
    </select>



    <update id="updateHomePageDataByPictureName" parameterType="com.miaxis.carousel.vo.HomePageDataInfoVo">
        update home_page_data_info f
        <set>
            <if test="jumpUrl!=null">
                f.jump_url= #{jumpUrl}
            </if>
        </set>
        where f.picture_name = #{pictureName}
    </update>


</mapper>
