liurunyu
4 天以前 7aab004601e77890b158f19d1735594a8326feaa
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?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.dy.pipIrrGlobal.daoSt.StLossMonthMapper">
  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoSt.StLossMonth">
    <!--@mbg.generated-->
    <!--@Table st_loss_month-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="intake_id" jdbcType="BIGINT" property="intakeId" />
    <result column="year" jdbcType="INTEGER" property="year" />
    <result column="month" jdbcType="INTEGER" property="month" />
    <result column="amount" jdbcType="FLOAT" property="amount" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, intake_id, `year`, `month`, amount
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from st_loss_month
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="selectByIntakeIdAndYearAndMonth" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from st_loss_month
    <where>
      <if test="intakeId != null">
        and `intake_id` = #{intakeId,jdbcType=BIGINT}
      </if>
     <if test="year != null">
        and `year` = #{year,jdbcType=INTEGER}
      </if>
      <if test="month != null">
        and `month` = #{month,jdbcType=INTEGER}
      </if>
    </where>
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from st_loss_month
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSt.StLossMonth">
    <!--@mbg.generated-->
    insert into st_loss_month (id, intake_id, `year`, 
      `month`, amount)
    values (#{id,jdbcType=BIGINT}, #{intakeId,jdbcType=BIGINT}, #{year,jdbcType=INTEGER}, 
      #{month,jdbcType=INTEGER}, #{amount,jdbcType=FLOAT})
  </insert>
  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoSt.StLossMonth">
    <!--@mbg.generated-->
    insert into st_loss_month
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="intakeId != null">
        intake_id,
      </if>
      <if test="year != null">
        `year`,
      </if>
      <if test="month != null">
        `month`,
      </if>
      <if test="amount != null">
        amount,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="intakeId != null">
        #{intakeId,jdbcType=BIGINT},
      </if>
      <if test="year != null">
        #{year,jdbcType=INTEGER},
      </if>
      <if test="month != null">
        #{month,jdbcType=INTEGER},
      </if>
      <if test="amount != null">
        #{amount,jdbcType=FLOAT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoSt.StLossMonth">
    <!--@mbg.generated-->
    update st_loss_month
    <set>
      <if test="intakeId != null">
        intake_id = #{intakeId,jdbcType=BIGINT},
      </if>
      <if test="year != null">
        `year` = #{year,jdbcType=INTEGER},
      </if>
      <if test="month != null">
        `month` = #{month,jdbcType=INTEGER},
      </if>
      <if test="amount != null">
        amount = #{amount,jdbcType=FLOAT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoSt.StLossMonth">
    <!--@mbg.generated-->
    update st_loss_month
    set intake_id = #{intakeId,jdbcType=BIGINT},
      `year` = #{year,jdbcType=INTEGER},
      `month` = #{month,jdbcType=INTEGER},
      amount = #{amount,jdbcType=FLOAT}
    where id = #{id,jdbcType=BIGINT}
  </update>
 
 
  <select id="statisticsByIntake" resultType="com.dy.pipIrrGlobal.voSt.VoIntakeLossStatistics">
    select intake_id as intakeId,
    sum(amount) as amount
    from st_loss_month
    where `year` = #{year,jdbcType=INTEGER}
    group by intake_id
  </select>
 
 
  <!-- 为查询统计取水口日漏损量,统计取水口数量 -->
  <select id="selectIntakeCount4LossMonth" resultType="java.lang.Long">
    SELECT COUNT(*)
    FROM pr_intake tb
    <where>
      AND tb.deleted != 1
      <if test="intakeNum != null and intakeNum != ''">
        AND tb.name = #{intakeNum}
      </if>
    </where>
  </select>
 
  <!-- 为查询统计取水口日漏损量,查询一页取水口ID -->
  <select id="selectIntakes4LossMonth" resultType="com.dy.pipIrrGlobal.voSt.VoMonthAmount">
    SELECT id    as intakeId,
    name  as intakeNum,
    lat   as intakeLat,
    lng   as intakeLng
    FROM pr_intake
    <where>
      AND deleted != 1
      <if test="intakeNum != null and intakeNum != ''">
        AND name = #{intakeNum}
      </if>
    </where>
    order by id DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start, javaType=Integer, jdbcType=INTEGER}, #{count, javaType=Integer, jdbcType=INTEGER}
      </if>
    </trim>
  </select>
 
  <sql id="selectLossAmountOfMonth_with">
      SELECT intaId.intakeId   AS intakeId,
             sld.year          AS `year`,
             sld.month         AS `month`,
             sld.amount        AS amount
      FROM JSON_TABLE(
        #{intakesJson},
          '$[*]' COLUMNS (
          intakeId BIGINT PATH '$.intakeId'
        )
      ) intaId
      INNER JOIN st_loss_month sld ON sld.intake_id = intaId.intakeId
      <where>
        <if test="year != null ">
          AND sld.year = #{year, javaType=Integer, jdbcType=INTEGER}
        </if>
      </where>
  </sql>
 
  <!--统计指定月份各月漏损量(1号到6月)-->
  <select id="selectLossAmountOfMonth01_06" resultType="com.dy.pipIrrGlobal.voSt.VoMonthAmount">
    WITH intakeLossAmountMonth AS (<include refid="selectLossAmountOfMonth_with" />)
    SELECT inta.intakeId     AS intakeId,
           inta.intakeNum    AS intakeNum,
           inta.intakeLng    AS intakeLng,
           inta.intakeLat    AS intakeLat,
           tb01.amount   AS month1,
           tb02.amount   AS month2,
           tb03.amount   AS month3,
           tb04.amount   AS month4,
           tb05.amount   AS month5,
           tb06.amount   AS month6
    FROM JSON_TABLE(
      #{intakesJson},
        '$[*]' COLUMNS (
        intakeId BIGINT PATH '$.intakeId',
        intakeNum VARCHAR(100) PATH '$.intakeNum',
        intakeLng DOUBLE PATH '$.intakeLng',
        intakeLat DOUBLE PATH '$.intakeLat'
      )
    ) inta
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 1
    ) as tb01 on tb01.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 2
    ) as tb02 on tb02.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 3
    ) as tb03 on tb03.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 4
    ) as tb04 on tb04.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 5
    ) as tb05 on tb05.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 6
    ) as tb06 on tb06.intakeId = inta.intakeId
  </select>
 
  <!--统计指定月份各月漏损量(7号到12月)-->
  <select id="selectLossAmountOfMonth07_12" resultType="com.dy.pipIrrGlobal.voSt.VoMonthAmount">
    WITH intakeLossAmountMonth AS (<include refid="selectLossAmountOfMonth_with" />)
    SELECT inta.intakeId     AS intakeId,
           inta.intakeNum    AS intakeNum,
           inta.intakeLng    AS intakeLng,
           inta.intakeLat    AS intakeLat,
           tb07.amount   AS month7,
           tb08.amount   AS month8,
           tb09.amount   AS month9,
           tb010.amount  AS month10,
           tb011.amount  AS month11,
           tb012.amount  AS month12
    FROM JSON_TABLE(
      #{intakesJson},
        '$[*]' COLUMNS (
        intakeId BIGINT PATH '$.intakeId',
        intakeNum VARCHAR(100) PATH '$.intakeNum',
        intakeLng DOUBLE PATH '$.intakeLng',
        intakeLat DOUBLE PATH '$.intakeLat'
      )
    ) inta
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 7
    ) as tb07 on tb07.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 8
    ) as tb08 on tb08.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 9
    ) as tb09 on tb09.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 10
    ) as tb010 on tb010.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 11
    ) as tb011 on tb011.intakeId = inta.intakeId
    LEFT JOIN (
      SELECT tb.intakeId AS intakeId,
             tb.amount AS amount
      FROM intakeLossAmountMonth AS tb
      WHERE tb.year = #{year}
            AND tb.month = 12
    ) as tb012 on tb012.intakeId = inta.intakeId
  </select>
 
</mapper>