WarehousingMapper.xml 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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.WarehousingMapper">
  5. <sql id="field">
  6. order_code
  7. ,material_id,purchase_num,arrival_num,type,qualified_num,disqualification_num,wbs,arrival_time,measurement_id,supplier_id,entry_number,warehousing_num
  8. </sql>
  9. <!-- 查询物料库位 -->
  10. <select id="getMaterialClass" resultType="com.tld.model.MaterialClass">
  11. select a.id,
  12. a.storage_location_code,
  13. a.wllb_code
  14. from tld_material_class a
  15. join tld_material b on a.wllb_code = b.code
  16. where b.code = #{wllbCode}
  17. </select>
  18. <!-- 根据物料分类查询库位 -->
  19. <select id="getMaterialClassType" resultType="com.tld.model.MaterialClass">
  20. select b.id,
  21. b.storage_location_code
  22. from tld_material a
  23. join tld_storage_location b on b.storage_location_type like CONCAT('%', a.wllb_class, '%')
  24. where a.code = #{wllbCode}
  25. </select>
  26. <!-- 新增库位信息虚拟表 -->
  27. <insert id="addWarehousingVirtual">
  28. insert into tld_warehousing_virtual(unique_code, num, storage_location_code, wllb_code, supp_id, serial, type,
  29. produc_date, capacity, seq, user_id, storage_location_name, attribute,
  30. notice_id, warehouse_transfer_id, storage_location_code_ck,wbs, receive_goods_id, account_sleeve)
  31. values (#{uniqueCode}, #{num}, #{storageLocationCode}, #{wllbCode}, #{suppId}, #{serial}, #{type},
  32. #{producDate}, #{capacity}, #{seq}, #{userId}, #{storageLocationName}, #{attribute}, #{noticeId},
  33. #{warehouseTransferId}, #{storageLocationCodeCk},#{wbs},#{receiveGoodsId},#{accountSleeve})
  34. </insert>
  35. <!-- 查询总数量 -->
  36. <select id="getScanNum" resultType="java.util.Map">
  37. SELECT (ifnull(sum(a.num), 0) + ${num} + ifnull(sum(c.amount), 0)) as scanNum,
  38. ifnull(b.storage_location_capacity, 0) as storageLocationCapacity
  39. FROM tld_warehousing_virtual a
  40. right join tld_storage_location b on a.storage_location_code = b.storage_location_code
  41. left join tld_inventory c on b.storage_location_code = c.storage_location_code
  42. where b.storage_location_code = #{storageLocationCode}
  43. </select>
  44. <!-- 查询 -->
  45. <select id="recommend" resultType="com.tld.model.StorageLocation">
  46. SELECT id,
  47. storage_location_code,
  48. storage_location_name,
  49. warehouse_where,
  50. storage_location_type,
  51. storage_location_capacity,
  52. is_not_disable,
  53. create_time
  54. FROM tld_storage_location
  55. WHERE #{storageLocationCode} like CONCAT('%', CONCAT(storage_location_code, ','), '%')
  56. and warehouse_where != '5000'
  57. </select>
  58. <!-- 查询是否是混合物料 -->
  59. <select id="getIsNotSisable" resultType="String">
  60. select is_not_disable
  61. from tld_material
  62. where code = #{wllbCode}
  63. </select>
  64. <!-- 查询混合库位 -->
  65. <select id="getIsNotSisableLocation" resultType="com.tld.model.StorageLocation">
  66. select id,
  67. storage_location_code,
  68. storage_location_name,
  69. warehouse_where,
  70. storage_location_type,
  71. storage_location_capacity,
  72. is_not_disable,
  73. create_time
  74. from tld_storage_location
  75. where is_not_disable = #{isNotDisable}
  76. </select>
  77. <!-- 删除虚拟表 -->
  78. <delete id="delWarehousingVirtual">
  79. delete
  80. from tld_warehousing_virtual
  81. where id = #{id}
  82. </delete>
  83. <!-- 查询虚拟表数据进行入库 -->
  84. <select id="getVirtual" resultType="com.tld.model.WarehousingVirtual">
  85. select
  86. a.id,
  87. a.unique_code,
  88. a.num,
  89. a.storage_location_code,
  90. a.wllb_code,
  91. a.supp_id,
  92. a.serial,
  93. a.type,
  94. a.produc_date,
  95. a.capacity,
  96. a.seq,
  97. a.user_id,
  98. a.attribute,
  99. a.warehouse_transfer_id,
  100. a.storage_location_code_ck,
  101. a.storage_location_name,
  102. b.user_name,
  103. a.receive_goods_id,
  104. a.wbs,
  105. a.account_sleeve,
  106. a.warehouse_transfer_id
  107. from tld_warehousing_virtual a
  108. left join tld_user b on a.user_id = b.id
  109. where a.unique_code = #{uniqueCode} and a.type = #{type}
  110. <if test="warehouseTransferId != null and warehouseTransferId != ''">
  111. and a.warehouse_transfer_id = #{warehouseTransferId}
  112. </if>
  113. </select>
  114. <!-- 查询采购单信息 -->
  115. <select id="getReceiveGoods" resultType="com.tld.model.ReceiveGoods">
  116. SELECT a.id,
  117. a.order_code,
  118. a.material_id,+
  119. a.purchase_num,
  120. a.arrival_num,
  121. a.type,
  122. a.qualified_num,
  123. a.disqualification_num,
  124. a.wbs,
  125. a.arrival_time,
  126. a.measurement_id,
  127. a.supplier_id,
  128. a.entry_number,
  129. a.warehousing_num,
  130. b.company_number,
  131. b.order_number,
  132. b.source_type,
  133. b.move_type,
  134. f.name as supplierName
  135. FROM tld_receive_goods a
  136. LEFT JOIN tld_receive_goods_f b on a.order_code = b.order_code
  137. JOIN tld_material c on a.material_id = c.tld_id
  138. LEFT JOIN tld_customer f on a.supplier_id = f.code
  139. WHERE a.supplier_id = #{suppId}
  140. and IFNULL(a.warehousing_num, 0) <![CDATA[<]]> a.qualified_num
  141. and c.code = #{wllbCode}
  142. ORDER BY a.arrival_time DESC
  143. </select>
  144. <!-- 修改采购单入库数量 -->
  145. <update id="updateReceiveGood">
  146. update tld_receive_goods
  147. set warehousing_num = warehousing_num + #{warehousingNum}
  148. where id = #{id}
  149. </update>
  150. <!-- 查询物料类型 -->
  151. <select id="getWlClass" resultType="com.tld.model.WarehousingVirtual">
  152. select wllb_class, tld_id as materialId
  153. from tld_material
  154. where code = #{wllbCode}
  155. </select>
  156. <!-- 插入入库流水 -->
  157. <insert id="addStorage">
  158. insert into
  159. tld_storage(wllb_code,supplier_id,serial,produc_date,produc_batch,capacity,seq,type,user_id,department_id,storage_location_code,scrq,storage_code,wbs,order_code)
  160. values
  161. <foreach collection="list" index="index" item="item" separator=",">
  162. (#{item.wllbCode},#{item.suppId},#{item.serial},#{item.producDate},#{item.producDate},#{item.num},#{item.seq},#{item.type},#{item.userId},#{item.departmentId},#{item.storageLocationCode},now(),#{item.storageCode},#{item.wbs},#{item.warehouseTransferId})
  163. </foreach>
  164. </insert>
  165. <!-- 插入库存 -->
  166. <insert id="addInventory">
  167. insert into
  168. tld_inventory(storage_location_code,wllb_class,material_id,amount,totime,hold,amount_lock,account_sleeve,wbs,supplier_id,serial,wllb_code,produc_date,scrq,produc_batch,attribute)
  169. values
  170. <foreach collection="list" index="index" item="item" separator=",">
  171. (#{item.storageLocationCode},#{item.wllbClass},#{item.materialId},#{item.num},now(),'0','0',#{item.accountSleeve},#{item.wbs},#{item.suppId},#{item.serial},#{item.wllbCode},#{item.producDate},
  172. now(),#{item.producDate},#{item.attribute})
  173. </foreach>
  174. </insert>
  175. <!-- 删除临时表数据 -->
  176. <delete id="delVirtual">
  177. delete
  178. from tld_warehousing_virtual
  179. where unique_code = #{uniqueCode}
  180. </delete>
  181. <!-- 查询当天质检数量 -->
  182. <select id="getWarehousingCount" resultType="int">
  183. select count(*)
  184. from tld_return_gs_warehousing
  185. where scrq BETWEEN CONCAT(CURDATE(), ' 00:00:00') AND CONCAT(CURDATE(), ' 23:59:59');
  186. </select>
  187. <!-- 存入为gs穿的信息 -->
  188. <insert id="addReturnWarehousing">
  189. insert into tld_return_gs_warehousing(storage_code, gs_ck, source_type, move_type, entry_number, wbs,
  190. material_id, warehousing_num, receive_goods_id, scrq, order_number,
  191. user_name, storage_location_code)
  192. values (#{storageCode}, #{gsCk}, #{sourceType}, #{moveType}, #{entryNumber}, #{wbs}, #{materialId},
  193. #{warehousingNum}, #{id}, now(), #{orderNumber}, #{userName}, #{storageLocationCode});
  194. </insert>
  195. <!-- 入库回传 -->
  196. <select id="getPlugOutWarehousing" resultType="com.tld.model.ReturnWarehousing">
  197. select a.*,
  198. ifnull(a.wbs, '') as wbsId,
  199. ifnull(b.code, '') as wbsCode,
  200. ifnull(b.name, '') as wbsName
  201. from tld_return_gs_warehousing a
  202. left join tld_wbs b on a.wbs = b.tld_id
  203. where #{orderNumber} LIKE CONCAT('%', CONCAT(order_number, ','), '%')
  204. </select>
  205. <!-- 查询入库流水 -->
  206. <select id="warehousingFlowing" resultType="com.tld.model.Storage">
  207. select
  208. a.id,
  209. b.name as materialName,
  210. a.wllb_code,
  211. h.name as supplierName,
  212. a.serial,
  213. a.produc_date,
  214. a.produc_batch,
  215. a.capacity,
  216. a.seq,
  217. a.type,
  218. c.user_name as userName,
  219. e.name as departmentName,
  220. g.storage_location_name as storageLocationName,
  221. a.scrq,
  222. a.storage_code,
  223. a.wbs,
  224. c.real_name as realName,
  225. a.order_code as orderCode
  226. from tld_storage a
  227. left join tld_material b on a.wllb_code = b.code
  228. left join tld_user c on a.user_id = c.id
  229. left join tld_department e on a.department_id = e.code
  230. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  231. left join tld_customer h on a.supplier_id = h.code
  232. <trim prefix="WHERE" prefixOverrides="and |or">
  233. <if test="storageCode != null and storageCode != ''">
  234. and a.storage_code like CONCAT(CONCAT('%', #{storageCode}), '%')
  235. </if>
  236. <if test="wllbCode != null and wllbCode != ''">
  237. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  238. </if>
  239. <if test="materialName != null and materialName != ''">
  240. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  241. </if>
  242. <if test="userName != null and userName != ''">
  243. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  244. </if>
  245. <if test="realName != null and realName != ''">
  246. and c.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  247. </if>
  248. <if test="storageLocationName != null and storageLocationName != ''">
  249. and g.storage_location_name like CONCAT(CONCAT('%', #{storageLocationName}), '%')
  250. </if>
  251. <if test="wbs != null and wbs != ''">
  252. and a.wbs like CONCAT(CONCAT('%', #{wbs}), '%')
  253. </if>
  254. <if test="orderCode != null and orderCode != ''">
  255. and a.order_code like CONCAT(CONCAT('%', #{orderCode}), '%')
  256. </if>
  257. <if test="supplierId != null and supplierId != ''">
  258. and a.supplier_id = #{supplierId}
  259. </if>
  260. <if test="startTime != null and startTime != ''">
  261. and a.scrq <![CDATA[>=]]> #{startTime}
  262. </if>
  263. <if test="endTime != null and endTime != ''">
  264. and a.scrq <![CDATA[<=]]> #{endTime}
  265. </if>
  266. </trim>
  267. order by scrq desc
  268. </select>
  269. <!-- 查询虚拟入库 -->
  270. <select id="getWarehousingVirtual" resultType="com.tld.model.WarehousingVirtual">
  271. select id,
  272. unique_code,
  273. num,
  274. storage_location_code,
  275. wllb_code,
  276. supp_id,
  277. serial,
  278. type,
  279. produc_date,
  280. capacity,
  281. seq,
  282. user_id,
  283. storage_location_name,
  284. warehouse_transfer_id,
  285. wbs,
  286. receive_goods_id
  287. from tld_warehousing_virtual
  288. where unique_code = #{uniqueCode}
  289. and type = #{type} and warehouse_transfer_id = #{warehouseTransferId}
  290. order by id desc
  291. </select>
  292. <!-- 查询导出内容 -->
  293. <select id="export" resultType="java.util.LinkedHashMap">
  294. select
  295. b.name as materialName,
  296. a.wllb_code as wllbCode,
  297. h.name as supplierName,
  298. if(a.serial = '', null ,a.serial) as serial,
  299. if(a.produc_date = '', null ,a.produc_date) as producDate,
  300. if(a.produc_batch = '', null ,a.produc_batch) as producbatch,
  301. a.capacity,
  302. a.seq,
  303. a.type,
  304. c.user_name as userName,
  305. e.name as departmentName,
  306. g.storage_location_name as storageLocationName,
  307. a.scrq,
  308. a.storage_code,
  309. a.wbs,
  310. c.real_name as realName,
  311. a.order_code as orderCode
  312. from tld_storage a
  313. left join tld_material b on a.wllb_code = b.code
  314. left join tld_user c on a.user_id = c.id
  315. left join tld_department e on a.department_id = e.code
  316. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  317. left join tld_customer h on a.supplier_id = h.code
  318. <trim prefix="WHERE" prefixOverrides="and |or">
  319. <if test="storageCode != null and storageCode != ''">
  320. and a.storage_code like CONCAT(CONCAT('%', #{storageCode}), '%')
  321. </if>
  322. <if test="wllbCode != null and wllbCode != ''">
  323. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  324. </if>
  325. <if test="materialName != null and materialName != ''">
  326. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  327. </if>
  328. <if test="userName != null and userName != ''">
  329. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  330. </if>
  331. <if test="realName != null and realName != ''">
  332. and c.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  333. </if>
  334. <if test="storageLocationName != null and storageLocationName != ''">
  335. and g.storage_location_name like CONCAT(CONCAT('%', #{storageLocationName}), '%')
  336. </if>
  337. <if test="wbs != null and wbs != ''">
  338. and a.wbs like CONCAT(CONCAT('%', #{wbs}), '%')
  339. </if>
  340. <if test="orderCode != null and orderCode != ''">
  341. and a.order_code like CONCAT(CONCAT('%', #{orderCode}), '%')
  342. </if>
  343. <if test="supplierId != null and supplierId != ''">
  344. and a.supplier_id = #{supplierId}
  345. </if>
  346. <if test="startTime != null and startTime != ''">
  347. and a.scrq <![CDATA[>=]]> #{startTime}
  348. </if>
  349. <if test="endTime != null and endTime != ''">
  350. and a.scrq <![CDATA[<=]]> #{endTime}
  351. </if>
  352. </trim>
  353. order by a.scrq desc
  354. </select>
  355. <!-- 查询是否扫描 -->
  356. <select id="getScanIsNot" resultType="java.util.Map">
  357. select
  358. (select count(*)
  359. from tld_inventory a
  360. join tld_storage_location b on a.storage_location_code = b.storage_location_code
  361. where a.supplier_id = #{suppId} and a.serial = #{unique} and a.wllb_code = #{wllbCode} and a.produc_date =
  362. #{producDate}
  363. <if test="warehouseWhere != null and warehouseWhere != ''">
  364. and b.warehouse_where = #{warehouseWhere}
  365. </if>) as inventoryCount,
  366. (select count(*) from tld_warehousing_virtual where supp_id = #{suppId} and serial = #{unique} and wllb_code =
  367. #{wllbCode} and produc_date = #{producDate}) as virtualCount
  368. from dual
  369. </select>
  370. <!-- 查询物料是否存在 -->
  371. <select id="getMateriaIsExist" resultType="com.tld.model.MaterialClass">
  372. select id,
  373. code,
  374. name,
  375. tld_id,
  376. specification_and_model,
  377. unit_of_measurement,
  378. ifnull(size, 0) as size,
  379. wllb_class,
  380. is_not_disable,
  381. is_recommend,
  382. part_type
  383. from tld_material
  384. where code = #{wllbCode}
  385. </select>
  386. <!-- 查询库存是否同物料同批次存在 -->
  387. <select id="getInventoryProduc" resultType="int">
  388. SELECT produc_date as producDate
  389. FROM tld_inventory a
  390. JOIN tld_material b ON a.material_id = b.tld_id
  391. WHERE a.produc_date = #{producDate}
  392. AND b.code = #{wllbCode}
  393. and a.storage_location_code = #{storageLocationCode}
  394. and hold = '0'
  395. </select>
  396. <!-- 查询报工单 -->
  397. <select id="getNotice" resultType="com.tld.model.Notice">
  398. select
  399. a.id,
  400. a.notice_id,
  401. a.entry_number,
  402. a.production_code,
  403. a.material_id,
  404. a.wbs,
  405. a.measurement_id,
  406. a.num,
  407. a.type,
  408. a.warehousing_num,
  409. b.company_number,
  410. c.name as materialName,
  411. c.wllb_class as wllbClass,
  412. c.code as wllbCode,
  413. e.name as companyName,
  414. b.notice_time as noticeTime,
  415. b.source_type as sourceType,
  416. b.move_type as moveType,
  417. b.notice_code as noticeCode
  418. from tld_notice a
  419. join tld_notice_f b on a.notice_id = b.notice_id
  420. join tld_material c on a.material_id = c.tld_id
  421. join tld_company e on b.company_number = e.code
  422. <trim prefix="WHERE" prefixOverrides="and |or">
  423. <if test="type != null and type != ''">
  424. and a.type = #{type}
  425. </if>
  426. <if test="noticeId != null and noticeId != ''">
  427. and a.notice_id like CONCAT(CONCAT('%', #{noticeId}), '%')
  428. </if>
  429. <if test="entryNumber != null and entryNumber != ''">
  430. and a.entry_number like CONCAT(CONCAT('%', #{entryNumber}), '%')
  431. </if>
  432. <if test="wllbCode != null and wllbCode != ''">
  433. and c.code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  434. </if>
  435. <if test="materialName != null and materialName != ''">
  436. and c.name like CONCAT(CONCAT('%', #{materialName}), '%')
  437. </if>
  438. <if test="startTime != null and startTime != ''">
  439. and b.notice_time <![CDATA[>=]]> #{startTime}
  440. </if>
  441. <if test="endTime != null and endTime != ''">
  442. and b.notice_time <![CDATA[<=]]> #{endTime}
  443. </if>
  444. <if test="partType != null and partType != ''">
  445. and c.part_type = #{partType}
  446. </if>
  447. <if test="companyNumber != null and companyNumber != ''">
  448. and b.company_number = #{companyNumber}
  449. </if>
  450. <if test="productionCode != null and productionCode != ''">
  451. and a.production_code like CONCAT(CONCAT('%', #{productionCode}), '%')
  452. </if>
  453. <if test="wbs != null and wbs != ''">
  454. and a.wbs like CONCAT(CONCAT('%', #{wbs}), '%')
  455. </if>
  456. <if test="moveType != null and moveType != ''">
  457. and b.move_type like CONCAT(CONCAT('%', #{moveType}), '%')
  458. </if>
  459. <if test="sourceType != null and sourceType != ''">
  460. and b.source_type like CONCAT(CONCAT('%', #{sourceType}), '%')
  461. </if>
  462. <if test="noticeCode != null and noticeCode != ''">
  463. and b.notice_code like CONCAT(CONCAT('%', #{noticeCode}), '%')
  464. </if>
  465. </trim>
  466. order by a.id desc
  467. </select>
  468. <!-- 查询通知单是否入库 -->
  469. <select id="getNoticeId" resultType="com.tld.model.Notice">
  470. select a.id,
  471. a.notice_id,
  472. a.entry_number,
  473. a.production_code,
  474. a.material_id,
  475. a.wbs,
  476. a.measurement_id,
  477. a.num,
  478. a.type,
  479. a.warehousing_num,
  480. b.wllb_class,
  481. c.source_type,
  482. c.move_type,
  483. b.code as materialCode,
  484. c.notice_time as noticeTime,
  485. c.company_number
  486. from tld_notice a
  487. join tld_notice_f c on a.notice_id = c.notice_id
  488. left join tld_material b on a.material_id = b.tld_id
  489. where a.notice_id = #{noticeId}
  490. and a.material_id = #{materialId}
  491. </select>
  492. <!-- 半成品跟部分产成品入库存 -->
  493. <insert id="addInventoryNotice">
  494. insert into tld_inventory(storage_location_code, material_id, amount, hold, amount_lock, account_sleeve, wbs,
  495. produc_date, scrq, wllb_class, produc_batch, attribute, serial, supplier_id,
  496. wllb_code, totime)
  497. value (#{storageLocationCode},#{materialId},#{warehousingNum},'0','0',#{companyNumber},#{wbs},#{producBatch},now(),#{wllbClass},#{producBatch},#{attribute},#{serial},#{supplierId},#{wllbCode},now());
  498. </insert>
  499. <!-- 查询库存里是否存在半成品虚拟库位 -->
  500. <select id="getInventoryNotice" resultType="int">
  501. select count(*)
  502. from tld_inventory
  503. where storage_location_code = #{storageLocationCode}
  504. and material_id = #{materialId}
  505. and account_sleeve = #{companyNumber}
  506. and wbs = #{wbs}
  507. </select>
  508. <!-- 增加半成品/产成品虚拟库位数量 -->
  509. <update id="updateInventoryNotice">
  510. update tld_inventory
  511. set amount = amount + #{warehousingNum},
  512. totime = now()
  513. where storage_location_code = #{storageLocationCode}
  514. and material_id = #{materialId}
  515. and wbs = #{wbs};
  516. </update>
  517. <!-- 半成品出库库存查询 -->
  518. <select id="getHalfInventory" resultType="com.tld.model.Inventory">
  519. select storage_location_code, wllb_class, material_id, amount
  520. from tld_inventory
  521. where storage_location_code = #{storageLocationCode}
  522. and material_id = #{materialId}
  523. and account_sleeve = #{companyNumber}
  524. and wbs = #{wbs}
  525. and hold = '0'
  526. order by produc_batch
  527. </select>
  528. <!-- 删除库存信息 -->
  529. <delete id="delInventoryNotice">
  530. delete
  531. from tld_inventory
  532. where storage_location_code = #{storageLocationCode}
  533. and material_id = #{materialId}
  534. </delete>
  535. <!-- 删减库存 -->
  536. <update id="updateInventoryNoticeNum">
  537. update tld_inventory
  538. set amount = amount - #{warehousingNum}
  539. where storage_location_code = #{storageLocationCode}
  540. and material_id = #{materialId}
  541. </update>
  542. <!-- 新增半成品入库流水 -->
  543. <insert id="addProduct">
  544. insert into tld_half_product(wllb_code, produc_date, produc_batch, capacity, user_id, storage_location_code,
  545. scrq, storage_code, wbs, production_code)
  546. value (#{wllbCode},#{producDate},#{producDate},#{num},#{userId},#{storageLocationCode},now(),#{storageCode},#{wbs}, #{productionCode})
  547. </insert>
  548. <!-- 查询半成品入库流水-->
  549. <select id="getProduct" resultType="com.tld.model.Notice">
  550. select
  551. a.id,
  552. a.wllb_code,
  553. a.produc_date,
  554. a.produc_batch,
  555. a.capacity as warehousingNum,
  556. a.user_id,
  557. c.user_name,
  558. a.storage_location_code,
  559. a.scrq,
  560. b.name as materialName,
  561. b.code as materialCode,
  562. a.storage_code,
  563. a.wbs,
  564. a.production_code,
  565. c.real_name as realName,
  566. a.production_code as productionCode
  567. from tld_half_product a
  568. left join tld_material b on a.wllb_code = b.code
  569. left join tld_user c on a.user_id = c.id
  570. <trim prefix="WHERE" prefixOverrides="and |or">
  571. <if test="startTime != null and startTime != ''">
  572. and a.scrq <![CDATA[>=]]> #{startTime}
  573. </if>
  574. <if test="endTime != null and endTime != ''">
  575. and a.scrq <![CDATA[<=]]> #{endTime}
  576. </if>
  577. <if test="wllbCode != null and wllbCode != ''">
  578. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  579. </if>
  580. <if test="materialName != null and materialName != ''">
  581. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  582. </if>
  583. <if test="storageLocationCode != null and storageLocationCode != ''">
  584. and a.storage_location_code = #{storageLocationCode}
  585. </if>
  586. <if test="userName != null and userName != ''">
  587. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  588. </if>
  589. <if test="realName != null and realName != ''">
  590. and c.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  591. </if>
  592. <if test="productionCode != null and productionCode != ''">
  593. and a.production_code like CONCAT(CONCAT('%', #{productionCode}), '%')
  594. </if>
  595. <if test="storageCode != null and storageCode != ''">
  596. and a.storage_code like CONCAT(CONCAT('%', #{storageCode}), '%')
  597. </if>
  598. <if test="productionCode != null and productionCode != ''">
  599. and a.production_code like CONCAT(CONCAT('%', #{productionCode}), '%')
  600. </if>
  601. <if test="wbs != null and wbs != ''">
  602. and a.wbs like CONCAT(CONCAT('%', #{wbs}), '%')
  603. </if>
  604. </trim>
  605. order by a.scrq desc
  606. </select>
  607. <!-- 查询半成品入库流水导出-->
  608. <select id="productExcel" resultType="java.util.LinkedHashMap">
  609. select
  610. b.name,
  611. a.wllb_code,
  612. a.produc_date,
  613. a.capacity,
  614. c.user_name,
  615. a.scrq,
  616. a.storage_code,
  617. a.wbs,
  618. c.real_name as realName,
  619. a.production_code as productionCode
  620. from tld_half_product a
  621. left join tld_material b on a.wllb_code = b.code
  622. left join tld_user c on a.user_id = c.id
  623. <trim prefix="WHERE" prefixOverrides="and |or">
  624. <if test="startTime != null and startTime != ''">
  625. and a.scrq <![CDATA[>=]]> #{startTime}
  626. </if>
  627. <if test="endTime != null and endTime != ''">
  628. and a.scrq <![CDATA[<=]]> #{endTime}
  629. </if>
  630. <if test="wllbCode != null and wllbCode != ''">
  631. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  632. </if>
  633. <if test="materialName != null and materialName != ''">
  634. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  635. </if>
  636. <if test="storageLocationCode != null and storageLocationCode != ''">
  637. and a.storage_location_code = #{storageLocationCode}
  638. </if>
  639. <if test="userName != null and userName != ''">
  640. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  641. </if>
  642. <if test="realName != null and realName != ''">
  643. and c.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  644. </if>
  645. <if test="productionCode != null and productionCode != ''">
  646. and a.production_code like CONCAT(CONCAT('%', #{productionCode}), '%')
  647. </if>
  648. <if test="storageCode != null and storageCode != ''">
  649. and a.storage_code like CONCAT(CONCAT('%', #{storageCode}), '%')
  650. </if>
  651. <if test="wbs != null and wbs != ''">
  652. and a.wbs like CONCAT(CONCAT('%', #{wbs}), '%')
  653. </if>
  654. </trim>
  655. order by a.scrq desc
  656. </select>
  657. <!-- 查询要料单信息 -->
  658. <select id="getAskGoodsHalf" resultType="com.tld.model.AskGoods">
  659. select a.id,
  660. a.ask_goods_id,
  661. a.material_id,
  662. a.wbs,
  663. a.measurement_id,
  664. a.num,
  665. a.out_num,
  666. a.entry_number,
  667. b.source_type,
  668. b.move_type,
  669. c.code as wllbCode,
  670. a.type,
  671. b.department
  672. from tld_ask_goods a
  673. join tld_ask_goods_f b on a.ask_goods_id = b.ask_goods_id
  674. left join tld_material c on a.material_id = c.tld_id
  675. where a.ask_goods_id = #{askGoodsId}
  676. and a.material_id = #{materialId}
  677. </select>
  678. <!-- 修改要货单出库数量 -->
  679. <update id="updateAskGoodsHalf">
  680. update tld_ask_goods
  681. set out_num = ifnull(out_num, 0) + #{warehousingNum},
  682. type = '1'
  683. where id = #{id}
  684. </update>
  685. <!-- 新增半成品流水 -->
  686. <insert id="addRemovalHalfProduct">
  687. insert into tld_removal_half_product(wllb_code, num, user_id, scrq, ask_goods_id, department, storage_code, wbs, company_number)
  688. value (#{wllbCode},#{num},#{userId},now(),#{askGoodsId},#{department},#{storageCode},#{wbs},#{companyNumber})
  689. </insert>
  690. <!-- 查询指定物料内容 -->
  691. <select id="getMaterial" resultType="com.tld.model.MaterialClass">
  692. select
  693. code as wllbCode,
  694. name as wllbName,
  695. tld_id,
  696. specification_and_model,
  697. unit_of_measurement,
  698. size,
  699. wllb_class,
  700. is_not_disable,
  701. is_recommend,
  702. part_type
  703. from tld_material
  704. <trim prefix="WHERE" prefixOverrides="and |or">
  705. <if test="materialId != null and materialId != ''">
  706. and tld_id = #{materialId}
  707. </if>
  708. <if test="materialCode != null and materialCode != ''">
  709. and code = #{materialCode}
  710. </if>
  711. </trim>
  712. </select>
  713. <!-- 查询库存信息 -->
  714. <select id="getInventoryInfo" resultType="com.tld.model.Inventory">
  715. select storage_location_code,
  716. wllb_class,
  717. library_type,
  718. material_id,
  719. amount,
  720. total,
  721. totime,
  722. hold,
  723. amount_lock,
  724. account_sleeve,
  725. wbs,
  726. supplier_id,
  727. serial,
  728. wllb_code,
  729. produc_date,
  730. scrq,
  731. produc_batch,
  732. attribute
  733. from tld_inventory
  734. where storage_location_code = #{storageLocationCode}
  735. </select>
  736. <!-- 产成品入库 -->
  737. <insert id="addHalf">
  738. insert into tld_half(wllb_code, produc_date, produc_batch, capacity, user_id, storage_location_code, scrq,
  739. serial, seq, attribute, storage_code, wbs, production_code)
  740. value (#{wllbCode},#{producDate},#{producDate},#{num},#{userId},#{storageLocationCode},now(),#{serial},#{seq},#{attribute},#{storageCode},#{wbs},#{productionCode})
  741. </insert>
  742. <!-- 查询虚拟表数据进行入库 -->
  743. <select id="getVirtualNotice" resultType="com.tld.model.WarehousingVirtual">
  744. select a.id,
  745. a.unique_code,
  746. a.num,
  747. a.storage_location_code,
  748. a.wllb_code,
  749. a.supp_id,
  750. a.serial,
  751. a.type,
  752. a.produc_date,
  753. a.capacity,
  754. a.seq,
  755. a.user_id,
  756. a.attribute,
  757. a.storage_location_name,
  758. b.user_name
  759. from tld_warehousing_virtual a
  760. left join tld_user b on a.user_id = b.id
  761. where a.unique_code = #{uniqueCode}
  762. and a.type = #{type}
  763. and a.notice_id = #{noticeId}
  764. </select>
  765. <!-- 产成品入库流水 -->
  766. <select id="getHalf" resultType="com.tld.model.Notice">
  767. select
  768. a.id,
  769. a.wllb_code,
  770. a.produc_date,
  771. a.produc_batch,
  772. a.capacity,
  773. a.user_id,
  774. a.storage_location_code,
  775. e.storage_location_name as storageLocationName,
  776. a.scrq,
  777. a.serial,
  778. a.seq,
  779. a.attribute,
  780. b.name as materialName,
  781. c.user_name as userName,
  782. b.code as materialCode,
  783. a.storage_code,
  784. a.wbs,
  785. c.real_name as realName,
  786. a.production_code as productionCode
  787. from tld_half a
  788. left join tld_material b on a.wllb_code = b.code
  789. left join tld_user c on a.user_id = c.id
  790. left join tld_storage_location e on a.storage_location_code = e.storage_location_code
  791. <trim prefix="WHERE" prefixOverrides="and |or">
  792. <if test="startTime != null and startTime != ''">
  793. and a.scrq <![CDATA[>=]]> #{startTime}
  794. </if>
  795. <if test="endTime != null and endTime != ''">
  796. and a.scrq <![CDATA[<=]]> #{endTime}
  797. </if>
  798. <if test="materialName != null and materialName != ''">
  799. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  800. </if>
  801. <if test="wllbCode != null and wllbCode != ''">
  802. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  803. </if>
  804. <if test="userName != null and userName != ''">
  805. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  806. </if>
  807. <if test="realName != null and realName != ''">
  808. and c.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  809. </if>
  810. <if test="attribute != null and attribute != ''">
  811. and a.attribute like CONCAT(CONCAT('%', #{attribute}), '%')
  812. </if>
  813. <if test="storageCode != null and storageCode != ''">
  814. and a.storage_code like CONCAT(CONCAT('%', #{storageCode}), '%')
  815. </if>
  816. <if test="wbs != null and wbs != ''">
  817. and a.wbs like CONCAT(CONCAT('%', #{wbs}), '%')
  818. </if>
  819. <if test="storageLocationName != null and storageLocationName != ''">
  820. and e.storage_location_name like CONCAT(CONCAT('%', #{storageLocationName}), '%')
  821. </if>
  822. </trim>
  823. order by a.scrq desc
  824. </select>
  825. <!-- 产成品导出 -->
  826. <select id="getHalfExcel" resultType="java.util.LinkedHashMap">
  827. select
  828. b.name as materialName,
  829. a.wllb_code,
  830. if(a.produc_batch = '' , null , a.produc_batch) as producBatch,
  831. a.capacity,
  832. c.user_name as userName,
  833. a.storage_location_code,
  834. a.scrq,
  835. a.serial,
  836. if(a.seq = '' , null , a.seq) as seq,
  837. if(a.attribute = '' , null , a.attribute) as attribute,
  838. a.storage_code,
  839. if(a.wbs = '' , null , a.wbs) as wbs,
  840. c.real_name as realName,
  841. a.production_code as productionCode
  842. from tld_half a
  843. left join tld_material b on a.wllb_code = b.code
  844. left join tld_user c on a.user_id = c.id
  845. <trim prefix="WHERE" prefixOverrides="and |or">
  846. <if test="startTime != null and startTime != ''">
  847. and a.scrq <![CDATA[>=]]> #{startTime}
  848. </if>
  849. <if test="endTime != null and endTime != ''">
  850. and a.scrq <![CDATA[<=]]> #{endTime}
  851. </if>
  852. <if test="materialName != null and materialName != ''">
  853. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  854. </if>
  855. <if test="wllbCode != null and wllbCode != ''">
  856. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  857. </if>
  858. <if test="userName != null and userName != ''">
  859. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  860. </if>
  861. <if test="realName != null and realName != ''">
  862. and c.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  863. </if>
  864. <if test="attribute != null and attribute != ''">
  865. and a.attribute like CONCAT(CONCAT('%', #{attribute}), '%')
  866. </if>
  867. <if test="storageCode != null and storageCode != ''">
  868. and a.storage_code like CONCAT(CONCAT('%', #{storageCode}), '%')
  869. </if>
  870. <if test="wbs != null and wbs != ''">
  871. and a.wbs like CONCAT(CONCAT('%', #{wbs}), '%')
  872. </if>
  873. <if test="productionCode != null and productionCode != ''">
  874. and a.production_code like CONCAT(CONCAT('%', #{productionCode}), '%')
  875. </if>
  876. <if test="storageLocationName != null and storageLocationName != ''">
  877. and e.storage_location_name like CONCAT(CONCAT('%', #{storageLocationName}), '%')
  878. </if>
  879. <if test="productionCode != null and productionCode != ''">
  880. and a.production_code like CONCAT(CONCAT('%', #{productionCode}), '%')
  881. </if>
  882. </trim>
  883. order by a.scrq desc
  884. </select>
  885. <!-- 查询通知单虚拟库扫描数 -->
  886. <select id="getSumScanNumVal" resultType="int">
  887. SELECT ifnull(sum(a.num), 0)
  888. FROM tld_warehousing_virtual a
  889. left join tld_material b on a.wllb_code = b.code
  890. WHERE a.notice_id = #{noticeId} and b.tld_id = #{materialId}
  891. </select>
  892. <!-- 修改报工单入库数量 -->
  893. <update id="updateNotice">
  894. update tld_notice
  895. set warehousing_num = (warehousing_num + 0) + #{warehousingNum}
  896. <if test="type != null and type != ''">
  897. ,type = '1'
  898. </if>
  899. where notice_id = #{noticeId}
  900. and material_id = #{materialId}
  901. </update>
  902. <!-- 查询产成品是否扫描 -->
  903. <select id="getScanIsNotProduct" resultType="java.util.Map">
  904. select (select count(*)
  905. from tld_inventory
  906. where attribute = #{attribute}
  907. and serial = #{serial}
  908. and wllb_code = #{materialCode}
  909. and produc_date = #{producBatch}) as inventoryCount,
  910. (select count(*)
  911. from tld_warehousing_virtual
  912. where attribute = #{attribute}
  913. and serial = #{serial}
  914. and wllb_code = #{materialCode}
  915. and produc_date = #{producBatch}) as virtualCount
  916. from dual
  917. </select>
  918. <!-- 查询昨天没满的库位 -->
  919. <select id="getStorageLocationCode" resultType="String">
  920. SELECT ifnull(max(storage_location_code), "0")
  921. FROM tld_inventory
  922. WHERE attribute = #{attribute} and DATE_FORMAT(scrq,'%Y-%m-%d') <![CDATA[${symbol}]]> CURDATE() and material_id = #{materialId} and account_sleeve = #{companyNumber}
  923. <if test="producBatch != null">
  924. and produc_batch = #{producBatch}
  925. </if>
  926. ORDER BY scrq desc LIMIT 1
  927. </select>
  928. <select id="getCountStorage" resultType="int">
  929. SELECT count(*)
  930. FROM tld_inventory
  931. where attribute = #{attribute}
  932. and storage_location_code = #{storageLocationCode}
  933. and DATE_FORMAT(scrq,'%Y-%m-%d') <![CDATA[${symbol}]]> CURDATE()
  934. and material_id = #{materialId}
  935. <if test="producBatch != null">
  936. and produc_batch = #{producBatch}
  937. </if>
  938. ORDER BY scrq desc LIMIT 1
  939. </select>
  940. <!-- 增加流水入库编号 -->
  941. <update id="updateStorage">
  942. update tld_storage
  943. set storage_code = #{storageCode}
  944. where wllb_code = #{wllbCode}
  945. and supplier_id = #{suppId}
  946. and serial = #{serial}
  947. and produc_batch = #{producDate}
  948. </update>
  949. <!-- 查询公共设置 -->
  950. <select id="getNumUtil" resultType="int">
  951. select num
  952. from tld_util
  953. where type = #{type}
  954. </select>
  955. <!-- 其他入库 -->
  956. <update id="updateInventoryOther">
  957. update tld_inventory
  958. set amount = (amount + 0) + #{amount}
  959. where id = #{id}
  960. </update>
  961. <!-- 移库虚拟库入库 -->
  962. <update id="updateVitrualNum">
  963. update tld_inventory
  964. set amount = amount + #{num}
  965. where material_id = #{materialId}
  966. and storage_location_code = #{storageLocationCode}
  967. </update>
  968. <!-- 其他入库返回gs -->
  969. <insert id="addReturnWarehousingOther">
  970. insert into tld_return_gs_other_warehousing(storage_code, account_sleeve, storage_location_code, wbs, amount,
  971. material_id)
  972. value (#{storageCode},#{accountSleeve},#{storageLocationCode},#{wbs},#{num},#{materialId})
  973. </insert>
  974. <!-- 其他入库 -->
  975. <insert id="addInventoryOther">
  976. insert into tld_inventory(storage_location_code, wllb_class, library_type, material_id, amount, totime,
  977. amount_lock, account_sleeve, wbs, supplier_id, serial, wllb_code, produc_date, scrq,
  978. produc_batch, attribute)
  979. value (#{storageLocationCode},#{wllbClass},#{libraryType},#{materialId},#{amount},now(),'0',#{accountSleeve},#{wbs},#{supplierId},#{serial},#{wllbCode},#{producDate},now(),#{producDate},#{attribute})
  980. </insert>
  981. <!-- 查询扫描数量 -->
  982. <select id="getSumWarehousingVirtual" resultType="java.util.Map">
  983. select
  984. (select ifnull(sum(num), 0) from tld_warehousing_virtual where receive_goods_id = #{receiveGoodsId}) as scanNum,
  985. (select (qualified_num + 0) - ifnull((warehousing_num + 0), 0) from tld_receive_goods where id = #{receiveGoodsId}) as num
  986. from dual
  987. </select>
  988. </mapper>