From 1e3eeec2d3a470d066d21900586b912dfef58c91 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期四, 17 四月 2025 15:07:41 +0800
Subject: [PATCH] 优化代码

---
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/StIntakeAmountMonthMapper.xml |  313 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 313 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/StIntakeAmountMonthMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/StIntakeAmountMonthMapper.xml
new file mode 100644
index 0000000..cb32952
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/StIntakeAmountMonthMapper.xml
@@ -0,0 +1,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.StIntakeAmountMonthMapper">
+  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth">
+    <!--@mbg.generated-->
+    <!--@Table st_intake_amount_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_intake_amount_month
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+ <select id="selectByIntakeIdAndYearAndMonth" resultMap="BaseResultMap">
+    select
+    <include refid="Base_Column_List" />
+    from st_intake_amount_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_intake_amount_month
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth">
+    <!--@mbg.generated-->
+    insert into st_intake_amount_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.StIntakeAmountMonth">
+    <!--@mbg.generated-->
+    insert into st_intake_amount_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.StIntakeAmountMonth">
+    <!--@mbg.generated-->
+    update st_intake_amount_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.StIntakeAmountMonth">
+    <!--@mbg.generated-->
+    update st_intake_amount_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.VoIntakeAmountStatistics">
+    select intake_id, sum(amount) as amount
+    from st_intake_amount_month
+    where `year` = #{year,jdbcType=INTEGER}
+    group by intake_id
+  </select>
+
+
+
+
+  <!-- 涓烘煡璇㈢粺璁″彇姘村彛鏃ョ敤姘撮噺锛岀粺璁″彇姘村彛鏁伴噺 -->
+  <select id="selectIntakeCount4AmountMonth" 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="selectIntakes4AmountMonth" 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="selectIntakeAmountOfMonth_with">
+      SELECT intaId.intakeId   AS intakeId,
+             siam.year          AS `year`,
+             siam.month         AS `month`,
+             siam.amount        AS amount
+      FROM JSON_TABLE(
+        #{intakesJson},
+          '$[*]' COLUMNS (
+          intakeId BIGINT PATH '$.intakeId'
+        )
+      ) intaId
+      INNER JOIN st_intake_amount_month siam ON siam.intake_id = intaId.intakeId
+      <where>
+        <if test="year != null ">
+          AND siam.year = #{year, javaType=Integer, jdbcType=INTEGER}
+        </if>
+      </where>
+  </sql>
+
+  <!--缁熻鎸囧畾鏈堜唤鍚勬湀鐢ㄦ按閲�(1鍙峰埌6鏈�)-->
+  <select id="selectIntakeAmountOfMonth01_06" resultType="com.dy.pipIrrGlobal.voSt.VoMonthAmount">
+    WITH intakeAmountMonth AS (<include refid="selectIntakeAmountOfMonth_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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth AS tb
+      WHERE tb.year = #{year}
+            AND tb.month = 6
+    ) as tb06 on tb06.intakeId = inta.intakeId
+  </select>
+
+  <!--缁熻鎸囧畾鏈堜唤鍚勬湀鐢ㄦ按閲�(7鍙峰埌12鏈�)-->
+  <select id="selectIntakeAmountOfMonth07_12" resultType="com.dy.pipIrrGlobal.voSt.VoMonthAmount">
+    WITH intakeAmountMonth AS (<include refid="selectIntakeAmountOfMonth_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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth 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 intakeAmountMonth AS tb
+      WHERE tb.year = #{year}
+            AND tb.month = 12
+    ) as tb012 on tb012.intakeId = inta.intakeId
+  </select>
+
+</mapper>
\ No newline at end of file

--
Gitblit v1.8.0