<?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="org.jeecg.modules.projectManagement.mapper.FdWorkingHoursMapper">
    <select id="findByPage" resultType="org.jeecg.modules.projectManagement.entity.FdWorkingHours">
           SELECT
                wh.id,
                wh.CODE,
                wh.create_time,
                wh.hour_filler,
                wh.role_name,
                con.CODE AS contractCode,
                whi.project_description,
                cpmi.description
            FROM
                fd_working_hours wh
                LEFT JOIN fd_working_hours_items whi ON whi.pk_woking_hour = wh.id
                LEFT JOIN fd_contract con ON con.id = whi.pk_contract
                LEFT JOIN fd_clinical_project_milestones_items cpmi ON cpmi.id = whi.pk_milestones_items
                 ${ew.customSqlSegment}
        </select>

    <update id="updateReviewBatch" parameterType="java.util.List">
        update fd_working_hours set status = '1' where id in
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <update id="updateAuditBatch" parameterType="java.util.List">
        update fd_working_hours set status = '0' where id in
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <select id="getNowDayCount" resultType="java.lang.Integer">
        select count(*) from fd_working_hours where del_flag='0' AND date(actual_hours)=#{nowDate} and create_by=#{createBy}
    </select>

    <select id="examinePage" resultType="org.jeecg.modules.projectManagement.entity.FdWorkingHours">
        SELECT
            * ,p.pk_personnel
        FROM
            fd_working_hours wh
            LEFT JOIN sys_user u ON wh.create_by = u.username
            left join fd_personnel p on u.personnel_id=p.id
            ${ew.customSqlSegment}
    </select>
    
    <update id="updateStatus" parameterType="org.jeecg.modules.projectManagement.entity.FdWorkingHours">
        UPDATE fd_working_hours set status=#{fdWorkingHours.status} where id=#{fdWorkingHours.id}
    </update>
</mapper>