IotWorkOrderMaterialMapper.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. -- sap库存物料
  47. SELECT
  48. sap.factory_id AS factoryId,
  49. 0 AS costCenterId,
  50. sap.storage_location_id AS storageLocationId,
  51. sap.material_code AS materialCode,
  52. sap.material_name AS materialName,
  53. sap.unit_price AS unitPrice,
  54. sap.quantity AS totalInventoryQuantity,
  55. sap.unit AS unit,
  56. 'sap库存' AS materialSource
  57. FROM
  58. rq_iot_sap_stock sap
  59. WHERE
  60. 1=1
  61. <if test="materialCodes != null and materialCodes.size &gt; 0">
  62. AND sap.material_code 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 sap.factory_id IN
  69. <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
  70. #{key}
  71. </foreach>
  72. </if>
  73. <if test="stockLocationIds != null and stockLocationIds.size &gt; 0">
  74. AND sap.storage_location_id IN
  75. <foreach collection="stockLocationIds" index="index" item="key" open="(" separator="," close=")">
  76. #{key}
  77. </foreach>
  78. </if>
  79. <if test="materialName!=null and materialName!=''">
  80. AND sap.material_name LIKE concat(concat("%",#{materialName}),"%")
  81. </if>
  82. <if test="materialCode!=null and materialCode!=''">
  83. AND sap.material_code LIKE concat(concat("%",#{materialCode}),"%")
  84. </if>
  85. UNION ALL
  86. -- sap主数据
  87. SELECT
  88. 0 AS factoryId,
  89. 0 AS costCenterId,
  90. 0 AS storageLocationId,
  91. m.`code` AS materialCode,
  92. m.`name` AS materialName,
  93. m.unit_price AS unitPrice,
  94. 0 AS totalInventoryQuantity,
  95. m.unit AS unit,
  96. 'sap主数据' AS materialSource
  97. FROM
  98. rq_iot_material m
  99. WHERE
  100. 1=1
  101. <if test="materialCodes != null and materialCodes.size &gt; 0">
  102. AND m.`code` IN
  103. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  104. #{key}
  105. </foreach>
  106. </if>
  107. <if test="materialName!=null and materialName!=''">
  108. AND m.`name` LIKE concat(concat("%",#{materialName}),"%")
  109. </if>
  110. <if test="materialCode!=null and materialCode!=''">
  111. AND m.`code` LIKE concat(concat("%",#{materialCode}),"%")
  112. </if>
  113. UNION ALL
  114. -- 本地库存物料
  115. SELECT
  116. lo.factory_id AS factoryId,
  117. lo.cost_center_id AS costCenterId,
  118. lo.storage_location_id AS storageLocationId,
  119. lo.material_code AS materialCode,
  120. lo.material_name AS materialName,
  121. lo.unit_price AS unitPrice,
  122. lo.quantity AS totalInventoryQuantity,
  123. lo.unit AS unit,
  124. '本地库存' AS materialSource
  125. FROM
  126. rq_iot_lock_stock lo
  127. WHERE
  128. 1=1
  129. <if test="materialCodes != null and materialCodes.size &gt; 0">
  130. AND lo.material_code NOT IN
  131. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  132. #{key}
  133. </foreach>
  134. </if>
  135. <if test="factoryIds != null and factoryIds.size &gt; 0">
  136. AND lo.factory_id IN
  137. <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
  138. #{key}
  139. </foreach>
  140. </if>
  141. <if test="costCenterIds != null and costCenterIds.size &gt; 0">
  142. AND lo.cost_center_id IN
  143. <foreach collection="costCenterIds" index="index" item="key" open="(" separator="," close=")">
  144. #{key}
  145. </foreach>
  146. </if>
  147. <if test="materialName!=null and materialName!=''">
  148. AND lo.material_name LIKE concat(concat("%",#{materialName}),"%")
  149. </if>
  150. <if test="materialCode!=null and materialCode!=''">
  151. AND lo.material_code LIKE concat(concat("%",#{materialCode}),"%")
  152. </if>
  153. UNION ALL
  154. -- sap库存物料
  155. SELECT
  156. sap.factory_id AS factoryId,
  157. 0 AS costCenterId,
  158. sap.storage_location_id AS storageLocationId,
  159. sap.material_code AS materialCode,
  160. sap.material_name AS materialName,
  161. sap.unit_price AS unitPrice,
  162. sap.quantity AS totalInventoryQuantity,
  163. sap.unit AS unit,
  164. 'sap库存' AS materialSource
  165. FROM
  166. rq_iot_sap_stock sap
  167. WHERE
  168. 1=1
  169. <if test="materialCodes != null and materialCodes.size &gt; 0">
  170. AND sap.material_code NOT IN
  171. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  172. #{key}
  173. </foreach>
  174. </if>
  175. <if test="factoryIds != null and factoryIds.size &gt; 0">
  176. AND sap.factory_id IN
  177. <foreach collection="factoryIds" index="index" item="key" open="(" separator="," close=")">
  178. #{key}
  179. </foreach>
  180. </if>
  181. <if test="stockLocationIds != null and stockLocationIds.size &gt; 0">
  182. AND sap.storage_location_id IN
  183. <foreach collection="stockLocationIds" index="index" item="key" open="(" separator="," close=")">
  184. #{key}
  185. </foreach>
  186. </if>
  187. <if test="materialName!=null and materialName!=''">
  188. AND sap.material_name LIKE concat(concat("%",#{materialName}),"%")
  189. </if>
  190. <if test="materialCode!=null and materialCode!=''">
  191. AND sap.material_code LIKE concat(concat("%",#{materialCode}),"%")
  192. </if>
  193. UNION ALL
  194. -- sap主数据
  195. SELECT
  196. 0 AS factoryId,
  197. 0 AS costCenterId,
  198. 0 AS storageLocationId,
  199. m.`code` AS materialCode,
  200. m.`name` AS materialName,
  201. m.unit_price AS unitPrice,
  202. 0 AS totalInventoryQuantity,
  203. m.unit AS unit,
  204. 'sap主数据' AS materialSource
  205. FROM
  206. rq_iot_material m
  207. WHERE
  208. 1=1
  209. <if test="materialCodes != null and materialCodes.size &gt; 0">
  210. AND m.`code` NOT IN
  211. <foreach collection="materialCodes" index="index" item="key" open="(" separator="," close=")">
  212. #{key}
  213. </foreach>
  214. </if>
  215. <if test="materialName!=null and materialName!=''">
  216. AND m.`name` LIKE concat(concat("%",#{materialName}),"%")
  217. </if>
  218. <if test="materialCode!=null and materialCode!=''">
  219. AND m.`code` LIKE concat(concat("%",#{materialCode}),"%")
  220. </if>
  221. </select>
  222. </mapper>