<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.business.dao.WorkScheduleAttendanceDAO">
    <resultMap id="WorkScheduleAttendanceMap"
               type="com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance">
        <id property="id" column="id_"/>
        <result property="personScheduleId" column="person_schedule_id"/>
        <result property="workShiftId" column="work_shift_id"/>
        <result property="attendanceDate" column="attendance_date"/>
        <result property="classify" column="classify_"/>
        <result property="personId" column="person_id"/>
        <result property="result" column="result_"/>
        <result property="temperature" column="temperature_"/>
        <result property="recordTime" column="record_time"/>
        <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="delFlag" column="del_flag"/>
        <result property="workStatus" column="work_status"/>
        <result property="remark" column="remark_"/>
        <result property="workShiftNumber" column="work_shift_number"/>
        <result property="supplementWorkPersonId" column="supplement_work_person_id"/>
        <result property="lateLeaveMinute" column="late_leave_minute"/>
        <result property="coefficientDays" column="coefficient_days"/>
        <result property="workOverPersonId" column="work_over_person_id"/>
        <result property="offsetMinute" column="offset_minute"/>
        <result property="workMinute" column="work_minute"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into business_work_schedule_attendance
	    (id_,person_schedule_id,work_shift_id,attendance_date,classify_,person_id,result_,temperature_,
	    record_time,create_by,create_time,update_by,update_time,del_flag,work_status,remark_,supplement_work_person_id,
	    late_leave_minute,work_over_person_id,offset_minute,work_minute)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{personScheduleId,jdbcType=VARCHAR}
            ,#{workShiftId,jdbcType=VARCHAR}
            ,#{attendanceDate,jdbcType=VARCHAR}
            ,#{classify,jdbcType=VARCHAR}
            ,#{personId,jdbcType= NUMERIC }
            ,#{result,jdbcType=VARCHAR}
            ,#{temperature,jdbcType= NUMERIC }
            ,#{recordTime,jdbcType= TIMESTAMP }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{workStatus,jdbcType=VARCHAR}
            ,#{remark,jdbcType=VARCHAR}
            ,#{supplementWorkPersonId,jdbcType=VARCHAR}
            ,#{lateLeaveMinute,jdbcType=NUMERIC}
            ,#{workOverPersonId,jdbcType=VARCHAR}
            ,#{offsetMinute,jdbcType=NUMERIC}
            ,#{workMinute,jdbcType=NUMERIC}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from business_work_schedule_attendance where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance">
        update business_work_schedule_attendance
        <set>
            <if test="personScheduleId!=null">
                person_schedule_id=#{personScheduleId,jdbcType=VARCHAR},
            </if>
            <if test="workShiftId!=null">
                work_shift_id=#{workShiftId,jdbcType=VARCHAR},
            </if>
            <if test="attendanceDate!=null">
                attendance_date=#{attendanceDate,jdbcType=VARCHAR},
            </if>
            <if test="classify!=null">
                classify_=#{classify,jdbcType=VARCHAR},
            </if>
            <if test="personId!=null">
                person_id=#{personId,jdbcType= NUMERIC },
            </if>
            <if test="result!=null">
                result_=#{result,jdbcType=VARCHAR},
            </if>
            <if test="temperature!=null">
                temperature_=#{temperature,jdbcType= NUMERIC },
            </if>
            <if test="recordTime!=null">
                record_time=#{recordTime,jdbcType= TIMESTAMP },
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="workStatus!=null">
                work_status=#{workStatus,jdbcType=VARCHAR},
            </if>
            <if test="remark!=null">
                remark_=#{remark,jdbcType=VARCHAR},
            </if>
            <if test="supplementWorkPersonId!=null">
                supplement_work_person_id=#{supplementWorkPersonId,jdbcType=VARCHAR},
            </if>
            <if test="lateLeaveMinute!=null">
                late_leave_minute=#{lateLeaveMinute,jdbcType=NUMERIC},
            </if>
            <if test="workOverPersonId!=null">
                work_over_person_id=#{workOverPersonId, jdbcType=NUMERIC},
            </if>
            <if test="offsetMinute!=null">
                offset_minute=#{offsetMinute,jdbcType=NUMERIC},
            </if>
            <if test="workMinute!=null">
                work_minute=#{workMinute,jdbcType=NUMERIC},
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="WorkScheduleAttendanceMap">
        select * from business_work_schedule_attendance where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from business_work_schedule_attendance where id_=#{0}
    </select>
    <select id="list" resultMap="WorkScheduleAttendanceMap">
        select * from business_work_schedule_attendance
    </select>
    <select id="search" parameterType="hashmap" resultMap="WorkScheduleAttendanceMap">
        <![CDATA[
			SELECT
                a.*
            FROM
                business_work_schedule_attendance a
		]]>
        <where>
            a.del_flag = 0
            <if test="searchParams.personId != null">
                and a.person_id = #{searchParams.personId}
            </if>
            <if test="searchParams.startMonth != null">
                and ( a.attendance_date LIKE #{searchParams.startMonth}
                or a.attendance_date LIKE #{searchParams.endMonth} )
            </if>
            <if test="searchParams.attendanceDateLike != null">
              and a.attendance_date LIKE #{searchParams.attendanceDateLike}

            </if>
            <if test="searchParams.result != null">
                and a.result_ = #{searchParams.result}
            </if>
            <if test="searchParams.workStatus != null">
                and a.work_status = #{searchParams.workStatus}
            </if>
            <if test="searchParams.attendanceDate != null">
                and a.attendance_date = #{searchParams.attendanceDate}
            </if>
            <if test="searchParams.personInfoList != null ">
                <foreach collection="searchParams.personInfoList" item="item" index="index" open="and a.person_id in(" separator="," close=")">
                    #{item.id}
                </foreach>
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findByPersonScheduleIdAndClassify" resultMap="WorkScheduleAttendanceMap">
        select * from business_work_schedule_attendance
        where person_schedule_id=#{personScheduleId}
        and work_shift_id = #{workShiftId}
        and classify_=#{classify}
        and del_flag=0
        order by record_time desc
    </select>
    <select id="findByScheduleAttendanceId" resultMap="WorkScheduleAttendanceMap">
        select * from business_work_schedule_attendance
        where person_schedule_id=#{personScheduleId}
        and work_shift_id = #{workShiftId}
        and classify_=#{classify}
        and del_flag=0
        order by create_time desc
    </select>
    <select id="findAttendanceDateByPersonAndMonths" resultType="date">
        SELECT DISTINCT
            attendance_date
        FROM
            business_work_schedule_attendance
        WHERE
            del_flag = 0
            AND person_id = #{personId}
            <foreach collection="months" index="index" item="month" open="and (" separator="or" close=")">
                attendance_date like #{month}
            </foreach>
        ORDER BY
            attendance_date
    </select>
    <select id="findByPersonIdAndShiftIdAndAttendanceDate" resultMap="WorkScheduleAttendanceMap">
        SELECT
            a.*,
            b.number_ as work_shift_number
        FROM
            business_work_schedule_attendance a
            LEFT JOIN base_work_shift_info b ON b.id_ = a.work_shift_id
        WHERE
            a.del_flag = 0
            AND a.person_id = #{personId}
            AND a.work_shift_id = #{shiftId}
            AND a.attendance_date = #{attendanceDate}
        ORDER BY
            a.attendance_date,
            b.number_ + 0,
            a.record_time
    </select>
    <select id="findFullAttendanceCount" resultType="int">
        SELECT
            count(*)
        FROM
            business_work_schedule_attendance
        WHERE
            attendance_date NOT IN (
                SELECT DISTINCT
                    attendance_date
                FROM
                    business_work_schedule_attendance
                WHERE
                    del_flag = 0
                    AND person_id = #{personId}
                    AND result_ != '1'
                    <foreach collection="months" index="index" item="month" open="and (" separator="or" close=")">
                        attendance_date like #{month}
                    </foreach>
            )
            AND del_flag = 0
            AND person_id = #{personId}
            <foreach collection="months" index="index" item="month" open="and (" separator="or" close=")">
                attendance_date like #{month}
            </foreach>
        ORDER BY
            attendance_date,
            record_time
    </select>
    <select id="findCountByParams" resultType="int">
        SELECT
        count( attendance_date )
        FROM
        business_work_schedule_attendance
        WHERE
        del_flag = 0
        AND person_id = #{personId}
        <![CDATA[
            and attendance_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
            and attendance_date <= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
        ]]>
        <if test="searchParams.result != null">
            AND result_ = #{searchParams.result}
        </if>
        <if test="searchParams.workStatus != null">
            AND work_status = #{searchParams.workStatus}
        </if>
        <if test="searchParams.classify != null">
            AND classify_ = #{searchParams.classify}
        </if>
        <if test="searchParams.noResult != null">
            AND result_ != #{searchParams.noResult}
        </if>
        <if test="searchParams.noWorkStatus != null">
            AND work_status != #{searchParams.noWorkStatus}
        </if>
        <if test="searchParams.noWorkStatus7 != null">
            AND work_status != #{searchParams.noWorkStatus7}
        </if>
    </select>

    <select id="findByPersonIdShiftIdAttendanceDateClassifyResult" resultMap="WorkScheduleAttendanceMap">
        <![CDATA[
        select * from business_work_schedule_attendance
          ]]>
        <where>
            del_flag = 0
            <if test="personId != null">
                and person_id = #{personId}
            </if>
            <if test="workShiftId != null">
                and work_shift_id = #{workShiftId}
            </if>
            <if test="date != null">
                and attendance_date = #{date}
            </if>
            <if test="classify != null">
                and classify_ = #{classify}
            </if>
            <if test="result != null">
                and result_ = #{result}
            </if>
        </where>
        limit 1
    </select>

    <select id="findSumLMinuteByParams" resultType="double">
        SELECT COALESCE
        ( sum( late_leave_minute ), 0 )
        FROM
            business_work_schedule_attendance
        WHERE
        del_flag = 0
        AND person_id = #{personId}
        <![CDATA[
            and attendance_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
            and attendance_date <= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
        ]]>
        <if test="searchParams.result != null">
            AND result_ = #{searchParams.result}
        </if>
        <if test="searchParams.workStatus != null">
            AND work_status = #{searchParams.workStatus}
        </if>
        <if test="searchParams.classify != null">
            AND classify_ = #{searchParams.classify}
        </if>
        <if test="searchParams.noResult != null">
            AND result_ != #{searchParams.noResult}
        </if>
    </select>

    <select id="findByPersonIdRecordTimeResult" resultMap="WorkScheduleAttendanceMap">
        <![CDATA[
        select * from business_work_schedule_attendance
        ]]>
        where del_flag = 0
        and person_id = #{personId}
        and record_time = #{recordTime}
        and result_ = #{result}
        limit 1
    </select>

    <select id="findByPersonIdAttendanceDateResult" resultMap="WorkScheduleAttendanceMap">
        <![CDATA[
        select * from business_work_schedule_attendance
        ]]>
        where del_flag = 0
        and person_id = #{personId}
        and attendance_date = #{attendanceDate}
        and result_ = #{result}
        order by record_time asc
    </select>

    <select id="findPersonIdListRecordTimeResult" resultType="java.lang.Long">
        select DISTINCT(a.person_id) from business_work_schedule_attendance a
        where a.attendance_date = #{attendanceDate}
        and a.result_ = #{result}
    </select>
    <select id="findGroupByPersonIdAndMonthsAndResult" resultMap="WorkScheduleAttendanceMap">
        SELECT
            a.*,
            b.days_ as coefficient_days
        FROM
            business_work_schedule_attendance a
            left join base_work_shift_info b on a.work_shift_id = b.id_
        WHERE
            a.del_flag = 0
            AND a.person_id = #{personId}
            <if test="searchParams.totalResult != null">
                AND (
                a.result_ = #{searchParams.totalResult}
                OR a.result_ = 2  OR a.result_ = 3
                )
            </if>
            <if test="searchParams.result != null">
                AND a.result_ = #{searchParams.result}
            </if>
            <if test="searchParams.noWorkStatus != null">
                AND a.work_status != #{searchParams.noWorkStatus}
            </if>
            <if test="searchParams.noWorkStatus4 != null">
                AND a.work_status != #{searchParams.noWorkStatus4}
            </if>
            <if test="searchParams.workStatus != null">
                AND a.work_status = #{searchParams.workStatus}
            </if>
            <![CDATA[
            and attendance_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
            and attendance_date <= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
            ]]>
        GROUP BY
            a.work_shift_id,
            a.attendance_date
        HAVING
            count( a.result_ ) > 1
        ORDER BY
            a.attendance_date,
            a.record_time
    </select>

    <select id="findNotGroupByPersonIdAndMonthsAndResult" resultMap="WorkScheduleAttendanceMap">
        SELECT
        a.*,
        b.days_ as coefficient_days
        FROM
        business_work_schedule_attendance a
        left join base_work_shift_info b on a.work_shift_id = b.id_
        WHERE
        a.del_flag = 0
        AND a.person_id = #{personId}
        <if test="searchParams.totalResult != null">
            AND (
            a.result_ = #{searchParams.totalResult}
            OR a.result_ = 2  OR a.result_ = 3
            )
        </if>
        <if test="searchParams.result != null">
            AND a.result_ = #{searchParams.result}
        </if>
        <if test="searchParams.noWorkStatus != null">
            AND a.work_status != #{searchParams.noWorkStatus}
        </if>
        <if test="searchParams.noWorkStatus4 != null">
            AND a.work_status != #{searchParams.noWorkStatus4}
        </if>
        <if test="searchParams.workStatus != null">
            AND a.work_status = #{searchParams.workStatus}
        </if>
        <![CDATA[
            and attendance_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
            and attendance_date <= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
            ]]>
        GROUP BY
        a.work_shift_id,
        a.attendance_date
        HAVING
        count( a.result_ ) = 1
        ORDER BY
        a.attendance_date,
        a.record_time
    </select>

    <select id="findAbsenteeismGroupByPersonIdAndMonthsAndResult" resultMap="WorkScheduleAttendanceMap">
        SELECT
        a.*,
        b.days_ as coefficient_days
        FROM
        business_work_schedule_attendance a
        left join base_work_shift_info b on a.work_shift_id = b.id_
        WHERE
        a.del_flag = 0
        AND a.person_id = #{personId}
        <if test="searchParams.totalResult != null">
            AND (
            a.result_ = #{searchParams.totalResult}
            OR a.result_ = 2  OR a.result_ = 3
            )
        </if>
        <if test="searchParams.result != null">
            AND a.result_ = #{searchParams.result}
        </if>
        <if test="searchParams.noWorkStatus != null">
            AND a.work_status != #{searchParams.noWorkStatus}
        </if>
        <if test="searchParams.noWorkStatus4 != null">
            AND a.work_status != #{searchParams.noWorkStatus4}
        </if>
        <if test="searchParams.noWorkStatus7 != null">
            AND a.work_status != #{searchParams.noWorkStatus7}
        </if>
        <if test="searchParams.workStatus != null">
            AND a.work_status = #{searchParams.workStatus}
        </if>
        <![CDATA[
            and attendance_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
            and attendance_date <= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
            ]]>
        GROUP BY
        a.work_shift_id,
        a.attendance_date
        HAVING
        count( a.result_ ) > 0
        ORDER BY
        a.attendance_date,
        a.record_time
    </select>

    <select id="findShiftByPersonAndAttendanceDate" resultType="java.lang.String">
        select DISTINCT(a.work_shift_id) from business_work_schedule_attendance a
        where a.attendance_date = #{attendanceDate}
        and a.person_id = #{personId}
        and a.del_flag=0
    </select>

    <select id="findLastByPersonScheduleIdAndClassify" resultMap="WorkScheduleAttendanceMap">
        select * from business_work_schedule_attendance
        where person_schedule_id=#{personScheduleId}
        and work_shift_id = #{workShiftId}
        and classify_=#{classify}
        and del_flag=0
        order by record_time desc
        limit 1
    </select>
    <select id="findByPersonIdAndDate" resultMap="WorkScheduleAttendanceMap">
        <![CDATA[
            select * from business_work_schedule_attendance
        ]]>
        <where>
            del_flag = 0
            <if test="personId != null">
                and person_id = #{personId}
            </if>
            <if test="beginDate != null">
                and record_time >= #{beginDate}
            </if>
            <if test="endDate != null">
                <![CDATA[
                and record_time <= #{endDate}
                ]]>
            </if>
            <if test="result != null and result != ''">
                and result_ = #{result}
            </if>
            <if test="workStatus != null">
                and work_status = #{workStatus}
            </if>
        </where>
        order by record_time asc
    </select>
    <update id="deleteByPersonIdAndAttendanceDate">
        update business_work_schedule_attendance
        set del_flag=1,update_time=now()
        where person_id=#{personId}
        and attendance_date=#{attendanceDate}
        and del_flag=0
    </update>
    <update id="deleteByPersonIdAndAttendanceDateAndExcludeShiftId">
        update business_work_schedule_attendance
        set del_flag=1,update_time=now()
        where person_id=#{personId}
        and attendance_date=#{attendanceDate}
        and find_in_set(work_shift_id,#{shiftIds})=0
        and del_flag=0
    </update>
    <update id="deleteByPersonIdAndAttendanceDateAndExcludeSchedule">
        <![CDATA[
            update business_work_schedule_attendance
            set del_flag=1,update_time=now()
            where person_id=#{personId}
            and attendance_date=#{attendanceDate}
            and
            (
                person_schedule_id<>#{workPersonScheduling.id}
                or
                find_in_set(work_shift_id,#{workPersonScheduling.shiftIds})=0
            )
            and del_flag=0
        ]]>
    </update>
    <update id="updateScheduleByPersonIdAndAttendanceDate">
        <![CDATA[
            update business_work_schedule_attendance
            set
            person_schedule_id=#{personScheduleId},
            work_shift_id=#{workShiftId},
            update_time=now()
            where person_id=#{personId}
            and attendance_date=#{attendanceDate}
            and supplement_work_person_id is not null
            and del_flag=0
        ]]>
    </update>
    <update id="updateWorkMinute" parameterType="com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance">
        update business_work_schedule_attendance
        set work_minute=#{workMinute},update_time=#{updateTime}
        where id_=#{id}
    </update>
    <select id="numListSearch" resultMap="WorkScheduleAttendanceMap">
        <![CDATA[
			SELECT
                DISTINCT(a.person_id)
            FROM
                business_work_schedule_attendance a
		]]>
        <where>
            a.del_flag = 0
            <if test="searchParams.personId != null">
                and a.person_id = #{searchParams.personId}
            </if>
            <if test="searchParams.startMonth != null">
                and ( a.attendance_date LIKE #{searchParams.startMonth}
                or a.attendance_date LIKE #{searchParams.endMonth} )
            </if>
            <if test="searchParams.result != null">
                and a.result_ = #{searchParams.result}
            </if>
            <if test="searchParams.workStatus != null">
                and a.work_status = #{searchParams.workStatus}
            </if>
            <if test="searchParams.attendanceDate != null">
                and a.attendance_date = #{searchParams.attendanceDate}
            </if>
            <if test="searchParams.personInfoList != null ">
                <foreach collection="searchParams.personInfoList" item="item" index="index" open="and a.person_id in(" separator="," close=")">
                    #{item.id}
                </foreach>
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findHqWorkTimeByPersonIdAndSEDate" resultType="int">
        <![CDATA[
            SELECT
                TIMESTAMPDIFF(
                    MINUTE,
                    DATE_FORMAT( a.record_time, '%Y-%m-%d %H:%i' ),
                    CONCAT( date_format( a.record_time, '%Y-%m-%d ' ), b.work_time )
                )
            FROM
                business_work_schedule_attendance a
                LEFT JOIN base_work_shift_info b ON a.work_shift_id = b.id_
            WHERE
                a.person_id = #{personId}
                AND a.del_flag = 0
                and a.result_ != '0'
	            and a.work_status != '4'
                AND a.record_time >=#{startDate}
                AND a.record_time <=#{endDate}
                AND a.classify_ = '1'
        ]]>
    </select>
    <select id="findHqCloseTimeByPersonIdAndSEDate" resultType="int">
        <![CDATA[
            SELECT
                TIMESTAMPDIFF(
                    MINUTE,
                    CONCAT( date_format( a.record_time, '%Y-%m-%d ' ), b.closing_time ) ,
                    DATE_FORMAT( a.record_time, '%Y-%m-%d %H:%i' )
                )
            FROM
                business_work_schedule_attendance a
                LEFT JOIN base_work_shift_info b ON a.work_shift_id = b.id_
            WHERE
                a.person_id = #{personId}
                AND a.del_flag = 0
                and a.result_ != '0'
	            and a.work_status != '4'
                AND a.record_time >=#{startDate}
                AND a.record_time <=#{endDate}
                AND a.classify_ = '2'
        ]]>
    </select>
    <select id="findOneBySupplementWorkPersonId" resultMap="WorkScheduleAttendanceMap">
        select * from business_work_schedule_attendance
        where
        supplement_work_person_id=#{supplementWorkPersonId}
        and
        del_flag=0
        order by create_time desc
        limit 1
    </select>
    <select id="findOneByWorkOverPersonId" resultMap="WorkScheduleAttendanceMap">
        select * from business_work_schedule_attendance
        where
        work_over_person_id=#{workOverPersonId}
        and
        del_flag=0
        order by create_time desc
        limit 1
    </select>
    <select id="statScheduleAttendanceByDate" resultType="java.util.Map">
        <![CDATA[
            select work_shift_id as workShiftId,
            count(distinct(attendance_date)) as dayCount
            from business_work_schedule_attendance
            where person_id=#{personId}
            and record_time>=#{startDate}
            and record_time<=#{endDate}
            and result_<>0
            and del_flag=0
            group by work_shift_id
        ]]>
    </select>
    <select id="findEmptyWorkMinuteList" resultMap="WorkScheduleAttendanceMap">
        select * from
        business_work_schedule_attendance
        where
        work_minute is null
        and
        classify_='2'
        and
        del_flag=0
        order by record_time asc
        limit ${limit}
    </select>
    <select id="findSumWorkMinuteByParams" resultType="java.lang.Double">
        SELECT COALESCE(sum(work_minute),0)
        FROM
        business_work_schedule_attendance
        WHERE del_flag = 0
        and person_id = #{personId}
        and work_minute>0
        <![CDATA[
            and attendance_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
            and attendance_date <= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
        ]]>
        <if test="searchParams.classify != null">
            AND classify_ = #{searchParams.classify}
        </if>
    </select>
    <select id="queryDuplicateRecord" resultType="java.util.Map">
        <![CDATA[
            select * from (
                select
                person_schedule_id as personScheduleId,
                work_shift_id as workShiftId,
                classify_ as classify,
                count(*) as total
                from business_work_schedule_attendance
                where
                attendance_date>=DATE_FORMAT(#{startDate}, '%Y-%m-%d')
                and
                del_flag=0
                group by person_schedule_id,work_shift_id,classify_
            ) as t
            where
            t.total>1
            limit ${limit}
        ]]>
    </select>
</mapper>