<?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.qy.worksheetsystem.model.mapper.PersonWorkMapper">
    <select id="selectBillKey" resultType="String">
        select dbo.newbosid('CF9DCEB1') as id
    </select>
    <select id="selectKeyByBosTyoe" resultType="String">
        select dbo.newbosid(#{bosTyoe}) as id
    </select>
    <select id="getAvailableDateInfo" resultType="java.util.Map">
        SELECT
        item.fid as "id",
        CONVERT(varchar(10) , item.FDate, 120 ) as "date",
        CAST (item.FDayType as varchar) as "dateType",
        item.FWEEK "week",hre.CFEmployeeID employeeID,hre.workHours
        FROM
        T_HR_ATS_WorkCalendarItem item
        left join T_HR_ATS_WorkCalendar w on w.fid=item.FCALENDARGROUPID
        left join (
        select whre.CFEmployeeID,whre.CFdata,sum(whre.CFWorkingHours) workHours
        from
        CT_PRO_WorkHoursReportEntry whre
        where whre.CFEmployeeID=#{employeeID}
        group by whre.CFData,whre.CFEmployeeID) hre on hre.CFdata=item.FDate
        WHERE
        item.FDate BETWEEN #{startDate}
        AND #{endDate}
        AND w.FISDEFAULT=1
        order by item.FDate
    </select>
    <!---->
    <select id="getPersonWorkList" resultType="java.util.Map">
        select * from CT_PRO_WorkHoursReportEntry
    </select>
    <insert id="insertBill" parameterType="java.util.List" >
        insert
        into CT_PRO_WorkHoursReport(
        CFAffiliatedProjec,FAdminOrgUnitId,FHROrgUnitID,
        FBillState,FNumber,FBizDate,
        FCreatorID,FCreateTime,FLastUpdateUserID,
        FLastUpdateTime, FControlUnitID,FID,
        CFDataSource,CFFillingStartDate,CFFillingEndDate
        )
        values
        <foreach collection="billList" item="item" index="index" separator=",">
        (
            #{item.affiliatedProject}, #{item.adminOrg}, #{item.hrOrgUnit},
            #{item.billState}, #{item.number}, #{item.bizDate},
            #{item.creator}, getDate(), #{item.lastUpdateUser},
            getDate(), #{item.CU}, #{item.id},
            'employeeReport', #{item.fillingStartDate}, #{item.fillingEndDate}
        )
        </foreach>
    </insert>
    <insert id="insertWork" parameterType="java.util.List">
        INSERT
        into CT_PRO_WorkHoursReportEntry(FParentID,CFEmployeeID,CFClockTime,
        CFClockLocation,CFData,CFWorkingHours,
        CFNotes,FSeq,Fid
        )
        values
        <foreach collection="workList" item="item" index="index" separator=",">
            (
            #{item.parent},#{item.employee},
            #{item.clockTime},#{item.clockLocation},#{item.data},
            #{item.WorkingHours},#{item.notes},
            #{item.seq},dbo.newbosid('22DCD041')
            )
        </foreach>
    </insert>
</mapper>