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

    <select id="getMonthlyDiscrepancyReport" resultType="org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestonesCompletedNumber">
        SELECT
            bsm.milestone_code,
            bsmcn.*
        FROM
            fd_bioanalysis_sample_milestones_completed_number bsmcn
            LEFT JOIN fd_bioanalysis_sample_milestones bsm ON bsm.id = bsmcn.pk_bioanalysis_sample_milestones
        WHERE
            bsm.del_flag='0' AND
            bsmcn.MONTH <![CDATA[ <> ]]> date_format( bsmcn.check_in_time, '%m' )
        <if test="startDate !=null and startDate!='' and startDate!='null'">
            <![CDATA[ and DATE_FORMAT(bsmcn.create_time,'%Y-%m-%d') >=DATE_FORMAT(#{startDate},'%Y-%m-%d') ]]>
        </if>

        <if test="endDate !=null and endDate!='' and endDate!='null'">
            <![CDATA[ and DATE_FORMAT(bsmcn.create_time,'%Y-%m-%d') <=DATE_FORMAT(#{endDate},'%Y-%m-%d') ]]>
        </if>
        ORDER BY
            bsm.milestone_code,
            bsmcn.compound_id
    </select>
    <!--<![CDATA[ and bsmcn.create_time >=#{startDate} ]]>-->
    <!--<![CDATA[ and bsmcn.create_time <=#{endDate} ]]>-->

    <update id="updateCompletedNumberBatch" parameterType="java.util.List">
        <foreach collection="completedNumberList" item="completedNumber" index="index" open="" close="" separator=";">
            update fd_bioanalysis_sample_milestones_completed_number
            <set>
                current_number =#{completedNumber.currentNumber},
                month=#{completedNumber.month},
                monthly_percentage=#{completedNumber.monthlyPercentage},
                accumulated_percentage=#{completedNumber.accumulatedPercentage},
                <if test="completedNumber.matrixProportion !=null and completedNumber.matrixProportion!=''">
                    matrix_proportion=#{completedNumber.matrixProportion},
                </if>
                <if test="completedNumber.totalNumber !=null and completedNumber.totalNumber!=''">
                    total_number=#{completedNumber.totalNumber}
                </if>
            </set>
            <where>
                id=#{completedNumber.id}
            </where>
        </foreach>
    </update>
</mapper>