<?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.yunniu.farming.webadmin.dao.ArticleDao">
	<!-- 返回的结果集 -->
	<resultMap id="BaseResultMap" type="com.yunniu.farming.webadmin.model.Article">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. -->
		<id column="id" property="id" jdbcType="INTEGER" />
		<result column="stitle" property="stitle" jdbcType="VARCHAR" />
		<result column="sthumbpic" property="sthumbpic" jdbcType="VARCHAR" />
		<result column="scontent" property="scontent" jdbcType="LONGVARCHAR" />
		<result column="pcatalogid " property="pcatalogid" jdbcType="INTEGER" />
		<result column="catalogid" property="catalogid" jdbcType="INTEGER" />
		<result column="itype" property="itype" jdbcType="INTEGER" />
		<result column="sshortpic1" property="sshortpic1" jdbcType="VARCHAR" />
		<result column="sshortpic2" property="sshortpic2" jdbcType="VARCHAR" />
		<result column="sshortpic3" property="sshortpic3" jdbcType="VARCHAR" />
		<result column="sshortpic4" property="sshortpic4" jdbcType="VARCHAR" />
		<result column="sshortpic5" property="sshortpic5" jdbcType="VARCHAR" />
		<result column="sshortpic6" property="sshortpic6" jdbcType="VARCHAR" />
		<result column="spubdate" property="spubdate" jdbcType="VARCHAR" />
		<result column="tcreatetime" property="tcreatetime" jdbcType="DECIMAL" />
		<result column="istop" property="istop" jdbcType="INTEGER" />
		<result column="sauthor" property="sauthor" jdbcType="VARCHAR" />
		<result column="iviewnum" property="iviewnum" jdbcType="INTEGER" />
		<result column="isharenum" property="isharenum" jdbcType="INTEGER" />
		<result column="isshow" property="isshow" jdbcType="INTEGER" />
		<result column="sdef1" property="sdef1" jdbcType="VARCHAR" />
		<result column="sdef2" property="sdef2" jdbcType="VARCHAR" />
		<result column="sdef3" property="sdef3" jdbcType="VARCHAR" />
		<result column="sdef4" property="sdef4" jdbcType="VARCHAR" />
		<result column="sdef5" property="sdef5" jdbcType="VARCHAR" />
		<result column="idef6" property="idef6" jdbcType="INTEGER" />
		<result column="idef7" property="idef7" jdbcType="INTEGER" />
		<result column="ddef8" property="ddef8" jdbcType="DECIMAL" />
		<result column="ddef9" property="ddef9" jdbcType="DECIMAL" />
		<result column="ddef10" property="ddef10" jdbcType="TIMESTAMP" />
		<result column="svideourl" property="svideourl" jdbcType="VARCHAR" />
		<result column="readflag" property="readflag" jdbcType="INTEGER" />

	</resultMap>
	<!-- sql块  -->
	<sql id="Base_Column_List">
		id, stitle, sthumbpic, scontent, catalogid,pcatalogid,itype,sshortpic1,sshortpic2,
		sshortpic3,sshortpic4, sshortpic5, sshortpic6, spubdate, tcreatetime,
		istop, sauthor, iviewnum,isharenum,isshow, 
		sdef1, sdef2, sdef3, sdef4, sdef5, idef6,idef7,ddef8, ddef9, ddef10,svideourl
	</sql>
	
	<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. -->
		select 'false' as QUERYID,
		<include refid="Base_Column_List" />
		from article
		where id = #{id,jdbcType=INTEGER}
	</select>
	
	
	<!-- 添加 -->
	<insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="com.yunniu.farming.webadmin.model.Article">
		insert into article (
		id, stitle, sthumbpic, scontent, catalogid,pcatalogid,itype,sshortpic1,sshortpic2,
		sshortpic3,sshortpic4, sshortpic5, sshortpic6, spubdate, tcreatetime,
		istop, sauthor, iviewnum,isharenum,isshow,
		sdef1, sdef2, sdef3, sdef4, sdef5, idef6,idef7,ddef8, ddef9, ddef10,svideourl
		)
		values (#{id,jdbcType=INTEGER},
		#{stitle,jdbcType=VARCHAR}, #{sthumbpic,jdbcType=VARCHAR},#{scontent,jdbcType=LONGVARCHAR},
		#{catalogid,jdbcType=INTEGER}, #{pcatalogid,jdbcType=VARCHAR},#{itype,jdbcType=INTEGER},#{sshortpic1,jdbcType=VARCHAR},
		#{sshortpic2,jdbcType=VARCHAR},#{sshortpic3,jdbcType=VARCHAR},
		#{sshortpic4,jdbcType=VARCHAR},#{sshortpic5,jdbcType=VARCHAR},#{sshortpic6,jdbcType=VARCHAR},
		 #{spubdate,jdbcType=VARCHAR},
		#{tcreatetime,jdbcType=DECIMAL}, #{istop,jdbcType=INTEGER},
		#{sauthor,jdbcType=VARCHAR},
		#{iviewnum,jdbcType=INTEGER}, #{isharenum,jdbcType=INTEGER}, #{isshow,jdbcType=INTEGER},
		#{sdef1,jdbcType=VARCHAR},
		#{sdef2,jdbcType=VARCHAR}, #{sdef3,jdbcType=VARCHAR}, #{sdef4,jdbcType=VARCHAR},
		#{sdef5,jdbcType=VARCHAR}, #{idef6,jdbcType=INTEGER},
		#{idef7,jdbcType=INTEGER},
		#{ddef8,jdbcType=DECIMAL}, #{ddef9,jdbcType=DECIMAL}, #{ddef10,jdbcType=TIMESTAMP},
		#{svideourl,jdbcType=VARCHAR}
		)
	</insert>
	<!-- 普通条件查询 -->
	<select id="findByParam" resultMap="BaseResultMap" parameterType="com.yunniu.farming.webadmin.model.Article">
		select
		<include refid="Base_Column_List" />
		FROM article
		<where>
			<if test="id != null">
				AND id = #{id,jdbcType=INTEGER}
			</if>
			<if test="stitle != null" >
				AND stitle like '%${stitle}%'
			</if>
			<if test="itype != null">
				AND itype = #{itype,jdbcType=INTEGER}
			</if>

		</where>

		<if test="sortfields != null" >
	     	ORDER BY ${sortfields}
	   	</if>

	</select>




	<select id="findParamRead" resultMap="BaseResultMap" parameterType="com.yunniu.farming.webadmin.model.Article">
		select
		n.id,id,stitle,scontent,tcreatetime,
		n.id IN (SELECT noticeid FROM notice_read WHERE customerid = #{customerid,jdbcType=INTEGER}) AS readflag
		FROM article n
		<where>
			<if test="stitle != null" >
				AND stitle like '%${stitle}%'
			</if>
			<if test="itype != null">
				AND itype = #{itype,jdbcType=INTEGER}
			</if>
		</where>

		ORDER BY readflag DESC,n.tcreatetime DESC

	</select>




	
	<!-- FRICE TODO 带参数常规查询分页 Start -->
	<select id="findPageList" resultMap="BaseResultMap" parameterType="com.yunniu.farming.webadmin.model.Article">
		select
		<include refid="Base_Column_List" />
		FROM article
		<where>
			<if test="id != null">
				AND id = #{id,jdbcType=INTEGER}
			</if>
			<if test="stitle != null" >
				AND stitle like '%${stitle}%'
			</if>     
			<if test="itype != null">
				AND itype = #{itype,jdbcType=INTEGER}
			</if>

		</where>
		
		<if test="sortfields != null" >
	     	ORDER BY ${sortfields}
	   	</if>
	   			
	</select>
	<!--删除  -->
	<delete id="deleteByid" parameterType="java.lang.Integer">
		delete from article
		where id = #{id,jdbcType=INTEGER}
	</delete>
	<!-- 修改 -->
	<update id="updateByPrimaryKeySelective" parameterType="com.yunniu.farming.webadmin.model.Article">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. -->
		update article
		<set>
			
			<if test="stitle != null">
				stitle = #{stitle,jdbcType=VARCHAR},
			</if>
			<if test="sthumbpic != null">
				sthumbpic = #{sthumbpic,jdbcType=VARCHAR},
			</if>
			<if test="itype != null">
				itype = #{itype,jdbcType=INTEGER},
			</if>
			<if test="scontent != null">
				scontent=#{scontent,jdbcType=LONGVARCHAR},
			</if>
			<if test="pcatalogid != null">
				pcatalogid = #{pcatalogid,jdbcType=INTEGER},
			</if>
			<if test="catalogid != null">
				catalogid = #{catalogid,jdbcType=INTEGER},
			</if>
			<if test="sshortpic1 != null">
				sshortpic1 = #{sshortpic1,jdbcType=VARCHAR},
			</if>
			<if test="sshortpic2 != null">
				sshortpic2 = #{sshortpic2,jdbcType=VARCHAR},
			</if>
			<if test="sshortpic4 != null">
				sshortpic4 = #{sshortpic4,jdbcType=VARCHAR},
			</if>
			<if test="sshortpic5 != null">
				sshortpic5 = #{sshortpic5,jdbcType=VARCHAR},
			</if>
			<if test="sshortpic6 != null">
				sshortpic6 = #{sshortpic6,jdbcType=VARCHAR},
			</if>

			<if test="spubdate != null">
				spubdate = #{spubdate,jdbcType=CHAR},
			</if>
			<if test="tcreatetime != null">
				tcreatetime = #{tcreatetime,jdbcType=DATETIME},
			</if>
			<if test="istop != null">
				istop = #{istop,jdbcType=INTEGER},
			</if>

			<if test="iviewnum != null">
				iviewnum = #{iviewnum,jdbcType=INTEGER},
			</if>
			<if test="isharenum != null">
				isharenum = #{isharenum,jdbcType=INTEGER},
			</if>
			<if test="isshow != null">
				isshow = #{isshow,jdbcType=INTEGER},
			</if>
			<if test="sdef1 != null">
				sdef1 = #{sdef1,jdbcType=VARCHAR},
			</if>
			<if test="sdef2 != null">
				sdef2 = #{sdef2,jdbcType=VARCHAR},
			</if>
			<if test="sdef3 != null">
				sdef3 = #{sdef3,jdbcType=VARCHAR},
			</if>
			<if test="sdef4 != null">
				sdef4 = #{sdef4,jdbcType=VARCHAR},
			</if>
			<if test="sdef5 != null">
				sdef5 = #{sdef5,jdbcType=VARCHAR},
			</if>
			<if test="idef6 != null">
				idef6 = #{idef6,jdbcType=INTEGER},
			</if>
			<if test="idef7 != null">
				idef7 = #{idef7,jdbcType=INTEGER},
			</if>
			<if test="ddef8 != null">
				ddef8 = #{ddef8,jdbcType=DECIMAL},
			</if>
			<if test="ddef9 != null">
				ddef9 = #{ddef9,jdbcType=DECIMAL},
			</if>
			<if test="ddef10 != null">
				ddef10 = #{ddef10,jdbcType=TIMESTAMP}
			</if>
			<if test="svideourl != null">
				svideourl = #{svideourl,jdbcType=TIMESTAMP}
			</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>


	<!-- 一键阅读 -->
	<update id="speedreads">
		update article
		<set>
			<if test="idef6 != null">
				idef6 = #{idef6},
			</if>
		</set>

		<where>
			<if test="itype != null">
				and itype = #{itype,jdbcType=INTEGER}
			</if>
		</where>

	</update>




	<select id="findAdminCount" resultType="int" parameterType="com.yunniu.farming.webadmin.model.Article">

		SELECT

		IFNULL(COUNT(*),0) AS adminNum

		FROM article

		<where>
			<if test="itype != null" >
				AND article.itype = #{itype,jdbcType=INTEGER}
			</if>

			<if test="idef6 != null">
				AND IFNULL(article.idef6,0) = #{idef6,jdbcType=INTEGER}
			</if>
		</where>

	</select>


</mapper>