|
@@ -2,9 +2,9 @@
|
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
<mapper namespace="cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialMapper">
|
|
|
|
|
|
+ <!--
|
|
|
<select id="selectMaterialsBySapOrg"
|
|
|
resultType="cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialRespVO">
|
|
|
- -- 本地库存中与bom节点关联的物料
|
|
|
SELECT
|
|
|
lo.factory_id AS factoryId,
|
|
|
lo.cost_center_id AS costCenterId,
|
|
@@ -45,7 +45,75 @@
|
|
|
</if>
|
|
|
|
|
|
UNION ALL
|
|
|
- -- 本地库存物料
|
|
|
+
|
|
|
+ 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 > 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 > 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 > 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
|
|
|
+ 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 > 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
|
|
|
lo.factory_id AS factoryId,
|
|
|
lo.cost_center_id AS costCenterId,
|
|
@@ -86,8 +154,6 @@
|
|
|
</if>
|
|
|
|
|
|
UNION ALL
|
|
|
-
|
|
|
- -- sap库存物料
|
|
|
SELECT
|
|
|
sap.factory_id AS factoryId,
|
|
|
0 AS costCenterId,
|
|
@@ -103,7 +169,7 @@
|
|
|
WHERE
|
|
|
1=1
|
|
|
<if test="materialCodes != null and materialCodes.size > 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,7 +194,81 @@
|
|
|
</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 > 0">
|
|
|
+ AND m.`code` NOT 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>
|
|
|
+
|
|
|
+ </select> -->
|
|
|
+
|
|
|
+ <select id="selectMaterialsBySapOrg"
|
|
|
+ resultType="cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialRespVO">
|
|
|
+ -- 1. 本地库存中与bom节点关联的物料(IN materialCodes)
|
|
|
+ SELECT
|
|
|
+ lo.factory_id AS factoryId,
|
|
|
+ lo.cost_center_id AS costCenterId,
|
|
|
+ lo.storage_location_id AS storageLocationId,
|
|
|
+ lo.material_code AS materialCode,
|
|
|
+ lo.material_name AS materialName,
|
|
|
+ lo.unit_price AS unitPrice,
|
|
|
+ lo.quantity AS totalInventoryQuantity,
|
|
|
+ lo.unit AS unit,
|
|
|
+ '本地库存' AS materialSource,
|
|
|
+ 1 AS sortOrder -- 添加排序字段
|
|
|
+ FROM
|
|
|
+ rq_iot_lock_stock lo
|
|
|
+ WHERE
|
|
|
+ 1=1
|
|
|
+ <if test="materialCodes != null and materialCodes.size > 0">
|
|
|
+ AND lo.material_code IN
|
|
|
+ <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="factoryIds != null and factoryIds.size > 0">
|
|
|
+ AND lo.factory_id IN
|
|
|
+ <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="costCenterIds != null and costCenterIds.size > 0">
|
|
|
+ AND lo.cost_center_id IN
|
|
|
+ <foreach collection="costCenterIds" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="materialName!=null and materialName!=''">
|
|
|
+ AND lo.material_name LIKE concat(concat("%",#{materialName}),"%")
|
|
|
+ </if>
|
|
|
+ <if test="materialCode!=null and materialCode!=''">
|
|
|
+ AND lo.material_code LIKE concat(concat("%",#{materialCode}),"%")
|
|
|
+ </if>
|
|
|
+
|
|
|
+ UNION ALL
|
|
|
+
|
|
|
+ -- 2. sap库存物料(IN materialCodes)
|
|
|
SELECT
|
|
|
sap.factory_id AS factoryId,
|
|
|
0 AS costCenterId,
|
|
@@ -138,24 +278,25 @@
|
|
|
sap.unit_price AS unitPrice,
|
|
|
sap.quantity AS totalInventoryQuantity,
|
|
|
sap.unit AS unit,
|
|
|
- 'sap库存' AS materialSource
|
|
|
+ 'sap库存' AS materialSource,
|
|
|
+ 2 AS sortOrder -- 添加排序字段
|
|
|
FROM
|
|
|
rq_iot_sap_stock sap
|
|
|
WHERE
|
|
|
1=1
|
|
|
- <if test="materialCodes != null and materialCodes.size > 0">
|
|
|
- AND sap.material_code NOT IN
|
|
|
+ <if test="materialCodes != null and materialCodes.size > 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 > 0">
|
|
|
+ <if test="factoryIds != null and factoryIds.size > 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 > 0">
|
|
|
+ <if test="stockLocationIds != null and stockLocationIds.size > 0">
|
|
|
AND sap.storage_location_id IN
|
|
|
<foreach collection="stockLocationIds" index="index" item="key" open="(" separator="," close=")">
|
|
|
#{key}
|
|
@@ -168,6 +309,149 @@
|
|
|
AND sap.material_code LIKE concat(concat("%",#{materialCode}),"%")
|
|
|
</if>
|
|
|
|
|
|
+ UNION ALL
|
|
|
+ -- 3. sap主数据(IN materialCodes)
|
|
|
+ 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,
|
|
|
+ 3 AS sortOrder -- 添加排序字段
|
|
|
+ FROM
|
|
|
+ rq_iot_material m
|
|
|
+ WHERE
|
|
|
+ 1=1
|
|
|
+ <if test="materialCodes != null and materialCodes.size > 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>
|
|
|
+
|
|
|
+ <if test="materialCodes != null and materialCodes.size > 0">
|
|
|
+ UNION ALL
|
|
|
+ -- 4. 本地库存物料(NOT IN materialCodes)
|
|
|
+ SELECT
|
|
|
+ lo.factory_id AS factoryId,
|
|
|
+ lo.cost_center_id AS costCenterId,
|
|
|
+ lo.storage_location_id AS storageLocationId,
|
|
|
+ lo.material_code AS materialCode,
|
|
|
+ lo.material_name AS materialName,
|
|
|
+ lo.unit_price AS unitPrice,
|
|
|
+ lo.quantity AS totalInventoryQuantity,
|
|
|
+ lo.unit AS unit,
|
|
|
+ '本地库存' AS materialSource,
|
|
|
+ 4 AS sortOrder -- 添加排序字段
|
|
|
+ FROM
|
|
|
+ rq_iot_lock_stock lo
|
|
|
+ WHERE
|
|
|
+ 1=1
|
|
|
+ AND lo.material_code NOT IN
|
|
|
+ <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ <if test="factoryIds != null and factoryIds.size > 0">
|
|
|
+ AND lo.factory_id IN
|
|
|
+ <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="costCenterIds != null and costCenterIds.size > 0">
|
|
|
+ AND lo.cost_center_id IN
|
|
|
+ <foreach collection="costCenterIds" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="materialName!=null and materialName!=''">
|
|
|
+ AND lo.material_name LIKE concat(concat("%",#{materialName}),"%")
|
|
|
+ </if>
|
|
|
+ <if test="materialCode!=null and materialCode!=''">
|
|
|
+ AND lo.material_code LIKE concat(concat("%",#{materialCode}),"%")
|
|
|
+ </if>
|
|
|
+
|
|
|
+ UNION ALL
|
|
|
+ -- 5. sap库存物料(NOT IN materialCodes)
|
|
|
+ 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,
|
|
|
+ 5 AS sortOrder -- 添加排序字段
|
|
|
+ FROM
|
|
|
+ rq_iot_sap_stock sap
|
|
|
+ WHERE
|
|
|
+ 1=1
|
|
|
+ AND sap.material_code NOT IN
|
|
|
+ <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ <if test="factoryIds != null and factoryIds.size > 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 > 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
|
|
|
+ -- 6. sap主数据(NOT IN materialCodes)
|
|
|
+ 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,
|
|
|
+ 6 AS sortOrder -- 添加排序字段
|
|
|
+ FROM
|
|
|
+ rq_iot_material m
|
|
|
+ WHERE
|
|
|
+ 1=1
|
|
|
+ AND m.`code` NOT IN
|
|
|
+ <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
|
|
|
+ #{key}
|
|
|
+ </foreach>
|
|
|
+ <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>
|
|
|
+ </if>
|
|
|
|
|
|
+ ORDER BY sortOrder, materialCode -- 按排序字段和物料编码排序
|
|
|
</select>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
</mapper>
|