| package com.dy.pipIrrStatistics.statistics; | 
|   | 
| import com.dy.common.multiDataSource.DataSourceContext; | 
| import com.dy.common.schedulerTask.TaskJob; | 
| import com.dy.common.schedulerTask.Test; | 
| import com.dy.common.springUtil.SpringContextUtil; | 
| import com.dy.common.util.DateTime; | 
| import com.dy.common.util.IDLongGenerator; | 
| import com.dy.pipIrrGlobal.util.Org; | 
| import org.apache.logging.log4j.LogManager; | 
| import org.apache.logging.log4j.Logger; | 
| import org.quartz.JobExecutionContext; | 
| import org.quartz.JobExecutionException; | 
|   | 
| import java.util.List; | 
|   | 
| /** | 
|  * @Author: liurunyu | 
|  * @Date: 2024/7/22 16:41 | 
|  * @Description | 
|  */ | 
| public class StatisticsJob extends TaskJob { | 
|   | 
|     private static Logger log = LogManager.getLogger(Test.class.getName()) ; | 
|   | 
|     private StLoss stLoss ; | 
|   | 
|     private StIntake stIntake ; | 
|   | 
|     private StClient stClient ; | 
|   | 
|     private Integer statisticsYear; | 
|     private Integer statisticsMonth; | 
|     private Long statisticsStartId ; | 
|     private Long statisticsEndId ; | 
|   | 
|     @Override | 
|     public void execute(JobExecutionContext ctx) throws JobExecutionException { | 
|         stLoss = SpringContextUtil.getBean(StLoss.class); | 
|         stIntake = SpringContextUtil.getBean(StIntake.class); | 
|         stClient = SpringContextUtil.getBean(StClient.class); | 
|         if(stLoss != null && stIntake != null && stClient != null){ | 
|             int[] ymd = DateTime.yyyy_MM_dd_2_ymdGroup(DateTime.yyyy_MM_dd()) ; | 
|             if(ymd[2] == 1){ | 
|                 //统计上个月的 | 
|                 String statisticsYyyy_mm = DateTime.lastMonth_ym() ; //统计年月 | 
|                 statisticsYear = Integer.parseInt(statisticsYyyy_mm.substring(0, 4)) ;//统计年 | 
|                 statisticsMonth = Integer.parseInt(statisticsYyyy_mm.substring(5, 7)) ;//统计月 | 
|                 statisticsStartId = IDLongGenerator.generateOneDayStartId(statisticsYear, statisticsMonth, 1) ; | 
|                 statisticsEndId = IDLongGenerator.generateOneDayEndId(statisticsYear, statisticsMonth, 31) ; | 
|             }else{ | 
|                 //统计本月的 | 
|                 statisticsYear = ymd[0] ;//统计月 | 
|                 statisticsMonth =  ymd[1] ;//统计月 | 
|                 statisticsStartId = IDLongGenerator.generateOneDayStartId(ymd[0], ymd[1], 1) ; | 
|                 statisticsEndId = IDLongGenerator.generateOneDayEndId(ymd[0], ymd[1], 31) ; | 
|             } | 
|             doStatistics() ; | 
|         }else{ | 
|             log.error("未能从Spring容器中得到统计bean"); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 统计 | 
|      */ | 
|     private void doStatistics(){ | 
|         List<Org.OrgVo> orgList = Org.OrgList ; | 
|         if(orgList != null && orgList.size() >0){ | 
|             for(Org.OrgVo vo : orgList){ | 
|                 DataSourceContext.set(vo.tag);//设置数据源 | 
|                 stLoss.statistics(statisticsYear, statisticsMonth, statisticsStartId, statisticsEndId) ; | 
|                 stIntake.statistics(statisticsYear, statisticsMonth, statisticsStartId, statisticsEndId) ; | 
|                 stClient.statistics(statisticsYear, statisticsMonth, statisticsStartId, statisticsEndId) ; | 
|             } | 
|         } | 
|     } | 
| } |