<?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.ghy.worker.mapper.WorkerCertificationMapper">

    <resultMap type="WorkerCertification" id="WorkerCertificationResult">
        <result property="workerCertificationId"    column="worker_certification_id"    />
        <result property="workerId"    column="worker_id"    />
        <result property="surname"    column="surname"    />
        <result property="name"    column="name"    />
        <result property="idCardNum"    column="id_card_num"    />
        <result property="idCardUrl1"    column="id_card_url_1"    />
        <result property="idCardUrl2"    column="id_card_url_2"    />
        <result property="brandName"    column="brand_name"    />
        <result property="companySize"    column="company_size"    />
        <result property="companyName"    column="company_name"    />
        <result property="businessLicenseNum"    column="business_license_num"    />
        <result property="businessLicenseUrl"    column="business_license_url"    />
        <result property="companyProvinceId"    column="company_province_id"    />
        <result property="companyCityId"    column="company_city_id"    />
        <result property="companyCountryId"    column="company_country_id"    />
        <result property="companyAddress"    column="company_address"    />
        <result property="legalPersionName"    column="legal_persion_name"    />
        <result property="legalPersionPhoneNum"    column="legal_persion_phone_num"    />
        <result property="otherServ"    column="other_serv"    />
        <result property="status"    column="status"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectWorkerCertificationVo">
        select worker_certification_id, worker_id, surname, name, id_card_num, id_card_url_1, id_card_url_2, brand_name, company_size, company_name, business_license_num, business_license_url, company_province_id, company_city_id, company_country_id, company_address, legal_persion_name, legal_persion_phone_num, other_serv, status, create_by, create_time, update_by, update_time, remark from worker_certification
    </sql>

    <select id="selectWorkerCertificationList" parameterType="WorkerCertification" resultMap="WorkerCertificationResult">
        select worker_certification.* from worker_certification left join  worker on worker_certification.worker_id = worker.worker_id
        <where>
            <if test="workerId != null  and workerId != ''"> and worker_certification.worker_id = #{workerId}</if>
            <if test="name != null  and name != ''"> and worker_certification.name like concat('%', #{name}, '%')</if>
            <if test="idCardNum != null  and idCardNum != ''"> and worker_certification.id_card_num = #{idCardNum}</if>
            <if test="idCardUrl1 != null  and idCardUrl1 != ''"> and worker_certification.id_card_url_1 = #{idCardUrl1}</if>
            <if test="idCardUrl2 != null  and idCardUrl2 != ''"> and worker_certification.id_card_url_2 = #{idCardUrl2}</if>
            <if test="brandName != null  and brandName != ''"> and worker_certification.brand_name like concat('%', #{brandName}, '%')</if>
            <if test="companySize != null "> and worker_certification.company_size = #{companySize}</if>
            <if test="companyName != null  and companyName != ''"> and worker_certification.company_name like concat('%', #{companyName}, '%')</if>
            <if test="businessLicenseNum != null  and businessLicenseNum != ''"> and worker_certification.business_license_num = #{businessLicenseNum}</if>
            <if test="businessLicenseUrl != null  and businessLicenseUrl != ''"> and worker_certification.business_license_url = #{businessLicenseUrl}</if>
            <if test="companyProvinceId != null "> and worker_certification.company_province_id = #{companyProvinceId}</if>
            <if test="companyCityId != null "> and worker_certification.company_city_id = #{companyCityId}</if>
            <if test="companyCountryId != null "> and worker_certification.company_country_id = #{companyCountryId}</if>
            <if test="companyAddress != null  and companyAddress != ''"> and worker_certification.company_address = #{companyAddress}</if>
            <if test="legalPersionName != null  and legalPersionName != ''"> and worker_certification.legal_persion_name like concat('%', #{legalPersionName}, '%')</if>
            <if test="legalPersionPhoneNum != null  and legalPersionPhoneNum != ''"> and worker_certification.legal_persion_phone_num = #{legalPersionPhoneNum}</if>
            <if test="otherServ != null  and otherServ != ''"> and worker_certification.other_serv = #{otherServ}</if>
            <if test="status != null "> and worker_certification.status = #{status}</if>
            <if test="deptId != null and deptId != ''"> and worker.dept_id = #{deptId}</if>
        </where>
    </select>

    <select id="selectWorkerCertificationByWorkerCertificationId" parameterType="String" resultMap="WorkerCertificationResult">
        <include refid="selectWorkerCertificationVo"/>
        where worker_certification_id = #{workerCertificationId}
    </select>

    <select id="selectByWorkerId" parameterType="Long" resultMap="WorkerCertificationResult">
        <include refid="selectWorkerCertificationVo" /> WHERE worker_id = #{workerId}
    </select>

    <insert id="insertWorkerCertification" parameterType="WorkerCertification" useGeneratedKeys="true" keyProperty="workerCertificationId">
        insert into worker_certification
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workerId != null">worker_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="surname != null and surname != ''">surname,</if>
            <if test="idCardNum != null and idCardNum != ''">id_card_num,</if>
            <if test="idCardUrl1 != null">id_card_url_1,</if>
            <if test="idCardUrl2 != null">id_card_url_2,</if>
            <if test="brandName != null">brand_name,</if>
            <if test="companySize != null">company_size,</if>
            <if test="companyName != null">company_name,</if>
            <if test="businessLicenseNum != null">business_license_num,</if>
            <if test="businessLicenseUrl != null">business_license_url,</if>
            <if test="companyProvinceId != null">company_province_id,</if>
            <if test="companyCityId != null">company_city_id,</if>
            <if test="companyCountryId != null">company_country_id,</if>
            <if test="companyAddress != null">company_address,</if>
            <if test="legalPersionName != null">legal_persion_name,</if>
            <if test="legalPersionPhoneNum != null">legal_persion_phone_num,</if>
            <if test="otherServ != null">other_serv,</if>
            <if test="status != null">status,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workerId != null">#{workerId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="surname != null and surname != ''">#{surname},</if>
            <if test="idCardNum != null and idCardNum != ''">#{idCardNum},</if>
            <if test="idCardUrl1 != null">#{idCardUrl1},</if>
            <if test="idCardUrl2 != null">#{idCardUrl2},</if>
            <if test="brandName != null">#{brandName},</if>
            <if test="companySize != null">#{companySize},</if>
            <if test="companyName != null">#{companyName},</if>
            <if test="businessLicenseNum != null">#{businessLicenseNum},</if>
            <if test="businessLicenseUrl != null">#{businessLicenseUrl},</if>
            <if test="companyProvinceId != null">#{companyProvinceId},</if>
            <if test="companyCityId != null">#{companyCityId},</if>
            <if test="companyCountryId != null">#{companyCountryId},</if>
            <if test="companyAddress != null">#{companyAddress},</if>
            <if test="legalPersionName != null">#{legalPersionName},</if>
            <if test="legalPersionPhoneNum != null">#{legalPersionPhoneNum},</if>
            <if test="otherServ != null">#{otherServ},</if>
            <if test="status != null">#{status},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWorkerCertification" parameterType="WorkerCertification">
        update worker_certification
        <trim prefix="SET" suffixOverrides=",">
            <if test="workerId != null and workerId != ''">worker_id = #{workerId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="idCardNum != null and idCardNum != ''">id_card_num = #{idCardNum},</if>
            <if test="idCardUrl1 != null">id_card_url_1 = #{idCardUrl1},</if>
            <if test="idCardUrl2 != null">id_card_url_2 = #{idCardUrl2},</if>
            <if test="brandName != null">brand_name = #{brandName},</if>
            <if test="companySize != null">company_size = #{companySize},</if>
            <if test="companyName != null">company_name = #{companyName},</if>
            <if test="businessLicenseNum != null">business_license_num = #{businessLicenseNum},</if>
            <if test="businessLicenseUrl != null">business_license_url = #{businessLicenseUrl},</if>
            <if test="companyProvinceId != null">company_province_id = #{companyProvinceId},</if>
            <if test="companyCityId != null">company_city_id = #{companyCityId},</if>
            <if test="companyCountryId != null">company_country_id = #{companyCountryId},</if>
            <if test="companyAddress != null">company_address = #{companyAddress},</if>
            <if test="legalPersionName != null">legal_persion_name = #{legalPersionName},</if>
            <if test="legalPersionPhoneNum != null">legal_persion_phone_num = #{legalPersionPhoneNum},</if>
            <if test="otherServ != null">other_serv = #{otherServ},</if>
            <if test="status != null">status = #{status},</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="remark != null">remark = #{remark},</if>
        </trim>
        where worker_certification_id = #{workerCertificationId}
    </update>

    <delete id="deleteWorkerCertificationByWorkerCertificationId" parameterType="String">
        delete from worker_certification where worker_certification_id = #{workerCertificationId}
    </delete>

    <delete id="deleteWorkerCertificationByWorkerCertificationIds" parameterType="String">
        delete from worker_certification where worker_certification_id in
        <foreach item="workerCertificationId" collection="array" open="(" separator="," close=")">
            #{workerCertificationId}
        </foreach>
    </delete>

    <delete id="deleteCertificationByWorkerId" parameterType="Long">
        DELETE FROM worker_certification WHERE worker_id = #{workerId}
    </delete>

    <update id="changeStatus">
        UPDATE worker_certification set status = #{status}
        WHERE worker_certification_id in ( #{ids} )
    </update>
</mapper>
