<?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.iamberry.wechat.service.mapper.ImageTextInfoMapper">
	<resultMap type="ImageTextInfo" id="ImageTextInfo">
		<id column="imageTextNo" property="imageTextNo" />
		<result column="wxpublicNo" property="wxpublicNo" />
		<result column="title" property="title" />
		<result column="imageUrl" property="imageUrl" />
		<result column="digest" property="digest" />
		<result column="mainText" property="mainText" />
		<result column="clickUrl" property="clickUrl" />
		<result column="clickOutUrl" property="clickOutUrl" />
		<result column="sourceUrl" property="sourceUrl" />
		<result column="imageTextType" property="imageTextType" />
		<result column="createTime" property="createTime" />
	</resultMap>

	<!-- 添加单图文素材 -->
	<insert id="addImageTextInfo" useGeneratedKeys="true"
		keyProperty="imageTextNo" parameterType="ImageTextInfo">
		insert into
		tb_wx_imagetextinfo
		(clickOutUrl,
		clickUrl,
		createTime,
		digest,
		imageTextType,
		imageUrl,
		mainText,
		sourceUrl,
		title,
		wxpublicNo)
		values
		(#{clickOutUrl},
		#{clickUrl},
		#{createTime},
		#{digest},
		#{imageTextType},
		#{imageUrl},
		#{mainText},
		#{sourceUrl},
		#{title},
		#{wxpublicNo})
	</insert>

	<!-- 删除图文素材 -->
	<delete id="delImageTextInfo" parameterType="java.lang.Long">
		delete from
		tb_wx_imagetextinfo
		where
		imageTextNo=#{imageTextNo}
	</delete>

	<!-- 修改图文操作 -->
	<update id="updateImageTextInfo">
		UPDATE tb_wx_imagetextinfo
		SET
		imageTextNo = #{imageTextNo} ,
		clickOutUrl = #{clickOutUrl} ,
		clickUrl = #{clickUrl} ,
		createTime =
		#{createTime} ,
		digest = #{digest} ,
		imageTextType = #{imageTextType} ,
		imageUrl = #{imageUrl} ,
		mainText = #{mainText} ,
		sourceUrl =
		#{sourceUrl} ,
		title = #{title} ,
		wxpublicNo = #{wxpublicNo}

		WHERE
		imageTextNo = #{imageTextNo}
	</update>

	<!-- 根据id来查找图文素材 -->
	<select id="findImageTextInfoById" parameterType="java.lang.Long" resultMap="ImageTextInfo">
		SELECT
			*
		FROM
			TB_WX_IMAGETEXTINFO
		WHERE
			IMAGETEXTNO = #{imageTextNo}
	</select>

	<!-- 按照公众账号来查询所有的图文素材 -->
	<select id="findImageTextInfoBywxPublicNo" parameterType="String">
		select
		*
		from
		tb_wx_imagetextinfo
		where
		wxpublicNo=#{wxpublicNo} 
		ORDER BY imageTextNo DESC
	</select>

	<!-- 根据微信公众账号、页数、每页显示的记录来分页查询 -->
	<select id="findImageTextInfo" resultMap="ImageTextInfo">
		select *
		from
		tb_wx_imagetextinfo
		where
		wxpublicNo=#{0} order by createTime desc
		limit #{1},
		#{2}
	</select>
	
	
	<!-- 分页查询图文素材列表 -->
	<select id="selectImageTextInfoList" parameterType="PaperBean" resultMap="ImageTextInfo">
		select *
		from
		tb_wx_imagetextinfo
		where
		wxpublicNo=#{str} order by createTime desc
		limit #{minNum},
		#{maxNum}
	</select>
	
	<!-- 根据微信公众号来查询该微信共有多少图文素材 -->
	<select id="findImageTextInfoNo" parameterType="String"
		resultType="int">
		select
		count(*)
		from
		tb_wx_imagetextinfo
		where
		wxpublicNo=#{wxpublicNo}
	</select>
	
		<!-- 查看全部素材 -->
	<select id="selectAllImageTextList" parameterType="String" resultMap="ImageTextInfo">
		select *
		from
		tb_wx_imagetextinfo
		where
		wxpublicNo=#{0} order by createTime desc
	</select>
	
	<!-- 根据id查询是否在其他表中使用了该素材 -->
	<select id="selectFirstAnswerByID" parameterType="java.lang.Integer" resultType="int">
		SELECT count(imageTextNo) FROM tb_wx_firstjoinkey WHERE imageTextNo = #{0}
	</select>
	
	<select id="selectKeyWordByID" parameterType="java.lang.Integer" resultType="int">
		SELECT count(refImageTextId) FROM tb_wx_keyword WHERE refImageTextId = #{0}
	</select>
	
	<select id="selectMenuKeyByID" parameterType="java.lang.Integer" resultType="int">
		SELECT count(refImageTextId) FROM tb_wx_menukeyset WHERE refImageTextId = #{0}
	</select>
	
	
</mapper>