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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfContactEntity" id="tbCfContactMap">
        <result property="contactId" column="contact_id"/>
        <result property="contactWay" column="contact_way"/>
        <result property="contactDetail" column="contact_detail"/>
        <result property="enableFlag" column="enable_flag"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfContactEntity">
		select
			`contact_id`,
			`contact_way`,
			`contact_detail`,
			`enable_flag`
		from tb_cf_contact
		where contact_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfContactEntity">
		select
    		`contact_id`,
    		`contact_way`,
    		`contact_detail`,
    		`enable_flag`
		from tb_cf_contact
		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 contact_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_contact
		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.TbCfContactEntity">
		insert into tb_cf_contact(
			`contact_id`,
			`contact_way`,
			`contact_detail`,
			`enable_flag`)
		values(
			#{contactId},
			#{contactWay},
			#{contactDetail},
			#{enableFlag})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfContactEntity">
		update tb_cf_contact 
		<set>
			<if test="contactWay != null">`contact_way` = #{contactWay}, </if>
			<if test="contactDetail != null">`contact_detail` = #{contactDetail}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}</if>
		</set>
		where contact_id = #{contactId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_contact where contact_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_contact where contact_id in 
		<foreach item="contactId" collection="array" open="(" separator="," close=")">
			#{contactId}
		</foreach>
	</delete>

	<!--获取有效的联系方式-->
	<select id="getContactList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfContactEntity">
		select * from tb_cf_contact where enable_flag=1
	</select>

</mapper>