<?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.ygtx.system.mapper.SysPostHomePageMapper">

	<resultMap type="SysPostHomePage" id="SysPostHomePageResult">
		<result property="id"    column="id"    />
		<result property="postIds"    column="post_ids"    />
		<result property="homePageType"    column="home_page_type"    />
		<result property="status"    column="status"    />
		<result property="createBy"    column="create_by"    />
		<result property="createTime"    column="create_time"    />
		<result property="updateBy"    column="update_by"    />
		<result property="updateTime"    column="update_time"    />
		<result property="name"    column="name"    />
		<result property="remark"    column="remark"    />
	</resultMap>

	<sql id="selectSysPostHomePageVo">
        select id, post_ids, home_page_type, status, create_by, create_time, update_by, update_time, name, remark from sys_post_home_page
    </sql>
	
	<select id="selectSysPostHomePageList" parameterType="SysPostHomePage" resultMap="SysPostHomePageResult">
	    <include refid="selectSysPostHomePageVo"/>
		<where>
			<if test="id != null and id != ''">
				AND id = #{id}
			</if>
			<if test="postIds != null and postIds != ''">
				AND (post_ids = #{postIds} OR post_ids LIKE CONCAT(#{postIds}, ',%') OR post_ids LIKE CONCAT('%,', #{postIds}, ',%') OR post_ids LIKE CONCAT('%,', #{postIds}))
			</if>
			<if test="homePageType != null and homePageType != ''">
				AND home_page_type = #{homePageType}
			</if>
			<if test="status != null and status != ''">
				AND status = #{status}
			</if>
			<if test="name != null and name != ''">
				AND name like concat('%', #{name}, '%')
			</if>
		</where>
	</select>
	
	<select id="selectSysPostHomePageById" parameterType="Long" resultMap="SysPostHomePageResult">
		<include refid="selectSysPostHomePageVo"/>
		where id = #{id}
	</select>
	
	<insert id="insertSysPostHomePage" parameterType="SysPostHomePage" useGeneratedKeys="true" keyProperty="id">
 		insert into sys_post_home_page(
			post_ids,
			home_page_type,
			status,
			<if test="name != null and name != ''">name,</if>
			<if test="remark != null">remark,</if>
			<if test="createBy != null and createBy != ''">create_by,</if>
			create_time
		) values (
			#{postIds},
			#{homePageType},
			#{status},
			<if test="name != null and name != ''">#{name},</if>
			<if test="remark != null">#{remark},</if>
			<if test="createBy != null and createBy != ''">#{createBy},</if>
			sysdate()
		)
	</insert>
	
	<update id="updateSysPostHomePage" parameterType="SysPostHomePage">
 		update sys_post_home_page
 		<set>
			<if test="postIds != null and postIds != ''">post_ids = #{postIds},</if>
			<if test="homePageType != null and homePageType != ''">home_page_type = #{homePageType},</if>
			<if test="status != null and status != ''">status = #{status},</if>
			<if test="name != null and name != ''">name = #{name},</if>
			<if test="remark != null">remark = #{remark},</if>
			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
			update_time = sysdate()
		</set>
		where id = #{id}
	</update>
 	
	<delete id="deleteSysPostHomePageById" parameterType="Long">
		delete from sys_post_home_page where id = #{id}
	</delete>
	
	<delete id="deleteSysPostHomePageByIds" parameterType="Long">
 		delete from sys_post_home_page where id in
 		<foreach collection="array" item="id" open="(" separator="," close=")">
 			#{id}
        </foreach> 
 	</delete>

</mapper>