<?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.TContractorMapper">
    
    <resultMap type="TContractor" id="TContractorResult">
        <result property="id"    column="id"    />
        <result property="contractorName"    column="contractor_name"    />
        <result property="certificateName"    column="certificate_name"    />
        <result property="certificateUrl"    column="certificate_url"    />
        <result property="teamInformation"    column="team_information"    />
        <result property="contractorEvaluate"    column="contractor_evaluate"    />
        <result property="violationRecords"    column="violation_records"    />
        <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="status"    column="status"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTContractorVo">
        select id, contractor_name, certificate_name, certificate_url, team_information, contractor_evaluate, violation_records, legal_person, legal_person_phone, key_person, key_person_phone, safety_person, safety_person_phone, status, is_del, create_time, update_time from t_contractor
    </sql>

    <select id="selectTContractorList" parameterType="TContractor" resultMap="TContractorResult">
        <include refid="selectTContractorVo"/>
        <where>  is_del = '0'
            <if test="contractorName != null  and contractorName != ''"> and contractor_name like concat('%', #{contractorName}, '%')</if>
            <if test="certificateName != null  and certificateName != ''"> and certificate_name like concat('%', #{certificateName}, '%')</if>
            <if test="certificateUrl != null  and certificateUrl != ''"> and certificate_url = #{certificateUrl}</if>
            <if test="teamInformation != null  and teamInformation != ''"> and team_information = #{teamInformation}</if>
            <if test="contractorEvaluate != null  and contractorEvaluate != ''"> and contractor_evaluate = #{contractorEvaluate}</if>
            <if test="violationRecords != null  and violationRecords != ''"> and violation_records = #{violationRecords}</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="status != null  and status != ''"> and status = #{status}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectTContractorById" parameterType="Long" resultMap="TContractorResult">
        <include refid="selectTContractorVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTContractor" parameterType="TContractor">
        insert into t_contractor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="contractorName != null">contractor_name,</if>
            <if test="certificateName != null">certificate_name,</if>
            <if test="certificateUrl != null">certificate_url,</if>
            <if test="teamInformation != null">team_information,</if>
            <if test="contractorEvaluate != null">contractor_evaluate,</if>
            <if test="violationRecords != null">violation_records,</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="status != null">status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="contractorName != null">#{contractorName},</if>
            <if test="certificateName != null">#{certificateName},</if>
            <if test="certificateUrl != null">#{certificateUrl},</if>
            <if test="teamInformation != null">#{teamInformation},</if>
            <if test="contractorEvaluate != null">#{contractorEvaluate},</if>
            <if test="violationRecords != null">#{violationRecords},</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="status != null">#{status},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTContractor" parameterType="TContractor">
        update t_contractor
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractorName != null">contractor_name = #{contractorName},</if>
            certificate_name = #{certificateName},
            certificate_url = #{certificateUrl},
            team_information = #{teamInformation},
            contractor_evaluate = #{contractorEvaluate},
            violation_records = #{violationRecords},
            legal_person = #{legalPerson},
            legal_person_phone = #{legalPersonPhone},
            key_person = #{keyPerson},
            key_person_phone = #{keyPersonPhone},
            safety_person = #{safetyPerson},
            safety_person_phone = #{safetyPersonPhone},
            <if test="status != null">status = #{status},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTContractorById" parameterType="Long">
        delete from t_contractor where id = #{id}
    </delete>

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