<?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.engine.organization.mapper.personnelcard.CardAccessMapper">
    <resultMap id="BaseResultMap" type="com.engine.organization.entity.personnelcard.po.CardAccessPO">
        <result column="id" property="id"/>
        <result column="type_id" property="typeId"/>
        <result column="type_name" property="typeName"/>
        <result column="status" property="status"/>
        <result column="all_people" property="allPeople"/>
        <result column="superior" property="superior"/>
        <result column="all_superior" property="allSuperior"/>
        <result column="custom" property="custom"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>


    <!-- 表字段 -->
    <sql id="baseColumns">
        t.id
        , t.type_id
        , t.type_name
        , t.status
        , t.all_people
        , t.superior
        , t.all_superior
        , t.custom
        , t.creator
        , t.delete_type
        , t.create_time
        , t.update_time
    </sql>



    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.personnelcard.po.CardAccessPO" keyProperty="id"
            keyColumn="id" useGeneratedKeys="true">
        INSERT INTO jcl_org_cardaccess
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeId != null ">
                type_id,
            </if>
            <if test="typeName != null and typeName != ''">
                type_name,
            </if>
            <if test="status != null ">
                status,
            </if>
            <if test="allPeople != null ">
                all_people,
            </if>
            <if test="superior != null ">
                superior,
            </if>
            <if test="allSuperior != null ">
                all_superior,
            </if>
            <if test="custom != null">
                custom,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="typeId != null ">
                #{typeId},
            </if>
            <if test="typeName != null and typeName != ''">
                #{typeName},
            </if>
            <if test="status != null ">
                #{status},
            </if>
            <if test="allPeople != null ">
                #{allPeople},
            </if>
            <if test="superior != null ">
                #{superior},
            </if>
            <if test="allSuperior != null ">
                #{allSuperior},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="custom != null">
                #{custom},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.personnelcard.po.CardAccessPO" databaseId="oracle">
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select JCL_ORG_CARDACCESS_ID.currval from dual
        </selectKey>
        INSERT INTO jcl_org_cardaccess
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeId != null ">
                type_id,
            </if>
            <if test="typeName != null and typeName != ''">
                type_name,
            </if>
            <if test="status != null ">
                status,
            </if>
            <if test="allPeople != null ">
                all_people,
            </if>
            <if test="superior != null ">
                superior,
            </if>
            <if test="allSuperior != null ">
                all_superior,
            </if>
            <if test="custom != null">
                custom,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="typeId != null ">
                #{typeId},
            </if>
            <if test="typeName != null and typeName != ''">
                #{typeName},
            </if>
            <if test="status != null ">
                #{status},
            </if>
            <if test="allPeople != null ">
                #{allPeople},
            </if>
            <if test="superior != null ">
                #{superior},
            </if>
            <if test="allSuperior != null ">
                #{allSuperior},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="custom != null">
                #{custom},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>



    <update id="saveCardAccess" parameterType="java.util.List">
        update jcl_org_cardaccess
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="status =case" suffix="end,">
                <foreach collection="dataList" item="item" index="index">
                    <if test="item.status != null">
                        when id=#{item.id} then #{item.status}
                    </if>
                </foreach>
            </trim>
            <trim prefix="all_people =case" suffix="end,">
                <foreach collection="dataList" item="item" index="index">
                    <if test="item.allPeople != null">
                        when id=#{item.id} then #{item.allPeople}
                    </if>
                </foreach>
            </trim>
            <trim prefix="superior =case" suffix="end,">
                <foreach collection="dataList" item="item" index="index">
                    <if test="item.superior != null">
                        when id=#{item.id} then #{item.superior}
                    </if>
                </foreach>
            </trim>
            <trim prefix="all_superior =case" suffix="end,">
                <foreach collection="dataList" item="item" index="index">
                    <if test="item.allSuperior != null">
                        when id=#{item.id} then #{item.allSuperior}
                    </if>
                </foreach>
            </trim>
            <trim prefix="custom =case" suffix="end,">
                <foreach collection="dataList" item="item" index="index">
                        when id=#{item.id} then #{item.custom}
                </foreach>
            </trim>
            <trim prefix="update_time =case" suffix="end,">
                <foreach collection="dataList" item="item" index="index">
                    <if test="item.updateTime != null">
                        when id=#{item.id} then #{item.updateTime}
                    </if>
                </foreach>
            </trim>
        </trim>
        where
        <foreach collection="dataList" separator="or" item="item" index="index" >
            id=#{item.id}
        </foreach>
    </update>

    <update id="deleteByIds">
        UPDATE jcl_org_cardaccess
        SET delete_type = 1
        WHERE delete_type = 0
        AND type_id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>



    <select id="selectById" resultMap="BaseResultMap">
        select
          <include refid="baseColumns"/>
        from jcl_org_cardaccess t
        WHERE delete_type = 0
        AND type_id = #{id}
    </select>



    <update id="updateTabName">
        UPDATE jcl_org_cardaccess
        SET type_name = #{name}
        WHERE type_id = #{id}
    </update>
</mapper>