zss
5 小时以前 3bdaa5708b94e64f813f70ede8ba0bbd1a3179ec
src/main/resources/mapper/production/ProductOrderMapper.xml
@@ -5,71 +5,86 @@
    <resultMap id="basicMap" type="com.ruoyi.production.pojo.ProductOrder">
        <id property="id" column="id"/>
        <result property="productModelId" column="product_model_id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="salesLedgerId" column="sales_ledger_id"/>
        <result property="routeId" column="route_id"/>
        <result property="npsNo" column="nps_no"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="planCompleteTime" column="plan_complete_time"/>
        <result property="status" column="status"/>
    </resultMap>
    <resultMap id="ProductOrderSourceMap" type="com.ruoyi.production.dto.ProductOrderSourceDto">
        <id property="applyNo" column="apply_no"/>
        <result property="applyNo" column="apply_no"/>
        <collection property="productPlans" ofType="com.ruoyi.productionPlan.dto.ProductionPlanDto" autoMapping="true">
            <id property="id" column="plan_id"/>
            <result property="materialCode" column="material_code"/>
            <result property="productName" column="product_name"/>
            <result property="model" column="model"/>
            <result property="unit" column="unit"/>
            <result property="totalAssignedQuantity" column="total_assigned_quantity"/>
        </collection>
    </resultMap>
    <select id="pageProductOrder" resultType="com.ruoyi.production.dto.ProductOrderDto">
        select po.*,
        sl.sales_contract_no,
        sl.customer_name,
        p.product_name as product_category,
        pm.model as specification_model,
        pm.unit,
        ppr.process_route_code,
        pb.bom_no,
        SELECT
        po.id,
        po.nps_no,
        po.tenant_id,
        po.create_time,
        po.update_time,
        po.route_id,
        po.quantity,
        po.complete_quantity,
        po.start_time,
        po.end_time,
        po.plan_complete_time,
        po.status,
        pm.product_name,
        po.strength AS strength,
        pr.process_route_code AS processRouteCode,
        pr.description,
        pb.id AS bomId,
        pb.bom_no AS bomNo,
        ROUND(po.complete_quantity / po.quantity * 100, 2) AS completionStatus,
        DATEDIFF(sl.delivery_date, CURDATE()) AS delivery_days_diff,
        sl.delivery_date,
        CASE
        WHEN shipping_status_counts.total_count = 0 THEN false
        WHEN shipping_status_counts.unshipped_count = 0 THEN true
        ELSE false
        END AS is_fh
        from product_order po
        left join sales_ledger sl on po.sales_ledger_id = sl.id
        LEFT JOIN (
        SELECT sales_ledger_id,
        COUNT(*) as total_count,
        SUM(CASE WHEN status != '已发货' THEN 1 ELSE 0 END) as unshipped_count
        FROM shipping_info
        GROUP BY sales_ledger_id
        ) shipping_status_counts ON sl.id = shipping_status_counts.sales_ledger_id
            left join product_model pm on po.product_model_id = pm.id
            left join product p on pm.product_id = p.id
        left join sales_ledger_product slp on po.sale_ledger_product_id = slp.id
        left join product_process_route ppr on po.id = ppr.product_order_id
        left join product_bom pb on pb.id = ppr.bom_id
        pms.model,
        pms.material_code AS materialCode,
        pms.id AS productId
        FROM product_order po
        LEFT JOIN process_route pr ON po.route_id = pr.id
        LEFT JOIN product_bom pb ON pr.bom_id = pb.id
        LEFT JOIN product_material_sku pms ON pms.id = po.product_material_sku_id
        LEFT JOIN product_material pm ON pm.id = pms.product_id
        <where>
            <if test="c.npsNo != null and c.npsNo != ''">
                and po.nps_no like concat('%',#{c.npsNo},'%')
            </if>
            <if test="c.salesContractNo != null and c.salesContractNo != ''">
                and sl.sales_contract_no like concat('%',#{c.salesContractNo},'%')
            </if>
            <if test="c.customerName != null and c.customerName != ''">
                and sl.customer_name like concat('%',#{c.customerName},'%')
            </if>
            <if test="c.productCategory != null and c.productCategory != ''">
                and slp.product_category like concat('%',#{c.productCategory},'%')
            </if>
            <if test="c.specificationModel != null and c.specificationModel != ''">
                and slp.specification_model like concat('%',#{c.specificationModel},'%')
                AND po.nps_no LIKE CONCAT('%', #{c.npsNo}, '%')
            </if>
            <if test="c.startTime != null and c.endTime != null">
                and po.create_time between #{c.startTime} and #{c.endTime}
                AND po.create_time BETWEEN #{c.startTime} AND #{c.endTime}
            </if>
            <if test="c.status != null">
                AND po.status = #{c.status}
            </if>
            <if test="c.productName != null and c.productName != ''">
                AND pm.product_name LIKE CONCAT('%', #{c.productName}, '%')
            </if>
            <if test="c.materialCode != null and c.materialCode != ''">
                AND pms.material_code LIKE CONCAT('%', #{c.materialCode}, '%')
            </if>
            <if test="c.model != null and c.model != ''">
                AND pms.model LIKE CONCAT('%', #{c.model}, '%')
            </if>
            <if test="c.strength != null and c.strength != ''">
                AND po.strength = #{c.strength}
            </if>
        </where>
    </select>
    <select id="listProcessRoute" resultType="com.ruoyi.production.pojo.ProcessRoute">
        select pr.*
        from process_route pr
                 left join product_model pm on pr.product_model_id = pm.id
        where pm.id = #{productModelId}
                 left join product_material_sku pms on pms.id = pr.product_model_id
        where pms.id = #{productModelId}
    </select>
    <select id="listProcessBom" resultType="com.ruoyi.production.dto.ProductStructureDto">
        select ps.id,
@@ -79,35 +94,141 @@
               ps.unit_quantity * po.quantity as demandedQuantity,
               ps.unit,
               p.product_name,
               pp.name as  process_name,
               pp.name                        as process_name,
               pm.product_id,
               pm.model
        from
            product_structure ps
                left join product_model pm on ps.product_model_id = pm.id
                left join product p on pm.product_id = p.id
                left join product_process pp on ps.process_id = pp.id
                left join product_process_route ppr on ps.bom_id = ppr.bom_id
                left join product_order po on po.id = ppr.product_order_id
        from product_structure ps
                 left join product_model pm on ps.product_model_id = pm.id
                 left join product p on pm.product_id = p.id
                 left join product_process pp on ps.process_id = pp.id
                 left join product_process_route ppr on ps.bom_id = ppr.bom_id
                 left join product_order po on po.id = ppr.product_order_id
        where ppr.product_order_id = #{orderId}
        order by ps.id
    </select>
    <select id="countCreated" resultType="java.lang.Integer">
        SELECT count(1) FROM product_order
        WHERE create_time &gt;= #{startDate} AND create_time &lt;= #{endDate}
        SELECT count(1)
        FROM product_order
        WHERE create_time &gt;= #{startDate}
          AND create_time &lt;= #{endDate}
    </select>
    <select id="countCompleted" resultType="java.lang.Integer">
        SELECT count(1) FROM product_order
        WHERE end_time &gt;= #{startDate} AND end_time &lt;= #{endDate}
        SELECT count(1)
        FROM product_order
        WHERE end_time &gt;= #{startDate}
          AND end_time &lt;= #{endDate}
          AND complete_quantity &gt;= quantity
    </select>
    <select id="countPending" resultType="java.lang.Integer">
        SELECT count(1) FROM product_order
        WHERE create_time &gt;= #{startDate} AND create_time &lt;= #{endDate}
        SELECT count(1)
        FROM product_order
        WHERE create_time &gt;= #{startDate}
          AND create_time &lt;= #{endDate}
          AND complete_quantity &lt; quantity
    </select>
    <select id="productOrderSource" resultMap="ProductOrderSourceMap"
            parameterType="java.lang.Long">
        SELECT pp.id                 AS plan_id,
               pp.apply_no,
               pp.*,
               pop.assigned_quantity AS total_assigned_quantity,
               sku.material_code,
               sku.model,
               pm.product_name,
               pm.unit
        FROM product_order_plan pop
                 LEFT JOIN production_plan pp ON pop.production_plan_id = pp.id
                 LEFT JOIN product_material_sku sku ON pp.product_material_sku_id = sku.id
                 LEFT JOIN product_material pm ON sku.product_id = pm.id
        WHERE pop.product_order_id = #{orderId}
        ORDER BY pp.apply_no
    </select>
    <select id="finishedPage" resultType="com.ruoyi.quality.dto.FinishedPageDto">
        select * from
            (select po.id productOrderId,
                    po.status,
                    po.nps_no,
                    sku.material_code,
                    pm.product_name,
                    sku.model,
                    po.strength,
                    po.quantity needQuantity,
                    sum(ppo.quantity) qualifiedQuantity,
                    sum(ppo.scrap_qty) unqualifiedQuantity,
                    sum(ppo.quantity+ppo.scrap_qty) quantity
            from product_order po
            LEFT JOIN product_material_sku sku ON po.product_material_sku_id = sku.id
            LEFT JOIN product_material pm ON sku.product_id = pm.id
            LEFT JOIN production_product_main ppm ON ppm.product_order_id = po.id
            LEFT JOIN production_product_output ppo ON ppo.product_main_id = ppm.id
            group by po.id ,
                    po.status,
                    po.nps_no,
                    sku.material_code,
                    pm.product_name,
                    sku.model,
                    po.strength,
                    po.quantity
            order by po.id desc )A
        <where>
            <if test="c.npsNo != null and c.npsNo != ''">
                AND A.nps_no LIKE CONCAT('%', #{c.npsNo}, '%')
            </if>
            <if test="c.productName != null and c.productName != ''">
                AND A.product_name LIKE CONCAT('%', #{c.productName}, '%')
            </if>
            <if test="c.materialCode != null and c.materialCode != ''">
                AND A.material_code LIKE CONCAT('%', #{c.materialCode}, '%')
            </if>
            <if test="c.model != null and c.model != ''">
                AND A.model LIKE CONCAT('%', #{c.model}, '%')
            </if>
            <if test="c.strength != null and c.strength != ''">
                AND A.strength = #{c.strength}
            </if>
        </where>
    </select>
    <select id="finishedRatio" resultType="com.ruoyi.quality.dto.FinishedRatioDto">
        select A.material_code,
               product_name,
               model,
               unit,
               actualInputQuantity,
               actualOutputQuantity,
               actualInputQuantity / actualOutputQuantity actualInputOutputRatio,
               unit_quantity standardInputOutputRatio,
               (actualInputQuantity / actualOutputQuantity - unit_quantity)/unit_quantity  deviationRate
        from (select
               sku.material_code,
               pm.product_name,
               sku.model,
               pprip.unit,
               pos.unit_quantity,
               sum(pprip.product_value) actualInputQuantity,
               sum(ppo.quantity+ppo.scrap_qty) actualOutputQuantity
        from   production_product_route_item_param pprip
        left join production_product_route_item ppri on ppri.id=pprip.production_product_route_item_id
        left join production_product_main ppm on ppm.id=ppri.product_main_id
        left join production_product_output ppo on ppm.id=ppo.product_main_id
        left join product_material_sku sku ON pprip.product_id = sku.id
        left join product_material pm ON sku.product_id = pm.id
        left join production_order_structure pos ON pos.product_model_id = pprip.product_id
        where ppm.product_order_id = #{productOrderId}
        and pos.order_id = #{productOrderId}
        and pprip.order_item_param_id is null
        group by sku.material_code,
                 pm.product_name,
                 sku.model,
                 pos.unit_quantity,
                 pprip.unit)A
    </select>
</mapper>