<?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.unis.purchaseAndSalesSupervision.modular.bizPssStorageAnomaly.mapper.BizPssStorageAnomalyMapper">
    <select id="findPage" resultType="com.unis.purchaseAndSalesSupervision.modular.bizPssStorageAnomaly.entity.BizPssStorageAnomaly">
        SELECT
        a.id,
        a.create_time,
        a.create_user,
        a.update_time,
        a.update_user,
        a.crkyw_rmdj_default_id,
        a.org_id,
        a.license_plate_number,
        a.storage_time,
        a.in_storage_time,
        a.grain_variety_id,
        a.alarm_date,
        a.STATUS,
        c.org_name orgName,
        d.enumname grainVarietyName
        FROM
        biz_pss_storage_anomaly a
        LEFT JOIN depot_qh.org_info c ON c.org_id = a.org_id
        LEFT JOIN depot_qh.basic_enum d ON d.enumId = a.grain_variety_id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where ${ew.sqlSegment}
        </if>
    </select>
    <select id="getAnomalyDatas" resultType="java.util.Map">
      SELECT
        a.DataID as "dataId",
        a.UnitID as "unitId",
        a.cph,
        a.lspz,
        TIMESTAMPDIFF(HOUR,ywdjsj,IFNULL(b.cmsj,NOW())) as inStorageTime,
        DATE_FORMAT(a.ywdjsj,'%Y-%m-%d %T') ywdjsj,
        DATE_FORMAT(IFNULL(b.cmsj,''),'%Y-%m-%d %T') cmsj,
        if(IFNULL(b.BizNo,'') = '',1,2) as "status"
    FROM
        depot_qh.data_crkyw_rmdj_default a
    LEFT JOIN depot_qh.data_crkyw_rkcm_default b on a.BizNo = b.BizNo
    INNER JOIN depot_qh.data_crkyw_qyxx_default c ON c.BizNo = a.BizNo
    WHERE
    a.ywdjsj &gt;= DATE_ADD(NOW(),INTERVAL -48 HOUR)
     /*查询48小时之内的入门数据*/
    AND  DATE_ADD(NOW(),INTERVAL -${inventoryTimeThreshold} HOUR) &gt; a.ywdjsj
    /* -- 相关超过指定的时间*/
    ORDER BY a.UnitID,a.ywdjsj
    </select>
</mapper>