<?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.nbclass.szxgl.mapper.ProjectTaskJournalMapper">
  <resultMap id="BaseResultMap" type="com.nbclass.szxgl.model.ProjectTaskJournal">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="CHAR" property="id" />
    <result column="_project_task_id" jdbcType="CHAR" property="projectTaskId" />
    <result column="_start_time" jdbcType="TIMESTAMP" property="startTime" />
    <result column="_end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="_content" jdbcType="VARCHAR" property="content" />
    <result column="_journal" jdbcType="VARCHAR" property="journal" />
    <result column="_create_user_id" jdbcType="CHAR" property="createUserId" />
    <result column="_create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="_update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>

	<select id="getList" resultType="com.nbclass.szxgl.model.ProjectTaskJournal">
  		select j.*, sy_users.true_name as createUserName
		from project_task_journal j
		left join sy_users ON j._create_user_id = sy_users.id
		where j._project_task_id = #{taskId}
  		order by j._create_time desc
	</select>

    <delete id="deleteByTaskId" parameterType="java.lang.String">
        delete from project_task_journal where _project_task_id = #{projectTaskId}
    </delete>

    <update id="updateTaskJournal">
        update project_task_journal set
        <if test="score!=null">
            _score = #{score},
        </if>
        <if test="comment!=null and comment!=''">
            _comment = #{comment},
        </if>
        <if test="commentId!=null and commentId!=''">
            _comment_id = #{commentId},
        </if>
        <if test="status!=null">
            _status = #{status}
        </if>
        where id = #{id}
    </update>

    <select id="getUserName" resultType="java.lang.String">
        select su.true_name from project_task_journal j LEFT JOIN sy_users su ON j._comment_id = su.id where j.id = #{id}
    </select>

    <insert id="addTaskFontType" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
        insert into project_task_journal_font_type
        (
        id,
        list_values_id,
        project_task_journal_id,
        created_time
        )
        values
        (
        #{id},
        #{listValuesId},
        #{projectTaskJournalId},
        now()
        )
    </insert>

</mapper>
