<?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.casic.missiles.modular.system.dao.AlarmRecordsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.modular.system.model.AlarmRecords">
        <id column="ID" property="id" />
        <result column="DEVICE_ID" property="deviceId" />
        <result column="DEVCODE" property="devcode" />
        <result column="WELL_CODE" property="wellCode" />
        <result column="ALARM_TYPE" property="alarmType" />
        <result column="ALARM_CONTENT" property="alarmContent" />
        <result column="ALARM_VALUE" property="alarmValue" />
        <result column="ALARM_TIME" property="alarmTime" />
        <result column="STATUS" property="status" />
        <result column="JOB_ID" property="jobId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ID AS id, DEVICE_ID AS deviceId, DEVCODE AS devcode, WELL_CODE AS wellCode, ALARM_TYPE AS alarmType, ALARM_CONTENT AS alarmContent, ALARM_VALUE AS alarmValue, ALARM_TIME AS alarmTime, STATUS AS status, JOB_ID AS jobId
    </sql>
<!--
{
    "code": 200,
    "message":"success",
    "data":{
        "rows":[
        {
        "id":1,
        "wellId":1,
        "wellCode":"N51F131",
        "position":"宋郎路",
        "alarmType":"1",
        "alarmTypeName":"数据异常",
        "alarmContent":"1",
        "alarmContentName":"液位超限",
        "deptid":"1",
        "deptName":"一分公司",
        "alarmTime":"2018-12-27 00:00:00",
        "status":"1",
        "statusName":"已取消",
        "jobId":1,
        "jobStatus":"0",
        "jobStatusName":"待处理",
        }
        ],
        "total":200
    }
  }
-->
    <select id="alarmList" resultType="map">
        SELECT ar.ID as id,ar.WELL_CODE as wellCode,ar.ALARM_CONTENT as alarmContentName,
        DATE_FORMAT(ar.ALARM_TIME,'%Y-%m-%d %H:%i:%s') as alarmTime,ar.DEVICE_ID as deviceId,
        ar.STATUS as status,ar.alarm_type as alarmType,ar.ALARM_VALUE AS alarmValue,aj.DEVCODE as devcode,
        aj.JOB_STATUS as jobStatus,ar.JOB_ID as jobId,bwi.DEPTID AS deptid
        FROM alarm_records ar LEFT JOIN alarm_job aj ON ar.JOB_ID = aj.ID
        LEFT JOIN bus_well_info bwi ON ar.WELL_CODE = bwi.WELL_CODE
        WHERE 1=1 and aj.id > 0
        AND ar.ALARM_TYPE = '1'
        <if test="status!='' and status!=null">
            AND ar.STATUS = #{status}
        </if>
         <if test="beginTime!='' and beginTime!=null">
             <![CDATA[ and ar.ALARM_TIME >= #{beginTime} ]]>
        </if>
         <if test="endTime!='' and endTime!=null">
             <![CDATA[ and ar.ALARM_TIME <= #{endTime} ]]>
        </if>
         <if test="keywords!='' and keywords!=null">
             and ar.WELL_CODE like concat('%',CONCAT(#{keywords},'%'))
        </if>
        <!--<if test="alarmType!='' and alarmType!= null">-->
            <!--AND ar.ALARM_TYPE = #{alarmType}-->
        <!--</if>-->
        <if test="alarmContent!='' and alarmContent!= null">
            AND ar.ALARM_CONTENT = #{alarmContent}
        </if>
<!--        ar.STATUS = (iStatus) AND ar.ALARM_TIME BETWEEN NOW()-1 AND NOW()
        and ar.WELLCODE like concat('%',CONCAT(str,'%'))
         AND ar.ALARMTYPE = AND ar.ALARMCONTENT LIKE concat('%',CONCAT(str,'%'));
         -->
    </select>

    <select id="alarmListAll" resultType="map">
        SELECT ar.ID as id,ar.WELL_CODE as wellCode,ar.ALARM_CONTENT as alarmContentName,
        DATE_FORMAT(ar.ALARM_TIME,'%Y-%m-%d %H:%i:%s') as alarmTime,ar.DEVICE_ID as deviceId,
        ar.STATUS as status,ar.alarm_type as alarmType,ar.ALARM_VALUE AS alarmValue,aj.DEVCODE as devcode,
        aj.JOB_STATUS as jobStatus,ar.JOB_ID as jobId,bwi.DEPTID AS deptid
        FROM alarm_records ar LEFT JOIN alarm_job aj ON ar.JOB_ID = aj.ID
        LEFT JOIN bus_well_info bwi ON ar.WELL_CODE = bwi.WELL_CODE
        WHERE 1=1 and aj.id > 0
        <if test="status!='' and status!=null">
            AND ar.STATUS = #{status}
        </if>
         <if test="beginTime!='' and beginTime!=null">
             <![CDATA[ and ar.ALARM_TIME >= #{beginTime} ]]>
        </if>
         <if test="endTime!='' and endTime!=null">
             <![CDATA[ and ar.ALARM_TIME <= #{endTime} ]]>
        </if>
         <if test="keywords!='' and keywords!=null">
             and ar.WELL_CODE like concat('%',CONCAT(#{keywords},'%'))
        </if>
        <if test="alarmType!='' and alarmType!= null">
            AND ar.ALARM_TYPE = #{alarmType}
        </if>

        <if test="alarmContent!='' and alarmContent!= null">
            AND ar.ALARM_CONTENT = #{alarmContent}
        </if>
<!--        ar.STATUS = (iStatus) AND ar.ALARM_TIME BETWEEN NOW()-1 AND NOW()
        and ar.WELLCODE like concat('%',CONCAT(str,'%'))
         AND ar.ALARMTYPE = AND ar.ALARMCONTENT LIKE concat('%',CONCAT(str,'%'));
         -->
    </select>

</mapper>
