<?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.EnterpriseApplyMapper">
    
    <resultMap type="EnterpriseApply" id="EnterpriseApplyResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="coding"    column="coding"    />
        <result property="legalPersonName"    column="legal_person_name"    />
        <result property="cardType"    column="card_type"    />
        <result property="legalPersonCard"    column="legal_person_card"    />
        <result property="phone"    column="phone"    />
        <result property="isAudit"    column="is_audit"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="auditOpinion"    column="audit_opinion"    />
        <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"    />

        <collection  property="enterprisePhotoList"   javaType="java.util.List"    resultMap="EnterprisePhotoResult" />
    </resultMap>


    <resultMap type="EnterprisePhoto" id="EnterprisePhotoResult">
        <result property="id"    column="id"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="path"    column="path"    />
        <result property="type"    column="type"    />
        <result property="remark"    column="remark"    />
    </resultMap>


    <sql id="selectEnterpriseApplyVo">
        select a.id, a.name, a.coding, a.legal_person_name, a.card_type, a.legal_person_card, a.phone, a.is_audit, a.user_id, a.user_name, a.user_phone,
               a.audit_opinion, a.create_by, a.create_time, a.update_by, a.
            update_time, a.remark, p.path,p.type,p.remark
        from enterprise_apply a
        left join enterprise_photo p on p.enterprise_id = a.id
    </sql>

    <select id="selectEnterpriseApplyList" parameterType="EnterpriseApply" resultMap="EnterpriseApplyResult">
        <include refid="selectEnterpriseApplyVo"/>
        <where>  
            <if test="name != null  and name != ''"> and a.name like concat('%', #{name}, '%')</if>
            <if test="coding != null  and coding != ''"> and a.coding = #{coding}</if>
            <if test="legalPersonName != null  and legalPersonName != ''"> and a.legal_person_name like concat('%', #{legalPersonName}, '%')</if>
            <if test="cardType != null  and cardType != ''"> and a.card_type = #{cardType}</if>
            <if test="legalPersonCard != null  and legalPersonCard != ''"> and a.legal_person_card = #{legalPersonCard}</if>
            <if test="phone != null  and phone != ''"> and a.phone = #{phone}</if>
            <if test="isAudit != null  and isAudit != ''"> and a.is_audit = #{isAudit}</if>
            <if test="userName != null  and userName != ''"> and a.user_name like concat('%', #{userName}, '%')</if>
            <if test="userPhone != null  and userPhone != ''"> and a.user_phone = #{userPhone}</if>
            <if test="auditOpinion != null  and auditOpinion != ''"> and a.audit_opinion = #{auditOpinion}</if>
        </where>
    </select>
    
    <select id="selectEnterpriseApplyById" parameterType="Long" resultMap="EnterpriseApplyResult">
        <include refid="selectEnterpriseApplyVo"/>
        where a.id = #{id}
    </select>
        
    <insert id="insertEnterpriseApply" parameterType="EnterpriseApply" useGeneratedKeys="true" keyProperty="id">
        insert into enterprise_apply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="coding != null">coding,</if>
            <if test="legalPersonName != null">legal_person_name,</if>
            <if test="cardType != null">card_type,</if>
            <if test="legalPersonCard != null">legal_person_card,</if>
            <if test="phone != null">phone,</if>
            <if test="isAudit != null">is_audit,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="auditOpinion != null">audit_opinion,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="coding != null">#{coding},</if>
            <if test="legalPersonName != null">#{legalPersonName},</if>
            <if test="cardType != null">#{cardType},</if>
            <if test="legalPersonCard != null">#{legalPersonCard},</if>
            <if test="phone != null">#{phone},</if>
            <if test="isAudit != null">#{isAudit},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="auditOpinion != null">#{auditOpinion},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateEnterpriseApply" parameterType="EnterpriseApply">
        update enterprise_apply
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="coding != null">coding = #{coding},</if>
            <if test="legalPersonName != null">legal_person_name = #{legalPersonName},</if>
            <if test="cardType != null">card_type = #{cardType},</if>
            <if test="legalPersonCard != null">legal_person_card = #{legalPersonCard},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="isAudit != null">is_audit = #{isAudit},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="auditOpinion != null">audit_opinion = #{auditOpinion},</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 id = #{id}
    </update>

    <delete id="deleteEnterpriseApplyById" parameterType="Long">
        delete from enterprise_apply where id = #{id}
    </delete>

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