<?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.fbsWorkshopDispatchList.mapper.FbsWorkshopDispatchListMapper">
    <update id="updateState">
        update fbs_workshop_dispatch_list set state =#{state} where id = #{id}
    </update>

    <select id="selNowDispatchList" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
            a.*,b.first_time as firstTime
        FROM
            fbs_workshop_dispatch_list a
            left join fbs_working_statistics b on a.id = b.pk_workshop_dispatch_list and b.del_flag='0'
        WHERE
            a.del_flag = '0' and a.state ='1'

    </select>

    <select id="getDispatchListByDate" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
        fwdl.*,
        ftp.memo as workCenter
        FROM
            fbs_workshop_dispatch_list fwdl
        LEFT JOIN fbs_technological_process ftp on fwdl.fbs_technological_process_id=ftp.id
        WHERE
        fwdl.del_flag = '0'
            and DATE_FORMAT( #{date},'%Y-%m-%d') <![CDATA[ >= ]]> DATE_FORMAT(fwdl.planned_start_time,'%Y-%m-%d')
            and DATE_FORMAT( #{date},'%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(fwdl.planned_end_time,'%Y-%m-%d')
            <!--AND date_format( date, '%Y-%m-%d' ) = DATE_FORMAT( #{date}, '%Y-%m-%d' )-->
        GROUP BY
            product
    </select>
    
    <select id="getSumDispatch" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
            *,
            sum(latest_completed_quantity) as latestCompletedQuantityTotal
        FROM
            fbs_workshop_dispatch_list
            where del_flag='0'
            <!--and substring(production_order_number_name,3,4)=#{yearMonth}-->
            <if test="list!=null and list.size()>0">
                AND production_order_number_name IN
                <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

        GROUP BY
            production_order_number_id,product_id
    </select>

    <select id="getSumDispatchNumber" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
        *,
        planned_quantity AS planned_quantity,
        FORMAT((planned_quantity*standard_working_hours_z),2) AS standard_working_hours_z,
        sum( latest_completed_quantity ) AS latest_completed_quantity,
        sum(man_hours_completed) as manHoursCompletedTotal
        FROM
        fbs_workshop_dispatch_list
        where del_flag='0'
        <if test="month!=null and month!=''">
            AND substring(production_order_number_name, 3, 4)=#{month}
        </if>
        GROUP BY
        production_order_number_id,product_id
        ORDER BY
        production_line_name
    </select>

    <select id="getDispatchClose" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
       <!-- SELECT
            fwdl.* ,fws.qualified_number,fws.end_date,convert(fwdl.man_hours_completed/fwdl.standard_working_hours,decimal(15,2))*100 as productionEfficiency
            ,convert(fws.qualified_number/fwdl.number_of_tasks,decimal(15,2))*100 as achievementRate
        FROM
            fbs_workshop_dispatch_list fwdl
            left join fbs_working_statistics fws on fwdl.id=fws.pk_workshop_dispatch_list
        WHERE
            fwdl.del_flag = '0' and fws.del_flag='0' and fws.final_state='3'
            <if test="startDate!=null">
                <![CDATA[   and DATE_FORMAT(fws.end_date, '%Y-%m-%d')>=  #{startDate}]]>
            </if>
            <if test="endDate!=null">
                <![CDATA[  and DATE_FORMAT(fws.end_date, '%Y-%m-%d') <= #{endDate} ]]>
            </if>-->
        SELECT
        fwdl.production_order_number_name,
        fwdl.product_id,
        CONVERT (sum(COALESCE(fws.qualified_number,0)), DECIMAL ( 15, 1 ) ) qualified_number,
        DATE_FORMAT(fws.final_time,'%Y-%m-%d') final_time,
        CONVERT ( (fwdl.standard_working_hours_z*sum(COALESCE(fws.qualified_number,0))) / sum(fws.working_hours), DECIMAL ( 15, 1 ) ) * 100 AS productionEfficiency,
        CONVERT ( sum(fws.qualified_number) / fwdl.number_of_tasks, DECIMAL ( 15, 1 ) ) * 100 AS achievementRate,
        fwdl.number_of_tasks number_of_tasks,
        CONVERT (sum(fws.working_hours), DECIMAL ( 15, 1 ) ) man_hours_completed,
        CONVERT (COALESCE((fwdl.standard_working_hours_z*sum(COALESCE(fws.qualified_number,0))),0), DECIMAL ( 15, 1 )) standard_working_hours,
        fwdl.standard_working_hours_z
        FROM
        fbs_workshop_dispatch_list fwdl
        LEFT JOIN fbs_working_statistics fws ON fwdl.id = fws.pk_workshop_dispatch_list
        WHERE
        fwdl.del_flag = '0'
        AND fws.del_flag = '0'
        <!--AND fwdl.latest_completed_quantity <![CDATA[ <> ]]> fwdl.number_of_tasks-->
        and fws.final_state in('2','3')
        <if test="startDate!=null">
            <![CDATA[   and DATE_FORMAT(fws.final_time, '%Y-%m-%d')>=  #{startDate}]]>
        </if>
        <if test="endDate!=null">
            <![CDATA[  and DATE_FORMAT(fws.final_time, '%Y-%m-%d') <= #{endDate} ]]>
        </if>
        GROUP BY
        fwdl.production_order_number_name,
        fwdl.product_id,
        DATE_FORMAT(fws.final_time,'%Y-%m-%d'),
        fwdl.standard_working_hours
    </select>

    <select id="getProductHoursMonthReport" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
       SELECT
            sum( standard_working_hours ) as productTotal,product
        FROM
            fbs_workshop_dispatch_list
        WHERE
            del_flag = '0'
            AND date_format( date, #{dateString} ) = DATE_FORMAT( now( ), #{dateString} )
        GROUP BY
            product
    </select>

    <select id="getAbnormalHoursMonthReport" resultType="java.util.HashMap">
        <!--SELECT-->
            <!--IFNULL(sum( quality ),0) AS '质量',-->
            <!--IFNULL(sum( design ),0) AS '设计',-->
            <!--&lt;!&ndash;IFNULL(sum( rework ),0) AS '返工',&ndash;&gt;-->
            <!--IFNULL(sum( materiel ),0) AS '物料',-->
            <!--IFNULL(sum( energy ),0) AS '能源',-->
            <!--&lt;!&ndash;IFNULL(sum( other ),0) AS '其他',&ndash;&gt;-->
            <!--IFNULL(sum( equipment ),0) AS '设备',-->
            <!--IFNULL(sum( plan ),0) AS '计划'-->
        <!--FROM-->
            <!--fbs_abnormal_working_hours-->
        <!--WHERE-->
            <!--del_flag = '0'-->
            <!--<if test="dateString=='%Y-%m-%d'">-->
                <!--AND date_format( date, #{dateString} ) = DATE_FORMAT( date_sub(curdate(),interval 1 day),  #{dateString} )-->
            <!--</if>-->
            <!--<if test="dateString=='%Y-%m'">-->
                <!--AND date_format( date, #{dateString} ) = DATE_FORMAT( now( ),  #{dateString} )-->
            <!--</if>-->

        SELECT
            fawhd.anomaly_classification AS type,
            sum( fawhd.abnormal_working_hours ) AS working
        FROM
          `fbs_abnormal_working_hours_describe` fawhd
          LEFT JOIN fbs_abnormal_working_hours fawh ON fawhd.abnormal_working_hours_id = fawh.id
        WHERE
          fawhd.anomaly_classification IS NOT NULL
          and fawh.del_flag='0'
        <if test="dateString=='%Y-%m-%d'">
            AND date_format( fawh.date, #{dateString} ) = DATE_FORMAT( date_sub(curdate(),interval 1 day),  #{dateString} )
        </if>
        <if test="dateString=='%Y-%m'">
            AND date_format( fawh.date, #{dateString} ) = DATE_FORMAT( now( ),  #{dateString} )
        </if>
        GROUP BY
          fawhd.anomaly_classification
        ORDER BY fawhd.anomaly_classification
    </select>

    <select id="getAbnormalHoursMonthReportSameDay" resultType="java.util.HashMap">
        SELECT
        sum( quality ) AS '质量',
        sum( design ) AS '设计',
        sum( rework ) AS '返工',
        sum( materiel ) AS '物料',
        sum( energy ) AS '能源',
        sum( other ) AS '其他',
        sum( equipment ) AS '设备',
        sum( plan ) AS '计划'
        FROM
        fbs_abnormal_working_hours
        WHERE
        del_flag = '0'
        AND date_format( date, '%Y-%m-%d' ) = DATE_FORMAT( now( ), '%Y-%m-%d' )
    </select>

    <select id="getAttendance" resultType="java.util.HashMap">
        <!--SELECT
            (
        SELECT
            count( personnel_code )
        FROM
            fbs_working_statistics
        WHERE
            del_flag = '0'
            AND date_format( start_date, '%Y' ) = date_format( now( ), '%Y' )
            AND date_format( fwdl.planned_start_time, '%Y-%m' ) = date_format( start_date, '%Y-%m' )
        GROUP BY
            date_format( start_date, '%Y-%m' )
            ) as sum1,
            count( personnel_id_u8 ) as sum2,
            date_format( fwdl.planned_start_time, '%m' ) as label
        FROM
            fbs_workshop_dispatch_list fwdl
        WHERE
            del_flag = '0'
            AND date_format( planned_start_time, '%Y' ) = date_format( now( ), '%Y' )
        GROUP BY
            date_format( planned_start_time, '%Y-%m' )-->
        SELECT
        (
        SELECT
        count( * )
        FROM
        (
        SELECT
        count( personnel_code ),
        personnel_code,
        start_date
        FROM
        fbs_working_statistics
        WHERE
        del_flag = '0'
        AND date_format( start_date, '%Y' ) = date_format( now( ), '%Y' )
        GROUP BY
        personnel_code
        ) fws
        WHERE
        date_format( fwdl.planned_start_time, '%Y-%m' ) = date_format( start_date, '%Y-%m' )
        GROUP BY
        date_format( start_date, '%Y-%m' )
        ) AS sum1,
        count( personnel_id_u8 ) AS sum2,
        date_format( fwdl.planned_start_time, '%m' ) AS label
        FROM
        fbs_workshop_dispatch_list fwdl
        WHERE
        del_flag = '0'
        AND date_format( planned_start_time, '%Y' ) = date_format( now( ), '%Y' )
        GROUP BY
        date_format( planned_start_time, '%Y-%m' )
    </select>

    <select id="getWorkingHoursContrast" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        <!--SELECT
            sum( fwdl.man_hours_completed ) AS manHoursCompleted,
            sum( fwdl.standard_working_hours ) AS standardWorkingHours,
            fwdl.product
        FROM
            fbs_workshop_dispatch_list fwdl
            LEFT JOIN fbs_working_statistics fws ON fwdl.id = fws.pk_workshop_dispatch_list
        WHERE
            fwdl.del_flag = '0'
            AND fws.del_flag = '0'
            AND fws.final_state = '3'
            AND date_format( fws.end_date, '%Y-%m' ) = date_format( now( ), '%Y-%m' )
        GROUP BY
            fwdl.product-->

             SELECT
        FORMAT(sum( fwdl.man_hours_completed ),2) AS manHoursCompleted,
        sum( fwdl.standard_working_hours ) AS standardWorkingHours,
        fwdl.product
        FROM
        fbs_workshop_dispatch_list fwdl
        WHERE
        fwdl.del_flag = '0'
        AND fwdl.man_hours_completed >0
        AND fwdl.state='3'
        AND fwdl.latest_completed_quantity=fwdl.number_of_tasks
        and DATE_FORMAT(now( ),'%Y-%m-%d') <![CDATA[ >= ]]> DATE_FORMAT(fwdl.planned_start_time,'%Y-%m-%d')
        and DATE_FORMAT(now( ),'%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(fwdl.planned_end_time,'%Y-%m-%d')
        GROUP BY
        fwdl.product
    </select>

    <!--   需要加入当日时间判断   -->
    <select id="getProductionEfficiency" resultType="java.lang.String">
        <!--SELECT CONVERT
            ( count( fws.pk_workshop_dispatch_list ) / count( fwdl.id ), DECIMAL ( 15, 2 ) ) * 100
        FROM
            fbs_workshop_dispatch_list fwdl
            LEFT JOIN ( SELECT pk_workshop_dispatch_list FROM fbs_working_statistics WHERE del_flag = '0'
            and DATE_FORMAT(now( ),#{dateString}) <![CDATA[ >= ]]> DATE_FORMAT(start_date,#{dateString})
            and DATE_FORMAT(now( ),#{dateString}) <![CDATA[ <= ]]> DATE_FORMAT(end_date,#{dateString})
             GROUP BY pk_workshop_dispatch_list ) fws ON fwdl.id = fws.pk_workshop_dispatch_list
        WHERE
            fwdl.del_flag = '0'
            and DATE_FORMAT(now( ),#{dateString}) <![CDATA[ >= ]]> DATE_FORMAT(fwdl.planned_start_time,#{dateString})
            and DATE_FORMAT(now( ),#{dateString}) <![CDATA[ <= ]]> DATE_FORMAT(fwdl.planned_end_time,#{dateString})-->
       <!-- SELECT CONVERT
          ( sum( standard_working_hours ) / sum( man_hours_completed ), DECIMAL ( 15, 2 ) ) * 100
        FROM
          fbs_workshop_dispatch_list
        WHERE
            del_flag = '0'
            and DATE_FORMAT(now( ),#{dateString}) <![CDATA[ >= ]]> DATE_FORMAT(planned_start_time,#{dateString})
            and DATE_FORMAT(now( ),#{dateString}) <![CDATA[ <= ]]> DATE_FORMAT(planned_end_time,#{dateString}) -->
        select  CONVERT
        ( sum(w.workingB) / sum(w.workingS), DECIMAL ( 15, 2 ) ) * 100 as rate
        FROM(
        SELECT
        CONVERT (( fwdl.standard_working_hours_z * sum( COALESCE ( fws.qualified_number, 0 ) ) ), DECIMAL ( 15, 1 ) ) AS workingB,
        CONVERT ( COALESCE ( sum( working_hours ), 0 ), DECIMAL ( 15, 1 ) ) workingS
        FROM
        fbs_workshop_dispatch_list fwdl
        LEFT JOIN fbs_working_statistics fws ON fwdl.id = fws.pk_workshop_dispatch_list
        WHERE
        fwdl.del_flag = '0'
        AND fws.del_flag = '0'
        <!--AND fwdl.standard_working_hours_z>0-->
        <if test="dateString =='%Y-%m-%d'">
            AND date_format( fws.final_time, '%Y-%m-%d' ) = DATE_FORMAT( date_sub(curdate(),interval 1 day),  '%Y-%m-%d' )
        </if>
        <if test="dateString =='%Y-%m'">
            AND date_format( fws.final_time, '%Y-%m' ) = DATE_FORMAT( now( ),  '%Y-%m' )
        </if>
        GROUP BY
        fwdl.production_order_number_name,
        fwdl.product
        <!--HAVING sum( COALESCE ( fws.qualified_number, 0 ) )>0-->
        ) as w
    </select>

    <select id="getAchievementRate" resultType="java.util.HashMap">
       <!-- SELECT
            sum( fws.qualified_number ) AS '已完成',
            sum( fwd.number_of_tasks ) - sum( fws.qualified_number ) AS '未完成'
        FROM
            fbs_workshop_dispatch_list fwd
            LEFT JOIN fbs_working_statistics fws ON fwd.id = fws.pk_workshop_dispatch_list
            AND fws.del_flag = '0'
            AND fws.final_state = '3'
        WHERE
            fwd.del_flag = '0'
            and DATE_FORMAT(date_sub(curdate(),interval 1 day),'%Y-%m-%d') <![CDATA[ >= ]]> DATE_FORMAT(fwd.planned_start_time,'%Y-%m-%d')
            and DATE_FORMAT(date_sub(curdate(),interval 1 day),'%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(fwd.planned_end_time,'%Y-%m-%d')-->
        <!--SELECT
        sum( qualified_number ) '已完成',
        sum( number_of_tasks ) - sum( qualified_number ) '未完成'
        FROM
        (
        SELECT
        sum( fws.qualified_number ) AS qualified_number,
        fwd.number_of_tasks AS number_of_tasks
        FROM
        fbs_workshop_dispatch_list fwd
        LEFT JOIN fbs_working_statistics fws ON fwd.id = fws.pk_workshop_dispatch_list
        AND fws.del_flag = '0'
        AND fws.final_state IN ( '2', '3' )
        WHERE
        fwd.del_flag = '0'
        AND date_format( fws.final_time, '%Y-%m-%d' ) = DATE_FORMAT( date_sub( curdate( ), INTERVAL 1 DAY ), '%Y-%m-%d' )
        GROUP BY
        fwd.production_order_number_name,
        fwd.product
        ) f-->

        SELECT
        sum( latest_completed_quantity ) '已完成',
        sum( number_of_tasks ) - sum( latest_completed_quantity ) '未完成'
        FROM
        fbs_workshop_dispatch_list
        where
        del_flag = '0'
    </select>

    <select id="getAttendanceOfTheDay" resultType="java.util.HashMap">
       <!-- SELECT
            count( pdl.pk_workshop_dispatch_list ) AS '考勤人数',
            count( fwdl.id ) - count( pdl.pk_workshop_dispatch_list ) AS '未考勤人数'
        FROM
            fbs_workshop_dispatch_list fwdl
            LEFT JOIN ( SELECT * FROM fbs_working_statistics WHERE del_flag = '0' GROUP BY pk_workshop_dispatch_list ) pdl ON fwdl.id = pdl.pk_workshop_dispatch_list
        WHERE
            fwdl.del_flag = '0'
            AND date_format( fwdl.date, '%Y-%m-%d' ) = DATE_FORMAT( now( ), '%Y-%m-%d' ) -->
        SELECT
          IfNULL( sum( actual_number_of_people ), 0 ) AS '实到人数',
          IfNULL( ( number_of_people_to_arrive ), 0 )-IfNULL( sum( actual_number_of_people ), 0 )  AS '未到人数'
        FROM
          fbs_abnormal_working_hours
        WHERE
          del_flag = '0'
          AND DATE_FORMAT( date, '%Y-%m-%d' ) = DATE_FORMAT( date_sub(curdate(),interval 1 day), '%Y-%m-%d' )
    </select>

    <select id="getProductList" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
            fwdl.production_order_number_name,
            <!--fws.end_date,-->
            fwdl.product,
            fwdl.product_id,
            fwdl.planned_start_time,
            fwdl.planned_end_time,
            fwdl.number_of_tasks,
        <!--fws.qualified_number,-->
            fwdl.product_id,
            fwdl.latest_completed_quantity,
            fwdl.fbs_technological_process_item_name,
            fwdl.fbs_technological_process_id
        FROM
          fbs_workshop_dispatch_list fwdl
        <!--LEFT JOIN fbs_working_statistics fws ON fwdl.id = fws.pk_workshop_dispatch_list
          AND fws.del_flag = '0'-->
        WHERE
        fwdl.del_flag = '0'
        and fwdl.state ='1'
        <!--and fwdl.state <![CDATA[ <> ]]> '0'-->
        <!--and date_format( fwdl.date, '%Y-%m-%d' ) = date_format( now( ), '%Y-%m-%d' )-->
        ORDER BY
            fwdl.date DESC
    </select>

    <select id="getProjectScheduleCompletion" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
       <!-- SELECT
        fwdl.project_name,
        fwdl.standard_working_hours,
        fws.working_hours as manHoursCompleted
        FROM
        fbs_workshop_dispatch_list fwdl
        LEFT JOIN ( SELECT sum( working_hours ) working_hours, pk_workshop_dispatch_list FROM fbs_working_statistics WHERE del_flag = '0' AND final_state <> '3' GROUP BY pk_workshop_dispatch_list ) fws ON fwdl.id = fws.pk_workshop_dispatch_list
        WHERE
        fwdl.del_flag = '0'
        AND fwdl.state <![CDATA[ <> ]]>'3' UNION ALL
        SELECT
        fwdl.project_name,
        fwdl.standard_working_hours,
        fwdl.man_hours_completed
        FROM
        fbs_workshop_dispatch_list fwdl
        LEFT JOIN fbs_working_statistics fws ON fwdl.id = fws.pk_workshop_dispatch_list
        WHERE
        fwdl.del_flag = '0'
        AND fws.del_flag = '0'
        AND fwdl.state = '3'
        AND fws.final_state = '3' -->
        SELECT
            fwdl.project_name,
            fwdl.production_order_number_name,
            sum( fwdl.standard_working_hours ) as standard_working_hours,
            sum( fwdl.man_hours_completed ) as man_hours_completed,
            sum( fwdl.number_of_tasks ) as number_of_tasks,
            sum( fwdl.latest_completed_quantity ) as  latest_completed_quantity
        FROM
          fbs_workshop_dispatch_list fwdl
        WHERE
          fwdl.del_flag = '0'
        GROUP BY
          fwdl.production_order_number_id
        ORDER BY fwdl.production_order_number_name
    </select>

    <select id="getListWhereStartEnd" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
        *,
        CONVERT ( IFNULL( (latest_completed_quantity), 0 )*IFNULL( (standard_working_hours_z), 0 ) / IFNULL( ( man_hours_completed  ), 0 ), DECIMAL ( 15, 0 ) ) * 100 as productionEfficiency,
        CONVERT ( IFNULL( (latest_completed_quantity), 0 ) / IFNULL( ( number_of_tasks  ), 0 ), DECIMAL ( 15, 0 ) ) * 100 as achievementRate
        ,(number_of_tasks-latest_completed_quantity) as remainingQuantity
        FROM
        fbs_workshop_dispatch_list
        WHERE
        del_flag = '0'
        AND latest_completed_quantity  <![CDATA[ <> ]]> number_of_tasks
        ORDER BY name
       <!-- AND DATE_FORMAT( now( ), '%Y-%m-%d' ) <![CDATA[ >= ]]> DATE_FORMAT( planned_start_time, '%Y-%m-%d' )
        AND DATE_FORMAT( now( ), '%Y-%m-%d' ) <![CDATA[ <= ]]> DATE_FORMAT( planned_end_time, '%Y-%m-%d' )-->
    </select>

    <select id="getEsopList" resultType="java.util.HashMap">
        SELECT
            production_order_number_name orderSheetCode,
            product_id materialCode,
            product materialName,
            number_of_tasks qty
        FROM
          fbs_workshop_dispatch_list
        WHERE
            del_flag = '0'
            AND number_of_tasks > latest_completed_quantity
           <!-- ORDER by create_time DESC-->
    </select>

    <select id="getFirstFinalTime" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
            min( first_time ) first_time,
            max( final_time ) final_time
        FROM
            fbs_working_statistics
        WHERE
            pk_workshop_dispatch_list = #{pkWorkshopDispatchList}
    </select>

    <select id="getOutstandingCumulativeWorkDone" resultType="java.math.BigDecimal">
        SELECT
          round( sum( IFNULL( man_hours_completed, 0 ) ), 1 )
        FROM
          fbs_workshop_dispatch_list
        WHERE del_flag = '0' AND production_order_number_name IN
            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                            #{item}
            </foreach>
    </select>

    <select id="getLatelyDayWorkShopDispatch" resultType="org.jeecg.modules.fbsWorkshopDispatchList.entity.FbsWorkshopDispatchList">
        SELECT
            id,
            name,
            personnel_id_u8,
            personnel_name_u8,
            date,
            production_order_number_id,
            production_order_number_name,
            product_id,
            product,
            number_of_tasks,
            standard_working_hours,
            planned_start_time,
            planned_end_time,
            del_flag,
            create_by,
            create_time,
            update_by,
            update_time,
            sort,
            production_line_name,
            production_line_id,
            state,
            man_hours_completed,
            `row_number`,
            project_name,
            planned_quantity,
            standard_working_hours_z,
            remaining_quantity,
            latest_completed_quantity_u8_memo,
            sum( latest_completed_quantity ) latest_completed_quantity
        FROM
          fbs_workshop_dispatch_list
        WHERE
            del_flag = '0'
            AND date <![CDATA[ >= ]]> DATE_SUB( CURDATE( ), INTERVAL 90 DAY )
           <!-- AND number_of_tasks <![CDATA[ <> ]]> latest_completed_quantity -->
        GROUP BY
          production_order_number_name,product_id
    </select>

    <update id="updateBatchWorkShopDispatch" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";" >
            UPDATE fbs_workshop_dispatch_list
            <set>
                <if test="item.latestCompletedQuantity != null and item.latestCompletedQuantity!=''">
                    latest_completed_quantity = #{item.latestCompletedQuantity},
                </if>
                <if test="item.latestCompletedQuantityU8Memo != null and item.latestCompletedQuantityU8Memo!=''">
                    latest_completed_quantity_u8_memo = #{item.latestCompletedQuantityU8Memo},
                </if>
                <if test="item.state !=null and item.state!=''">
                    state=#{item.state},
                </if>
                <if test="item.manHoursCompleted !=null and item.manHoursCompleted!=''">
                    man_hours_completed=#{item.manHoursCompleted},
                </if>
                update_time = NOW()
            </set>
            WHERE production_order_number_name = #{item.productionOrderNumberName}
        </foreach>
    </update>

    <update id="updateSAPstateByCode">
        update fbs_workshop_dispatch_list set SAP_state=#{SAPState} where production_order_number_name=#{code} and del_flag='0'
    </update>

    <select id="getProduceRateTotal" resultType="java.lang.Integer">
        SELECT
            ROUND( sum( latest_completed_quantity * standard_working_hours_z )/ sum( man_hours_completed )* 100, 0 )
        FROM
            `fbs_workshop_dispatch_list`
        WHERE
            del_flag = '0'
          AND latest_completed_quantity = number_of_tasks
          AND DATE_FORMAT( date, '%Y%m' ) = DATE_FORMAT( CURDATE( ), '%Y%m' )
          and production_order_number_name not like concat('23','%')
    </select>
</mapper>