yangys
2025-11-18 8e944cfabb253fc2556588e308e282586043f7b0
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
<?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.SuperProcessParameterMapper">
 
    <resultMap id="BaseResultMap" type="com.qianwen.smartman.modules.mdc.entity.WorkstationCollectData">
        
        
        <id column="ts" jdbcType="BIGINT" property="ts"/>
        
        <result column="n" jdbcType="VARCHAR" property="n"/>
        <result column="v" jdbcType="VARCHAR" property="v"/>
        <result column="workstation_id" jdbcType="BIGINT" property="workstationId"/>
    </resultMap>
    <!-- 
    <select id="queryLastParameter" resultType="com.qianwen.smartman.modules.mdc.entity.WorkstationCollectData">
        select last(ts),  n, last(v),workstation_id from super_collect_data
        <where>
            and workstation_id = #{workstationId}
        </where>
        group by workstation_id,n
    </select>
  -->
     
    
    <select id="queryProcessParameter" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select ts as time,
        ts as realTime,
        n as collectItem,
        v as value_collect
        from iot_data.super_collect_data
        <where>
            n in
            <foreach collection="collectItems" item="ids" index="index" open="(" close=")" separator=",">
                #{ids}
            </foreach>
            and ts &gt;= #{startTime}
            and ts &lt;= #{endTime}
            and workstation_id = #{workstationId}
        </where>
        order by ts asc
    </select>
    <!-- 
    <select id="pageProcessParameter" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select ts as time,
        ts as realTime,
        n as collectItem,
        v as value_collect
        from iot_data.super_collect_data
        <where>
            n = #{item}
            and ts &gt;= #{startTime}
            and ts &lt;= #{endTime}
            and workstation_id = #{workstationId}
        </where>
        order by ts asc
        limit #{current}, #{size}
    </select>
     -->
     <select id="pageProcessParameter" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select 
        n as collectItem,
        v as value_collect
        from root.f2.process_param_${workstationId}_${item}
        where time &gt;= #{startTime}
            and time &lt;= #{endTime}
        order by time asc
        limit #{size} offset #{current}
    </select>
    <!-- 
    <select id="countProcessParameter" resultType="java.lang.Long">
        select count(*)
        from iot_data.super_collect_data
        <where>
            n = #{item}
            and ts &gt;= #{startTime}
            and ts &lt;= #{endTime}
            and workstation_id = #{workstationId}
        </where>
    </select>
 -->
   <select id="countProcessParameter" resultType="java.lang.Long">
        select count(*)
        from root.f2.process_param_${workstationId}_${item}
        <where>
            and time &gt;= #{startTime}
            and time &lt;= #{endTime}
        </where>
    </select>
    <select id="getOneDate" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select ts as time,
        ts as realTime,
        n as collectItem,
        v as value_collect
        from iot_data.super_collect_data
        where workstation_id = #{workstationId}
        and n = #{item}
        <if test="flag != null and 'true'.toString() == flag.toString()">
            and ts &gt; #{time}
            order by ts asc
        </if>
        <if test="flag != null and 'false'.toString() == flag.toString()">
            and ts &lt; #{time}
            order by ts desc
        </if>
        limit 1
    </select>
 
    <select id="processParameterListByShift" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select ts as time,
        ts as realTime,
        n as collectItem,
        v as value_collect
        from iot_data.super_collect_data
        <where>
            n in
            <foreach collection="collectItems" item="ids" index="index" open="(" close=")" separator=",">
                #{ids}
            </foreach>
            and
            <foreach collection="times" item="time" index="index" open="(" close=")" separator="or">
                (ts &gt;= #{time.startTime}
            and ts &lt;= #{time.endTime})
            </foreach>
            and workstation_id = #{workstationId}
        </where>
        order by ts asc
    </select>
<!-- 
    <select id="oldOneCollectList" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select ts as realTime,
               n  as collectItem,
               v  as value_collect
        from iot_data.super_collect_data
        where n = #{item}
          and ts &gt;= #{startTime}
          and ts &lt;= #{endTime}
          and workstation_id = #{workstationId}
        order by ts
    </select>
 
      
    <select id="oldFirstStatue" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select last(ts) as realTime,
               last(v)  as value_collect
        from iot_data.super_collect_data
        where n = #{item}
          and ts &lt; #{startTime}
          and workstation_id = #{workstationId}
    </select>
     -->
    <!-- 
    <select id="oldLastStatue" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select last(ts) as realTime,
               last(v)  as value_collect
        from iot_data.super_collect_data
        where n = #{item}
          and ts &gt; #{endTime}
          and workstation_id = #{workstationId}
    </select>
     -->
    
    <!-- sql修改开始 -->
    <!--  queryLastParameter 这个是根据原始sql改的,mp有问题,改在service中实现了
    <select id="queryLastParameter" resultMap="BaseResultMap">
        select max_time(n) as ts,last_value(n) as n,last_value(v) as v,last_value(workstation_id) as workstationId from root.f2.process_param_${workstationId}_*  align by device
    </select>
    -->
    <!-- 
    <select id="getLastParameters" resultType="com.qianwen.smartman.modules.mdc.entity.LastProcessParam">
        select workstation_id as workstationId,update_time as updateTime, param_json as paramJson from root.f2.last_process_param where workstation_id = #{workstationId}
    </select>
     -->
    
  
     <!-- 根据oldFirstStatue 改造的-->
     <!--
    <select id="lastParameterLessThanTime" resultType="com.qianwen.smartman.modules.mdc.entity.LastProcessParam">
        select workstation_id as workstationId,update_time as updateTime, param_json as paramJson 
        from root.f2.last_process_param
        where n = #{item} 
          and time &lt; #{startTime}
          and workstation_id = #{workstationId}
    </select> -->
    <!-- 根据oldLastStatue改的 -->
    <!-- 
    <select id="lastParameterGreaterThanTime" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select workstation_id as workstationId,update_time as updateTime, param_json as paramJson 
        from root.f2.last_process_param
        where n = #{item}
          and ts &gt; #{endTime}
          and workstation_id = #{workstationId}
    </select> -->
    <select id="oldOneCollectList" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select n as collectItem,v as valueCollect
        from root.f2.process_param_${workstationId}_${item}
        where time &gt;= #{startTime}
          and time &lt;= #{endTime}
        order by time
        align by device
    </select>
    
    <select id="lastParameterNotEqValue" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select n as collectItem,v as valueCollect
        from root.f2.process_param_${workstationId}_${item}
        where v&lt;&gt;"#{value}"
        order by time desc limit 1
    </select>
    
    <select id="firstParameterEqValueGtTime" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select n as collectItem,v as valueCollect
        from root.f2.process_param_${workstationId}_${item}
        where v="#{value}" and time &gt; #{time}
        order by time limit 1
    </select>
    
    <select id="firstParameterEqValue" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select n as collectItem,v as valueCollect
        from root.f2.process_param_${workstationId}_${item}
        where v="#{value}"
        order by time limit 1
    </select>
</mapper>