<?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.PushRecordMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.push.po.PushRecordPO">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="acct_record_id" property="acctRecordId"/>
        <result column="setting_id" property="settingId"/>
        <result column="mode_id" property="modeId"/>
        <result column="table_name" property="tableName"/>
        <result column="status" property="status"/>
        <result column="type" property="type"/>
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="update_time" property="updateTime"/>
        <result column="fail_reason" property="failReason"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        acct_record_id
        , t.mode_id
        , t.table_name
        , t.create_time
        , t.creator
        , t.delete_type
        , t.id
        , t.name
        , t.setting_id
        , t.status
        , t.tenant_key
        , t.type
        , t.update_time
        , t.fail_reason
        , t.start_time
        , t.end_time
    </sql>

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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.push.po.PushRecordPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_push_record t
        WHERE delete_type = 0
        <if test="acctRecordId != null">
            AND acct_record_id = #{acctRecordId}
        </if>
        <if test="modeId != null">
            AND mode_id = #{modeId}
        </if>
        <if test="tableName != null">
            AND table_name = #{tableName}
        </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="id != null">
            AND id = #{id}
        </if>
        <if test="name != null">
            AND name = #{name}
        </if>
        <if test="settingId != null">
            AND setting_id = #{settingId}
        </if>
        <if test="status != null">
            AND status = #{status}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="type != null">
            AND type = #{type}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        <if test="failReason != null">
            AND fail_reason = #{failReason}
        </if>
        <if test="startTime != null">
            AND start_time = #{startTime}
        </if>
        <if test="endTime != null">
            AND end_time = #{endTime}
        </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>


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

            <if test="modeId != null">
                mode_id,
            </if>
            <if test="tableName != null">
                table_name,
            </if>
            <if test="acctRecordId != null">
                acct_record_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="settingId != null">
                setting_id,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="type != null">
                type,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="failReason != null">
                fail_reason,
            </if>
            <if test="startTime != null">
                start_time,
            </if>
            <if test="endTime != null">
                end_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="modeId != null">
                #{modeId},
            </if>
            <if test="tableName != null">
                #{tableName},
            </if>
            <if test="acctRecordId != null">
                #{acctRecordId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="settingId != null">
                #{settingId},
            </if>
            <if test="status != null">
                #{status},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="type != null">
                #{type},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="failReason != null">
                #{failReason},
            </if>
            <if test="startTime != null">
                #{startTime},
            </if>
            <if test="endTime != null">
                #{endTime},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.push.po.PushRecordPO">
        UPDATE hrsa_push_record
        <set>
            mode_id=#{modeId},
            table_name=#{tableName},
            acct_record_id=#{acctRecordId},
            create_time=#{createTime},
            creator=#{creator},
            delete_type=#{deleteType},
            name=#{name},
            setting_id=#{settingId},
            status=#{status},
            tenant_key=#{tenantKey},
            type=#{type},
            update_time=#{updateTime},
            fail_reason=#{failReason},
            start_time=#{startTime},
            end_time=#{endTime},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.push.po.PushRecordPO">
        UPDATE hrsa_push_record
        <set>
            <if test="modeId != null">
                mode_id=#{modeId},
            </if>
            <if test="tableName != null">
                table_name=#{tableName},
            </if>
            <if test="acctRecordId != null">
                acct_record_id=#{acctRecordId},
            </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="name != null">
                name=#{name},
            </if>
            <if test="settingId != null">
                setting_id=#{settingId},
            </if>
            <if test="status != null">
                status=#{status},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
            <if test="type != null">
                type=#{type},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="failReason != null">
                fail_reason=#{failReason},
            </if>
            <if test="startTime != null">
                start_time=#{startTime},
            </if>
            <if test="endTime != null">
                end_time=#{endTime},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


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

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

    <select id="countBeforeBatch" resultType="int">
        SELECT count(0)
        FROM hrsa_push_record t
        WHERE delete_type = 0
          and status <![CDATA[ < ]]> 3
    </select>

</mapper>