<?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.TContractorPersonMapper">
    
    <resultMap type="TContractorPersonVo" id="TContractorPersonResult">
        <result property="id"    column="id"    />
        <result property="contractorId"    column="contractor_id"    />
        <result property="contractorName"    column="contractor_name"    />
        <result property="name"    column="name"    />
        <result property="age"    column="age"    />
        <result property="sex"    column="sex"    />
        <result property="phone"    column="phone"    />
        <result property="certificateName"    column="certificate_name"    />
        <result property="certificateUrl"    column="certificate_url"    />
        <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="selectTContractorPersonVo">
        select t.id, t.contractor_id, t.name, t.age, t.sex, t.phone, t.certificate_name, t.certificate_url, t.status, t.is_del, t.create_time, t.update_time,
        c.contractor_name
        from t_contractor_person t left join t_contractor c on t.contractor_id = c.id
    </sql>

    <select id="selectTContractorPersonList" parameterType="TContractorPerson" resultMap="TContractorPersonResult">
        <include refid="selectTContractorPersonVo"/>
        <where>  t.is_del = '0'
            <if test="name != null  and name != ''"> and t.name like concat('%', #{name}, '%')</if>
            <if test="contractorId != null and contractorId != ''"> and t.contractor_id = #{contractorId}</if>
            <if test="age != null "> and t.age = #{age}</if>
            <if test="sex != null "> and t.sex = #{sex}</if>
            <if test="phone != null  and phone != ''"> and t.phone like concat('%', #{phone}, '%')</if>
            <if test="status != null  and status != ''"> and t.status = #{status}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(t.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(t.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectTContractorPersonById" parameterType="Long" resultMap="TContractorPersonResult">
        <include refid="selectTContractorPersonVo"/>
        where t.id = #{id}
    </select>
        
    <insert id="insertTContractorPerson" parameterType="TContractorPerson">
        insert into t_contractor_person
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="contractorId != null">contractor_id,</if>
            <if test="name != null">name,</if>
            <if test="age != null">age,</if>
            <if test="sex != null">sex,</if>
            <if test="phone != null">phone,</if>
            <if test="certificateName != null">certificate_name,</if>
            <if test="certificateUrl != null">certificate_url,</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="contractorId != null">#{contractorId},</if>
            <if test="name != null">#{name},</if>
            <if test="age != null">#{age},</if>
            <if test="sex != null">#{sex},</if>
            <if test="phone != null">#{phone},</if>
            <if test="certificateName != null">#{certificateName},</if>
            <if test="certificateUrl != null">#{certificateUrl},</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="updateTContractorPerson" parameterType="TContractorPerson">
        update t_contractor_person
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="age != null">age = #{age},</if>
            <if test="sex != null">sex = #{sex},</if>
            contractor_id = #{contractorId},
            phone = #{phone},
            certificate_name = #{certificateName},
            certificate_url = #{certificateUrl},
            <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="deleteTContractorPersonById" parameterType="Long">
        delete from t_contractor_person where id = #{id}
    </delete>

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