Преглед изворни кода

配合前端添加月统计、年统计

gz пре 1 недеља
родитељ
комит
c7af90d707

+ 31 - 0
kaojiplatform/src/main/java/com/mvc/controller/sthjb/SthjbController.java

@@ -99,4 +99,35 @@ public class SthjbController {
         }
         return resultModel;
     }
+
+
+    @ApiOperation("根据单位代码和年月获取用量")
+    @RequestMapping(value = "/getUsageDataByStationCodeAndYMonth", method = RequestMethod.GET)
+    @ResponseBody
+    public ResultGeekerModel getUsageDataByStationCodeAndYMonth(String stationCode, int year, int month) {
+        ResultGeekerModel resultModel;
+        try {
+            var res = sthjbService.getUsageDataByStationCodeAndYMonth(stationCode, year,month);
+            resultModel = new ResultGeekerModel(res);
+        } catch (Exception e) {
+            e.printStackTrace();
+            resultModel = new ResultGeekerModel(e.getMessage());
+        }
+        return resultModel;
+    }
+
+    @ApiOperation("根据单位代码和年获取用量")
+    @RequestMapping(value = "/getAnnualUsageDataByStationCodeAndYear", method = RequestMethod.GET)
+    @ResponseBody
+    public ResultGeekerModel getAnnualUsageDataByStationCodeAndYear(String stationCode, int year) {
+        ResultGeekerModel resultModel;
+        try {
+            var res = sthjbService.getAnnualUsageDataByStationCodeAndYear(stationCode, year);
+            resultModel = new ResultGeekerModel(res);
+        } catch (Exception e) {
+            e.printStackTrace();
+            resultModel = new ResultGeekerModel(e.getMessage());
+        }
+        return resultModel;
+    }
 }

+ 88 - 6
kaojiplatform/src/main/java/com/mvc/service/sthjb/SthjbService.java

@@ -11,6 +11,7 @@ import com.mvc.service.copy.TAireadService;
 import com.mvc.service.taizhang.StationAccService;
 import com.mvc.service.tyrq.TyrqStatisticsService;
 import com.mvc.utils.DateUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -21,6 +22,7 @@ import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 @Transactional
@@ -344,15 +346,35 @@ public class SthjbService {
      */
     public Map<String, Object> getRecentUsageDataByStationCode(String stationCode, int days) {
         days = days < 10 || days > 31 ? 30 : days;//天数限制
+
         List<String> recentUsageXAxis = new ArrayList<>();//最近用量-X轴名称
         List<BigDecimal> recentUsageYAxis = new ArrayList<>();//最近用量-Y轴数据
 
         Date today = DateUtil.getZeroTimeOfDay(new Date());
         Date startDate = DateUtil.getOtherDateByCurrentDate(today, -days);
-        List<TAiread> aireadModels = tyrqStatisticsService.getAireadData(stationCode, startDate, today);
+        return getRecentUsageDataByStationCodeAndTime(stationCode, startDate, today);
+
+
+    }
+
+    /**
+     * 获取最近用量数据
+     *
+     * @param stationCode 站码
+     * @param startDate   开始时间
+     * @param endDate     结束时间
+     * @return
+     */
+    public Map<String, Object> getRecentUsageDataByStationCodeAndTime(String stationCode, Date startDate, Date endDate) {
+        List<String> recentUsageXAxis = new ArrayList<>();//最近用量-X轴名称
+        List<BigDecimal> recentUsageYAxis = new ArrayList<>();//最近用量-Y轴数据
+
+        //算用量要+1天,才能包含昨天
+        endDate = DateUtil.getOtherDateByCurrentDate(endDate, 1);
+        List<TAiread> aireadModels = tyrqStatisticsService.getAireadData(stationCode, startDate, endDate);
 
         Date tempDate = startDate;//循环变量
-        while (tempDate.compareTo(today) < 0) {
+        while (tempDate.compareTo(endDate) < 0) {
             Date finalTempDate0 = tempDate;
 
             tempDate = DateUtil.getOtherDateByCurrentDate(tempDate, 1);
@@ -393,11 +415,71 @@ public class SthjbService {
         return resMap;
     }
 
-    /*public Map<String, Object> getRecentUsageDataByStationCode(String stationCode, Date startTime, Date endTime) {
-        trend
+    /**
+     * 根据站码年月获取用量数据
+     *
+     * @param stationCode
+     * @param year
+     * @param month
+     * @return
+     */
+    public Map<String, Object> getUsageDataByStationCodeAndYMonth(String stationCode, int year, int month) {
+        Date startDate = DateUtil.parseTimeStr(year + "-" + month + "-01", "yyyy-MM-dd");//当月第一天
+        Date endDate = DateUtil.getLastDayOfMonth(startDate);
+
+        return getRecentUsageDataByStationCodeAndTime(stationCode, startDate, endDate);
     }
 
-    public Map<String, Object> getRecentUsageDataByStationCode11(String stationCode, int months) {
+    /**
+     * 根据单位代码和年月获取用量
+     *
+     * @param stationCode
+     * @param year
+     * @return
+     */
+    public Map<String, Object> getAnnualUsageDataByStationCodeAndYear(String stationCode, int year) {
+        Date startDate = DateUtil.parseTimeStr(year + "-01-01", "yyyy-MM-dd");
+        Date endDate = DateUtil.parseTimeStr((year + 1) + "-01-01", "yyyy-MM-dd");
+
+        // 获取整年所有数据
+        List<TAiread> aireadModels = tyrqStatisticsService.getAireadData(stationCode, startDate, endDate);
+
+        // 建立时间精确匹配的Map(方便直接取 1号0点 数据)
+        Map<Long, TAiread> timeMap = aireadModels.stream()
+                .filter(s -> s.getResultValue() != null)
+                .collect(Collectors.toMap(
+                        s -> s.getSampleTime().getTime(),
+                        s -> s,
+                        (a, b) -> a // 如果有重复时间取第一个
+                ));
+
+        List<String> xAxis = new ArrayList<>();
+        List<BigDecimal> yAxis = new ArrayList<>();
+
+        Date tempDate = startDate;
+
+        for (int month = 1; month <= 12; month++) {
+            xAxis.add(StringUtils.leftPad(String.valueOf(month), 2, "0"));
+
+            Date monthStart = tempDate;
+            Date nextMonthStart = DateUtil.getOtherDateByMonth(monthStart, 1);
+            tempDate = nextMonthStart; // 为下轮准备
+
+            TAiread startAiread = timeMap.get(monthStart.getTime());
+            TAiread endAiread = timeMap.get(nextMonthStart.getTime());
+
+            if (startAiread != null && endAiread != null) {
+                yAxis.add(endAiread.getResultValue().subtract(startAiread.getResultValue()));
+            } else {
+                // 缺数处理
+                yAxis.add(BigDecimal.ZERO);
+            }
+        }
+
+        Map<String, Object> resMap = new HashMap<>();
+        resMap.put("xAxis", xAxis);
+        resMap.put("yAxis", yAxis);
+        return resMap;
+    }
 
-    }*/
 }

+ 368 - 0
kaojiplatform/src/main/resources/com/mvc/dao/TStationStructureMapper.xml

@@ -0,0 +1,368 @@
+<?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.mvc.dao.TStationStructureMapper">
+  <resultMap id="BaseResultMap" type="com.mvc.entity.TStationStructure">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    <id column="ID" jdbcType="INTEGER" property="id" />
+    <result column="STATION_CODE" jdbcType="VARCHAR" property="stationCode" />
+    <result column="PARENT_CODE" jdbcType="VARCHAR" property="parentCode" />
+    <result column="WATER_METER_LEVEL" jdbcType="INTEGER" property="waterMeterLevel" />
+    <result column="WATER_TYPE" jdbcType="INTEGER" property="waterType" />
+    <result column="UNIT_CODE" jdbcType="VARCHAR" property="unitCode" />
+    <result column="NODE_KEY" jdbcType="VARCHAR" property="nodeKey" />
+    <result column="PARENT_KEY" jdbcType="VARCHAR" property="parentKey" />
+    <result column="NODE_LABEL" jdbcType="VARCHAR" property="nodeLabel" />
+    <result column="NODE_TYPE" jdbcType="TINYINT" property="nodeType" />
+    <result column="NODE_ORDER" jdbcType="TINYINT" property="nodeOrder" />
+  </resultMap>
+  <sql id="Example_Where_Clause">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    <where>
+      <foreach collection="oredCriteria" item="criteria" separator="or">
+        <if test="criteria.valid">
+          <trim prefix="(" prefixOverrides="and" suffix=")">
+            <foreach collection="criteria.criteria" item="criterion">
+              <choose>
+                <when test="criterion.noValue">
+                  and ${criterion.condition}
+                </when>
+                <when test="criterion.singleValue">
+                  and ${criterion.condition} #{criterion.value}
+                </when>
+                <when test="criterion.betweenValue">
+                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
+                </when>
+                <when test="criterion.listValue">
+                  and ${criterion.condition}
+                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
+                    #{listItem}
+                  </foreach>
+                </when>
+              </choose>
+            </foreach>
+          </trim>
+        </if>
+      </foreach>
+    </where>
+  </sql>
+  <sql id="Update_By_Example_Where_Clause">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    <where>
+      <foreach collection="example.oredCriteria" item="criteria" separator="or">
+        <if test="criteria.valid">
+          <trim prefix="(" prefixOverrides="and" suffix=")">
+            <foreach collection="criteria.criteria" item="criterion">
+              <choose>
+                <when test="criterion.noValue">
+                  and ${criterion.condition}
+                </when>
+                <when test="criterion.singleValue">
+                  and ${criterion.condition} #{criterion.value}
+                </when>
+                <when test="criterion.betweenValue">
+                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
+                </when>
+                <when test="criterion.listValue">
+                  and ${criterion.condition}
+                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
+                    #{listItem}
+                  </foreach>
+                </when>
+              </choose>
+            </foreach>
+          </trim>
+        </if>
+      </foreach>
+    </where>
+  </sql>
+  <sql id="Base_Column_List">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    ID, STATION_CODE, PARENT_CODE, WATER_METER_LEVEL, WATER_TYPE, UNIT_CODE, NODE_KEY, 
+    PARENT_KEY, NODE_LABEL, NODE_TYPE, NODE_ORDER
+  </sql>
+  <select id="selectByExample" parameterType="com.mvc.entity.TStationStructureExample" resultMap="BaseResultMap">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    select
+    <if test="distinct">
+      distinct
+    </if>
+    <include refid="Base_Column_List" />
+    from t_station_structure
+    <if test="_parameter != null">
+      <include refid="Example_Where_Clause" />
+    </if>
+    <if test="orderByClause != null">
+      order by ${orderByClause}
+    </if>
+  </select>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    select 
+    <include refid="Base_Column_List" />
+    from t_station_structure
+    where ID = #{id,jdbcType=INTEGER}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    delete from t_station_structure
+    where ID = #{id,jdbcType=INTEGER}
+  </delete>
+  <delete id="deleteByExample" parameterType="com.mvc.entity.TStationStructureExample">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    delete from t_station_structure
+    <if test="_parameter != null">
+      <include refid="Example_Where_Clause" />
+    </if>
+  </delete>
+  <insert id="insert" parameterType="com.mvc.entity.TStationStructure">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    insert into t_station_structure (ID, STATION_CODE, PARENT_CODE, 
+      WATER_METER_LEVEL, WATER_TYPE, UNIT_CODE, 
+      NODE_KEY, PARENT_KEY, NODE_LABEL, 
+      NODE_TYPE, NODE_ORDER)
+    values (#{id,jdbcType=INTEGER}, #{stationCode,jdbcType=VARCHAR}, #{parentCode,jdbcType=VARCHAR}, 
+      #{waterMeterLevel,jdbcType=INTEGER}, #{waterType,jdbcType=INTEGER}, #{unitCode,jdbcType=VARCHAR}, 
+      #{nodeKey,jdbcType=VARCHAR}, #{parentKey,jdbcType=VARCHAR}, #{nodeLabel,jdbcType=VARCHAR}, 
+      #{nodeType,jdbcType=TINYINT}, #{nodeOrder,jdbcType=TINYINT})
+  </insert>
+  <insert id="insertSelective" parameterType="com.mvc.entity.TStationStructure">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    insert into t_station_structure
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        ID,
+      </if>
+      <if test="stationCode != null">
+        STATION_CODE,
+      </if>
+      <if test="parentCode != null">
+        PARENT_CODE,
+      </if>
+      <if test="waterMeterLevel != null">
+        WATER_METER_LEVEL,
+      </if>
+      <if test="waterType != null">
+        WATER_TYPE,
+      </if>
+      <if test="unitCode != null">
+        UNIT_CODE,
+      </if>
+      <if test="nodeKey != null">
+        NODE_KEY,
+      </if>
+      <if test="parentKey != null">
+        PARENT_KEY,
+      </if>
+      <if test="nodeLabel != null">
+        NODE_LABEL,
+      </if>
+      <if test="nodeType != null">
+        NODE_TYPE,
+      </if>
+      <if test="nodeOrder != null">
+        NODE_ORDER,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=INTEGER},
+      </if>
+      <if test="stationCode != null">
+        #{stationCode,jdbcType=VARCHAR},
+      </if>
+      <if test="parentCode != null">
+        #{parentCode,jdbcType=VARCHAR},
+      </if>
+      <if test="waterMeterLevel != null">
+        #{waterMeterLevel,jdbcType=INTEGER},
+      </if>
+      <if test="waterType != null">
+        #{waterType,jdbcType=INTEGER},
+      </if>
+      <if test="unitCode != null">
+        #{unitCode,jdbcType=VARCHAR},
+      </if>
+      <if test="nodeKey != null">
+        #{nodeKey,jdbcType=VARCHAR},
+      </if>
+      <if test="parentKey != null">
+        #{parentKey,jdbcType=VARCHAR},
+      </if>
+      <if test="nodeLabel != null">
+        #{nodeLabel,jdbcType=VARCHAR},
+      </if>
+      <if test="nodeType != null">
+        #{nodeType,jdbcType=TINYINT},
+      </if>
+      <if test="nodeOrder != null">
+        #{nodeOrder,jdbcType=TINYINT},
+      </if>
+    </trim>
+  </insert>
+  <select id="countByExample" parameterType="com.mvc.entity.TStationStructureExample" resultType="java.lang.Long">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    select count(*) from t_station_structure
+    <if test="_parameter != null">
+      <include refid="Example_Where_Clause" />
+    </if>
+  </select>
+  <update id="updateByExampleSelective" parameterType="map">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    update t_station_structure
+    <set>
+      <if test="record.id != null">
+        ID = #{record.id,jdbcType=INTEGER},
+      </if>
+      <if test="record.stationCode != null">
+        STATION_CODE = #{record.stationCode,jdbcType=VARCHAR},
+      </if>
+      <if test="record.parentCode != null">
+        PARENT_CODE = #{record.parentCode,jdbcType=VARCHAR},
+      </if>
+      <if test="record.waterMeterLevel != null">
+        WATER_METER_LEVEL = #{record.waterMeterLevel,jdbcType=INTEGER},
+      </if>
+      <if test="record.waterType != null">
+        WATER_TYPE = #{record.waterType,jdbcType=INTEGER},
+      </if>
+      <if test="record.unitCode != null">
+        UNIT_CODE = #{record.unitCode,jdbcType=VARCHAR},
+      </if>
+      <if test="record.nodeKey != null">
+        NODE_KEY = #{record.nodeKey,jdbcType=VARCHAR},
+      </if>
+      <if test="record.parentKey != null">
+        PARENT_KEY = #{record.parentKey,jdbcType=VARCHAR},
+      </if>
+      <if test="record.nodeLabel != null">
+        NODE_LABEL = #{record.nodeLabel,jdbcType=VARCHAR},
+      </if>
+      <if test="record.nodeType != null">
+        NODE_TYPE = #{record.nodeType,jdbcType=TINYINT},
+      </if>
+      <if test="record.nodeOrder != null">
+        NODE_ORDER = #{record.nodeOrder,jdbcType=TINYINT},
+      </if>
+    </set>
+    <if test="_parameter != null">
+      <include refid="Update_By_Example_Where_Clause" />
+    </if>
+  </update>
+  <update id="updateByExample" parameterType="map">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    update t_station_structure
+    set ID = #{record.id,jdbcType=INTEGER},
+      STATION_CODE = #{record.stationCode,jdbcType=VARCHAR},
+      PARENT_CODE = #{record.parentCode,jdbcType=VARCHAR},
+      WATER_METER_LEVEL = #{record.waterMeterLevel,jdbcType=INTEGER},
+      WATER_TYPE = #{record.waterType,jdbcType=INTEGER},
+      UNIT_CODE = #{record.unitCode,jdbcType=VARCHAR},
+      NODE_KEY = #{record.nodeKey,jdbcType=VARCHAR},
+      PARENT_KEY = #{record.parentKey,jdbcType=VARCHAR},
+      NODE_LABEL = #{record.nodeLabel,jdbcType=VARCHAR},
+      NODE_TYPE = #{record.nodeType,jdbcType=TINYINT},
+      NODE_ORDER = #{record.nodeOrder,jdbcType=TINYINT}
+    <if test="_parameter != null">
+      <include refid="Update_By_Example_Where_Clause" />
+    </if>
+  </update>
+  <update id="updateByPrimaryKeySelective" parameterType="com.mvc.entity.TStationStructure">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    update t_station_structure
+    <set>
+      <if test="stationCode != null">
+        STATION_CODE = #{stationCode,jdbcType=VARCHAR},
+      </if>
+      <if test="parentCode != null">
+        PARENT_CODE = #{parentCode,jdbcType=VARCHAR},
+      </if>
+      <if test="waterMeterLevel != null">
+        WATER_METER_LEVEL = #{waterMeterLevel,jdbcType=INTEGER},
+      </if>
+      <if test="waterType != null">
+        WATER_TYPE = #{waterType,jdbcType=INTEGER},
+      </if>
+      <if test="unitCode != null">
+        UNIT_CODE = #{unitCode,jdbcType=VARCHAR},
+      </if>
+      <if test="nodeKey != null">
+        NODE_KEY = #{nodeKey,jdbcType=VARCHAR},
+      </if>
+      <if test="parentKey != null">
+        PARENT_KEY = #{parentKey,jdbcType=VARCHAR},
+      </if>
+      <if test="nodeLabel != null">
+        NODE_LABEL = #{nodeLabel,jdbcType=VARCHAR},
+      </if>
+      <if test="nodeType != null">
+        NODE_TYPE = #{nodeType,jdbcType=TINYINT},
+      </if>
+      <if test="nodeOrder != null">
+        NODE_ORDER = #{nodeOrder,jdbcType=TINYINT},
+      </if>
+    </set>
+    where ID = #{id,jdbcType=INTEGER}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.mvc.entity.TStationStructure">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    update t_station_structure
+    set STATION_CODE = #{stationCode,jdbcType=VARCHAR},
+      PARENT_CODE = #{parentCode,jdbcType=VARCHAR},
+      WATER_METER_LEVEL = #{waterMeterLevel,jdbcType=INTEGER},
+      WATER_TYPE = #{waterType,jdbcType=INTEGER},
+      UNIT_CODE = #{unitCode,jdbcType=VARCHAR},
+      NODE_KEY = #{nodeKey,jdbcType=VARCHAR},
+      PARENT_KEY = #{parentKey,jdbcType=VARCHAR},
+      NODE_LABEL = #{nodeLabel,jdbcType=VARCHAR},
+      NODE_TYPE = #{nodeType,jdbcType=TINYINT},
+      NODE_ORDER = #{nodeOrder,jdbcType=TINYINT}
+    where ID = #{id,jdbcType=INTEGER}
+  </update>
+  <select id="selectByExampleWithRowbounds" parameterType="com.mvc.entity.TStationStructureExample" resultMap="BaseResultMap">
+    <!--
+    description  guozhao  2025-08-07 10:15:50
+    -->
+    select
+    <if test="distinct">
+      distinct
+    </if>
+    <include refid="Base_Column_List" />
+    from t_station_structure
+    <if test="_parameter != null">
+      <include refid="Example_Where_Clause" />
+    </if>
+    <if test="orderByClause != null">
+      order by ${orderByClause}
+    </if>
+  </select>
+</mapper>