IotWorkOrderMaterialMapper.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialMapper">
  4. <select id="selectMaterialsBySapOrg"
  5. resultType="cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.vo.IotMainWorkOrderBomMaterialRespVO">
  6. -- 本地库存中与bom节点关联的物料
  7. SELECT
  8. lo.factory_id AS factoryId,
  9. lo.cost_center_id AS costCenterId,
  10. lo.storage_location_id AS storageLocationId,
  11. lo.material_code AS materialCode,
  12. lo.material_name AS materialName,
  13. lo.unit_price AS unitPrice,
  14. lo.quantity AS totalInventoryQuantity,
  15. lo.unit AS unit,
  16. '本地库存' AS materialSource
  17. FROM
  18. rq_iot_lock_stock lo
  19. WHERE
  20. 1=1
  21. <if test="materialCodes != null and materialCodes.size &gt; 0">
  22. AND lo.material_code IN
  23. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  24. #{key}
  25. </foreach>
  26. </if>
  27. <if test="factoryIds != null and factoryIds.size &gt; 0">
  28. AND lo.factory_id IN
  29. <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
  30. #{key}
  31. </foreach>
  32. </if>
  33. <if test="costCenterIds != null and costCenterIds.size &gt; 0">
  34. AND lo.cost_center_id IN
  35. <foreach collection="costCenterIds" index="index" item="key" open="(" separator="," close=")">
  36. #{key}
  37. </foreach>
  38. </if>
  39. <if test="materialName!=null and materialName!=''">
  40. AND lo.material_name LIKE concat(concat("%",#{materialName}),"%")
  41. </if>
  42. <if test="materialCode!=null and materialCode!=''">
  43. AND lo.material_code LIKE concat(concat("%",#{materialCode}),"%")
  44. </if>
  45. UNION ALL
  46. -- 本地库存物料
  47. SELECT
  48. lo.factory_id AS factoryId,
  49. lo.cost_center_id AS costCenterId,
  50. lo.storage_location_id AS storageLocationId,
  51. lo.material_code AS materialCode,
  52. lo.material_name AS materialName,
  53. lo.unit_price AS unitPrice,
  54. lo.quantity AS totalInventoryQuantity,
  55. lo.unit AS unit,
  56. '本地库存' AS materialSource
  57. FROM
  58. rq_iot_lock_stock lo
  59. WHERE
  60. 1=1
  61. <if test="materialCodes != null and materialCodes.size &gt; 0">
  62. AND lo.material_code NOT IN
  63. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  64. #{key}
  65. </foreach>
  66. </if>
  67. <if test="factoryIds != null and factoryIds.size &gt; 0">
  68. AND lo.factory_id IN
  69. <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
  70. #{key}
  71. </foreach>
  72. </if>
  73. <if test="costCenterIds != null and costCenterIds.size &gt; 0">
  74. AND lo.cost_center_id IN
  75. <foreach collection="costCenterIds" index="index" item="key" open="(" separator="," close=")">
  76. #{key}
  77. </foreach>
  78. </if>
  79. <if test="materialName!=null and materialName!=''">
  80. AND lo.material_name LIKE concat(concat("%",#{materialName}),"%")
  81. </if>
  82. <if test="materialCode!=null and materialCode!=''">
  83. AND lo.material_code LIKE concat(concat("%",#{materialCode}),"%")
  84. </if>
  85. UNION ALL
  86. -- sap库存物料
  87. SELECT
  88. sap.factory_id AS factoryId,
  89. 0 AS costCenterId,
  90. sap.storage_location_id AS storageLocationId,
  91. sap.material_code AS materialCode,
  92. sap.material_name AS materialName,
  93. sap.unit_price AS unitPrice,
  94. sap.quantity AS totalInventoryQuantity,
  95. sap.unit AS unit,
  96. 'sap库存' AS materialSource
  97. FROM
  98. rq_iot_sap_stock sap
  99. WHERE
  100. 1=1
  101. <if test="materialCodes != null and materialCodes.size &gt; 0">
  102. AND sap.material_code IN
  103. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  104. #{key}
  105. </foreach>
  106. </if>
  107. <if test="factoryIds != null and factoryIds.size &gt; 0">
  108. AND sap.factory_id IN
  109. <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
  110. #{key}
  111. </foreach>
  112. </if>
  113. <if test="stockLocationIds != null and stockLocationIds.size &gt; 0">
  114. AND sap.storage_location_id IN
  115. <foreach collection="stockLocationIds" index="index" item="key" open="(" separator="," close=")">
  116. #{key}
  117. </foreach>
  118. </if>
  119. <if test="materialName!=null and materialName!=''">
  120. AND sap.material_name LIKE concat(concat("%",#{materialName}),"%")
  121. </if>
  122. <if test="materialCode!=null and materialCode!=''">
  123. AND sap.material_code LIKE concat(concat("%",#{materialCode}),"%")
  124. </if>
  125. UNION ALL
  126. -- sap库存物料
  127. SELECT
  128. sap.factory_id AS factoryId,
  129. 0 AS costCenterId,
  130. sap.storage_location_id AS storageLocationId,
  131. sap.material_code AS materialCode,
  132. sap.material_name AS materialName,
  133. sap.unit_price AS unitPrice,
  134. sap.quantity AS totalInventoryQuantity,
  135. sap.unit AS unit,
  136. 'sap库存' AS materialSource
  137. FROM
  138. rq_iot_sap_stock sap
  139. WHERE
  140. 1=1
  141. <if test="materialCodes != null and materialCodes.size &gt; 0">
  142. AND sap.material_code NOT IN
  143. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  144. #{key}
  145. </foreach>
  146. </if>
  147. <if test="factoryIds != null and factoryIds.size &gt; 0">
  148. AND sap.factory_id IN
  149. <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
  150. #{key}
  151. </foreach>
  152. </if>
  153. <if test="stockLocationIds != null and stockLocationIds.size &gt; 0">
  154. AND sap.storage_location_id IN
  155. <foreach collection="stockLocationIds" index="index" item="key" open="(" separator="," close=")">
  156. #{key}
  157. </foreach>
  158. </if>
  159. <if test="materialName!=null and materialName!=''">
  160. AND sap.material_name LIKE concat(concat("%",#{materialName}),"%")
  161. </if>
  162. <if test="materialCode!=null and materialCode!=''">
  163. AND sap.material_code LIKE concat(concat("%",#{materialCode}),"%")
  164. </if>
  165. </select>
  166. </mapper>