HxpStockMapper.xml 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zd.chemical.mapper.HxpStockMapper">
  6. <resultMap type="com.zd.chemical.domain.HxpStock" id="HxpStockResult">
  7. <result property="id" column="id"/>
  8. <result property="joinId" column="join_id"/>
  9. <result property="chemicalNum" column="chemical_num"/>
  10. <result property="userId" column="user_id"/>
  11. <result property="chemicalName" column="chemical_name"/>
  12. <result property="createBy" column="create_by"/>
  13. <result property="cabinetNum" column="cabinet_num"/>
  14. <result property="createTime" column="create_time"/>
  15. <result property="cabinetName" column="cabinet_name"/>
  16. <result property="updateBy" column="update_by"/>
  17. <result property="chemicalClassify" column="chemical_classify"/>
  18. <result property="updateTime" column="update_time"/>
  19. <result property="remark" column="remark"/>
  20. <result property="status" column="status"/>
  21. <result property="chemicalShape" column="chemical_shape"/>
  22. <result property="labelType" column="label_type"/>
  23. <result property="printCode" column="print_code"/>
  24. <result property="joinType" column="join_type"/>
  25. <result property="joinUserId" column="join_user_id"/>
  26. <result property="joinTime" column="join_time"/>
  27. <result property="expirationTime" column="expiration_time"/>
  28. <result property="measuringMethod" column="measuring_method"/>
  29. <result property="chemicalUnit" column="chemical_unit"/>
  30. <result property="verification" column="verification"/>
  31. <result property="anotherName" column="another_name"/>
  32. <result property="casNum" column="cas_num"/>
  33. <result property="factory" column="factory"/>
  34. <result property="purity" column="purity"/>
  35. <result property="joinOneUser" column="join_one_user"/>
  36. <result property="joinTwoUser" column="join_two_user"/>
  37. <result property="joinVideo" column="join_video"/>
  38. <result property="tagCode" column="tag_code"/>
  39. <result property="rfidCode" column="rfid_code"/>
  40. <result property="usages" column="usages"/>
  41. <result property="outUserId" column="out_user_id"/>
  42. <result property="outOneUser" column="out_one_user"/>
  43. <result property="outTwoUser" column="out_two_user"/>
  44. <result property="outTime" column="out_time"/>
  45. <result property="outUsages" column="out_usages"/>
  46. <result property="subId" column="sub_id"/>
  47. <result property="tare" column="tare"/>
  48. </resultMap>
  49. <sql id="selectHxpStockVo">
  50. select id,
  51. join_id,
  52. chemical_num,
  53. user_id,
  54. chemical_name,
  55. create_by,
  56. cabinet_num,
  57. create_time,
  58. cabinet_name,
  59. update_by,
  60. chemical_classify,
  61. update_time,
  62. remark,
  63. status,
  64. chemical_shape,
  65. label_type,
  66. print_code,
  67. join_type,
  68. join_user_id,
  69. join_time,
  70. expiration_time,
  71. measuring_method,
  72. chemical_unit,
  73. verification,
  74. another_name,
  75. cas_num,
  76. factory,
  77. purity,
  78. join_one_user,
  79. join_two_user,
  80. join_video,
  81. tag_code,
  82. rfid_code,
  83. usages,
  84. out_user_id,
  85. out_one_user,
  86. out_two_user,
  87. out_time,
  88. out_usages,
  89. sub_id,
  90. tare
  91. from hxp_stock
  92. </sql>
  93. <sql id="selectHxpStockListVo">
  94. select t.id,
  95. t.join_id,
  96. t.chemical_num,
  97. t.user_id,
  98. t.chemical_name,
  99. t.create_by,
  100. t.cabinet_num,
  101. t.create_time,
  102. t.cabinet_name,
  103. t.update_by,
  104. t.chemical_classify,
  105. t.update_time,
  106. t.remark,
  107. t.status,
  108. t.label_type,
  109. t.print_code,
  110. t.join_type,
  111. t.join_user_id,
  112. t.join_time,
  113. t.expiration_time,
  114. t.measuring_method,
  115. t.chemical_unit,
  116. t.verification,
  117. t.another_name,
  118. t.cas_num,
  119. t.factory,
  120. t.purity,
  121. t.join_one_user,
  122. t.join_two_user,
  123. t.join_video,
  124. t.tag_code,
  125. t.rfid_code,
  126. t.usages,
  127. t.out_user_id,
  128. t.out_one_user,
  129. t.out_two_user,
  130. t.out_time,
  131. t.out_usages,
  132. t.sub_id,
  133. t.tare,
  134. jc.chemical_amount,
  135. jc.chemical_amount_unit,
  136. s.safe_user_id,
  137. t.chemical_shape,
  138. ( select join_hazard_id from hxp_chemical where id = jc.chemical_id ) hazardId,
  139. (select ccf.classify_name from hxp_chemical_classify ccf where ccf.id = t.chemical_classify) classifyName,
  140. (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'hxp_classifyattribute' AND
  141. FIND_IN_SET(dda.dict_value, (select classify_attribute from hxp_chemical where id = jc.chemical_id
  142. ))) classifyAttribute
  143. from hxp_stock as t left join hxp_chemical_join_cabinet jc on jc.id = t.join_id
  144. left join lab_subject s on s.id = t.sub_id
  145. left join hxp_chemical che on jc.chemical_id = che.id
  146. </sql>
  147. <select id="selectHxpStockList" parameterType="com.zd.chemical.domain.HxpStock" resultMap="HxpStockResult">
  148. <include refid="selectHxpStockListVo"/>
  149. <where>
  150. <if test="id != null ">and t.id = #{id}</if>
  151. <if test="joinId != null ">and t.join_id = #{joinId}</if>
  152. <if test="chemicalNum != null and chemicalNum != ''">and t.chemical_num = #{chemicalNum}</if>
  153. <if test="userId != null ">and t.user_id = #{userId}</if>
  154. <if test="cabinetId != null">
  155. and jc.cabinet_id = #{cabinetId}
  156. </if>
  157. <if test="chemicalName != null and chemicalName != ''">
  158. and (t.chemical_name like concat('%', #{chemicalName}, '%')
  159. or t.another_name like concat('%', #{chemicalName}, '%')
  160. or che.chemical_name_char like concat(#{chemicalName}, '%')
  161. or che.another_name_char like concat(#{chemicalName}, '%')
  162. )
  163. </if>
  164. <if test="cabinetNum != null and cabinetNum != ''">and t.cabinet_num = #{cabinetNum}</if>
  165. <if test="cabinetName != null and cabinetName != ''">and t.cabinet_name like concat('%', #{cabinetName},
  166. '%')
  167. </if>
  168. <if test="chemicalClassify != null and chemicalClassify != ''">and t.chemical_classify =
  169. #{chemicalClassify}
  170. </if>
  171. <if test="status != null ">and t.status = #{status}</if>
  172. <if test="chemicalShape != null and chemicalShape != ''">and t.chemical_shape = #{chemicalShape}</if>
  173. <if test="labelType != null and labelType != ''">and t.label_type = #{labelType}</if>
  174. <if test="joinType != null ">and t.join_type = #{joinType}</if>
  175. <if test="joinUserId != null ">and t.join_user_id = #{joinUserId}</if>
  176. <if test="joinTime != null ">and t.join_time = #{joinTime}</if>
  177. <if test="expirationTime != null ">and t.expiration_time = #{expirationTime}</if>
  178. <if test="measuringMethod != null ">and t.measuring_method = #{measuringMethod}</if>
  179. <if test="chemicalUnit != null and chemicalUnit != ''">and chemical_unit = #{chemicalUnit}</if>
  180. <if test="verification != null ">and t.verification = #{verification}</if>
  181. <if test="anotherName != null and anotherName != ''">and t.another_name like concat('%', #{anotherName},
  182. '%')
  183. </if>
  184. <if test="casNum != null and casNum != ''">and t.cas_num = #{casNum}</if>
  185. <if test="factory != null and factory != ''">and t.factory = #{factory}</if>
  186. <if test="purity != null and purity != ''">and t.purity = #{purity}</if>
  187. <if test="joinOneUser != null ">and t.join_one_user = #{joinOneUser}</if>
  188. <if test="joinTwoUser != null ">and t.join_two_user = #{joinTwoUser}</if>
  189. <if test="tagCode != null and tagCode != ''">and t.tag_code = #{tagCode}</if>
  190. <if test="usages != null ">and t.usages = #{usages}</if>
  191. <if test="outUserId != null ">and t.out_user_id = #{outUserId}</if>
  192. <if test="outTime != null ">and t.out_time = #{outTime}</if>
  193. <if test="outUsages != null ">and t.out_usages = #{outUsages}</if>
  194. <if test="subId != null ">and t.sub_id = #{subId}</if>
  195. <if test="scanCode != null and scanCode != ''">
  196. and (t.tag_code = #{scanCode} or t.rfid_code = #{scanCode})
  197. </if>
  198. </where>
  199. </select>
  200. <select id="selectHxpStockById" parameterType="Long" resultMap="HxpStockResult">
  201. <include refid="selectHxpStockListVo"/>
  202. where t.id = #{id}
  203. </select>
  204. <select id="selectCountByTagCode" resultType="java.lang.Integer">
  205. select count(1)
  206. from hxp_stock
  207. where tag_code = #{tagCode}
  208. </select>
  209. <select id="selectHxpStockListDetail" parameterType="com.zd.chemical.domain.vo.HxpStockSearch"
  210. resultType="com.zd.chemical.domain.vo.HxpStockDetailVO">
  211. SELECT sk.id,(SELECT cjc.join_num FROM hxp_chemical_join_cabinet cjc WHERE cjc.id = sk.join_id) joinNum,
  212. sk.chemical_name chemicalName,
  213. (SELECT cl.cas_num FROM hxp_chemical_join_cabinet cjc,hxp_chemical cl WHERE cjc.id = sk.join_id AND cjc.chemical_id = cl.id) casNum,
  214. ct.cabinet_name cabinetName,
  215. CONCAT((SELECT st.name FROM lab_subject st WHERE st.id = sk.`sub_id`),
  216. '-', (SELECT dt.dept_name FROM sys_dept dt,lab_subject st WHERE dt.dept_id = st.build_id AND st.id = sk.`sub_id`),
  217. '-',(SELECT bg.name FROM lab_building bg,lab_subject st WHERE bg.id = st.floor_id AND st.id = sk.`sub_id`),
  218. '-', (SELECT slt.room FROM lab_subject_layout slt, lab_subject st WHERE slt.id = st.layout_id AND st.id = sk.`sub_id`)) posi,
  219. (SELECT cc.classify_name FROM hxp_chemical_classify cc WHERE cc.id = sk.chemical_classify) classifyName,
  220. (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda,hxp_chemical_join_cabinet cjc,hxp_chemical cl
  221. WHERE cjc.id = sk.join_id AND cjc.chemical_id = cl.id AND dda.dict_type = 'hxp_classifyattribute' AND FIND_IN_SET(dda.dict_value, cl.classify_attribute)) classifyAttribute,
  222. IFNULL((SELECT CONCAT(cjc.chemical_amount, cjc.chemical_amount_unit)
  223. FROM hxp_chemical_join_cabinet cjc
  224. WHERE cjc.id = sk.join_id),
  225. '无') chemicalAmountUnit,
  226. IFNULL((SELECT CONCAT(cjc.tare, cjc.chemical_amount_unit)
  227. FROM hxp_chemical_join_cabinet cjc
  228. WHERE cjc.id = sk.join_id),
  229. '无') tareUnit,
  230. CASE WHEN sk.label_type = 1 THEN 'RFID' ELSE '二维码' END labelType,
  231. sk.tag_code tagCode,
  232. sk.expiration_time expirationTime,
  233. CONCAT(sk.usages-IFNULL(sk.tare,0), sk.chemical_unit) usages,
  234. CASE WHEN sk.status=2 OR sk.status=3 THEN CONCAT(0, sk.chemical_unit) ELSE
  235. CONCAT(sk.out_usages-IFNULL(sk.tare,0), sk.chemical_unit) END outUsages,
  236. CASE
  237. WHEN sk.status = 1 THEN '在库'
  238. ELSE CASE WHEN sk.status = 2 THEN '用结出库'
  239. else case when sk.status = 3 then '作废出库'
  240. else '已过期'
  241. end END END stockStatus,
  242. sk.join_time joinTime,
  243. sk.out_time outTime
  244. FROM hxp_stock sk LEFT JOIN hxp_chemical_join_cabinet cjc ON sk.join_id = cjc.id
  245. LEFT JOIN hxp_chemical cl ON cjc.chemical_id = cl.id
  246. LEFT JOIN hxp_cabinet ct ON ct.id = cjc.cabinet_id
  247. LEFT JOIN lab_subject st ON ct.sub_id = st.id
  248. <where>
  249. <if test="searchValue != null and searchValue != ''">
  250. and (cl.chemical_name like concat('%',#{searchValue},'%')
  251. or cl.another_name like concat('%',#{searchValue},'%')
  252. or cl.cas_num like concat('%',#{searchValue},'%')
  253. or cjc.join_num like concat('%',#{searchValue},'%')
  254. or st.name like concat('%',#{searchValue},'%')
  255. )
  256. </if>
  257. <if test="chemicalClassify != null">
  258. AND cl.chemical_classify = #{chemicalClassify}
  259. </if>
  260. <if test="labelType != null">
  261. AND sk.label_type = #{labelType}
  262. </if>
  263. <if test="deptId != null">
  264. AND st.dept_id = #{deptId}
  265. </if>
  266. <if test="cabinetId != null">
  267. AND cjc.cabinet_id = #{cabinetId}
  268. </if>
  269. <if test="status != null">
  270. AND sk.status = #{status}
  271. </if>
  272. <if test="classifyAttribute != null ">
  273. and FIND_IN_SET(#{classifyAttribute}, cl.classify_attribute)
  274. </if>
  275. <if test="joinTimeBegin != null">
  276. AND date_format(sk.join_time,'%Y-%m-%d') >= date_format(#{joinTimeBegin},'%Y-%m-%d')
  277. </if>
  278. <if test="joinTimeEnd != null">
  279. AND date_format(sk.join_time,'%Y-%m-%d') &lt;= date_format(#{joinTimeEnd},'%Y-%m-%d')
  280. </if>
  281. <if test="outTimeBegin != null">
  282. AND date_format(sk.out_time,'%Y-%m-%d') >= date_format(#{outTimeBegin},'%Y-%m-%d')
  283. </if>
  284. <if test="outTimeEnd != null">
  285. AND date_format(sk.out_time,'%Y-%m-%d') &lt;= date_format(#{outTimeEnd},'%Y-%m-%d')
  286. </if>
  287. <if test="ids!=null and ids.size > 0">
  288. AND sk.id IN
  289. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  290. </if>
  291. <!-- 数据范围过滤 -->
  292. ${params.dataScope}
  293. </where>
  294. order by sk.create_time desc
  295. </select>
  296. <select id="selectHxpStockListJoin" parameterType="com.zd.chemical.domain.vo.HxpStockSearch"
  297. resultType="com.zd.chemical.domain.vo.HxpStockJoinVO">
  298. SELECT sk.id,sk.join_time joinTime,
  299. (SELECT cjc.join_num FROM hxp_chemical_join_cabinet cjc WHERE cjc.id = sk.join_id) joinNum
  300. ,
  301. sk.chemical_name chemicalName,
  302. (SELECT cl.cas_num FROM hxp_chemical_join_cabinet cjc,hxp_chemical cl WHERE cjc.id = sk.join_id AND cjc.chemical_id = cl.id) casNum,
  303. (SELECT cc.classify_name FROM hxp_chemical_classify cc WHERE cc.id = sk.chemical_classify) classifyName,
  304. (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda,hxp_chemical_join_cabinet cjc,hxp_chemical cl
  305. WHERE cjc.id = sk.join_id AND cjc.chemical_id = cl.id AND dda.dict_type = 'hxp_classifyattribute' AND FIND_IN_SET(dda.dict_value, cl.classify_attribute)) classifyAttribute,
  306. CASE
  307. WHEN sk.chemical_shape = 1 THEN CONCAT('固体', '(', sk.chemical_unit, ')')
  308. ELSE CONCAT('液体', '(', sk.chemical_unit, ')') END chemicalShape,
  309. IFNULL((SELECT CONCAT(cjc.chemical_amount, cjc.chemical_amount_unit)
  310. FROM hxp_chemical_join_cabinet cjc
  311. WHERE cjc.id = sk.join_id),
  312. '无') chemicalAmountUnit,
  313. IFNULL((SELECT CONCAT(cjc.tare, cjc.chemical_amount_unit)
  314. FROM hxp_chemical_join_cabinet cjc
  315. WHERE cjc.id = sk.join_id),
  316. '无') tareUnit,
  317. CASE WHEN sk.label_type = 1 THEN 'RFID' ELSE '二维码' END labelType,
  318. sk.tag_code tagCode,
  319. ct.cabinet_name cabinetName,
  320. CONCAT((SELECT st.name FROM lab_subject st WHERE st.id = sk.`sub_id`),
  321. '-', (SELECT dt.dept_name FROM sys_dept dt, lab_subject st WHERE dt.dept_id = st.build_id AND st.id = sk.`sub_id`),
  322. '-',(SELECT bg.name FROM lab_building bg,lab_subject st WHERE bg.id = st.floor_id AND st.id = sk.`sub_id`),
  323. '-', (SELECT slt.room FROM lab_subject_layout slt, lab_subject st WHERE slt.id = st.layout_id AND st.id = sk.`sub_id`)) posi,
  324. CASE WHEN sk.join_type = 1 THEN '称重' ELSE '录入' END joinType,
  325. CONCAT(sk.usages-IFNULL(sk.tare,0), sk.chemical_unit) usages,
  326. CONCAT(sk.out_usages-IFNULL(sk.tare,0), sk.chemical_unit) outUsages,
  327. CONCAT(ifnull((SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = sk.join_user_id), "")) operator,
  328. CONCAT(ifnull((SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = sk.join_one_user), ""),
  329. case when sk.join_two_user is not null then '、' else '' end,
  330. ifnull((SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = sk.join_two_user), "")) verify,
  331. sk.join_video as joinVideo,
  332. ll.close_lock_video
  333. FROM hxp_stock sk LEFT JOIN hxp_chemical_join_cabinet cjc ON sk.join_id = cjc.id
  334. LEFT JOIN hxp_chemical cl ON cjc.chemical_id = cl.id
  335. LEFT JOIN hxp_cabinet ct ON ct.id = cjc.cabinet_id
  336. LEFT JOIN lab_subject st ON ct.sub_id = st.id
  337. left join hxp_cabinetlock_log ll on sk.id = ll.stock_id and ll.operation_type = 1
  338. <where>
  339. <if test="searchValue != null and searchValue != ''">
  340. and (cl.chemical_name like concat('%',#{searchValue},'%')
  341. or cl.another_name like concat('%',#{searchValue},'%')
  342. or cl.cas_num like concat('%',#{searchValue},'%')
  343. or cjc.join_num like concat('%',#{searchValue},'%')
  344. or st.name like concat('%',#{searchValue},'%')
  345. )
  346. </if>
  347. <if test="chemicalClassify != null">
  348. AND cl.chemical_classify = #{chemicalClassify}
  349. </if>
  350. <if test="classifyAttribute != null ">
  351. and FIND_IN_SET(#{classifyAttribute}, cl.classify_attribute)
  352. </if>
  353. <if test="deptId != null">
  354. AND st.dept_id = #{deptId}
  355. </if>
  356. <if test="cabinetId != null">
  357. AND cjc.cabinet_id = #{cabinetId}
  358. </if>
  359. <if test="labelType != null ">
  360. AND sk.label_type = #{labelType}
  361. </if>
  362. <if test="joinTimeBegin != null">
  363. AND date_format(sk.join_time,'%Y-%m-%d') >= date_format(#{joinTimeBegin},'%Y-%m-%d')
  364. </if>
  365. <if test="joinTimeEnd != null">
  366. AND date_format(sk.join_time,'%Y-%m-%d') &lt;= date_format(#{joinTimeEnd},'%Y-%m-%d')
  367. </if>
  368. <if test="ids!=null and ids.size > 0">
  369. AND sk.id IN
  370. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  371. </if>
  372. <if test="loginUserId!=null">
  373. and sk.join_user_id = #{loginUserId}
  374. </if>
  375. <!-- 数据范围过滤 -->
  376. ${params.dataScope}
  377. </where>
  378. order by sk.join_time desc
  379. </select>
  380. <select id="selectHxpStockListOut" parameterType="com.zd.chemical.domain.vo.HxpStockSearch"
  381. resultType="com.zd.chemical.domain.vo.HxpStockOutVO">
  382. SELECT sk.id,sk.out_time outTime,
  383. (SELECT cjc.join_num FROM hxp_chemical_join_cabinet cjc WHERE cjc.id = sk.join_id) joinNum,
  384. sk.chemical_name chemicalName,
  385. (SELECT cl.cas_num FROM hxp_chemical_join_cabinet cjc,hxp_chemical cl WHERE cjc.id = sk.join_id AND cjc.chemical_id = cl.id) casNum,
  386. (SELECT cc.classify_name FROM hxp_chemical_classify cc WHERE cc.id = sk.chemical_classify) classifyName,
  387. (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda,hxp_chemical_join_cabinet cjc,hxp_chemical cl
  388. WHERE cjc.id = sk.join_id AND cjc.chemical_id = cl.id and dda.dict_type = 'hxp_classifyattribute' AND FIND_IN_SET(dda.dict_value, cl.classify_attribute)) classifyAttribute,
  389. CASE
  390. WHEN sk.chemical_shape = 1 THEN CONCAT('固体', '(', sk.chemical_unit, ')')
  391. ELSE CONCAT('液体', '(', sk.chemical_unit, ')') END chemicalShape,
  392. IFNULL((SELECT CONCAT(cjc.chemical_amount, cjc.chemical_amount_unit)
  393. FROM hxp_chemical_join_cabinet cjc
  394. WHERE cjc.id = sk.join_id),
  395. '无') chemicalAmountUnit,
  396. IFNULL((SELECT CONCAT(cjc.tare, cjc.chemical_amount_unit)
  397. FROM hxp_chemical_join_cabinet cjc
  398. WHERE cjc.id = sk.join_id),
  399. '无') tareUnit,
  400. CASE WHEN sk.label_type = 1 THEN 'RFID' ELSE '二维码' END labelType,
  401. sk.tag_code tagCode,
  402. ct.cabinet_name cabinetName,
  403. CONCAT((SELECT st.name FROM lab_subject st WHERE st.id = sk.`sub_id`),
  404. '-', (SELECT dt.dept_name FROM sys_dept dt, lab_subject st WHERE dt.dept_id = st.build_id AND st.id = sk.`sub_id`),
  405. '-',(SELECT bg.name FROM lab_building bg,lab_subject st WHERE bg.id = st.floor_id AND st.id = sk.`sub_id`),
  406. '-', (SELECT slt.room FROM lab_subject_layout slt, lab_subject st WHERE slt.id = st.layout_id AND st.id = sk.`sub_id`)) posi,
  407. CONCAT(sk.out_usages-IFNULL(sk.tare,0), sk.chemical_unit) outUsages,
  408. CASE WHEN sk.status = 2 THEN '用结出库' ELSE '作废出库' END stockStatus,
  409. CONCAT(ifnull((SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = sk.out_user_id), "")) operator,
  410. CONCAT(ifnull((SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = sk.out_one_user), ""),
  411. case when sk.out_two_user is not null then '、' else '' end,
  412. ifnull((SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = sk.out_two_user), "")) verify,
  413. ll.close_lock_video
  414. FROM hxp_stock sk LEFT JOIN hxp_chemical_join_cabinet cjc ON sk.join_id = cjc.id
  415. LEFT JOIN hxp_chemical cl ON cjc.chemical_id = cl.id
  416. LEFT JOIN hxp_cabinet ct ON ct.id = cjc.cabinet_id
  417. LEFT JOIN lab_subject st ON ct.sub_id = st.id
  418. left join hxp_cabinetlock_log ll on sk.id = ll.stock_id and ll.operation_type = 2
  419. <where>
  420. and sk.status IN (2, 3)
  421. <if test="searchValue != null and searchValue != ''">
  422. and (cl.chemical_name like concat('%',#{searchValue},'%')
  423. or cl.another_name like concat('%',#{searchValue},'%')
  424. or cl.cas_num like concat('%',#{searchValue},'%')
  425. or cjc.join_num like concat('%',#{searchValue},'%')
  426. or st.name like concat('%',#{searchValue},'%')
  427. )
  428. </if>
  429. <if test="chemicalClassify != null">
  430. AND cl.chemical_classify = #{chemicalClassify}
  431. </if>
  432. <if test="classifyAttribute != null ">
  433. and FIND_IN_SET(#{classifyAttribute}, cl.classify_attribute)
  434. </if>
  435. <if test="deptId != null">
  436. AND st.dept_id = #{deptId}
  437. </if>
  438. <if test="cabinetId != null">
  439. AND cjc.cabinet_id = #{cabinetId}
  440. </if>
  441. <if test="status != null">
  442. AND sk.status = #{status}
  443. </if>
  444. <if test="labelType != null">
  445. AND sk.label_type = #{labelType}
  446. </if>
  447. <if test="outTimeBegin != null">
  448. AND date_format(sk.out_time,'%Y-%m-%d') >= date_format(#{outTimeBegin},'%Y-%m-%d')
  449. </if>
  450. <if test="outTimeEnd != null">
  451. AND date_format(sk.out_time,'%Y-%m-%d') &lt;= date_format(#{outTimeEnd},'%Y-%m-%d')
  452. </if>
  453. <if test="ids!=null and ids.size > 0">
  454. AND sk.id IN
  455. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  456. </if>
  457. <if test="loginUserId!=null">
  458. and sk.join_user_id = #{loginUserId}
  459. </if>
  460. <!-- 数据范围过滤 -->
  461. ${params.dataScope}
  462. </where>
  463. order by sk.out_time desc
  464. </select>
  465. <select id="selectByRfidCode" resultType="com.zd.chemical.domain.HxpStock">
  466. <include refid="selectHxpStockVo"/>
  467. where rfid_code = #{rfidCode} and status = 1
  468. limit 1
  469. </select>
  470. <select id="selectCountByRfidCode" resultType="java.lang.Integer">
  471. select count(1) from hxp_stock where rfid_code = #{rfidCode}
  472. <if test="id != null">
  473. and id != #{id}
  474. </if>
  475. </select>
  476. <select id="selectStockByExpired" resultType="com.zd.chemical.domain.vo.HxpStockVO">
  477. SELECT sk.id,
  478. sk.join_id,
  479. sk.chemical_num,
  480. sk.user_id,
  481. sk.chemical_name,
  482. sk.create_by,
  483. sk.cabinet_num,
  484. sk.create_time,
  485. sk.cabinet_name,
  486. sk.update_by,
  487. sk.chemical_classify,
  488. sk.update_time,
  489. sk.remark,
  490. sk.STATUS,
  491. sk.chemical_shape,
  492. sk.label_type,
  493. sk.print_code,
  494. sk.join_type,
  495. sk.join_user_id,
  496. sk.join_time,
  497. sk.expiration_time,
  498. sk.measuring_method,
  499. sk.chemical_unit,
  500. sk.verification,
  501. sk.another_name,
  502. sk.cas_num,
  503. sk.factory,
  504. sk.purity,
  505. sk.join_one_user,
  506. sk.join_two_user,
  507. sk.tag_code,
  508. sk.rfid_code,
  509. sk.usages,
  510. sk.out_user_id,
  511. sk.out_one_user,
  512. sk.out_two_user,
  513. sk.out_time,
  514. sk.out_usages,
  515. sk.sub_id,
  516. sk.tare,
  517. '1' expireStatus,
  518. st.`name` subName,
  519. st.safe_user_id as safeUserId
  520. FROM hxp_stock sk LEFT JOIN lab_subject st ON sk.sub_id = st.`id`
  521. WHERE sk.STATUS = 1 AND DATEDIFF(sk.expiration_time, NOW()) = 30
  522. UNION
  523. SELECT sk.id,
  524. sk.join_id,
  525. sk.chemical_num,
  526. sk.user_id,
  527. sk.chemical_name,
  528. sk.create_by,
  529. sk.cabinet_num,
  530. sk.create_time,
  531. sk.cabinet_name,
  532. sk.update_by,
  533. sk.chemical_classify,
  534. sk.update_time,
  535. sk.remark,
  536. sk.status,
  537. sk.chemical_shape,
  538. sk.label_type,
  539. sk.print_code,
  540. sk.join_type,
  541. sk.join_user_id,
  542. sk.join_time,
  543. sk.expiration_time,
  544. sk.measuring_method,
  545. sk.chemical_unit,
  546. sk.verification,
  547. sk.another_name,
  548. sk.cas_num,
  549. sk.factory,
  550. sk.purity,
  551. sk.join_one_user,
  552. sk.join_two_user,
  553. sk.tag_code,
  554. sk.rfid_code,
  555. sk.usages,
  556. sk.out_user_id,
  557. sk.out_one_user,
  558. sk.out_two_user,
  559. sk.out_time,
  560. sk.out_usages,
  561. sk.sub_id,
  562. sk.tare,
  563. '2' expireStatus,
  564. st.`name` subName,
  565. st.safe_user_id as safeUserId
  566. FROM hxp_stock sk LEFT JOIN lab_subject st ON sk.sub_id = st.`id`
  567. WHERE sk.status = 1 AND DATE_FORMAT(sk.expiration_time,'%Y-%m-%d') &lt; DATE_FORMAT(NOW(),'%Y-%m-%d')
  568. </select>
  569. <insert id="insertHxpStock" parameterType="com.zd.chemical.domain.HxpStock" useGeneratedKeys="true"
  570. keyProperty="id">
  571. insert into hxp_stock
  572. <trim prefix="(" suffix=")" suffixOverrides=",">
  573. <if test="joinId != null">join_id,</if>
  574. <if test="chemicalNum != null">chemical_num,</if>
  575. <if test="userId != null">user_id,</if>
  576. <if test="chemicalName != null">chemical_name,</if>
  577. <if test="createBy != null and createBy != ''">create_by,</if>
  578. <if test="cabinetNum != null">cabinet_num,</if>
  579. <if test="createTime != null">create_time,</if>
  580. <if test="cabinetName != null">cabinet_name,</if>
  581. <if test="updateBy != null and updateBy != ''">update_by,</if>
  582. <if test="chemicalClassify != null">chemical_classify,</if>
  583. <if test="updateTime != null">update_time,</if>
  584. <if test="remark != null">remark,</if>
  585. <if test="status != null">status,</if>
  586. <if test="chemicalShape != null">chemical_shape,</if>
  587. <if test="labelType != null">label_type,</if>
  588. <if test="printCode != null">print_code,</if>
  589. <if test="joinType != null">join_type,</if>
  590. <if test="joinUserId != null">join_user_id,</if>
  591. <if test="joinTime != null">join_time,</if>
  592. <if test="expirationTime != null">expiration_time,</if>
  593. <if test="measuringMethod != null">measuring_method,</if>
  594. <if test="chemicalUnit != null and chemicalUnit != ''">chemical_unit,</if>
  595. <if test="verification != null">verification,</if>
  596. <if test="anotherName != null and anotherName != ''">another_name,</if>
  597. <if test="casNum != null and casNum != ''">cas_num,</if>
  598. <if test="factory != null and factory != ''">factory,</if>
  599. <if test="purity != null and purity != ''">purity,</if>
  600. <if test="joinOneUser != null">join_one_user,</if>
  601. <if test="joinTwoUser != null">join_two_user,</if>
  602. <if test="joinVideo != null">join_video,</if>
  603. <if test="tagCode != null">tag_code,</if>
  604. <if test="rfidCode != null">rfid_code,</if>
  605. <if test="usages != null">usages,</if>
  606. <if test="outUserId != null">out_user_id,</if>
  607. <if test="outOneUser != null">out_one_user,</if>
  608. <if test="outTwoUser != null">out_two_user,</if>
  609. <if test="outTime != null">out_time,</if>
  610. <if test="outUsages != null">out_usages,</if>
  611. <if test="subId != null">sub_id,</if>
  612. <if test="tare != null">tare,</if>
  613. </trim>
  614. <trim prefix="values (" suffix=")" suffixOverrides=",">
  615. <if test="joinId != null">#{joinId},</if>
  616. <if test="chemicalNum != null">#{chemicalNum},</if>
  617. <if test="userId != null">#{userId},</if>
  618. <if test="chemicalName != null">#{chemicalName},</if>
  619. <if test="createBy != null and createBy != ''">#{createBy},</if>
  620. <if test="cabinetNum != null">#{cabinetNum},</if>
  621. <if test="createTime != null">#{createTime},</if>
  622. <if test="cabinetName != null">#{cabinetName},</if>
  623. <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
  624. <if test="chemicalClassify != null">#{chemicalClassify},</if>
  625. <if test="updateTime != null">#{updateTime},</if>
  626. <if test="remark != null">#{remark},</if>
  627. <if test="status != null">#{status},</if>
  628. <if test="chemicalShape != null">#{chemicalShape},</if>
  629. <if test="labelType != null">#{labelType},</if>
  630. <if test="printCode != null">#{printCode},</if>
  631. <if test="joinType != null">#{joinType},</if>
  632. <if test="joinUserId != null">#{joinUserId},</if>
  633. <if test="joinTime != null">#{joinTime},</if>
  634. <if test="expirationTime != null">#{expirationTime},</if>
  635. <if test="measuringMethod != null">#{measuringMethod},</if>
  636. <if test="chemicalUnit != null and chemicalUnit != ''">#{chemicalUnit},</if>
  637. <if test="verification != null">#{verification},</if>
  638. <if test="anotherName != null and anotherName != ''">#{anotherName},</if>
  639. <if test="casNum != null and casNum != ''">#{casNum},</if>
  640. <if test="factory != null and factory != ''">#{factory},</if>
  641. <if test="purity != null and purity != ''">#{purity},</if>
  642. <if test="joinOneUser != null">#{joinOneUser},</if>
  643. <if test="joinTwoUser != null">#{joinTwoUser},</if>
  644. <if test="joinVideo != null">#{joinVideo},</if>
  645. <if test="tagCode != null">#{tagCode},</if>
  646. <if test="rfidCode != null">#{rfidCode},</if>
  647. <if test="usages != null">#{usages},</if>
  648. <if test="outUserId != null">#{outUserId},</if>
  649. <if test="outOneUser != null">#{outOneUser},</if>
  650. <if test="outTwoUser != null">#{outTwoUser},</if>
  651. <if test="outTime != null">#{outTime},</if>
  652. <if test="outUsages != null">#{outUsages},</if>
  653. <if test="subId != null">#{subId},</if>
  654. <if test="tare != null">#{tare},</if>
  655. </trim>
  656. </insert>
  657. <update id="updateHxpStock" parameterType="com.zd.chemical.domain.HxpStock">
  658. update hxp_stock
  659. <trim prefix="SET" suffixOverrides=",">
  660. <if test="joinId != null">join_id = #{joinId},</if>
  661. <if test="chemicalNum != null">chemical_num = #{chemicalNum},</if>
  662. <if test="userId != null">user_id = #{userId},</if>
  663. <if test="chemicalName != null">chemical_name = #{chemicalName},</if>
  664. <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
  665. <if test="cabinetNum != null">cabinet_num = #{cabinetNum},</if>
  666. <if test="createTime != null">create_time = #{createTime},</if>
  667. <if test="cabinetName != null">cabinet_name = #{cabinetName},</if>
  668. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  669. <if test="chemicalClassify != null">chemical_classify = #{chemicalClassify},</if>
  670. <if test="updateTime != null">update_time = #{updateTime},</if>
  671. <if test="remark != null">remark = #{remark},</if>
  672. <if test="status != null">status = #{status},</if>
  673. <if test="chemicalShape != null">chemical_shape = #{chemicalShape},</if>
  674. <if test="labelType != null">label_type = #{labelType},</if>
  675. <if test="printCode != null">print_code = #{printCode},</if>
  676. <if test="joinType != null">join_type = #{joinType},</if>
  677. <if test="joinUserId != null">join_user_id = #{joinUserId},</if>
  678. <if test="joinTime != null">join_time = #{joinTime},</if>
  679. <if test="expirationTime != null">expiration_time = #{expirationTime},</if>
  680. <if test="measuringMethod != null">measuring_method = #{measuringMethod},</if>
  681. <if test="chemicalUnit != null and chemicalUnit != ''">chemical_unit = #{chemicalUnit},</if>
  682. <if test="verification != null">verification = #{verification},</if>
  683. <if test="anotherName != null and anotherName != ''">another_name = #{anotherName},</if>
  684. <if test="casNum != null and casNum != ''">cas_num = #{casNum},</if>
  685. <if test="factory != null and factory != ''">factory = #{factory},</if>
  686. <if test="purity != null and purity != ''">purity = #{purity},</if>
  687. <if test="joinOneUser != null">join_one_user = #{joinOneUser},</if>
  688. <if test="joinTwoUser != null">join_two_user = #{joinTwoUser},</if>
  689. <if test="joinVideo != null">join_video = #{joinVideo},</if>
  690. <if test="tagCode != null">tag_code = #{tagCode},</if>
  691. <if test="rfidCode != null">rfid_code = #{rfidCode},</if>
  692. <if test="usages != null">usages = #{usages},</if>
  693. <if test="outUserId != null">out_user_id = #{outUserId},</if>
  694. <if test="outOneUser != null">out_one_user = #{outOneUser},</if>
  695. <if test="outTwoUser != null">out_two_user = #{outTwoUser},</if>
  696. <if test="outTime != null">out_time = #{outTime},</if>
  697. <if test="outUsages != null">out_usages = #{outUsages},</if>
  698. <if test="subId != null">sub_id = #{subId},</if>
  699. <if test="tare != null">tare = #{tare},</if>
  700. </trim>
  701. where id = #{id}
  702. </update>
  703. <update id="updateExpiredByIds">
  704. update hxp_stock set status = 4 where id in
  705. <foreach item="id" collection="list" open="(" separator="," close=")">
  706. #{id}
  707. </foreach>
  708. </update>
  709. <delete id="deleteHxpStockById" parameterType="Long">
  710. delete
  711. from hxp_stock
  712. where id = #{id}
  713. </delete>
  714. <delete id="deleteHxpStockByIds" parameterType="String">
  715. delete from hxp_stock where id in
  716. <foreach item="id" collection="array" open="(" separator="," close=")">
  717. #{id}
  718. </foreach>
  719. </delete>
  720. </mapper>