<?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.qianwen.smartman.modules.mdc.mapper.SuperAlarmMapper">
|
|
<insert id="insertData">
|
insert into iot_data.alarm_${workstationId}
|
values ${sql}
|
</insert>
|
|
<update id="createTable">
|
create table if not exists iot_data.alarm_${workstationId} using super_alarm tags
|
(
|
#{workstationId}
|
)
|
</update>
|
|
|
|
|
|
<select id="countAlarm" resultType="java.lang.Long">
|
select * count(*)
|
from iot_data.super_alarm
|
where workstation_id = #{vo.workstationId}
|
/*按照班次查询*/
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@SHIFT == vo.enums">
|
and shift_index = #{vo.shiftIndex}
|
and factory_date = #{queryTime}
|
</if>
|
/*按照日查询*/
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@DAY == vo.enums">
|
and factory_date = #{queryTime}
|
</if>
|
/*按照月查询*/
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@MONTH == vo.enums">
|
and factory_year = #{vo.year}
|
and factory_month = #{vo.month}
|
</if>
|
/*按照周询*/
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@WEEK == vo.enums">
|
and factory_year = #{vo.year}
|
and factory_week = #{vo.week}
|
</if>
|
</select>
|
|
|
|
|
|
|
<select id="selectAllAlarm" resultType="com.qianwen.smartman.modules.mdc.entity.SuperAlarm">
|
select *
|
from iot_data.super_alarm
|
where workstation_id = #{vo.workstationId}
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@SHIFT == vo.enums">
|
and factory_date between #{startTime} and #{endTime}
|
and shift_index != -1
|
</if>
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@MONTH == vo.enums">
|
and factory_year = #{year}
|
and factory_month in
|
<foreach collection="list" item="month" index="index" open="(" close=")" separator=",">
|
#{month}
|
</foreach>
|
</if>
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@WEEK == vo.enums">
|
and factory_year = #{year}
|
and factory_week in
|
<foreach collection="list" item="week" index="index" open="(" close=")" separator=",">
|
#{week}
|
</foreach>
|
</if>
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@DAY == vo.enums">
|
and factory_date between #{startTime} and #{endTime}
|
</if>
|
order by ts desc
|
</select>
|
|
|
|
<select id="alarmReportByTime" resultType="com.qianwen.smartman.modules.report.vo.WorkstaionAlarmByTimeReportVO">
|
select
|
-- code as alarmCode,
|
-- ts,
|
factory_date factoryDate,
|
-- factory_year factoryYear,
|
factory_month factoryMonth,
|
factory_week factoryWeek,
|
workstation_id workstationId,
|
shift_index shiftIndex,
|
shift_time_type shiftTimeType
|
from iot_data.super_alarm
|
where shift_index != 0
|
<if test="ids != null and ids.size() > 0">
|
AND workstation_id IN
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
#{id}
|
</foreach>
|
</if>
|
<if test="beginTime != null and endTime != null">
|
AND factory_date BETWEEN #{beginTime} AND #{endTime}
|
</if>
|
order by ts desc
|
</select>
|
|
<select id="alarmReportByShift" resultType="com.qianwen.smartman.modules.report.vo.WorkstaionAlarmByShiftReportVO">
|
select
|
shift_index shiftIndex,
|
ts,
|
factory_date factoryDate,
|
workstation_id workstationId
|
from iot_data.super_alarm
|
where shift_index != 0
|
<if test="ids != null and ids.size() > 0">
|
AND workstation_id IN
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
#{id}
|
</foreach>
|
</if>
|
<if test="beginTime != null and endTime != null">
|
AND factory_date BETWEEN #{beginTime} AND #{endTime}
|
</if>
|
<if test="filterType != null and 'true'.toString() == filterType.toString()">
|
and shift_time_type != 2
|
</if>
|
<if test="filterShift != null and 'true'.toString() == filterShift.toString()">
|
and shift_index > 0
|
</if>
|
order by ts desc
|
</select>
|
|
<select id="drillAlarmReportByTime" resultType="com.qianwen.smartman.modules.report.vo.DrillWorkstationAlarmByTimeVO">
|
select code as alarmCode,
|
ts,
|
message alarmMsg,
|
factory_date factoryDate,
|
workstation_id workstationId
|
from iot_data.alarm_${workstationId}
|
where shift_index != 0
|
<if test="beginTime != null and endTime != null">
|
AND factory_date BETWEEN #{beginTime} AND #{endTime}
|
</if>
|
<if test="filterType != null and 'true'.toString() == filterType.toString()">
|
and shift_time_type != 2
|
</if>
|
<if test="filterShift != null and 'true'.toString() == filterShift.toString()">
|
and shift_index > 0
|
</if>
|
order by ts desc
|
<if test="pageNo != null and pageSize != null">
|
limit ${(pageNo - 1) * pageSize}, ${pageSize}
|
</if>
|
</select>
|
|
<select id="drillAlarmReportByShift" resultType="com.qianwen.smartman.modules.report.vo.DrillWorkstationAlarmByShiftVO">
|
select code as alarmCode,
|
ts,
|
message alarmMsg,
|
factory_date factoryDate,
|
workstation_id workstationId,
|
shift_index shiftIndex
|
from iot_data.alarm_${workstationId}
|
where shift_index != 0
|
<if test="beginTime != null and endTime != null">
|
AND factory_date BETWEEN #{beginTime} AND #{endTime}
|
</if>
|
<if test="filterType != null and 'true'.toString() == filterType.toString()">
|
and shift_time_type != 2
|
</if>
|
<if test="filterShift != null and 'true'.toString() == filterShift.toString()">
|
and shift_index > 0
|
</if>
|
order by ts desc
|
<if test="pageNo != null and pageSize != null">
|
limit ${(pageNo - 1) * pageSize}, ${pageSize}
|
</if>
|
</select>
|
|
<select id="drillCountAlarmReport" resultType="long">
|
select count(*)
|
from iot_data.alarm_${workstationId}
|
where shift_index != 0
|
<if test="beginTime != null and endTime != null">
|
AND factory_date BETWEEN #{beginTime} AND #{endTime}
|
</if>
|
<if test="filterType != null and 'true'.toString() == filterType.toString()">
|
and shift_time_type != 2
|
</if>
|
<if test="filterShift != null and 'true'.toString() == filterShift.toString()">
|
and shift_index > 0
|
</if>
|
</select>
|
<select id="pageAlarm" resultType="com.qianwen.smartman.modules.mdc.entity.SuperAlarm">
|
select *
|
from iot_data.super_alarm
|
where workstation_id = #{workstationId}
|
order by ts desc
|
<if test="pageNo != null and pageSize != null">
|
limit ${(pageNo - 1) * pageSize}, ${pageSize}
|
</if>
|
</select>
|
<select id="countAlarmByWorkstationId" resultType="java.lang.Integer">
|
select count(ts)
|
from iot_data.super_alarm
|
where workstation_id = #{workstationId}
|
</select>
|
|
|
<!-- sql修改开始 -->
|
|
<!-- 原始limit limit #{start}, #{end} ,实际上end应该是pageSize-->
|
<select id="alarmByWorkstation" resultType="com.qianwen.smartman.modules.mdc.vo.AlarmAnalysisWorkstationVO">
|
select code as alarmCode,
|
message as alarmMsg
|
from root.f2.alarm_${workstationId} order by time desc
|
limit #{end} offset #{start}
|
align by device
|
</select>
|
|
<select id="alarmByWorkstationTotal" resultType="java.lang.Integer">
|
select count(workstation_id) from root.f2.alarm_${workstationId}
|
</select>
|
|
<!-- , -->
|
<sql id="alarmColumns">
|
code,message,level,workstation_id as workstationId,calendar_code as calendarCode,factory_year as factoryYear,factory_month as factoryMonth,factory_week as factoryWeek,factory_date as factoryDate,shift_index as shiftIndex,shift_time_type as shiftTimeType
|
</sql>
|
|
|
<select id="selectListAlarm" resultType="com.qianwen.smartman.modules.mdc.entity.SuperAlarm">
|
select <include refid="alarmColumns"/>
|
from root.f2.alarm_*
|
where workstation_id = #{vo.workstationId}
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@SHIFT == vo.enums">
|
and shift_index = #{vo.shiftIndex}
|
and factory_date = #{factoryDate}
|
</if>
|
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@DAY == vo.enums">
|
and factory_date = #{factoryDate}
|
</if>
|
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@MONTH == vo.enums">
|
and factory_year = #{vo.year}
|
and factory_month = #{vo.month}
|
</if>
|
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@WEEK == vo.enums">
|
and factory_year = #{vo.year}
|
and factory_week = #{vo.week}
|
</if>
|
align by device
|
</select>
|
|
<select id="queryAlarm" resultType="com.qianwen.smartman.modules.mdc.entity.SuperAlarm">
|
select <include refid="alarmColumns"/>
|
from root.f2.alarm_*
|
where workstation_id = #{vo.workstationId}
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@SHIFT == vo.enums">
|
and shift_index = #{vo.shiftIndex}
|
and factory_date = #{factoryDate}
|
</if>
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@DAY == vo.enums">
|
and factory_date = #{factoryDate}
|
</if>
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@MONTH == vo.enums">
|
and factory_year = #{vo.year}
|
and factory_month = #{vo.month}
|
</if>
|
<if test="@com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum@WEEK == vo.enums">
|
and factory_year = #{vo.year}
|
and factory_week = #{vo.week}
|
</if>
|
order by time desc
|
<if test="query != null">
|
limit ${query.size} offset ${(query.current - 1) * query.size}
|
</if>
|
align by device
|
</select>
|
|
<select id="selectListAlarmByShift" resultType="com.qianwen.smartman.modules.mdc.entity.SuperAlarm">
|
select <include refid="alarmColumns"/>
|
from root.f2.alarm_*
|
where workstation_id = #{workstationId}
|
and factory_date <![CDATA[>=]]> #{startFactoryDate}
|
and factory_date <![CDATA[<=]]> #{endFactoryDate}
|
align by device
|
</select>
|
</mapper>
|