DeliveryMapper.xml 13 KB

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