<?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="jnpf.cultivate.mapper.CultivateCourseMsgMapper">
    <!--查询用户未读的培养课程消息-->
    <select id="queryUserUnreadMsg"
            resultType="jnpf.model.cultivate.vo.course.app.FtbCultivateCourseMsgForAppVO">
        SELECT
            F_Id as msgId,
            F_Desc as messageInfo,
            F_CourseId as courseId
        FROM
            ftb_cultivate_course_msg
        WHERE
            F_Id NOT IN (
                SELECT
                    F_MsgId
                FROM
                    ftb_cultivate_course_msg_user
                WHERE
                    F_UserId = #{dto.userId}
                  AND F_Status = 1
            )
          and F_State = #{dto.states}
          <if test="dto.courseId != null">
              and F_CourseId = #{dto.courseId}
          </if>

    </select>

    <select id="queryUserUnreadMsgV2" resultType="jnpf.model.cultivate.vo.course.app.FtbCultivateCourseMsgForAppVO">
        SELECT
            F_Id as msgId,
            F_Desc as messageInfo,
            F_CourseId as courseId
        FROM
            ftb_cultivate_course_msg
        WHERE F_DeleteMark=0
          and F_Status = 0
          and F_UserId = #{dto.userId}
          and F_CourseId in
          <foreach item="item" collection="dto.courseIds" separator="," open="(" close=")" index="">
              #{item}
          </foreach>
    </select>

    <update id="deleteInfoByMsgIdV2">
        delete from ftb_cultivate_course_msg
        WHERE F_UserId = #{userId}
          AND F_CourseId = #{courseId}
    </update>
</mapper>