From 69dc6b16ef04bdfbfa65f77c169c0847dc7e65c2 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 06 五月 2026 16:26:43 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New_pro' into dev_New_pro

---
 src/main/resources/mapper/production/ProductionOrderMapper.xml |  157 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 151 insertions(+), 6 deletions(-)

diff --git a/src/main/resources/mapper/production/ProductionOrderMapper.xml b/src/main/resources/mapper/production/ProductionOrderMapper.xml
index b2d1cb6..1a304ef 100644
--- a/src/main/resources/mapper/production/ProductionOrderMapper.xml
+++ b/src/main/resources/mapper/production/ProductionOrderMapper.xml
@@ -17,13 +17,147 @@
         <result column="end_time" property="endTime" />
         <result column="create_user" property="createUser" />
         <result column="dept_id" property="deptId" />
+        <result column="plan_complete_time" property="planCompleteTime" />
+        <result column="status" property="status" />
     </resultMap>
+
+    <resultMap id="ProductionOrderVoResultMap" type="com.ruoyi.production.bean.vo.ProductionOrderVo" extends="BaseResultMap">
+        <result column="salesContractNo" property="salesContractNo" />
+        <result column="customerName" property="customerName" />
+        <result column="productName" property="productName" />
+        <result column="model" property="model" />
+        <result column="processRouteCode" property="processRouteCode" />
+        <result column="returned" property="returned" />
+    </resultMap>
+
+    <sql id="ProductionOrderVoColumns">
+        po.id,
+        po.production_plan_ids,
+        po.product_model_id,
+        po.nps_no,
+        po.create_time,
+        po.update_time,
+        po.technology_routing_id,
+        po.quantity,
+        po.complete_quantity,
+        po.start_time,
+        po.end_time,
+        po.create_user,
+        po.dept_id,
+        po.plan_complete_time,
+        po.status,
+        po_sales.salesContractNo,
+        po_sales.customerName,
+        p.product_name as productName,
+        pm.model as model,
+        po.is_end_order as endOrder,
+        tr.process_route_code as processRouteCode,
+        ROUND(po.complete_quantity / po.quantity * 100, 2) AS completionStatus,
+        tb.bom_no as bomNo,
+        pop_return.returned as returned
+    </sql>
+
+    <sql id="ProductionOrderVoFrom">
+        from production_order po
+                 left join (
+            select po2.id as orderId,
+                   group_concat(distinct sl2.sales_contract_no order by sl2.sales_contract_no separator ',') as salesContractNo,
+                   group_concat(distinct sl2.customer_name order by sl2.customer_name separator ',') as customerName,
+                   group_concat(distinct sl2.project_name order by sl2.project_name separator ',') as projectName,
+                   min(sl2.delivery_date) as deliveryDate
+            from production_order po2
+                     left join production_plan pp2
+                               on find_in_set(pp2.id, replace(replace(replace(po2.production_plan_ids, '[', ''), ']', ''), ' ', '')) > 0
+                     left join sales_ledger sl2 on sl2.id = pp2.sales_ledger_id
+            group by po2.id
+        ) po_sales on po_sales.orderId = po.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 technology_routing tr on po.technology_routing_id = tr.id
+                 left join technology_bom tb on tb.id = tr.bom_id
+                 left join (
+            select production_order_id as productionOrderId,
+                   if(max(case when ifnull(is_returned, 0) = 1 then 1 else 0 end) = 1, true, false) as returned
+            from production_order_pick
+            group by production_order_id
+        ) pop_return on pop_return.productionOrderId = po.id
+    </sql>
+
+    <sql id="ProductionOrderWhere">
+        <where>
+            <if test="c != null">
+                <if test="c.id != null">
+                    and po.id = #{c.id}
+                </if>
+                <if test="c.productName != null and c.productName != ''">
+                    and p.product_name like concat('%', #{c.productName}, '%')
+                </if>
+                <if test="c.model != null and c.model != ''">
+                    and pm.model like concat('%', #{c.model}, '%')
+                </if>
+                <if test="c.productModelId != null">
+                    and po.product_model_id = #{c.productModelId}
+                </if>
+                <if test="c.technologyRoutingId != null">
+                    and po.technology_routing_id = #{c.technologyRoutingId}
+                </if>
+                <if test="c.status != null">
+                    and po.status = #{c.status}
+                </if>
+                <if test="c.createUser != null">
+                    and po.create_user = #{c.createUser}
+                </if>
+                <if test="c.deptId != null">
+                    and po.dept_id = #{c.deptId}
+                </if>
+                <if test="c.npsNo != null and c.npsNo != ''">
+                    and po.nps_no like concat('%', #{c.npsNo}, '%')
+                </if>
+                <if test="c.productionPlanIds != null and c.productionPlanIds != ''">
+                    and po.production_plan_ids like concat('%', #{c.productionPlanIds}, '%')
+                </if>
+                <if test="c.planCompleteTime != null">
+                    and po.plan_complete_time = #{c.planCompleteTime}
+                </if>
+                <if test="c.startTime != null">
+                    and po.start_time &gt;= #{c.startTime}
+                </if>
+                <if test="c.endTime != null">
+                    and po.end_time &lt;= #{c.endTime}
+                </if>
+            </if>
+        </where>
+    </sql>
+
+    <select id="pageProductionOrder" resultMap="ProductionOrderVoResultMap">
+        select
+        <include refid="ProductionOrderVoColumns" />
+        <include refid="ProductionOrderVoFrom" />
+        <include refid="ProductionOrderWhere" />
+        order by po.id desc
+    </select>
+
+    <select id="listProductionOrder" resultMap="ProductionOrderVoResultMap">
+        select
+        <include refid="ProductionOrderVoColumns" />
+        <include refid="ProductionOrderVoFrom" />
+        <include refid="ProductionOrderWhere" />
+        order by po.id desc
+    </select>
+
+    <select id="getProductionOrderInfo" resultMap="ProductionOrderVoResultMap">
+        select
+        <include refid="ProductionOrderVoColumns" />
+        <include refid="ProductionOrderVoFrom" />
+        where po.id = #{id}
+        limit 1
+    </select>
 
     <select id="selectProgressOrders" resultType="com.ruoyi.home.dto.ProductionProgressOrderDto">
         select po.nps_no,
-               sl.sales_contract_no,
-               sl.project_name,
-               sl.customer_name,
+               po_sales.salesContractNo,
+               po_sales.projectName,
+               po_sales.customerName,
                p.product_name as productCategory,
                pm.model as specificationModel,
                tr.process_route_code as processRouteCode,
@@ -31,11 +165,22 @@
                ifnull(po.complete_quantity, 0) as completeQuantity,
                round(ifnull(po.complete_quantity, 0) / nullif(po.quantity, 0) * 100, 2) as completionStatus,
                tb.bom_no,
-               datediff(sl.delivery_date, curdate()) as deliveryDaysDiff,
-               sl.delivery_date,
+               datediff(po_sales.deliveryDate, curdate()) as deliveryDaysDiff,
+               po_sales.deliveryDate as deliveryDate,
                false as isFh
         from production_order po
-                 left join sales_ledger sl on po.sales_ledger_id = sl.id
+                 left join (
+            select po2.id as orderId,
+                   group_concat(distinct sl2.sales_contract_no order by sl2.sales_contract_no separator ',') as salesContractNo,
+                   group_concat(distinct sl2.customer_name order by sl2.customer_name separator ',') as customerName,
+                   group_concat(distinct sl2.project_name order by sl2.project_name separator ',') as projectName,
+                   min(sl2.delivery_date) as deliveryDate
+            from production_order po2
+                     left join production_plan pp2
+                               on find_in_set(pp2.id, replace(replace(replace(po2.production_plan_ids, '[', ''), ']', ''), ' ', '')) > 0
+                     left join sales_ledger sl2 on sl2.id = pp2.sales_ledger_id
+            group by po2.id
+        ) po_sales on po_sales.orderId = po.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 technology_routing tr on po.technology_routing_id = tr.id

--
Gitblit v1.9.3