<?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.mapper.AutomobileEnterpriseMapper">

    <resultMap type="com.ruoyi.domain.AutomobileEnterprise" id="AutomobileEnterpriseResult">
        <result property="id" column="id"/>
        <result property="enterpriseName" column="enterprise_name"/>
        <result property="address" column="address"/>
        <result property="postcode" column="postcode"/>
        <result property="enterpriseContact" column="enterprise_contact"/>
        <result property="contactNumber" column="contact_number"/>
        <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="deleted" column="deleted"/>
    </resultMap>

    <sql id="selectAutomobileEnterpriseVo">
        select id,
               enterprise_name,
               address,
               postcode,
               enterprise_contact,
               contact_number,
               create_by,
               create_time,
               update_by,
               update_time,
               deleted
        from t_automobile_enterprise
    </sql>

    <sql id="selectAutomobileEnterpriseListSQL">
        select ae.id,
               ae.enterprise_name,
               ae.address,
               ae.postcode,
               ae.enterprise_contact,
               ae.contact_number,
               su.nick_name create_by,
               ae.create_time,
               ae.update_by,
               ae.update_time,
               ae.deleted
        from t_automobile_enterprise ae
        left join sys_user su on ae.create_by = su.user_id
    </sql>

    <select id="selectAutomobileEnterpriseList" parameterType="com.ruoyi.domain.AutomobileEnterprise"
            resultMap="AutomobileEnterpriseResult">
        <include refid="selectAutomobileEnterpriseListSQL"/>
        <where>
            ae.deleted = 0
            <if test="enterpriseName != null  and enterpriseName != ''">and ae.enterprise_name like concat('%',
                #{enterpriseName}, '%')
            </if>
            <if test="address != null  and address != ''">and ae.address like concat('%', #{address}, '%')</if>
            <if test="postcode != null  and postcode != ''">and ae.postcode like concat('%', #{postcode}, '%')</if>
            <if test="enterpriseContact != null  and enterpriseContact != ''">
                and ae.enterprise_contact like concat('%', #{enterpriseContact}, '%')
            </if>
            <if test="contactNumber != null  and contactNumber != ''">and ae.contact_number like concat('%', #{contactNumber}, '%')</if>
        </where>
        order by ae.create_time desc
    </select>

    <select id="selectAutomobileEnterpriseById" parameterType="Long" resultMap="AutomobileEnterpriseResult">
        <include refid="selectAutomobileEnterpriseVo"/>
        where id = #{id}
    </select>

    <insert id="insertAutomobileEnterprise" parameterType="com.ruoyi.domain.AutomobileEnterprise">
        insert into t_automobile_enterprise
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="enterpriseName != null">enterprise_name,</if>
            <if test="address != null">address,</if>
            <if test="postcode != null">postcode,</if>
            <if test="enterpriseContact != null">enterprise_contact,</if>
            <if test="contactNumber != null">contact_number,</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="id != null">#{id},</if>
            <if test="enterpriseName != null">#{enterpriseName},</if>
            <if test="address != null">#{address},</if>
            <if test="postcode != null">#{postcode},</if>
            <if test="enterpriseContact != null">#{enterpriseContact},</if>
            <if test="contactNumber != null">#{contactNumber},</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="updateAutomobileEnterprise" parameterType="com.ruoyi.domain.AutomobileEnterprise">
        update t_automobile_enterprise
        <trim prefix="SET" suffixOverrides=",">
            <if test="enterpriseName != null">enterprise_name = #{enterpriseName},</if>
            <if test="address != null">address = #{address},</if>
            <if test="postcode != null">postcode = #{postcode},</if>
            <if test="enterpriseContact != null">enterprise_contact = #{enterpriseContact},</if>
            <if test="contactNumber != null">contact_number = #{contactNumber},</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>
</mapper>