Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

姜永辉 2 жил өмнө
parent
commit
8d1f03edd1

+ 29 - 18
src/main/java/com/dk/mdm/mapper/sale/OrderItemMapper.xml

@@ -286,31 +286,42 @@
 
     <!-- 根据条件进行查询(出库用) -->
     <select id="selectByCondForOut" resultMap="BaseResultMapResponse">
-        SELECT t.item_id                                        as "fromItemId",
-               t.order_id                                       as "fromId",
+        SELECT t.item_id                                  as "fromItemId",
+               t.order_id                                 as "fromId",
                t.item_index,
                t.sku_id,
-               tmgs.sku_code                                       as "skuCode",
-               tmgs.sku_model                                      as "skuModel",
-               tmgs.sku_name                                       as "skuName",
-               t.item_qty                                       as "orderQty",
-               t.item_qty - t.outing_qty                     as "canOutingQty",
-               t.item_qty - t.outing_qty                     as outing_qty,
-               t.price_sale                                     as "priceOut",
+               tmgs.sku_code                              as "skuCode",
+               tmgs.sku_model                             as "skuModel",
+               tmgs.sku_name                              as "skuName",
+               t.item_qty                                 as "orderQty",
+               t.item_qty - t.outing_qty                  as "canOutingQty",
+               t.item_qty - t.outing_qty                  as outing_qty,
+               t.price_sale                               as "priceOut",
                t.price_sale * (t.item_qty - t.outing_qty) as outing_amt,
                t.non_std_code,
                t.remarks,
-               tpi.inv_id                                          as "invId",
-               tpi.wh_id                                           as "whId",
-               tpi.inv_qty                                         as "invQty",
-               tpi.usable_qty                                      as "usableQty",
-               tmw.wh_name                                         as "whName"
+               i.inv_id                                   as "invId",
+               i.wh_id                                    as "whId",
+               i.inv_qty                                  as "invQty",
+               i.usable_qty                               as "usableQty",
+               i.wh_name                                  as "whName"
         FROM dkic_b.t_psi_order_item as t
                  inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
-                 left join dkic_b.t_psi_inventory as tpi
-                           on tpi.sku_id = t.sku_id and tpi.non_std_code = t.non_std_code and
-                              tpi.cp_id = t.cp_id
-                 left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
+                 left join(SELECT T.*
+                           FROM (select tpi.inv_id,
+                                        tpi.wh_id,
+                                        tpi.inv_qty,
+                                        tpi.usable_qty,
+                                        tpi.sku_id,
+                                        tpi.non_std_code,
+                                        tpi.cp_id,
+                                        tmw.wh_name,
+                                        rank()
+                                        over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
+                                 from dkic_b.t_psi_inventory as tpi
+                                          left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id) T
+                           WHERE T.RK = 1) as i
+                          on i.sku_id = t.sku_id and i.non_std_code = t.non_std_code and i.cp_id = t.cp_id
         where t.flg_valid
           and t.item_qty > t.outing_qty
           and t.order_id = #{orderId}::uuid