<?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="cn.com.countrygarden.bi.main.dao.experience.TygInfoManageMapper">

	<update id="updateById" parameterType="cn.com.countrygarden.bi.main.dto.manager.TygInfoManage">
		update tyg_info_manage set
		<if test="title !=null and title !=''">
			title=#{title},
		</if>
		<if test="url !=null and url !=''">
			url=#{url},
		</if>
		<if test="effectiveTimeStart !=null">
			effective_time_start=#{effectiveTimeStart},
		</if>
		<if test="effectiveTimeEnd !=null">
			effective_time_end=#{effectiveTimeEnd},
		</if>
		<if test="content !=null">
			content=#{content},
		</if>
		update_by =#{updateBy},
		update_time =#{updateTime}
		where id =#{id}
	</update>

	<insert id="add" parameterType="cn.com.countrygarden.bi.main.dto.manager.TygInfoManage" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		insert into tyg_info_manage(id,title,url,effective_time_start,effective_time_end,create_time,create_by,status,content)
		value(null,#{title},#{url},#{effectiveTimeStart},#{effectiveTimeEnd}
		,now(),#{createBy},0,#{content}
		)
	</insert>

	<select id="list" parameterType="cn.com.countrygarden.bi.main.dto.experience.TygInfoManageDto"
	resultType="cn.com.countrygarden.bi.main.dto.manager.TygInfoManage">
		select
		id,
		title,
		url,
		effective_time_start effectiveTimeStart,
		effective_time_end effectiveTimeEnd,
		status status,
		create_time createTime,
		create_by createBy,
		content
		from tyg_info_manage
		where status=0
		<if test="title !=null and title !=''">
			and title like concat('%',#{title},'%')
		</if>
		<if test="effectiveTimeStart !=null">
			and effective_time_start &lt;= #{effectiveTimeStart}
		</if>
		<if test="effectiveTimeEnd !=null">
			and effective_time_end >= #{effectiveTimeEnd}
		</if>
		ORDER BY
		create_time DESC
		<if test="page != null and size != null">
			limit #{pageStart}, #{size}
		</if>
	</select>

	<select id="count" resultType="int" parameterType="cn.com.countrygarden.bi.main.dto.experience.TygInfoManageDto">
		select count(0) from tyg_info_manage where status =0
		<if test="title !=null and title !=''">
			and title like concat('%',#{title},'%')
		</if>
		<if test="effectiveTimeStart !=null">
			and effective_time_start &lt;= #{effectiveTimeStart}
		</if>
		<if test="effectiveTimeEnd !=null">
			and effective_time_end >= #{effectiveTimeEnd}
		</if>
	</select>

	<select id="selectById" resultType="cn.com.countrygarden.bi.main.dto.manager.TygInfoManage">
			select
		id,
		title,
		url,
		effective_time_start effectiveTimeStart,
		effective_time_end effectiveTimeEnd,
		status status,
		create_time createTime,
		create_by createBy,
		content
		from tyg_info_manage
		where id=#{id}
	</select>

	<update id="del">
		update tyg_info_manage set status=1 where id=#{id}
	</update>
</mapper>