DeliveryMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. b.delivery_code,
  11. a.entry_number,
  12. a.material_id,
  13. d.code as wbsCode,
  14. a.wbs,
  15. a.measurement_id,
  16. a.gs_delivery_num,
  17. a.gs_cancel_num,
  18. a.out_num,
  19. b.company_number,
  20. b.bills_time,
  21. b.customer_code,
  22. b.delivery_type,
  23. b.source_type,
  24. b.move_type,
  25. c.name as materialName,
  26. c.code as materialCode,
  27. c.part_type as partType
  28. from tld_delivery a
  29. join tld_delivery_f b on a.delivery_id = b.delivery_id
  30. left join tld_material c on a.material_id = c.tld_id
  31. left join tld_wbs d on a.wbs = d.tld_id
  32. where (a.gs_delivery_num - a.gs_cancel_num) != a.out_num
  33. and a.status != '1'
  34. <if test="deliveryId != null and deliveryId != ''">
  35. and a.delivery_id = #{deliveryId}
  36. </if>
  37. <if test="materialId != null and materialId != ''">
  38. and a.material_id = #{materialId}
  39. </if>
  40. <if test="entryNumber != null and entryNumber != ''">
  41. and a.entry_number = #{entryNumber}
  42. </if>
  43. <if test="wbs != null and wbs != ''">
  44. and a.wbs = #{wbs}
  45. </if>
  46. </select>
  47. <!-- 查询所有产成品库位 -->
  48. <select id="getStorageLocationCodeList" resultType="String">
  49. select
  50. CONCAT(CONCAT(GROUP_CONCAT(storage_location_code SEPARATOR ","),','), '111111,')
  51. from tld_storage_location where is_product = '1'
  52. </select>
  53. <!-- 查询指定库位跟物料的库存 -->
  54. <select id="getInventory" resultType="com.tld.model.Inventory">
  55. SELECT
  56. a.id,
  57. a.storage_location_code,
  58. a.wllb_class,
  59. a.library_type,
  60. a.material_id,
  61. 0 + (a.amount - a.amount_lock) as amount,
  62. a.wbs,
  63. a.serial,
  64. a.wllb_code,
  65. a.produc_date,
  66. a.scrq,
  67. a.produc_batch,
  68. a.attribute,
  69. b.storage_location_name as storageLocationName,
  70. a.account_sleeve
  71. FROM tld_inventory a
  72. LEFT JOIN tld_storage_location b on a.storage_location_code = b.storage_location_code
  73. WHERE #{storageLocationCode} LIKE CONCAT( '%', CONCAT( a.storage_location_code, ',' ), '%' )
  74. AND a.material_id = #{delivery.materialId} AND a.hold = '0' AND a.wbs = #{delivery.wbs} and a.account_sleeve = #{delivery.companyNumber}
  75. <if test="delivery.attribute != null">
  76. and a.attribute = #{delivery.attribute}
  77. </if>
  78. ORDER BY
  79. a.produc_batch
  80. </select>
  81. <!-- 查询指定库存内容 -->
  82. <select id="getInventoryHalf" resultType="com.tld.model.Inventory">
  83. SELECT
  84. a.id,
  85. a.storage_location_code,
  86. a.wllb_class,
  87. a.library_type,
  88. a.material_id,
  89. a.amount,
  90. a.amount_lock,
  91. a.wbs,
  92. a.serial,
  93. a.wllb_code,
  94. a.produc_date,
  95. a.scrq,
  96. a.produc_batch,
  97. a.attribute
  98. FROM tld_inventory a
  99. JOIN tld_material b on a.material_id = b.tld_id
  100. WHERE b.code = #{wllbCode} and a.account_sleeve = #{companyNumber} and a.wbs = #{wbs} and a.hold = '0'
  101. <if test="attribute != null and attribute != ''">
  102. and a.attribute = #{attribute}
  103. </if>
  104. <if test="serial != null and serial != ''">
  105. and a.serial = #{serial}
  106. </if>
  107. <if test="storageLocationCode != null and storageLocationCode != ''">
  108. and a.storage_location_code = #{storageLocationCode}
  109. </if>
  110. </select>
  111. <!-- 暂时使用 后期删除-->
  112. <!-- 查询指定库存内容 -->
  113. <select id="getTemporarily" resultType="com.tld.model.Inventory">
  114. SELECT
  115. a.id,
  116. a.storage_location_code,
  117. a.wllb_class,
  118. a.library_type,
  119. a.material_id,
  120. a.amount,
  121. a.amount_lock,
  122. a.wbs,
  123. a.serial,
  124. a.wllb_code,
  125. a.produc_date,
  126. a.scrq,
  127. a.produc_batch,
  128. a.attribute
  129. FROM tld_inventory a
  130. JOIN tld_material b on a.material_id = b.tld_id
  131. WHERE b.code = #{wllbCode} and a.account_sleeve = #{companyNumber} and a.wbs = #{wbs} and a.hold = '0'
  132. <if test="attribute != null and attribute != ''">
  133. and a.attribute = #{attribute}
  134. </if>
  135. <if test="storageLocationCode != null and storageLocationCode != ''">
  136. and a.storage_location_code = #{storageLocationCode}
  137. </if>
  138. and (a.amount + 0) <![CDATA[>=]]> (#{num} + 0) limit 1
  139. </select>
  140. <!-- 暂时使用 后期删除-->
  141. <!-- 查询指定库存被占用数量 -->
  142. <select id="getVitrual" resultType="int">
  143. select
  144. count(*)
  145. from tld_ask_goods_vitrual a
  146. join tld_material b on a.wllb_code = b.code
  147. where a.storage_location_code = #{storageLocationCode} and b.code = #{wllbCode} and a.attribute = #{attribute} and a.produc_date = #{producBatch} and serial = #{serial}
  148. </select>
  149. <!-- 修改销售单出库数量 -->
  150. <update id="updateDelivery">
  151. update tld_delivery set out_num = (out_num + 0) + #{num} where delivery_id = #{deliveryId} and material_id = #{materialId} and entry_number = #{entryNumber}
  152. </update>
  153. <!-- 产成品出库流水 -->
  154. <insert id="addRemovalHalf">
  155. insert into tld_removal_half(wllb_code,num,user_id,scrq,delivery_id,company_number,customer_code,storage_code,wbs,transmission_type,serial)
  156. value(#{materialCode},#{outNum},#{userId},now(),#{deliveryId},#{companyNumber},#{customerCode},#{storageCode},#{wbs},0,#{serial})
  157. </insert>
  158. <!-- 查询销售单父级信息 -->
  159. <select id="getDeliveryF" resultType="com.tld.model.Delivery">
  160. select
  161. id,
  162. delivery_id,
  163. delivery_code,
  164. company_number,
  165. customer_code,
  166. bills_time,
  167. delivery_type,
  168. source_type,
  169. move_type
  170. from tld_delivery_f where delivery_id = #{deliveryId}
  171. </select>
  172. <!-- 查询产成品属性 -->
  173. <select id="getAttribute" resultType="com.tld.model.Inventory">
  174. SELECT
  175. DISTINCT attribute,
  176. storage_location_code,
  177. wllb_code,
  178. produc_batch
  179. FROM tld_inventory
  180. WHERE CONCAT(#{storageLocationCode}) LIKE CONCAT( '%', CONCAT( storage_location_code, ',' ), '%' )
  181. AND material_id = #{delivery.materialId} AND hold = '0'
  182. </select>
  183. <!-- 查询库存 -->
  184. <select id="getSumAmount" resultType="int">
  185. select sum(amount) from tld_inventory where storage_location_code = #{storageLocationCode}
  186. </select>
  187. <!-- 查询物料信息 -->
  188. <select id="getMaterialClass" resultType="com.tld.model.MaterialClass">
  189. select
  190. id,
  191. name,
  192. code,
  193. tld_id,
  194. specification_and_model,
  195. unit_of_measurement,
  196. size,
  197. wllb_class,
  198. is_not_disable,
  199. is_recommend,
  200. part_type
  201. from tld_material where tld_id = #{materialId}
  202. </select>
  203. <!-- 查询虚拟表半成品扫描数量 -->
  204. <select id="getProductNumVitrual" resultType="int">
  205. select
  206. sum(num) as num
  207. from tld_ask_goods_vitrual a
  208. join tld_material b on a.wllb_code = b.code
  209. where a.storage_location_code = #{storageLocationCode} and b.code = #{wllbCode} and a.wbs = #{wbs}
  210. </select>
  211. <!-- 查询库存数量是否充足 -->
  212. <select id="getScanIsNot" resultType="java.util.Map">
  213. select
  214. (select ifnull(amount,0) from tld_inventory where id = #{id}) as amount,
  215. (select ifnull(sum(num),0) from tld_ask_goods_vitrual where wbs = #{wbs} and wllb_code = #{wllbCode} and storage_location_code = #{storageLocationCode} and produc_date = #{producDate} and account_sleeve = #{companyNumber}
  216. <if test="serial != null and serial !=''">
  217. and serial = #{serial}
  218. </if>
  219. <if test="attribute != null and attribute !=''">
  220. and attribute = #{attribute}
  221. </if>) as vitrualNum
  222. from dual
  223. </select>
  224. <!-- 查询销售交货单原始数据 -->
  225. <select id="getDeliverys" resultType="java.util.Map">
  226. select * from tld_delivery where id = #{id}
  227. </select>
  228. <!-- 删除销售交货单原始数据 -->
  229. <delete id="delDelivery">
  230. delete from tld_delivery where id = #{id}
  231. </delete>
  232. <!-- 物料库位选择 -->
  233. <select id="getMaterialCk" resultType="com.tld.model.Inventory">
  234. select a.storage_location_code,
  235. a.wllb_class,
  236. a.library_type,
  237. a.material_id,
  238. (a.amount - ifnull(a.amount_lock, 0)) as amount,
  239. a.total,
  240. a.totime,
  241. a.hold,
  242. a.amount_lock,
  243. a.account_sleeve,
  244. a.wbs,
  245. a.supplier_id,
  246. a.serial,
  247. a.wllb_code,
  248. a.produc_date,
  249. a.scrq,
  250. b.storage_location_name as storageLocationName
  251. from tld_inventory a
  252. join tld_storage_location b on a.storage_location_code = b.storage_location_code
  253. join tld_warehouse c on b.warehouse_where = c.tld_id
  254. where a.material_id = #{materialId}
  255. and a.account_sleeve = #{companyNumber}
  256. and a.hold = '0'
  257. and (c.warehouse_type = '0' or c.warehouse_type = '1' or c.warehouse_type = '2')
  258. and a.wbs = #{wbs}
  259. order by a.produc_date
  260. </select>
  261. <!-- 查询销售出库是否扫描 -->
  262. <select id="getDeliveryScan" resultType="int">
  263. select count(*) from tld_ask_goods_vitrual
  264. <trim prefix="WHERE" prefixOverrides="and |or">
  265. <if test="serial != null and serial != ''">
  266. and serial = #{serial}
  267. </if>
  268. <if test="supplierId != null and supplierId != ''">
  269. and supplier_id = #{supplierId}
  270. </if>
  271. <if test="wllbCode != null and wllbCode != ''">
  272. and wllb_code = #{wllbCode}
  273. </if>
  274. <if test="producDate != null and producDate != ''">
  275. and produc_date = #{producDate}
  276. </if>
  277. </trim>
  278. </select>
  279. <!-- 查询指定销售单物料已扫数量 -->
  280. <select id="getScanSum" resultType="int">
  281. SELECT
  282. ifnull(sum( a.num ), 0)
  283. FROM
  284. tld_ask_goods_vitrual a
  285. join tld_material b on a.wllb_code = b.code
  286. WHERE
  287. a.ask_goods_id = #{deliveryId} and b.tld_id = #{materialId}
  288. </select>
  289. <!-- 新增半成品流水 -->
  290. <insert id="addRemovalHalfProduct">
  291. insert into tld_removal_half_product(wllb_code,num,user_id,scrq,ask_goods_id,storage_code,wbs,company_number,transmission_type)
  292. value(#{materialCode},#{outNum},#{userId},now(),#{deliveryId},#{storageCode},#{wbs},#{companyNumber},0)
  293. </insert>
  294. <!-- 查询销售订单 -->
  295. <select id="getDeliveryInfo" resultType="com.tld.model.Delivery">
  296. select out_num,gs_delivery_num from tld_delivery where delivery_id = #{askGoodsId} and entry_number = #{entryNumber}
  297. </select>
  298. <!-- 查询指定库存 -->
  299. <select id="getInventoryVal" resultType="com.tld.model.Inventory">
  300. select amount from tld_inventory where id = #{id}
  301. </select>
  302. <!-- 查询指定销售单扫描数量 -->
  303. <select id="getScanNumDelivery" resultType="String">
  304. select ifnull(sum(num), 0) as num from tld_ask_goods_vitrual where ask_goods_id = #{askGoodsId} and entry_number = #{entryNumber}
  305. </select>
  306. <!-- 虚拟表此物料占用数量 -->
  307. <select id="getAllScanNumDelivery" resultType="String">
  308. select ifnull(sum(num), 0) as num from tld_ask_goods_vitrual where wllb_code = #{wllbCode} and account_sleeve = #{accountSleeve} and wbs = #{wbs}
  309. <if test="producDate != null and producDate != ''">
  310. and produc_date = #{producDate}
  311. </if>
  312. <if test="serial != null and serial != ''">
  313. and serial = #{serial}
  314. </if>
  315. </select>
  316. <!-- 查询销售单绑定的软件类 -->
  317. <select id="getEquipmentSoftware" resultType="java.util.Map">
  318. select
  319. a.equipment_code as equipmentCode
  320. a.software_code as softwareCode,
  321. b.tld_id as materialId
  322. from tld_equipment_binding_software a
  323. join tld_material b on a.equipment_code = b.code
  324. where a.equipment_code = #{code}
  325. </select>
  326. </mapper>