<?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.WorkerSpecialSkillMapper">

    <resultMap id="WorkerSpecialSkillResult"        type="com.ghy.worker.domain.WorkerSpecialSkill">
        <result property="workerSpecialSkillId"     column="worker_special_skill_id"/>
        <result property="workerId"                 column="worker_id"/>
        <result property="specialSkillId"           column="special_skill_id"/>
        <result property="credential"               column="credential"/>
        <result property="insurance"                column="insurance"/>
        <result property="insuranceStart"           column="insurance_start"/>
        <result property="insuranceEnd"             column="insurance_end"/>
        <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"/>
        <result property="specialSkillName"         column="special_skill_name"/>
        <result property="dangerous"         column="dangerous"/>
    </resultMap>

    <sql id="selectSpecialSkill">
        SELECT wss.worker_special_skill_id, wss.worker_id, wss.special_skill_id, wss.credential, wss.insurance, wss.insurance_start,
        wss.insurance_end, wss.create_by, wss.create_time, wss.update_by, wss.update_time, wss.remark, ss.special_skill_name, ss.dangerous
        FROM worker_special_skill wss
        LEFT JOIN special_skill ss on ss.special_skill_id = wss.special_skill_id
    </sql>

    <insert id="insert" parameterType="com.ghy.worker.domain.WorkerSpecialSkill" useGeneratedKeys="true"
            keyProperty="workerSpecialSkillId">
        INSERT INTO worker_special_skill(
        <if test="workerId != null and workerId > 0">worker_id,</if>
        <if test="specialSkillId != null and specialSkillId > 0">special_skill_id,</if>
        <if test="credential != null and credential != ''">credential,</if>
        <if test="insurance != null and insurance != ''">insurance,</if>
        <if test="insuranceStart != null">insurance_start,</if>
        <if test="insuranceEnd != null">insurance_end,</if>
        <if test="createBy != null and createBy != ''">create_by,</if>
        <if test="remark != null and remark != ''">remark,</if>
        create_time
        )VALUES(
        <if test="workerId != null and workerId > 0">#{workerId},</if>
        <if test="specialSkillId != null and specialSkillId > 0">#{specialSkillId},</if>
        <if test="credential != null and credential != ''">#{credential},</if>
        <if test="insurance != null and insurance != ''">#{insurance},</if>
        <if test="insuranceStart != null">#{insuranceStart},</if>
        <if test="insuranceEnd != null">#{insuranceEnd},</if>
        <if test="createBy != null and createBy != ''">#{createBy},</if>
        <if test="remark != null and remark != ''">#{remark},</if>
        sysdate()
        )
    </insert>

    <insert id="batchInsert" parameterType="list" >
        INSERT INTO worker_special_skill ( worker_id, special_skill_id, credential, insurance, insurance_start, insurance_end,
        create_by, create_time)
        VALUES
        <foreach collection="workerSpecialSkills" separator=","  item="item">
            (#{item.workerId}, #{item.specialSkillId}, #{item.credential}, #{item.insurance}, #{item.insuranceStart},
            #{item.insuranceEnd}, #{item.workerId}, sysdate())
        </foreach>
    </insert>

    <select id="getByWorker" parameterType="Long" resultMap="WorkerSpecialSkillResult">
        <include refid="selectSpecialSkill"/>
        WHERE wss.worker_id = #{workerId}
    </select>

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

    <delete id="delete" parameterType="Long">
        DELETE FROM worker_special_skill WHERE worker_special_skill_id IN
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
