<?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="id"    column="id"    />
        <result property="unitName"    column="unit_name"    />
        <result property="orgCode"    column="org_code"    />
        <result property="runAddress"    column="run_address"    />
        <result property="regAddress"    column="reg_address"    />
        <result property="regulationType"    column="regulation_type"    />
        <result property="regDate"    column="reg_date"    />
        <result property="businessTerm"    column="business_term"    />
        <result property="dutyPhone"    column="duty_phone"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="businessScope"    column="business_scope"    />
        <result property="employeeNum"    column="employee_num"    />
        <result property="legalPerson"    column="legal_person"    />
        <result property="legalPersonPhone"    column="legal_person_phone"    />
        <result property="keyPerson"    column="key_person"    />
        <result property="keyPersonPhone"    column="key_person_phone"    />
        <result property="safetyPerson"    column="safety_person"    />
        <result property="safetyPersonPhone"    column="safety_person_phone"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTEnterpriseInfoVo">
        select id, unit_name, org_code, run_address, reg_address, regulation_type, reg_date, business_term, duty_phone, longitude, latitude, business_scope, employee_num, legal_person, legal_person_phone, key_person, key_person_phone, safety_person, safety_person_phone, create_user_id, update_user_id, update_time, create_time, remarks from t_enterprise_info
    </sql>

    <select id="selectTEnterpriseInfoList" parameterType="TEnterpriseInfo" resultMap="TEnterpriseInfoResult">
        <include refid="selectTEnterpriseInfoVo"/>
        <where>  
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="orgCode != null  and orgCode != ''"> and org_code = #{orgCode}</if>
            <if test="runAddress != null  and runAddress != ''"> and run_address = #{runAddress}</if>
            <if test="regAddress != null  and regAddress != ''"> and reg_address = #{regAddress}</if>
            <if test="regulationType != null  and regulationType != ''"> and regulation_type = #{regulationType}</if>
            <if test="regDate != null "> and reg_date = #{regDate}</if>
            <if test="businessTerm != null  and businessTerm != ''"> and business_term = #{businessTerm}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="businessScope != null  and businessScope != ''"> and business_scope = #{businessScope}</if>
            <if test="employeeNum != null  and employeeNum != ''"> and employee_num = #{employeeNum}</if>
            <if test="legalPerson != null  and legalPerson != ''"> and legal_person = #{legalPerson}</if>
            <if test="legalPersonPhone != null  and legalPersonPhone != ''"> and legal_person_phone = #{legalPersonPhone}</if>
            <if test="keyPerson != null  and keyPerson != ''"> and key_person = #{keyPerson}</if>
            <if test="keyPersonPhone != null  and keyPersonPhone != ''"> and key_person_phone = #{keyPersonPhone}</if>
            <if test="safetyPerson != null  and safetyPerson != ''"> and safety_person = #{safetyPerson}</if>
            <if test="safetyPersonPhone != null  and safetyPersonPhone != ''"> and safety_person_phone = #{safetyPersonPhone}</if>
            <if test="createUserId != null  and createUserId != ''"> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null  and updateUserId != ''"> and update_user_id = #{updateUserId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTEnterpriseInfoById" parameterType="Long" resultMap="TEnterpriseInfoResult">
        <include refid="selectTEnterpriseInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTEnterpriseInfo" parameterType="TEnterpriseInfo">
        insert into t_enterprise_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unitName != null">unit_name,</if>
            <if test="orgCode != null">org_code,</if>
            <if test="runAddress != null">run_address,</if>
            <if test="regAddress != null">reg_address,</if>
            <if test="regulationType != null">regulation_type,</if>
            <if test="regDate != null">reg_date,</if>
            <if test="businessTerm != null">business_term,</if>
            <if test="dutyPhone != null">duty_phone,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="businessScope != null">business_scope,</if>
            <if test="employeeNum != null">employee_num,</if>
            <if test="legalPerson != null">legal_person,</if>
            <if test="legalPersonPhone != null">legal_person_phone,</if>
            <if test="keyPerson != null">key_person,</if>
            <if test="keyPersonPhone != null">key_person_phone,</if>
            <if test="safetyPerson != null">safety_person,</if>
            <if test="safetyPersonPhone != null">safety_person_phone,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="orgCode != null">#{orgCode},</if>
            <if test="runAddress != null">#{runAddress},</if>
            <if test="regAddress != null">#{regAddress},</if>
            <if test="regulationType != null">#{regulationType},</if>
            <if test="regDate != null">#{regDate},</if>
            <if test="businessTerm != null">#{businessTerm},</if>
            <if test="dutyPhone != null">#{dutyPhone},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="businessScope != null">#{businessScope},</if>
            <if test="employeeNum != null">#{employeeNum},</if>
            <if test="legalPerson != null">#{legalPerson},</if>
            <if test="legalPersonPhone != null">#{legalPersonPhone},</if>
            <if test="keyPerson != null">#{keyPerson},</if>
            <if test="keyPersonPhone != null">#{keyPersonPhone},</if>
            <if test="safetyPerson != null">#{safetyPerson},</if>
            <if test="safetyPersonPhone != null">#{safetyPersonPhone},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTEnterpriseInfo" parameterType="TEnterpriseInfo">
        update t_enterprise_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="orgCode != null">org_code = #{orgCode},</if>
            <if test="runAddress != null">run_address = #{runAddress},</if>
            <if test="regAddress != null">reg_address = #{regAddress},</if>
            <if test="regulationType != null">regulation_type = #{regulationType},</if>
            <if test="regDate != null">reg_date = #{regDate},</if>
            <if test="businessTerm != null">business_term = #{businessTerm},</if>
            duty_phone = #{dutyPhone},
            longitude = #{longitude},
            latitude = #{latitude},
            business_scope = #{businessScope},
            employee_num = #{employeeNum},
            legal_person = #{legalPerson},
            legal_person_phone = #{legalPersonPhone},
            key_person = #{keyPerson},
            key_person_phone = #{keyPersonPhone},
            safety_person = #{safetyPerson},
            safety_person_phone = #{safetyPersonPhone},
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTEnterpriseInfoById" parameterType="Long">
        delete from t_enterprise_info where id = #{id}
    </delete>

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