危化品全生命周期管理后端
“djh”
2025-05-07 da2c594ade5d69621dd11a13bb758477e2dc079e
hazmat-system/src/main/resources/mapper/system/HzHazmatMapper.xml
@@ -39,8 +39,8 @@
    <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,d.cupboard_name
               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,d.cupboard_name as cupboard_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
@@ -76,7 +76,7 @@
    </select>
    <select id="selectHazmatGroupWareHouse" resultType="com.gkhy.hazmat.system.domain.vo.HzHazmatWarehouseVO">
        select a.basic_id,a.warehouse_id,
        select a.basic_id,a.warehouse_id,a.cupboard_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
@@ -100,9 +100,9 @@
            <if test="params.productSn != null and params.productSn != ''">
                AND b.product_sn =#{params.productSn}
            </if>
            and a.del_flag=0
            and a.del_flag=0 and b.del_flag = 0
        </where>
        group by a.basic_id,a.warehouse_id
        group by a.basic_id,a.warehouse_id, a.cupboard_id
    </select>
@@ -110,7 +110,16 @@
    <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)
        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) and a.cupboard_id = #{cupboardId}
    </select>
    <select id="selectHazmatWarehouseCheck" resultType="com.gkhy.hazmat.system.domain.vo.TabooDisVo">
        select DISTINCT b.peculiarity_number spNum ,b.id  from hz_hazmat a
                                    inner join hz_hazmat_basic b on b.id=basic_id
        where a.warehouse_id=#{warehouseId}  and a.company_id=#{companyId} and b.company_id=#{companyId}
          and a.del_flag=0 and (a.state=0 or a.state=1) and a.cupboard_id = #{cupboardId}
    </select>
    <select id="selectHazmatByCode" resultMap="HzHazmatResult">
@@ -160,4 +169,73 @@
        order by a.id
        limit #{startIndex},#{pageSize}
    </select>
    <select id="useCountHourlyStatic" resultType="com.gkhy.hazmat.system.domain.vo.HzEntryRecordVO">
        SELECT
        DATE_FORMAT(create_time, '%H') AS hour,
        COUNT(*) AS count
        FROM hz_hazmat
        WHERE create_time &gt;= #{startDate}
        AND create_time &lt; #{endDate}
        AND state IN (2, 3)
        <if test="companyId != null">
            AND company_id = #{companyId}
        </if>
        GROUP BY hour
        ORDER BY hour ASC
    </select>
    <select id="companyMessage" resultType="com.gkhy.hazmat.system.domain.vo.HzCompanyMessage">
        SELECT
            sc.id,
            sc.name as company_name,
            scf.longitude,
            scf.latitude,
            COALESCE(hw.warehouse_count, 0) AS warehouse_count,
            COALESCE(htw.warning_count, 0) AS warning_count,
            htw.latest_warning_time
        FROM sys_company sc
                 LEFT JOIN (
            SELECT company_id, COUNT(*) AS warehouse_count
            FROM hz_warehouse
            WHERE del_flag = 0
            GROUP BY company_id
        ) hw ON sc.id = hw.company_id
                 LEFT JOIN (
            SELECT
                company_id,
                COUNT(*) AS warning_count,
                MAX(create_time) AS latest_warning_time
            FROM hz_taboo_warning
            WHERE del_flag = 0
            GROUP BY company_id
        ) htw ON sc.id = htw.company_id
        LEFT JOIN sys_config scf on sc.id = scf.company_id
        <where>
            sc.del_flag = 0
            <if test="type!=null">
                and sc.type = #{type}
            </if>
        </where>
        ORDER BY htw.latest_warning_time DESC;
    </select>
    <select id="countTotal" resultType="java.lang.Integer">
        SELECT
        COUNT(*) AS total_count
        FROM hz_hazmat
        WHERE state IN (2, 3)
        <if test="companyId != null">
            AND company_id = #{companyId}
        </if>
    </select>
    <!--    SELECT COUNT(*) AS count, DATE_FORMAT(create_time, '%H') AS hour-->
<!--    FROM hz_hazmat-->
<!--    WHERE create_time &gt;= #{startDate} AND create_time &lt;  #{endDate}-->
<!--    AND state IN (2, 3)-->
<!--    <if test="companyId != null">-->
<!--        AND company_id = #{companyId}-->
<!--    </if>-->
<!--    GROUP BY hour-->
<!--    ORDER BY hour ASC-->
</mapper>