فهرست منبع

智能装配 查询商标太慢 (生产计划)

qinqi 1 سال پیش
والد
کامیت
2953d05106
1فایلهای تغییر یافته به همراه180 افزوده شده و 63 حذف شده
  1. 180 63
      wwwroot/main/Assemble/api/GetLogoData.ashx

+ 180 - 63
wwwroot/main/Assemble/api/GetLogoData.ashx

@@ -49,11 +49,104 @@ public class GetLogoData : IHttpHandler, IReadOnlySessionState
                 if (planFlag != null && planFlag.Rows.Count > 0 && planFlag.Rows[0]["PLANFLAG"].ToString() == "0")
                 {
                     //低级权限
+                    //DataTable plansTable = conn.ExecuteDatatable(@"
+                    //              SELECT l.logoid AS id
+                    //                      ,CASE
+                    //                           WHEN linshi.residuequantity IS NOT NULL THEN
+                    //                             l.logoname || '[' || t2.materialcode || ']' || ' 剩余[' || linshi.residuequantity || ']'
+                    //                           ELSE
+                    //                            l.logoname || '[' || t2.materialcode || ']'
+                    //                       END AS NAME
+                    //                      ,t2.materialcode
+                    //                      ,nvl(gdd.valueflag, '0') AS iscurrentlogo
+                    //                      ,1 AS ISCONTROL
+                    //                  FROM tp_mst_logo l
+                    //                 INNER JOIN (SELECT DISTINCT t.goodsid,t.logoid,t.materialcode
+                    //                               FROM (SELECT g.goodsid,g.logoid,g.materialcode
+                    //                                       FROM tp_mst_goods g
+                    //                                     UNION ALL
+                    //                                     SELECT s.goodsid,s.logoid,s.materialcode
+                    //                                       FROM tp_mst_goodslogosap s) t
+                    //                              WHERE EXISTS (SELECT 1 FROM tp_pm_groutingdailydetail g
+                    //                                      WHERE g.goodsid = t.goodsid AND g.barcode = @BARCODE@)) t2 ON t2.logoid = l.logoid
+                    //                  LEFT JOIN tp_pm_groutingdailydetail gdd ON gdd.logoid = l.logoid
+                    //                   AND gdd.barcode = @BARCODE@
+                    //                  RIGHT JOIN ( 
+                    //                    SELECT case when t.goodsid is null then tt.goodsid  else t.goodsid end as goodsid 
+                    //                          ,case when t.logoid is null then tt.logoid else t.logoid end as logoid 
+                    //                          ,case when t.changenum is null then sum(0) else SUM(t.changenum) end as changenum 
+                    //                           ,tt.quantity
+                    //                            ,case when t.changenum is null then  tt.quantity else tt.quantity - SUM(t.changenum) end as residuequantity  
+                    //                               FROM (
+                    //                                --在装配环节变更数量
+                    //                               SELECT ip.goodsid,ip.logoid,COUNT(distinct l.barcode) changenum
+                    //                                       FROM tp_pm_logochangedrecord l
+                    //                                       right JOIN tp_pm_groutingdailydetail ip ON l.barcode = ip.barcode 
+                    //                                       LEFT JOIN tp_pc_procedure p ON l.procedureid = p.procedureid
+                    //                                       LEFT JOIN (SELECT pp.goodsid,pp.logoid,pp.quantity,gdd.materialcode,pp.begintime ,pp.endtime
+                    //                                                   FROM tp_pm_production_plan pp
+                    //                                                   LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid
+                    //                                                  WHERE gdd.barcode = @BARCODE@
+                    //                                                    AND pp.begintime <= SYSDATE
+                    //                                                    AND pp.endtime > SYSDATE and pp.valueflag = 1 AND pp.CONTROLRANGE = 1) plans  ON plans.goodsid = ip.goodsid AND plans.logoid =  ip.logoid
+                    //                                      WHERE l.createtime >= plans.begintime
+                    //                                        AND l.createtime < plans.endtime
+                    //                                        AND ip.goodsid = @GOODSID@ 
+                    //                                        and ip.logoid = l.newlogoid 
+                    //                                        AND l.oldlogoid <> l.newlogoid
+                    //                                        AND p.modeltype = '-5' 
+                    //                                        AND p.procedureid not in(126,152) 
+                    //                                        AND NOT EXISTS (SELECT s.barcode FROM tp_pm_scrapproduct s
+                    //                                              WHERE s.barcode = l.barcode AND s.valueflag = 1 AND s.createtime >= l.createtime)
+                    //                                        GROUP BY ip.goodsid,ip.logoid
+                    //                                      UNION ALL
+                    //                                     --生产数据该产品商标在装配环节保存的数量(装配环节没有变更商标) 
+                    //                                     SELECT  pd.goodsid ,pd.logoid ,COUNT(distinct pd.barcode) changenum
+                    //                                       FROM tp_pm_productiondata pd  
+                    //                                       LEFT JOIN tp_pc_procedure p ON pd.procedureid = p.procedureid 
+                    //                                       left join (SELECT pp.goodsid,pp.logoid,pp.quantity,gdd.materialcode,pp.begintime ,pp.endtime
+                    //                                                        FROM tp_pm_production_plan pp
+                    //                                                        LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid  
+                    //                                                        WHERE gdd.barcode = @BARCODE@
+                    //                                                        AND pp.begintime <= SYSDATE
+                    //                                                        AND pp.endtime > SYSDATE AND pp.CONTROLRANGE = 1 AND pp.VALUEFLAG = 1 ) plans1 on plans1.goodsid = pd.goodsid and plans1.logoid = pd.logoid
+                    //                                                  WHERE  pd.createtime >= plans1.begintime
+                    //                                                  and pd.createtime < plans1.endtime
+                    //                                                  and pd.valueflag = 1 
+                    //                                                  and p.modeltype = '-5' 
+                    //                                                  and p.procedureid not in(126,152) 
+                    //                                                  AND NOT EXISTS (SELECT s.barcode
+                    //                                                      FROM tp_pm_logochangedrecord s
+                    //                                                      LEFT JOIN tp_pc_procedure p ON s.procedureid = p.procedureid
+                    //                                                     WHERE s.barcode = pd.barcode
+                    //                                                      AND  p.modeltype = '-5' 
+                    //                                                      and p.procedureid not in(126,152) 
+                    //                                                      --AND  s.oldlogoid = pd.logoid
+                    //                                                      AND  s.oldlogoid <> s.newlogoid)  
+                    //                                                GROUP BY pd.goodsid,pd.logoid) t
+                    //                               RIGHT JOIN (SELECT pp.goodsid,pp.logoid,pp.quantity
+                    //                                           FROM tp_pm_production_plan pp
+                    //                                           LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid
+                    //                                          WHERE gdd.barcode = @BARCODE@
+                    //                                            AND pp.begintime <= SYSDATE
+                    //                                            AND pp.endtime > SYSDATE
+                    //                                            and pp.valueflag = 1 AND pp.CONTROLRANGE = 1) tt
+                    //                                 ON t.logoid = tt.logoid
+                    //                              GROUP BY  t.goodsid,tt.goodsid,t.logoid,tt.logoid,tt.quantity ,t.changenum
+                    //                             ) linshi  ON linshi.logoid = l.logoid
+                    //                 WHERE l.valueflag = '1' AND l.accountid = @ACCOUNTID@
+                    //                 ORDER BY l.displayno",
+                    //        new CDAParameter("BARCODE", context.Request["barCode"]),
+                    //        new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]),
+                    //        new CDAParameter("GOODSID", planData.Rows[0]["GOODSID"].ToString())
+                    //    );
                     DataTable plansTable = conn.ExecuteDatatable(@"
                                   SELECT l.logoid AS id
                                           ,CASE
-                                               WHEN linshi.residuequantity IS NOT NULL THEN
+                                               WHEN linshi.residuequantity IS NOT NULL AND linshi.quantity IS NOT NULL  THEN
                                                  l.logoname || '[' || t2.materialcode || ']' || ' 剩余[' || linshi.residuequantity || ']'
+                                                WHEN linshi.residuequantity IS  NULL AND linshi.quantity IS NOT NULL THEN
+                                                 l.logoname || '[' || t2.materialcode || ']' || ' 剩余[' || linshi.quantity || ']'
                                                ELSE
                                                 l.logoname || '[' || t2.materialcode || ']'
                                            END AS NAME
@@ -71,12 +164,12 @@ public class GetLogoData : IHttpHandler, IReadOnlySessionState
                                                           WHERE g.goodsid = t.goodsid AND g.barcode = @BARCODE@)) t2 ON t2.logoid = l.logoid
                                       LEFT JOIN tp_pm_groutingdailydetail gdd ON gdd.logoid = l.logoid
                                        AND gdd.barcode = @BARCODE@
-                                      RIGHT JOIN ( 
+                                      RIGHT JOIN (
                                         SELECT case when t.goodsid is null then tt.goodsid  else t.goodsid end as goodsid 
                                               ,case when t.logoid is null then tt.logoid else t.logoid end as logoid 
-                                              ,case when t.changenum is null then sum(0) else SUM(t.changenum) end as changenum 
+                                              , SUM(t.changenum) as changenum 
                                                ,tt.quantity
-                                                ,case when t.changenum is null then  tt.quantity else tt.quantity - SUM(t.changenum) end as residuequantity  
+                                                , tt.quantity - SUM(t.changenum)  residuequantity  
                                                    FROM (
                                                     --在装配环节变更数量
                                                    SELECT ip.goodsid,ip.logoid,COUNT(distinct l.barcode) changenum
@@ -99,31 +192,41 @@ public class GetLogoData : IHttpHandler, IReadOnlySessionState
                                                             AND NOT EXISTS (SELECT s.barcode FROM tp_pm_scrapproduct s
                                                                   WHERE s.barcode = l.barcode AND s.valueflag = 1 AND s.createtime >= l.createtime)
                                                             GROUP BY ip.goodsid,ip.logoid
-                                                          UNION ALL
-                                                         --生产数据该产品商标在装配环节保存的数量(装配环节没有变更商标) 
-                                                         SELECT  pd.goodsid ,pd.logoid ,COUNT(distinct pd.barcode) changenum
-                                                           FROM tp_pm_productiondata pd  
-                                                           LEFT JOIN tp_pc_procedure p ON pd.procedureid = p.procedureid 
-                                                           left join (SELECT pp.goodsid,pp.logoid,pp.quantity,gdd.materialcode,pp.begintime ,pp.endtime
-                                                                            FROM tp_pm_production_plan pp
-                                                                            LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid  
-                                                                            WHERE gdd.barcode = @BARCODE@
-                                                                            AND pp.begintime <= SYSDATE
-                                                                            AND pp.endtime > SYSDATE AND pp.CONTROLRANGE = 1 AND pp.VALUEFLAG = 1 ) plans1 on plans1.goodsid = pd.goodsid and plans1.logoid = pd.logoid
-                                                                      WHERE  pd.createtime >= plans1.begintime
-                                                                      and pd.createtime < plans1.endtime
-                                                                      and pd.valueflag = 1 
-                                                                      and p.modeltype = '-5' 
-                                                                      and p.procedureid not in(126,152) 
-                                                                      AND NOT EXISTS (SELECT s.barcode
-                                                                          FROM tp_pm_logochangedrecord s
-                                                                          LEFT JOIN tp_pc_procedure p ON s.procedureid = p.procedureid
-                                                                         WHERE s.barcode = pd.barcode
-                                                                          AND  p.modeltype = '-5' 
-                                                                          and p.procedureid not in(126,152) 
-                                                                          --AND  s.oldlogoid = pd.logoid
-                                                                          AND  s.oldlogoid <> s.newlogoid)  
-                                                                    GROUP BY pd.goodsid,pd.logoid) t
+                                                          UNION ALL 
+                                                      --生产数据该产品商标在装配环节保存的数量(装配环节没有变更商标) 
+                                                           SELECT  pd.goodsid ,pd.logoid ,COUNT(distinct pd.barcode) changenum
+                                                             FROM TP_PM_FINISHEDPRODUCT pd  
+                                                            -- LEFT JOIN tp_pc_procedure p ON pd.procedureid = p.procedureid 
+                                                             left join (SELECT pp.goodsid,pp.logoid,pp.quantity,gdd.materialcode,pp.begintime ,pp.endtime
+                                                                              FROM tp_pm_production_plan pp
+                                                                              LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid  
+                                                                              WHERE gdd.barcode = @BARCODE@
+                                                                              AND pp.begintime <= SYSDATE
+                                                                              AND pp.endtime > SYSDATE AND pp.CONTROLRANGE = 1 AND pp.VALUEFLAG = 1 ) plans1 on plans1.goodsid = pd.goodsid and plans1.logoid = pd.logoid
+                                                                        WHERE  pd.valueflag = 1  
+                                                                        and pd.goodsid =@GOODSID@
+                                                                       -- and p.modeltype = '-5' 
+                                                                       -- and p.procedureid not in(126,152) 
+                                                                         and pd.createtime >= trunc(plans1.begintime)
+                                                                        and pd.createtime < trunc(plans1.endtime)
+                                                                        AND NOT EXISTS (SELECT s.barcode
+                                                                            FROM tp_pm_logochangedrecord s
+                                                                            LEFT JOIN tp_pc_procedure p ON s.procedureid = p.procedureid
+                                                                           WHERE s.barcode = pd.barcode
+                                                                            AND  p.modeltype = '-5' 
+                                                                            and p.procedureid not in(126,152) 
+                                                                            --AND  s.oldlogoid = pd.logoid
+                                                                            AND  s.oldlogoid <> s.newlogoid)
+                                                                         AND  EXISTS (SELECT pdd.barcode
+                                                                            FROM tp_pm_productiondata pdd
+                                                                            LEFT JOIN tp_pc_procedure p ON pdd.procedureid = p.procedureid
+                                                                           WHERE pdd.barcode = pd.barcode
+                                                                            AND  p.modeltype = '-5'
+                                                                            AND pdd.valueflag = 1  
+                                                                            and p.procedureid not in(126,152) 
+                                                                            and pdd.createtime >=plans1.begintime )
+                                                                               GROUP BY pd.goodsid,pd.logoid    
+                                                                    ) t
                                                    RIGHT JOIN (SELECT pp.goodsid,pp.logoid,pp.quantity
                                                                FROM tp_pm_production_plan pp
                                                                LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid
@@ -132,23 +235,27 @@ public class GetLogoData : IHttpHandler, IReadOnlySessionState
                                                                 AND pp.endtime > SYSDATE
                                                                 and pp.valueflag = 1 AND pp.CONTROLRANGE = 1) tt
                                                      ON t.logoid = tt.logoid
-                                                  GROUP BY  t.goodsid,tt.goodsid,t.logoid,tt.logoid,tt.quantity ,t.changenum
+                                                  GROUP BY  t.goodsid,tt.goodsid,t.logoid,tt.logoid,tt.quantity
+                                      
+                                      
                                                  ) linshi  ON linshi.logoid = l.logoid
                                      WHERE l.valueflag = '1' AND l.accountid = @ACCOUNTID@
                                      ORDER BY l.displayno",
-                            new CDAParameter("BARCODE", context.Request["barCode"]),
-                            new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]),
-                            new CDAParameter("GOODSID", planData.Rows[0]["GOODSID"].ToString())
-                        );
+                        new CDAParameter("BARCODE", context.Request["barCode"]),
+                        new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]),
+                        new CDAParameter("GOODSID", planData.Rows[0]["GOODSID"].ToString())
+                    );
                     context.Response.Write(new JsonResult() { success = true, message = "操作成功!", rows = plansTable }.ToJson());
                 }
                 else
                 {
                     DataTable plansTable = conn.ExecuteDatatable(@"
                                 SELECT l.logoid AS id
-                                          ,CASE
-                                               WHEN linshi.residuequantity IS NOT NULL THEN
+                                          ,CASE 
+                                               WHEN linshi.residuequantity IS NOT NULL AND linshi.quantity IS NOT NULL  THEN
                                                  l.logoname || '[' || t2.materialcode || ']' || ' 剩余[' || linshi.residuequantity || ']'
+                                                WHEN linshi.residuequantity IS  NULL AND linshi.quantity IS NOT NULL THEN
+                                                 l.logoname || '[' || t2.materialcode || ']' || ' 剩余[' || linshi.quantity || ']'
                                                ELSE
                                                 l.logoname || '[' || t2.materialcode || ']'
                                            END AS NAME
@@ -169,9 +276,9 @@ public class GetLogoData : IHttpHandler, IReadOnlySessionState
                                       LEFT JOIN ( 
                                         SELECT case when t.goodsid is null then tt.goodsid  else t.goodsid end as goodsid 
                                               ,case when t.logoid is null then tt.logoid else t.logoid end as logoid 
-                                              ,case when t.changenum is null then sum(0) else SUM(t.changenum) end as changenum 
+                                              , SUM(t.changenum)  as changenum 
                                                ,tt.quantity
-                                                ,case when t.changenum is null then  tt.quantity else tt.quantity - SUM(t.changenum) end as residuequantity 
+                                                , tt.quantity - SUM(t.changenum) as residuequantity 
                                                    FROM (SELECT ip.goodsid,ip.logoid,COUNT(distinct l.barcode) changenum
                                                            FROM tp_pm_logochangedrecord l
                                                            right JOIN tp_pm_groutingdailydetail ip ON l.barcode = ip.barcode 
@@ -193,30 +300,40 @@ public class GetLogoData : IHttpHandler, IReadOnlySessionState
                                                                   WHERE s.barcode = l.barcode AND s.valueflag = 1 AND s.createtime >= l.createtime)
                                                             GROUP BY ip.goodsid,ip.logoid 
                                                           UNION ALL
-                                                          --生产数据该产品商标在装配环节保存的数量(装配环节没有变更商标) 
-                                                         SELECT  pd.goodsid ,pd.logoid ,COUNT(distinct pd.barcode) changenum
-                                                           FROM tp_pm_productiondata pd  
-                                                           LEFT JOIN tp_pc_procedure p ON pd.procedureid = p.procedureid 
-                                                           left join (SELECT pp.goodsid,pp.logoid,pp.quantity,gdd.materialcode,pp.begintime ,pp.endtime
-                                                                            FROM tp_pm_production_plan pp
-                                                                            LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid  
-                                                                            WHERE gdd.barcode = @BARCODE@
-                                                                            AND pp.begintime <= SYSDATE
-                                                                            AND pp.endtime > SYSDATE AND pp.CONTROLRANGE = 1 AND pp.VALUEFLAG = 1 ) plans1 on plans1.goodsid = pd.goodsid and plans1.logoid = pd.logoid
-                                                                      WHERE  pd.createtime >= plans1.begintime
-                                                                      and pd.createtime < plans1.endtime
-                                                                      and pd.valueflag = 1 
-                                                                      and p.modeltype = '-5' 
-                                                                      and p.procedureid not in(126,152) 
-                                                                      AND NOT EXISTS (SELECT s.barcode
-                                                                          FROM tp_pm_logochangedrecord s
-                                                                          LEFT JOIN tp_pc_procedure p ON s.procedureid = p.procedureid
-                                                                         WHERE s.barcode = pd.barcode
-                                                                          AND  p.modeltype = '-5' 
-                                                                          and p.procedureid not in(126,152) 
-                                                                          --AND  s.oldlogoid = pd.logoid
-                                                                          AND  s.oldlogoid <> s.newlogoid)  
-                                                                    GROUP BY pd.goodsid,pd.logoid) t
+                                                            --生产数据该产品商标在装配环节保存的数量(装配环节没有变更商标) 
+                                                           SELECT  pd.goodsid ,pd.logoid ,COUNT(distinct pd.barcode) changenum
+                                                             FROM TP_PM_FINISHEDPRODUCT pd  
+                                                            -- LEFT JOIN tp_pc_procedure p ON pd.procedureid = p.procedureid 
+                                                             left join (SELECT pp.goodsid,pp.logoid,pp.quantity,gdd.materialcode,pp.begintime ,pp.endtime
+                                                                              FROM tp_pm_production_plan pp
+                                                                              LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid  
+                                                                              WHERE gdd.barcode = @BARCODE@
+                                                                              AND pp.begintime <= SYSDATE
+                                                                              AND pp.endtime > SYSDATE AND pp.CONTROLRANGE = 1 AND pp.VALUEFLAG = 1 ) plans1 on plans1.goodsid = pd.goodsid and plans1.logoid = pd.logoid
+                                                                        WHERE  pd.valueflag = 1  
+                                                                        and pd.goodsid =@GOODSID@
+                                                                       -- and p.modeltype = '-5' 
+                                                                       -- and p.procedureid not in(126,152) 
+                                                                         and pd.createtime >= trunc(plans1.begintime)
+                                                                        and pd.createtime < trunc(plans1.endtime)
+                                                                        AND NOT EXISTS (SELECT s.barcode
+                                                                            FROM tp_pm_logochangedrecord s
+                                                                            LEFT JOIN tp_pc_procedure p ON s.procedureid = p.procedureid
+                                                                           WHERE s.barcode = pd.barcode
+                                                                            AND  p.modeltype = '-5' 
+                                                                            and p.procedureid not in(126,152) 
+                                                                            --AND  s.oldlogoid = pd.logoid
+                                                                            AND  s.oldlogoid <> s.newlogoid)
+                                                                         AND  EXISTS (SELECT pdd.barcode
+                                                                            FROM tp_pm_productiondata pdd
+                                                                            LEFT JOIN tp_pc_procedure p ON pdd.procedureid = p.procedureid
+                                                                           WHERE pdd.barcode = pd.barcode
+                                                                            AND  p.modeltype = '-5'
+                                                                            AND pdd.valueflag = 1  
+                                                                            and p.procedureid not in(126,152) 
+                                                                            and pdd.createtime >=plans1.begintime )
+                                                                               GROUP BY pd.goodsid,pd.logoid                                                           
+                                                    ) t
                                                    RIGHT JOIN (SELECT pp.goodsid,pp.logoid,pp.quantity
                                                                FROM tp_pm_production_plan pp
                                                                LEFT JOIN tp_pm_groutingdailydetail gdd ON pp.goodsid = gdd.goodsid
@@ -225,7 +342,7 @@ public class GetLogoData : IHttpHandler, IReadOnlySessionState
                                                                 AND pp.endtime > SYSDATE
                                                                 and pp.valueflag = 1 AND pp.CONTROLRANGE = 1) tt
                                                      ON t.logoid = tt.logoid
-                                                   GROUP BY  t.goodsid,tt.goodsid,t.logoid,tt.logoid,tt.quantity ,t.changenum
+                                                   GROUP BY  t.goodsid,tt.goodsid,t.logoid,tt.logoid,tt.quantity 
                                                  ) linshi  ON linshi.logoid = l.logoid
                                      WHERE l.valueflag = '1' AND l.accountid = @ACCOUNTID@
                                      ORDER BY l.displayno",