<?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.TbCfPlatformDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfPlatformEntity" id="tbCfPlatformMap">
        <result property="platformId" column="platform_id"/>
        <result property="platformCode" column="platform_code"/>
        <result property="platformName" column="platform_name"/>
        <result property="platformBrief" column="platform_brief"/>
        <result property="platformUrl" column="platform_url"/>
        <result property="platformImg" column="platform_img"/>
        <result property="enableFlag" column="enable_flag"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformEntity">
		select
			`platform_id`,
			`platform_code`,
			`platform_name`,
			`platform_brief`,
			`platform_url`,
			`platform_img`,
			`enable_flag`,
			`create_time`
		from tb_cf_platform
		where platform_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformEntity">
		select
    		`platform_id`,
    		`platform_code`,
    		`platform_name`,
    		`platform_brief`,
    		`platform_url`,
    		`platform_img`,
    		`enable_flag`,
    		`create_time`
		from tb_cf_platform
		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 platform_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_platform
		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.TbCfPlatformEntity">
		insert into tb_cf_platform(
			`platform_id`,
			`platform_code`,
			`platform_name`,
			`platform_brief`,
			`platform_url`,
			`platform_img`,
			`enable_flag`,
			`create_time`)
		values(
			#{platformId},
			#{platformCode},
			#{platformName},
			#{platformBrief},
			#{platformUrl},
			#{platformImg},
			#{enableFlag},
			#{createTime})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformEntity">
		update tb_cf_platform 
		<set>
			<if test="platformCode != null">`platform_code` = #{platformCode}, </if>
			<if test="platformName != null">`platform_name` = #{platformName}, </if>
			<if test="platformBrief != null">`platform_brief` = #{platformBrief}, </if>
			<if test="platformUrl != null">`platform_url` = #{platformUrl}, </if>
			<if test="platformImg != null">`platform_img` = #{platformImg}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}, </if>
			<if test="createTime != null">`create_time` = #{createTime}</if>
		</set>
		where platform_id = #{platformId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_platform where platform_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_platform where platform_id in 
		<foreach item="platformId" collection="array" open="(" separator="," close=")">
			#{platformId}
		</foreach>
	</delete>

    <!--获取平台独立站-->
	<select id="getPlatformList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformEntity">
        select * from tb_cf_platform where enable_flag=1 order by create_time desc
    </select>

</mapper>