HxpChemicalJoinCabinetMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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.HxpChemicalJoinCabinetMapper">
  6. <resultMap type="com.zd.chemical.domain.HxpChemicalJoinCabinet" id="HxpChemicalJoinCabinetResult">
  7. <result property="id" column="id"/>
  8. <result property="joinNum" column="join_num"/>
  9. <result property="subId" column="sub_id"/>
  10. <result property="chemicalId" column="chemical_id"/>
  11. <result property="cabinetId" column="cabinet_id"/>
  12. <result property="chemicalAmount" column="chemical_amount"/>
  13. <result property="chemicalAmountUnit" column="chemical_amount_unit"/>
  14. <result property="expireTime" column="expire_time"/>
  15. <result property="userId" column="user_id"/>
  16. <result property="createBy" column="create_by"/>
  17. <result property="createTime" column="create_time"/>
  18. <result property="status" column="status"/>
  19. </resultMap>
  20. <sql id="selectHxpChemicalJoinCabinetVo">
  21. select id,join_num,sub_id, chemical_id, cabinet_id,chemical_amount,chemical_amount_unit,expire_time, user_id, create_by, create_time,status from hxp_chemical_join_cabinet
  22. </sql>
  23. <sql id="selectHxpChemicalJoinCabinetListVo">
  24. select t.id,t.join_num,t.sub_id, t.chemical_id, t.cabinet_id,t.chemical_amount,t.chemical_amount_unit,t.expire_time, t.user_id, t.create_by, t.create_time,t.status from hxp_chemical_join_cabinet as t
  25. </sql>
  26. <select id="selectHxpChemicalJoinCabinetList" parameterType="com.zd.chemical.domain.vo.HxpChemicalJoinCabinetSearch" resultType="com.zd.chemical.domain.vo.HxpChemicalJoinCabinetListVo">
  27. SELECT cjc.`id`,cjc.`join_num` joinNum,cl.chemical_name chemicalName,IFNULL(CONCAT(cjc.chemical_amount,cjc.`chemical_amount_unit`),'') chemicalAmountUnit,cjc.expire_time expireTime,ct.cabinet_name cabinetName,
  28. (SELECT he.name FROM lab_hardware he WHERE he.id = cjc.cabinetlock_id) lockName,
  29. CONCAT((SELECT st.name FROM lab_subject st WHERE st.id = ct.`sub_id`),'-',(SELECT dt.dept_name FROM sys_dept dt,lab_subject st WHERE dt.dept_id = st.build_id AND st.id = ct.`sub_id`),
  30. '-',(SELECT bg.name FROM lab_building bg,lab_subject st WHERE bg.id = st.floor_id AND st.id = ct.`sub_id`),
  31. IFNULL(CONCAT('-',(SELECT slt.room_num room FROM lab_build_floor_layout slt,lab_subject st WHERE slt.sub_id = st.id AND st.id = ct.`sub_id`)),'')) posi,
  32. ct.cabinet_num cabinetNum,
  33. CASE WHEN cjc.status=0 THEN '未入库' ELSE CASE WHEN sk.status=2 OR sk.status=3 THEN '已出库' ELSE CASE WHEN cjc.status=1 THEN '已入库' ELSE
  34. case when sk.status=4 then '已过期' else '未知'
  35. end
  36. END
  37. END
  38. END cabinetStatus,
  39. cjc.create_time createTime,
  40. (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = cjc.user_id) createBy,cjc.status,
  41. IFNULL(CONCAT(cjc.tare,cl.chemical_unit),'') tare
  42. FROM hxp_chemical_join_cabinet cjc LEFT JOIN hxp_cabinet ct ON ct.id = cjc.cabinet_id
  43. LEFT JOIN hxp_chemical cl ON cjc.chemical_id = cl.id
  44. LEFT JOIN lab_subject st ON ct.sub_id = st.id
  45. LEFT JOIN hxp_stock sk ON sk.join_id = cjc.id
  46. <where>
  47. <if test="chemicalId != null "> and cjc.chemical_id= #{chemicalId}</if>
  48. <if test="searchValue != null ">
  49. and (
  50. cl.chemical_name like concat('%',#{searchValue},'%') or
  51. cl.another_name like concat('%',#{searchValue},'%') or
  52. cl.cas_num like concat('%',#{searchValue},'%') or
  53. cjc.join_num like concat('%',#{searchValue},'%') or
  54. st.name like concat('%',#{searchValue},'%')
  55. )
  56. </if>
  57. <if test="status != null ">
  58. <if test="status == 0 ">
  59. and cjc.status= #{status}
  60. </if>
  61. <if test="status == 1">
  62. and sk.status= #{status}
  63. </if>
  64. <if test="status == 2 ">
  65. and (sk.status=2 OR sk.status=3)
  66. </if>
  67. <if test="status == 4">
  68. and sk.status= #{status}
  69. </if>
  70. </if>
  71. <if test="userId != null">
  72. and cjc.user_id = #{userId}
  73. </if>
  74. </where>
  75. order by cjc.create_time desc
  76. </select>
  77. <select id="selectHxpChemicalJoinCabinetById" parameterType="Long" resultMap="HxpChemicalJoinCabinetResult">
  78. <include refid="selectHxpChemicalJoinCabinetVo"/>
  79. where id = #{id}
  80. </select>
  81. <select id="queryUserNameBySafeUserId" parameterType="string" resultType="string">
  82. SELECT GROUP_CONCAT(nick_name) safeUserName FROM sys_user WHERE FIND_IN_SET(user_id, #{safeUserId})
  83. </select>
  84. <select id="queryUserPhoneBySafeUserId" parameterType="string" resultType="string">
  85. SELECT GROUP_CONCAT(phonenumber) safeUserPhone FROM sys_user WHERE FIND_IN_SET(user_id, #{safeUserId})
  86. </select>
  87. <select id="selectChemicalVoList" resultType="com.zd.chemical.domain.vo.AioChemicalVo">
  88. select
  89. che.chemical_num,
  90. che.chemical_name,
  91. che.chemical_classify,
  92. che.chemical_shape,
  93. che.measuring_method,
  94. che.chemical_unit,
  95. che.verification,
  96. che.another_name,
  97. che.cas_num,
  98. che.factory,
  99. che.purity,
  100. che.collect_hour,
  101. che.collect_minute,
  102. che.join_hazard_id as hazardId,
  103. jo.id joinId,
  104. jo.join_num,
  105. jo.sub_id,
  106. jo.chemical_id,
  107. jo.cabinet_id,
  108. jo.chemical_amount,
  109. jo.chemical_amount_unit,
  110. jo.expire_time,
  111. cab.cabinet_num,
  112. cab.cabinet_name,
  113. cab.cabinet_status,
  114. s.safe_user_id,
  115. jo.tare,
  116. cc.label_type,
  117. cc.print_code,
  118. (select ccf.classify_name from hxp_chemical_classify ccf where ccf.id = che.chemical_classify) classifyName,
  119. (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'hxp_classifyattribute' AND
  120. FIND_IN_SET(dda.dict_value, (select classify_attribute from hxp_chemical where id = jo.chemical_id
  121. ))) classifyAttribute
  122. from hxp_chemical_join_cabinet jo
  123. inner join hxp_cabinet cab on cab.id = jo.cabinet_id and cab.sub_id = jo.sub_id
  124. inner join hxp_chemical che on che.id = jo.chemical_id
  125. inner join lab_subject s on jo.sub_id = s.id
  126. left join hxp_classify_config cc on che.chemical_classify = cc.join_classify_id
  127. <where>
  128. jo.sub_id = #{subId} and jo.status = 0
  129. <if test="cabinetId != null">
  130. and jo.cabinet_id = #{cabinetId}
  131. </if>
  132. <if test="labelType != null">
  133. and che.label_type = #{labelType}
  134. </if>
  135. <if test="chemicalName != null and chemicalName != ''">
  136. and (
  137. che.chemical_name like concat("%", #{chemicalName}, "%")
  138. or che.another_name like concat("%", #{chemicalName}, "%")
  139. or che.chemical_name_char like concat(#{chemicalName}, "%")
  140. or che.another_name_char like concat(#{chemicalName}, "%")
  141. )
  142. </if>
  143. </where>
  144. order by che.chemical_name , jo.create_time desc
  145. </select>
  146. <select id="selByChemical" parameterType="Long" resultMap="HxpChemicalJoinCabinetResult">
  147. <include refid="selectHxpChemicalJoinCabinetVo"/>
  148. where chemical_id = #{id}
  149. </select>
  150. <select id="selectChemicalListById" parameterType="com.zd.chemical.domain.HxpChemicalJoinCabinet" resultType="com.zd.chemical.domain.HxpChemicalJoinCabinet">
  151. SELECT
  152. jo.id joinId,
  153. jo.join_num,
  154. jo.sub_id,
  155. jo.chemical_id,
  156. jo.cabinet_id,
  157. jo.chemical_amount,
  158. jo.chemical_amount_unit,
  159. jo.expire_time
  160. FROM hxp_chemical_join_cabinet jo
  161. INNER JOIN hxp_stock sk ON jo.id = sk.`join_id`
  162. <where>
  163. <if test="id != null">
  164. and jo.`id` = #{id}
  165. </if>
  166. </where>
  167. </select>
  168. <insert id="insertHxpChemicalJoinCabinet" parameterType="com.zd.chemical.domain.HxpChemicalJoinCabinet" useGeneratedKeys="true" keyProperty="id">
  169. insert into hxp_chemical_join_cabinet
  170. <trim prefix="(" suffix=")" suffixOverrides=",">
  171. <if test="joinNum != null">join_num,</if>
  172. <if test="subId != null">sub_id,</if>
  173. <if test="chemicalId != null">chemical_id,</if>
  174. <if test="cabinetId != null">cabinet_id,</if>
  175. <if test="cabinetlockId != null">cabinetlock_id,</if>
  176. <if test="chemicalAmount != null">chemical_amount,</if>
  177. <if test="chemicalAmountUnit != null">chemical_amount_unit,</if>
  178. <if test="expireTime != null">expire_time,</if>
  179. <if test="userId != null">user_id,</if>
  180. <if test="createBy != null">create_by,</if>
  181. <if test="createTime != null">create_time,</if>
  182. <if test="tare != null">tare,</if>
  183. </trim>
  184. <trim prefix="values (" suffix=")" suffixOverrides=",">
  185. <if test="joinNum != null">#{joinNum},</if>
  186. <if test="subId != null">#{subId},</if>
  187. <if test="chemicalId != null">#{chemicalId},</if>
  188. <if test="cabinetId != null">#{cabinetId},</if>
  189. <if test="cabinetlockId != null">#{cabinetlockId},</if>
  190. <if test="chemicalAmount != null">#{chemicalAmount},</if>
  191. <if test="chemicalAmountUnit != null">#{chemicalAmountUnit},</if>
  192. <if test="expireTime != null">#{expireTime},</if>
  193. <if test="userId != null">#{userId},</if>
  194. <if test="createBy != null">#{createBy},</if>
  195. <if test="createTime != null">#{createTime},</if>
  196. <if test="tare != null">#{tare},</if>
  197. </trim>
  198. </insert>
  199. <update id="updateHxpChemicalJoinCabinet" parameterType="com.zd.chemical.domain.HxpChemicalJoinCabinet">
  200. update hxp_chemical_join_cabinet
  201. <trim prefix="SET" suffixOverrides=",">
  202. <if test="chemicalId != null">chemical_id = #{chemicalId},</if>
  203. <if test="cabinetId != null">cabinet_id = #{cabinetId},</if>
  204. <if test="userId != null">user_id = #{userId},</if>
  205. <if test="createBy != null">create_by = #{createBy},</if>
  206. <if test="createTime != null">create_time = #{createTime},</if>
  207. <if test="status != null">status = #{status},</if>
  208. </trim>
  209. where id = #{id}
  210. </update>
  211. <update id="updateExpiredByIds">
  212. update hxp_chemical_join_cabinet set status = 4 where id in
  213. <foreach item="id" collection="list" open="(" separator="," close=")">
  214. #{id}
  215. </foreach>
  216. </update>
  217. <update id="updateChemicalJoinCabinetByExpired">
  218. update hxp_chemical_join_cabinet set status = 4 where status != 2 and status != 4 and date_format(expire_time,'%Y-%m-%d') &lt; date_format(now(),'%Y-%m-%d')
  219. </update>
  220. <delete id="deleteHxpChemicalJoinCabinetById" parameterType="Long">
  221. delete from hxp_chemical_join_cabinet where id = #{id}
  222. </delete>
  223. <delete id="deleteHxpChemicalJoinCabinetByIds" parameterType="String">
  224. delete from hxp_chemical_join_cabinet where id in
  225. <foreach item="id" collection="array" open="(" separator="," close=")">
  226. #{id}
  227. </foreach>
  228. </delete>
  229. <delete id="delByChemical" parameterType="String">
  230. delete from hxp_chemical_join_cabinet where chemical_id in
  231. <foreach item="id" collection="array" open="(" separator="," close=")">
  232. #{id}
  233. </foreach>
  234. </delete>
  235. </mapper>