AskGoodsMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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.AskGoodsMapper">
  5. <!-- 查询要货单id+物料id是否存在 -->
  6. <select id="getAskGoods" resultType="int">
  7. select count(*) from tld_ask_goods where ask_goods_id = #{askGoodsId} and material_id = #{materialId}
  8. </select>
  9. <!-- 修改要料申请单数量 -->
  10. <update id="updateAskGoodsNum">
  11. update tld_ask_goods
  12. set
  13. num =#{num}
  14. where ask_goods_id = #{askGoodsId} and material_id = #{materialId}
  15. </update>
  16. <!-- 新增要料申请单 -->
  17. <insert id="addAskGoods">
  18. insert into tld_ask_goods(ask_goods_id,entry_number,production_code,material_id,wbs,measurement_id,num,type)
  19. values(#{askGoodsId},#{entryNumber},#{productionCode},#{materialId},#{wbs},#{measurementId},#{num},#{type})
  20. </insert>
  21. <!-- 新增要料日志 -->
  22. <insert id="addAskGoodsLog">
  23. insert into tld_ask_goods_log(ask_goods_id,entry_number,production_code,material_id,wbs,measurement_id,num,out_num,ask_goods_code,company_number,sqrq,department_id,source_type,move_type,ask_goods_type)
  24. values(#{askGoodsId},#{entryNumber},#{productionCode},#{materialId},#{wbs},#{measurementId},#{num},#{outNum},#{askGoodsCode},#{companyNumber},#{sqrq},#{departmentId},#{sourceType},#{moveType},#{askGoodsType})
  25. </insert>
  26. <!-- 查询次要货单是否存在 -->
  27. <select id="getAskGoodsf" resultType="int">
  28. select count(*) from tld_ask_goods_f where ask_goods_id = #{askGoodsId} and ask_goods_code = #{askGoodsCode}
  29. </select>
  30. <!-- 新增要料申请单父级 -->
  31. <insert id="addAskGoodsf">
  32. insert into tld_ask_goods_f(ask_goods_id,ask_goods_code,company_number,sqrq,department,source_type,move_type)
  33. values(#{askGoodsId},#{askGoodsCode},#{companyNumber},#{sqrq},#{department},#{sourceType},#{moveType})
  34. </insert>
  35. <!-- 查询生产领料单 -->
  36. <select id="getAskGoodsfList" resultType="com.tld.model.AskGoods">
  37. select
  38. DISTINCT a.ask_goods_id,
  39. a.ask_goods_code,
  40. b.name as departmentName,
  41. a.company_number
  42. from tld_ask_goods_f a
  43. join tld_ask_goods d on a.ask_goods_id = d.ask_goods_id
  44. left join tld_department b on a.department = b.tld_id
  45. join tld_material c on d.material_id = c.tld_id
  46. where c.part_type != '半成品'
  47. order by a.sqrq desc
  48. </select>
  49. <!-- 查询指定生产单的物料 -->
  50. <select id="getAskGoodsMaterial" resultType="com.tld.model.AskGoods">
  51. SELECT
  52. a.id,
  53. a.material_id,
  54. a.num,
  55. b.name as materialName,
  56. b.code as materialCode,
  57. a.out_num
  58. FROM
  59. tld_ask_goods a
  60. left join tld_material b on a.material_id = b.tld_id
  61. WHERE
  62. a.ask_goods_id = #{askGoodsId} and (a.num + 0) <![CDATA[>]]> (a.out_num + 0) and b.part_type != '半成品' and b.part_type != '产成品'
  63. </select>
  64. <!-- 物料库位选择 -->
  65. <select id="getMaterialCk" resultType="com.tld.model.Inventory">
  66. select
  67. a.storage_location_code,
  68. a.wllb_class,
  69. a.library_type,
  70. a.material_id,
  71. (a.amount - ifnull(a.amount_lock, 0)) as amount,
  72. a.total,
  73. a.totime,
  74. a.hold,
  75. a.amount_lock,
  76. a.account_sleeve,
  77. a.wbs,
  78. a.supplier_id,
  79. a.serial,
  80. a.wllb_code,
  81. a.produc_date,
  82. a.scrq,
  83. b.storage_location_name as storageLocationName
  84. from tld_inventory a
  85. join tld_storage_location b on a.storage_location_code = b.storage_location_code
  86. where a.material_id = #{materialId} and a.account_sleeve = #{companyNumber} and a.hold = '0' and b.warehouse_where != '5000' order by a.produc_date
  87. </select>
  88. <!-- 新增出库虚拟表 -->
  89. <insert id="addAskGoodsVitrual">
  90. insert into tld_ask_goods_vitrual(unique_code,supplier_id,serial,wllb_code,produc_date,ask_goods_id,type,storage_location_code,num,user_id,department,attribute,account_sleeve)
  91. values(#{uniqueCode},#{supplierId},#{serial},#{wllbCode},#{producDate},#{askGoodsId},#{type},#{storageLocationCode},#{num},#{userId},#{department},#{attribute},#{companyNumber})
  92. </insert>
  93. <!-- 查询指定库存内容 -->
  94. <select id="getInventory" resultType="com.tld.model.Inventory">
  95. select
  96. id,
  97. storage_location_code,
  98. wllb_class,
  99. library_type,
  100. material_id,
  101. amount,
  102. total,
  103. totime,
  104. hold,
  105. amount_lock,
  106. account_sleeve,
  107. wbs,
  108. supplier_id,
  109. serial,
  110. wllb_code,
  111. produc_date,
  112. scrq
  113. from tld_inventory where supplier_id = #{supplierId} and serial = #{serial} and wllb_code = #{wllbCode} and produc_date = #{producDate}
  114. </select>
  115. <!-- 查询库存是否充足 -->
  116. <select id="getAsk" resultType="com.tld.model.AskGoods">
  117. SELECT
  118. ifnull(sum(a.num),0) as num
  119. FROM
  120. tld_ask_goods_vitrual a
  121. join tld_material b on a.wllb_code = b.code and b.tld_id = #{materialId}
  122. where a.storage_location_code = #{storageLocationCode}
  123. </select>
  124. <!-- 查询是否扫描 -->
  125. <select id="getScanIsNot" resultType="java.util.Map">
  126. select
  127. (select ifnull(amount,0) from tld_inventory where supplier_id = #{supplierId} and serial = #{serial} and wllb_code = #{wllbCode} and produc_date = #{producDate}) as inventoryNum,
  128. (select ifnull(sum(num),0) from tld_ask_goods_vitrual where supplier_id = #{supplierId} and serial = #{serial} and wllb_code = #{wllbCode} and produc_date = #{producDate} and type = #{type}) as virtualNum
  129. from dual
  130. </select>
  131. <!-- 查询指定送货单信息 -->
  132. <select id="getAsknInfo" resultType="com.tld.model.AskGoods">
  133. SELECT
  134. a.id,
  135. a.ask_goods_id,
  136. a.entry_number,
  137. a.production_code,
  138. a.material_id,
  139. a.wbs,
  140. a.measurement_id,
  141. a.num,
  142. a.out_num
  143. FROM
  144. tld_ask_goods a
  145. join tld_material b on a.material_id = b.tld_id
  146. where a.ask_goods_id = #{askGoodsId} and b.code = #{wllbCode}
  147. </select>
  148. <!-- 查询已扫描总数 -->
  149. <select id="getAskInfoNumVitrual" resultType="int">
  150. select ifnull(sum(num), 0) from tld_ask_goods_vitrual where wllb_code = #{wllbCode} and ask_goods_id = #{askGoodsId} and type = #{type}
  151. </select>
  152. <!-- 查询此库存在虚拟表里占用的数量 -->
  153. <select id="getInventoryAlready" resultType="int">
  154. select ifnull(sum(num), 0) from tld_ask_goods_vitrual where supplier_id = #{supplierId} and serial = #{serial} and wllb_code = #{wllbCode} and produc_date = #{producDate} and type = #{type}
  155. </select>
  156. <!-- 查询虚拟表指定pda跟状态的的数据 -->
  157. <select id="getVirtualUniqueCode" resultType="com.tld.model.AskGoods">
  158. select
  159. id,
  160. unique_code,
  161. supplier_id,
  162. serial,
  163. wllb_code,
  164. produc_date,
  165. ask_goods_id,
  166. type,
  167. storage_location_code,
  168. num,
  169. user_id,
  170. department
  171. from tld_ask_goods_vitrual where unique_code = #{uniqueCode} and type = #{type} and ask_goods_id = #{askGoodsId}
  172. </select>
  173. <!-- 删除库存 -->
  174. <delete id="deleteInventory">
  175. delete from tld_inventory where id = #{id}
  176. </delete>
  177. <!-- 修改库存数量 -->
  178. <update id="updateInventory">
  179. UPDATE tld_inventory
  180. SET amount = amount - #{amount}
  181. WHERE
  182. id = #{id}
  183. </update>
  184. <!-- 删除虚拟表出库记录 -->
  185. <delete id="deleteVirtual">
  186. delete from tld_ask_goods_vitrual where id = #{id}
  187. </delete>
  188. <!-- 插入出库流水 -->
  189. <insert id="addRemoval">
  190. insert into tld_removal(wllb_code,supplier_id,serial,num,type,user_id,storage_location_code,scrq,process,ask_goods_id,produc_date,department,storage_code,wbs)
  191. values(#{wllbCode},#{supplierId},#{serial},#{num},#{type},#{userId},#{storageLocationCode},now(),#{process},#{askGoodsId},#{producDate},#{department},#{storageCode},#{wbs})
  192. </insert>
  193. <!-- 查询指定物料类型的id -->
  194. <select id="getMaterialId" resultType="String">
  195. select tld_id from tld_material where code = #{wllbCode}
  196. </select>
  197. <!-- 查询要料申请单内容 -->
  198. <select id="getAskDetailed" resultType="com.tld.model.AskGoods">
  199. select
  200. id,
  201. ask_goods_id,
  202. entry_number,
  203. production_code,
  204. material_id,
  205. wbs,
  206. measurement_id,
  207. num,
  208. out_num
  209. from tld_ask_goods
  210. where ask_goods_id = #{askGoodsId} and material_id = #{materialId}
  211. </select>
  212. <!-- 新增返回gs数据字表信息 -->
  213. <insert id="addReturnGsRemoval">
  214. insert into tld_return_gs_removal_z(material_id,wbs,num,entry_number,document_id,document_points_id,storage_location_code)
  215. values(#{materialId},#{wbs},#{num},#{entryNumber},#{documentId},#{documentPointsId},#{storageLocationCode})
  216. </insert>
  217. <!-- 查询要货单父级信息 -->
  218. <select id="getAskDetailedF" resultType="com.tld.model.AskGoods">
  219. select
  220. id,
  221. ask_goods_id,
  222. ask_goods_code,
  223. company_number,
  224. sqrq,
  225. department,
  226. source_type,
  227. move_type
  228. from tld_ask_goods_f where ask_goods_id = #{askGoodsId}
  229. </select>
  230. <!-- 新增返回gs数据父表信息 -->
  231. <insert id="addReturnGsRemovalF">
  232. insert into tld_return_gs_removal(document_id,removal_code,source_type,move_type,scrq,delivery_type)
  233. values(#{documentId},#{removalCode},#{sourceType},#{moveType},now(),#{deliveryType})
  234. </insert>
  235. <!-- 查询当天出库数量 -->
  236. <select id="getReturnRemovalCount" resultType="int">
  237. select count(*) from tld_return_gs_removal where scrq BETWEEN CONCAT(CURDATE(),' 00:00:00') AND CONCAT(CURDATE(),' 23:59:59');
  238. </select>
  239. <!-- 查询回传数据 -->
  240. <select id="plugOutRemoval" resultType="java.util.Map">
  241. select
  242. id,
  243. document_id as askGoodsId,
  244. removal_code as removalCode,
  245. source_type as sourceType,
  246. move_type as moveType
  247. from tld_return_gs_removal where removal_code = #{removalCode}
  248. </select>
  249. <!-- 查询字表回传数据 -->
  250. <select id="getRemovalz" resultType="java.util.Map">
  251. select
  252. material_id as materialId,
  253. wbs,
  254. num,
  255. entry_number as entryNumber,
  256. document_id as askGoodsId,
  257. document_points_id as askId
  258. from tld_return_gs_removal_z where document_id = #{askGoodsId}
  259. </select>
  260. <!-- 查询出库流水 -->
  261. <select id="getRemoval" resultType="com.tld.model.AskGoods">
  262. select
  263. a.id,
  264. b.name as materialName,
  265. a.wllb_code,
  266. h.name as supplierName,
  267. a.serial,
  268. a.type,
  269. c.user_name as userName,
  270. e.name as department,
  271. g.storage_location_name as storageLocationName,
  272. a.scrq,
  273. a.num,
  274. a.storage_code,
  275. a.wbs
  276. from tld_removal a
  277. left join tld_material b on a.wllb_code = b.code
  278. left join tld_user c on a.user_id = c.id
  279. left join tld_department e on a.department = e.tld_id
  280. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  281. left join tld_customer h on a.supplier_id = h.code
  282. <trim prefix="WHERE" prefixOverrides="and |or">
  283. <if test="wllbCode != null and wllbCode != ''">
  284. and a.wllb_code = #{wllbCode}
  285. </if>
  286. <if test="startTime != null and startTime != ''">
  287. and a.scrq <![CDATA[>=]]> #{startTime}
  288. </if>
  289. <if test="endTime != null and endTime != ''">
  290. and a.scrq <![CDATA[<=]]> #{endTime}
  291. </if>
  292. <if test="type != null and type != ''">
  293. and a.type like CONCAT(CONCAT('%', #{type}), '%')
  294. </if>
  295. </trim>
  296. order by a.id desc
  297. </select>
  298. <!-- 导出 -->
  299. <select id="export" resultType="java.util.LinkedHashMap">
  300. select
  301. b.name as materialName,
  302. h.name as supplierName,
  303. a.serial,
  304. a.type,
  305. c.user_name as userName,
  306. e.name as department,
  307. g.storage_location_name as storageLocationName,
  308. a.scrq,
  309. a.num
  310. from tld_removal a
  311. left join tld_material b on a.wllb_code = b.code
  312. left join tld_user c on a.user_id = c.id
  313. left join tld_department e on a.department = e.tld_id
  314. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  315. left join tld_customer h on a.supplier_id = h.code
  316. <trim prefix="WHERE" prefixOverrides="and |or">
  317. <if test="wllbCode != null and wllbCode != ''">
  318. and a.wllb_code = #{wllbCode}
  319. </if>
  320. <if test="startTime != null and startTime != ''">
  321. and a.scrq <![CDATA[>=]]> #{startTime}
  322. </if>
  323. <if test="endTime != null and endTime != ''">
  324. and a.scrq <![CDATA[<=]]> #{endTime}
  325. </if>
  326. <if test="type != null and type != ''">
  327. and a.type like CONCAT(CONCAT('%', #{type}), '%')
  328. </if>
  329. </trim>
  330. order by a.id desc
  331. </select>
  332. <!-- 查询指定pda出库虚拟表 -->
  333. <select id="getAskGoodsVitrual" resultType="com.tld.model.AskGoods">
  334. select
  335. id,
  336. unique_code,
  337. supplier_id,
  338. serial,
  339. wllb_code,
  340. produc_date,
  341. ask_goods_id,
  342. type,
  343. storage_location_code,
  344. num,
  345. user_id,
  346. department
  347. from tld_ask_goods_vitrual
  348. where unique_code = #{uniqueCode} and type = #{type}
  349. </select>
  350. <!-- 删除指定虚拟表数据 -->
  351. <delete id="delAskGoodsVitrual">
  352. delete from tld_ask_goods_vitrual where id = #{id} and type = #{type}
  353. </delete>
  354. <!-- 修改出库数量 -->
  355. <update id="updateOutNum">
  356. update tld_ask_goods
  357. set out_num = out_num + #{num} where material_id = #{materialId} and ask_goods_id = #{askGoodsId}
  358. </update>
  359. <!-- 查询指定pda 指定物料扫描总数 -->
  360. <select id="getScanNum" resultType="String">
  361. select if(AVG(num) is null, 0, num)
  362. from tld_ask_goods_vitrual
  363. where unique_code = #{uniqueCode} and ask_goods_id = #{askGoodsId} and wllb_code = #{wllbCode}
  364. </select>
  365. <!-- 查询半成品出库数据 -->
  366. <select id="getGoodsHalf" resultType="com.tld.model.AskGoods">
  367. SELECT
  368. a.id,
  369. a.material_id,
  370. a.num,
  371. a.production_code,
  372. b.name as materialName,
  373. b.code as materialCode,
  374. a.out_num,
  375. a.ask_goods_id,
  376. c.company_number
  377. e.name as department,
  378. a.type
  379. FROM
  380. tld_ask_goods a
  381. join tld_material b on a.material_id = b.tld_id
  382. join tld_ask_goods_f c on a.ask_goods_id = c.ask_goods_id
  383. left join tld_department e on c.department = e.tld_id
  384. WHERE
  385. (a.num + 0) <![CDATA[>]]> (a.out_num + 0) and b.part_type = #{partType}
  386. <if test="productionCode != null and productionCode != ''">
  387. and a.production_code = #{productionCode}
  388. </if>
  389. <if test="askGoodsId != null and askGoodsId != ''">
  390. and a.ask_goods_id = #{askGoodsId}
  391. </if>
  392. <if test="id != null and id != ''">
  393. and a.id = #{id}
  394. </if>
  395. <if test="type != null and type != ''">
  396. and a.type = #{type}
  397. </if>
  398. </select>
  399. <!-- 查询半成品出库流水 -->
  400. <select id="getRemovalHalfProduct" resultType="com.tld.model.AskGoods">
  401. select
  402. a.id,
  403. a.wllb_code,
  404. a.num,
  405. a.user_id,
  406. a.scrq,
  407. a.ask_goods_id,
  408. c.name as department,
  409. b.name as materialName,
  410. e.user_name as userName,
  411. b.code as materialCode,
  412. a.storage_code,
  413. a.wbs
  414. from tld_removal_half_product a
  415. left join tld_material b on a.wllb_code = b.code
  416. left join tld_department c on a.department = c.tld_id
  417. left join tld_user e on a.user_id = e.id
  418. <if test="wllbCode != null and wllbCode != ''">
  419. and a.wllb_code = #{wllbCode}
  420. </if>
  421. <if test="startTime != null and startTime != ''">
  422. and a.scrq <![CDATA[>=]]> #{startTime}
  423. </if>
  424. <if test="endTime != null and endTime != ''">
  425. and a.scrq <![CDATA[<=]]> #{endTime}
  426. </if>
  427. order by a.scrq desc
  428. </select>
  429. <!-- 查询半成品出库流水导出 -->
  430. <select id="getRemovalHalfProductExcel" resultType="java.util.LinkedHashMap">
  431. select
  432. b.name as materialName,
  433. a.num,
  434. e.user_name as userName,
  435. a.scrq,
  436. a.ask_goods_id,
  437. c.name as department,
  438. a.storage_code,
  439. a.wbs
  440. from tld_removal_half_product a
  441. left join tld_material b on a.wllb_code = b.code
  442. left join tld_department c on a.department = c.tld_id
  443. left join tld_user e on a.user_id = e.id
  444. <if test="wllbCode != null and wllbCode != ''">
  445. and a.wllb_code = #{wllbCode}
  446. </if>
  447. <if test="startTime != null and startTime != ''">
  448. and a.scrq <![CDATA[>=]]> #{startTime}
  449. </if>
  450. <if test="endTime != null and endTime != ''">
  451. and a.scrq <![CDATA[<=]]> #{endTime}
  452. </if>
  453. order by a.scrq desc
  454. </select>
  455. <!-- 产成品出库流水 -->
  456. <select id="getRemovalHalf" resultType="com.tld.model.AskGoods">
  457. select
  458. a.id,
  459. a.wllb_code,
  460. a.num,
  461. a.user_id,
  462. a.scrq,
  463. a.delivery_id,
  464. a.company_number,
  465. a.customer_code,
  466. b.name as materialName,
  467. c.user_name as userName,
  468. e.name as customerName,
  469. f.name as companyName,
  470. b.code as materialCode,
  471. a.storage_code,
  472. a.wbs
  473. from tld_removal_half a
  474. left join tld_material b on a.wllb_code = b.code
  475. left join tld_user c on a.user_id = c.id
  476. left join tld_customer e on a.customer_code = e.code
  477. left join tld_company f on a.company_number = f.tld_id
  478. <if test="wllbCode != null and wllbCode != ''">
  479. and a.wllb_code = #{wllbCode}
  480. </if>
  481. <if test="startTime != null and startTime != ''">
  482. and a.scrq <![CDATA[>=]]> #{startTime}
  483. </if>
  484. <if test="endTime != null and endTime != ''">
  485. and a.scrq <![CDATA[<=]]> #{endTime}
  486. </if>
  487. order by a.scrq desc
  488. </select>
  489. <!-- 产成品导出出库流水 -->
  490. <select id="getRemovalHalfExcel" resultType="java.util.LinkedHashMap">
  491. select
  492. b.name as materialName,
  493. a.num,
  494. c.user_name as userName,
  495. a.scrq,
  496. f.name as companyName,
  497. e.name,
  498. a.storage_code,
  499. a.wbs
  500. from tld_removal_half a
  501. left join tld_material b on a.wllb_code = b.code
  502. left join tld_user c on a.user_id = c.id
  503. left join tld_customer e on a.customer_code = e.code
  504. left join tld_company f on a.company_number = f.tld_id
  505. <if test="wllbCode != null and wllbCode != ''">
  506. and a.wllb_code = #{wllbCode}
  507. </if>
  508. <if test="startTime != null and startTime != ''">
  509. and a.scrq <![CDATA[>=]]> #{startTime}
  510. </if>
  511. <if test="endTime != null and endTime != ''">
  512. and a.scrq <![CDATA[<=]]> #{endTime}
  513. </if>
  514. order by a.scrq desc
  515. </select>
  516. <!-- 查询指定物料的库存 -->
  517. <select id="getInventoryInfo" resultType="com.tld.model.Inventory">
  518. select
  519. id,
  520. storage_location_code,
  521. wllb_class,
  522. library_type,
  523. material_id,
  524. amount,
  525. total,
  526. totime,
  527. hold,
  528. amount_lock,
  529. account_sleeve,
  530. wbs,
  531. supplier_id,
  532. serial,
  533. wllb_code,
  534. produc_date,
  535. scrq,
  536. produc_batch,
  537. attribute
  538. from tld_inventory where storage_location_code = #{storageLocationCode} and material_id = #{materialId} and account_sleeve = #{accountSleeve} and amount <![CDATA[>=]]> #{num}
  539. <if test="wbs != '' and wbs != null">
  540. and wbs = #{wbs}
  541. </if>
  542. <if test="wbs == ''.toString() or wbs == null ">
  543. and wbs is null
  544. </if>
  545. </select>
  546. </mapper>