<?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.sundot.airport.ledger.mapper.LedgerRewardPenaltyMapper">

    <resultMap id="BaseResultMap" type="com.sundot.airport.ledger.domain.LedgerRewardPenalty">
        <id property="id" column="id" />
        <result property="recordDate" column="record_date" />
        <result property="deptName" column="dept_name" />
        <result property="teamName" column="team_name" />
        <result property="personName" column="person_name" />
        <result property="personUserId" column="person_user_id" />
        <result property="type" column="type" />
        <result property="eventDesc" column="event_desc" />
        <result property="scoreChange" column="score_change" />
        <result property="scoreDimension" column="score_dimension" />
        <result property="evidenceFile" column="evidence_file" />
        <result property="remark" column="remark" />
        <result property="importBatch" column="import_batch" />
        <result property="sourceType" column="source_type" />
        <result property="createBy"   column="create_by"   />
        <result property="createTime" column="create_time" />
        <result property="updateBy"   column="update_by"   />
        <result property="updateTime" column="update_time" />
        <result property="syncFlag" column="sync_flag" />
    </resultMap>

    <sql id="selectVo">
        SELECT id, record_date,dept_name,team_name,person_name,person_user_id,type,event_desc,score_change,score_dimension,evidence_file,remark, import_batch, source_type, create_by, create_time, update_by, update_time, sync_flag
        FROM ledger_reward_penalty
        WHERE del_flag = '0'
    </sql>

    <select id="selectList" parameterType="com.sundot.airport.ledger.domain.LedgerRewardPenalty" resultMap="BaseResultMap">
        <include refid="selectVo"/>
        <if test="deptName != null and deptName != ''">AND dept_name LIKE CONCAT('%', #{deptName}, '%')</if>
        <if test="teamName != null and teamName != ''">AND team_name LIKE CONCAT('%', #{teamName}, '%')</if>
        <if test="personName != null and personName != ''">AND person_name LIKE CONCAT('%', #{personName}, '%')</if>
        <if test="syncFlag != null and syncFlag != ''">AND sync_flag = #{syncFlag}</if>
        <if test="params != null and params.beginTime != null and params.beginTime != ''">
            AND (record_date &gt;= #{params.beginTime} OR approve_date &gt;= #{params.beginTime} OR exam_date &gt;= #{params.beginTime})
        </if>
        <if test="params != null and params.endTime != null and params.endTime != ''">
            AND (record_date &lt;= #{params.endTime} OR approve_date &lt;= #{params.endTime} OR exam_date &lt;= #{params.endTime})
        </if>
        ORDER BY id DESC
    </select>

    <update id="updateSyncFlag">
        update ledger_reward_penalty
        set sync_flag = '1'
        where sync_flag = '0'
    </update>
</mapper>