From 2419f5b2f83ce47a1df1ea9af2990ddc0bcd562a Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期一, 16 十二月 2024 11:05:25 +0800 Subject: [PATCH] 临时任务功能相关数据库操作代码增加事务注解 --- pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeIntakeAmountSv.java | 145 +++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 135 insertions(+), 10 deletions(-) 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 bcbe4da..b430a8e 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,15 +34,20 @@ this.dao = dao; } + + //////////////////////////////////////// + // + // 鏈夊叧鏃ョ粺璁� + // + /////////////////////////////////////// + + /** + * 璋冩暣鍙栨按鍙f棩鍙栨按閲忕粺璁� + * @throws Exception + */ public void chIntakeAmountDay() throws Exception{ RmIntakeAmountDay lastAd = null ; - //List<VoIntake> list = dao.selectAllPrIntakes() ; - - List<VoIntake> list = new ArrayList<>() ; - VoIntake voIntake = new VoIntake() ; - voIntake.setIntakeId(2024090522242500007L) ; - list.add(voIntake) ; - + List<VoIntake> list = dao.selectAllPrIntakes() ; if(list != null && list.size() > 0){ for(VoIntake vo : list){ lastAd = null ; @@ -112,7 +119,7 @@ ); ad.amount = 0.0 ; } - this.doUpdateOneIntakeAmountDay(ad.id, 0.0); + this.doUpdateOneIntakeAmountDay(ad.id, ad.amount); } } lastAd = ad ; @@ -123,7 +130,125 @@ } @Transactional - int doUpdateOneIntakeAmountDay(Long id, Double amount){ + protected 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 + */ + @Transactional + 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) ; + } + } + } + } + @Transactional + protected 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 + */ + @Transactional + 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) ; + } + } + @Transactional + protected 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) ; + } + } + } + } -- Gitblit v1.8.0