InventoryMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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.InventoryMapper">
  5. <!--录入盘点-->
  6. <insert id="addInventory">
  7. insert into tld_plate(storage_location_code, amount, total, wllb_code, scrq, material_id, plate_id,
  8. account_sleeve, supplier_id, serial, attribute, uuid)
  9. values (#{storageLocationCode}, #{amount}, #{total}, #{wllbCode}, now(), #{materialId}, #{plateId},
  10. #{accountSleeve}, #{supplierId}, #{serial}, #{attribute}, #{uuid})
  11. </insert>
  12. <!--添加盘点主表信息-->
  13. <insert id="addInventoryPlate">
  14. insert into tld_plate_f(user_id, scrq, uuid, title)
  15. values (#{modifyUser}, now(), #{uuid}, #{title})
  16. </insert>
  17. <!--添加盘点子表信息-->
  18. <insert id="addInventoryPlates">
  19. insert into tld_plate_z(material_id, wllb_code, name, amount, gs_amount, uuid, account_sleeve)
  20. values
  21. <foreach collection="inventory" index="index" item="item" separator=",">
  22. (#{item.materialId}, #{item.wllbCode}, #{item.name}, #{item.amount}, #{item.gsAmount}, #{item.uuid},#{item.accountSleeve})
  23. </foreach>
  24. </insert>
  25. <!--修改录入信息为主表id为空的添加主表uuid进行关联-->
  26. <update id="updateInventoryPlate">
  27. update tld_plate
  28. set plate_id = #{uuid}
  29. where scrq like CONCAT(CONCAT('%', #{scrq}), '%')
  30. and (plate_id is null or plate_id = '')
  31. </update>
  32. <!--删除重复录入的信息-->
  33. <delete id="delInventoryRepetition">
  34. delete
  35. from tld_plate
  36. where id = #{id}
  37. </delete>
  38. <!--导出盘点数据-->
  39. <select id="export" resultType="java.util.LinkedHashMap">
  40. select
  41. a.material_id,
  42. a.wllb_code,
  43. a.name,
  44. a.amount,
  45. a.gs_amount,
  46. c.plateAmount,
  47. b.name as accountName
  48. from tld_plate_z a
  49. left join tld_company b on a.account_sleeve = b.code
  50. left join (select sum(amount) as plateAmount,material_id,uuid from tld_plate GROUP BY material_id,uuid) c on a.material_id = c.material_id and a.uuid = c.uuid
  51. <trim prefix="WHERE" prefixOverrides="and |or">
  52. <if test="materialId != null and materialId != ''">
  53. and a.material_id = #{materialId}
  54. </if>
  55. <if test="wllbCode != null and wllbCode != ''">
  56. and a.wllb_code = #{wllbCode}
  57. </if>
  58. <if test="uuid != null and uuid != ''">
  59. and a.uuid = #{uuid}
  60. </if>
  61. <if test="name != null and name != ''">
  62. and a.name like CONCAT(CONCAT('%', #{name}), '%')
  63. </if>
  64. <if test="accountSleeve != null and accountSleeve != ''">
  65. and a.account_sleeve = #{accountSleeve}
  66. </if>
  67. </trim>
  68. </select>
  69. <!--查询录入盘点信息-->
  70. <select id="getInventory" resultType="com.tld.model.MakeInventory">
  71. select
  72. a.id,
  73. a.storage_location_code,
  74. a.amount,
  75. a.total,
  76. a.wllb_code,
  77. a.scrq,
  78. a.material_id,
  79. a.plate_id,
  80. a.account_sleeve,
  81. a.supplier_id,
  82. a.serial,
  83. a.attribute,
  84. a.uuid,
  85. b.name as name ,
  86. c.storage_location_name as storageLocationName
  87. from tld_plate a
  88. left join tld_material b on a.wllb_code = b.code
  89. left join tld_storage_location c on a.storage_location_code = c.storage_location_code
  90. <trim prefix="WHERE" prefixOverrides="and |or">
  91. <if test="wllbCodes != null and wllbCodes != ''">
  92. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCodes}), '%')
  93. </if>
  94. <if test="name != null and name != ''">
  95. and b.name like CONCAT(CONCAT('%', #{name}), '%')
  96. </if>
  97. <if test="storageLocationName != null and storageLocationName != ''">
  98. and c.storageLocationName like CONCAT(CONCAT('%', #{storageLocationName}), '%')
  99. </if>
  100. <if test="wllbCodes != null and wllbCodes != ''">
  101. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCodes}), '%')
  102. </if>
  103. <if test="materialId != null and materialId != ''">
  104. and a.material_id = #{materialId}
  105. </if>
  106. <if test="amount != null and amount != ''">
  107. and a.amount = #{amount}
  108. </if>
  109. <if test="total != null and total != ''">
  110. and a.total = #{total}
  111. </if>
  112. <if test="storageLocationCodes != null and storageLocationCodes != ''">
  113. and a.storage_location_code like CONCAT(CONCAT('%', #{storageLocationCodes}), '%')
  114. </if>
  115. <if test="plateId != null and plateId != ''">
  116. and a.plate_id = #{plateId}
  117. </if>
  118. <if test="accountSleeve != null and accountSleeve != ''">
  119. and a.account_sleeve = #{accountSleeve}
  120. </if>
  121. <if test="supplierId != null and supplierId != ''">
  122. and a.supplier_id = #{supplierId}
  123. </if>
  124. <if test="serial != null and serial != ''">
  125. and a.serial = #{serial}
  126. </if>
  127. <if test="attribute != null and attribute != ''">
  128. and a.attribute = #{attribute}
  129. </if>
  130. <if test="uuid != null and uuid != ''">
  131. and a.uuid = #{uuid}
  132. </if>
  133. <if test="scrq != null and scrq != ''">
  134. and a.scrq like CONCAT(CONCAT('%', #{scrq}), '%')
  135. </if>
  136. <if test="startTime != null and startTime != ''">
  137. and a.sqrq <![CDATA[>=]]> #{startTime}
  138. </if>
  139. <if test="endTime != null and endTime != ''">
  140. and a.sqrq <![CDATA[<=]]> #{endTime}
  141. </if>
  142. </trim>
  143. order by a.scrq desc
  144. </select>
  145. <!--查询盘点主表信息-->
  146. <select id="getInventoryDataList" resultType="com.tld.model.MakeInventory">
  147. select
  148. a.id,
  149. a.user_id,
  150. a.scrq,
  151. a.uuid,
  152. a.title,
  153. b.user_name as userName
  154. from tld_plate_f a
  155. left join tld_user b on a.user_id = b.id
  156. <trim prefix="WHERE" prefixOverrides="and |or">
  157. <if test="userId != null and userId != ''">
  158. and a.user_id = #{userId}
  159. </if>
  160. <if test="uuid != null and uuid != ''">
  161. and a.uuid = #{uuid}
  162. </if>
  163. <if test="scrq != null and scrq != ''">
  164. and a.scrq like CONCAT(CONCAT('%', #{scrq}), '%')
  165. </if>
  166. <if test="userName != null and userName != ''">
  167. and b.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  168. </if>
  169. <if test="title != null and title != ''">
  170. and a.title like CONCAT(CONCAT('%', #{title}), '%')
  171. </if>
  172. <if test="plateId != null and plateId != ''">
  173. and a.id = #{plateId}
  174. </if>
  175. <if test="startTime != null and startTime != ''">
  176. and a.scrq <![CDATA[>=]]> #{startTime}
  177. </if>
  178. <if test="endTime != null and endTime != ''">
  179. and a.scrq <![CDATA[<=]]> #{endTime}
  180. </if>
  181. </trim>
  182. order by a.scrq desc
  183. </select>
  184. <!--查询盘点录入信息是否重复-->
  185. <select id="getInventoryRepetition" resultType="com.tld.model.MakeInventory">
  186. select
  187. id,
  188. storage_location_code,
  189. amount,
  190. total,
  191. wllb_code,
  192. scrq,
  193. material_id,
  194. plate_id,
  195. account_sleeve,
  196. supplier_id,
  197. serial,
  198. attribute,
  199. uuid
  200. from tld_plate
  201. <trim prefix="WHERE" prefixOverrides="and |or">
  202. <if test="materialId != null and materialId != ''">
  203. and material_id = #{materialId}
  204. </if>
  205. <if test="accountSleeve != null and accountSleeve != ''">
  206. and account_sleeve = #{accountSleeve}
  207. </if>
  208. <if test="supplierId != null and supplierId != ''">
  209. and supplier_id = #{supplierId}
  210. </if>
  211. <if test="serial != null and serial != ''">
  212. and serial = #{serial}
  213. </if>
  214. <if test="attribute != null and attribute != ''">
  215. and attribute = #{attribute}
  216. </if>
  217. <if test="uuid != null and uuid != ''">
  218. and uuid = #{uuid}
  219. </if>
  220. </trim>
  221. </select>
  222. <!--查询本地库存.gs库存.录入库存 数量-->
  223. <select id="getInventoryPlate" resultType="com.tld.model.MakeInventory">
  224. SELECT a.storage_location_code,
  225. a.account_sleeve,
  226. a.wllb_code,
  227. a.supplier_id,
  228. a.produc_batch,
  229. a.material_id,
  230. b.NAME,
  231. a.amount,
  232. c.amount AS gsAmount
  233. FROM tld_inventory a
  234. LEFT JOIN tld_material b ON a.wllb_code = b.CODE
  235. INNER JOIN tld_inventory_gs c ON a.material_id = c.material_id
  236. </select>
  237. <!--查询是否重复-->
  238. <select id="getInventoryPlates" resultType="com.tld.model.MakeInventory">
  239. select *
  240. from tld_plate_z
  241. where uuid = #{uuid}
  242. </select>
  243. <!--查询盘点子表信息-->
  244. <select id="getInventoryPlatesList" resultType="com.tld.model.MakeInventory">
  245. select
  246. a.id,
  247. a.plate_id,
  248. a.material_id,
  249. a.wllb_code,
  250. a.amount,
  251. a.gs_amount,
  252. e.plateAmount,
  253. a.uuid,
  254. b.name as name,
  255. a.account_sleeve,
  256. c.name as accountName
  257. from tld_plate_z a
  258. left join tld_material b on a.wllb_code = b.code
  259. left join tld_company c on a.account_sleeve = c.code
  260. left join (select sum(amount) as plateAmount,material_id,uuid from tld_plate GROUP BY material_id,uuid) e on a.material_id = e.material_id and a.uuid = e.uuid
  261. <trim prefix="WHERE" prefixOverrides="and |or">
  262. <if test="materialId != null and materialId != ''">
  263. and a.material_id = #{materialId}
  264. </if>
  265. <if test="wllbCode != null and wllbCode != ''">
  266. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  267. </if>
  268. <if test="uuid != null and uuid != ''">
  269. and a.uuid = #{uuid}
  270. </if>
  271. <if test="name != null and name != ''">
  272. and b.name like CONCAT(CONCAT('%', #{name}), '%')
  273. </if>
  274. <if test="accountSleeve != null and accountSleeve != ''">
  275. and a.account_sleeve = #{accountSleeve}
  276. </if>
  277. </trim>
  278. order by a.id desc
  279. </select>
  280. <!--查询本地库存.gs库存.录入库存 数量-->
  281. <select id="getInventoryLocality" resultType="java.util.Map">
  282. SELECT a.wllb_code AS wllbCode,
  283. a.material_id AS materialId,
  284. b.amount AS gsAmount,
  285. SUM(a.amount) AS amount,
  286. if(b.material_id is null ,'',b.material_id) AS bId,
  287. c.NAME AS name,
  288. a.account_sleeve as accountSleeve,
  289. ${uuid} AS uuid
  290. FROM tld_inventory a
  291. LEFT JOIN tld_inventory_gs b ON a.material_id = b.material_id
  292. LEFT JOIN tld_material c ON a.wllb_code = c.CODE
  293. <trim prefix="WHERE" prefixOverrides="and |or">
  294. <if test="accountSleeve != null and accountSleeve != ''">
  295. and a.account_sleeve = #{accountSleeve}
  296. </if>
  297. </trim>
  298. GROUP BY a.material_id
  299. </select>
  300. <!--查询本地库存.gs库存.录入库存 数量 中 没有连接到的gs的数据-->
  301. <select id="getInventoryLocalityGs" resultType="java.util.Map">
  302. select
  303. c.code AS wllbCode,
  304. a.material_id AS materialId,
  305. a.amount AS gsAmount,
  306. 0 AS amount,
  307. c.NAME AS name,
  308. a.account_sleeve as accountSleeve
  309. from tld_inventory_gs a
  310. LEFT JOIN tld_material c ON a.material_id = c.tld_id
  311. where material_id not in
  312. <foreach collection="list" index="index" item="item" separator="," close=")" open="(">
  313. <if test="item.bId != null ">
  314. #{item.bId}
  315. </if>
  316. </foreach>
  317. </select>
  318. <!--盘点录入信息导出-->
  319. <select id="exportEntering" resultType="java.util.LinkedHashMap">
  320. select
  321. a.wllb_code,
  322. b.name as name ,
  323. c.storage_location_name as storageLocationName,
  324. a.total,
  325. a.amount
  326. from tld_plate a
  327. left join tld_material b on a.wllb_code = b.code
  328. left join tld_storage_location c on a.storage_location_code = c.storage_location_code
  329. <trim prefix="WHERE" prefixOverrides="and |or">
  330. <if test="wllbCodes != null and wllbCodes != ''">
  331. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCodes}), '%')
  332. </if>
  333. <if test="name != null and name != ''">
  334. and b.name like CONCAT(CONCAT('%', #{name}), '%')
  335. </if>
  336. <if test="storageLocationName != null and storageLocationName != ''">
  337. and c.storageLocationName like CONCAT(CONCAT('%', #{storageLocationName}), '%')
  338. </if>
  339. <if test="wllbCodes != null and wllbCodes != ''">
  340. and a.wllb_code like CONCAT(CONCAT('%', #{wllbCodes}), '%')
  341. </if>
  342. <if test="materialId != null and materialId != ''">
  343. and a.material_id = #{materialId}
  344. </if>
  345. <if test="amount != null and amount != ''">
  346. and a.amount = #{amount}
  347. </if>
  348. <if test="total != null and total != ''">
  349. and a.total = #{total}
  350. </if>
  351. <if test="storageLocationCodes != null and storageLocationCodes != ''">
  352. and a.storage_location_code like CONCAT(CONCAT('%', #{storageLocationCodes}), '%')
  353. </if>
  354. <if test="plateId != null and plateId != ''">
  355. and a.plate_id = #{plateId}
  356. </if>
  357. <if test="accountSleeve != null and accountSleeve != ''">
  358. and a.account_sleeve = #{accountSleeve}
  359. </if>
  360. <if test="supplierId != null and supplierId != ''">
  361. and a.supplier_id = #{supplierId}
  362. </if>
  363. <if test="serial != null and serial != ''">
  364. and a.serial = #{serial}
  365. </if>
  366. <if test="attribute != null and attribute != ''">
  367. and a.attribute = #{attribute}
  368. </if>
  369. <if test="uuid != null and uuid != ''">
  370. and a.uuid = #{uuid}
  371. </if>
  372. <if test="scrq != null and scrq != ''">
  373. and a.scrq like CONCAT(CONCAT('%', #{scrq}), '%')
  374. </if>
  375. <if test="startTime != null and startTime != ''">
  376. and a.sqrq <![CDATA[>=]]> #{startTime}
  377. </if>
  378. <if test="endTime != null and endTime != ''">
  379. and a.sqrq <![CDATA[<=]]> #{endTime}
  380. </if>
  381. </trim>
  382. order by a.scrq desc
  383. </select>
  384. </mapper>