DeliveryMapper.xml 17 KB

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