HxpStockMapper.xml 39 KB

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