<?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.cftech.mp.wechat.dao.ImagetextReadMapper">

	<resultMap id="resultMap" type="com.cftech.mp.wechat.model.ImagetextRead">
		<id column="id" property="id"/>
		<result column="image_textid" property="imageTextid"/>
		<result column="openid" property="openid"/>
		<result column="createtime" property="createtime"/>
		<result column="updatetime" property="updatetime"/>
		<result column="delflag" property="delflag"/>
	</resultMap>

	<sql id="sqlWhere">
		<if test="conds!=null">
			<trim prefix="WHERE" prefixOverrides="AND|OR">
				<foreach collection="conds.conds" index="index" item="cond">
					${cond.linkType}
					<if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
					<if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
					<if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
					<if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
					<if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
					<if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
					<if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND #{cond.endValue}</if>
					<if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
					<if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
					<if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
					<if test="cond.condType == 'IN'">${cond.param} IN
						<foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
							#{item}
						</foreach>
					</if>
				</foreach>
			</trim>
		</if>
	</sql>

	<sql id="sqlColumns">
		id, image_textid, openid, createtime, updatetime, delflag
	</sql>

	<insert id="save" parameterType="com.cftech.mp.wechat.model.ImagetextRead" keyProperty="id">
		insert into wx_mp_imagetext_read
		(
		<include refid="sqlColumns"/>
		)
		values
		(
		#{id, jdbcType=BIGINT},  #{imageTextid, jdbcType=BIGINT},  #{openid, jdbcType=VARCHAR},  now(),  
		now(),  #{delflag, jdbcType=CHAR}
		)
	</insert>

	<select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
		SELECT <include refid="sqlColumns" /> FROM wx_mp_imagetext_read t
		WHERE t.id=#{id}
	</select>

	<select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
		SELECT COUNT(1)  FROM wx_mp_imagetext_read<include refid="sqlWhere" />
	</select>

	<select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
		SELECT <include refid="sqlColumns" /> 
		FROM wx_mp_imagetext_read t
		<include refid="sqlWhere" />
		<if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
		<if test="limit>0">limit #{offset},#{limit}</if>
	</select>

	<update id="update" parameterType="com.cftech.mp.wechat.model.ImagetextRead">
		update wx_mp_imagetext_read
		<set>
			<if test="id != null">
				id = #{id, jdbcType=BIGINT},
			</if>
			<if test="imageTextid != null">
				image_textid = #{imageTextid, jdbcType=BIGINT},
			</if>
			<if test="openid != null">
				openid = #{openid, jdbcType=VARCHAR},
			</if>
			<if test="createtime != null">
				createtime = #{createtime, jdbcType=TIMESTAMP},
			</if>
			<if test="updatetime != null">
				updatetime=now(),
			</if>
			<if test="delflag != null">
				delflag = #{delflag, jdbcType=CHAR},
			</if>
		</set>
		where id=#{id,jdbcType=BIGINT}
	</update>

	<update id="delete" parameterType="java.lang.Long">
		update wx_mp_imagetext_read set delflag=1 where id=#{id,jdbcType=BIGINT}
	</update>

</mapper>