<?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.salary.mapper.datacollection.AttendQuoteDataValueMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.po.AttendQuoteDataValuePO">
        <result column="id" property="id"/>
        <result column="employee_id" property="employeeId"/>
        <result column="attend_quote_id" property="attendQuoteId"/>
        <result column="attend_quote_data_id" property="attendQuoteDataId"/>
        <result column="attend_quote_field_id" property="attendQuoteFieldId"/>
        <result column="data_value" property="dataValue"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="tenant_key" property="tenantKey"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.employee_id
        , t.attend_quote_id
        , t.attend_quote_data_id
        , t.attend_quote_field_id
        , t.data_value
        , t.create_time
        , t.update_time
        , t.creator
        , t.delete_type
        , t.tenant_key
    </sql>

    <!-- 查询全部 -->
    <select id="listAll" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_attend_quote_data_value t
        WHERE delete_type = 0
    </select>

    <!-- 根据主键获取单条记录 -->
    <select id="getById" resultMap="BaseResultMap" parameterType="Long">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_attend_quote_data_value t
        WHERE id = #{id} AND delete_type = 0
    </select>

    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.datacollection.po.AttendQuoteDataValuePO"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO hrsa_attend_quote_data_value
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="attendQuoteId != null">
                attend_quote_id,
            </if>
            <if test="attendQuoteDataId != null">
                attend_quote_data_id,
            </if>
            <if test="attendQuoteFieldId != null">
                attend_quote_field_id,
            </if>
            <if test="dataValue != null">
                data_value,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="employeeId != null">
                #{employeeId},
            </if>
            <if test="attendQuoteId != null">
                #{attendQuoteId},
            </if>
            <if test="attendQuoteDataId != null">
                #{attendQuoteDataId},
            </if>
            <if test="attendQuoteFieldId != null">
                #{attendQuoteFieldId},
            </if>
            <if test="dataValue != null">
                #{dataValue},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.datacollection.po.AttendQuoteDataValuePO" databaseId="oracle"
    >
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select hrsa_attend_quote_data_value_id.currval from dual
        </selectKey>
        INSERT INTO hrsa_attend_quote_data_value
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="employeeId != null">
                employee_id,
            </if>
            <if test="attendQuoteId != null">
                attend_quote_id,
            </if>
            <if test="attendQuoteDataId != null">
                attend_quote_data_id,
            </if>
            <if test="attendQuoteFieldId != null">
                attend_quote_field_id,
            </if>
            <if test="dataValue != null">
                data_value,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="employeeId != null">
                #{employeeId},
            </if>
            <if test="attendQuoteId != null">
                #{attendQuoteId},
            </if>
            <if test="attendQuoteDataId != null">
                #{attendQuoteDataId},
            </if>
            <if test="attendQuoteFieldId != null">
                #{attendQuoteFieldId},
            </if>
            <if test="dataValue != null">
                #{dataValue},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.datacollection.po.AttendQuoteDataValuePO">
        UPDATE hrsa_attend_quote_data_value
        <set>
            employee_id=#{employeeId},
            attend_quote_id=#{attendQuoteId},
            attend_quote_data_id=#{attendQuoteDataId},
            attend_quote_field_id=#{attendQuoteFieldId},
            data_value=#{dataValue},
            create_time=#{createTime},
            update_time=#{updateTime},
            creator=#{creator},
            delete_type=#{deleteType},
            tenant_key=#{tenantKey},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.datacollection.po.AttendQuoteDataValuePO">
        UPDATE hrsa_attend_quote_data_value
        <set>
            <if test="employeeId != null">
                employee_id=#{employeeId},
            </if>
            <if test="attendQuoteId != null">
                attend_quote_id=#{attendQuoteId},
            </if>
            <if test="attendQuoteDataId != null">
                attend_quote_data_id=#{attendQuoteDataId},
            </if>
            <if test="attendQuoteFieldId != null">
                attend_quote_field_id=#{attendQuoteFieldId},
            </if>
            <if test="dataValue != null">
                data_value=#{dataValue},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <update id="updateDataValueByFiledIdAndEmployeeId" parameterType="com.engine.salary.entity.datacollection.po.AttendQuoteDataValuePO">
        UPDATE hrsa_attend_quote_data_value
        <set>
            <if test="dataValue != null">
                data_value=#{dataValue},
            </if>
        </set>
        WHERE employee_id = #{employeeId} AND delete_type = 0 AND attend_quote_field_id = #{attendQuoteFieldId}
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete" parameterType="com.engine.salary.entity.datacollection.po.AttendQuoteDataValuePO">
        UPDATE hrsa_attend_quote_data_value
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>


    <update id="deleteByAttendQuoteDataIds">
        UPDATE hrsa_attend_quote_data_value
        SET delete_type = 1
        WHERE delete_type = 0
        AND attend_quote_data_id IN
        <foreach collection="attendQuoteDataIds" open="(" item="attendQuoteDataId" separator="," close=")">
            #{attendQuoteDataId}
        </foreach>
    </update>

    <insert id="insertData">
        INSERT INTO hrsa_attend_quote_data_value(
        employee_id,
        attend_quote_id,
        attend_quote_data_id,
        attend_quote_field_id,
        data_value,
        create_time,
        update_time,
        creator,
        tenant_key)
        VALUES
        <foreach collection="collection" item="item" separator=",">
            (
            #{item.employeeId},
            #{item.attendQuoteId},
            #{item.attendQuoteDataId},
            #{item.attendQuoteFieldId},
            #{item.dataValue},
            #{item.createTime},
            #{item.updateTime},
            #{item.creator},
            #{item.tenantKey}
            )
        </foreach>
    </insert>
    <insert id="insertData" databaseId="oracle">
        INSERT INTO hrsa_attend_quote_data_value(
        employee_id,
        attend_quote_id,
        attend_quote_data_id,
        attend_quote_field_id,
        data_value,
        create_time,
        update_time,
        creator,
        tenant_key)

        <foreach collection="collection" item="item" separator="union all">
            select
            #{item.employeeId,jdbcType=DOUBLE},
            #{item.attendQuoteId,jdbcType=DOUBLE},
            #{item.attendQuoteDataId,jdbcType=DOUBLE},
            #{item.attendQuoteFieldId,jdbcType=DOUBLE},
            #{item.dataValue,jdbcType=VARCHAR},
            #{item.createTime,jdbcType=DATE},
            #{item.updateTime,jdbcType=DATE},
            #{item.creator,jdbcType=DOUBLE},
            #{item.tenantKey,jdbcType=VARCHAR}
            from dual
        </foreach>
    </insert>
    <insert id="insertData" databaseId="sqlserver">
        <foreach collection="collection" item="item" separator=";">
        INSERT INTO hrsa_attend_quote_data_value(
        employee_id,
        attend_quote_id,
        attend_quote_data_id,
        attend_quote_field_id,
        data_value,
        create_time,
        update_time,
        creator,
        tenant_key)
        VALUES
            (
            #{item.employeeId},
            #{item.attendQuoteId},
            #{item.attendQuoteDataId},
            #{item.attendQuoteFieldId},
            #{item.dataValue},
            #{item.createTime},
            #{item.updateTime},
            #{item.creator},
            #{item.tenantKey}
            )
        </foreach>
    </insert>

    <!-- 查询全部 -->
    <select id="listSome" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_attend_quote_data_value t
        WHERE delete_type = 0
        <if test="param.attendQuoteId != null and param.attendQuoteId != ''">
            AND attend_quote_id = #{param.attendQuoteId}
        </if>
        <if test="param.employeeIds != null and param.employeeIds.size() > 0">
            AND employee_id IN
            <foreach collection="param.employeeIds" open="(" item="employeeId" separator="," close=")">
                #{employeeId}
            </foreach>
        </if>
    </select>

    <update id="deleteByAttendIds">
        UPDATE hrsa_attend_quote_data_value
        SET delete_type = 1
        WHERE delete_type = 0
        AND attend_quote_id IN
        <foreach collection="attendIds" open="(" item="attendId" separator="," close=")">
            #{attendId}
        </foreach>
    </update>


</mapper>