<?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.AttendQuoteDataMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.datacollection.po.AttendQuoteDataPO">
        <result column="id" property="id"/>
        <result column="employee_id" property="employeeId"/>
        <result column="attend_quote_id" property="attendQuoteId"/>
        <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.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 t
        WHERE delete_type = 0
    </select>

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

    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.datacollection.po.AttendQuoteDataPO">
        INSERT INTO hrsa_attend_quote_data
        <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="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="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.AttendQuoteDataPO">
        UPDATE hrsa_attend_quote_data
        <set>
            employee_id=#{employeeId},
            attend_quote_id=#{attendQuoteId},
            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.AttendQuoteDataPO">
        UPDATE hrsa_attend_quote_data
        <set>
            <if test="employeeId != null">
                employee_id=#{employeeId},
            </if>
            <if test="attendQuoteId != null">
                attend_quote_id=#{attendQuoteId},
            </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>



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


    <sql id="attendQuoteDataColumn">
        t1.id,
        t1.employee_id,
        t1.attend_quote_id,
        e.lastname as username,
        d.departmentname AS departmentName,
        e.mobile,
        e.workcode as job_num,
        e.certificatenum as idNo
    </sql>

    <sql id="paramSql">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <!-- 关键字（姓名、部门、工号 -->
        <if test="param.keyword != null and param.keyword != ''">
            AND
            (
            e.lastname like CONCAT('%',#{param.keyword},'%')
            OR d.departmentname like CONCAT('%',#{param.keyword},'%')
            OR e.workcode like CONCAT('%',#{param.keyword},'%')
            OR e.mobile like CONCAT('%',#{param.keyword},'%')
            )
        </if>
        <if test="param.attendQuoteId != null">
            AND t1.attend_quote_id = #{param.attendQuoteId}
        </if>
        <if test="param.unAccountingIds != null and param.unAccountingIds.size()>0">
            AND t1.attend_quote_id IN
            <foreach collection="param.unAccountingIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

    </sql>
    <sql id="paramSql" databaseId="oracle">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.keyword != null and param.keyword != ''">
            AND
            (
            e.lastname  like '%'||#{param.keyword}||'%'
            OR d.departmentname like '%'||#{param.keyword}||'%'
            OR e.workcode like '%'||#{param.keyword}||'%'
            OR e.mobile like '%'||#{param.keyword}||'%'
            )
        </if>
        <if test="param.attendQuoteId != null">
            AND t1.attend_quote_id = #{param.attendQuoteId}
        </if>
        <if test="param.unAccountingIds != null and param.unAccountingIds.size()>0">
            AND t1.attend_quote_id IN
            <foreach collection="param.unAccountingIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </sql>
    <sql id="paramSql" databaseId="sqlserver">
        <if test="param.ids != null and param.ids.size()>0">
            AND t1.id IN
            <foreach collection="param.ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>

        <if test="param.keyword != null and param.keyword != ''">
            AND
            (
            e.lastname like '%'+#{param.keyword}+'%'
            OR d.departmentname like '%'+#{param.keyword}+'%'
            OR e.workcode like '%'+#{param.keyword}+'%'
            OR e.mobile like '%'+#{param.keyword}+'%'
            )
        </if>
        <if test="param.attendQuoteId != null">
            AND t1.attend_quote_id = #{param.attendQuoteId}
        </if>
        <if test="param.unAccountingIds != null and param.unAccountingIds.size()>0">
            AND t1.attend_quote_id IN
            <foreach collection="param.unAccountingIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </sql>

    <select id="list" resultType="com.engine.salary.entity.datacollection.dto.AttendQuoteDataBaseDTO">
        SELECT
        <include refid="attendQuoteDataColumn"/>
        FROM
        hrsa_attend_quote_data t1
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
        WHERE
         t1.delete_type = 0
        AND e.status not in (7)

        <include refid="paramSql"/>
        <!-- 排序 -->
        <if test="param.orderRule != null">
            ORDER BY  ${param.orderRule.orderRule}  ${param.orderRule.ascOrDesc}
        </if>
    </select>
    <select id="list" resultType="com.engine.salary.entity.datacollection.dto.AttendQuoteDataBaseDTO" databaseId="oracle">
        SELECT
        <include refid="attendQuoteDataColumn"/>
        FROM
        hrsa_attend_quote_data t1
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
        WHERE
        t1.delete_type = 0
        AND e.status not in (7)

        <include refid="paramSql"/>
        <!-- 排序 -->
        <if test="param.orderRule != null">
            ORDER BY  ${param.orderRule.orderRule}  ${param.orderRule.ascOrDesc}
        </if>
    </select>
    <select id="list" resultType="com.engine.salary.entity.datacollection.dto.AttendQuoteDataBaseDTO" databaseId="sqlserver">
        SELECT
        <include refid="attendQuoteDataColumn"/>
        FROM
        hrsa_attend_quote_data t1
        LEFT JOIN hrmresource e ON e.id = t1.employee_id
        LEFT JOIN hrmdepartment d ON d.id = e.departmentid
        LEFT JOIN hrmsubcompany c ON c.id = e.subcompanyid1
        WHERE
        t1.delete_type = 0
        AND e.status not in (7)

        <include refid="paramSql"/>
        <!-- 排序 -->
        <if test="param.orderRule != null">
            ORDER BY  ${param.orderRule.orderRule}  ${param.orderRule.ascOrDesc}
        </if>
    </select>

    <update id="deleteByAttendQuoteIds">
        UPDATE hrsa_attend_quote_data
        SET delete_type = 1
        WHERE  delete_type = 0
        AND attend_quote_id IN
        <foreach collection="attendQuoteIds" open="(" item="attendQuoteId" separator="," close=")">
            #{attendQuoteId}
        </foreach>
    </update>

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

        <foreach collection="collection" item="item" separator="union all">
            select
            #{item.id,jdbcType=DOUBLE},
            #{item.employeeId,jdbcType=DOUBLE},
            #{item.attendQuoteId,jdbcType=DOUBLE},
            #{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(
        id,
        employee_id,
        attend_quote_id,
        create_time,
        update_time,
        creator,
        tenant_key)
        VALUES
            (
            #{item.id},
            #{item.employeeId},
            #{item.attendQuoteId},
            #{item.createTime},
            #{item.updateTime},
            #{item.creator},
            #{item.tenantKey}
            )
        </foreach>
    </insert>


    <select id="listSome" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_attend_quote_data t
        WHERE delete_type = 0
        <if test="param.unAccountingIds != null and param.unAccountingIds.size()>0">
            AND t.attend_quote_id IN
            <foreach collection="param.unAccountingIds" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

</mapper>