From a8157b2445e6d17fa23fcf19143f5e1fcb179ee2 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期一, 16 十二月 2024 10:09:40 +0800
Subject: [PATCH] 实现临时任务功能:重新统计所有取水口月用水量和年用水量
---
pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeIntakeAmountSv.java | 129 +++++++++++++++++++++++++
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoTmp/ChangeMapper.java | 48 +++++++++
pipIrr-platform/pipIrr-global/src/main/resources/mapper/Temp4ChangeMapper.xml | 62 ++++++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-temp/说明.txt | 6 +
pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeCtrl.java | 25 +++++
5 files changed, 268 insertions(+), 2 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoTmp/ChangeMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoTmp/ChangeMapper.java
index 5245577..8c7af33 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoTmp/ChangeMapper.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoTmp/ChangeMapper.java
@@ -2,10 +2,13 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dy.pipIrrGlobal.pojoRm.RmIntakeAmountDay;
+import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth;
+import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountYear;
import com.dy.pipIrrGlobal.voSt.VoIntake;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
+import java.util.Date;
import java.util.List;
/**
@@ -37,4 +40,49 @@
*/
int updateOneIntakeAmountDay(@Param("id")Long id, @Param("amount")Double amount);
+
+
+
+ /**
+ * 鍒犻櫎鎵�鏈夊彇姘村彛鐨勬湀鐢ㄦ按閲忕粺璁�
+ * @return 褰卞搷瀹炰綋鏁�
+ */
+ int deleteAllIntakeAmountMonth();
+
+
+ /**
+ * 缁熻鎵�鏈夊彇姘村彛鐨勬湀鐢ㄦ按閲�
+ * @return 瀹炰綋闆嗗悎
+ */
+ List<StIntakeAmountMonth> statisticAllIntakeAmountMonthFromAmountDay(@Param("startDt")Date startDt,
+ @Param("endDt")Date endDt);
+ /**
+ * 淇濆瓨鍙栨按鍙g殑鏈堢敤姘撮噺缁熻
+ * @return 褰卞搷瀹炰綋鏁�
+ */
+ int saveOneIntakeAmountMonth(StIntakeAmountMonth pojo);
+
+
+
+
+ /**
+ * 鍒犻櫎鎵�鏈夊彇姘村彛鐨勫勾鐢ㄦ按閲忕粺璁�
+ * @return 褰卞搷瀹炰綋鏁�
+ */
+ int deleteAllIntakeAmountYear();
+
+
+ /**
+ * 缁熻鎵�鏈夊彇姘村彛鐨勫勾鐢ㄦ按閲�
+ * @return 瀹炰綋闆嗗悎
+ */
+ List<StIntakeAmountYear> statisticAllIntakeAmountYearFromAmountDay(@Param("startDt")Date startDt,
+ @Param("endDt")Date endDt);
+ /**
+ * 淇濆瓨鍙栨按鍙g殑鏈堢敤姘撮噺缁熻
+ * @return 褰卞搷瀹炰綋鏁�
+ */
+ int saveOneIntakeAmountYear(StIntakeAmountYear pojo);
+
+
}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/Temp4ChangeMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/Temp4ChangeMapper.xml
index 2c0bfcd..1380e68 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/Temp4ChangeMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/Temp4ChangeMapper.xml
@@ -28,4 +28,66 @@
set amount = #{amount, jdbcType=FLOAT}
where id = #{id, jdbcType=BIGINT}
</update>
+
+
+ <delete id="deleteAllIntakeAmountMonth">
+ delete from st_intake_amount_month
+ </delete>
+
+ <!-- -->
+ <select id="statisticAllIntakeAmountMonthFromAmountDay" resultType="com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth">
+ select intake_id as intakeId ,
+ sum(amount) as amount
+ from rm_intake_amount_day
+ where dt <![CDATA[>=]]> #{startDt, jdbcType=DATE}
+ and dt <![CDATA[<=]]> #{endDt, jdbcType=DATE}
+ group by intake_id
+ </select>
+
+ <insert id="saveOneIntakeAmountMonth" 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>
+
+ <delete id="deleteAllIntakeAmountYear">
+ delete from st_intake_amount_year
+ </delete>
+
+ <!-- -->
+ <select id="statisticAllIntakeAmountYearFromAmountDay" resultType="com.dy.pipIrrGlobal.pojoSt.StIntakeAmountYear">
+ select intake_id as intakeId ,
+ sum(amount) as amount
+ from rm_intake_amount_day
+ where dt <![CDATA[>=]]> #{startDt, jdbcType=DATE}
+ and dt <![CDATA[<=]]> #{endDt, jdbcType=DATE}
+ group by intake_id
+ </select>
+
+ <insert id="saveOneIntakeAmountYear" parameterType="com.dy.pipIrrGlobal.pojoSt.StIntakeAmountYear">
+ <!--@mbg.generated-->
+ insert into st_intake_amount_year (
+ id,
+ intake_id,
+ year,
+ amount
+ )
+ values (#{id,jdbcType=BIGINT},
+ #{intakeId,jdbcType=BIGINT},
+ #{year,jdbcType=INTEGER},
+ #{amount,jdbcType=FLOAT}
+ )
+ </insert>
+
</mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeCtrl.java
index 666a62c..3c7befe 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeCtrl.java
@@ -37,4 +37,29 @@
this.intakeAmountSv.chIntakeAmountDay();
return BaseResponseUtils.buildSuccess(true);
}
+
+
+ /**
+ * 閲嶆柊缁熻鍙栨按鍙f湀鍙栨按閲�
+ * @return
+ */
+ @GetMapping(path = "reStatisticsAllIntakeMonthAmount")
+ @SsoAop()
+ public BaseResponse<Boolean> reStatisticsAllIntakeMonthAmount() throws Exception{
+ this.intakeAmountSv.deleteAllIntakeAmountMonth();
+ this.intakeAmountSv.statisticsIntakeAmountMonth();
+ return BaseResponseUtils.buildSuccess(true);
+ }
+
+ /**
+ * 閲嶆柊缁熻鍙栨按鍙f墍鍙栨按閲�
+ * @return
+ */
+ @GetMapping(path = "reStatisticsAllIntakeYearAmount")
+ @SsoAop()
+ public BaseResponse<Boolean> reStatisticsAllIntakeYearAmount() throws Exception{
+ this.intakeAmountSv.deleteAllIntakeAmountYear();
+ this.intakeAmountSv.statisticsIntakeAmountYear();
+ return BaseResponseUtils.buildSuccess(true);
+ }
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeIntakeAmountSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeIntakeAmountSv.java
index ab034f2..fcebfd9 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeIntakeAmountSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeIntakeAmountSv.java
@@ -3,13 +3,15 @@
import com.dy.common.util.DateTime;
import com.dy.pipIrrGlobal.daoTmp.ChangeMapper;
import com.dy.pipIrrGlobal.pojoRm.RmIntakeAmountDay;
+import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth;
+import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountYear;
import com.dy.pipIrrGlobal.voSt.VoIntake;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
/**
@@ -32,6 +34,17 @@
this.dao = dao;
}
+
+ ////////////////////////////////////////
+ //
+ // 鏈夊叧鏃ョ粺璁�
+ //
+ ///////////////////////////////////////
+
+ /**
+ * 璋冩暣鍙栨按鍙f棩鍙栨按閲忕粺璁�
+ * @throws Exception
+ */
public void chIntakeAmountDay() throws Exception{
RmIntakeAmountDay lastAd = null ;
List<VoIntake> list = dao.selectAllPrIntakes() ;
@@ -120,4 +133,118 @@
int doUpdateOneIntakeAmountDay(Long id, Double amount){
return dao.updateOneIntakeAmountDay(id, amount);
}
+
+
+
+ ////////////////////////////////////////
+ //
+ // 鏈夊叧鏈堢粺璁�
+ //
+ ///////////////////////////////////////
+
+ private static final int DealStartYear = 2024 ;
+ private static final int DealStartMonth = 8 ;
+
+ private static final String endDayOfMonth(int year, int month){
+ if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
+ return "31" ;
+ }else{
+ if(month == 2){
+ if(DateTime.isLeapYear(year)){
+ return "29" ;
+ }else{
+ return "28" ;
+ }
+ }else{
+ return "30" ;
+ }
+ }
+ }
+ /**
+ * 鍒犻櫎鎵�鏈夊彇姘村彛鏈堝彇姘撮噺缁熻
+ * @throws Exception
+ */
+ public void deleteAllIntakeAmountMonth(){
+ dao.deleteAllIntakeAmountMonth();
+ }
+
+ /**
+ * 缁熻鍙栨按鍙f湀鍙栨按閲�
+ * @throws Exception
+ */
+ public void statisticsIntakeAmountMonth() throws Exception{
+ int nowYear = Integer.parseInt(DateTime.yyyy()) ;
+ int nowMonth = Integer.parseInt(DateTime.mm()) ;
+ Date startDt ;
+ Date endDt ;
+ List<StIntakeAmountMonth> list ;
+ for(int year = DealStartYear; year <= nowYear; year ++){
+ list = null ;
+ if(year < nowYear){
+ for(int month = 1 ; month <= 12 ; month ++){
+ startDt = DateTime.dateFrom_MM_dd(year + "-" + month + "-01") ;
+ endDt = DateTime.dateFrom_MM_dd(year + "-" + month + endDayOfMonth(year, month)) ;
+ list = dao.statisticAllIntakeAmountMonthFromAmountDay(startDt, endDt) ;
+ this.doStatisticsIntakeAmountMonth(year, month, list) ;
+ }
+ }else{
+ for(int month = 1 ; month <= nowMonth ; month ++){
+ startDt = DateTime.dateFrom_MM_dd(year + "-" + month + "-01") ;
+ endDt = DateTime.dateFrom_MM_dd(year + "-" + month + endDayOfMonth(year, month)) ;
+ list = dao.statisticAllIntakeAmountMonthFromAmountDay(startDt, endDt) ;
+ this.doStatisticsIntakeAmountMonth(year, month, list) ;
+ }
+ }
+ }
+ }
+ private void doStatisticsIntakeAmountMonth(int year, int month, List<StIntakeAmountMonth> list) throws Exception{
+ if(list != null && list.size() > 0){
+ for(StIntakeAmountMonth po : list){
+ po.year = year ;
+ po.month = month ;
+ dao.saveOneIntakeAmountMonth(po) ;
+ }
+ }
+ }
+
+
+ ////////////////////////////////////////
+ //
+ // 鏈夊叧骞寸粺璁�
+ //
+ ///////////////////////////////////////
+ /**
+ * 鍒犻櫎鎵�鏈夊彇姘村彛骞村彇姘撮噺缁熻
+ * @throws Exception
+ */
+ public void deleteAllIntakeAmountYear(){
+ dao.deleteAllIntakeAmountYear();
+ }
+
+ /**
+ * 缁熻鍙栨按鍙f湀鍙栨按閲�
+ * @throws Exception
+ */
+ public void statisticsIntakeAmountYear() throws Exception{
+ int nowYear = Integer.parseInt(DateTime.yyyy()) ;
+ Date startDt ;
+ Date endDt ;
+ List<StIntakeAmountYear> list ;
+ for(int year = DealStartYear; year <= nowYear; year ++){
+ list = null ;
+ startDt = DateTime.dateFrom_MM_dd(year + "-01-01") ;
+ endDt = DateTime.dateFrom_MM_dd(year + "-12-31") ;
+ list = dao.statisticAllIntakeAmountYearFromAmountDay(startDt, endDt) ;
+ this.doStatisticsIntakeAmountYear(year, list) ;
+ }
+ }
+ private void doStatisticsIntakeAmountYear(int year, List<StIntakeAmountYear> list) throws Exception{
+ if(list != null && list.size() > 0){
+ for(StIntakeAmountYear po : list){
+ po.year = year ;
+ dao.saveOneIntakeAmountYear(po) ;
+ }
+ }
+ }
+
}
diff --git "a/pipIrr-platform/pipIrr-web/pipIrr-web-temp/\350\257\264\346\230\216.txt" "b/pipIrr-platform/pipIrr-web/pipIrr-web-temp/\350\257\264\346\230\216.txt"
index a64244a..e431db2 100644
--- "a/pipIrr-platform/pipIrr-web/pipIrr-web-temp/\350\257\264\346\230\216.txt"
+++ "b/pipIrr-platform/pipIrr-web/pipIrr-web-temp/\350\257\264\346\230\216.txt"
@@ -10,4 +10,8 @@
/temp/delSome/deleteSomeStatisticClientAmount
4銆佷慨鏀逛竴浜涘彇姘村彛鏃ュ彇姘撮噺缁熻---鍥燫TU涓�澶╁唴鏁寸偣鎶ヤ腑绱娴侀噺闂存瓏鍑虹幇0鍊硷紝涓ゆ涓婃姤绱娴侀噺宸�间細浜х敓澶у��
-/temp/chSome/changeSomeIntakeDayAmount
\ No newline at end of file
+/temp/chSome/changeSomeIntakeDayAmount
+5銆侀噸鏂扮粺璁″彇姘村彛鏈堝彇姘撮噺
+/temp/chSome/reStatisticsAllIntakeMonthAmount
+6銆侀噸鏂扮粺璁″彇姘村彛鎵�鍙栨按閲�
+/temp/chSome/reStatisticsAllIntakeYearAmount
\ No newline at end of file
--
Gitblit v1.8.0