<?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.ruoyi.system.mapper.SysUserEnterpriseMapper">
    
    <resultMap type="SysUserEnterprise" id="SysUserEnterpriseResult">
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="userId"    column="user_id"    />
        <result property="idCard"    column="id_card"    />
        <result property="realName"    column="real_name"    />
        <result property="creditCode"    column="credit_code"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="enterpriseType"    column="enterprise_type"    />
        <result property="enterpriseAddress"    column="enterprise_address"    />
        <result property="legalName"    column="legal_name"    />
        <result property="registeredCapital"    column="registered_capital"    />
        <result property="establishData"    column="establish_data"    />
        <result property="businessTerm"    column="business_term"    />
        <result property="businessScope"    column="business_scope"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysUserEnterpriseVo">
        select enterprise_id,user_id, id_card, real_name, credit_code, enterprise_name, enterprise_type, enterprise_address, legal_name, registered_capital, establish_data, business_term,business_scope, image_url, del_flag, create_by, create_time, update_by, update_time, remark from sys_user_enterprise
    </sql>

    <select id="selectSysUserEnterpriseList" parameterType="SysUserEnterprise" resultMap="SysUserEnterpriseResult">
        <include refid="selectSysUserEnterpriseVo"/>
        <where>  
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="enterpriseName != null  and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
            <if test="enterpriseType != null  and enterpriseType != ''"> and enterprise_type = #{enterpriseType}</if>
            <if test="enterpriseAddress != null  and enterpriseAddress != ''"> and enterprise_address = #{enterpriseAddress}</if>
            <if test="legalName != null  and legalName != ''"> and legal_name like concat('%', #{legalName}, '%')</if>
            <if test="registeredCapital != null  and registeredCapital != ''"> and registered_capital = #{registeredCapital}</if>
            <if test="establishData != null  and establishData != ''"> and establish_data = #{establishData}</if>
            <if test="businessTerm != null  and businessTerm != ''"> and business_term = #{businessTerm}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
        </where>
        order by create_time
    </select>
    
    <select id="selectSysUserEnterpriseByUserId" parameterType="Long" resultMap="SysUserEnterpriseResult">
        <include refid="selectSysUserEnterpriseVo"/>
        where user_id = #{userId}
    </select>
    <select id="selectSysUserEnterpriseByEnterpriseId" parameterType="Long" resultMap="SysUserEnterpriseResult">
        <include refid="selectSysUserEnterpriseVo"/>
        where enterprise_id = #{enterpriseId}
    </select>

    <insert id="insertSysUserEnterprise" parameterType="SysUserEnterprise" useGeneratedKeys="true" keyProperty="enterpriseId">
        insert into sys_user_enterprise
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="idCard != null and idCard != ''">id_card,</if>
            <if test="realName != null and realName != ''">real_name,</if>
            <if test="creditCode != null">credit_code,</if>
            <if test="enterpriseName != null and enterpriseName != ''">enterprise_name,</if>
            <if test="enterpriseType != null and enterpriseType != ''">enterprise_type,</if>
            <if test="enterpriseAddress != null and enterpriseAddress != ''">enterprise_address,</if>
            <if test="legalName != null and legalName != ''">legal_name,</if>
            <if test="registeredCapital != null and registeredCapital != ''">registered_capital,</if>
            <if test="establishData != null and establishData != ''">establish_data,</if>
            <if test="businessTerm != null and businessTerm != ''">business_term,</if>
            <if test="businessScope != null and businessScope != ''">business_scope,</if>
            <if test="imageUrl != null and imageUrl != ''">image_url,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="idCard != null and idCard != ''">#{idCard},</if>
            <if test="realName != null and realName != ''">#{realName},</if>
            <if test="creditCode != null">#{creditCode},</if>
            <if test="enterpriseName != null and enterpriseName != ''">#{enterpriseName},</if>
            <if test="enterpriseType != null and enterpriseType != ''">#{enterpriseType},</if>
            <if test="enterpriseAddress != null and enterpriseAddress != ''">#{enterpriseAddress},</if>
            <if test="legalName != null and legalName != ''">#{legalName},</if>
            <if test="registeredCapital != null and registeredCapital != ''">#{registeredCapital},</if>
            <if test="establishData != null and establishData != ''">#{establishData},</if>
            <if test="businessTerm != null and businessTerm != ''">#{businessTerm},</if>
            <if test="businessScope != null and businessScope != ''">#{businessScope},</if>
            <if test="imageUrl != null and imageUrl != ''">#{imageUrl},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            sysdate()
         </trim>
    </insert>

    <update id="updateSysUserEnterprise" parameterType="SysUserEnterprise">
        update sys_user_enterprise
        <trim prefix="SET" suffixOverrides=",">
            <if test="idCard != null and idCard != ''">id_card = #{idCard},</if>
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="creditCode != null">credit_code = #{creditCode},</if>
            <if test="enterpriseName != null and enterpriseName != ''">enterprise_name = #{enterpriseName},</if>
            <if test="enterpriseType != null and enterpriseType != ''">enterprise_type = #{enterpriseType},</if>
            <if test="enterpriseAddress != null and enterpriseAddress != ''">enterprise_address = #{enterpriseAddress},</if>
            <if test="legalName != null and legalName != ''">legal_name = #{legalName},</if>
            <if test="registeredCapital != null and registeredCapital != ''">registered_capital = #{registeredCapital},</if>
            <if test="establishData != null and establishData != ''">establish_data = #{establishData},</if>
            <if test="businessTerm != null and businessTerm != ''">business_term = #{businessTerm},</if>
            <if test="businessScope != null and businessScope != ''">business_scope = #{businessScope},</if>
            <if test="imageUrl != null and imageUrl != ''">image_url = #{imageUrl},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where enterprise_id = #{enterpriseId}
    </update>

    <delete id="deleteSysUserEnterpriseByUserId" parameterType="Long">
        delete from sys_user_enterprise where user_id = #{userId}
    </delete>

    <delete id="deleteSysUserEnterpriseByUserIds" parameterType="String">
        delete from sys_user_enterprise where user_id in
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
    <delete id="deleteSysUserEnterpriseByEnterpriseId" parameterType="Long">
        delete from sys_user_enterprise where enterprise_id = #{enterpriseId}
    </delete>
    <delete id="deleteSysUserEnterpriseByEnterpriseIds" parameterType="String">
        delete from sys_user_enterprise where enterprise_id in
        <foreach item="enterpriseId" collection="array" open="(" separator="," close=")">
            #{enterpriseId}
        </foreach>
    </delete>
</mapper>