<?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.ScoreEventMapper">

    <resultMap id="ScoreEventResult" type="com.sundot.airport.ledger.domain.ScoreEvent">
        <id     property="id"            column="id"/>
        <result property="dimensionId"   column="dimension_id"/>
        <result property="dimensionName" column="dimension_name"/>
        <result property="indicatorId"   column="indicator_id"/>
        <result property="level2Name"    column="level2_name"/>
        <result property="level3Name"    column="level3_name"/>
        <result property="level4Name"    column="level4_name"/>
        <result property="eventTime"     column="event_time"/>
        <result property="location"      column="location"/>
        <result property="personId"    column="person_id"/>
        <result property="deptId"    column="dept_id"/>
        <result property="teamId"    column="team_id"/>
        <result property="groupId"    column="group_id"/>
        <result property="personName"    column="person_name"/>
        <result property="deptName"      column="dept_name"/>
        <result property="teamName"      column="team_name"/>
        <result property="groupName"     column="group_name"/>
        <result property="scoreValue"    column="score_value"/>
        <result property="cascadeScore"  column="cascade_score"/>
        <result property="totalScore"    column="total_score"/>
        <result property="eventDesc"     column="event_desc"/>
        <result property="sourceType"    column="source_type"/>
        <result property="sourceLedger"  column="source_ledger"/>
        <result property="importBatch"   column="import_batch"/>
        <result property="evidenceFile"  column="evidence_file"/>
        <result property="org"  column="org"/>
        <result property="remark"        column="remark"/>
        <result property="createBy"      column="create_by"/>
        <result property="createTime"    column="create_time"/>
        <result property="updateBy"      column="update_by"/>
        <result property="updateTime"    column="update_time"/>
    </resultMap>

    <sql id="selectVo">
        SELECT id, dimension_id, dimension_name, indicator_id,
               level2_name, level3_name, level4_name,
               event_time, location, person_id, dept_id, team_id, group_id, person_name, dept_name, team_name, group_name,
               score_value, cascade_score, total_score, event_desc,
               source_type, source_ledger, import_batch, evidence_file, org, remark,
               create_by, create_time, update_by, update_time
        FROM score_event
        WHERE del_flag = '0'
    </sql>

    <select id="selectList" parameterType="com.sundot.airport.ledger.domain.ScoreEvent"
            resultMap="ScoreEventResult">
        <include refid="selectVo"/>
        <if test="dimensionId != null">AND dimension_id = #{dimensionId}</if>
        <if test="personId != null">person_id = #{personId}</if>
        <if test="deptId != null">dept_id = #{deptId}</if>
        <if test="teamId != null">team_id = #{teamId}</if>
        <if test="groupId != null">group_id = #{groupId}</if>
        <if test="org != null and org != ''">org = #{org}</if>
        <if test="personName != null and personName != ''">AND person_name LIKE CONCAT('%', #{personName}, '%')</if>
        <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="sourceType != null and sourceType != ''">AND source_type = #{sourceType}</if>
        <if test="level2Name != null and level2Name != ''">AND level2_name LIKE CONCAT('%', #{level2Name}, '%')</if>
        <if test="params != null and params.beginTime != null and params.beginTime != ''">
            AND event_time &gt;= #{params.beginTime}
        </if>
        <if test="params != null and params.endTime != null and params.endTime != ''">
            AND event_time &lt;= #{params.endTime}
        </if>
        ORDER BY event_time DESC, id DESC
    </select>

</mapper>
