yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?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>