<?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.mmc.iuav.user.dao.CooperationDao">

    <insert id="addApply" parameterType="com.mmc.iuav.user.entity.UserApplyTagDO" useGeneratedKeys="true" keyProperty="id">
        insert into user_apply_tag(cooperation_tag_id, user_account_id, apply_name, apply_phone, remark, create_time)
         values(#{cooperationTagId}, #{userAccountId}, #{applyName}, #{applyPhone}, #{remark}, NOW())
    </insert>

    <update id="updateUserApplyTag" parameterType="com.mmc.iuav.user.entity.UserApplyTagDO">
        UPDATE user_apply_tag
        <set>
            <if test="cooperationTagId != null">
                cooperation_tag_id = #{cooperationTagId},
            </if>
            <if test="userAccountId != null">
                user_account_id = #{userAccountId},
            </if>
            <if test="applyName != null">
                apply_name = #{applyName},
            </if>
            <if test="applyPhone != null">
                apply_phone = #{applyPhone},
            </if>
            <if test="applyStatus != null">
                apply_status = #{applyStatus},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
        </set>
        WHERE id = #{id};
    </update>

    <select id="listTags" resultType="com.mmc.iuav.user.entity.CooperationTagDO">
        select id, tag_name, tag_img, tag_description, create_time from cooperation_tag
    </select>

    <select id="getUserApplyTag" resultType="com.mmc.iuav.user.entity.UserApplyTagDO">
        select id, cooperation_tag_id, user_account_id, apply_name, apply_phone, apply_status, remark, create_time
        from user_apply_tag
        where user_account_id = #{userAccountId} and is_deleted = 0
    </select>
</mapper>