<?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.gkhy.hazmat.system.mapper.HzHazmatMapper">
|
<resultMap type="com.gkhy.hazmat.system.domain.HzHazmat" id="HzHazmatResult">
|
<result property="id" column="id" />
|
<result property="basicId" column="basic_id" />
|
<result property="warehouseId" column="warehouse_id" />
|
<result property="remaining" column="remaining" />
|
<result property="state" column="state" />
|
<result property="code" column="code" />
|
<result property="delFlag" column="del_flag" />
|
<result property="companyId" column="company_id" />
|
<result property="version" column="version" />
|
<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" />
|
<result property="warehouseName" column="warehouse_name" />
|
<association property="hazmatBasic" javaType="com.gkhy.hazmat.system.domain.HzHazmatBasic" resultMap="hazmatBasicResult" />
|
</resultMap>
|
|
|
<resultMap type="com.gkhy.hazmat.system.domain.HzHazmatBasic" id="hazmatBasicResult">
|
<result property="id" column="basic_id" />
|
<result property="name" column="basic_name" />
|
<result property="cas" column="basic_cas" />
|
<result property="hazmatType" column="basic_hazmat_type" />
|
<result property="hazmatCharacter" column="basic_hazmat_character" />
|
<result property="supplier" column="basic_supplier" />
|
<result property="minPackage" column="basic_min_package" />
|
<result property="manufacturer" column="basic_manufacturer" />
|
<result property="metering" column="basic_metering" />
|
<result property="unit" column="basic_unit" />
|
<result property="productSn" column="product_sn" />
|
</resultMap>
|
|
<sql id="selectHazmatVo">
|
select a.id, a.basic_id, a.warehouse_id, a.code,a.remaining, a.state,a.company_id,a.version, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
|
b.id as basic_id,b.name as basic_name,b.cas as basic_cas,b.hazmat_type as basic_hazmat_type,b.hazmat_character as basic_hazmat_character,
|
b.supplier as basic_supplier,b.manufacturer as basic_manufacturer,b.metering as basic_metering,b.unit as basic_unit,b.product_sn,b.min_package as basic_min_package,c.name as warehouse_name
|
from hz_hazmat a
|
left join hz_hazmat_basic b on b.id=a.basic_id
|
left join hz_warehouse c on c.id=a.warehouse_id
|
</sql>
|
|
<update id="deleteHazmatById" parameterType="com.gkhy.hazmat.system.domain.HzHazmat">
|
update hz_hazmat set del_flag=1 where id=#{hazmatId}
|
</update>
|
|
<select id="selectHazmatList" resultMap="HzHazmatResult"
|
parameterType="com.gkhy.hazmat.system.domain.HzHazmat">
|
<include refid="selectHazmatVo"/>
|
<where>
|
and a.del_flag=0
|
<if test="warehouseId != null">
|
and a.warehouse_id=#{warehouseId}
|
</if>
|
<if test="state != null">
|
and a.state=#{state}
|
</if>
|
<if test="basicId != null">
|
and a.basic_id=#{basicId}
|
</if>
|
<if test="entryId != null">
|
and a.entry_id=#{entryId}
|
</if>
|
<if test="companyId != null">
|
AND a.company_id= #{companyId}
|
</if>
|
</where>
|
order by a.id desc
|
</select>
|
|
<select id="selectHazmatGroupWareHouse" resultType="com.gkhy.hazmat.system.domain.vo.HzHazmatWarehouseVO">
|
select a.basic_id,a.warehouse_id,
|
(select count(1) from hz_hazmat where state=0 and basic_id=a.basic_id and warehouse_id=a.warehouse_id) as stock,
|
(select count(1) from hz_hazmat where state=1 and basic_id=a.basic_id and warehouse_id=a.warehouse_id) as miss_stock
|
from hz_hazmat a
|
left join hz_hazmat_basic b on b.id=a.basic_id
|
<where>
|
<if test="companyId != null">
|
AND a.company_id= #{companyId}
|
</if>
|
<if test="basicId != null">
|
AND a.basic_id= #{basicId}
|
</if>
|
<if test="state != null">
|
AND a.state= #{state}
|
</if>
|
<if test="warehouseId != null">
|
AND a.warehouse_id= #{warehouseId}
|
</if>
|
<if test="params.name != null and params.name != ''">
|
AND b.name like concat(#{params.name},"%")
|
</if>
|
<if test="params.productSn != null and params.productSn != ''">
|
AND b.product_sn =#{params.productSn}
|
</if>
|
and a.del_flag=0
|
</where>
|
group by a.basic_id,a.warehouse_id
|
</select>
|
|
|
|
<select id="selectHazmatCountOfWarehouse" resultType="integer">
|
select count(a.id) from hz_hazmat a
|
inner join hz_hazmat_basic b on b.id=basic_id
|
where a.warehouse_id=#{warehouseId} and b.id=#{basicId} and a.company_id=#{companyId} and b.company_id=#{companyId} and a.del_flag=0 and (a.state=0 or a.state=1)
|
</select>
|
|
<select id="selectHazmatByCode" resultMap="HzHazmatResult">
|
<include refid="selectHazmatVo"/>
|
where a.del_flag=0 and a.code=#{code} and a.company_id=#{companyId} limit 1
|
</select>
|
|
<select id="useCountEverydayStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzEntryRecordVO">
|
select count(*) as count, month(create_time) as month,day(create_time) as day from hz_hazmat
|
where create_time >= #{startTime} and create_time <= #{endTime} and state in (2,3)
|
<if test="companyId!=null">
|
and company_id=#{companyId}
|
</if>
|
group by month,day
|
order by month asc,day asc
|
</select>
|
|
<select id="maxUseCountStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzHazmatUseVO">
|
select count(*) as count,basic_id from hz_hazmat
|
where create_time >= #{startTime} and create_time <= #{endTime} and state in (1,2,3)
|
<if test="companyId!=null">
|
and company_id=#{companyId}
|
</if>
|
group by basic_id
|
order by count desc
|
limit 10
|
</select>
|
|
<select id="useCountStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzHazmatUseVO">
|
select count(*) as count,basic_id from hz_hazmat
|
where create_time >= #{startTime} and create_time <= #{endTime} and state =3
|
<if test="companyId!=null">
|
and company_id=#{companyId}
|
</if>
|
group by basic_id
|
order by count desc
|
</select>
|
|
|
<select id="selectWarningHazmatList" resultType="com.gkhy.hazmat.system.domain.HzHazmat">
|
select * from hz_hazmat_#{slice} a
|
left join hz_hazmat_basic b on b.id=a.basic_id
|
left join hz_warning c on c.hazmat_id=a.id and c.state=0
|
<where>
|
and c.id is null and b.threshold>0 and a.state=2 and DATE_ADD(a.update_time,INTERVAL b.threshold HOUR) <= now()
|
</where>
|
order by a.id
|
limit #{startIndex},#{pageSize}
|
</select>
|
</mapper>
|