<?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.oa.mapper.OaFeedbackMapper">

    <resultMap type="com.ruoyi.oa.domain.OaFeedback" id="OaFeedbackResult">
        <result property="feedbackId" column="feedback_id"/>
        <result property="content" column="content"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>
    <insert id="insertItem">

        INSERT INTO oa_feedback_item (
        feedback_id,
        user_id
        )
        SELECT
        #{feedbackId},
        su.user_id
        FROM sys_user su
        WHERE su.del_flag = 0
    </insert>


    <update id="updateToRead">
        update oa_feedback_item set status = 1 where feedback_id =#{feedbackId} and user_id = #{userId}
    </update>
    <delete id="delItem">
        delete from oa_feedback_item where feedback_id =#{feedbackId} and user_id = #{userId}
    </delete>


    <select id="selectVoPageAndStatus" resultType="com.ruoyi.oa.domain.vo.OaFeedbackVo">

        select
            oaf.feedback_id,
            oaf.content,
            oaf.status,
            oaf.title,
            ofi.status as state
        from oa_feedback oaf
            left join oa_feedback_item ofi on oaf.feedback_id = ofi.feedback_id
        ${ew.getCustomSqlSegment}
    </select>


</mapper>
