DeliveryMapper.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.tld.mapper.DeliveryMapper">
  5. <!-- 查询销售交货单 -->
  6. <select id="getDelivery" resultType="com.tld.model.Delivery">
  7. select
  8. a.id,
  9. a.delivery_id,
  10. a.entry_number,
  11. a.material_id,
  12. a.wbs,
  13. a.measurement_id,
  14. a.gs_delivery_num,
  15. a.gs_cancel_num,
  16. a.out_num,
  17. b.company_number,
  18. b.bills_time,
  19. b.delivery_type,
  20. b.source_type,
  21. b.move_type,
  22. c.name as materialName,
  23. c.code as materialCode
  24. from tld_delivery a
  25. join tld_delivery_f b on a.delivery_id = b.delivery_id
  26. left join tld_material c on a.material_id = c.tld_id
  27. where (a.gs_delivery_num - a.gs_cancel_num) != a.out_num
  28. <if test="deliveryId != null and deliveryId != ''">
  29. and a.delivery_id = #{deliveryId}
  30. </if>
  31. <if test="materialId != null and materialId != ''">
  32. and a.material_id = #{materialId}
  33. </if>
  34. </select>
  35. <!-- 查询所有产成品库位 -->
  36. <select id="getStorageLocationCodeList" resultType="String">
  37. select
  38. CONCAT(CONCAT(GROUP_CONCAT(storage_location_code SEPARATOR ","),','), '111111,')
  39. from tld_storage_location where is_product = '1'
  40. </select>
  41. <!-- 查询指定库位跟物料的库存 -->
  42. <select id="getInventory" resultType="com.tld.model.Inventory">
  43. SELECT
  44. a.id,
  45. a.storage_location_code,
  46. a.wllb_class,
  47. a.library_type,
  48. a.material_id,
  49. (a.amount - ifnull(a.amount_lock, 0)) as amount,
  50. a.wbs,
  51. a.serial,
  52. a.wllb_code,
  53. a.produc_date,
  54. a.scrq,
  55. a.produc_batch,
  56. a.attribute,
  57. b.storage_location_name as storageLocationName
  58. FROM tld_inventory a
  59. LEFT JOIN tld_storage_location b on a.storage_location_code = b.storage_location_code
  60. WHERE #{storageLocationCode} LIKE CONCAT( '%', CONCAT( a.storage_location_code, ',' ), '%' )
  61. AND a.material_id = #{delivery.materialId} AND a.hold = '0'
  62. <if test="delivery.attribute != null and delivery.attribute != ''">
  63. and a.attribute = #{delivery.attribute}
  64. </if>
  65. ORDER BY
  66. a.produc_batch
  67. </select>
  68. <!-- 查询指定库存内容 -->
  69. <select id="getInventoryHalf" resultType="com.tld.model.AskGoods">
  70. SELECT
  71. a.id,
  72. a.storage_location_code,
  73. a.wllb_class,
  74. a.library_type,
  75. a.material_id,
  76. a.amount,
  77. a.amount_lock,
  78. a.wbs,
  79. a.serial,
  80. a.wllb_code,
  81. a.produc_date,
  82. a.scrq,
  83. a.produc_batch,
  84. a.attribute,
  85. b.storage_location_name as storageLocationName
  86. FROM tld_inventory a
  87. JOIN tld_material b on a.material_id = b.tld_id
  88. WHERE a.attribute = #{attribute} and a.produc_batch = #{producDate} and a.serial = #{serial} and b.code = #{wllbCode}
  89. </select>
  90. <!-- 查询指定库存被占用数量 -->
  91. <select id="getVitrual" resultType="int">
  92. select
  93. ifnull(sum(a.num), 0)
  94. from tld_ask_goods_vitrual a
  95. join tld_material b on a.wllb_code = b.code
  96. where a.storage_location_code = #{storageLocationCode} and b.code = #{wllbCode} and a.attribute = #{attribute} and a.produc_date = #{producBatch}
  97. </select>
  98. <!-- 修改销售单出库数量 -->
  99. <update id="updateDelivery">
  100. update tld_delivery set ifnull(out_num, 0) = #{num} where delivery_id = #{deliveryId} and material_id = #{materialId}
  101. </update>
  102. <!-- 产成品出库流水 -->
  103. <insert id="addRemovalHalf">
  104. insert into tld_removal_half(wllb_code,num,user_id,scrq,delivery_id,company_number,customer_code,storage_code,wbs)
  105. value(#{materialCode},#{outNum},#{userId},now(),#{deliveryId},#{companyNumber},#{customerCode},#{storageCode},#{wbs})
  106. </insert>
  107. <!-- 查询销售单父级信息 -->
  108. <select id="getDeliveryF" resultType="com.tld.model.Delivery">
  109. select
  110. id,
  111. delivery_id,
  112. delivery_code,
  113. company_number,
  114. customer_code,
  115. bills_time,
  116. delivery_type,
  117. source_type,
  118. move_type
  119. from tld_delivery_f where delivery_id = #{deliveryId}
  120. </select>
  121. <!-- 查询产成品属性 -->
  122. <select id="getAttribute" resultType="com.tld.model.Inventory">
  123. SELECT
  124. DISTINCT attribute,
  125. storage_location_code,
  126. wllb_code,
  127. produc_batch
  128. FROM tld_inventory
  129. WHERE CONCAT(#{storageLocationCode},'111111,') LIKE CONCAT( '%', CONCAT( storage_location_code, ',' ), '%' )
  130. AND material_id = #{delivery.materialId} AND hold = '0'
  131. </select>
  132. <!-- 查询库存 -->
  133. <select id="getSumAmount" resultType="int">
  134. select sum(amount) from tld_inventory where storage_location_code = #{storageLocationCode}
  135. </select>
  136. <!-- 查询物料信息 -->
  137. <select id="getMaterialClass" resultType="com.tld.model.MaterialClass">
  138. select
  139. id,
  140. name,
  141. code,
  142. tld_id,
  143. specification_and_model,
  144. unit_of_measurement,
  145. size,
  146. wllb_class,
  147. is_not_disable,
  148. is_recommend,
  149. part_type
  150. from tld_material where tld_id = #{materialId}
  151. </select>
  152. </mapper>