| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zd.chemical.mapper.HxpChemicalMapper">
- <resultMap type="com.zd.chemical.domain.HxpChemical" id="HxpChemicalResult">
- <result property="id" column="id" />
- <result property="chemicalNum" column="chemical_num" />
- <result property="chemicalName" column="chemical_name" />
- <result property="chemicalClassify" column="chemical_classify" />
- <result property="classifyAttribute" column="classify_attribute" />
- <result property="chemicalShape" column="chemical_shape" />
- <result property="labelType" column="label_type" />
- <result property="measuringMethod" column="measuring_method" />
- <result property="chemicalUnit" column="chemical_unit" />
- <result property="verification" column="verification" />
- <result property="anotherName" column="another_name" />
- <result property="casNum" column="cas_num" />
- <result property="factory" column="factory" />
- <result property="purity" column="purity" />
- <result property="collectHour" column="collect_hour" />
- <result property="collectMinute" column="collect_minute" />
- <result property="joinHazardId" column="join_hazard_id" />
- <result property="userId" column="user_id" />
- <result property="createBy" column="create_by" />
- <result property="createTime" column="create_time" />
- <result property="updateBy" column="update_by" />
- <result property="updateTime" column="update_time" />
- <result property="remark" column="remark" />
- </resultMap>
- <sql id="selectHxpChemicalVo">
- 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
- </sql>
- <sql id="selectHxpChemicalListVo">
- 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
- </sql>
- <select id="selectHxpChemicalList" parameterType="com.zd.chemical.domain.vo.HxpChemicalSearch" resultType="com.zd.chemical.domain.vo.HxpChemicalVo">
- select hc.id, hc.chemical_num, hc.chemical_name, hc.chemical_classify,
- (select ccf.classify_name from hxp_chemical_classify ccf where ccf.id = hc.chemical_classify) classifyName,
- (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,
- (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,
- (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,
- case when hc.label_type=1 then 'RFID' else '二维码' end labelContent, hc.measuring_method, hc.chemical_unit,
- 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,
- (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = hc.user_id) create_by, hc.create_time,
- hc.update_by, hc.update_time, hc.remark,
- CASE WHEN hc.measuring_method = 1 THEN '重量' ELSE CASE WHEN hc.measuring_method = 2 THEN '体积' ELSE '个数' END END measuringMethodContent
- from hxp_chemical hc LEFT JOIN sys_user su ON hc.user_id = su.user_id
- <where>
- <if test="searchValue != null and searchValue != ''">
- and (hc.chemical_name like concat('%',#{searchValue},'%') or hc.another_name like concat('%',#{searchValue},'%') or hc.cas_num like concat('%',#{searchValue},'%'))
- </if>
- <if test="chemicalClassify != null "> and hc.chemical_classify = #{chemicalClassify}</if>
- <if test="classifyAttribute != null "> AND FIND_IN_SET(#{classifyAttribute}, hc.classify_attribute)</if>
- <if test="labelType != null "> and hc.label_type = #{labelType}</if>
- <if test="ids!=null and ids.size > 0">
- AND hc.id IN
- <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
- </if>
- <if test="casNum != null "> and hc.cas_num = #{casNum}</if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- </where>
- order by hc.create_time desc
- </select>
- <select id="selectHxpChemicalById" parameterType="Long" resultMap="HxpChemicalResult">
- <include refid="selectHxpChemicalVo"/>
- where id = #{id}
- </select>
- <select id="selectHxpChemicalMaxById" parameterType="String" resultMap="HxpChemicalResult">
- select id, MAX(chemical_num) chemical_num
- from hxp_chemical
- where chemical_num like concat(#{chemicalNum}, '%')
- </select>
- <insert id="insertHxpChemical" parameterType="com.zd.chemical.domain.HxpChemical" useGeneratedKeys="true" keyProperty="id">
- insert into hxp_chemical
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="chemicalNum != null">chemical_num,</if>
- <if test="chemicalName != null">chemical_name,</if>
- <if test="chemicalClassify != null">chemical_classify,</if>
- <if test="classifyAttribute != null">classify_attribute,</if>
- <if test="chemicalShape != null">chemical_shape,</if>
- <if test="labelType != null">label_type,</if>
- <if test="measuringMethod != null">measuring_method,</if>
- <if test="chemicalUnit != null">chemical_unit,</if>
- <if test="verification != null">verification,</if>
- <if test="anotherName != null">another_name,</if>
- <if test="casNum != null">cas_num,</if>
- <if test="factory != null">factory,</if>
- <if test="purity != null">purity,</if>
- <if test="collectHour != null">collect_hour,</if>
- <if test="collectMinute != null">collect_minute,</if>
- <if test="userId != null">user_id,</if>
- <if test="createBy != null">create_by,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateBy != null">update_by,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="remark != null">remark,</if>
- <if test="chemicalNamePinyin != null">chemical_name_pinyin,</if>
- <if test="chemicalNameChar != null">chemical_name_char,</if>
- <if test="anotherNamePinyin != null">another_name_pinyin,</if>
- <if test="anotherNameChar != null">another_name_char,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="chemicalNum != null">#{chemicalNum},</if>
- <if test="chemicalName != null">#{chemicalName},</if>
- <if test="chemicalClassify != null">#{chemicalClassify},</if>
- <if test="classifyAttribute != null">#{classifyAttribute},</if>
- <if test="chemicalShape != null">#{chemicalShape},</if>
- <if test="labelType != null">#{labelType},</if>
- <if test="measuringMethod != null">#{measuringMethod},</if>
- <if test="chemicalUnit != null">#{chemicalUnit},</if>
- <if test="verification != null">#{verification},</if>
- <if test="anotherName != null">#{anotherName},</if>
- <if test="casNum != null">#{casNum},</if>
- <if test="factory != null">#{factory},</if>
- <if test="purity != null">#{purity},</if>
- <if test="collectHour != null">#{collectHour},</if>
- <if test="collectMinute != null">#{collectMinute},</if>
- <if test="userId != null">#{userId},</if>
- <if test="createBy != null">#{createBy},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateBy != null">#{updateBy},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="remark != null">#{remark},</if>
- <if test="chemicalNamePinyin != null">#{chemicalNamePinyin},</if>
- <if test="chemicalNameChar != null">#{chemicalNameChar},</if>
- <if test="anotherNamePinyin != null">#{anotherNamePinyin},</if>
- <if test="anotherNameChar != null">#{anotherNameChar},</if>
- </trim>
- </insert>
- <update id="updateHxpChemical" parameterType="com.zd.chemical.domain.HxpChemical">
- update hxp_chemical
- <trim prefix="SET" suffixOverrides=",">
- <if test="chemicalNum != null">chemical_num = #{chemicalNum},</if>
- <if test="chemicalName != null">chemical_name = #{chemicalName},</if>
- <if test="chemicalClassify != null">chemical_classify = #{chemicalClassify},</if>
- <if test="classifyAttribute != null">classify_attribute = #{classifyAttribute},</if>
- <if test="chemicalShape != null">chemical_shape = #{chemicalShape},</if>
- <if test="labelType != null">label_type = #{labelType},</if>
- <if test="measuringMethod != null">measuring_method = #{measuringMethod},</if>
- <if test="chemicalUnit != null">chemical_unit = #{chemicalUnit},</if>
- <if test="verification != null">verification = #{verification},</if>
- <if test="anotherName != null">another_name = #{anotherName},</if>
- <if test="casNum != null">cas_num = #{casNum},</if>
- <if test="factory != null">factory = #{factory},</if>
- <if test="purity != null">purity = #{purity},</if>
- <if test="collectHour != null">collect_hour = #{collectHour},</if>
- <if test="collectMinute != null">collect_minute = #{collectMinute},</if>
- <if test="joinHazardId != null">join_hazard_id = #{joinHazardId},</if>
- <if test="userId != null">user_id = #{userId},</if>
- <if test="createBy != null">create_by = #{createBy},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateBy != null">update_by = #{updateBy},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- <if test="remark != null">remark = #{remark},</if>
- <if test="chemicalNamePinyin != null">chemical_name_pinyin = #{chemicalNamePinyin},</if>
- <if test="chemicalNameChar != null">chemical_name_char = #{chemicalNameChar},</if>
- <if test="anotherNamePinyin != null">another_name_pinyin = #{anotherNamePinyin},</if>
- <if test="anotherNameChar != null">another_name_char = #{anotherNameChar},</if>
- </trim>
- where id = #{id}
- </update>
- <update id="clearHxpChemicalByJoinHazard" parameterType="com.zd.chemical.domain.HxpChemical">
- update hxp_chemical set
- join_hazard_id = NULL
- where id = #{id}
- </update>
- <delete id="deleteHxpChemicalById" parameterType="Long">
- delete from hxp_chemical where id = #{id}
- </delete>
- <delete id="deleteHxpChemicalByIds" parameterType="String">
- delete from hxp_chemical where id in
- <foreach item="id" collection="array" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- <select id="chemicalUsageCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalVo">
- SELECT
- (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=1) chemicalUsableNum,
- (SELECT IFNULL(COUNT(1),0) FROM hxp_cabinet ct WHERE ct.cabinet_status=1) cabinetNum,
- (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=2) chemicalOutNum,
- (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=3) chemicalCancelNum,
- (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)<=NOW()
- AND cjc.expire_time>NOW()
- ) overdueTime
- FROM DUAL
- </select>
- <select id="chemicalUnusualCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUnusualVo">
- SELECT
- (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd WHERE rd.use_status = 1) toBeReturned,
- (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd WHERE rd.use_status = 2) overtimeReturn,
- (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,
- (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,
- (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,
- (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
- FROM DUAL
- </select>
- <select id="chemicalUsagesCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUsagesVo">
- SELECT CONCAT(cl.`chemical_name`,'使用重量',CONCAT(SUM(sk.usages-sk.out_usages),cl.chemical_unit)) chemicalUsages, SUM(sk.usages-sk.out_usages)usages,
- (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = cl.user_id) adminUser,
- (SELECT cc.classify_name FROM hxp_chemical_classify cc WHERE cc.id = cl.chemical_classify) classifyName,
- (SELECT cc.hazard_level FROM hxp_chemical_classify cc WHERE cc.id = cl.chemical_classify) classifyLevel
- FROM hxp_stock sk
- INNER JOIN hxp_chemical_join_cabinet cjc ON sk.`join_id` = cjc.`id`
- INNER JOIN hxp_chemical cl ON cjc.`chemical_id` = cl.`id`
- GROUP BY cl.`id` ORDER BY usages DESC LIMIT 6
- </select>
- <select id="chemicalClassifyMix" parameterType="com.zd.chemical.domain.HxpChemical" resultType="java.util.LinkedHashMap">
- SELECT x1.dict_label classifyAttribute,CONCAT(CASE WHEN x2.chemical_name IS NULL THEN 0 ELSE COUNT(0) END,'') chemicalMix FROM (
- select xx1.* from(SELECT dda.`dict_label`,dda.dict_value
- FROM sys_dict_data dda
- WHERE dda.dict_type = 'hxp_classifyattribute'
- ORDER BY dda.`dict_sort`
- )xx1
- union all
- select '其他' dict_label,99 dict_value from dual
- )x1
- LEFT JOIN
- (
- 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 (
- SELECT cl.chemical_name,cl.classify_attribute
- FROM hxp_stock sk
- INNER JOIN hxp_chemical_join_cabinet cjc ON sk.join_id= cjc.id
- INNER JOIN hxp_chemical cl ON cjc.`chemical_id` = cl.`id`
- GROUP BY cl.chemical_num
- )xx
- )x2 ON FIND_IN_SET( x1.dict_value, x2.classify_attribute )
- GROUP BY x1.dict_value
- </select>
- <select id="stockTotal" parameterType="com.zd.chemical.domain.HxpChemical" resultType="java.lang.Long">
- SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk WHERE sk.status=1 OR sk.status=4
- </select>
- <select id="joinOutCount" parameterType="com.zd.chemical.domain.HxpStock" resultType="java.util.LinkedHashMap">
- SELECT x1.*,CASE WHEN sk.id IS NULL THEN 0 ELSE COUNT(1) END stockNum FROM (
- SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 6 DAY),'%Y-%m-%d') nowData FROM DUAL
- UNION ALL
- SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 5 DAY),'%Y-%m-%d') FROM DUAL
- UNION ALL
- SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 4 DAY),'%Y-%m-%d') FROM DUAL
- UNION ALL
- SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 3 DAY),'%Y-%m-%d') FROM DUAL
- UNION ALL
- SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 2 DAY),'%Y-%m-%d') FROM DUAL
- UNION ALL
- SELECT DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d') FROM DUAL
- UNION ALL
- SELECT DATE_FORMAT(NOW(),'%Y-%m-%d') FROM DUAL
- )x1 LEFT JOIN hxp_stock sk
- <if test="status == 1">
- ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.join_time,'%Y-%m-%d') AND (sk.status=#{status} or sk.status=4)
- </if>
- <if test="status == 2">
- ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.out_time,'%Y-%m-%d') AND (sk.status=#{status} or sk.status=3)
- </if>
- GROUP BY x1.nowData
- </select>
- </mapper>
|