<?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.diaoyun.zion.chinafrica.dao.TbCfHomePageDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfHomePageEntity" id="tbCfHomePageMap">
        <result property="pageId" column="page_id"/>
        <result property="imgName" column="img_name"/>
        <result property="sort" column="sort"/>
        <result property="linkUrl" column="link_url"/>
        <result property="imgUrl" column="img_url"/>
        <result property="scanFlag" column="scan_flag"/>
        <result property="redirectFlag" column="redirect_flag"/>
        <result property="enableFlag" column="enable_flag"/>
    </resultMap>

    <select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfHomePageEntity">
		select
			`page_id`,
			`img_name`,
			`sort`,
			`link_url`,
			`img_url`,
			`scan_flag`,
			`redirect_flag`,
			`enable_flag`
		from tb_cf_home_page
		where page_id = #{id}
	</select>

    <select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfHomePageEntity">
        select
        `page_id`,
        `img_name`,
        `sort`,
        `link_url`,
        `img_url`,
        `scan_flag`,
        `redirect_flag`,
        `enable_flag`
        from tb_cf_home_page
        WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by page_id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
        select count(*) from tb_cf_home_page
        WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
    </select>

    <insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfHomePageEntity">
		insert into tb_cf_home_page(
			`page_id`,
			`img_name`,
			`sort`,
			`link_url`,
			`img_url`,
			`scan_flag`,
			`redirect_flag`,
			`enable_flag`)
		values(
			#{pageId},
			#{imgName},
			#{sort},
			#{linkUrl},
			#{imgUrl},
			#{scanFlag},
			#{redirectFlag},
			#{enableFlag})
	</insert>

    <update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfHomePageEntity">
        update tb_cf_home_page
        <set>
            <if test="imgName != null">`img_name` = #{imgName},</if>
            <if test="sort != null">`sort` = #{sort},</if>
            <if test="linkUrl != null">`link_url` = #{linkUrl},</if>
            <if test="imgUrl != null">`img_url` = #{imgUrl},</if>
            <if test="scanFlag != null">`scan_flag` = #{scanFlag},</if>
            <if test="redirectFlag != null">`redirect_flag` = #{redirectFlag},</if>
            <if test="enableFlag != null">`enable_flag` = #{enableFlag}</if>
        </set>
        where page_id = #{pageId}
    </update>

    <delete id="delete">
		delete from tb_cf_home_page where page_id = #{value}
	</delete>

    <delete id="deleteBatch">
        delete from tb_cf_home_page where page_id in
        <foreach item="pageId" collection="array" open="(" separator="," close=")">
            #{pageId}
        </foreach>
    </delete>

    <!--获取有效的启动页图片-->
    <select id="getStartPageImage" resultType="com.diaoyun.zion.chinafrica.entity.TbCfHomePageEntity">
        select * from tb_cf_home_page where enable_flag=1 order by sort desc
    </select>

</mapper>