DepotItemMapperEx.xml 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.jsh.erp.datasource.mappers.DepotItemMapperEx">
  4. <resultMap id="DetailByTypeAndMIdResultMap" type="com.jsh.erp.datasource.entities.DepotItemVo4DetailByTypeAndMId">
  5. <result column="number" jdbcType="VARCHAR" property="number" />
  6. <result column="bar_code" jdbcType="VARCHAR" property="barCode" />
  7. <result column="material_name" jdbcType="VARCHAR" property="materialName" />
  8. <result column="type" jdbcType="VARCHAR" property="type" />
  9. <result column="sub_type" jdbcType="VARCHAR" property="subType" />
  10. <result column="b_num" jdbcType="DECIMAL" property="bnum" />
  11. <result column="unit_price" jdbcType="DECIMAL" property="unitPrice" />
  12. <result column="all_price" jdbcType="DECIMAL" property="allPrice" />
  13. <result column="material_unit" jdbcType="VARCHAR" property="materialUnit" />
  14. <result column="depotName" jdbcType="VARCHAR" property="depotName" />
  15. <result column="depotName" jdbcType="VARCHAR" property="depotName" />
  16. <result column="oTime" jdbcType="TIMESTAMP" property="otime" />
  17. </resultMap>
  18. <resultMap extends="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap" id="ResultAndMaterialMap" type="com.jsh.erp.datasource.entities.DepotItemVo4Material">
  19. <result column="mName" jdbcType="VARCHAR" property="mname" />
  20. <result column="mModel" jdbcType="VARCHAR" property="mmodel" />
  21. </resultMap>
  22. <resultMap extends="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap" id="ResultWithInfoExMap" type="com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx">
  23. <result column="MName" jdbcType="VARCHAR" property="MName" />
  24. <result column="MModel" jdbcType="VARCHAR" property="MModel" />
  25. <result column="MaterialUnit" jdbcType="VARCHAR" property="MaterialUnit" />
  26. <result column="MColor" jdbcType="VARCHAR" property="MColor" />
  27. <result column="MStandard" jdbcType="VARCHAR" property="MStandard" />
  28. <result column="MMfrs" jdbcType="VARCHAR" property="MMfrs" />
  29. <result column="weight" jdbcType="VARCHAR" property="weight" />
  30. <result column="position" jdbcType="VARCHAR" property="position" />
  31. <result column="img_name" jdbcType="VARCHAR" property="imgName" />
  32. <result column="MOtherField1" jdbcType="VARCHAR" property="MOtherField1" />
  33. <result column="MOtherField2" jdbcType="VARCHAR" property="MOtherField2" />
  34. <result column="MOtherField3" jdbcType="VARCHAR" property="MOtherField3" />
  35. <result column="enable_serial_number" jdbcType="VARCHAR" property="enableSerialNumber" />
  36. <result column="enable_batch_number" jdbcType="VARCHAR" property="enableBatchNumber" />
  37. <result column="brand" jdbcType="VARCHAR" property="brand" />
  38. <result column="DepotName" jdbcType="VARCHAR" property="DepotName" />
  39. <result column="AnotherDepotName" jdbcType="VARCHAR" property="AnotherDepotName" />
  40. <result column="barCode" jdbcType="VARCHAR" property="barCode" />
  41. <result column="purchase_decimal" jdbcType="DECIMAL" property="purchaseDecimal" />
  42. </resultMap>
  43. <resultMap extends="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap" id="ResultByMaterial" type="com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx">
  44. <result column="MId" jdbcType="VARCHAR" property="MId" />
  45. <result column="bar_code" jdbcType="VARCHAR" property="barCode" />
  46. <result column="MName" jdbcType="VARCHAR" property="MName" />
  47. <result column="MMfrs" jdbcType="VARCHAR" property="MMfrs" />
  48. <result column="MModel" jdbcType="VARCHAR" property="MModel" />
  49. <result column="MStandard" jdbcType="VARCHAR" property="MStandard" />
  50. <result column="MaterialUnit" jdbcType="VARCHAR" property="MaterialUnit" />
  51. <result column="MOtherField1" jdbcType="VARCHAR" property="MOtherField1" />
  52. <result column="MOtherField2" jdbcType="VARCHAR" property="MOtherField2" />
  53. <result column="MOtherField3" jdbcType="VARCHAR" property="MOtherField3" />
  54. <result column="unit_id" jdbcType="BIGINT" property="unitId" />
  55. <result column="unit_name" jdbcType="VARCHAR" property="unitName" />
  56. <result column="MColor" jdbcType="VARCHAR" property="MColor" />
  57. <result column="brand" jdbcType="VARCHAR" property="brand" />
  58. <result column="purchase_decimal" jdbcType="DECIMAL" property="purchaseDecimal" />
  59. <result column="currentUnitPrice" jdbcType="DECIMAL" property="currentUnitPrice" />
  60. </resultMap>
  61. <resultMap id="ResultStockWarningCount" type="com.jsh.erp.datasource.vo.DepotItemStockWarningCount">
  62. <result column="MId" jdbcType="VARCHAR" property="MId" />
  63. <result column="bar_code" jdbcType="VARCHAR" property="barCode" />
  64. <result column="MName" jdbcType="VARCHAR" property="MName" />
  65. <result column="MMfrs" jdbcType="VARCHAR" property="MMfrs" />
  66. <result column="MModel" jdbcType="VARCHAR" property="MModel" />
  67. <result column="MStandard" jdbcType="VARCHAR" property="MStandard" />
  68. <result column="MColor" jdbcType="VARCHAR" property="MColor" />
  69. <result column="brand" jdbcType="VARCHAR" property="brand" />
  70. <result column="MaterialUnit" jdbcType="VARCHAR" property="MaterialUnit" />
  71. <result column="MOtherField1" jdbcType="VARCHAR" property="MOtherField1" />
  72. <result column="MOtherField2" jdbcType="VARCHAR" property="MOtherField2" />
  73. <result column="MOtherField3" jdbcType="VARCHAR" property="MOtherField3" />
  74. <result column="unit_name" jdbcType="VARCHAR" property="unitName" />
  75. <result column="current_number" jdbcType="DECIMAL" property="currentNumber" />
  76. <result column="low_safe_stock" jdbcType="DECIMAL" property="lowSafeStock" />
  77. <result column="high_safe_stock" jdbcType="DECIMAL" property="highSafeStock" />
  78. </resultMap>
  79. <resultMap id="stockMap" type="com.jsh.erp.datasource.vo.DepotItemVo4Stock">
  80. <result column="inTotal" jdbcType="DECIMAL" property="inTotal" />
  81. <result column="outTotal" jdbcType="DECIMAL" property="outTotal" />
  82. <result column="transfInTotal" jdbcType="DECIMAL" property="transfInTotal" />
  83. <result column="transfOutTotal" jdbcType="DECIMAL" property="transfOutTotal" />
  84. <result column="assemInTotal" jdbcType="DECIMAL" property="assemInTotal" />
  85. <result column="assemOutTotal" jdbcType="DECIMAL" property="assemOutTotal" />
  86. <result column="disAssemInTotal" jdbcType="DECIMAL" property="disAssemInTotal" />
  87. <result column="disAssemOutTotal" jdbcType="DECIMAL" property="disAssemOutTotal" />
  88. </resultMap>
  89. <resultMap id="batchNumberListMap" type="com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList">
  90. <result column="id" jdbcType="VARCHAR" property="id" />
  91. <result column="bar_code" jdbcType="VARCHAR" property="barCode" />
  92. <result column="name" jdbcType="VARCHAR" property="name" />
  93. <result column="standard" jdbcType="VARCHAR" property="standard" />
  94. <result column="model" jdbcType="VARCHAR" property="model" />
  95. <result column="unit_id" jdbcType="BIGINT" property="unitId" />
  96. <result column="commodity_unit" jdbcType="VARCHAR" property="commodityUnit" />
  97. <result column="batch_number" jdbcType="VARCHAR" property="batchNumber" />
  98. <result column="expiration_date" jdbcType="TIMESTAMP" property="expirationDate" />
  99. <result column="total_num" jdbcType="VARCHAR" property="totalNum" />
  100. </resultMap>
  101. <resultMap id="materialSumMap" type="com.jsh.erp.datasource.entities.DepotItemVo4MaterialAndSum">
  102. <result column="material_extend_id" jdbcType="VARCHAR" property="materialExtendId" />
  103. <result column="oper_number" jdbcType="VARCHAR" property="operNumber" />
  104. </resultMap>
  105. <select id="selectByConditionDepotItem" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
  106. select *
  107. FROM jsh_depot_item
  108. where 1=1
  109. <if test="name != null">
  110. <bind name="bindName" value="'%'+name+'%'"/>
  111. and name like #{bindName}
  112. </if>
  113. <if test="type != null">
  114. and type = #{type}
  115. </if>
  116. <if test="remark != null">
  117. <bind name="bindRemark" value="'%'+remark+'%'"/>
  118. and remark like #{bindRemark}
  119. </if>
  120. and ifnull(delete_flag,'0') !='1'
  121. <if test="offset != null and rows != null">
  122. limit #{offset},#{rows}
  123. </if>
  124. </select>
  125. <select id="countsByDepotItem" resultType="java.lang.Long">
  126. SELECT
  127. COUNT(id)
  128. FROM jsh_depot_item
  129. WHERE 1=1
  130. <if test="name != null">
  131. <bind name="bindName" value="'%'+name+'%'"/>
  132. and name like #{bindName}
  133. </if>
  134. <if test="type != null">
  135. and type = #{type}
  136. </if>
  137. <if test="remark != null">
  138. <bind name="bindRemark" value="'%'+remark+'%'"/>
  139. and remark like #{bindRemark}
  140. </if>
  141. and ifnull(delete_flag,'0') !='1'
  142. </select>
  143. <select id="findDetailByDepotIdsAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultType="com.jsh.erp.datasource.entities.DepotItemVo4DetailByTypeAndMId">
  144. select tb.number, tb.bar_code, tb.material_name, tb.type, tb.sub_type, tb.b_num, tb.unit_price,
  145. ifnull(tb.b_num*tb.unit_price,0) as all_price, tb.material_unit materialUnit, tb.depotName, tb.oTime from
  146. (select dh.number,me.bar_code,m.name material_name,dh.type,dh.sub_type,
  147. case
  148. when type='入库' then ifnull(di.basic_number,0)
  149. when type='出库' then 0-ifnull(di.basic_number,0)
  150. when dh.sub_type='组装单' and di.material_type='组合件' then ifnull(di.basic_number,0)
  151. when dh.sub_type='组装单' and di.material_type='普通子件' then 0-ifnull(di.basic_number,0)
  152. when dh.sub_type='拆卸单' and di.material_type='普通子件' then ifnull(di.basic_number,0)
  153. when dh.sub_type='拆卸单' and di.material_type='组合件' then 0-ifnull(di.basic_number,0)
  154. when dh.sub_type='盘点复盘' then ifnull(di.basic_number,0)
  155. else 0
  156. end
  157. as b_num, di.unit_price, di.material_unit,
  158. (select name from jsh_depot d where d.id=di.depot_id and ifnull(d.delete_flag,'0') !='1') as depotName,
  159. date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime
  160. from jsh_depot_head dh
  161. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  162. left join jsh_material m on di.material_id=m.id and ifnull(m.delete_flag,'0') !='1'
  163. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  164. where (dh.type!='其它'
  165. or (dh.type='其它' and dh.sub_type='组装单')
  166. or (dh.type='其它' and dh.sub_type='拆卸单')
  167. or (dh.type='其它' and dh.sub_type='盘点复盘'))
  168. <if test="inOutManageFlag">
  169. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  170. </if>
  171. <if test="depotIdArray != null and depotIdArray.length>0">
  172. and di.depot_id in (
  173. <foreach collection="depotIdArray" item="depotId" separator=",">#{depotId}</foreach>
  174. )
  175. </if>
  176. <if test="forceFlag">
  177. and dh.status = '1'
  178. </if>
  179. <if test="sku != null and sku !=''">
  180. and di.sku = #{sku}
  181. </if>
  182. <if test="batchNumber != null and batchNumber !=''">
  183. and di.batch_number = #{batchNumber}
  184. </if>
  185. <if test="number != null and number !=''">
  186. <bind name="bindNumber" value="'%'+number+'%'"/>
  187. and dh.number like #{bindNumber}
  188. </if>
  189. <if test="beginTime != null and beginTime !=''">
  190. and dh.oper_time >= #{beginTime}
  191. </if>
  192. <if test="endTime != null and endTime !=''">
  193. and dh.oper_time &lt;= #{endTime}
  194. </if>
  195. and di.material_id = #{mId}
  196. and ifnull(dh.delete_flag,'0') !='1'
  197. union all
  198. select dh.number,me.bar_code,m.name material_name,dh.type,dh.sub_type,
  199. ifnull(di.basic_number,0) as b_num, di.unit_price, di.material_unit,
  200. (select concat(name,'[调入]') from jsh_depot d where d.id=di.another_depot_id and ifnull(d.delete_flag,'0') !='1') as depotName,
  201. date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime
  202. from jsh_depot_head dh
  203. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  204. left join jsh_material m on di.material_id=m.id and ifnull(m.delete_flag,'0') !='1'
  205. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  206. where dh.type='出库' and dh.sub_type='调拨'
  207. <if test="depotIdArray != null and depotIdArray.length>0">
  208. and di.another_depot_id in (
  209. <foreach collection="depotIdArray" item="depotId" separator=",">#{depotId}</foreach>
  210. )
  211. </if>
  212. <if test="forceFlag">
  213. and dh.status = '1'
  214. </if>
  215. <if test="sku != null and sku !=''">
  216. and di.sku = #{sku}
  217. </if>
  218. <if test="batchNumber != null and batchNumber !=''">
  219. and di.batch_number = #{batchNumber}
  220. </if>
  221. <if test="number != null and number !=''">
  222. <bind name="bindNumber" value="'%'+number+'%'"/>
  223. and dh.number like #{bindNumber}
  224. </if>
  225. <if test="beginTime != null and beginTime !=''">
  226. and dh.oper_time >= #{beginTime}
  227. </if>
  228. <if test="endTime != null and endTime !=''">
  229. and dh.oper_time &lt;= #{endTime}
  230. </if>
  231. and di.material_id = #{mId}
  232. and ifnull(dh.delete_flag,'0') !='1') tb
  233. order by tb.oTime desc
  234. <if test="offset != null and rows != null">
  235. limit #{offset},#{rows}
  236. </if>
  237. </select>
  238. <select id="findDetailByDepotIdsAndMaterialIdCount" resultType="java.lang.Long">
  239. select count(tb.number) from
  240. (select dh.number from jsh_depot_head dh
  241. left JOIN jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  242. where (dh.type!='其它'
  243. or (dh.type='其它' and dh.sub_type='组装单')
  244. or (dh.type='其它' and dh.sub_type='拆卸单')
  245. or (dh.type='其它' and dh.sub_type='盘点复盘'))
  246. <if test="inOutManageFlag">
  247. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  248. </if>
  249. <if test="depotIdArray != null and depotIdArray.length>0">
  250. and di.depot_id in (
  251. <foreach collection="depotIdArray" item="depotId" separator=",">#{depotId}</foreach>
  252. )
  253. </if>
  254. <if test="forceFlag">
  255. and dh.status = '1'
  256. </if>
  257. <if test="sku != null and sku !=''">
  258. and di.sku = #{sku}
  259. </if>
  260. <if test="batchNumber != null and batchNumber !=''">
  261. and di.batch_number = #{batchNumber}
  262. </if>
  263. <if test="number != null and number !=''">
  264. <bind name="bindNumber" value="'%'+number+'%'"/>
  265. and dh.number like #{bindNumber}
  266. </if>
  267. <if test="beginTime != null and beginTime !=''">
  268. and dh.oper_time >= #{beginTime}
  269. </if>
  270. <if test="endTime != null and endTime !=''">
  271. and dh.oper_time &lt;= #{endTime}
  272. </if>
  273. and di.material_id =#{mId}
  274. and ifnull(dh.delete_flag,'0') !='1'
  275. union all
  276. --单独构造记录:调拨入库
  277. select dh.number from jsh_depot_head dh
  278. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  279. where dh.type='出库' and dh.sub_type='调拨'
  280. <if test="depotIdArray != null and depotIdArray.length>0">
  281. and di.another_depot_id in (
  282. <foreach collection="depotIdArray" item="depotId" separator=",">#{depotId}</foreach>
  283. )
  284. </if>
  285. <if test="forceFlag">
  286. and dh.status = '1'
  287. </if>
  288. <if test="sku != null and sku !=''">
  289. and di.sku = #{sku}
  290. </if>
  291. <if test="batchNumber != null and batchNumber !=''">
  292. and di.batch_number = #{batchNumber}
  293. </if>
  294. <if test="number != null and number !=''">
  295. <bind name="bindNumber" value="'%'+number+'%'"/>
  296. and dh.number like #{bindNumber}
  297. </if>
  298. <if test="beginTime != null and beginTime !=''">
  299. and dh.oper_time >= #{beginTime}
  300. </if>
  301. <if test="endTime != null and endTime !=''">
  302. and dh.oper_time &lt;= #{endTime}
  303. </if>
  304. and di.material_id = #{mId}
  305. and ifnull(dh.delete_flag,'0') !='1') tb
  306. </select>
  307. <select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultType="com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx">
  308. select di.*,m.name MName,m.model MModel,m.color MColor,m.unit_id,m.standard MStandard,m.weight, m.img_name,
  309. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,m.enable_serial_number, m.enable_batch_number,
  310. m.brand, dp1.name DepotName,dp2.name AnotherDepotName, me.purchase_decimal,
  311. me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.position,s.supplier supplierName,u.name unit_name,me.inventory,
  312. us.username warehousingUserName
  313. from jsh_depot_item di
  314. left join jsh_material m on di.material_id=m.id and ifnull(m.delete_flag,'0') !='1'
  315. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  316. left join jsh_depot dp1 on di.depot_id=dp1.id and ifnull(dp1.delete_Flag,'0') !='1'
  317. left join jsh_depot dp2 on di.another_depot_id=dp2.id and ifnull(dp2.delete_Flag,'0') !='1'
  318. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  319. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  320. left join jsh_user us on di.warehousing_user=us.id and ifnull(us.delete_Flag,'0') !='1'
  321. where di.header_id = #{headerId}
  322. and ifnull(di.delete_flag,'0') !='1'
  323. order by di.id asc
  324. </select>
  325. <select id="getBillDetailListByIds" resultType="com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx">
  326. select di.*,m.name MName,m.model MModel,m.color MColor,m.unit_id,m.standard MStandard,m.weight, m.img_name,
  327. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,m.enable_serial_number, m.enable_batch_number,
  328. m.brand, dp1.name DepotName,dp2.name AnotherDepotName, me.purchase_decimal,
  329. me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.position,s.supplier supplierName,me.inventory
  330. from jsh_depot_item di
  331. left join jsh_material m on di.material_id=m.id and ifnull(m.delete_flag,'0') !='1'
  332. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  333. left join jsh_depot dp1 on di.depot_id=dp1.id and ifnull(dp1.delete_Flag,'0') !='1'
  334. left join jsh_depot dp2 on di.another_depot_id=dp2.id and ifnull(dp2.delete_Flag,'0') !='1'
  335. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  336. where ifnull(di.delete_flag,'0') !='1'
  337. and di.header_id in
  338. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  339. #{item}
  340. </foreach>
  341. order by di.header_id desc, di.id asc
  342. </select>
  343. <select id="getInOutStock" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial">
  344. select m.id MId, me.bar_code, m.name MName, m.model MModel, m.standard MStandard, m.brand,
  345. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,
  346. concat_ws('', m.unit, u.basic_unit) MaterialUnit, m.color MColor, m.unit_id, u.name unit_name,
  347. ifnull(me.purchase_decimal,0) purchase_decimal, ifnull(mcs.current_unit_price,0) currentUnitPrice
  348. from jsh_material m
  349. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  350. left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
  351. left join jsh_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'
  352. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  353. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  354. where 1=1 and me.default_flag=1
  355. <if test="materialParam != null and materialParam !=''">
  356. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  357. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  358. or m.color like #{bindKey} like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  359. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  360. </if>
  361. <if test="categoryIdList.size()>0">
  362. and m.category_id in
  363. <foreach collection="categoryIdList" item="item" index="index" separator="," open="(" close=")">
  364. #{item}
  365. </foreach>
  366. </if>
  367. <if test="endTime != null">
  368. and dh.oper_time &lt;= #{endTime}
  369. </if>
  370. and ifnull(m.delete_flag,'0') !='1'
  371. group by m.id, me.bar_code, m.name, m.model, m.standard, m.brand,
  372. m.other_field1,m.other_field2,m.other_field3,m.unit, u.basic_unit, m.color, m.unit_id, u.name,
  373. me.purchase_decimal, mcs.current_unit_price
  374. order by m.id desc
  375. <if test="offset != null and rows != null">
  376. limit #{offset},#{rows}
  377. </if>
  378. </select>
  379. <select id="getInOutStockCount" resultType="java.lang.Integer">
  380. select count(1) from (select m.id
  381. from jsh_material m
  382. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  383. left join jsh_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'
  384. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  385. where 1=1 and me.default_flag=1
  386. <if test="materialParam != null and materialParam !=''">
  387. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  388. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  389. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  390. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  391. </if>
  392. <if test="categoryIdList.size()>0">
  393. and m.category_id in
  394. <foreach collection="categoryIdList" item="item" index="index" separator="," open="(" close=")">
  395. #{item}
  396. </foreach>
  397. </if>
  398. <if test="endTime != null">
  399. and dh.oper_time &lt;= #{endTime}
  400. </if>
  401. and ifnull(m.delete_flag,'0') !='1'
  402. group by m.id) cc
  403. </select>
  404. <select id="getListWithBuyOrSale" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial">
  405. select m.id MId, me.bar_code, m.name MName, m.model MModel, m.standard MStandard,
  406. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,
  407. concat_ws('', m.unit, u.basic_unit) MaterialUnit, m.color MColor, m.brand, u.name unit_name
  408. from jsh_material m
  409. left join jsh_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'
  410. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  411. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  412. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  413. where 1=1
  414. <if test="categoryList.size()>0">
  415. and m.category_id in
  416. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  417. #{item}
  418. </foreach>
  419. </if>
  420. <if test="materialParam != null and materialParam !=''">
  421. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  422. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  423. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  424. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  425. </if>
  426. <if test="billType =='buy'">
  427. and (dh.sub_type = '采购' or dh.sub_type = '采购退货')
  428. </if>
  429. <if test="billType =='sale'">
  430. and (dh.sub_type = '销售' or dh.sub_type = '销售退货')
  431. </if>
  432. <if test="billType =='retail'">
  433. and (dh.sub_type = '零售' or dh.sub_type = '零售退货')
  434. </if>
  435. <if test="beginTime != null">
  436. and dh.oper_time >= #{beginTime}
  437. </if>
  438. <if test="endTime != null">
  439. and dh.oper_time &lt;= #{endTime}
  440. </if>
  441. <if test="creatorArray != null">
  442. and dh.creator in (
  443. <foreach collection="creatorArray" item="creator" separator=",">
  444. #{creator}
  445. </foreach>
  446. )
  447. </if>
  448. <if test="organId != null">
  449. and dh.organ_id = #{organId}
  450. </if>
  451. <if test="organArray != null and organArray !=''">
  452. and dh.organ_id in (
  453. <foreach collection="organArray" item="organId" separator=",">
  454. #{organId}
  455. </foreach>
  456. )
  457. </if>
  458. <if test="depotList.size()>0">
  459. and di.depot_id in
  460. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  461. #{item}
  462. </foreach>
  463. </if>
  464. <if test="forceFlag">
  465. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  466. </if>
  467. and ifnull(m.delete_flag,'0') !='1'
  468. group by m.id, me.bar_code, m.name, m.model, m.standard,
  469. m.other_field1,m.other_field2,m.other_field3, m.unit, u.basic_unit, m.color, m.brand, u.name
  470. order by m.id desc
  471. <if test="offset != null and rows != null">
  472. limit #{offset},#{rows}
  473. </if>
  474. </select>
  475. <select id="getListWithBuyOrSaleCount" resultType="java.lang.Integer">
  476. select count(1) from (select m.id
  477. from jsh_material m
  478. left join jsh_depot_item di on di.material_id=m.id and ifnull(m.delete_Flag,'0') !='1'
  479. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  480. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  481. where 1=1
  482. <if test="categoryList.size()>0">
  483. and m.category_id in
  484. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  485. #{item}
  486. </foreach>
  487. </if>
  488. <if test="materialParam != null and materialParam !=''">
  489. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  490. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  491. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  492. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  493. </if>
  494. <if test="billType =='buy'">
  495. and (dh.sub_type = '采购' or dh.sub_type = '采购退货')
  496. </if>
  497. <if test="billType =='sale'">
  498. and (dh.sub_type = '销售' or dh.sub_type = '销售退货')
  499. </if>
  500. <if test="billType =='retail'">
  501. and (dh.sub_type = '零售' or dh.sub_type = '零售退货')
  502. </if>
  503. <if test="beginTime != null">
  504. and dh.oper_time >= #{beginTime}
  505. </if>
  506. <if test="endTime != null">
  507. and dh.oper_time &lt;= #{endTime}
  508. </if>
  509. <if test="creatorArray != null">
  510. and dh.creator in (
  511. <foreach collection="creatorArray" item="creator" separator=",">
  512. #{creator}
  513. </foreach>
  514. )
  515. </if>
  516. <if test="organId != null">
  517. and dh.organ_id = #{organId}
  518. </if>
  519. <if test="organArray != null and organArray !=''">
  520. and dh.organ_id in (
  521. <foreach collection="organArray" item="organId" separator=",">
  522. #{organId}
  523. </foreach>
  524. )
  525. </if>
  526. <if test="depotList.size()>0">
  527. and di.depot_id in
  528. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  529. #{item}
  530. </foreach>
  531. </if>
  532. <if test="forceFlag">
  533. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  534. </if>
  535. and ifnull(di.delete_flag,'0') !='1'
  536. group by m.id) cc
  537. </select>
  538. <select id="buyOrSaleNumber" resultType="java.math.BigDecimal">
  539. select ifnull(sum(basic_number),0) as BasicNumber from jsh_depot_item di,jsh_depot_head dh
  540. where di.header_id = dh.id
  541. and dh.type=#{type} and dh.sub_type=#{subType}
  542. and dh.oper_time &gt;= #{beginTime}
  543. and dh.oper_time &lt;= #{endTime}
  544. and di.material_id =#{MId}
  545. <if test="creatorArray != null">
  546. and dh.creator in (
  547. <foreach collection="creatorArray" item="creator" separator=",">
  548. #{creator}
  549. </foreach>
  550. )
  551. </if>
  552. <if test="organId != null">
  553. and dh.organ_id = #{organId}
  554. </if>
  555. <if test="organArray != null and organArray !=''">
  556. and dh.organ_id in (
  557. <foreach collection="organArray" item="organId" separator=",">
  558. #{organId}
  559. </foreach>
  560. )
  561. </if>
  562. <if test="depotList.size()>0">
  563. and di.depot_id in
  564. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  565. #{item}
  566. </foreach>
  567. </if>
  568. <if test="forceFlag">
  569. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  570. </if>
  571. and ifnull(dh.delete_flag,'0') !='1'
  572. and ifnull(di.delete_flag,'0') !='1'
  573. </select>
  574. <select id="buyOrSalePrice" resultType="java.math.BigDecimal">
  575. select ifnull(sum(all_price),0) as AllPrice from jsh_depot_item di,jsh_depot_head dh
  576. where di.header_id = dh.id
  577. and dh.type=#{type} and dh.sub_type=#{subType}
  578. and dh.oper_time &gt;= #{beginTime}
  579. and dh.oper_time &lt;= #{endTime}
  580. <if test="MId != null">
  581. and di.material_id =#{MId}
  582. </if>
  583. <if test="creatorArray != null">
  584. and dh.creator in (
  585. <foreach collection="creatorArray" item="creator" separator=",">
  586. #{creator}
  587. </foreach>
  588. )
  589. </if>
  590. <if test="organId != null">
  591. and dh.organ_id = #{organId}
  592. </if>
  593. <if test="organArray != null and organArray !=''">
  594. and dh.organ_id in (
  595. <foreach collection="organArray" item="organId" separator=",">
  596. #{organId}
  597. </foreach>
  598. )
  599. </if>
  600. <if test="depotList.size()>0">
  601. and di.depot_id in
  602. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  603. #{item}
  604. </foreach>
  605. </if>
  606. <if test="forceFlag">
  607. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  608. </if>
  609. and ifnull(dh.delete_flag,'0') !='1'
  610. and ifnull(di.delete_flag,'0') !='1'
  611. </select>
  612. <select id="buyOrSalePriceTotal" resultType="java.math.BigDecimal">
  613. select ifnull(sum(di.all_price),0) as AllPrice
  614. from jsh_depot_item di
  615. left join jsh_depot_head dh on dh.id=di.header_id and ifnull(dh.delete_flag,'0') !='1'
  616. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  617. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
  618. where ifnull(di.delete_flag,'0') !='1'
  619. and dh.type=#{type} and dh.sub_type=#{subType}
  620. and dh.oper_time &gt;= #{beginTime}
  621. and dh.oper_time &lt;= #{endTime}
  622. <if test="categoryList.size()>0">
  623. and m.category_id in
  624. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  625. #{item}
  626. </foreach>
  627. </if>
  628. <if test="materialParam != null and materialParam !=''">
  629. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  630. and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
  631. </if>
  632. <if test="creatorArray != null">
  633. and dh.creator in (
  634. <foreach collection="creatorArray" item="creator" separator=",">
  635. #{creator}
  636. </foreach>
  637. )
  638. </if>
  639. <if test="organId != null">
  640. and dh.organ_id = #{organId}
  641. </if>
  642. <if test="organArray != null and organArray !=''">
  643. and dh.organ_id in (
  644. <foreach collection="organArray" item="organId" separator=",">
  645. #{organId}
  646. </foreach>
  647. )
  648. </if>
  649. <if test="depotList.size()>0">
  650. and di.depot_id in
  651. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  652. #{item}
  653. </foreach>
  654. </if>
  655. <if test="forceFlag">
  656. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  657. </if>
  658. </select>
  659. <select id="inOrOutPriceList" resultType="com.jsh.erp.datasource.vo.InOutPriceVo">
  660. select distinct dh.id, dh.discount_last_money, dh.total_price, dh.type, dh.sub_type, dh.oper_time
  661. from jsh_depot_head dh
  662. left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') != '1'
  663. where di.id is not null
  664. and (dh.type='入库' or dh.type='出库')
  665. and dh.oper_time &gt;= #{beginTime}
  666. and dh.oper_time &lt;= #{endTime}
  667. <if test="forceFlag">
  668. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  669. </if>
  670. <if test="creatorArray != null">
  671. and dh.creator in (
  672. <foreach collection="creatorArray" item="creator" separator=",">
  673. #{creator}
  674. </foreach>
  675. )
  676. </if>
  677. and ifnull(dh.delete_flag,'0') != '1'
  678. </select>
  679. <select id="getSkuStockCheckSumByDepotList" resultType="java.math.BigDecimal">
  680. select ifnull(sum(di.basic_number),0) stockCheckSum from jsh_depot_head dh
  681. left JOIN jsh_depot_item di on dh.id=di.header_id
  682. where 1=1
  683. <if test="meId != null">
  684. and di.material_extend_id=#{meId}
  685. </if>
  686. and dh.sub_type='盘点复盘'
  687. <if test="depotList.size()>0">
  688. and di.depot_id in
  689. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  690. #{item}
  691. </foreach>
  692. </if>
  693. <if test="forceFlag">
  694. and dh.status = '1'
  695. </if>
  696. <if test="beginTime != null">
  697. and dh.oper_time &gt;= #{beginTime}
  698. </if>
  699. <if test="endTime != null">
  700. and dh.oper_time &lt;= #{endTime}
  701. </if>
  702. and ifnull(dh.delete_flag,'0') !='1'
  703. and ifnull(di.delete_flag,'0') !='1'
  704. </select>
  705. <select id="getStockCheckSumByDepotList" resultType="java.math.BigDecimal">
  706. select ifnull(sum(di.basic_number),0) stockCheckSum from jsh_depot_head dh
  707. left JOIN jsh_depot_item di on dh.id=di.header_id
  708. where 1=1
  709. <if test="mId != null">
  710. and di.material_id=#{mId}
  711. </if>
  712. and dh.sub_type='盘点复盘'
  713. <if test="depotList.size()>0">
  714. and di.depot_id in
  715. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  716. #{item}
  717. </foreach>
  718. </if>
  719. <if test="forceFlag">
  720. and dh.status = '1'
  721. </if>
  722. <if test="beginTime != null">
  723. and dh.oper_time &gt;= #{beginTime}
  724. </if>
  725. <if test="endTime != null">
  726. and dh.oper_time &lt;= #{endTime}
  727. </if>
  728. and ifnull(dh.delete_flag,'0') !='1'
  729. and ifnull(di.delete_flag,'0') !='1'
  730. </select>
  731. <select id="getSkuStockByParamWithDepotList" resultMap="stockMap">
  732. select
  733. sum(case when dh.type='入库' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as inTotal,
  734. sum(case when dh.type='出库' and dh.sub_type!='调拨' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as outTotal,
  735. sum(case when dh.sub_type='调拨' <include refid="anotherDepotParam" /> then di.basic_number else 0 end) as transfInTotal,
  736. sum(case when dh.sub_type='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as transfOutTotal,
  737. sum(case when dh.sub_type='组装单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemInTotal,
  738. sum(case when dh.sub_type='组装单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemOutTotal,
  739. sum(case when dh.sub_type='拆卸单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemInTotal,
  740. sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemOutTotal
  741. from
  742. jsh_depot_head dh
  743. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  744. where 1=1
  745. and ifnull(dh.delete_flag,'0') !='1'
  746. and di.material_extend_id=#{meId}
  747. and ifnull(di.sku,'') !=''
  748. <if test="forceFlag">
  749. and dh.status = '1'
  750. </if>
  751. <if test="beginTime != null">
  752. and dh.oper_time &gt;= #{beginTime}
  753. </if>
  754. <if test="endTime != null">
  755. and dh.oper_time &lt;= #{endTime}
  756. </if>
  757. </select>
  758. <select id="getStockByParamWithDepotList" resultMap="stockMap">
  759. select
  760. sum(case when dh.type='入库' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as inTotal,
  761. sum(case when dh.type='出库' and dh.sub_type!='调拨' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as outTotal,
  762. sum(case when dh.sub_type='调拨' <include refid="anotherDepotParam" /> then di.basic_number else 0 end) as transfInTotal,
  763. sum(case when dh.sub_type='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as transfOutTotal,
  764. sum(case when dh.sub_type='组装单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemInTotal,
  765. sum(case when dh.sub_type='组装单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemOutTotal,
  766. sum(case when dh.sub_type='拆卸单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemInTotal,
  767. sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemOutTotal
  768. from
  769. jsh_depot_head dh
  770. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  771. where 1=1
  772. and ifnull(dh.delete_flag,'0') !='1'
  773. and di.material_id=#{mId}
  774. <if test="forceFlag">
  775. and dh.status = '1'
  776. </if>
  777. <if test="beginTime != null">
  778. and dh.oper_time &gt;= #{beginTime}
  779. </if>
  780. <if test="endTime != null">
  781. and dh.oper_time &lt;= #{endTime}
  782. </if>
  783. </select>
  784. <sql id="inOutManageParam">
  785. <if test="inOutManageFlag">
  786. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  787. </if>
  788. </sql>
  789. <sql id="depotParam">
  790. <if test="depotList.size()>0">
  791. and di.depot_id in <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">#{item}</foreach>
  792. </if>
  793. </sql>
  794. <sql id="anotherDepotParam">
  795. <if test="depotList.size()>0">
  796. and di.another_depot_id in <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">#{item}</foreach>
  797. </if>
  798. </sql>
  799. <select id="findDepotItemListBydepotheadId" resultType="com.jsh.erp.datasource.entities.DepotItem">
  800. select
  801. dep.id,dep.header_id,dep.material_id,dep.material_unit,dep.oper_number,
  802. dep.basic_number,dep.unit_price,dep.tax_unit_price,dep.all_price,dep.remark,
  803. dep.depot_id,dep.another_depot_id,dep.tax_rate,
  804. dep.tax_money,dep.tax_last_money,dep.material_type
  805. from jsh_depot_item dep,jsh_material mat
  806. where 1=1
  807. <if test="depotheadId != null">
  808. and dep.header_id = #{depotheadId}
  809. </if>
  810. and dep.material_id=mat.id
  811. <if test="enableSerialNumber != null">
  812. and mat.enable_serial_number = #{enableSerialNumber}
  813. </if>
  814. and ifnull(dep.delete_flag,'0') !='1'
  815. and ifnull(mat.delete_flag,'0') !='1'
  816. </select>
  817. <update id="batchDeleteDepotItemByDepotHeadIds">
  818. update jsh_depot_item
  819. set delete_flag='1'
  820. where 1=1
  821. and header_id in
  822. (
  823. <foreach collection="depotheadIds" item="depotheadId" separator=",">
  824. #{depotheadId}
  825. </foreach>
  826. )
  827. </update>
  828. <update id="batchDeleteDepotItemByIds">
  829. update jsh_depot_item
  830. set delete_flag='1'
  831. where 1=1
  832. and id in (
  833. <foreach collection="ids" item="id" separator=",">
  834. #{id}
  835. </foreach>
  836. )
  837. </update>
  838. <select id="getDepotItemListListByDepotIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
  839. select
  840. <include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" />
  841. from jsh_depot_item
  842. where 1=1
  843. and depot_id in (
  844. <foreach collection="depotIds" item="depotId" separator=",">
  845. #{depotId}
  846. </foreach>
  847. )
  848. and ifnull(delete_flag,'0') !='1'
  849. </select>
  850. <select id="getDepotItemListListByMaterialIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
  851. select
  852. <include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" />
  853. from jsh_depot_item
  854. where 1=1
  855. and material_id in (
  856. <foreach collection="materialIds" item="materialId" separator=",">
  857. #{materialId}
  858. </foreach>
  859. )
  860. and ifnull(delete_flag,'0') !='1'
  861. </select>
  862. <select id="findStockWarningCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStockWarningCount">
  863. select m.id MId, m.name MName, me.bar_code, m.model MModel, m.standard MStandard,m.color MColor, m.brand,
  864. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,d.name depotName,
  865. m.unit MaterialUnit, u.basic_unit unit_name,mcs.current_number,
  866. mis.low_safe_stock, mis.high_safe_stock
  867. from jsh_material m
  868. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  869. left join jsh_material_initial_stock mis on mis.material_id=m.id and ifnull(mis.delete_Flag,'0') !='1'
  870. left join jsh_material_current_stock mcs on mcs.material_id=m.id and ifnull(mcs.delete_Flag,'0') !='1'
  871. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  872. left join jsh_depot d on d.id=mis.depot_id and ifnull(u.delete_flag,'0') !='1'
  873. where 1=1
  874. and me.default_flag=1
  875. and ifnull(m.delete_flag,'0') !='1'
  876. and mis.depot_id=mcs.depot_id
  877. and ((ifnull(mis.low_safe_stock,0)!=0 and mcs.current_number &lt; ifnull(mis.low_safe_stock,0))
  878. or (ifnull(mis.high_safe_stock,0)!=0 and mcs.current_number > ifnull(mis.high_safe_stock,0)))
  879. <if test="materialParam != null and materialParam !=''">
  880. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  881. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  882. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  883. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  884. </if>
  885. <if test="depotList.size()>0">
  886. and mis.depot_id in
  887. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  888. #{item}
  889. </foreach>
  890. </if>
  891. <if test="categoryList.size()>0">
  892. and m.category_id in
  893. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  894. #{item}
  895. </foreach>
  896. </if>
  897. order by depotName asc
  898. <if test="offset != null and rows != null">
  899. limit #{offset},#{rows}
  900. </if>
  901. </select>
  902. <select id="findStockWarningCountTotal" resultType="java.lang.Integer">
  903. select count(1) from
  904. (select m.id
  905. from jsh_material m
  906. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  907. left join jsh_material_initial_stock mis on mis.material_id=m.id and ifnull(mis.delete_Flag,'0') !='1'
  908. left join jsh_material_current_stock mcs on mcs.material_id=m.id and ifnull(mcs.delete_Flag,'0') !='1'
  909. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  910. left join jsh_depot d on d.id=mis.depot_id and ifnull(u.delete_flag,'0') !='1'
  911. where 1=1
  912. and me.default_flag=1
  913. and ifnull(m.delete_flag,'0') !='1'
  914. and mis.depot_id=mcs.depot_id
  915. and ((ifnull(mis.low_safe_stock,0)!=0 and mcs.current_number &lt; ifnull(mis.low_safe_stock,0))
  916. or (ifnull(mis.high_safe_stock,0)!=0 and mcs.current_number > ifnull(mis.high_safe_stock,0)))
  917. <if test="materialParam != null and materialParam !=''">
  918. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  919. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  920. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  921. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  922. </if>
  923. <if test="depotList.size()>0">
  924. and mis.depot_id in
  925. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  926. #{item}
  927. </foreach>
  928. </if>
  929. <if test="categoryList.size()>0">
  930. and m.category_id in
  931. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  932. #{item}
  933. </foreach>
  934. </if>
  935. ) tb
  936. </select>
  937. <select id="getFinishNumber" resultType="java.math.BigDecimal">
  938. select ifnull(sum(di.basic_number),0) from jsh_depot_item di
  939. where di.material_extend_id=#{meId}
  940. and di.link_id=#{linkId}
  941. and ifnull(di.delete_flag,'0') !='1'
  942. and di.header_id
  943. in
  944. (
  945. select dh.id from jsh_depot_head dh
  946. where 1=1
  947. <if test="noType == 'normal'">
  948. and dh.link_number=#{linkStr}
  949. </if>
  950. <if test="noType == 'apply'">
  951. and dh.link_apply=#{linkStr}
  952. </if>
  953. and ifnull(dh.delete_flag,'0') !='1'
  954. <if test="goToType != null and goToType !=''">
  955. and dh.sub_type=#{goToType}
  956. </if>
  957. )
  958. </select>
  959. <select id="getRealFinishNumber" resultType="java.math.BigDecimal">
  960. select ifnull(sum(di.basic_number),0) from jsh_depot_item di
  961. where di.material_extend_id=#{meId}
  962. and di.link_id=#{linkId}
  963. and ifnull(di.delete_flag,'0') !='1'
  964. and di.header_id
  965. in
  966. (
  967. select dh.id from jsh_depot_head dh
  968. where
  969. dh.id!=#{currentHeaderId}
  970. <if test="linkType == 'normal'">
  971. and dh.link_number=#{linkStr}
  972. </if>
  973. <if test="linkType == 'apply'">
  974. and dh.link_apply=#{linkStr}
  975. </if>
  976. and ifnull(dh.delete_flag,'0') !='1'
  977. <if test="goToType != null and goToType !=''">
  978. and dh.sub_type=#{goToType}
  979. </if>
  980. )
  981. </select>
  982. <select id="getBatchNumberList" resultType="com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList">
  983. select id, bar_code, name, standard, model, unit_id,
  984. commodity_unit, batch_number, expiration_date, sum(basic_number) total_num from
  985. (select di.batch_number id, me.bar_code, m.name, m.standard, m.model, m.unit_id,
  986. me.commodity_unit, di.batch_number,di.expiration_date,
  987. di.basic_number*(case dh.type when '入库' then 1 when '出库' then -1 end) as basic_number
  988. from jsh_depot_head dh
  989. left join jsh_depot_item di on dh.id=di.header_id
  990. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag, '0') != '1'
  991. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_flag,'0') !='1'
  992. where me.bar_code= #{barCode}
  993. <if test="name != null">
  994. <bind name="bindName" value="'%'+name+'%'"/>
  995. and di.batch_number like #{bindName}
  996. </if>
  997. <if test="depotId != null">
  998. and di.depot_id= #{depotId}
  999. </if>
  1000. <if test="batchNumber != null">
  1001. and di.batch_number= #{batchNumber}
  1002. </if>
  1003. <if test="number != null">
  1004. and dh.number!= #{number}
  1005. </if>
  1006. <if test="forceFlag">
  1007. and dh.status = '1'
  1008. </if>
  1009. <if test="inOutManageFlag">
  1010. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  1011. </if>
  1012. and m.enable_batch_number =1
  1013. and di.delete_flag!=1) tb
  1014. group by id, bar_code, name, standard, model, unit_id,
  1015. commodity_unit, batch_number, expiration_date
  1016. order by expiration_date asc
  1017. </select>
  1018. <select id="getCountByMaterialAndDepot" resultType="java.lang.Long">
  1019. select count(1) from jsh_depot_item di
  1020. where di.material_id=#{mId} and di.depot_id=#{depotId}
  1021. and ifnull(di.delete_flag,'0') !='1'
  1022. </select>
  1023. <select id="getLinkBillDetailMaterialSum" resultMap="materialSumMap">
  1024. select di.material_extend_id, sum(di.oper_number) oper_number from jsh_depot_head dh
  1025. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1026. where dh.number=#{linkStr}
  1027. and ifnull(dh.delete_flag,'0') !='1'
  1028. group by di.material_extend_id
  1029. </select>
  1030. <select id="getBatchBillDetailMaterialSum" resultMap="materialSumMap">
  1031. select di.material_extend_id, sum(di.oper_number) oper_number from jsh_depot_head dh
  1032. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1033. where dh.type=#{type}
  1034. <if test="linkType == 'normal'">
  1035. and dh.link_number=#{linkStr}
  1036. </if>
  1037. <if test="linkType == 'apply'">
  1038. and dh.link_apply=#{linkStr}
  1039. </if>
  1040. and ifnull(dh.delete_flag,'0') !='1'
  1041. group by di.material_extend_id
  1042. </select>
  1043. <select id="getCountByMaterialAndBatchNumber" resultType="java.lang.Long">
  1044. select count(di.id) from
  1045. jsh_depot_head dh
  1046. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1047. where 1=1
  1048. and ifnull(dh.delete_flag,'0') !='1'
  1049. and di.material_extend_id=#{meId}
  1050. and di.batch_number=#{batchNumber}
  1051. </select>
  1052. <select id="getDepotItemByBatchNumber" resultType="com.jsh.erp.datasource.entities.DepotItem">
  1053. select di.* from jsh_depot_head dh
  1054. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1055. where 1=1
  1056. and ifnull(dh.delete_flag,'0') !='1'
  1057. and di.material_extend_id = #{materialExtendId}
  1058. and di.batch_number = #{batchNumber}
  1059. and dh.type = '入库'
  1060. </select>
  1061. <select id="getBillItemByParam" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  1062. select m.*,u.name unit_name, me.id meId, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  1063. me.wholesale_decimal, me.low_decimal, me.sku,
  1064. me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.depot_id, me.position,d.`name` depotName,s.supplier supplierName
  1065. from jsh_material m
  1066. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  1067. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  1068. left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
  1069. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  1070. where 1=1
  1071. <if test="batchNumbers != null">
  1072. and me.batch_number in (${batchNumbers})
  1073. </if>
  1074. and ifnull(m.delete_flag,'0') !='1'
  1075. order by m.id desc
  1076. </select>
  1077. <select id="getCurrentStockByParam" resultType="java.math.BigDecimal">
  1078. select sum(ifnull(current_number,0))
  1079. from jsh_material_current_stock
  1080. where 1=1
  1081. <if test="depotId != null">
  1082. and depot_id = ${depotId}
  1083. </if>
  1084. <if test="mId != null">
  1085. and material_id = ${mId}
  1086. </if>
  1087. and ifnull(delete_flag,'0') !='1'
  1088. </select>
  1089. <select id="getLastUnitPriceByParam" resultType="java.math.BigDecimal">
  1090. select di.unit_price from jsh_depot_head dh
  1091. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1092. where dh.organ_id = #{organId}
  1093. and di.material_extend_id = #{meId}
  1094. and dh.type = #{type} and dh.sub_type = #{subType}
  1095. and ifnull(dh.delete_flag,'0') !='1'
  1096. order by dh.id desc, di.id desc
  1097. limit 0,1
  1098. </select>
  1099. <select id="getDepotMaterialBySystemSku" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  1100. select m.*,u.name unit_name, me.id meId, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  1101. me.wholesale_decimal, me.low_decimal, me.sku,
  1102. me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.depot_id, me.position,d.`name` depotName,s.supplier supplierName
  1103. from jsh_material m
  1104. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  1105. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  1106. left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
  1107. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  1108. where m.system_sku = #{systemSku}
  1109. AND me.inventory > 0
  1110. AND ifnull(m.delete_flag,'0') !='1'
  1111. order by me.production_date LIMIT 1
  1112. </select>
  1113. </mapper>