AskGoodsMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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(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)
  24. values(#{askGoodsId},#{entryNumber},#{productionCode},#{materialId},#{wbs},#{measurementId},#{outNum},#{askGoodsCode},#{companyNumber},#{sqrq},#{departmentId},#{sourceType},#{moveType})
  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="addAskGoodsNumf">
  32. insert into tld_ask_goods_f(ask_goods_id,ask_goods_code,company_number,sqrq,department,source_type,move_type)
  33. values(#{askGoodsId},#{askGoodsCode},#{companyNumber},#{sqrq},#{department},#{sourceType},#{moveType})
  34. </insert>
  35. <!-- 查询生产领料单 -->
  36. <select id="getAskGoodsfList" resultType="com.tld.model.AskGoods">
  37. select ask_goods_id,ask_goods_code,department from tld_ask_goods_f order by sqrq desc
  38. </select>
  39. <!-- 查询指定生产单的物料 -->
  40. <select id="getAskGoodsMaterial" resultType="com.tld.model.AskGoods">
  41. SELECT
  42. a.id,
  43. a.material_id,
  44. a.num,
  45. b.name as materialName,
  46. b.code as materialCode
  47. FROM
  48. tld_ask_goods a
  49. left join tld_material b on a.material_id = b.tld_id
  50. WHERE
  51. a.ask_goods_id = #{askGoodsId} and a.num <![CDATA[>]]> a.out_num
  52. </select>
  53. <!-- 物料库位选择 -->
  54. <select id="getMaterialCk" resultType="com.tld.model.Inventory">
  55. select * from tld_inventory where material_id = #{materialId} order by scrq
  56. </select>
  57. <!-- 新增出库虚拟表 -->
  58. <insert id="addAskGoodsVitrual">
  59. 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)
  60. values(#{uniqueCode},#{supplierId},#{serial},#{wllbCode},#{producDate},#{askGoodsId},#{type},#{storageLocationCode},#{num},#{userId},#{department})
  61. </insert>
  62. <!-- 查询指定库存内容 -->
  63. <select id="getInventory" resultType="com.tld.model.Inventory">
  64. select * from tld_inventory where supplier_id = #{supplierId} and serial = #{uniqueCode} and wllb_code = #{wllbCode} and produc_date = #{producDate}
  65. </select>
  66. <!-- 查询库存是否充足 -->
  67. <select id="getAsk" resultType="com.tld.model.AskGoods">
  68. SELECT
  69. a.*
  70. FROM
  71. tld_ask_goods_vitrual a
  72. join tld_material b on a.wllb_code = b.code and b.tld_id = #{materialId}
  73. where a.storage_location_code = #{storageLocationCode}
  74. </select>
  75. <!-- 查询是否扫描 -->
  76. <select id="getScanIsNot" resultType="java.util.Map">
  77. select
  78. (select amount from tld_inventory where supplier_id = #{supplierId} and serial = #{uniqueCode} and wllb_code = #{wllbCode} and produc_date = #{producDate}) as inventoryNum,
  79. (select sum(num) from tld_ask_goods_vitrual where supplier_id = #{supplierId} and serial = #{uniqueCode} and wllb_code = #{wllbCode} and produc_date = #{producDate} and type = #{type}) as virtualNum
  80. from dual
  81. </select>
  82. <!-- 查询指定送货单信息 -->
  83. <select id="getAsknInfo" resultType="com.tld.model.AskGoods">
  84. SELECT
  85. a.*
  86. FROM
  87. tld_ask_goods a
  88. join tld_material b on a.material_id = b.tld_id
  89. where a.ask_goods_id = #{askGoodsId} and b.code = #{materialCode}
  90. </select>
  91. <!-- 查询已扫描总数 -->
  92. <select id="getAskInfoNumVitrual" resultType="int">
  93. select sum(num) from tld_ask_goods_vitrual where wllb_code = #{materialCode} and ask_goods_id = #{askGoodsId} and type = #{type}
  94. </select>
  95. <!-- 查询此库存在虚拟表里占用的数量 -->
  96. <select id="getInventoryAlready" resultType="int">
  97. select sum(num) from tld_ask_goods_vitrual where supplier_id = #{supplierId} and serial = #{uniqueCode} and wllb_code = #{wllbCode} and produc_date = #{producDate} and type = #{type}
  98. </select>
  99. <!-- 查询虚拟表指定pda跟状态的的数据 -->
  100. <select id="getVirtualUniqueCode" resultType="com.tld.model.AskGoods">
  101. select * from tld_ask_goods_vitrual where unique_code = #{uniqueCode} and type = #{type} and ask_goods_id = #{askGoodsId}
  102. </select>
  103. <!-- 删除库存 -->
  104. <delete id="deleteInventory">
  105. delete from tld_inventory where id = #{id}
  106. </delete>
  107. <!-- 修改库存数量 -->
  108. <update id="updateInventory">
  109. UPDATE tld_inventory
  110. SET amount = ( SELECT a.amount FROM (select (amount - ${amount}) as amount from tld_inventory WHERE id = #{id}) as a )
  111. WHERE
  112. id = #{id}
  113. </update>
  114. <!-- 删除虚拟表出库记录 -->
  115. <delete id="deleteVirtual">
  116. delete from tld_ask_goods_vitrual where id = #{id}
  117. </delete>
  118. <!-- 插入出库流水 -->
  119. <insert id="addRemoval">
  120. insert into tld_removal(wllb_code,supplier_id,serial,num,type,user_id,storage_location_code,scrq,process,ask_goods_id,produc_date,department)
  121. values(#{materialCode},#{supplierId},#{serial},#{num},#{type},#{userId},#{storageLocationCode},now(),#{process},#{askGoodsId},#{producDate},#{department})
  122. </insert>
  123. <!-- 查询指定物料类型的id -->
  124. <select id="getMaterialId" resultType="String">
  125. select tld_id from tld_material where code = #{wllbCode}
  126. </select>
  127. <!-- 查询要料申请单内容 -->
  128. <select id="getAskDetailed" resultType="com.tld.model.AskGoods">
  129. select *
  130. from tld_ask_goods
  131. where ask_goods_id = #{askGoodsId} and material_id = #{materialId}
  132. </select>
  133. <!-- 新增返回gs数据字表信息 -->
  134. <insert id="addReturnGsRemoval">
  135. insert into tld_return_gs_removal_z(material_id,wbs,num,entry_number,ask_goods_id,ask_id,storage_location_code)
  136. values(#{materialId},#{wbs},#{num},#{entryNumber},#{askGoodsId},#{askId},#{storageLocationCode})
  137. </insert>
  138. <!-- 查询要货单父级信息 -->
  139. <select id="getAskDetailedF" resultType="com.tld.model.AskGoods">
  140. select * from tld_ask_goods_f where ask_goods_id = #{askGoodsId}
  141. </select>
  142. <!-- 新增返回gs数据父表信息 -->
  143. <insert id="addReturnGsRemovalF">
  144. insert into tld_ask_goods_f(ask_goods_id,removal_code,source_type,move_type,scrq)
  145. values(#{askGoodsId},#{removalCode},#{sourceType},#{movetype},now())
  146. </insert>
  147. <!-- 查询当天出库数量 -->
  148. <select id="getReturnRemovalCount" resultType="int">
  149. select count(*) from tld_return_gs_removal where scrq BETWEEN CONCAT(CURDATE(),' 00:00:00') AND CONCAT(CURDATE(),' 23:59:59');
  150. </select>
  151. <!-- 查询回传数据 -->
  152. <select id="plugOutRemoval" resultType="java.util.Map">
  153. select
  154. id,
  155. ask_goods_id as askGoodsId,
  156. removal_code as removalCode,
  157. source_type as sourceType,
  158. move_type as moveType
  159. from tld_return_gs_removal where removal_code = #{removalCode}
  160. </select>
  161. <!-- 查询字表回传数据 -->
  162. <select id="getRemovalz" resultType="java.util.Map">
  163. select
  164. material_id as materialId,
  165. wbs,
  166. num,
  167. entry_number as entryNumber,
  168. ask_goods_id as askGoodsId,
  169. ask_id as askId
  170. from tld_return_gs_removal_z where ask_goods_id = #{askGoodsId}
  171. </select>
  172. <!-- 查询出库流水 -->
  173. <select id="getRemoval" resultType="com.tld.model.AskGoods">
  174. select
  175. a.id,
  176. b.name as materialName,
  177. a.wllb_code,
  178. h.name as supplierName,
  179. a.serial,
  180. a.type,
  181. c.user_name as userName,
  182. e.name as departmentName,
  183. g.storage_location_name as storageLocationName,
  184. a.scrq,
  185. a.num
  186. from tld_removal a
  187. left join tld_material b on a.wllb_code = b.code
  188. left join tld_user c on a.user_id = c.id
  189. left join tld_department e on a.department = e.tld_id
  190. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  191. left join tld_customer h on a.supplier_id = h.code
  192. <trim prefix="WHERE" prefixOverrides="and |or">
  193. <if test="wllbCode != null and wllbCode != ''">
  194. and a.wllb_code = #{wllbCode}
  195. </if>
  196. <if test="startTime != null and startTime != ''">
  197. and a.scrq <![CDATA[>=]]> #{startTime}
  198. </if>
  199. <if test="endTime != null and endTime != ''">
  200. and a.scrq <![CDATA[<=]]> #{endTime}
  201. </if>
  202. <if test="type != null and type != ''">
  203. and a.type like CONCAT(CONCAT('%', #{type}), '%')
  204. </if>
  205. </trim>
  206. </select>
  207. <!-- 导出 -->
  208. <select id="export" resultType="java.util.LinkedHashMap">
  209. select
  210. b.name as materialName,
  211. h.name as supplierName,
  212. a.serial,
  213. a.type,
  214. c.user_name as userName,
  215. e.name as departmentName,
  216. g.storage_location_name as storageLocationName,
  217. a.scrq,
  218. a.num
  219. from tld_removal a
  220. left join tld_material b on a.wllb_code = b.code
  221. left join tld_user c on a.user_id = c.id
  222. left join tld_department e on a.department = e.tld_id
  223. left join tld_storage_location g on a.storage_location_code = g.storage_location_code
  224. left join tld_customer h on a.supplier_id = h.code
  225. <trim prefix="WHERE" prefixOverrides="and |or">
  226. <if test="wllbCode != null and wllbCode != ''">
  227. and a.wllb_code = #{wllbCode}
  228. </if>
  229. <if test="startTime != null and startTime != ''">
  230. and a.scrq <![CDATA[>=]]> #{startTime}
  231. </if>
  232. <if test="endTime != null and endTime != ''">
  233. and a.scrq <![CDATA[<=]]> #{endTime}
  234. </if>
  235. <if test="type != null and type != ''">
  236. and a.type like CONCAT(CONCAT('%', #{type}), '%')
  237. </if>
  238. </trim>
  239. </select>
  240. </mapper>