HxpChemicalMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.HxpChemicalMapper">
  6. <resultMap type="com.zd.chemical.domain.HxpChemical" id="HxpChemicalResult">
  7. <result property="id" column="id" />
  8. <result property="chemicalNum" column="chemical_num" />
  9. <result property="chemicalName" column="chemical_name" />
  10. <result property="chemicalClassify" column="chemical_classify" />
  11. <result property="classifyAttribute" column="classify_attribute" />
  12. <result property="chemicalShape" column="chemical_shape" />
  13. <result property="labelType" column="label_type" />
  14. <result property="measuringMethod" column="measuring_method" />
  15. <result property="chemicalUnit" column="chemical_unit" />
  16. <result property="verification" column="verification" />
  17. <result property="anotherName" column="another_name" />
  18. <result property="casNum" column="cas_num" />
  19. <result property="factory" column="factory" />
  20. <result property="purity" column="purity" />
  21. <result property="collectHour" column="collect_hour" />
  22. <result property="collectMinute" column="collect_minute" />
  23. <result property="joinHazardId" column="join_hazard_id" />
  24. <result property="userId" column="user_id" />
  25. <result property="createBy" column="create_by" />
  26. <result property="createTime" column="create_time" />
  27. <result property="updateBy" column="update_by" />
  28. <result property="updateTime" column="update_time" />
  29. <result property="remark" column="remark" />
  30. </resultMap>
  31. <sql id="selectHxpChemicalVo">
  32. select id, chemical_num, chemical_name, chemical_classify, classify_attribute, chemical_shape, label_type, measuring_method, chemical_unit, verification, another_name, cas_num, factory, purity, collect_hour, collect_minute, user_id, create_by, create_time, update_by, update_time, remark from hxp_chemical
  33. </sql>
  34. <sql id="selectHxpChemicalListVo">
  35. select t.id, t.chemical_num, t.chemical_name, t.chemical_classify, classify_attribute, t.chemical_shape, t.label_type, t.measuring_method, t.chemical_unit, t.verification, t.another_name, t.cas_num, t.factory, t.purity, t.collect_hour, t.collect_minute, t.user_id, t.create_by, t.create_time, t.update_by, t.update_time, t.remark from hxp_chemical as t
  36. </sql>
  37. <select id="selectHxpChemicalList" parameterType="com.zd.chemical.domain.vo.HxpChemicalSearch" resultType="com.zd.chemical.domain.vo.HxpChemicalVo">
  38. select hc.id, hc.chemical_num, hc.chemical_name, hc.chemical_classify,
  39. (select ccf.classify_name from hxp_chemical_classify ccf where ccf.id = hc.chemical_classify) classifyName,
  40. (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'hxp_classifyattribute' AND FIND_IN_SET(dda.dict_value, hc.classify_attribute)) classifyAttribute,
  41. (SELECT GROUP_CONCAT(CONCAT(dda.dict_label,'(',hc.chemical_unit,')')) FROM sys_dict_data dda WHERE dda.dict_type = 'chemical_shape' AND dda.dict_value = hc.chemical_shape) chemicalShapeInfo,
  42. (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'chemical_shape' AND dda.dict_value = hc.chemical_shape) chemicalShapeInfo2,
  43. case when hc.label_type=1 then 'RFID' else '二维码' end labelContent, hc.measuring_method, hc.chemical_unit,
  44. case when hc.verification=1 then '单人验证' else '双人双卡' end verificationContent, hc.another_name, hc.cas_num, hc.factory, hc.purity, hc.collect_hour, hc.collect_minute, hc.user_id,
  45. (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = hc.user_id) create_by, hc.create_time,
  46. hc.update_by, hc.update_time, hc.remark,
  47. CASE WHEN hc.measuring_method = 1 THEN '重量' ELSE CASE WHEN hc.measuring_method = 2 THEN '体积' ELSE '个数' END END measuringMethodContent
  48. from hxp_chemical hc LEFT JOIN sys_user su ON hc.user_id = su.user_id
  49. <where>
  50. <if test="searchValue != null and searchValue != ''">
  51. and (hc.chemical_name like concat('%',#{searchValue},'%') or hc.another_name like concat('%',#{searchValue},'%') or hc.cas_num like concat('%',#{searchValue},'%'))
  52. </if>
  53. <if test="chemicalClassify != null "> and hc.chemical_classify = #{chemicalClassify}</if>
  54. <if test="classifyAttribute != null "> AND FIND_IN_SET(#{classifyAttribute}, hc.classify_attribute)</if>
  55. <if test="labelType != null "> and hc.label_type = #{labelType}</if>
  56. <if test="ids!=null and ids.size > 0">
  57. AND hc.id IN
  58. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  59. </if>
  60. <if test="casNum != null "> and hc.cas_num = #{casNum}</if>
  61. <!-- 数据范围过滤 -->
  62. ${params.dataScope}
  63. </where>
  64. order by hc.create_time desc
  65. </select>
  66. <select id="selectHxpChemicalById" parameterType="Long" resultMap="HxpChemicalResult">
  67. <include refid="selectHxpChemicalVo"/>
  68. where id = #{id}
  69. </select>
  70. <select id="selectHxpChemicalMaxById" parameterType="String" resultMap="HxpChemicalResult">
  71. select id, MAX(chemical_num) chemical_num
  72. from hxp_chemical
  73. where chemical_num like concat(#{chemicalNum}, '%')
  74. </select>
  75. <insert id="insertHxpChemical" parameterType="com.zd.chemical.domain.HxpChemical" useGeneratedKeys="true" keyProperty="id">
  76. insert into hxp_chemical
  77. <trim prefix="(" suffix=")" suffixOverrides=",">
  78. <if test="chemicalNum != null">chemical_num,</if>
  79. <if test="chemicalName != null">chemical_name,</if>
  80. <if test="chemicalClassify != null">chemical_classify,</if>
  81. <if test="classifyAttribute != null">classify_attribute,</if>
  82. <if test="chemicalShape != null">chemical_shape,</if>
  83. <if test="labelType != null">label_type,</if>
  84. <if test="measuringMethod != null">measuring_method,</if>
  85. <if test="chemicalUnit != null">chemical_unit,</if>
  86. <if test="verification != null">verification,</if>
  87. <if test="anotherName != null">another_name,</if>
  88. <if test="casNum != null">cas_num,</if>
  89. <if test="factory != null">factory,</if>
  90. <if test="purity != null">purity,</if>
  91. <if test="collectHour != null">collect_hour,</if>
  92. <if test="collectMinute != null">collect_minute,</if>
  93. <if test="userId != null">user_id,</if>
  94. <if test="createBy != null">create_by,</if>
  95. <if test="createTime != null">create_time,</if>
  96. <if test="updateBy != null">update_by,</if>
  97. <if test="updateTime != null">update_time,</if>
  98. <if test="remark != null">remark,</if>
  99. <if test="chemicalNamePinyin != null">chemical_name_pinyin,</if>
  100. <if test="chemicalNameChar != null">chemical_name_char,</if>
  101. <if test="anotherNamePinyin != null">another_name_pinyin,</if>
  102. <if test="anotherNameChar != null">another_name_char,</if>
  103. </trim>
  104. <trim prefix="values (" suffix=")" suffixOverrides=",">
  105. <if test="chemicalNum != null">#{chemicalNum},</if>
  106. <if test="chemicalName != null">#{chemicalName},</if>
  107. <if test="chemicalClassify != null">#{chemicalClassify},</if>
  108. <if test="classifyAttribute != null">#{classifyAttribute},</if>
  109. <if test="chemicalShape != null">#{chemicalShape},</if>
  110. <if test="labelType != null">#{labelType},</if>
  111. <if test="measuringMethod != null">#{measuringMethod},</if>
  112. <if test="chemicalUnit != null">#{chemicalUnit},</if>
  113. <if test="verification != null">#{verification},</if>
  114. <if test="anotherName != null">#{anotherName},</if>
  115. <if test="casNum != null">#{casNum},</if>
  116. <if test="factory != null">#{factory},</if>
  117. <if test="purity != null">#{purity},</if>
  118. <if test="collectHour != null">#{collectHour},</if>
  119. <if test="collectMinute != null">#{collectMinute},</if>
  120. <if test="userId != null">#{userId},</if>
  121. <if test="createBy != null">#{createBy},</if>
  122. <if test="createTime != null">#{createTime},</if>
  123. <if test="updateBy != null">#{updateBy},</if>
  124. <if test="updateTime != null">#{updateTime},</if>
  125. <if test="remark != null">#{remark},</if>
  126. <if test="chemicalNamePinyin != null">#{chemicalNamePinyin},</if>
  127. <if test="chemicalNameChar != null">#{chemicalNameChar},</if>
  128. <if test="anotherNamePinyin != null">#{anotherNamePinyin},</if>
  129. <if test="anotherNameChar != null">#{anotherNameChar},</if>
  130. </trim>
  131. </insert>
  132. <update id="updateHxpChemical" parameterType="com.zd.chemical.domain.HxpChemical">
  133. update hxp_chemical
  134. <trim prefix="SET" suffixOverrides=",">
  135. <if test="chemicalNum != null">chemical_num = #{chemicalNum},</if>
  136. <if test="chemicalName != null">chemical_name = #{chemicalName},</if>
  137. <if test="chemicalClassify != null">chemical_classify = #{chemicalClassify},</if>
  138. <if test="classifyAttribute != null">classify_attribute = #{classifyAttribute},</if>
  139. <if test="chemicalShape != null">chemical_shape = #{chemicalShape},</if>
  140. <if test="labelType != null">label_type = #{labelType},</if>
  141. <if test="measuringMethod != null">measuring_method = #{measuringMethod},</if>
  142. <if test="chemicalUnit != null">chemical_unit = #{chemicalUnit},</if>
  143. <if test="verification != null">verification = #{verification},</if>
  144. <if test="anotherName != null">another_name = #{anotherName},</if>
  145. <if test="casNum != null">cas_num = #{casNum},</if>
  146. <if test="factory != null">factory = #{factory},</if>
  147. <if test="purity != null">purity = #{purity},</if>
  148. <if test="collectHour != null">collect_hour = #{collectHour},</if>
  149. <if test="collectMinute != null">collect_minute = #{collectMinute},</if>
  150. <if test="joinHazardId != null">join_hazard_id = #{joinHazardId},</if>
  151. <if test="userId != null">user_id = #{userId},</if>
  152. <if test="createBy != null">create_by = #{createBy},</if>
  153. <if test="createTime != null">create_time = #{createTime},</if>
  154. <if test="updateBy != null">update_by = #{updateBy},</if>
  155. <if test="updateTime != null">update_time = #{updateTime},</if>
  156. <if test="remark != null">remark = #{remark},</if>
  157. <if test="chemicalNamePinyin != null">chemical_name_pinyin = #{chemicalNamePinyin},</if>
  158. <if test="chemicalNameChar != null">chemical_name_char = #{chemicalNameChar},</if>
  159. <if test="anotherNamePinyin != null">another_name_pinyin = #{anotherNamePinyin},</if>
  160. <if test="anotherNameChar != null">another_name_char = #{anotherNameChar},</if>
  161. </trim>
  162. where id = #{id}
  163. </update>
  164. <update id="clearHxpChemicalByJoinHazard" parameterType="com.zd.chemical.domain.HxpChemical">
  165. update hxp_chemical set
  166. join_hazard_id = NULL
  167. where id = #{id}
  168. </update>
  169. <delete id="deleteHxpChemicalById" parameterType="Long">
  170. delete from hxp_chemical where id = #{id}
  171. </delete>
  172. <delete id="deleteHxpChemicalByIds" parameterType="String">
  173. delete from hxp_chemical where id in
  174. <foreach item="id" collection="array" open="(" separator="," close=")">
  175. #{id}
  176. </foreach>
  177. </delete>
  178. <select id="chemicalUsageCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalVo">
  179. SELECT
  180. (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=1) chemicalUsableNum,
  181. (SELECT IFNULL(COUNT(1),0) FROM hxp_cabinet ct WHERE ct.cabinet_status=1) cabinetNum,
  182. (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=2) chemicalOutNum,
  183. (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=3) chemicalCancelNum,
  184. (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk INNER JOIN hxp_chemical_join_cabinet cjc ON sk.join_id = cjc.id WHERE DATE_SUB(cjc.expire_time, INTERVAL 3 DAY)&lt;=NOW()
  185. AND cjc.expire_time>NOW()
  186. ) overdueTime
  187. FROM DUAL
  188. </select>
  189. <select id="chemicalUnusualCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUnusualVo">
  190. SELECT
  191. (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd WHERE rd.use_status = 1) toBeReturned,
  192. (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd WHERE rd.use_status = 2) overtimeReturn,
  193. (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd WHERE DATE_FORMAT(rd.collect_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')) todayCollect,
  194. (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd WHERE rd.use_status = 0 AND DATE_FORMAT(rd.collect_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')) todayReturn,
  195. (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=2 AND DATE_FORMAT(sk.out_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')) todayOutNum,
  196. (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=3 AND DATE_FORMAT(sk.out_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')) todayCancelNum
  197. FROM DUAL
  198. </select>
  199. <select id="chemicalUsagesCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUsagesVo">
  200. SELECT CONCAT(cl.`chemical_name`,'使用重量',CONCAT(SUM(sk.usages-sk.out_usages),cl.chemical_unit)) chemicalUsages, SUM(sk.usages-sk.out_usages)usages,
  201. (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = cl.user_id) adminUser,
  202. (SELECT cc.classify_name FROM hxp_chemical_classify cc WHERE cc.id = cl.chemical_classify) classifyName,
  203. (SELECT cc.hazard_level FROM hxp_chemical_classify cc WHERE cc.id = cl.chemical_classify) classifyLevel
  204. FROM hxp_stock sk
  205. INNER JOIN hxp_chemical_join_cabinet cjc ON sk.`join_id` = cjc.`id`
  206. INNER JOIN hxp_chemical cl ON cjc.`chemical_id` = cl.`id`
  207. GROUP BY cl.`id` ORDER BY usages DESC LIMIT 6
  208. </select>
  209. <select id="chemicalClassifyMix" parameterType="com.zd.chemical.domain.HxpChemical" resultType="java.util.LinkedHashMap">
  210. SELECT x1.dict_label classifyAttribute,CONCAT(CASE WHEN x2.chemical_name IS NULL THEN 0 ELSE COUNT(0) END,'') chemicalMix FROM (
  211. select xx1.* from(SELECT dda.`dict_label`,dda.dict_value
  212. FROM sys_dict_data dda
  213. WHERE dda.dict_type = 'hxp_classifyattribute'
  214. ORDER BY dda.`dict_sort`
  215. )xx1
  216. union all
  217. select '其他' dict_label,99 dict_value from dual
  218. )x1
  219. LEFT JOIN
  220. (
  221. select xx.chemical_name,case when xx.classify_attribute='' or xx.classify_attribute is null then 99 else xx.classify_attribute end classify_attribute from (
  222. SELECT cl.chemical_name,cl.classify_attribute
  223. FROM hxp_stock sk
  224. INNER JOIN hxp_chemical_join_cabinet cjc ON sk.join_id= cjc.id
  225. INNER JOIN hxp_chemical cl ON cjc.`chemical_id` = cl.`id`
  226. GROUP BY cl.chemical_num
  227. )xx
  228. )x2 ON FIND_IN_SET( x1.dict_value, x2.classify_attribute )
  229. GROUP BY x1.dict_value
  230. </select>
  231. <select id="stockTotal" parameterType="com.zd.chemical.domain.HxpChemical" resultType="java.lang.Long">
  232. SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=1 OR sk.status=4
  233. </select>
  234. <select id="joinOutCount" parameterType="com.zd.chemical.domain.HxpStock" resultType="java.util.LinkedHashMap">
  235. SELECT x1.*,CASE WHEN sk.id IS NULL THEN 0 ELSE COUNT(1) END stockNum FROM (
  236. SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 6 DAY),'%Y-%m-%d') nowData FROM DUAL
  237. UNION ALL
  238. SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 5 DAY),'%Y-%m-%d') FROM DUAL
  239. UNION ALL
  240. SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 4 DAY),'%Y-%m-%d') FROM DUAL
  241. UNION ALL
  242. SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 3 DAY),'%Y-%m-%d') FROM DUAL
  243. UNION ALL
  244. SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 2 DAY),'%Y-%m-%d') FROM DUAL
  245. UNION ALL
  246. SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d') FROM DUAL
  247. UNION ALL
  248. SELECT DATE_FORMAT(NOW(),'%Y-%m-%d') FROM DUAL
  249. )x1 LEFT JOIN hxp_stock sk
  250. <if test="status == 1">
  251. ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.join_time,'%Y-%m-%d') AND (sk.status=#{status} or sk.status=4)
  252. </if>
  253. <if test="status == 2">
  254. ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.out_time,'%Y-%m-%d') AND (sk.status=#{status} or sk.status=3)
  255. </if>
  256. GROUP BY x1.nowData
  257. </select>
  258. </mapper>