<?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.ruoyi.system.mapper.notice.XiaoyuanInfoMapper">
    
    <resultMap type="XiaoyuanInfo" id="XiaoyuanInfoResult">
        <result property="infoId"    column="info_id"    />
        <result property="infoTitle"    column="info_title"    />
        <result property="infoPhoto"    column="info_photo"    />
        <result property="schoolId"    column="school_id"    />
        <result property="schoolName"    column="school_name"    />
        <result property="infoType"    column="info_type"    />
        <result property="infoTypeZi"    column="info_type_zi"    />
        <result property="infoContent"    column="info_content"    />
        <result property="status"    column="status"    />
        <result property="faBuTime"    column="faBu_time"    />
        <result property="infoYiDu"    column="info_yidu"    />
        <result property="infoDianZanId"    column="info_dianzan_id"    />
        <result property="infoDianZan"    column="info_dianzan"    />
        <result property="infoZhuanFa"    column="info_zhuanfa"    />
        <result property="infoPingLunId"    column="info_pinglun_id"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <resultMap id="XiaoyuanInfoInfoPingLunResult" type="XiaoyuanInfo" extends="XiaoyuanInfoResult">
        <collection property="infoPingLunList" notNullColumn="sub_info_PingLun_id" javaType="java.util.List" resultMap="InfoPingLunResult" />
    </resultMap>

    <resultMap type="InfoPingLun" id="InfoPingLunResult">
        <result property="infoPingLunId"    column="sub_info_PingLun_id"    />
        <result property="infoId"    column="sub_info_id"    />
        <result property="infoPingLunParent"    column="sub_info_PingLun_parent"    />
        <result property="infoPingLunContent"    column="sub_info_PingLun_content"    />
        <result property="avatar"    column="sub_avatar"    />
        <result property="infoPingLunUserId"    column="sub_info_PingLun_user_id"    />
        <result property="infoPingLunUserName"    column="sub_info_PingLun_user_name"    />
        <result property="infoPingLunQuiltUserId"    column="sub_info_PingLun_quilt_user_id"    />
        <result property="infoPingLunQuiltUserName"    column="sub_info_PingLun_quilt_user_name"    />
        <result property="pingLunTime"    column="sub_PingLun_time"    />
        <result property="infoPingLunType"    column="sub_info_PingLun_type"    />
        <result property="infoPingLunExamine"    column="sub_info_PingLun_examine"    />
        <result property="createBy"    column="sub_create_by"    />
        <result property="createTime"    column="sub_create_time"    />
        <result property="updateBy"    column="sub_update_by"    />
        <result property="updateTime"    column="sub_update_time"    />
        <result property="remark"    column="sub_remark"    />
    </resultMap>

    <sql id="selectXiaoyuanInfoVo">
        select info_id, info_title, info_photo, school_id, school_name, info_type, info_type_zi, info_content, status, fabu_time, info_yidu, info_dianzan_id,info_dianzan, info_zhuanfa, info_pinglun_id, create_by, create_time, update_by, update_time, remark from xiaoyuan_info
    </sql>

    <select id="selectXiaoyuanInfoList" parameterType="XiaoyuanInfo" resultMap="XiaoyuanInfoResult">
        <include refid="selectXiaoyuanInfoVo"/>
        <where>  
            <if test="infoTitle != null  and infoTitle != ''"> and info_title = #{infoTitle}</if>
            <if test="infoPhoto != null  and infoPhoto != ''"> and info_photo = #{infoPhoto}</if>
            <if test="schoolId != null "> and school_id = #{schoolId}</if>
            <if test="schoolName != null  and schoolName != ''"> and school_name like concat('%', #{schoolName}, '%')</if>
            <if test="infoType != null  and infoType != ''"> and info_type = #{infoType}</if>
            <if test="infoTypeZi != null  and infoTypeZi != ''"> and info_type_zi = #{infoTypeZi}</if>
            <if test="infoContent != null  and infoContent != ''"> and info_content = #{infoContent}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="faBuTime != null "> and faBu_time = #{faBuTime}</if>
            <if test="infoYiDu != null  and infoYiDu != ''"> and info_yidu = #{infoYiDu}</if>
            <if test="infoZhuanFa != null  and infoZhuanFa != ''"> and info_zhuanfa = #{infoZhuanFa}</if>
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
        </where>
    </select>
    
    <select id="selectXiaoyuanInfoByInfoId" parameterType="Long" resultMap="XiaoyuanInfoInfoPingLunResult">
        select a.info_id, a.info_title, a.info_photo, a.school_id, a.school_name, a.info_type, a.info_type_zi, a.info_content, a.status, a.fabu_time, a.info_yidu, a.info_dianzan_id,a.info_dianzan, a.info_zhuanfa, a.info_pinglun_id, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
            b.info_pinglun_id as sub_info_PingLun_id, b.info_id as sub_info_id, b.info_pinglun_parent as sub_info_PingLun_parent, b.info_pinglun_content as sub_info_PingLun_content, b.avatar as sub_avatar, b.info_pinglun_user_id as sub_info_PingLun_user_id, b.info_pinglun_user_name as sub_info_PingLun_user_name, b.info_pinglun_quilt_user_id as sub_info_PingLun_quilt_user_id, b.info_pinglun_quilt_user_name as sub_info_PingLun_quilt_user_name, b.pinglun_time as sub_PingLun_time, b.info_pinglun_type as sub_info_PingLun_type, b.info_pinglun_examine as sub_info_PingLun_examine, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark
        from xiaoyuan_info a
        left join info_pinglun b on b.info_id = a.info_id
        where a.info_id = #{infoId}
    </select>
        
    <insert id="insertXiaoyuanInfo" parameterType="XiaoyuanInfo" useGeneratedKeys="true" keyProperty="infoId">
        insert into xiaoyuan_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="infoTitle != null and infoTitle != ''">info_title,</if>
            <if test="infoPhoto != null and infoPhoto != ''">info_photo,</if>
            <if test="schoolId != null">school_id,</if>
            <if test="schoolName != null and schoolName != ''">school_name,</if>
            <if test="infoType != null and infoType != ''">info_type,</if>
            <if test="infoTypeZi != null and infoTypeZi != ''">info_type_zi,</if>
            <if test="infoContent != null">info_content,</if>
            <if test="status != null">status,</if>
            <if test="faBuTime != null">fabu_time,</if>
            <if test="infoYiDu != null and infoYiDu != ''">info_yidu,</if>
            <if test="infoDianZanId != null">info_dianzan_id,</if>
            <if test="infoDianZan != null and infoDianZan != ''">info_dianzan,</if>
            <if test="infoZhuanFa != null and infoZhuanFa != ''">info_zhuanfa,</if>
            <if test="infoPingLunId != null">info_pinglun_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="infoTitle != null and infoTitle != ''">#{infoTitle},</if>
            <if test="infoPhoto != null and infoPhoto != ''">#{infoPhoto},</if>
            <if test="schoolId != null">#{schoolId},</if>
            <if test="schoolName != null and schoolName != ''">#{schoolName},</if>
            <if test="infoType != null and infoType != ''">#{infoType},</if>
            <if test="infoTypeZi != null and infoTypeZi != ''">#{infoTypeZi},</if>
            <if test="infoContent != null">#{infoContent},</if>
            <if test="status != null">#{status},</if>
            <if test="faBuTime != null">#{faBuTime},</if>
            <if test="infoYiDu != null and infoYiDu != ''">#{infoYiDu},</if>
            <if test="infoDianZanId != null">#{infoDianZanId},</if>
            <if test="infoDianZan != null and infoDianZan != ''">#{infoDianZan},</if>
            <if test="infoZhuanFa != null and infoZhuanFa != ''">#{infoZhuanFa},</if>
            <if test="infoPingLunId != null">#{infoPingLunId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateXiaoyuanInfo" parameterType="XiaoyuanInfo">
        update xiaoyuan_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="infoTitle != null and infoTitle != ''">info_title = #{infoTitle},</if>
            <if test="infoPhoto != null and infoPhoto != ''">info_photo = #{infoPhoto},</if>
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="schoolName != null and schoolName != ''">school_name = #{schoolName},</if>
            <if test="infoType != null and infoType != ''">info_type = #{infoType},</if>
            <if test="infoTypeZi != null and infoTypeZi != ''">info_type_zi = #{infoTypeZi},</if>
            <if test="infoContent != null">info_content = #{infoContent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="faBuTime != null">fabu_time = #{faBuTime},</if>
            <if test="infoYiDu != null and infoYiDu != ''">info_yidu = #{infoYiDu},</if>
            <if test="infoDianZanId != null">info_dianzan_id = #{infoDianZanId},</if>
            <if test="infoDianZan != null and infoDianZan != ''">info_dianzan = #{infoDianZan},</if>
            <if test="infoZhuanFa != null and infoZhuanFa != ''">info_zhuanfa = #{infoZhuanFa},</if>
            <if test="infoPingLunId != null">info_pinglun_id = #{infoPingLunId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where info_id = #{infoId}
    </update>

    <update id="updateXiaoyuanInfoYiDu" parameterType="XiaoyuanInfo">
        update xiaoyuan_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="infoYiDu != null and infoYiDu != ''">info_yidu = #{infoYiDu},</if>
            <if test="infoDianZan != null and infoDianZan != ''">info_dianzan = #{infoDianZan},</if>
            <if test="infoZhuanFa != null and infoZhuanFa != ''">info_zhuanfa = #{infoZhuanFa},</if>
        </trim>
        where info_id = #{infoId}
    </update>
    <delete id="deleteXiaoyuanInfoByInfoId" parameterType="Long">
        delete from xiaoyuan_info where info_id = #{infoId}
    </delete>

    <delete id="deleteXiaoyuanInfoByInfoIds" parameterType="String">
        delete from xiaoyuan_info where info_id in 
        <foreach item="infoId" collection="array" open="(" separator="," close=")">
            #{infoId}
        </foreach>
    </delete>
    
    <delete id="deleteInfoPingLunByInfoIds" parameterType="String">
        delete from info_pinglun where info_id in
        <foreach item="infoId" collection="array" open="(" separator="," close=")">
            #{infoId}
        </foreach>
    </delete>

    <delete id="deleteInfoPingLunByInfoId" parameterType="Long">
        delete from info_pinglun where info_id = #{infoId}
    </delete>

    <delete id="deletePingLun" parameterType="InfoPingLun">
           delete from info_pinglun where
        <if test="infoPingLunType != null and infoPingLunType == 1">info_pinglun_parent = #{infoPingLunId} or info_pinglun_id = #{infoPingLunId}</if>
        <if test="infoPingLunType != null and infoPingLunType == 2">info_pinglun_id = #{infoPingLunId}</if>
    </delete>

    <insert id="batchInfoPingLun">
        insert into info_pinglun( info_pinglun_id, info_id, info_pinglun_parent, info_pinglun_content, avatar, info_pinglun_user_id, info_pinglun_user_name, info_pinglun_quilt_user_id, info_pinglun_quilt_user_name, pinglun_time, info_pinglun_type, info_pinglun_examine, create_by, create_time, update_by, update_time, remark) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.infoPingLunId}, #{item.infoId}, #{item.infoPingLunParent}, #{item.infoPingLunContent}, #{item.avatar}, #{item.infoPingLunUserId}, #{item.infoPingLunUserName}, #{item.infoPingLunQuiltUserId}, #{item.infoPingLunQuiltUserName}, #{item.pingLunTime}, #{item.infoPingLunType}, #{item.infoPingLunExamine}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark})
        </foreach>
    </insert>
</mapper>