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

pms 查询物料时拼接SAP主数据

zhangcl 1 долоо хоног өмнө
parent
commit
edc19f5502

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicematerial/IotDeviceMaterialServiceImpl.java

@@ -380,7 +380,7 @@ public class IotDeviceMaterialServiceImpl implements IotDeviceMaterialService {
                         material.setFactory(StrUtil.EMPTY);
                         material.setStorageLocation(StrUtil.EMPTY);
                         material.setCostCenter(StrUtil.EMPTY);
-                        material.setMaterialSource("SAP主数据");
+                        material.setMaterialSource("sap主数据");
                     }
                 });
                 deviceMaterials.forEach(bomMaterial -> {

+ 85 - 28
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotWorkOrderMaterialMapper.xml

@@ -44,6 +44,77 @@
             AND lo.material_code LIKE concat(concat("%",#{materialCode}),"%")
         </if>
 
+        UNION ALL
+
+        -- sap库存物料
+        SELECT
+        sap.factory_id AS factoryId,
+        0 AS costCenterId,
+        sap.storage_location_id AS storageLocationId,
+        sap.material_code AS materialCode,
+        sap.material_name AS materialName,
+        sap.unit_price AS unitPrice,
+        sap.quantity AS totalInventoryQuantity,
+        sap.unit AS unit,
+        'sap库存' AS materialSource
+        FROM
+        rq_iot_sap_stock sap
+        WHERE
+        1=1
+        <if test="materialCodes != null and materialCodes.size &gt; 0">
+            AND sap.material_code IN
+            <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+        <if test="factoryIds != null and factoryIds.size &gt; 0">
+            AND sap.factory_id IN
+            <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+        <if test="stockLocationIds != null and stockLocationIds.size &gt; 0">
+            AND sap.storage_location_id IN
+            <foreach collection="stockLocationIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+        <if test="materialName!=null and materialName!=''">
+            AND sap.material_name LIKE concat(concat("%",#{materialName}),"%")
+        </if>
+        <if test="materialCode!=null and materialCode!=''">
+            AND sap.material_code LIKE concat(concat("%",#{materialCode}),"%")
+        </if>
+
+        UNION ALL
+        -- sap主数据
+        SELECT
+        0 AS factoryId,
+        0 AS costCenterId,
+        0 AS storageLocationId,
+        m.`code` AS materialCode,
+        m.`name` AS materialName,
+        m.unit_price AS unitPrice,
+        0 AS totalInventoryQuantity,
+        m.unit AS unit,
+        'sap主数据' AS materialSource
+        FROM
+        rq_iot_material m
+        WHERE
+        1=1
+        <if test="materialCodes != null and materialCodes.size &gt; 0">
+            AND m.`code` IN
+            <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+        <if test="materialName!=null and materialName!=''">
+            AND m.`name` LIKE concat(concat("%",#{materialName}),"%")
+        </if>
+        <if test="materialCode!=null and materialCode!=''">
+            AND m.`code` LIKE concat(concat("%",#{materialCode}),"%")
+        </if>
+
         UNION ALL
         -- 本地库存物料
         SELECT
@@ -86,7 +157,6 @@
         </if>
 
         UNION ALL
-
         -- sap库存物料
         SELECT
         sap.factory_id AS factoryId,
@@ -103,7 +173,7 @@
         WHERE
         1=1
         <if test="materialCodes != null and materialCodes.size &gt; 0">
-            AND sap.material_code IN
+            AND sap.material_code NOT IN
             <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
                 #{key}
             </foreach>
@@ -128,46 +198,33 @@
         </if>
 
         UNION ALL
-        -- sap库存物料
+        -- sap主数据
         SELECT
-        sap.factory_id AS factoryId,
+        0 AS factoryId,
         0 AS costCenterId,
-        sap.storage_location_id AS storageLocationId,
-        sap.material_code AS materialCode,
-        sap.material_name AS materialName,
-        sap.unit_price AS unitPrice,
-        sap.quantity AS totalInventoryQuantity,
-        sap.unit AS unit,
-        'sap库存' AS materialSource
+        0 AS storageLocationId,
+        m.`code` AS materialCode,
+        m.`name` AS materialName,
+        m.unit_price AS unitPrice,
+        0 AS totalInventoryQuantity,
+        m.unit AS unit,
+        'sap主数据' AS materialSource
         FROM
-        rq_iot_sap_stock sap
+        rq_iot_material m
         WHERE
         1=1
         <if test="materialCodes != null and materialCodes.size &gt; 0">
-            AND sap.material_code NOT IN
+            AND m.`code` NOT IN
             <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
                 #{key}
             </foreach>
         </if>
-        <if test="factoryIds != null and factoryIds.size &gt; 0">
-            AND sap.factory_id IN
-            <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
-                #{key}
-            </foreach>
-        </if>
-        <if test="stockLocationIds != null and stockLocationIds.size &gt; 0">
-            AND sap.storage_location_id IN
-            <foreach collection="stockLocationIds" index="index" item="key" open="(" separator="," close=")">
-                #{key}
-            </foreach>
-        </if>
         <if test="materialName!=null and materialName!=''">
-            AND sap.material_name LIKE concat(concat("%",#{materialName}),"%")
+            AND m.`name` LIKE concat(concat("%",#{materialName}),"%")
         </if>
         <if test="materialCode!=null and materialCode!=''">
-            AND sap.material_code LIKE concat(concat("%",#{materialCode}),"%")
+            AND m.`code` LIKE concat(concat("%",#{materialCode}),"%")
         </if>
 
-
     </select>
 </mapper>