廖井涛
2024-03-11 15f335a0553bbc56c23a1eea9548e53b8fdbcb87
north-glass-erp/src/main/resources/mapper/pp/ProductionScheduling.xml
@@ -8,6 +8,7 @@
        <result column="scheduling_quantity" property="schedulingQuantity"/>
        <result column="order_number" property="orderNumber"/>
        <result column="scheduling_id" property="schedulingId"/>
        <result column="order_id" property="orderId"/>
        <!--接收其他外键实体类数据-->
        <association property="order" javaType="com.example.erp.entity.sd.Order">
            <result column="project" property="project"/>
@@ -41,114 +42,185 @@
    </resultMap>
<!--    查询已排版数据-->
    <select id="SelectOkSchedulingMp">
        select date(ps.scheduled_start_time) as scheduled_start_time,
               date(ps.plan_end_time) as plan_end_time,
               od.order_id,o.customer_name,o.project,od.order_number,od.width,od.height,od.quantity,
        round(od.width*od.height*od.quantity/1000000,2) as area,
        ps.scheduling_quantity,
#         (od.quantity-IFNULL(ps.scheduling_quantity,0)) as pendingProductionQuantity,
#         round(od.width*od.height*(od.quantity-IFNULL(ps.scheduling_quantity,0))/1000000,2) as pendingProductionArea,
        IFNULL(ps.scheduling_quantity,0) as productionScheduledQuantity,
        round(od.width*od.height*(IFNULL(ps.scheduling_quantity,0))/1000000,2) as productionScheduledArea,
        IF(ps.review_status=0,"未审核","已审核") as review_status,
        ps.reviewer,
        od.product_name,od.shape,ps.scheduling_id
    <!--    查询已排版数据-->
    <select id="selectOkSchedulingMp">
        select date(ps.scheduled_start_time)                          as scheduled_start_time,
               date(ps.plan_end_time)                                 as plan_end_time,
               od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2) as area,
               ps.scheduling_quantity,
               (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) as pendingProductionQuantity,
               round(od.width * od.height * (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) / 1000000,
                     2)                                               as pendingProductionArea,
               IFNULL(ps.scheduling_quantity, 0)                      as productionScheduledQuantity,
               round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000,
                     2)                                               as productionScheduledArea,
               IF(ps.review_status = 0, "未审核", "已审核")           as review_status,
               ps.reviewer,
               od.product_name,
               od.shape,
               ps.scheduling_id
        from sd.order_detail as od
            left join sd.order as o on od.order_id=o.order_id
            left join production_scheduling as ps on ps.order_id=od.order_id and ps.order_number=od.order_number
        where  ps.scheduling_id IS NOT NULL
           and od.create_time between #{selectTime1} and #{selectTime2}
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where ps.scheduling_id IS NOT NULL
          and od.create_time between #{selectTime1} and #{selectTime2}
          and position(#{processes} in ps.processes)
          and position(#{orderId} in ps.order_id)
        group by od.order_id, od.order_number
        order by ps.id desc
    </select>
    <!--    查询已排产带订单编号的数据-->
    <select id="SelectSchedulingNotMp">
        select date(ps.scheduled_start_time) as scheduled_start_time,
        date(ps.plan_end_time) as plan_end_time,
        od.order_id,o.customer_name,o.project,od.order_number,od.width,od.height,od.quantity,
        round(od.width*od.height*od.quantity/1000000,2) as area,
        ps.scheduling_quantity,
#         (od.quantity-IFNULL(ps.scheduling_quantity,0)) as pendingProductionQuantity,
#         round(od.width*od.height*(od.quantity-IFNULL(ps.scheduling_quantity,0))/1000000,2) as pendingProductionArea,
        IFNULL(ps.scheduling_quantity,0) as productionScheduledQuantity,
        round(od.width*od.height*(IFNULL(ps.scheduling_quantity,0))/1000000,2) as productionScheduledArea,
        IF(ps.review_status=0,"未审核","已审核") as review_status,
        ps.reviewer,
        od.product_name,od.shape,ps.scheduling_id
    <!--    查询已排产的数据-->
    <select id="selectSchedulingNotMp">
        select date(ps.scheduled_start_time)                          as scheduled_start_time,
               date(ps.plan_end_time)                                 as plan_end_time,
               od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2) as area,
               ps.scheduling_quantity,
               (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) as pendingProductionQuantity,
               round(od.width * od.height * (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) / 1000000, 2)
                                                                      as pendingProductionArea,
               IFNULL(ps.scheduling_quantity, 0)                      as productionScheduledQuantity,
               round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000, 2)
                                                                      as productionScheduledArea,
               IF(ps.review_status = 0, "未审核", "已审核")
                                                                      as review_status,
               ps.reviewer,
               od.product_name,
               od.shape,
               ps.scheduling_id
        from sd.order_detail as od
        left join sd.order as o on od.order_id=o.order_id
        left join production_scheduling as ps on ps.order_id=od.order_id and ps.order_number=od.order_number
        where  (ps.scheduling_id IS NOT NULL )
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where (ps.scheduling_id IS NOT NULL)
          and position(#{processes} in ps.processes)
          and position(#{orderId} in ps.order_id)
        group by od.order_id, od.order_number
        order by ps.id desc
    </select>
<!--    查询未排产数据-->
    <select id="SelectNoSchedulingMp" >
        select od.order_id,o.customer_name,o.project,od.order_number,od.width,od.height,od.quantity,
        round(od.width*od.height*od.quantity/1000000,2) as area,
        (od.quantity-IFNULL(ps.scheduling_quantity,0)) as pendingProductionQuantity,
        round(od.width*od.height*(od.quantity-IFNULL(ps.scheduling_quantity,0))/1000000,2) as pendingProductionArea,
        IFNULL(ps.scheduling_quantity,0) as productionScheduledQuantity,
        round(od.width*od.height*(IFNULL(ps.scheduling_quantity,0))/1000000,2) as productionScheduledArea,
        od.product_name,od.shape
        from sd.order_detail as od left join sd.order as o on od.order_id=o.order_id
        left join production_scheduling as ps on ps.order_id=od.order_id and ps.order_number=od.order_number
        where   od.quantity-IFNULL(ps.scheduling_quantity,0)>0 and od.create_time between #{selectTime1} and #{selectTime2}
    <!--    查询未排产数据-->
    <select id="selectNoSchedulingMp">
        select od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2) as area,
               (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) as pendingProductionQuantity,
               round(od.width * od.height * (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) / 1000000, 2)
                                                                      as pendingProductionArea,
               IFNULL(ps.scheduling_quantity, 0)                      as productionScheduledQuantity,
               round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000,
                     2)                                               as productionScheduledArea,
               od.product_name,
               od.shape
        from sd.order_detail as od
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where (od.quantity - IFNULL((ps.scheduling_quantity), 0)) > 0
          and od.create_time between #{selectTime1} and #{selectTime2}
          and position(#{orderId} in ps.order_id)
    group by od.order_id,od.order_number
          and position(#{processes} in ps.processes)
        group by od.order_id, od.order_number
        order by ps.id desc
    </select>
<!--    首次查询排产数据-->
    <!--    首次查询排产数据-->
    <select id="selectLastSchedulingMp">
        select od.order_id,o.customer_name,o.project,od.order_number,od.width,od.height,od.quantity,
               round(od.width*od.height*od.quantity/1000000,2) as area,
               (od.quantity-IFNULL(ps.scheduling_quantity,0)) as pendingProductionQuantity,
               round(od.width*od.height*(od.quantity-IFNULL(ps.scheduling_quantity,0))/1000000,2) as pendingProductionArea,
               IFNULL(ps.scheduling_quantity,0) as productionScheduledQuantity,
               round(od.width*od.height*(IFNULL(ps.scheduling_quantity,0))/1000000,2) as productionScheduledArea,
               od.product_name,od.shape
        from sd.order_detail as od left join sd.order as o on od.order_id=o.order_id
                                   left join production_scheduling as ps on ps.order_id=od.order_id and ps.order_number=od.order_number
        where od.create_time between #{selectTime1} and #{selectTime2} and od.quantity-IFNULL(ps.scheduling_quantity,0)>0
        select od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2) as area,
               (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) as pendingProductionQuantity,
               round(od.width * od.height * (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) / 1000000,
                     2)                                               as pendingProductionArea,
               IFNULL(sum(ps.scheduling_quantity), 0)                 as productionScheduledQuantity,
               round(od.width * od.height * (IFNULL(sum(ps.scheduling_quantity), 0)) / 1000000,
                     2)                                               as productionScheduledArea,
               od.product_name,
               od.shape
        from sd.order_detail as od
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where od.create_time between #{selectTime1} and #{selectTime2}
          and (od.quantity - IFNULL((ps.scheduling_quantity), 0)) > 0
        group by od.order_id, od.order_number
        order by ps.id desc
    </select>
    <select id="selectMaxId">
        select
            COUNT(ps.scheduling_id)
        from
            `production_scheduling` as ps
        where
            date(ps.create_time) = curdate()
        select COUNT(ps.scheduling_id)
        from `production_scheduling` as ps
        where date(ps.create_time) = curdate()
    </select>
    <insert id="insertSelective">
        insert into production_scheduling(
               scheduling_id,
               order_id,
               order_number,
               processes,
               scheduling_quantity,
               scheduled_start_time,
               plan_end_time,
               notes,
               create_time
               )
        VALUES(
               #{schedulingId},
               #{orderId},
               #{orderNumber},
               #{processes},
               #{schedulingQuantity},
               #{scheduledStartTime},
               #{planEndTime},
               #{notes},
               now()
              )
        insert into production_scheduling(scheduling_id,
                                          order_id,
                                          order_number,
                                          processes,
                                          scheduling_quantity,
                                          scheduled_start_time,
                                          plan_end_time,
                                          notes,
                                          create_time)
        VALUES (#{schedulingId},
                #{orderId},
                #{orderNumber},
                #{processes},
                #{schedulingQuantity},
                #{scheduledStartTime},
                #{planEndTime},
                #{notes},
                now())
    </insert>
    <update id="examineSchedulingMp">
        update production_scheduling
        set review_status=1,
            reviewer=#{userName}
        where scheduling_id = #{schedulingId}
    </update>
    <delete id="deleteSchedulingMp">
        delete
        from production_scheduling
        where scheduling_id = #{schedulingId}
    </delete>
    <select id="selectProcess">
        SELECT *
        FROM sd.basic_data as bd
        where bd.basic_category = 'process'
          and bd.basic_type = 'product'
    </select>
    <select id="selectNumberMp">
    </select>
</mapper>