AskGoodsMapper.xml 19 KB

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