<?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.microservices.pms.project.mapper.PmsIssueCompletionMapper">

    <resultMap type="com.microservices.pms.project.domain.PmsIssueCompletion" id="PmsIssueCompletionResult">
        <result property="id" column="id"/>
        <result property="gitlinkIssueId" column="gitlink_issue_id"/>
        <result property="description" column="description"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="gitlinkUserId" column="gitlink_user_id"/>
    </resultMap>
    <insert id="insert" parameterType="com.microservices.pms.project.domain.PmsIssueCompletion">
        insert into pms_issue_completion
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="gitlinkIssueId != null and gitlinkIssueId != ''">
                gitlink_issue_id,
            </if>
            <if test="description != null and description != ''">
                description,
            </if>
            <if test="type != null and type != ''">
                type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="gitlinkUserId != null and gitlinkUserId != ''">
                gitlink_user_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="gitlinkIssueId != null and gitlinkIssueId != ''">
                #{gitlinkIssueId},
            </if>
            <if test="description != null and description != ''">
                #{description},
            </if>
            <if test="type != null and type != ''">
                #{type},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="gitlinkUserId != null and gitlinkUserId != ''">
                #{gitlinkUserId},
            </if>
        </trim>
    </insert>
    <update id="updateDescription" parameterType="com.microservices.pms.project.domain.PmsIssueCompletion">
        update pms_issue_completion
        set
        <if test="description != null and description != ''">
            description = #{description},
        </if>
        <if test="updateTime != null">
            update_time = #{updateTime}
        </if>
        where gitlink_issue_id = #{gitlinkIssueId} and gitlink_user_id = #{gitlinkUserId}
    </update>
    <delete id="deleteByGitlinkIssueIdAndUserId">
        delete from pms_issue_completion
        where gitlink_issue_id = #{gitlinkIssueId} and gitlink_user_id = #{gitlinkUserId}
    </delete>
    <select id="selectByGitlinkIssueIdAndUserId" resultType="com.microservices.pms.project.domain.PmsIssueCompletion">
        select description
        from pms_issue_completion
        where gitlink_issue_id = #{gitlinkIssueId} and gitlink_user_id = #{gitlinkUserId}
        order by id desc limit 1
    </select>

</mapper>