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

    <update id="parentIdBatch" parameterType="java.util.List">
        <foreach collection="templateItemList" item="templateItem" index="index" open="" close="" separator=";">
            update fd_bioanalysis_sample_milestones_items
            <set>
                parent_id =#{templateItem.parentId}
            </set>
            <where>
                id=#{templateItem.id}
            </where>
        </foreach>
    </update>

    <update id="tempItemsBatch" parameterType="java.util.List">
        <foreach collection="templateItemList" item="templateItem" index="index" open="" close="" separator=";">
            update fd_bioanalysis_sample_milestones_items
            <set>
                actual_start_time =#{templateItem.actualStartTime},
                actual_end_time=#{templateItem.actualEndTime},
                estimate_days=#{templateItem.estimateDays},
                completion_time_difference=#{templateItem.completionTimeDifference},
                project_progress=#{templateItem.projectProgress},
                is_input_income=#{templateItem.isInputIncome},
                month_income=#{templateItem.monthIncome}
            </set>
            <where>
                id=#{templateItem.id}
            </where>
        </foreach>
    </update>

    <select id="getMilestonesItemsOvertime" resultType="org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestonesItems">
        SELECT
        fbsmi.*,
        fbsm.project_file_no as projectFileNo,
        fbsm.contract_code as contractCode,
        fpf.investigator as investigatorId,
		fbt.name as matrixTypeName,
		fbtt.name as compoundName
        FROM
        fd_bioanalysis_sample_milestones_items fbsmi
        LEFT JOIN fd_bioanalysis_sample_milestones fbsm ON fbsmi.pk_bioanalysis_sample_milestones = fbsm.id
        left join fd_project_file fpf on fbsm.pk_project_file=fpf.id
        left join fd_bioanalysis_template fbt on fbsmi.template_id=fbt.id
		left join fd_bioanalysis_template fbtt on fbtt.key_id=fbt.parent_id
        WHERE
        fbsm.del_flag = '0'
        and fbsmi.estimate_end_time is not null
        and fbsmi.actual_start_time is null
        ORDER BY
        fbsmi.pk_bioanalysis_sample_milestones
    </select>
    
    <select id="getMilestonesItemsIsisInputIncome" resultType="org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestonesItems">
        SELECT
            fbsmi.*,
            fbsm.project_file_no AS projectFileNo,
            fbsm.contract_code AS contractCode,
            fpf.investigator AS investigatorId,
            fp.name as investigatorName,
            fbsm.pk_project_file AS pkProjectFile,
            fbt.NAME AS matrixTypeName,
            fbtt.NAME AS compoundName,
            fbsm.create_time
        FROM
            fd_bioanalysis_sample_milestones_items fbsmi
            LEFT JOIN fd_bioanalysis_sample_milestones fbsm ON fbsmi.pk_bioanalysis_sample_milestones = fbsm.id
            LEFT JOIN fd_project_file fpf ON fbsm.pk_project_file = fpf.id
            LEFT JOIN fd_bioanalysis_template fbt ON fbsmi.template_id = fbt.id
            LEFT JOIN fd_bioanalysis_template fbtt ON fbtt.key_id = fbt.parent_id
            LEFT JOIN fd_personnel fp ON fpf.investigator=fp.id
        WHERE
            fbsm.del_flag = '0'
	        and fbtt.del_flag='0'
            AND fbsmi.is_input_income = 2
        ORDER BY
            fbsmi.pk_bioanalysis_sample_milestones,fbsmi.month_income
    </select>
</mapper>