DepotItemMapperEx.xml 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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. select dh.number from jsh_depot_head dh
  277. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  278. where dh.type='出库' and dh.sub_type='调拨'
  279. <if test="depotIdArray != null and depotIdArray.length>0">
  280. and di.another_depot_id in (
  281. <foreach collection="depotIdArray" item="depotId" separator=",">#{depotId}</foreach>
  282. )
  283. </if>
  284. <if test="forceFlag">
  285. and dh.status = '1'
  286. </if>
  287. <if test="sku != null and sku !=''">
  288. and di.sku = #{sku}
  289. </if>
  290. <if test="batchNumber != null and batchNumber !=''">
  291. and di.batch_number = #{batchNumber}
  292. </if>
  293. <if test="number != null and number !=''">
  294. <bind name="bindNumber" value="'%'+number+'%'"/>
  295. and dh.number like #{bindNumber}
  296. </if>
  297. <if test="beginTime != null and beginTime !=''">
  298. and dh.oper_time >= #{beginTime}
  299. </if>
  300. <if test="endTime != null and endTime !=''">
  301. and dh.oper_time &lt;= #{endTime}
  302. </if>
  303. and di.material_id = #{mId}
  304. and ifnull(dh.delete_flag,'0') !='1') tb
  305. </select>
  306. <select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultType="com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx">
  307. select di.*,m.name MName,m.model MModel,m.color MColor,m.unit_id,m.standard MStandard,m.weight, m.img_name,
  308. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,m.enable_serial_number, m.enable_batch_number,
  309. m.brand, dp1.name DepotName,dp2.name AnotherDepotName, me.purchase_decimal,
  310. 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,
  311. us.username warehousingUserName
  312. from jsh_depot_item di
  313. left join jsh_material m on di.material_id=m.id and ifnull(m.delete_flag,'0') !='1'
  314. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  315. left join jsh_depot dp1 on di.depot_id=dp1.id and ifnull(dp1.delete_Flag,'0') !='1'
  316. left join jsh_depot dp2 on di.another_depot_id=dp2.id and ifnull(dp2.delete_Flag,'0') !='1'
  317. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  318. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  319. left join jsh_user us on di.warehousing_user=us.id and ifnull(us.delete_Flag,'0') !='1'
  320. where di.header_id = #{headerId}
  321. and ifnull(di.delete_flag,'0') !='1'
  322. order by di.id asc
  323. </select>
  324. <select id="getBillDetailListByIds" resultType="com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx">
  325. select di.*,m.name MName,m.model MModel,m.color MColor,m.unit_id,m.standard MStandard,m.weight, m.img_name,
  326. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,m.enable_serial_number, m.enable_batch_number,
  327. m.brand, dp1.name DepotName,dp2.name AnotherDepotName, me.purchase_decimal,
  328. me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.position,s.supplier supplierName,me.inventory
  329. from jsh_depot_item di
  330. left join jsh_material m on di.material_id=m.id and ifnull(m.delete_flag,'0') !='1'
  331. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  332. left join jsh_depot dp1 on di.depot_id=dp1.id and ifnull(dp1.delete_Flag,'0') !='1'
  333. left join jsh_depot dp2 on di.another_depot_id=dp2.id and ifnull(dp2.delete_Flag,'0') !='1'
  334. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  335. where ifnull(di.delete_flag,'0') !='1'
  336. and di.header_id in
  337. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  338. #{item}
  339. </foreach>
  340. order by di.header_id desc, di.id asc
  341. </select>
  342. <select id="getInOutStock" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial">
  343. select m.id MId, me.bar_code, m.name MName, m.model MModel, m.standard MStandard, m.brand,
  344. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,
  345. concat_ws('', m.unit, u.basic_unit) MaterialUnit, m.color MColor, m.unit_id, u.name unit_name,
  346. ifnull(me.purchase_decimal,0) purchase_decimal, ifnull(mcs.current_unit_price,0) currentUnitPrice
  347. from jsh_material m
  348. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  349. left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
  350. left join jsh_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'
  351. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  352. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  353. where 1=1 and me.default_flag=1
  354. <if test="materialParam != null and materialParam !=''">
  355. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  356. 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}
  357. or m.color like #{bindKey} like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  358. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  359. </if>
  360. <if test="categoryIdList.size()>0">
  361. and m.category_id in
  362. <foreach collection="categoryIdList" item="item" index="index" separator="," open="(" close=")">
  363. #{item}
  364. </foreach>
  365. </if>
  366. <if test="endTime != null">
  367. and dh.oper_time &lt;= #{endTime}
  368. </if>
  369. and ifnull(m.delete_flag,'0') !='1'
  370. group by m.id, me.bar_code, m.name, m.model, m.standard, m.brand,
  371. m.other_field1,m.other_field2,m.other_field3,m.unit, u.basic_unit, m.color, m.unit_id, u.name,
  372. me.purchase_decimal, mcs.current_unit_price
  373. order by m.id desc
  374. <if test="offset != null and rows != null">
  375. limit #{offset},#{rows}
  376. </if>
  377. </select>
  378. <select id="getInOutStockCount" resultType="java.lang.Integer">
  379. select count(1) from (select m.id
  380. from jsh_material m
  381. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  382. left join jsh_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'
  383. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  384. where 1=1 and me.default_flag=1
  385. <if test="materialParam != null and materialParam !=''">
  386. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  387. 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}
  388. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  389. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  390. </if>
  391. <if test="categoryIdList.size()>0">
  392. and m.category_id in
  393. <foreach collection="categoryIdList" item="item" index="index" separator="," open="(" close=")">
  394. #{item}
  395. </foreach>
  396. </if>
  397. <if test="endTime != null">
  398. and dh.oper_time &lt;= #{endTime}
  399. </if>
  400. and ifnull(m.delete_flag,'0') !='1'
  401. group by m.id) cc
  402. </select>
  403. <select id="getListWithBuyOrSale" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial">
  404. select m.id MId, me.bar_code, m.name MName, m.model MModel, m.standard MStandard,
  405. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,
  406. concat_ws('', m.unit, u.basic_unit) MaterialUnit, m.color MColor, m.brand, u.name unit_name
  407. from jsh_material m
  408. left join jsh_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'
  409. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  410. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  411. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  412. where 1=1
  413. <if test="categoryList.size()>0">
  414. and m.category_id in
  415. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  416. #{item}
  417. </foreach>
  418. </if>
  419. <if test="materialParam != null and materialParam !=''">
  420. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  421. 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}
  422. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  423. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  424. </if>
  425. <if test="billType =='buy'">
  426. and (dh.sub_type = '采购' or dh.sub_type = '采购退货')
  427. </if>
  428. <if test="billType =='sale'">
  429. and (dh.sub_type = '销售' or dh.sub_type = '销售退货')
  430. </if>
  431. <if test="billType =='retail'">
  432. and (dh.sub_type = '零售' or dh.sub_type = '零售退货')
  433. </if>
  434. <if test="beginTime != null">
  435. and dh.oper_time >= #{beginTime}
  436. </if>
  437. <if test="endTime != null">
  438. and dh.oper_time &lt;= #{endTime}
  439. </if>
  440. <if test="creatorArray != null">
  441. and dh.creator in (
  442. <foreach collection="creatorArray" item="creator" separator=",">
  443. #{creator}
  444. </foreach>
  445. )
  446. </if>
  447. <if test="organId != null">
  448. and dh.organ_id = #{organId}
  449. </if>
  450. <if test="organArray != null and organArray !=''">
  451. and dh.organ_id in (
  452. <foreach collection="organArray" item="organId" separator=",">
  453. #{organId}
  454. </foreach>
  455. )
  456. </if>
  457. <if test="depotList.size()>0">
  458. and di.depot_id in
  459. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  460. #{item}
  461. </foreach>
  462. </if>
  463. <if test="forceFlag">
  464. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  465. </if>
  466. and ifnull(m.delete_flag,'0') !='1'
  467. group by m.id, me.bar_code, m.name, m.model, m.standard,
  468. m.other_field1,m.other_field2,m.other_field3, m.unit, u.basic_unit, m.color, m.brand, u.name
  469. order by m.id desc
  470. <if test="offset != null and rows != null">
  471. limit #{offset},#{rows}
  472. </if>
  473. </select>
  474. <select id="getListWithBuyOrSaleCount" resultType="java.lang.Integer">
  475. select count(1) from (select m.id
  476. from jsh_material m
  477. left join jsh_depot_item di on di.material_id=m.id and ifnull(m.delete_Flag,'0') !='1'
  478. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  479. left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
  480. where 1=1
  481. <if test="categoryList.size()>0">
  482. and m.category_id in
  483. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  484. #{item}
  485. </foreach>
  486. </if>
  487. <if test="materialParam != null and materialParam !=''">
  488. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  489. 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}
  490. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  491. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  492. </if>
  493. <if test="billType =='buy'">
  494. and (dh.sub_type = '采购' or dh.sub_type = '采购退货')
  495. </if>
  496. <if test="billType =='sale'">
  497. and (dh.sub_type = '销售' or dh.sub_type = '销售退货')
  498. </if>
  499. <if test="billType =='retail'">
  500. and (dh.sub_type = '零售' or dh.sub_type = '零售退货')
  501. </if>
  502. <if test="beginTime != null">
  503. and dh.oper_time >= #{beginTime}
  504. </if>
  505. <if test="endTime != null">
  506. and dh.oper_time &lt;= #{endTime}
  507. </if>
  508. <if test="creatorArray != null">
  509. and dh.creator in (
  510. <foreach collection="creatorArray" item="creator" separator=",">
  511. #{creator}
  512. </foreach>
  513. )
  514. </if>
  515. <if test="organId != null">
  516. and dh.organ_id = #{organId}
  517. </if>
  518. <if test="organArray != null and organArray !=''">
  519. and dh.organ_id in (
  520. <foreach collection="organArray" item="organId" separator=",">
  521. #{organId}
  522. </foreach>
  523. )
  524. </if>
  525. <if test="depotList.size()>0">
  526. and di.depot_id in
  527. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  528. #{item}
  529. </foreach>
  530. </if>
  531. <if test="forceFlag">
  532. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  533. </if>
  534. and ifnull(di.delete_flag,'0') !='1'
  535. group by m.id) cc
  536. </select>
  537. <select id="buyOrSaleNumber" resultType="java.math.BigDecimal">
  538. select ifnull(sum(basic_number),0) as BasicNumber from jsh_depot_item di,jsh_depot_head dh
  539. where di.header_id = dh.id
  540. and dh.type=#{type} and dh.sub_type=#{subType}
  541. and dh.oper_time &gt;= #{beginTime}
  542. and dh.oper_time &lt;= #{endTime}
  543. and di.material_id =#{MId}
  544. <if test="creatorArray != null">
  545. and dh.creator in (
  546. <foreach collection="creatorArray" item="creator" separator=",">
  547. #{creator}
  548. </foreach>
  549. )
  550. </if>
  551. <if test="organId != null">
  552. and dh.organ_id = #{organId}
  553. </if>
  554. <if test="organArray != null and organArray !=''">
  555. and dh.organ_id in (
  556. <foreach collection="organArray" item="organId" separator=",">
  557. #{organId}
  558. </foreach>
  559. )
  560. </if>
  561. <if test="depotList.size()>0">
  562. and di.depot_id in
  563. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  564. #{item}
  565. </foreach>
  566. </if>
  567. <if test="forceFlag">
  568. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  569. </if>
  570. and ifnull(dh.delete_flag,'0') !='1'
  571. and ifnull(di.delete_flag,'0') !='1'
  572. </select>
  573. <select id="buyOrSalePrice" resultType="java.math.BigDecimal">
  574. select ifnull(sum(all_price),0) as AllPrice from jsh_depot_item di,jsh_depot_head dh
  575. where di.header_id = dh.id
  576. and dh.type=#{type} and dh.sub_type=#{subType}
  577. and dh.oper_time &gt;= #{beginTime}
  578. and dh.oper_time &lt;= #{endTime}
  579. <if test="MId != null">
  580. and di.material_id =#{MId}
  581. </if>
  582. <if test="creatorArray != null">
  583. and dh.creator in (
  584. <foreach collection="creatorArray" item="creator" separator=",">
  585. #{creator}
  586. </foreach>
  587. )
  588. </if>
  589. <if test="organId != null">
  590. and dh.organ_id = #{organId}
  591. </if>
  592. <if test="organArray != null and organArray !=''">
  593. and dh.organ_id in (
  594. <foreach collection="organArray" item="organId" separator=",">
  595. #{organId}
  596. </foreach>
  597. )
  598. </if>
  599. <if test="depotList.size()>0">
  600. and di.depot_id in
  601. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  602. #{item}
  603. </foreach>
  604. </if>
  605. <if test="forceFlag">
  606. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  607. </if>
  608. and ifnull(dh.delete_flag,'0') !='1'
  609. and ifnull(di.delete_flag,'0') !='1'
  610. </select>
  611. <select id="buyOrSalePriceTotal" resultType="java.math.BigDecimal">
  612. select ifnull(sum(di.all_price),0) as AllPrice
  613. from jsh_depot_item di
  614. left join jsh_depot_head dh on dh.id=di.header_id and ifnull(dh.delete_flag,'0') !='1'
  615. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  616. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
  617. where ifnull(di.delete_flag,'0') !='1'
  618. and dh.type=#{type} and dh.sub_type=#{subType}
  619. and dh.oper_time &gt;= #{beginTime}
  620. and dh.oper_time &lt;= #{endTime}
  621. <if test="categoryList.size()>0">
  622. and m.category_id in
  623. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  624. #{item}
  625. </foreach>
  626. </if>
  627. <if test="materialParam != null and materialParam !=''">
  628. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  629. 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})
  630. </if>
  631. <if test="creatorArray != null">
  632. and dh.creator in (
  633. <foreach collection="creatorArray" item="creator" separator=",">
  634. #{creator}
  635. </foreach>
  636. )
  637. </if>
  638. <if test="organId != null">
  639. and dh.organ_id = #{organId}
  640. </if>
  641. <if test="organArray != null and organArray !=''">
  642. and dh.organ_id in (
  643. <foreach collection="organArray" item="organId" separator=",">
  644. #{organId}
  645. </foreach>
  646. )
  647. </if>
  648. <if test="depotList.size()>0">
  649. and di.depot_id in
  650. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  651. #{item}
  652. </foreach>
  653. </if>
  654. <if test="forceFlag">
  655. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  656. </if>
  657. </select>
  658. <select id="inOrOutPriceList" resultType="com.jsh.erp.datasource.vo.InOutPriceVo">
  659. select distinct dh.id, dh.discount_last_money, dh.total_price, dh.type, dh.sub_type, dh.oper_time
  660. from jsh_depot_head dh
  661. left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') != '1'
  662. where di.id is not null
  663. and (dh.type='入库' or dh.type='出库')
  664. and dh.oper_time &gt;= #{beginTime}
  665. and dh.oper_time &lt;= #{endTime}
  666. <if test="forceFlag">
  667. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  668. </if>
  669. <if test="creatorArray != null">
  670. and dh.creator in (
  671. <foreach collection="creatorArray" item="creator" separator=",">
  672. #{creator}
  673. </foreach>
  674. )
  675. </if>
  676. and ifnull(dh.delete_flag,'0') != '1'
  677. </select>
  678. <select id="getSkuStockCheckSumByDepotList" resultType="java.math.BigDecimal">
  679. select ifnull(sum(di.basic_number),0) stockCheckSum from jsh_depot_head dh
  680. left JOIN jsh_depot_item di on dh.id=di.header_id
  681. where 1=1
  682. <if test="meId != null">
  683. and di.material_extend_id=#{meId}
  684. </if>
  685. and dh.sub_type='盘点复盘'
  686. <if test="depotList.size()>0">
  687. and di.depot_id in
  688. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  689. #{item}
  690. </foreach>
  691. </if>
  692. <if test="forceFlag">
  693. and dh.status = '1'
  694. </if>
  695. <if test="beginTime != null">
  696. and dh.oper_time &gt;= #{beginTime}
  697. </if>
  698. <if test="endTime != null">
  699. and dh.oper_time &lt;= #{endTime}
  700. </if>
  701. and ifnull(dh.delete_flag,'0') !='1'
  702. and ifnull(di.delete_flag,'0') !='1'
  703. </select>
  704. <select id="getStockCheckSumByDepotList" resultType="java.math.BigDecimal">
  705. select ifnull(sum(di.basic_number),0) stockCheckSum from jsh_depot_head dh
  706. left JOIN jsh_depot_item di on dh.id=di.header_id
  707. where 1=1
  708. <if test="mId != null">
  709. and di.material_id=#{mId}
  710. </if>
  711. and dh.sub_type='盘点复盘'
  712. <if test="depotList.size()>0">
  713. and di.depot_id in
  714. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  715. #{item}
  716. </foreach>
  717. </if>
  718. <if test="forceFlag">
  719. and dh.status = '1'
  720. </if>
  721. <if test="beginTime != null">
  722. and dh.oper_time &gt;= #{beginTime}
  723. </if>
  724. <if test="endTime != null">
  725. and dh.oper_time &lt;= #{endTime}
  726. </if>
  727. and ifnull(dh.delete_flag,'0') !='1'
  728. and ifnull(di.delete_flag,'0') !='1'
  729. </select>
  730. <select id="getSkuStockByParamWithDepotList" resultMap="stockMap">
  731. select
  732. sum(case when dh.type='入库' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as inTotal,
  733. sum(case when dh.type='出库' and dh.sub_type!='调拨' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as outTotal,
  734. sum(case when dh.sub_type='调拨' <include refid="anotherDepotParam" /> then di.basic_number else 0 end) as transfInTotal,
  735. sum(case when dh.sub_type='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as transfOutTotal,
  736. sum(case when dh.sub_type='组装单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemInTotal,
  737. sum(case when dh.sub_type='组装单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemOutTotal,
  738. sum(case when dh.sub_type='拆卸单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemInTotal,
  739. sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemOutTotal
  740. from
  741. jsh_depot_head dh
  742. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  743. where 1=1
  744. and ifnull(dh.delete_flag,'0') !='1'
  745. and di.material_extend_id=#{meId}
  746. and ifnull(di.sku,'') !=''
  747. <if test="forceFlag">
  748. and dh.status = '1'
  749. </if>
  750. <if test="beginTime != null">
  751. and dh.oper_time &gt;= #{beginTime}
  752. </if>
  753. <if test="endTime != null">
  754. and dh.oper_time &lt;= #{endTime}
  755. </if>
  756. </select>
  757. <select id="getStockByParamWithDepotList" resultMap="stockMap">
  758. select
  759. sum(case when dh.type='入库' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as inTotal,
  760. sum(case when dh.type='出库' and dh.sub_type!='调拨' <include refid="inOutManageParam" /> <include refid="depotParam" /> then di.basic_number else 0 end) as outTotal,
  761. sum(case when dh.sub_type='调拨' <include refid="anotherDepotParam" /> then di.basic_number else 0 end) as transfInTotal,
  762. sum(case when dh.sub_type='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as transfOutTotal,
  763. sum(case when dh.sub_type='组装单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemInTotal,
  764. sum(case when dh.sub_type='组装单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemOutTotal,
  765. sum(case when dh.sub_type='拆卸单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemInTotal,
  766. sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemOutTotal
  767. from
  768. jsh_depot_head dh
  769. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  770. where 1=1
  771. and ifnull(dh.delete_flag,'0') !='1'
  772. and di.material_id=#{mId}
  773. <if test="forceFlag">
  774. and dh.status = '1'
  775. </if>
  776. <if test="beginTime != null">
  777. and dh.oper_time &gt;= #{beginTime}
  778. </if>
  779. <if test="endTime != null">
  780. and dh.oper_time &lt;= #{endTime}
  781. </if>
  782. </select>
  783. <sql id="inOutManageParam">
  784. <if test="inOutManageFlag">
  785. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  786. </if>
  787. </sql>
  788. <sql id="depotParam">
  789. <if test="depotList.size()>0">
  790. and di.depot_id in <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">#{item}</foreach>
  791. </if>
  792. </sql>
  793. <sql id="anotherDepotParam">
  794. <if test="depotList.size()>0">
  795. and di.another_depot_id in <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">#{item}</foreach>
  796. </if>
  797. </sql>
  798. <select id="findDepotItemListBydepotheadId" resultType="com.jsh.erp.datasource.entities.DepotItem">
  799. select
  800. dep.id,dep.header_id,dep.material_id,dep.material_unit,dep.oper_number,
  801. dep.basic_number,dep.unit_price,dep.tax_unit_price,dep.all_price,dep.remark,
  802. dep.depot_id,dep.another_depot_id,dep.tax_rate,
  803. dep.tax_money,dep.tax_last_money,dep.material_type
  804. from jsh_depot_item dep,jsh_material mat
  805. where 1=1
  806. <if test="depotheadId != null">
  807. and dep.header_id = #{depotheadId}
  808. </if>
  809. and dep.material_id=mat.id
  810. <if test="enableSerialNumber != null">
  811. and mat.enable_serial_number = #{enableSerialNumber}
  812. </if>
  813. and ifnull(dep.delete_flag,'0') !='1'
  814. and ifnull(mat.delete_flag,'0') !='1'
  815. </select>
  816. <update id="batchDeleteDepotItemByDepotHeadIds">
  817. update jsh_depot_item
  818. set delete_flag='1'
  819. where 1=1
  820. and header_id in
  821. (
  822. <foreach collection="depotheadIds" item="depotheadId" separator=",">
  823. #{depotheadId}
  824. </foreach>
  825. )
  826. </update>
  827. <update id="batchDeleteDepotItemByIds">
  828. update jsh_depot_item
  829. set delete_flag='1'
  830. where 1=1
  831. and id in (
  832. <foreach collection="ids" item="id" separator=",">
  833. #{id}
  834. </foreach>
  835. )
  836. </update>
  837. <select id="getDepotItemListListByDepotIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
  838. select
  839. <include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" />
  840. from jsh_depot_item
  841. where 1=1
  842. and depot_id in (
  843. <foreach collection="depotIds" item="depotId" separator=",">
  844. #{depotId}
  845. </foreach>
  846. )
  847. and ifnull(delete_flag,'0') !='1'
  848. </select>
  849. <select id="getDepotItemListListByMaterialIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
  850. select
  851. <include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" />
  852. from jsh_depot_item
  853. where 1=1
  854. and material_id in (
  855. <foreach collection="materialIds" item="materialId" separator=",">
  856. #{materialId}
  857. </foreach>
  858. )
  859. and ifnull(delete_flag,'0') !='1'
  860. </select>
  861. <select id="findStockWarningCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStockWarningCount">
  862. select m.id MId, m.name MName, me.bar_code, m.model MModel, m.standard MStandard,m.color MColor, m.brand,
  863. m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,d.name depotName,
  864. m.unit MaterialUnit, u.basic_unit unit_name,mcs.current_number,
  865. mis.low_safe_stock, mis.high_safe_stock
  866. from jsh_material m
  867. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  868. left join jsh_material_initial_stock mis on mis.material_id=m.id and ifnull(mis.delete_Flag,'0') !='1'
  869. left join jsh_material_current_stock mcs on mcs.material_id=m.id and ifnull(mcs.delete_Flag,'0') !='1'
  870. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  871. left join jsh_depot d on d.id=mis.depot_id and ifnull(u.delete_flag,'0') !='1'
  872. where 1=1
  873. and me.default_flag=1
  874. and ifnull(m.delete_flag,'0') !='1'
  875. and mis.depot_id=mcs.depot_id
  876. and ((ifnull(mis.low_safe_stock,0)!=0 and mcs.current_number &lt; ifnull(mis.low_safe_stock,0))
  877. or (ifnull(mis.high_safe_stock,0)!=0 and mcs.current_number > ifnull(mis.high_safe_stock,0)))
  878. <if test="materialParam != null and materialParam !=''">
  879. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  880. 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}
  881. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  882. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  883. </if>
  884. <if test="depotList.size()>0">
  885. and mis.depot_id in
  886. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  887. #{item}
  888. </foreach>
  889. </if>
  890. <if test="categoryList.size()>0">
  891. and m.category_id in
  892. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  893. #{item}
  894. </foreach>
  895. </if>
  896. order by depotName asc
  897. <if test="offset != null and rows != null">
  898. limit #{offset},#{rows}
  899. </if>
  900. </select>
  901. <select id="findStockWarningCountTotal" resultType="java.lang.Integer">
  902. select count(1) from
  903. (select m.id
  904. from jsh_material m
  905. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  906. left join jsh_material_initial_stock mis on mis.material_id=m.id and ifnull(mis.delete_Flag,'0') !='1'
  907. left join jsh_material_current_stock mcs on mcs.material_id=m.id and ifnull(mcs.delete_Flag,'0') !='1'
  908. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  909. left join jsh_depot d on d.id=mis.depot_id and ifnull(u.delete_flag,'0') !='1'
  910. where 1=1
  911. and me.default_flag=1
  912. and ifnull(m.delete_flag,'0') !='1'
  913. and mis.depot_id=mcs.depot_id
  914. and ((ifnull(mis.low_safe_stock,0)!=0 and mcs.current_number &lt; ifnull(mis.low_safe_stock,0))
  915. or (ifnull(mis.high_safe_stock,0)!=0 and mcs.current_number > ifnull(mis.high_safe_stock,0)))
  916. <if test="materialParam != null and materialParam !=''">
  917. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  918. 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}
  919. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  920. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  921. </if>
  922. <if test="depotList.size()>0">
  923. and mis.depot_id in
  924. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  925. #{item}
  926. </foreach>
  927. </if>
  928. <if test="categoryList.size()>0">
  929. and m.category_id in
  930. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  931. #{item}
  932. </foreach>
  933. </if>
  934. ) tb
  935. </select>
  936. <select id="getFinishNumber" resultType="java.math.BigDecimal">
  937. select ifnull(sum(di.basic_number),0) from jsh_depot_item di
  938. where di.material_extend_id=#{meId}
  939. and di.link_id=#{linkId}
  940. and ifnull(di.delete_flag,'0') !='1'
  941. and di.header_id
  942. in
  943. (
  944. select dh.id from jsh_depot_head dh
  945. where 1=1
  946. <if test="noType == 'normal'">
  947. and dh.link_number=#{linkStr}
  948. </if>
  949. <if test="noType == 'apply'">
  950. and dh.link_apply=#{linkStr}
  951. </if>
  952. and ifnull(dh.delete_flag,'0') !='1'
  953. <if test="goToType != null and goToType !=''">
  954. and dh.sub_type=#{goToType}
  955. </if>
  956. )
  957. </select>
  958. <select id="getRealFinishNumber" resultType="java.math.BigDecimal">
  959. select ifnull(sum(di.basic_number),0) from jsh_depot_item di
  960. where di.material_extend_id=#{meId}
  961. and di.link_id=#{linkId}
  962. and ifnull(di.delete_flag,'0') !='1'
  963. and di.header_id
  964. in
  965. (
  966. select dh.id from jsh_depot_head dh
  967. where
  968. dh.id!=#{currentHeaderId}
  969. <if test="linkType == 'normal'">
  970. and dh.link_number=#{linkStr}
  971. </if>
  972. <if test="linkType == 'apply'">
  973. and dh.link_apply=#{linkStr}
  974. </if>
  975. and ifnull(dh.delete_flag,'0') !='1'
  976. <if test="goToType != null and goToType !=''">
  977. and dh.sub_type=#{goToType}
  978. </if>
  979. )
  980. </select>
  981. <select id="getBatchNumberList" resultType="com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList">
  982. select id, bar_code, name, standard, model, unit_id,
  983. commodity_unit, batch_number, expiration_date, sum(basic_number) total_num from
  984. (select di.batch_number id, me.bar_code, m.name, m.standard, m.model, m.unit_id,
  985. me.commodity_unit, di.batch_number,di.expiration_date,
  986. di.basic_number*(case dh.type when '入库' then 1 when '出库' then -1 end) as basic_number
  987. from jsh_depot_head dh
  988. left join jsh_depot_item di on dh.id=di.header_id
  989. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag, '0') != '1'
  990. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_flag,'0') !='1'
  991. where me.bar_code= #{barCode}
  992. <if test="name != null">
  993. <bind name="bindName" value="'%'+name+'%'"/>
  994. and di.batch_number like #{bindName}
  995. </if>
  996. <if test="depotId != null">
  997. and di.depot_id= #{depotId}
  998. </if>
  999. <if test="batchNumber != null">
  1000. and di.batch_number= #{batchNumber}
  1001. </if>
  1002. <if test="number != null">
  1003. and dh.number!= #{number}
  1004. </if>
  1005. <if test="forceFlag">
  1006. and dh.status = '1'
  1007. </if>
  1008. <if test="inOutManageFlag">
  1009. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  1010. </if>
  1011. and m.enable_batch_number =1
  1012. and di.delete_flag!=1) tb
  1013. group by id, bar_code, name, standard, model, unit_id,
  1014. commodity_unit, batch_number, expiration_date
  1015. order by expiration_date asc
  1016. </select>
  1017. <select id="getCountByMaterialAndDepot" resultType="java.lang.Long">
  1018. select count(1) from jsh_depot_item di
  1019. where di.material_id=#{mId} and di.depot_id=#{depotId}
  1020. and ifnull(di.delete_flag,'0') !='1'
  1021. </select>
  1022. <select id="getLinkBillDetailMaterialSum" resultMap="materialSumMap">
  1023. select di.material_extend_id, sum(di.oper_number) oper_number from jsh_depot_head dh
  1024. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1025. where dh.number=#{linkStr}
  1026. and ifnull(dh.delete_flag,'0') !='1'
  1027. group by di.material_extend_id
  1028. </select>
  1029. <select id="getBatchBillDetailMaterialSum" resultMap="materialSumMap">
  1030. select di.material_extend_id, sum(di.oper_number) oper_number from jsh_depot_head dh
  1031. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1032. where dh.type=#{type}
  1033. <if test="linkType == 'normal'">
  1034. and dh.link_number=#{linkStr}
  1035. </if>
  1036. <if test="linkType == 'apply'">
  1037. and dh.link_apply=#{linkStr}
  1038. </if>
  1039. and ifnull(dh.delete_flag,'0') !='1'
  1040. group by di.material_extend_id
  1041. </select>
  1042. <select id="getCountByMaterialAndBatchNumber" resultType="java.lang.Long">
  1043. select count(di.id) from
  1044. jsh_depot_head dh
  1045. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1046. where 1=1
  1047. and ifnull(dh.delete_flag,'0') !='1'
  1048. and di.material_extend_id=#{meId}
  1049. and di.batch_number=#{batchNumber}
  1050. </select>
  1051. <select id="getDepotItemByBatchNumber" resultType="com.jsh.erp.datasource.entities.DepotItem">
  1052. select di.* from jsh_depot_head dh
  1053. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1054. where 1=1
  1055. and ifnull(dh.delete_flag,'0') !='1'
  1056. and di.material_extend_id = #{materialExtendId}
  1057. and di.batch_number = #{batchNumber}
  1058. and dh.type = '入库'
  1059. </select>
  1060. <select id="getBillItemByParam" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  1061. select m.*,u.name unit_name, me.id meId, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  1062. me.wholesale_decimal, me.low_decimal, me.sku,
  1063. 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
  1064. from jsh_material m
  1065. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  1066. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  1067. left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
  1068. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  1069. where 1=1
  1070. <if test="barCodes != null">
  1071. and me.bar_code in (${barCodes})
  1072. </if>
  1073. and ifnull(m.delete_flag,'0') !='1'
  1074. order by m.id desc
  1075. </select>
  1076. <select id="getCurrentStockByParam" resultType="java.math.BigDecimal">
  1077. select sum(ifnull(current_number,0))
  1078. from jsh_material_current_stock
  1079. where 1=1
  1080. <if test="depotId != null">
  1081. and depot_id = ${depotId}
  1082. </if>
  1083. <if test="mId != null">
  1084. and material_id = ${mId}
  1085. </if>
  1086. and ifnull(delete_flag,'0') !='1'
  1087. </select>
  1088. <select id="getLastUnitPriceByParam" resultType="java.math.BigDecimal">
  1089. select di.unit_price from jsh_depot_head dh
  1090. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  1091. where dh.organ_id = #{organId}
  1092. and di.material_extend_id = #{meId}
  1093. and dh.type = #{type} and dh.sub_type = #{subType}
  1094. and ifnull(dh.delete_flag,'0') !='1'
  1095. order by dh.id desc, di.id desc
  1096. limit 0,1
  1097. </select>
  1098. <select id="getDepotMaterialBySystemSku" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  1099. select m.*,u.name unit_name, me.id meId, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  1100. me.wholesale_decimal, me.low_decimal, me.sku,
  1101. 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
  1102. from jsh_material m
  1103. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  1104. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  1105. left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
  1106. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  1107. where m.system_sku = #{systemSku}
  1108. AND me.inventory > 0
  1109. AND ifnull(m.delete_flag,'0') !='1'
  1110. order by me.production_date LIMIT 1
  1111. </select>
  1112. </mapper>