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

    <resultMap id="BaseResultMap" type="com.sundot.airport.ledger.domain.LedgerExamScore">
        <id property="id" column="id" />
        <result property="examDate" column="exam_date" />
        <result property="deptName" column="dept_name" />
        <result property="deptId" column="dept_id" />
        <result property="teamName" column="team_name" />
        <result property="teamId" column="team_id" />
        <result property="groupName" column="group_name" />
        <result property="groupId" column="group_id" />
        <result property="personName" column="person_name" />
        <result property="personId" column="person_id" />
        <result property="examCategory" column="exam_category" />
        <result property="examPeriod" column="exam_period" />
        <result property="theoryScore" column="theory_score" />
        <result property="imageScore"  column="image_score"  />
        <result property="importBatch" column="import_batch" />
        <result property="sourceType" column="source_type" />
        <result property="syncFlag" column="sync_flag" />
        <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, exam_date, dept_name, dept_id, team_name, team_id, group_name, group_id,
               person_name, person_id, exam_category, exam_period, theory_score, image_score,
               import_batch, source_type, sync_flag, create_by, create_time, update_by, update_time
        FROM ledger_exam_score
        WHERE del_flag = '0'
    </sql>

    <select id="selectList" parameterType="com.sundot.airport.ledger.domain.LedgerExamScore" 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="syncFlag != null and syncFlag != ''">AND sync_flag = #{syncFlag}</if>
        <if test="params != null and params.beginTime != null and params.beginTime != ''">
            AND exam_date &gt;= #{params.beginTime}
        </if>
        <if test="params != null and params.endTime != null and params.endTime != ''">
            AND exam_date &lt;= #{params.endTime}
        </if>
        ORDER BY id DESC
    </select>

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