<?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.ktg.iscs.mapper.IsJobCardMapper">

    <resultMap type="IsJobCard" id="IsJobCardResult">
        <result property="cardId"    column="card_id"    />
        <result property="cardCode"    column="card_code"    />
        <result property="hardwareId"    column="hardware_id"    />
        <result property="cardNfc"    column="card_nfc"    />
        <result property="cardType"    column="card_type"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="exStatus"    column="ex_status"    />
        <result property="exRemark"    column="ex_remark"    />
    </resultMap>

    <sql id="selectIsJobCardVo">
        select * from is_job_card
    </sql>

    <select id="selectIsJobCardList" parameterType="IsJobCard" resultMap="IsJobCardResult">
        <include refid="selectIsJobCardVo"/>
        <where>
            <if test="cardCode != null  and cardCode != ''"> and card_code = #{cardCode}</if>
            <if test="hardwareId != null "> and hardware_id = #{hardwareId}</if>
            <if test="cardNfc != null  and cardNfc != ''"> and card_nfc = #{cardNfc}</if>
            <if test="cardType != null "> and card_type = #{cardType}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
        </where>
    </select>

    <select id="selectIsJobCardByCardId" parameterType="Long" resultMap="IsJobCardResult">
        <include refid="selectIsJobCardVo"/>
        where card_id = #{cardId}
    </select>

    <insert id="insertIsJobCard" parameterType="IsJobCard" useGeneratedKeys="true" keyProperty="cardId">
        insert into is_job_card
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cardCode != null and cardCode != ''">card_code,</if>
            <if test="hardwareId != null">hardware_id,</if>
            <if test="cardNfc != null and cardNfc != ''">card_nfc,</if>
            <if test="cardType != null">card_type,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="exStatus != null and exStatus != ''">ex_status,</if>
            <if test="exRemark != null and exRemark != ''">ex_remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cardCode != null and cardCode != ''">#{cardCode},</if>
            <if test="hardwareId != null">#{hardwareId},</if>
            <if test="cardNfc != null and cardNfc != ''">#{cardNfc},</if>
            <if test="cardType != null">#{cardType},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="exStatus != null and exStatus != ''">#{exStatus},</if>
            <if test="exRemark != null and exRemark != ''">#{exRemark},</if>
         </trim>
    </insert>

    <update id="updateIsJobCard" parameterType="IsJobCard">
        update is_job_card
        <trim prefix="SET" suffixOverrides=",">
            <if test="cardCode != null and cardCode != ''">card_code = #{cardCode},</if>
            <if test="hardwareId != null">hardware_id = #{hardwareId},</if>
            <if test="cardNfc != null and cardNfc != ''">card_nfc = #{cardNfc},</if>
            <if test="cardType != null">card_type = #{cardType},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="exStatus != null and exStatus != ''">ex_status = #{exStatus},</if>
            <if test="exRemark != null and exRemark != ''">ex_remark = #{exRemark},</if>
        </trim>
        where card_id = #{cardId}
    </update>

    <delete id="deleteIsJobCardByCardId" parameterType="Long">
        delete from is_job_card where card_id = #{cardId}
    </delete>

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