AskGoodsMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  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,out_num)
  19. values(#{askGoodsId},#{entryNumber},#{productionCode},#{materialId},#{wbs},#{measurementId},#{num},#{type},'0')
  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},#{departmentId},#{sourceType},#{moveType})
  34. </insert>
  35. <!-- 查询生产领料单 -->
  36. <select id="getAskGoodsfList" resultType="com.tld.model.AskGoods">
  37. SELECT
  38. a.ask_goods_id,
  39. a.material_id,
  40. IFNULL( a.out_num, 0 ) AS num,
  41. e.NAME AS materialName,
  42. e.CODE AS materialCode,
  43. b.ask_goods_code,
  44. b.company_number
  45. FROM
  46. tld_ask_goods a
  47. JOIN tld_ask_goods_f b ON a.ask_goods_id = b.ask_goods_id
  48. LEFT JOIN tld_department c ON b.department = c.code
  49. JOIN tld_material e ON a.material_id = e.tld_id
  50. WHERE
  51. ( a.num + 0 ) <![CDATA[>]]> (
  52. IFNULL( a.out_num, 0 ) + 0) and e.part_type != '半成品' and e.part_type != '产成品'
  53. </select>
  54. <!-- 查询指定生产单的物料 -->
  55. <select id="getAskGoodsMaterial" resultType="com.tld.model.AskGoods">
  56. SELECT
  57. a.ask_goods_id,
  58. a.material_id,
  59. a.num,
  60. IFNULL( a.out_num, 0 ) AS out_num,
  61. e.NAME AS materialName,
  62. e.CODE AS materialCode,
  63. b.ask_goods_code,
  64. b.company_number,
  65. c.name ,
  66. c.code,
  67. c.id AS departmentId
  68. FROM
  69. tld_ask_goods a
  70. JOIN tld_ask_goods_f b ON a.ask_goods_id = b.ask_goods_id
  71. LEFT JOIN tld_department c ON b.department = c.code
  72. JOIN tld_material e ON a.material_id = e.tld_id
  73. WHERE
  74. ( a.num + 0 ) <![CDATA[>]]> (
  75. IFNULL( a.out_num, 0 ) + 0) and e.part_type != '半成品' and e.part_type != '产成品'
  76. </select>
  77. <!-- 物料库位选择 -->
  78. <select id="getMaterialCk" resultType="com.tld.model.Inventory">
  79. select
  80. a.storage_location_code,
  81. a.wllb_class,
  82. a.library_type,
  83. a.material_id,
  84. (a.amount - ifnull(a.amount_lock, 0)) as amount,
  85. a.total,
  86. a.totime,
  87. a.hold,
  88. a.amount_lock,
  89. a.account_sleeve,
  90. a.wbs,
  91. a.supplier_id,
  92. a.serial,
  93. a.wllb_code,
  94. a.produc_date,
  95. a.scrq,
  96. b.storage_location_name as storageLocationName
  97. from tld_inventory a
  98. join tld_storage_location b on a.storage_location_code = b.storage_location_code
  99. join tld_warehouse c on b.warehouse_where = c.tld_id
  100. where a.material_id = #{materialId} and a.account_sleeve = #{companyNumber} and a.hold = '0' and (c.warehouse_type = '0' or c.warehouse_type = '1' or c.warehouse_type = '2')
  101. order by a.produc_date
  102. </select>
  103. <!-- 新增出库虚拟表 -->
  104. <insert id="addAskGoodsVitrual">
  105. 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,storage_location_code_rk,wbs)
  106. values(#{uniqueCode},#{supplierId},#{serial},#{wllbCode},#{producDate},#{askGoodsId},#{type},#{storageLocationCode},#{num},#{userId},#{department},#{attribute},#{companyNumber},#{storageLocationCodeRk},#{wbs})
  107. </insert>
  108. <!-- 查询指定库存内容 -->
  109. <select id="getInventory" resultType="com.tld.model.Inventory">
  110. select
  111. id,
  112. storage_location_code,
  113. wllb_class,
  114. library_type,
  115. material_id,
  116. amount,
  117. total,
  118. totime,
  119. hold,
  120. amount_lock,
  121. account_sleeve,
  122. wbs,
  123. supplier_id,
  124. serial,
  125. wllb_code,
  126. produc_date,
  127. scrq
  128. from tld_inventory where supplier_id = #{supplierId} and serial = #{serial} and wllb_code = #{wllbCode} and produc_date = #{producDate} and account_sleeve = #{companyNumber} and wbs = #{wbs}
  129. </select>
  130. <!-- 查询指定库存内容 -->
  131. <select id="getInventoryWarehousing" resultType="com.tld.model.Inventory">
  132. select
  133. id,
  134. storage_location_code,
  135. wllb_class,
  136. library_type,
  137. material_id,
  138. amount,
  139. total,
  140. totime,
  141. hold,
  142. amount_lock,
  143. account_sleeve,
  144. wbs,
  145. supplier_id,
  146. serial,
  147. wllb_code,
  148. produc_date,
  149. scrq
  150. from tld_inventory where storage_location_code = #{storageLocationCode} and wllb_code = #{wllbCode} and account_sleeve = #{companyNumber} and wbs = #{wbs}
  151. </select>
  152. <!-- 查询库存是否充足 -->
  153. <select id="getAsk" resultType="com.tld.model.AskGoods">
  154. SELECT
  155. ifnull(sum(a.num),0) as num
  156. FROM
  157. tld_ask_goods_vitrual a
  158. join tld_material b on a.wllb_code = b.code and b.tld_id = #{materialId}
  159. where a.storage_location_code = #{storageLocationCode} and a.serial = #{serial}
  160. </select>
  161. <!-- 查询是否扫描 -->
  162. <select id="getScanIsNot" resultType="java.util.Map">
  163. select
  164. (select ifnull(amount,0) from tld_inventory where supplier_id = #{supplierId} and serial = #{serial} and wllb_code = #{wllbCode} and produc_date = #{producDate}) as inventoryNum,
  165. (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
  166. from dual
  167. </select>
  168. <!-- 查询指定送货单信息 -->
  169. <select id="getAsknInfo" resultType="com.tld.model.AskGoods">
  170. SELECT
  171. a.id,
  172. a.ask_goods_id,
  173. a.entry_number,
  174. a.production_code,
  175. a.material_id,
  176. a.wbs,
  177. a.measurement_id,
  178. a.num,
  179. ifnull(a.out_num, 0) as out_num
  180. FROM
  181. tld_ask_goods a
  182. join tld_material b on a.material_id = b.tld_id
  183. where a.ask_goods_id = #{askGoodsId} and b.code = #{wllbCode}
  184. </select>
  185. <!-- 查询指定移庫單 -->
  186. <select id="getWareInfo" resultType="com.tld.model.AskGoods">
  187. SELECT
  188. a.id,
  189. a.warehouse_transfer_id as askGoodsId,
  190. a.entry_number,
  191. a.material_id,
  192. a.wbs,
  193. a.measurement_id,
  194. a.num,
  195. ifnull(a.out_num, 0) as out_num
  196. FROM
  197. tld_warehouse_transfer a
  198. join tld_material b on a.material_id = b.tld_id
  199. where a.warehouse_transfer_id = #{askGoodsId} and b.code = #{wllbCode}
  200. </select>
  201. <!-- 查询已扫描总数 -->
  202. <select id="getAskInfoNumVitrual" resultType="int">
  203. select ifnull(sum(num), 0) from tld_ask_goods_vitrual where wllb_code = #{wllbCode} and ask_goods_id = #{askGoodsId} and type = #{type}
  204. </select>
  205. <!-- 查询此库存在虚拟表里占用的数量 -->
  206. <select id="getInventoryAlready" resultType="int">
  207. 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}
  208. </select>
  209. <!-- 查询虚拟表指定pda跟状态的的数据 -->
  210. <select id="getVirtualUniqueCode" resultType="com.tld.model.AskGoods">
  211. select
  212. id,
  213. unique_code,
  214. supplier_id,
  215. serial,
  216. wllb_code,
  217. produc_date,
  218. ask_goods_id,
  219. type,
  220. storage_location_code,
  221. num,
  222. user_id,
  223. department,
  224. account_sleeve,
  225. wbs,
  226. storage_location_code_rk
  227. from tld_ask_goods_vitrual where unique_code = #{uniqueCode} and type = #{type} and ask_goods_id = #{askGoodsId}
  228. </select>
  229. <!-- 删除库存 -->
  230. <delete id="deleteInventory">
  231. delete from tld_inventory where id = #{id}
  232. </delete>
  233. <!-- 修改库存数量 -->
  234. <update id="updateInventory">
  235. UPDATE tld_inventory
  236. SET amount = amount - #{amount}
  237. WHERE
  238. id = #{id}
  239. </update>
  240. <!-- 删除虚拟表出库记录 -->
  241. <delete id="deleteVirtual">
  242. delete from tld_ask_goods_vitrual where id = #{id}
  243. </delete>
  244. <!-- 插入出库流水 -->
  245. <insert id="addRemoval">
  246. 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)
  247. values(#{wllbCode},#{supplierId},#{serial},#{num},#{type},#{userId},#{storageLocationCode},now(),#{process},#{askGoodsId},#{producDate},#{department},#{storageCode},#{wbs})
  248. </insert>
  249. <!-- 查询指定物料类型的id -->
  250. <select id="getMaterialId" resultType="String">
  251. select tld_id from tld_material where code = #{wllbCode}
  252. </select>
  253. <!-- 查询要料申请单内容 -->
  254. <select id="getAskDetailed" resultType="com.tld.model.AskGoods">
  255. select
  256. id,
  257. ask_goods_id,
  258. entry_number,
  259. production_code,
  260. material_id,
  261. wbs,
  262. measurement_id,
  263. num,
  264. out_num
  265. from tld_ask_goods
  266. where ask_goods_id = #{askGoodsId} and material_id = #{materialId}
  267. </select>
  268. <!-- 新增返回gs数据字表信息 -->
  269. <insert id="addReturnGsRemoval">
  270. insert into tld_return_gs_removal_z(material_id,wbs,num,entry_number,document_id,document_points_id,storage_location_code)
  271. values(#{materialId},#{wbs},#{num},#{entryNumber},#{documentId},#{documentPointsId},#{storageLocationCode})
  272. </insert>
  273. <!-- 查询要货单父级信息 -->
  274. <select id="getAskDetailedF" resultType="com.tld.model.AskGoods">
  275. select
  276. id,
  277. ask_goods_id,
  278. ask_goods_code,
  279. company_number,
  280. sqrq,
  281. department,
  282. source_type,
  283. move_type
  284. from tld_ask_goods_f where ask_goods_id = #{askGoodsId}
  285. </select>
  286. <!-- 新增返回gs数据父表信息 -->
  287. <insert id="addReturnGsRemovalF">
  288. insert into tld_return_gs_removal(document_id,removal_code,source_type,move_type,scrq,delivery_type)
  289. values(#{documentId},#{removalCode},#{sourceType},#{moveType},now(),#{deliveryType})
  290. </insert>
  291. <!-- 添加 tld_access 记录-->
  292. <insert id="addAccess">
  293. insert into tld_access (type,data,scrq,access_type)
  294. values(#{names},#{returnGsRemoval},now(),#{accessType})
  295. </insert>
  296. <!-- 查询当天出库数量 -->
  297. <select id="getReturnRemovalCount" resultType="int">
  298. select count(*) from tld_return_gs_removal where scrq BETWEEN CONCAT(CURDATE(),' 00:00:00') AND CONCAT(CURDATE(),' 23:59:59');
  299. </select>
  300. <!-- 查询回传数据 -->
  301. <select id="plugOutRemoval" resultType="java.util.Map">
  302. select
  303. id,
  304. document_id as askGoodsId,
  305. removal_code as removalCode,
  306. source_type as sourceType,
  307. move_type as moveType,
  308. scrq
  309. from tld_return_gs_removal where document_id = #{removalCode}
  310. </select>
  311. <!-- 查询字表回传数据 -->
  312. <select id="getRemovalz" resultType="java.util.Map">
  313. SELECT
  314. a.material_id AS materialId,
  315. a.wbs,
  316. a.num,
  317. a.entry_number AS entryNumber,
  318. a.document_id AS askGoodsId,
  319. a.document_points_id AS askId,
  320. ifnull(a.wbs, '') as wbsId,
  321. ifnull(c.code, '') as wbsCode,
  322. ifnull(c.name, '') as wbsName
  323. FROM
  324. tld_return_gs_removal_z a
  325. join tld_storage_location b on a.storage_location_code = b.storage_location_code
  326. left join tld_wbs c on a.wbs = c.tld_id
  327. WHERE
  328. a.document_id = #{askGoodsId} and b.warehouse_where = #{warehouseWhere}
  329. </select>
  330. <!-- 查询出库流水 -->
  331. <select id="getRemoval" resultType="com.tld.model.AskGoods">
  332. select
  333. a.id,
  334. b.name as materialName,
  335. a.wllb_code,
  336. h.name as supplierName,
  337. a.serial,
  338. a.type,
  339. c.user_name as userName,
  340. e.name as department,
  341. g.storage_location_name as storageLocationName,
  342. a.scrq,
  343. a.num,
  344. a.storage_code,
  345. a.wbs
  346. from tld_removal a
  347. left join tld_material b on a.wllb_code = b.code
  348. left join tld_user c on a.user_id = c.id
  349. left join tld_department e on a.department = e.code
  350. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  351. left join tld_customer h on a.supplier_id = h.code
  352. <trim prefix="WHERE" prefixOverrides="and |or">
  353. <if test="wllbCode != null and wllbCode != ''">
  354. and a.wllb_code = #{wllbCode}
  355. </if>
  356. <if test="startTime != null and startTime != ''">
  357. and a.scrq <![CDATA[>=]]> #{startTime}
  358. </if>
  359. <if test="endTime != null and endTime != ''">
  360. and a.scrq <![CDATA[<=]]> #{endTime}
  361. </if>
  362. <if test="type != null and type != ''">
  363. and a.type like CONCAT(CONCAT('%', #{type}), '%')
  364. </if>
  365. </trim>
  366. order by a.id desc
  367. </select>
  368. <!-- 导出 -->
  369. <select id="export" resultType="java.util.LinkedHashMap">
  370. select
  371. b.name as materialName,
  372. h.name as supplierName,
  373. a.serial,
  374. a.type,
  375. c.user_name as userName,
  376. e.name as department,
  377. g.storage_location_name as storageLocationName,
  378. a.scrq,
  379. a.num
  380. from tld_removal a
  381. left join tld_material b on a.wllb_code = b.code
  382. left join tld_user c on a.user_id = c.id
  383. left join tld_department e on a.department = e.code
  384. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  385. left join tld_customer h on a.supplier_id = h.code
  386. <trim prefix="WHERE" prefixOverrides="and |or">
  387. <if test="wllbCode != null and wllbCode != ''">
  388. and a.wllb_code = #{wllbCode}
  389. </if>
  390. <if test="startTime != null and startTime != ''">
  391. and a.scrq <![CDATA[>=]]> #{startTime}
  392. </if>
  393. <if test="endTime != null and endTime != ''">
  394. and a.scrq <![CDATA[<=]]> #{endTime}
  395. </if>
  396. <if test="type != null and type != ''">
  397. and a.type like CONCAT(CONCAT('%', #{type}), '%')
  398. </if>
  399. </trim>
  400. order by a.id desc
  401. </select>
  402. <!-- 查询指定pda出库虚拟表 -->
  403. <select id="getAskGoodsVitrual" resultType="com.tld.model.AskGoods">
  404. select
  405. id,
  406. unique_code,
  407. supplier_id,
  408. serial,
  409. wllb_code,
  410. produc_date,
  411. ask_goods_id,
  412. type,
  413. storage_location_code,
  414. num,
  415. user_id,
  416. department
  417. from tld_ask_goods_vitrual
  418. where unique_code = #{uniqueCode} and type = #{type}
  419. </select>
  420. <!-- 删除指定虚拟表数据 -->
  421. <delete id="delAskGoodsVitrual">
  422. delete from tld_ask_goods_vitrual where id = #{id} and type = #{type}
  423. </delete>
  424. <!-- 删除出库回传主表信息 -->
  425. <delete id="delPlugOutRemoval">
  426. delete from tld_return_gs_removal where document_id = #{removalCode}
  427. </delete>
  428. <!-- 删除出库回传子表信息 -->
  429. <delete id="delRemovalz">
  430. delete from tld_return_gs_removal_z where document_id = #{removalCode}
  431. </delete>
  432. <!-- 删除入库回传信息 -->
  433. <delete id="delPlugOutWarehousing">
  434. delete from tld_return_gs_warehousing where order_number = #{orderNumber}
  435. </delete>
  436. <!-- 修改出库数量 -->
  437. <update id="updateOutNum">
  438. update tld_ask_goods
  439. set out_num = ifnull(out_num, 0) + #{num} where material_id = #{materialId} and ask_goods_id = #{askGoodsId}
  440. </update>
  441. <!-- 查询指定pda 指定物料扫描总数 -->
  442. <select id="getScanNum" resultType="String">
  443. select if(sum(num) is null, 0, num)
  444. from tld_ask_goods_vitrual
  445. where unique_code = #{uniqueCode} and ask_goods_id = #{askGoodsId} and wllb_code = #{wllbCode}
  446. </select>
  447. <!-- 查询半成品出库数据 -->
  448. <select id="getGoodsHalf" resultType="com.tld.model.AskGoods">
  449. SELECT
  450. a.id,
  451. a.material_id,
  452. a.num,
  453. a.production_code,
  454. b.name as materialName,
  455. b.code as materialCode,
  456. a.out_num,
  457. a.ask_goods_id,
  458. c.company_number,
  459. e.name as department,
  460. a.type,
  461. a.wbs
  462. FROM
  463. tld_ask_goods a
  464. join tld_material b on a.material_id = b.tld_id
  465. join tld_ask_goods_f c on a.ask_goods_id = c.ask_goods_id
  466. left join tld_department e on c.department = e.code
  467. WHERE
  468. (a.num + 0) <![CDATA[>]]> (a.out_num + 0) and b.part_type = #{partType}
  469. <if test="productionCode != null and productionCode != ''">
  470. and a.production_code = #{productionCode}
  471. </if>
  472. <if test="askGoodsId != null and askGoodsId != ''">
  473. and a.ask_goods_id = #{askGoodsId}
  474. </if>
  475. <if test="id != null and id != ''">
  476. and a.id = #{id}
  477. </if>
  478. <if test="type != null and type != ''">
  479. and a.type = #{type}
  480. </if>
  481. </select>
  482. <!-- 查询半成品出库流水 -->
  483. <select id="getRemovalHalfProduct" resultType="com.tld.model.AskGoods">
  484. select
  485. a.id,
  486. a.wllb_code,
  487. a.num,
  488. a.user_id,
  489. a.scrq,
  490. a.ask_goods_id,
  491. c.name as department,
  492. b.name as materialName,
  493. e.user_name as userName,
  494. b.code as materialCode,
  495. a.storage_code,
  496. a.wbs
  497. from tld_removal_half_product a
  498. left join tld_material b on a.wllb_code = b.code
  499. left join tld_department c on a.department = c.code
  500. left join tld_user e on a.user_id = e.id
  501. <if test="wllbCode != null and wllbCode != ''">
  502. and a.wllb_code = #{wllbCode}
  503. </if>
  504. <if test="startTime != null and startTime != ''">
  505. and a.scrq <![CDATA[>=]]> #{startTime}
  506. </if>
  507. <if test="endTime != null and endTime != ''">
  508. and a.scrq <![CDATA[<=]]> #{endTime}
  509. </if>
  510. order by a.scrq desc
  511. </select>
  512. <!-- 查询半成品出库流水导出 -->
  513. <select id="getRemovalHalfProductExcel" resultType="java.util.LinkedHashMap">
  514. select
  515. b.name as materialName,
  516. a.num,
  517. e.user_name as userName,
  518. a.scrq,
  519. a.ask_goods_id,
  520. c.name as department,
  521. a.storage_code,
  522. a.wbs
  523. from tld_removal_half_product a
  524. left join tld_material b on a.wllb_code = b.code
  525. left join tld_department c on a.department = c.code
  526. left join tld_user e on a.user_id = e.id
  527. <if test="wllbCode != null and wllbCode != ''">
  528. and a.wllb_code = #{wllbCode}
  529. </if>
  530. <if test="startTime != null and startTime != ''">
  531. and a.scrq <![CDATA[>=]]> #{startTime}
  532. </if>
  533. <if test="endTime != null and endTime != ''">
  534. and a.scrq <![CDATA[<=]]> #{endTime}
  535. </if>
  536. order by a.scrq desc
  537. </select>
  538. <!-- 产成品出库流水 -->
  539. <select id="getRemovalHalf" resultType="com.tld.model.AskGoods">
  540. select
  541. a.id,
  542. a.wllb_code,
  543. a.num,
  544. a.user_id,
  545. a.scrq,
  546. a.delivery_id,
  547. a.company_number,
  548. a.customer_code,
  549. b.name as materialName,
  550. c.user_name as userName,
  551. e.name as customerName,
  552. f.name as companyName,
  553. b.code as materialCode,
  554. a.storage_code,
  555. a.wbs
  556. from tld_removal_half a
  557. left join tld_material b on a.wllb_code = b.code
  558. left join tld_user c on a.user_id = c.id
  559. left join tld_customer e on a.customer_code = e.code
  560. left join tld_company f on a.company_number = f.tld_id
  561. <if test="wllbCode != null and wllbCode != ''">
  562. and a.wllb_code = #{wllbCode}
  563. </if>
  564. <if test="startTime != null and startTime != ''">
  565. and a.scrq <![CDATA[>=]]> #{startTime}
  566. </if>
  567. <if test="endTime != null and endTime != ''">
  568. and a.scrq <![CDATA[<=]]> #{endTime}
  569. </if>
  570. order by a.scrq desc
  571. </select>
  572. <!-- 产成品导出出库流水 -->
  573. <select id="getRemovalHalfExcel" resultType="java.util.LinkedHashMap">
  574. select
  575. b.name as materialName,
  576. a.num,
  577. c.user_name as userName,
  578. a.scrq,
  579. f.name as companyName,
  580. e.name,
  581. a.storage_code,
  582. a.wbs
  583. from tld_removal_half a
  584. left join tld_material b on a.wllb_code = b.code
  585. left join tld_user c on a.user_id = c.id
  586. left join tld_customer e on a.customer_code = e.code
  587. left join tld_company f on a.company_number = f.tld_id
  588. <if test="wllbCode != null and wllbCode != ''">
  589. and a.wllb_code = #{wllbCode}
  590. </if>
  591. <if test="startTime != null and startTime != ''">
  592. and a.scrq <![CDATA[>=]]> #{startTime}
  593. </if>
  594. <if test="endTime != null and endTime != ''">
  595. and a.scrq <![CDATA[<=]]> #{endTime}
  596. </if>
  597. order by a.scrq desc
  598. </select>
  599. <!-- 查询指定物料的库存 -->
  600. <select id="getInventoryInfo" resultType="com.tld.model.Inventory">
  601. select
  602. id,
  603. storage_location_code,
  604. wllb_class,
  605. library_type,
  606. material_id,
  607. amount,
  608. total,
  609. totime,
  610. hold,
  611. amount_lock,
  612. account_sleeve,
  613. wbs,
  614. supplier_id,
  615. serial,
  616. wllb_code,
  617. produc_date,
  618. scrq,
  619. produc_batch,
  620. attribute
  621. from tld_inventory where storage_location_code = #{storageLocationCode} and material_id = #{materialId} and account_sleeve = #{accountSleeve} and amount <![CDATA[>=]]> #{num}
  622. <if test="wbs != '' and wbs != null">
  623. and wbs = #{wbs}
  624. </if>
  625. <if test="wbs == ''.toString() or wbs == null ">
  626. and wbs is null
  627. </if>
  628. <if test="serial != '' and serial != null">
  629. and serial = #{serial}
  630. </if>
  631. <if test="attribute != '' and attribute != null">
  632. and attribute = #{attribute}
  633. </if>
  634. <if test="producDate != '' and producDate != null">
  635. and produc_batch = #{producDate}
  636. </if>
  637. <if test="supplierId != '' and supplierId != null">
  638. and supplier_id = #{supplierId}
  639. </if>
  640. </select>
  641. <!-- 其他入库查询库存是否存在 -->
  642. <select id="getInventoryInfoOther" resultType="com.tld.model.Inventory">
  643. select
  644. a.id,
  645. a.storage_location_code,
  646. a.wllb_class,
  647. a.library_type,
  648. a.material_id,
  649. a.amount,
  650. a.total,
  651. a.totime,
  652. a.hold,
  653. a.amount_lock,
  654. a.account_sleeve,
  655. a.wbs,
  656. a.supplier_id,
  657. a.serial,
  658. a.wllb_code,
  659. a.produc_date,
  660. a.scrq,
  661. a.produc_batch,
  662. a.attribute,
  663. b.name as accountName,
  664. c.storage_location_name as storageLocationName
  665. from tld_inventory a
  666. left join tld_company b on a.account_sleeve = b.code
  667. left join tld_storage_location c on a.storage_location_code = c.storage_location_code
  668. where material_id = #{materialId}
  669. <if test="wbs != '' and wbs != null">
  670. and a.wbs = #{wbs}
  671. </if>
  672. <if test="serial != '' and serial != null">
  673. and a.serial = #{serial}
  674. </if>
  675. <if test="attribute != '' and attribute != null">
  676. and a.attribute = #{attribute}
  677. </if>
  678. <if test="producDate != '' and producDate != null">
  679. and a.produc_batch = #{producDate}
  680. </if>
  681. <if test="supplierId != '' and supplierId != null">
  682. and a.supplier_id = #{supplierId}
  683. </if>
  684. <if test="storageLocationCode != '' and storageLocationCode != null">
  685. and a.storage_location_code = #{storageLocationCode}
  686. </if>
  687. <if test="accountSleeve != '' and accountSleeve != null">
  688. and a.account_sleeve = #{accountSleeve}
  689. </if>
  690. </select>
  691. <!-- 查询仓库 -->
  692. <select id="getWarehouseWhere" resultType="String">
  693. SELECT
  694. DISTINCT b.warehouse_where
  695. FROM
  696. tld_return_gs_removal_z a
  697. JOIN tld_storage_location b ON a.storage_location_code = b.storage_location_code
  698. WHERE
  699. a.document_id = #{removalCode}
  700. </select>
  701. <!-- 查询半成品原始数据 -->
  702. <select id="getInventoryNotice" resultType="java.util.Map">
  703. select * from tld_notice where id = #{id}
  704. </select>
  705. <!-- 删除半成品/产成品入库通知原始信息 -->
  706. <delete id="delInventoryNotice">
  707. delete from tld_notice where id = #{id}
  708. </delete>
  709. <!-- 查询要料申请单 -->
  710. <select id="getDelAskGoods" resultType="java.util.Map">
  711. select * from tld_ask_goods where id = #{id}
  712. </select>
  713. <!-- 销售发货单接口文档 父表信息 -->
  714. <select id="getGsRemoval" resultType="java.util.Map">
  715. select
  716. id,
  717. document_id as askGoodsId,
  718. removal_code as removalCode,
  719. source_type as sourceType,
  720. move_type as moveType,
  721. scrq
  722. from tld_return_gs_removal where document_id = #{removalCode}
  723. </select>
  724. <!--查询移库子表中的供货仓库仓库-->
  725. <select id="getSupplyWarehouseWhere" resultType="java.lang.String">
  726. SELECT
  727. supply_warehouse_id
  728. FROM
  729. tld_return_warehouse_transfer_z
  730. WHERE
  731. warehouse_transfer_id = #{removalCode}
  732. GROUP BY
  733. supply_warehouse_id
  734. </select>
  735. <!--查询移库父表信息-->
  736. <select id="getReturnWarehouseTransfer" resultType="java.util.Map">
  737. select
  738. id,
  739. warehouse_transfer_id as warehouseTransferId,
  740. warehouse_transfer_code as warehouseTransferCode,
  741. ask_goods_warehouse_id as askGoodsWarehouseId,
  742. warehouse_transfer_type as warehouseTransferType,
  743. scrq
  744. from tld_return_warehouse_transfer
  745. where warehouse_transfer_code = #{removalCode}
  746. </select>
  747. <!--查询出父表中的移库id根据code-->
  748. <select id="getSupplyWarehouseWheres" resultType="java.lang.String">
  749. select warehouse_transfer_id as warehouseTransferId from tld_return_warehouse_transfer where warehouse_transfer_code = #{removalCode}
  750. </select>
  751. <!--查询移库子表信息-->
  752. <select id="getReturnWarehouseTransferZ" resultType="java.util.Map">
  753. select a.id,
  754. a.warehouse_transfer_id as warehouseTransferId,
  755. a.entry_number as entryNumber,
  756. a.supply_warehouse_id as supplyWarehouseId,
  757. a.material_id as materialId,
  758. ifnull(a.wbs, '') as wbsId,
  759. a.out_num as outNum,
  760. ifnull(b.code, '') as wbsCode,
  761. ifnull(b.name, '') as wbsName
  762. from tld_return_warehouse_transfer_z a
  763. left join tld_wbs b on a.wbs = b.tld_id
  764. where a.warehouse_transfer_id = #{warehouseTransferId}
  765. and a.supply_warehouse_id = #{warehouseWhere}
  766. </select>
  767. <!-- 删除生产领料 -->
  768. <delete id="delAskGoods">
  769. delete from tld_ask_goods where id = #{id}
  770. </delete>
  771. <!--删除移库父表-->
  772. <delete id="delReturnWarehouseTransfer">
  773. delete from tld_return_warehouse_transfer where warehouse_transfer_code = #{removalCode}
  774. </delete>
  775. <!--删除移库子表-->
  776. <delete id="delReturnWarehouseTransferZ">
  777. delete from tld_return_warehouse_transfer_z where warehouse_transfer_id = #{warehouseTransferTd}
  778. </delete>
  779. </mapper>