<?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.ym.mec.cms.dal.dao.SysNewsInformationDao">
	
	<resultMap type="com.ym.mec.cms.dal.entity.SysNewsInformation" id="SysNewsInformation">
		<result column="id_" property="id" />
		<result column="title_" property="title" />
		<result column="content_" property="content" />
		<result column="cover_image_" property="coverImage" />
		<result column="link_url_" property="linkUrl"/>
		<result column="type_" property="type"/>
		<result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="del_flag_" property="delFlag" />
		<result column="href_target_" property="hrefTarget" />
		<result column="order_" property="order" />
	</resultMap>
	
	<sql id="queryCondition">
		<where>
			del_flag_=0
			<if test="type != null">
				and type_ = #{type}
			</if>
			<if test="status != null">
				and status_ = #{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			<if test="title != null">
				and title_ like '%' #{title} '%'
			</if>
			<if test="search != null">
				and title_ like '%' #{search} '%'
			</if>
		</where>
	</sql>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="SysNewsInformation" >
		SELECT * FROM sys_news_information WHERE id_ = #{id} AND del_flag_=0
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="SysNewsInformation">
		SELECT * FROM sys_news_information WHERE del_flag_=0 ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.cms.dal.entity.SysNewsInformation" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO sys_news_information (id_,title_,content_,cover_image_,type_,status_,create_time_,update_time_,link_url_,href_target_,order_,del_flag_)
		VALUES(#{id},#{title},#{content},#{coverImage},#{type},#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},now(),now(),#{linkUrl},#{hrefTarget},#{order},0)
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.cms.dal.entity.SysNewsInformation">
		UPDATE sys_news_information
		<set>
			<if test="status != null">
				status_ = #{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="title != null">
				title_ = #{title},
			</if>
			<if test="updateTime != null">
				update_time_ = NOW(),
			</if>
			<if test="content != null">
				content_ = #{content},
			</if>
			<if test="coverImage != null">
				cover_image_ = #{coverImage},
			</if>
			<if test="type != null">
				type_ = #{type},
			</if>
			<if test="linkUrl != null">
				link_url_ = #{linkUrl},
			</if>
			<if test="hrefTarget != null">
				href_target_ = #{hrefTarget},
			</if>
			<if test="order != null">
				order_ = #{order},
			</if>
			<if test="delFlag != null">
				del_flag_ = #{delFlag},
			</if>
		</set>
		WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM sys_news_information WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="SysNewsInformation" parameterType="map">
		SELECT * FROM sys_news_information
		<include refid="queryCondition" />
		order by order_ desc,update_time_ desc
		<include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM sys_news_information
		<include refid="queryCondition" />
	</select>
	
	<select id="queryByType" resultMap="SysNewsInformation" parameterType="java.lang.Integer">
		SELECT * FROM sys_news_information 
		<where>
			del_flag_=0
			<if test="type != null">
				and type_ = #{type}
			</if>
		</where>
	</select>
	
	<update id="deleteWithLogical">
		UPDATE sys_news_information SET del_flag_ = 1,update_time_ = NOW() WHERE id_ = #{id}
	</update>
</mapper>
