MaterialMapperEx.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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.MaterialMapperEx">
  4. <resultMap extends="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap" id="ResultMapList" type="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  5. <result column="unitName" jdbcType="VARCHAR" property="unitName" />
  6. <result column="ratio" jdbcType="DECIMAL" property="ratio" />
  7. <result column="categoryName" jdbcType="VARCHAR" property="categoryName" />
  8. <result column="bar_code" jdbcType="VARCHAR" property="mBarCode" />
  9. <result column="commodity_unit" jdbcType="VARCHAR" property="commodityUnit" />
  10. <result column="purchase_decimal" jdbcType="VARCHAR" property="purchaseDecimal" />
  11. <result column="commodity_decimal" jdbcType="VARCHAR" property="commodityDecimal" />
  12. <result column="wholesale_decimal" jdbcType="VARCHAR" property="wholesaleDecimal" />
  13. <result column="low_decimal" jdbcType="VARCHAR" property="lowDecimal" />
  14. <result column="sku" jdbcType="VARCHAR" property="sku" />
  15. </resultMap>
  16. <resultMap extends="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap" id="ResultMapListWithStock" type="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  17. <result column="unitName" jdbcType="VARCHAR" property="unitName" />
  18. <result column="categoryName" jdbcType="VARCHAR" property="categoryName" />
  19. <result column="mBarCode" jdbcType="VARCHAR" property="mBarCode" />
  20. <result column="purchaseDecimal" jdbcType="VARCHAR" property="purchaseDecimal" />
  21. <result column="currentUnitPrice" jdbcType="VARCHAR" property="currentUnitPrice" />
  22. <result column="initialStock" jdbcType="DECIMAL" property="initialStock" />
  23. <result column="currentStock" jdbcType="DECIMAL" property="currentStock" />
  24. <result column="currentStockPrice" jdbcType="DECIMAL" property="currentStockPrice" />
  25. <result column="currentStockMovePrice" jdbcType="DECIMAL" property="currentStockMovePrice" />
  26. <result column="currentWeight" jdbcType="DECIMAL" property="currentWeight" />
  27. </resultMap>
  28. <resultMap extends="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap" id="ResultAndUnitMap" type="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  29. <result column="meId" jdbcType="BIGINT" property="meId" />
  30. <result column="unit_name" jdbcType="VARCHAR" property="unitName" />
  31. <result column="sku" jdbcType="VARCHAR" property="sku" />
  32. <result column="production_date" jdbcType="DATE" property="productionDate" />
  33. <result column="expiry_num" jdbcType="INTEGER" property="expiryNum" />
  34. <result column="supplier_id" jdbcType="BIGINT" property="supplierId" />
  35. <result column="bar_code" jdbcType="VARCHAR" property="barCode" />
  36. <result column="batch_number" jdbcType="VARCHAR" property="batchNumber" />
  37. <result column="inventory" jdbcType="BIGINT" property="inventory" />
  38. <result column="depot_id" jdbcType="BIGINT" property="depotId" />
  39. <result column="position" jdbcType="VARCHAR" property="position" />
  40. <result column="depotName" jdbcType="VARCHAR" property="depotName" />
  41. </resultMap>
  42. <resultMap id="InitialStockWithMaterialMap" type="com.jsh.erp.datasource.entities.MaterialInitialStockWithMaterial">
  43. <result column="material_id" jdbcType="BIGINT" property="materialId" />
  44. <result column="number" jdbcType="DECIMAL" property="number" />
  45. </resultMap>
  46. <select id="selectByConditionMaterial" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
  47. select jm.*, u.name unitName, mc.name categoryName, jme.bar_code,
  48. jme.purchase_decimal, jme.commodity_decimal, jme.wholesale_decimal, jme.low_decimal, jme.sku
  49. from (select m.id, min(me.id) meId
  50. from jsh_material m
  51. left join jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
  52. where 1=1
  53. <if test="materialParam != null and materialParam !=''">
  54. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  55. 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}
  56. or m.model like #{bindKey} or m.color like #{bindKey} or m.brand like #{bindKey})
  57. </if>
  58. <if test="standard != null and standard !=''">
  59. <bind name="bindStandard" value="'%'+standard+'%'"/>
  60. and m.standard like #{bindStandard}
  61. </if>
  62. <if test="model != null and model !=''">
  63. <bind name="bindModel" value="'%'+model+'%'"/>
  64. and m.model like #{bindModel}
  65. </if>
  66. <if test="color != null and color !=''">
  67. <bind name="bindColor" value="'%'+color+'%'"/>
  68. and m.color like #{bindColor}
  69. </if>
  70. <if test="brand != null and brand !=''">
  71. <bind name="bindBrand" value="'%'+brand+'%'"/>
  72. and m.brand like #{bindBrand}
  73. </if>
  74. <if test="materialOther != null and materialOther !=''">
  75. <bind name="bindOther" value="'%'+materialOther+'%'"/>
  76. and (m.other_field1 like #{bindOther} or m.other_field2 like #{bindOther} or m.other_field3 like #{bindOther})
  77. </if>
  78. <if test="weight != null and weight !=''">
  79. and m.weight = #{weight}
  80. </if>
  81. <if test="expiryNum != null and expiryNum !=''">
  82. and m.expiry_num = #{expiryNum}
  83. </if>
  84. <if test="enableSerialNumber != null and enableSerialNumber !=''">
  85. and m.enable_serial_number = #{enableSerialNumber}
  86. </if>
  87. <if test="enableBatchNumber != null and enableBatchNumber !=''">
  88. and m.enable_batch_number = #{enableBatchNumber}
  89. </if>
  90. <if test="position != null and position !=''">
  91. <bind name="bindPosition" value="'%'+position+'%'"/>
  92. and m.position like #{bindPosition}
  93. </if>
  94. <if test="enabled != null and enabled !=''">
  95. and m.enabled = #{enabled}
  96. </if>
  97. <if test="remark != null and remark !=''">
  98. <bind name="bindRemark" value="'%'+remark+'%'"/>
  99. and m.remark like #{bindRemark}
  100. </if>
  101. <if test="idList.size()>0">
  102. and m.category_id in
  103. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  104. #{item}
  105. </foreach>
  106. </if>
  107. and ifnull(m.delete_flag,'0') !='1'
  108. group by m.id
  109. order by m.id desc) tb
  110. left join jsh_material jm on tb.id = jm.id and ifnull(jm.delete_Flag,'0') !='1'
  111. left join jsh_material_extend jme on tb.meId = jme.id and ifnull(jme.delete_Flag,'0') !='1'
  112. left join jsh_unit u on jm.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
  113. left join jsh_material_category mc on jm.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  114. order by tb.id desc
  115. </select>
  116. <insert id="insertSelectiveEx" parameterType="com.jsh.erp.datasource.entities.Material" useGeneratedKeys="true" keyProperty="id">
  117. insert into jsh_material
  118. <trim prefix="(" suffix=")" suffixOverrides=",">
  119. <if test="id != null">
  120. id,
  121. </if>
  122. <if test="categoryId != null">
  123. category_id,
  124. </if>
  125. <if test="name != null">
  126. name,
  127. </if>
  128. <if test="model != null">
  129. model,
  130. </if>
  131. <if test="standard != null">
  132. standard,
  133. </if>
  134. <if test="brand != null">
  135. brand,
  136. </if>
  137. <if test="mnemonic != null">
  138. mnemonic,
  139. </if>
  140. <if test="color != null">
  141. color,
  142. </if>
  143. <if test="unit != null">
  144. unit,
  145. </if>
  146. <if test="remark != null">
  147. remark,
  148. </if>
  149. <if test="imgName != null">
  150. img_name,
  151. </if>
  152. <if test="unitId != null">
  153. unit_id,
  154. </if>
  155. <if test="weight != null">
  156. weight,
  157. </if>
  158. <if test="enabled != null">
  159. enabled,
  160. </if>
  161. <if test="otherField1 != null">
  162. other_field1,
  163. </if>
  164. <if test="otherField2 != null">
  165. other_field2,
  166. </if>
  167. <if test="otherField3 != null">
  168. other_field3,
  169. </if>
  170. <if test="enableSerialNumber != null">
  171. enable_serial_number,
  172. </if>
  173. <if test="enableBatchNumber != null">
  174. enable_batch_number,
  175. </if>
  176. <if test="tenantId != null">
  177. tenant_id,
  178. </if>
  179. <if test="deleteFlag != null">
  180. delete_flag,
  181. </if>
  182. <if test="systemSku != null">
  183. system_sku,
  184. </if>
  185. <if test="movingPinReminderCycle != null">
  186. moving_pin_reminder_cycle,
  187. </if>
  188. </trim>
  189. <trim prefix="values (" suffix=")" suffixOverrides=",">
  190. <if test="id != null">
  191. #{id,jdbcType=BIGINT},
  192. </if>
  193. <if test="categoryId != null">
  194. #{categoryId,jdbcType=BIGINT},
  195. </if>
  196. <if test="name != null">
  197. #{name,jdbcType=VARCHAR},
  198. </if>
  199. <if test="model != null">
  200. #{model,jdbcType=VARCHAR},
  201. </if>
  202. <if test="standard != null">
  203. #{standard,jdbcType=VARCHAR},
  204. </if>
  205. <if test="brand != null">
  206. #{brand,jdbcType=VARCHAR},
  207. </if>
  208. <if test="mnemonic != null">
  209. #{mnemonic,jdbcType=VARCHAR},
  210. </if>
  211. <if test="color != null">
  212. #{color,jdbcType=VARCHAR},
  213. </if>
  214. <if test="unit != null">
  215. #{unit,jdbcType=VARCHAR},
  216. </if>
  217. <if test="remark != null">
  218. #{remark,jdbcType=VARCHAR},
  219. </if>
  220. <if test="imgName != null">
  221. #{imgName,jdbcType=VARCHAR},
  222. </if>
  223. <if test="unitId != null">
  224. #{unitId,jdbcType=BIGINT},
  225. </if>
  226. <if test="weight != null">
  227. #{weight,jdbcType=DECIMAL},
  228. </if>
  229. <if test="enabled != null">
  230. #{enabled,jdbcType=BIT},
  231. </if>
  232. <if test="otherField1 != null">
  233. #{otherField1,jdbcType=VARCHAR},
  234. </if>
  235. <if test="otherField2 != null">
  236. #{otherField2,jdbcType=VARCHAR},
  237. </if>
  238. <if test="otherField3 != null">
  239. #{otherField3,jdbcType=VARCHAR},
  240. </if>
  241. <if test="enableSerialNumber != null">
  242. #{enableSerialNumber,jdbcType=VARCHAR},
  243. </if>
  244. <if test="enableBatchNumber != null">
  245. #{enableBatchNumber,jdbcType=VARCHAR},
  246. </if>
  247. <if test="tenantId != null">
  248. #{tenantId,jdbcType=BIGINT},
  249. </if>
  250. <if test="deleteFlag != null">
  251. #{deleteFlag,jdbcType=VARCHAR},
  252. </if>
  253. <if test="systemSku != null">
  254. #{systemSku,jdbcType=VARCHAR},
  255. </if>
  256. <if test="movingPinReminderCycle != null">
  257. #{movingPinReminderCycle,jdbcType=VARCHAR},
  258. </if>
  259. </trim>
  260. </insert>
  261. <select id="findUnitList" resultType="com.jsh.erp.datasource.entities.Unit">
  262. select u.* from jsh_unit u
  263. left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1'
  264. where m.id = #{mId}
  265. and ifnull(u.delete_flag,'0') !='1'
  266. </select>
  267. <select id="findById" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
  268. select m.*,u.name unit_name from jsh_material m
  269. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_flag,'0') !='1'
  270. where m.id = #{id}
  271. and ifnull(m.delete_flag,'0') !='1'
  272. </select>
  273. <select id="findByIdWithBarCode" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
  274. select m.*,u.name unit_name,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  275. me.wholesale_decimal, me.low_decimal
  276. from jsh_material m
  277. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  278. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  279. where me.id = #{meId}
  280. and ifnull(m.delete_flag,'0') !='1'
  281. </select>
  282. <select id="getMaterialByParam" resultType="com.jsh.erp.datasource.vo.MaterialVoSearch">
  283. select me.bar_code, m.name, m.mnemonic, m.standard, m.model, m.color, me.commodity_unit unit, me.batch_number
  284. from jsh_material m
  285. left join jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
  286. where m.enabled=1 and me.id is not null
  287. <if test="materialParam != null and materialParam !=''">
  288. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  289. and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey} or m.mnemonic like #{bindKey})
  290. </if>
  291. and ifnull(m.delete_flag,'0') !='1'
  292. order by m.id desc, me.default_flag desc, me.id asc
  293. limit 0,20
  294. </select>
  295. <select id="findBySelectWithBarCode" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  296. select m.*,u.name unit_name,mc.name categoryName,me.bar_code,me.id meId,me.commodity_unit,me.sku,
  297. me.production_date,me.expiry_num,me.supplier_id,me.batch_number,me.depot_id,me.position,d.`name` depotName,s.supplier supplierName
  298. from jsh_material m
  299. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  300. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  301. left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  302. left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
  303. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  304. where m.enabled=1 and me.id is not null
  305. <if test="q != null and q !=''">
  306. <bind name="bindKey" value="'%'+q+'%'"/>
  307. 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}
  308. or m.model like #{bindKey} or m.color like #{bindKey} or m.brand like #{bindKey} )
  309. </if>
  310. <if test="standardOrModel != null and standardOrModel !=''">
  311. <bind name="bindStandardOrModel" value="'%'+standardOrModel+'%'"/>
  312. and (m.standard like #{bindStandardOrModel} or m.model like #{bindStandardOrModel})
  313. </if>
  314. <if test="color != null and color !=''">
  315. <bind name="bindColor" value="'%'+color+'%'"/>
  316. and m.color like #{bindColor}
  317. </if>
  318. <if test="brand != null and brand !=''">
  319. <bind name="bindBrand" value="'%'+brand+'%'"/>
  320. and m.brand like #{bindBrand}
  321. </if>
  322. <if test="idList.size()>0">
  323. and m.category_id in
  324. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  325. #{item}
  326. </foreach>
  327. </if>
  328. <if test="enableSerialNumber != null and enableSerialNumber !=''">
  329. and m.enable_serial_number = #{enableSerialNumber}
  330. </if>
  331. <if test="enableBatchNumber != null and enableBatchNumber !=''">
  332. and m.enable_batch_number = #{enableBatchNumber}
  333. </if>
  334. <if test="depotId != null and depotId !=''">
  335. and me.depot_id = #{depotId}
  336. </if>
  337. and ifnull(m.delete_flag,'0') !='1'
  338. ORDER BY m.id desc, me.default_flag desc, me.id asc
  339. <if test="offset != null and rows != null">
  340. limit #{offset},#{rows}
  341. </if>
  342. </select>
  343. <select id="findBySelectWithBarCodeCount" resultType="java.lang.Integer">
  344. select count(1) from jsh_material m
  345. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  346. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  347. where m.enabled=1 and me.id is not null
  348. <if test="q != null and q !=''">
  349. <bind name="bindKey" value="'%'+q+'%'"/>
  350. 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}
  351. or m.model like #{bindKey} or m.color like #{bindKey} or m.brand like #{bindKey})
  352. </if>
  353. <if test="standardOrModel != null and standardOrModel !=''">
  354. <bind name="bindStandardOrModel" value="'%'+standardOrModel+'%'"/>
  355. and (m.standard like #{bindStandardOrModel} or m.model like #{bindStandardOrModel})
  356. </if>
  357. <if test="color != null and color !=''">
  358. <bind name="bindColor" value="'%'+color+'%'"/>
  359. and m.color like #{bindColor}
  360. </if>
  361. <if test="brand != null and brand !=''">
  362. <bind name="bindBrand" value="'%'+brand+'%'"/>
  363. and m.brand like #{bindBrand}
  364. </if>
  365. <if test="idList.size()>0">
  366. and m.category_id in
  367. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  368. #{item}
  369. </foreach>
  370. </if>
  371. <if test="enableSerialNumber != null and enableSerialNumber !=''">
  372. and m.enable_serial_number = #{enableSerialNumber}
  373. </if>
  374. <if test="enableBatchNumber != null and enableBatchNumber !=''">
  375. and m.enable_batch_number = #{enableBatchNumber}
  376. </if>
  377. <if test="depotId != null and depotId !=''">
  378. and me.depot_id = #{depotId}
  379. </if>
  380. and ifnull(m.delete_flag,'0') !='1'
  381. </select>
  382. <select id="exportExcel" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
  383. select m.*,u.name unitName, u.ratio, mc.name categoryName,me.bar_code,me.commodity_unit,me.purchase_decimal, me.commodity_decimal,
  384. me.wholesale_decimal, me.low_decimal, me.sku, me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.depot_id, me.position
  385. from jsh_material m
  386. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  387. left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
  388. left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  389. where 1=1
  390. and (me.default_flag=1 or (me.sku is not null and me.sku!=''))
  391. <if test="materialParam != null and materialParam !=''">
  392. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  393. and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
  394. </if>
  395. <if test="color != null and color !=''">
  396. <bind name="bindColor" value="'%'+color+'%'"/>
  397. and m.color like #{bindColor}
  398. </if>
  399. <if test="materialOther != null and materialOther !=''">
  400. <bind name="bindOther" value="'%'+materialOther+'%'"/>
  401. and (m.other_field1 like #{bindOther}
  402. or m.other_field2 like #{bindOther} or m.other_field3 like #{bindOther})
  403. </if>
  404. <if test="weight != null and weight !=''">
  405. and m.weight = #{weight}
  406. </if>
  407. <if test="expiryNum != null and expiryNum !=''">
  408. and m.expiry_num = #{expiryNum}
  409. </if>
  410. <if test="enabled != null and enabled !=''">
  411. and m.enabled = #{enabled}
  412. </if>
  413. <if test="enableSerialNumber != null and enableSerialNumber !=''">
  414. and m.enable_serial_number = #{enableSerialNumber}
  415. </if>
  416. <if test="enableBatchNumber != null and enableBatchNumber !=''">
  417. and m.enable_batch_number = #{enableBatchNumber}
  418. </if>
  419. <if test="remark != null and remark !=''">
  420. <bind name="bindRemark" value="'%'+remark+'%'"/>
  421. and m.remark like #{bindRemark}
  422. </if>
  423. <if test="idList.size()>0">
  424. and m.category_id in
  425. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  426. #{item}
  427. </foreach>
  428. </if>
  429. and ifnull(m.delete_flag,'0') !='1'
  430. order by m.id desc, me.default_flag desc, me.id asc
  431. </select>
  432. <select id="getOtherMaterialList" resultType="com.jsh.erp.datasource.entities.MaterialExtend">
  433. select me.material_id, me.bar_code, me.commodity_unit from jsh_material_extend me
  434. where me.default_flag=0 and (me.sku='' or me.sku is null)
  435. and ifnull(me.delete_Flag,'0') !='1'
  436. group by me.material_id, me.bar_code, me.commodity_unit
  437. </select>
  438. <select id="findByMaterialName" resultType="com.jsh.erp.datasource.entities.Material">
  439. select m.*
  440. FROM jsh_material m
  441. where 1=1
  442. <if test="name != null">
  443. and m.name =#{name}
  444. </if>
  445. and ifnull(m.delete_flag,'0') !='1'
  446. </select>
  447. <select id="getMaterialEnableSerialNumberList" parameterType="java.util.Map" resultMap="ResultAndUnitMap">
  448. select m.*,me.bar_code m_bar_code from jsh_material m
  449. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  450. where 1=1
  451. and m.enabled=1
  452. and m.enable_serial_number ='1'
  453. <if test="q != null and q !=''">
  454. <bind name="bindKey" value="'%'+q+'%'"/>
  455. and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
  456. </if>
  457. and ifnull(m.delete_flag,'0') !='1'
  458. order by m.id desc
  459. <if test="offset != null and rows != null">
  460. limit #{offset},#{rows}
  461. </if>
  462. </select>
  463. <select id="getMaterialEnableSerialNumberCount" resultType="java.lang.Long">
  464. select count(me.id) from jsh_material m
  465. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  466. where 1=1
  467. and m.enabled ='1'
  468. and m.enable_serial_number ='1'
  469. <if test="q != null and q !=''">
  470. <bind name="bindKey" value="'%'+q+'%'"/>
  471. and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
  472. </if>
  473. and ifnull(m.delete_flag,'0') !='1'
  474. </select>
  475. <update id="batchDeleteMaterialByIds">
  476. update jsh_material
  477. set delete_flag='1'
  478. where 1=1
  479. and ifnull(delete_flag,'0') !='1'
  480. and id in (
  481. <foreach collection="ids" item="id" separator=",">
  482. #{id}
  483. </foreach>
  484. )
  485. </update>
  486. <select id="getMaterialListByCategoryIds" resultMap="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap">
  487. select
  488. <include refid="com.jsh.erp.datasource.mappers.MaterialMapper.Base_Column_List" />
  489. from jsh_material
  490. where 1=1
  491. and category_id in (
  492. <foreach collection="categoryIds" item="categoryId" separator=",">
  493. #{categoryId}
  494. </foreach>
  495. )
  496. and ifnull(delete_flag,'0') !='1'
  497. </select>
  498. <select id="getMaterialListByUnitIds" resultMap="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap">
  499. select
  500. <include refid="com.jsh.erp.datasource.mappers.MaterialMapper.Base_Column_List" />
  501. from jsh_material
  502. where 1=1
  503. and unit_id in (
  504. <foreach collection="unitIds" item="unitId" separator=",">
  505. #{unitId}
  506. </foreach>
  507. )
  508. and ifnull(delete_flag,'0') !='1'
  509. </select>
  510. <select id="getBarCodeList" resultType="java.lang.String">
  511. select me.bar_code from jsh_material_extend me
  512. where ifnull(me.delete_Flag,'0') !='1'
  513. </select>
  514. <select id="getMaterialByMeId" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
  515. select m.*,me.bar_code,u.name unitName, mc.name categoryName
  516. FROM jsh_material m
  517. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  518. left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_flag,'0') !='1'
  519. left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  520. where 1=1
  521. <if test="meId != null">
  522. and me.id = #{meId}
  523. </if>
  524. and ifnull(m.delete_flag,'0') !='1'
  525. </select>
  526. <select id="getMaterialNameList" resultType="java.lang.String">
  527. select m.name from jsh_material m
  528. where m.name is not null and m.name !='' and ifnull(m.delete_flag,'0') !='1'
  529. group by m.name
  530. order by m.name asc
  531. </select>
  532. <select id="getMaterialByBarCode" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
  533. select m.*,u.name unit_name, me.id meId,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  534. me.wholesale_decimal, me.low_decimal, me.sku, me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.depot_id, me.position
  535. from jsh_material m
  536. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  537. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  538. where
  539. me.bar_code in (
  540. <foreach collection="barCodeArray" item="barCode" separator=",">
  541. #{barCode}
  542. </foreach>
  543. )
  544. and ifnull(m.delete_flag,'0') !='1'
  545. order by m.id desc, me.default_flag desc, me.id asc
  546. </select>
  547. <select id="getMaterialByBarCodeAndWithOutMId" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
  548. select m.*,u.name unit_name, me.id meId,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  549. me.wholesale_decimal, me.low_decimal, me.sku
  550. from jsh_material m
  551. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  552. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  553. where
  554. me.bar_code in (
  555. <foreach collection="barCodeArray" item="barCode" separator=",">
  556. #{barCode}
  557. </foreach>
  558. )
  559. and me.material_id!=#{mId}
  560. and ifnull(m.delete_flag,'0') !='1'
  561. order by me.id desc
  562. </select>
  563. <update id="setUnitIdToNull">
  564. update jsh_material
  565. set unit_id = null
  566. where 1=1
  567. and ifnull(delete_flag,'0') !='1'
  568. and id = #{id}
  569. </update>
  570. <update id="setExpiryNumToNull">
  571. update jsh_material
  572. set expiry_num = null
  573. where 1=1
  574. and ifnull(delete_flag,'0') !='1'
  575. and id = #{id}
  576. </update>
  577. <select id="getInitialStockWithMaterial" resultMap="InitialStockWithMaterialMap">
  578. select material_id, ifnull(sum(mis.number),0) number
  579. from jsh_material_initial_stock mis
  580. where 1=1
  581. <if test="depotList.size()>0">
  582. and mis.depot_id in
  583. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  584. #{item}
  585. </foreach>
  586. </if>
  587. group by mis.material_id
  588. </select>
  589. <select id="getListWithStock" resultMap="ResultMapListWithStock">
  590. select m.id, m.name, m.standard, m.model, m.color, m.brand, m.position,
  591. me.commodity_unit unitName, mc.name categoryName, me.bar_code mBarCode,
  592. ifnull(me.purchase_decimal,0) purchaseDecimal,
  593. ifnull(mcs.current_unit_price,0) currentUnitPrice,
  594. ifnull(sum(mcs.current_number),0) currentStock,
  595. sum(ifnull(me.purchase_decimal, 0) * ifnull(mcs.current_number, 0)) currentStockPrice,
  596. sum(ifnull(mcs.current_unit_price, 0) * ifnull(mcs.current_number, 0)) currentStockMovePrice,
  597. sum(ifnull(m.weight, 0) * ifnull(mcs.current_number, 0)) currentWeight
  598. FROM jsh_material m
  599. left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
  600. left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
  601. <if test="depotList.size()>0">
  602. and mcs.depot_id in
  603. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  604. #{item}
  605. </foreach>
  606. </if>
  607. left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
  608. left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  609. where 1=1
  610. and me.default_flag=1
  611. <if test="idList.size()>0">
  612. and m.category_id in
  613. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  614. #{item}
  615. </foreach>
  616. </if>
  617. <if test="position != null and position !=''">
  618. <bind name="bindPosition" value="'%'+position+'%'"/>
  619. and m.position like #{bindPosition}
  620. </if>
  621. <if test="materialParam != null">
  622. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  623. 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}
  624. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  625. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  626. </if>
  627. and ifnull(m.delete_flag,'0') !='1'
  628. group by m.id, m.name, m.standard, m.model, m.color, m.brand,
  629. me.commodity_unit, mc.name, me.bar_code, me.purchase_decimal, mcs.current_unit_price
  630. <if test="zeroStock == 0">
  631. having ifnull(sum(mcs.current_number),0)!=0
  632. </if>
  633. <if test="column == 'createTime'">
  634. order by m.id desc
  635. </if>
  636. <if test="column != 'createTime'">
  637. order by ${column} ${order}
  638. </if>
  639. <if test="offset != null and rows != null">
  640. limit #{offset},#{rows}
  641. </if>
  642. </select>
  643. <select id="getListWithStockCount" resultType="java.lang.Integer">
  644. select count(tb.id) from
  645. (select m.id, ifnull(sum(mcs.current_number),0) currentStock from jsh_material m
  646. left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
  647. left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
  648. <if test="depotList.size()>0">
  649. and mcs.depot_id in
  650. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  651. #{item}
  652. </foreach>
  653. </if>
  654. left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
  655. left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  656. where 1=1
  657. and me.default_flag=1
  658. <if test="idList.size()>0">
  659. and m.category_id in
  660. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  661. #{item}
  662. </foreach>
  663. </if>
  664. <if test="position != null and position !=''">
  665. <bind name="bindPosition" value="'%'+position+'%'"/>
  666. and m.position like #{bindPosition}
  667. </if>
  668. <if test="materialParam != null">
  669. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  670. 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}
  671. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  672. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  673. </if>
  674. and ifnull(m.delete_flag,'0') !='1'
  675. group by m.id
  676. <if test="zeroStock == 0">
  677. having ifnull(sum(mcs.current_number),0)!=0
  678. </if>
  679. ) tb
  680. </select>
  681. <select id="getTotalStockAndPrice" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  682. select
  683. ifnull(sum(mcs.current_number),0) currentStock,
  684. sum(ifnull(me.purchase_decimal,0)*ifnull(mcs.current_number,0)) currentStockPrice,
  685. sum(ifnull(mcs.current_unit_price,0)*ifnull(mcs.current_number,0)) currentStockMovePrice,
  686. sum(ifnull(m.weight,0)*ifnull(mcs.current_number,0)) currentWeight
  687. from jsh_material m
  688. left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'
  689. left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
  690. left JOIN jsh_unit u on m.unit_id = u.id and ifnull(u.delete_Flag,'0') !='1'
  691. left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  692. where 1=1
  693. and me.default_flag=1
  694. <if test="depotList.size()>0">
  695. and mcs.depot_id in
  696. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  697. #{item}
  698. </foreach>
  699. </if>
  700. <if test="idList.size()>0">
  701. and m.category_id in
  702. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  703. #{item}
  704. </foreach>
  705. </if>
  706. <if test="position != null and position !=''">
  707. <bind name="bindPosition" value="'%'+position+'%'"/>
  708. and m.position like #{bindPosition}
  709. </if>
  710. <if test="materialParam != null">
  711. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  712. 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}
  713. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  714. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  715. </if>
  716. and ifnull(m.delete_flag,'0') !='1'
  717. </select>
  718. <select id="checkIsExist" resultType="java.lang.Integer">
  719. select count(1) from jsh_material m
  720. where ifnull(m.delete_flag,'0') !='1'
  721. <if test="name != null">
  722. and m.name = #{name}
  723. </if>
  724. <if test="model != null">
  725. and m.model = #{model}
  726. </if>
  727. <if test="color != null">
  728. and m.color = #{color}
  729. </if>
  730. <if test="standard != null">
  731. and m.standard = #{standard}
  732. </if>
  733. <if test="otherField1 != null">
  734. and m.other_field1 = #{otherField1}
  735. </if>
  736. <if test="otherField2 != null">
  737. and m.other_field2 = #{otherField2}
  738. </if>
  739. <if test="otherField3 != null">
  740. and m.other_field3 = #{otherField3}
  741. </if>
  742. <if test="unit != null">
  743. and m.unit = #{unit}
  744. </if>
  745. <if test="unitId != null">
  746. and m.unit_id = #{unitId}
  747. </if>
  748. <if test="id != null">
  749. and m.id != #{id}
  750. </if>
  751. </select>
  752. <select id="getMaterialExtendBySerialNumber" resultType="com.jsh.erp.datasource.entities.MaterialExtend">
  753. select me.bar_code
  754. from jsh_material m
  755. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_flag,'0') !='1'
  756. left join jsh_serial_number sn on sn.material_id=m.id and ifnull(sn.delete_flag,'0') !='1'
  757. where sn.serial_number = #{serialNumber}
  758. and me.default_flag=1
  759. and ifnull(m.delete_flag,'0') !='1'
  760. limit 0,1
  761. </select>
  762. <select id="getMaterialByBatchNumber" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  763. select m.*,u.name unit_name, me.id meId, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
  764. me.wholesale_decimal, me.low_decimal, me.sku,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
  765. from jsh_material m
  766. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  767. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  768. left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
  769. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  770. where
  771. me.batch_number in (
  772. <foreach collection="batchNumberArray" item="batchNumber" separator=",">
  773. #{batchNumber}
  774. </foreach>
  775. )
  776. and ifnull(m.delete_flag,'0') !='1'
  777. order by m.id desc, me.default_flag desc, me.id asc
  778. </select>
  779. <select id="getMaterialBySystemSku" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
  780. WITH RankedExtend AS (
  781. SELECT
  782. me.*,
  783. ROW_NUMBER() OVER (PARTITION BY me.material_id ORDER BY me.batch_number DESC) AS rn
  784. FROM jsh_material_extend me
  785. LEFT JOIN jsh_material m ON m.id = me.material_id
  786. WHERE ifnull(me.delete_Flag, '0') != '1'
  787. AND m.system_sku IN (
  788. <foreach collection="systemSkuArray" item="systemSku" separator=",">
  789. #{systemSku}
  790. </foreach>
  791. )
  792. )
  793. SELECT
  794. m.*,
  795. re.id AS meId,
  796. re.bar_code AS m_bar_code,
  797. re.commodity_unit,
  798. re.purchase_decimal,
  799. re.commodity_decimal,
  800. re.wholesale_decimal,
  801. re.low_decimal,
  802. me.sku,
  803. me.production_date,
  804. me.expiry_num,
  805. me.supplier_id,
  806. me.bar_code,
  807. me.batch_number,
  808. me.inventory,
  809. me.depot_id,
  810. me.POSITION
  811. FROM jsh_material m
  812. LEFT JOIN RankedExtend re ON m.id = re.material_id AND re.rn = 1
  813. LEFT JOIN jsh_material_extend me ON re.bar_code = me.bar_code
  814. WHERE ifnull(m.delete_flag, '0') != '1' AND re.id IS NOT NULL
  815. ORDER BY m.id DESC, me.default_flag DESC, me.production_date,me.batch_number ASC
  816. </select>
  817. <select id="inventoryInquiry" parameterType="com.jsh.erp.datasource.pda.dto.PDAInventoryDTO" resultType="com.jsh.erp.datasource.pda.vo.PDADepotItemVO">
  818. select m.id materialId,m.name materialName,m.standard materialStandard,u.name unit_name,mc.name categoryName,me.bar_code,me.id meId,me.commodity_unit,me.sku,
  819. me.production_date,me.expiry_num,me.supplier_id,me.batch_number,me.depot_id,me.position,d.`name` depotName,s.supplier supplierName
  820. from jsh_material m
  821. left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
  822. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  823. left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
  824. left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
  825. left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
  826. where m.enabled = 1
  827. and me.id is not null
  828. <if test="keyword != null and keyword !=''">
  829. <bind name="bindKey" value="'%'+keyword+'%'"/>
  830. and (me.batch_number like #{bindKey} or m.name like #{bindKey})
  831. </if>
  832. <if test="position != null and position !=''">
  833. <bind name="bindPosition" value="'%'+position+'%'"/>
  834. and me.position like #{bindPosition}
  835. </if>
  836. <if test="categoryId != null">
  837. and m.category_id IN (
  838. <foreach collection="categoryIds" item="item" separator=",">
  839. #{item}
  840. </foreach>
  841. )
  842. </if>
  843. <if test="type == 'have'">
  844. and me.inventory > 0
  845. </if>
  846. <if test="type == 'none'">
  847. and me.inventory &lt;= 0
  848. </if>
  849. and ifnull(me.delete_flag,'0') !='1'
  850. </select>
  851. <select id="getMaterialCurrentPriceByIdList" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultType="com.jsh.erp.datasource.vo.MaterialCurrentStock4SystemSku">
  852. WITH RankedExtend AS (
  853. SELECT
  854. me.*,
  855. ROW_NUMBER() OVER (PARTITION BY me.material_id ORDER BY me.batch_number DESC) AS rn
  856. FROM jsh_material_extend me
  857. LEFT JOIN jsh_material m ON m.id = me.material_id
  858. WHERE ifnull(me.delete_Flag, '0') != '1'
  859. AND m.id IN (
  860. <foreach collection="idList" item="systemSku" separator=",">
  861. #{systemSku}
  862. </foreach>
  863. )
  864. )
  865. SELECT
  866. m.id AS mId,
  867. m.name AS mName,
  868. m.unit AS unit,
  869. m.unit_id AS unitId,
  870. m.system_sku AS systemSku,
  871. re.wholesale_decimal AS basicUnitSalePrice
  872. FROM jsh_material m
  873. LEFT JOIN RankedExtend re ON m.id = re.material_id AND re.rn = 1
  874. WHERE ifnull(m.delete_flag, '0') != '1' AND re.id IS NOT NULL
  875. ORDER BY m.id DESC
  876. </select>
  877. </mapper>