<?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.push.PushRecordDetailMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.push.po.PushRecordDetailPO">
        <result column="acct_emp_id" property="acctEmpId"/>
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="formula" property="formula"/>
        <result column="id" property="id"/>
        <result column="record_id" property="recordId"/>
        <result column="status" property="status"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="update_time" property="updateTime"/>
        <result column="fail_reason" property="failReason"/>
        <result column="data_id" property="dataId"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        acct_emp_id
        , t.create_time
        , t.creator
        , t.delete_type
        , t.formula
        , t.id
        , t.record_id
        , t.status
        , t.tenant_key
        , t.update_time
        , t.fail_reason
        , t.data_id
    </sql>

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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.push.po.PushRecordDetailPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_push_record_detail t
        WHERE delete_type = 0
        <if test="acctEmpId != null">
            AND acct_emp_id = #{acctEmpId}
        </if>
        <if test="createTime != null">
            AND create_time = #{createTime}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="formula != null">
            AND formula = #{formula}
        </if>
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="recordId != null">
            AND record_id = #{recordId}
        </if>
        <if test="status != null">
            AND status = #{status}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        <if test="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>

    <select id="listDTO" resultType="com.engine.salary.entity.push.dto.PushRecordDetailDTO" parameterType="com.engine.salary.entity.push.dto.PushRecordDetailDTO">
        SELECT
        t.acct_emp_id
        , t.create_time
        , t.creator
        , t.delete_type
        , t.formula
        , t.id
        , t.record_id
        , t.status
        , t.tenant_key
        , t.update_time
        , t.fail_reason as failReason
        , t.data_id as dataId
        , e.LASTNAME as username
        FROM hrsa_push_record_detail t
        left join hrsa_salary_acct_emp emp
        on t.acct_emp_id=emp.id
        left join hrsa_salary_sob sob
        on emp.salary_sob_id = sob.id
        left join hrmresource e
        on emp.employee_id=e.id

        WHERE t.delete_type = 0
          and emp.delete_type = 0
          and sob.delete_type = 0

        <if test="acctEmpId != null">
            AND t.acct_emp_id = #{acctEmpId}
        </if>

        <if test="id != null">
            AND t.id = #{id}
        </if>
        <if test="recordId != null">
            AND t.record_id = #{recordId}
        </if>
        <if test="status != null">
            AND t.status = #{status}
        </if>





        ORDER BY id DESC
    </select>


    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.push.po.PushRecordDetailPO">
        INSERT INTO hrsa_push_record_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="acctEmpId != null">
                acct_emp_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="formula != null">
                formula,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="recordId != null">
                record_id,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="failReason != null">
                fail_reason,
            </if>
            <if test="dataId != null">
                data_id,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="acctEmpId != null">
                #{acctEmpId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="formula != null">
                #{formula},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="recordId != null">
                #{recordId},
            </if>
            <if test="status != null">
                #{status},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="failReason != null">
                #{failReason},
            </if>
            <if test="dataId != null">
                #{dataId},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.push.po.PushRecordDetailPO">
        UPDATE hrsa_push_record_detail
        <set>
            acct_emp_id=#{acctEmpId},
            create_time=#{createTime},
            creator=#{creator},
            delete_type=#{deleteType},
            formula=#{formula},
            record_id=#{recordId},
            status=#{status},
            tenant_key=#{tenantKey},
            update_time=#{updateTime},
            fail_reason=#{failReason},
            data_id=#{dataId},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.push.po.PushRecordDetailPO">
        UPDATE hrsa_push_record_detail
        <set>
            <if test="acctEmpId != null">
                acct_emp_id=#{acctEmpId},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </if>
            <if test="formula != null">
                formula=#{formula},
            </if>
            <if test="recordId != null">
                record_id=#{recordId},
            </if>
            <if test="status != null">
                status=#{status},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="failReason != null">
                fail_reason=#{failReason},
            </if>
            <if test="dataId != null">
                data_id=#{dataId},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete">
        UPDATE hrsa_push_record_detail
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>

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

    <delete id="deleteByRecordId">
        UPDATE hrsa_push_record_detail
        SET delete_type=1
        WHERE   record_id=#{recordId}
          AND delete_type = 0
    </delete>

</mapper>