<?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.dms.achievementLibrary.mapper.AchievementTeamMapper">
    
    <resultMap type="AchievementTeam" id="AchievementTeamResult">
        <result property="id"    column="id"    />
        <result property="achievementId"    column="achievement_id"    />
        <result property="username"    column="username"    />
        <result property="company"    column="company"    />
        <result property="technicalTitle"    column="technical_title"    />
        <result property="professionalTitle"    column="professional_title"    />
        <result property="researchDirection"    column="research_direction"    />
        <result property="phone"    column="phone"    />
        <result property="summary"    column="summary"    />
        <result property="workContent"    column="work_content"    />
        <result property="isLeader"    column="is_leader"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAchievementTeamVo">
        select id, achievement_id, username, company, technical_title, professional_title, research_direction, phone, summary, work_content, is_leader, status, create_by, create_time, update_by, update_time from achievement_team
    </sql>

    <select id="selectAchievementTeamList" parameterType="AchievementTeam" resultMap="AchievementTeamResult">
        <include refid="selectAchievementTeamVo"/>
        <where>  
            <if test="achievementId != null "> and achievement_id = #{achievementId}</if>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="company != null  and company != ''"> and company = #{company}</if>
            <if test="technicalTitle != null  and technicalTitle != ''"> and technical_title = #{technicalTitle}</if>
            <if test="professionalTitle != null  and professionalTitle != ''"> and professional_title = #{professionalTitle}</if>
            <if test="researchDirection != null  and researchDirection != ''"> and research_direction = #{researchDirection}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="summary != null  and summary != ''"> and summary = #{summary}</if>
            <if test="workContent != null  and workContent != ''"> and work_content = #{workContent}</if>
            <if test="isLeader != null  and isLeader != ''"> and is_leader = #{isLeader}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAchievementTeamById" parameterType="Long" resultMap="AchievementTeamResult">
        <include refid="selectAchievementTeamVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAchievementTeam" parameterType="AchievementTeam" useGeneratedKeys="true" keyProperty="id">
        insert into achievement_team
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="achievementId != null">achievement_id,</if>
            <if test="username != null and username != ''">username,</if>
            <if test="company != null">company,</if>
            <if test="technicalTitle != null">technical_title,</if>
            <if test="professionalTitle != null">professional_title,</if>
            <if test="researchDirection != null">research_direction,</if>
            <if test="phone != null">phone,</if>
            <if test="summary != null">summary,</if>
            <if test="workContent != null">work_content,</if>
            <if test="isLeader != null">is_leader,</if>
            <if test="status != null">status,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="achievementId != null">#{achievementId},</if>
            <if test="username != null and username != ''">#{username},</if>
            <if test="company != null">#{company},</if>
            <if test="technicalTitle != null">#{technicalTitle},</if>
            <if test="professionalTitle != null">#{professionalTitle},</if>
            <if test="researchDirection != null">#{researchDirection},</if>
            <if test="phone != null">#{phone},</if>
            <if test="summary != null">#{summary},</if>
            <if test="workContent != null">#{workContent},</if>
            <if test="isLeader != null">#{isLeader},</if>
            <if test="status != null">#{status},</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>
         </trim>
    </insert>

    <update id="updateAchievementTeam" parameterType="AchievementTeam">
        update achievement_team
        <trim prefix="SET" suffixOverrides=",">
            <if test="achievementId != null">achievement_id = #{achievementId},</if>
            <if test="username != null and username != ''">username = #{username},</if>
            <if test="company != null">company = #{company},</if>
            <if test="technicalTitle != null">technical_title = #{technicalTitle},</if>
            <if test="professionalTitle != null">professional_title = #{professionalTitle},</if>
            <if test="researchDirection != null">research_direction = #{researchDirection},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="summary != null">summary = #{summary},</if>
            <if test="workContent != null">work_content = #{workContent},</if>
            <if test="isLeader != null">is_leader = #{isLeader},</if>
            <if test="status != null">status = #{status},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAchievementTeamById" parameterType="Long">
        delete from achievement_team where id = #{id}
    </delete>

    <delete id="deleteAchievementTeamByIds" parameterType="String">
        delete from achievement_team where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteAchievementTeamByAId">
        delete
        from achievement_team
        where achievement_id = #{aid}
    </delete>

    <select id="selectAchievementTeamByAchId"   resultMap="AchievementTeamResult">
        <include refid="selectAchievementTeamVo"/>
        where achievement_id = #{achId}
    </select>
</mapper>