<?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.zehong.system.mapper.TEnterpriseInfoMapper">

    <resultMap type="TEnterpriseInfo" id="TEnterpriseInfoResult">
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="registerAddress"    column="register_address"    />
        <result property="legalRepresentative"    column="legal_representative"    />
        <result property="businessArea"    column="business_area"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="iconType"    column="icon_type"    />
        <result property="licenseKey"    column="license_key"    />
        <result property="licenseValidityTime"    column="license_validity_time"    />
        <result property="annualSupervisionInspection"    column="annual_supervision_inspection"    />
        <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="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="doDusiness"    column="do_business"    />
    </resultMap>

    <sql id="selectTEnterpriseInfoVo">
        select enterprise_id, enterprise_name, register_address, legal_representative,
        business_area, longitude, latitude, icon_type, license_key, license_validity_time, annual_supervision_inspection,
        create_by, create_time, update_by, update_time, remarks,do_business from t_enterprise_info
    </sql>

    <select id="selectTEnterpriseInfoList" parameterType="TEnterpriseInfo" resultMap="TEnterpriseInfoResult">
        <include refid="selectTEnterpriseInfoVo"/>
        <where>
            1=1 and is_del='0'
            <if test="enterpriseName != null  and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
            <if test="registerAddress != null  and registerAddress != ''"> and register_address = #{registerAddress}</if>
            <if test="legalRepresentative != null  and legalRepresentative != ''"> and legal_representative = #{legalRepresentative}</if>
            <if test="businessArea != null  and businessArea != ''"> and business_area = #{businessArea}</if>
            <if test="licenseKey != null  and licenseKey != ''"> and license_key = #{licenseKey}</if>
            <if test="licenseValidityTime != null  and licenseValidityTime != ''"> and license_validity_time = #{licenseValidityTime}</if>
            <if test="annualSupervisionInspection != null  and annualSupervisionInspection != ''"> and annual_supervision_inspection = #{annualSupervisionInspection}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
        group by enterprise_id desc
    </select>

    <select id="selectTEnterpriseInfoById" parameterType="Long" resultMap="TEnterpriseInfoResult">
        <include refid="selectTEnterpriseInfoVo"/>
        where enterprise_id = #{enterpriseId} and is_del='0'
    </select>

    <insert id="insertTEnterpriseInfo" parameterType="TEnterpriseInfo" useGeneratedKeys="true" keyProperty="enterpriseId">
        insert into t_enterprise_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="enterpriseName != null">enterprise_name,</if>
            <if test="registerAddress != null">register_address,</if>
            <if test="legalRepresentative != null">legal_representative,</if>
            <if test="businessArea != null">business_area,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="iconType != null">icon_type,</if>
            <if test="licenseKey != null">license_key,</if>
            <if test="licenseValidityTime != null">license_validity_time,</if>
            <if test="annualSupervisionInspection != null">annual_supervision_inspection,</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="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
            <if test="doDusiness != null">do_business,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="enterpriseName != null">#{enterpriseName},</if>
            <if test="registerAddress != null">#{registerAddress},</if>
            <if test="legalRepresentative != null">#{legalRepresentative},</if>
            <if test="businessArea != null">#{businessArea},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="iconType != null">#{iconType},</if>
            <if test="licenseKey != null">#{licenseKey},</if>
            <if test="licenseValidityTime != null">#{licenseValidityTime},</if>
            <if test="annualSupervisionInspection != null">#{annualSupervisionInspection},</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="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="doDusiness != null">#{doDusiness},</if>
         </trim>
    </insert>

    <update id="updateTEnterpriseInfo" parameterType="TEnterpriseInfo">
        update t_enterprise_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="enterpriseName != null">enterprise_name = #{enterpriseName},</if>
            <if test="registerAddress != null">register_address = #{registerAddress},</if>
            <if test="legalRepresentative != null">legal_representative = #{legalRepresentative},</if>
            <if test="businessArea != null">business_area = #{businessArea},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="iconType != null">icon_type = #{iconType},</if>
            <if test="licenseKey != null">license_key = #{licenseKey},</if>
            <if test="licenseValidityTime != null">license_validity_time = #{licenseValidityTime},</if>
            <if test="annualSupervisionInspection != null">annual_supervision_inspection = #{annualSupervisionInspection},</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="remarks != null">remarks = #{remarks},</if>
            <if test="doDusiness != null">do_business=#{doDusiness},</if>
        </trim>
        where enterprise_id = #{enterpriseId}
    </update>

    <update id="deleteTEnterpriseInfoById" parameterType="Long">
        update  t_enterprise_info set is_del='1' where enterprise_id = #{enterpriseId}
    </update>

    <update id="deleteTEnterpriseInfoByIds" parameterType="String">
        update  t_enterprise_info set is_del='1' where enterprise_id in
        <foreach item="enterpriseId" collection="array" open="(" separator="," close=")">
            #{enterpriseId}
        </foreach>
    </update>
</mapper>