<?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.TygGzhInfoManageMapper">

	<update id="updateById" parameterType="cn.com.countrygarden.bi.main.model.experience.TygGzhInfoManage">
		update tyg_gzh_info_manage set
		update_by =#{updateBy}
		<if test="projectName !=null and projectName !=''">
			,project_name=#{projectName}
		</if>
		<if test="title !=null and title !=''">
			,title=#{title}
		</if>
		<if test="taskName !=null and taskName !=''">
			,task_name=#{taskName}
		</if>
		<if test="finishTime !=null and finishTime !=''">
			,finish_time=#{finishTime}
		</if>
		<if test="url !=null and url !=''">
			,url=#{url}
		</if>
		<if test="appoint !=null and appoint !=''">
			,appoint=#{appoint}
		</if>
		<if test="personInfo !=null and personInfo !=''">
			,person_info=#{personInfo}
		</if>
		<if test="releaseTime !=null">
			,release_time=#{releaseTime}
		</if>
		<if test="descs !=null and descs !=''">
			,descs=#{descs}
		</if>
		<if test="detaUrl !=null and detaUrl !=''">
			,deta_url=#{detaUrl}
		</if>
		,update_time =now()
		where id =#{id}
	</update>

	<insert id="add" parameterType="cn.com.countrygarden.bi.main.model.experience.TygGzhInfoManage">
		insert into tyg_gzh_info_manage(
		model_id
		<if test="projectName !=null and projectName !=''">
			,project_name
		</if>
		<if test="title !=null and title !=''">
			,title
		</if>
		<if test="taskName !=null and taskName !=''">
			,task_name
		</if>
		<if test="finishTime !=null and finishTime !=''">
			,finish_time
		</if>
		<if test="url !=null and url !=''">
			,url
		</if>
		<if test="appoint !=null and appoint !=''">
			,appoint
		</if>
		<if test="descs !=null and descs !=''">
			,descs
		</if>
		,create_time
		,create_by
		,status
		<if test="personInfo !=null and personInfo !=''">
			,person_info
		</if>
		,deleted
		<if test="releaseTime !=null">
			,release_time
		</if>
		<if test="detaUrl !=null">
			,deta_url
		</if>
		)
		value(#{modelId}
		<if test="projectName !=null and projectName !=''">
			,#{projectName}
		</if>
		<if test="title !=null and title !=''">
			,#{title}
		</if>
		<if test="taskName !=null and taskName !=''">
			,#{taskName}
		</if>
		<if test="finishTime !=null and finishTime !=''">
			,#{finishTime}
		</if>
		<if test="url !=null and url !=''">
			,#{url}
		</if>
		<if test="appoint !=null and appoint !=''">
			,#{appoint}
		</if>
		<if test="descs !=null and descs !=''">
			,#{descs}
		</if>
		,now()
		,#{createBy}
		,0
		<if test="personInfo !=null and personInfo !=''">
			,#{personInfo}
		</if>
		,0
		<if test="releaseTime !=null">
			,#{releaseTime}
		</if>
		<if test="detaUrl !=null">
			,#{detaUrl}
		</if>
		)
	</insert>

	<select id="list" parameterType="cn.com.countrygarden.bi.main.dto.experience.TygGzhInfoManageDto" resultType="cn.com.countrygarden.bi.main.model.experience.TygGzhInfoManage">
		select
		id,
		model_id modelId,
		title,
		project_name projectName,
		task_name taskName,
		finish_time finishTime,
		url,
		appoint,
		create_time createTime,
		create_by createBy,
		update_time updateTime,
		update_by updateBy,
		status,
		person_info personInfo,
		release_time releaseTime,
		descs,
		deta_Url detaUrl
		from tyg_gzh_info_manage
		where deleted =0
		<if test="title !=null and title !=''">
			and title like concat('%',#{title},'%')
		</if>
		<if test="projectName !=null and projectName !=''">
			and project_name like concat('%',#{projectName},'%')
		</if>
		<if test="taskName !=null and taskName !=''">
			and task_name like concat('%',#{taskName},'%')
		</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.TygGzhInfoManageDto">
		select count(0) from tyg_gzh_info_manage where deleted =0
		<if test="title !=null and title !=''">
			and title like concat('%',#{title},'%')
		</if>
		<if test="projectName !=null and projectName !=''">
			and project_name like concat('%',#{projectName},'%')
		</if>
		<if test="taskName !=null and taskName !=''">
			and task_name like concat('%',#{taskName},'%')
		</if>
		ORDER BY
		create_time DESC
		<if test="page != null and size != null">
			limit #{pageStart}, #{size}
		</if>
	</select>

	<select id="selectById" resultType="cn.com.countrygarden.bi.main.model.experience.TygGzhInfoManage">
			select
		 id,
   		 model_id modelId,
    	 title,
    	 project_name projectName,
    	 task_name taskName,
         finish_time finishTime,
   		 url,
         appoint,
         create_time createTime,
         create_by createBy,
         update_time updateTime,
   		 update_by updateBy,
    	 status,
    	 person_info personInfo,
    	 release_time releaseTime,
    	 descs,
    	 deta_url detaUrl
		from tyg_gzh_info_manage
		where id=#{id} and deleted=0
	</select>

	<update id="del">
		update tyg_gzh_info_manage set deleted=1 where id=#{id}
	</update>

	<update id="updatePersonById">
		update tyg_gzh_info_manage set person_info=#{personInfo} where id=#{id}
	</update>
	<select id="selectListStatusNoEquals1" resultType="cn.com.countrygarden.bi.main.model.experience.TygGzhInfoManage">
		select id,
   		 model_id modelId,
    	 title,
    	 project_name projectName,
    	 task_name taskName,
         finish_time finishTime,
   		 url,
         appoint,
         deta_url detaUrl,
         create_time createTime,
         create_by createBy,
         update_time updateTime,
   		 update_by updateBy,
    	 status,
    	 person_info personInfo,
    	 release_time releaseTime,
    	 descs
    	  from tyg_gzh_info_manage where status=0
		AND release_time >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)
		and release_time &lt;= NOW()
		and deleted=0
	</select>
	<update id="update" parameterType="cn.com.countrygarden.bi.main.model.experience.TygGzhInfoManage">
		update tyg_gzh_info_manage set status=#{status} where id=#{id}
	</update>
</mapper>