瀏覽代碼

u8上传bug修复及速度优化

hxh 4 月之前
父節點
當前提交
bfd2003a7f

+ 144 - 74
src/custom/restcontroller/webmanage/sale/u8/SQL/销售出库U8上传序列号查询.sql

@@ -1,11 +1,116 @@
+WITH inserted AS (
+    -- 这里假设inserted是已有的CTE或表
+    -- 如果没有定义,请根据实际情况调整
+    SELECT * FROM u8 where u8id=$u8id$
+),
+     temp_a AS (
+         SELECT
+             t1.billno,
+             t1.STATUS,
+             t2.itemid,
+             t2.st_stockbillid,
+             t2.stockid,
+             t3.u8id,
+             CASE
+
+                 WHEN t1.typemx = '正品入库' THEN
+                     '红' ELSE t1.rb
+                 END rb,
+             t2.qty,
+             t1.type,
+             t1.typemx
+         FROM
+             st_stockbill t1
+                 INNER JOIN st_stockbill_items t2 ON t1.st_stockbillid = t2.st_stockbillid
+                 inner JOIN inserted t3 ON t3.period = t1.period
+                 AND DATE(t1.billdate) <= DATE(t3.billdate)
+    INNER JOIN st_stock t4 ON t2.stockid = t4.stockid
+    INNER JOIN sa_agents t5 ON t1.sys_enterpriseid = t5.sys_enterpriseid
+    AND t3.entity = t5.entity
+    INNER JOIN plm_item t6 ON t2.itemid = t6.itemid
+    LEFT JOIN sa_sendrepair t8 ON t1.sourceid = t8.sa_sendrepairid
+    AND t1.sourceobject = 'sa_sendrepair'
+WHERE
+    t1.STATUS = '审核'
+  AND (
+    ( t1.type = '销售出库' AND t4.type != '电商仓' AND t5.type != '电商' )
+   OR (
+    t1.type = '其他入库'
+  AND t1.typemx = '正品入库'
+  AND t4.stockno IN ( '103', '109' )
+  AND t8.STATUS = '审核'
+  AND t2.amount > 0
+    )
+    ) and (t6.topclassnum='集成灶' OR t6.itemno LIKE'10195%')and t6.stockno in('103','109')
+    ),
+    numbers AS (
+-- 生成0-511的数字序列(8×8×8-1),根据需要调整
+SELECT @row := @row + 1 AS number
+FROM
+    (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7) t1,
+    (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7) t2,
+    (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) t3,
+    (SELECT @row := -1) r
+    ),
+    expanded_temp_a AS (
+SELECT
+    ROW_NUMBER() OVER (PARTITION BY st_stockbillid, stockid, itemid ORDER BY stockid, itemid) AS `row`,
+    billno,
+    status,
+    itemid,
+    st_stockbillid,
+    stockid,
+    u8id,
+    rb,
+    1 AS qty,
+    type,
+    typemx
+FROM temp_a a
+    INNER JOIN numbers m ON m.number < a.qty AND m.number >= 0
+    ),
+    filtered_machinecode AS (
+SELECT
+    ROW_NUMBER() OVER (PARTITION BY t1.st_stockbillid, t1.stockid, t1.itemid ORDER BY t1.stockid, t1.itemid) AS `row`,
+    t1.itemid,
+    t1.sku,
+    t1.st_stockbillid,
+    t1.stockid,
+    t1.st_stockbill_items_skuid
+FROM st_stockbill_items_sku t1
+    INNER JOIN st_stockbill t2 ON t1.st_stockbillid = t2.st_stockbillid
+    INNER JOIN inserted t3 ON t3.period = t2.period
+    AND DATE(t2.billdate) <= DATE(t3.billdate)
+    INNER JOIN st_stock t5 ON t1.stockid = t5.stockid
+    INNER JOIN sa_agents t6 ON t2.sys_enterpriseid = t6.sys_enterpriseid
+    AND t3.entity = t6.entity
+    INNER JOIN plm_item t7 ON t1.itemid = t7.itemid
+    AND t7.departmentid =(select departmentid from sys_department where depno='103')
+WHERE t7.topclassnum = '集成灶'
+  AND t2.status = '审核'
+  AND (
+    (t5.stockno = '101'
+  AND t2.type = '销售出库'
+  AND t5.type != '电商仓'
+  AND t6.type != '电商')
+   OR
+    (t5.stockno IN ('103', '109')
+  AND t2.type = '其他入库'
+  AND t2.typemx = '正品入库'
+  AND EXISTS (
+    SELECT 1
+    FROM st_stockbill_items
+    WHERE st_stockbillid = t2.st_stockbillid
+  AND amount > 0
+    ))
+    )
+    ),
+    main_query AS (
 SELECT
     t1.billno,
     t1.status,
     t1.itemid,
     t2.sku,
     t1.st_stockbillid,
-    t2.sourceid,
-    t2.sourceobject,
     t1.stockid,
     t2.st_stockbill_items_skuid,
     t1.u8id,
@@ -13,75 +118,40 @@ SELECT
     t1.qty,
     t1.type,
     t1.typemx
-FROM
-    (
-        SELECT
-            t1.billno,
-            t1.STATUS,
-            t2.itemid,
-            t2.st_stockbillid,
-            t2.stockid,
-            t3.u8id,
-            CASE
-
-                WHEN t1.typemx = '正品入库' THEN
-                    '红' ELSE t1.rb
-                END rb,
-            t2.qty,
-            t1.type,
-            t1.typemx
-        FROM
-            st_stockbill t1
-                INNER JOIN st_stockbill_items t2 ON t1.st_stockbillid = t2.st_stockbillid
-                inner JOIN u8 t3 ON t3.period = t1.period
-                AND t1.billdate <= t3.billdate
-                AND t3.u8id = $u8id$
-                INNER JOIN st_stock t4 ON t2.stockid = t4.stockid
-                INNER JOIN sa_agents t5 ON t1.sys_enterpriseid = t5.sys_enterpriseid
-                AND t3.entity = t5.entity
-                INNER JOIN plm_item t6 ON t2.itemid = t6.itemid
-                LEFT JOIN sa_sendrepair t8 ON t1.sourceid = t8.sa_sendrepairid
-                AND t1.sourceobject = 'sa_sendrepair'
-        WHERE
-            t1.STATUS = '审核'
-          AND (
-            ( t1.type = '销售出库' AND t4.type != '电商仓' AND t5.type != '电商' )
-                OR (
-                t1.type = '其他入库'
-                    AND t1.typemx = '正品入库'
-                    AND t4.stockno IN ( '103', '109' )
-                    AND t8.STATUS = '审核'
-                    AND t2.amount > 0
-                )
-            )) t1
-        LEFT JOIN (
-        SELECT
-            t1.itemid,
-            t1.sku,
-            t1.st_stockbillid,
-            t1.stockid,
-            t1.st_stockbill_items_skuid,
-            t2.sourceid,
-            t2.sourceobject
-        FROM
-            st_stockbill_items_sku t1
-                INNER JOIN st_stockbill t2 ON t1.st_stockbillid = t2.st_stockbillid
-                INNER JOIN u8 t3 ON t3.period = t2.period
-                AND t2.billdate <= t3.billdate
-                AND t3.u8id = $u8id$
-                INNER JOIN st_stock t5 ON t1.stockid = t5.stockid
-                INNER JOIN sa_agents t6 ON t2.sys_enterpriseid = t6.sys_enterpriseid
-                AND t3.entity = t6.entity
-                INNER JOIN plm_item t7 ON t1.itemid = t7.itemid
-        WHERE
-            t2.STATUS = '审核'
-          AND (
-            ( t5.stockno = '101' AND t2.type = '销售出库' )
-                OR (
-                t5.stockno IN ( '103', '109' )
-                    AND t2.type = '其他入库'
-                    AND t2.typemx = '正品入库'
-                    AND EXISTS ( SELECT * FROM st_stockbill_items WHERE st_stockbillid = t2.st_stockbillid AND amount > 0 ))
-            )) t2 ON t1.st_stockbillid = t2.st_stockbillid
-        AND t1.stockid = t2.stockid
-        AND t1.itemid = t2.itemid
+FROM expanded_temp_a t1
+    LEFT JOIN filtered_machinecode t2 ON t1.st_stockbillid = t2.st_stockbillid
+    AND t1.stockid = t2.stockid
+    AND t1.itemid = t2.itemid
+    AND t1.row = t2.row
+    ),
+    ecommerce_query AS (
+SELECT
+    t1.billno,
+    t1.status,
+    t2.itemid,
+    '' sku,
+    t1.st_stockbillid,
+    t2.stockid,
+    '' st_stockbill_items_skuid,
+    t3.u8id,
+    t1.rb,
+    t2.qty,
+    t1.type,
+    t1.typemx
+FROM st_stockbill t1
+    INNER JOIN st_stockbill_items t2 ON t1.st_stockbillid = t2.st_stockbillid
+    INNER JOIN inserted t3 ON t1.period = t3.period
+    AND DATE(t1.billdate) <= DATE(t3.billdate)
+    INNER JOIN sa_agents t4 ON t1.sys_enterpriseid = t4.sys_enterpriseid
+    AND t3.entity = t4.entity
+    INNER JOIN plm_item t5 ON t2.itemid = t5.itemid
+WHERE t4.type = '电商'
+  AND t5.stockno IN ('103', '109')
+  AND t1.status = '审核'
+  AND t1.type = '销售出库'
+  AND t5.topclassnum = '集成灶'
+    )
+-- 最终结果
+SELECT * FROM main_query
+UNION ALL
+SELECT * FROM ecommerce_query;

+ 4 - 2
src/custom/restcontroller/webmanage/sale/u8/u8.java

@@ -597,10 +597,11 @@ public class u8 extends Controller {
         SQLFactory sqlFactory = new SQLFactory(this, "销售出库U8上传序列号查询");
         sqlFactory.addParameter("u8id", u8id);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
+        long[] u8billcodesids = createTableID("u8billcodes", rows.size());
+        int i = 0;
         for (Row row : rows) {
-            long u8billcodesid = createTableID("u8billcodes");
             InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "u8billcodes");
-            insertSQL.setUniqueid(u8billcodesid);
+            insertSQL.setUniqueid(u8billcodesids[i]);
             insertSQL.setSiteid(siteid);
             insertSQL.setValue("u8id", u8id);
             insertSQL.setValue("sourceid", row.getString("sourceid"));
@@ -618,6 +619,7 @@ public class u8 extends Controller {
             insertSQL.setValue("itemid", row.getString("itemid"));
             insertSQL.setValue("billno", row.getString("billno"));
             sqllist.add(insertSQL.getSQL());
+            i++;
         }
         dbConnect.runSqlUpdate(sqllist);
         sqllist = new ArrayList<>();