|  |  |  | 
|---|
|  |  |  | 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.JobDataMap; | 
|---|
|  |  |  | import org.quartz.JobExecutionContext; | 
|---|
|  |  |  | import org.quartz.JobExecutionException; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Author: liurunyu | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public class StatisticsJob extends TaskJob { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Logger log = LogManager.getLogger(Test.class.getName()) ; | 
|---|
|  |  |  | private static Logger log = LogManager.getLogger(StatisticsJob.class.getName()) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private StLoss stLoss ; | 
|---|
|  |  |  | private String orgTag ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private StIntake stIntake ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private StClient stClient ; | 
|---|
|  |  |  | private StLossAmount stLossAmount; | 
|---|
|  |  |  | private StIntakeAmount stIntakeAmount; | 
|---|
|  |  |  | private StClientAmount stClientAmount; | 
|---|
|  |  |  | private StChargeByIc stChargeByIc ; | 
|---|
|  |  |  | private StChargeByClient stChargeByClient ; | 
|---|
|  |  |  | private StConsumeByIc stConsumeByIc ; | 
|---|
|  |  |  | private StConsumeByClient stConsumeByClient ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Integer statisticsYear; | 
|---|
|  |  |  | private Integer statisticsMonth; | 
|---|
|  |  |  | private Long statisticsStartId ; | 
|---|
|  |  |  | private Long statisticsEndId ; | 
|---|
|  |  |  | private Integer statisticsDay; | 
|---|
|  |  |  | private Long statistics4DayStartId ; | 
|---|
|  |  |  | private Long statistics4DayEndId ; | 
|---|
|  |  |  | private Date statistics4DayStartDt ; | 
|---|
|  |  |  | private Date statistics4DayEndDt ; | 
|---|
|  |  |  | private Long statistics4MonthYearStartId ; | 
|---|
|  |  |  | private Long statistics4MonthYearEndId ; | 
|---|
|  |  |  | //private Date statistics4MonthYearStartDt ; | 
|---|
|  |  |  | //private Date statistics4MonthYearEndDt ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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){ | 
|---|
|  |  |  | JobDataMap jobDataMap = ctx.getJobDetail().getJobDataMap() ; | 
|---|
|  |  |  | if(jobDataMap != null){ | 
|---|
|  |  |  | orgTag = (String)jobDataMap.get(StatisticsListener.orgKey) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(orgTag == null){ | 
|---|
|  |  |  | return ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | DataSourceContext.set(orgTag);//设置数据源 | 
|---|
|  |  |  | stLossAmount = SpringContextUtil.getBean(StLossAmount.class); | 
|---|
|  |  |  | stIntakeAmount = SpringContextUtil.getBean(StIntakeAmount.class); | 
|---|
|  |  |  | stClientAmount = SpringContextUtil.getBean(StClientAmount.class); | 
|---|
|  |  |  | stChargeByIc = SpringContextUtil.getBean(StChargeByIc.class); | 
|---|
|  |  |  | stChargeByClient = SpringContextUtil.getBean(StChargeByClient.class); | 
|---|
|  |  |  | stConsumeByIc = SpringContextUtil.getBean(StConsumeByIc.class); | 
|---|
|  |  |  | stConsumeByClient = SpringContextUtil.getBean(StConsumeByClient.class); | 
|---|
|  |  |  | if(stLossAmount != null && stIntakeAmount != null && stClientAmount != null | 
|---|
|  |  |  | && stChargeByIc != null && stChargeByClient != null | 
|---|
|  |  |  | && stConsumeByIc != null && stConsumeByClient != null){ | 
|---|
|  |  |  | String yesterday = DateTime.lastXDay_yyyy_MM_dd(1) ;//得到昨天,零晨时刻统计,统计昨天的数 | 
|---|
|  |  |  | int[] yesterdayGrp = DateTime.yyyy_MM_dd_2_ymdGroup(yesterday) ; | 
|---|
|  |  |  | statisticsYear = yesterdayGrp[0] ;//统计年 | 
|---|
|  |  |  | statisticsMonth = yesterdayGrp[1] ;//统计月 | 
|---|
|  |  |  | statisticsDay = yesterdayGrp[2] ;//统计日 | 
|---|
|  |  |  | statistics4DayStartId = IDLongGenerator.generateOneDayStartId(statisticsYear, statisticsMonth, statisticsDay) ; | 
|---|
|  |  |  | statistics4DayEndId = IDLongGenerator.generateOneDayEndId(statisticsYear, statisticsMonth, statisticsDay) ; | 
|---|
|  |  |  | statistics4DayStartDt = DateTime.startOfDay(statisticsYear, statisticsMonth, statisticsDay) ; | 
|---|
|  |  |  | statistics4DayEndDt = DateTime.endOfDay(statisticsYear, statisticsMonth, statisticsDay) ; | 
|---|
|  |  |  | //统计日的量 | 
|---|
|  |  |  | doStatisticsDay() ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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) ; | 
|---|
|  |  |  | statistics4MonthYearStartId = IDLongGenerator.generateOneDayStartId(statisticsYear, statisticsMonth, 1) ; | 
|---|
|  |  |  | statistics4MonthYearEndId = IDLongGenerator.generateOneDayEndId(statisticsYear, statisticsMonth, DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; | 
|---|
|  |  |  | //statistics4MonthYearStartDt = DateTime.startOfDay(statisticsYear, statisticsMonth, 1) ; | 
|---|
|  |  |  | //statistics4MonthYearEndDt = DateTime.endOfDay(statisticsYear, statisticsMonth, DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //统计本月的 | 
|---|
|  |  |  | statisticsYear = ymd[0] ;//统计年 | 
|---|
|  |  |  | statisticsMonth =  ymd[1] ;//统计月 | 
|---|
|  |  |  | statisticsStartId = IDLongGenerator.generateOneDayStartId(ymd[0], ymd[1], 1) ; | 
|---|
|  |  |  | statisticsEndId = IDLongGenerator.generateOneDayEndId(ymd[0], ymd[1], 31) ; | 
|---|
|  |  |  | statistics4MonthYearStartId = IDLongGenerator.generateOneDayStartId(ymd[0], ymd[1], 1) ; | 
|---|
|  |  |  | statistics4MonthYearEndId = IDLongGenerator.generateOneDayEndId(ymd[0], ymd[1], DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; | 
|---|
|  |  |  | //statistics4MonthYearStartDt = DateTime.startOfDay(statisticsYear, statisticsMonth, 1) ; | 
|---|
|  |  |  | //statistics4MonthYearEndDt = DateTime.endOfDay(statisticsYear, statisticsMonth, DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | doStatistics() ; | 
|---|
|  |  |  | doStatisticsMonthAndYear() ; | 
|---|
|  |  |  | }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) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private void doStatisticsDay(){ | 
|---|
|  |  |  | stClientAmount.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statistics4DayStartId, statistics4DayEndId) ; | 
|---|
|  |  |  | //stChargeByIc.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statistics4DayStartId, statistics4DayEndId); | 
|---|
|  |  |  | //stChargeByClient.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statistics4DayStartId, statistics4DayEndId); | 
|---|
|  |  |  | //stConsumeByIc.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statistics4DayStartDt, statistics4DayEndDt); | 
|---|
|  |  |  | //stConsumeByClient.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statistics4DayStartDt, statistics4DayEndDt); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 统计 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void doStatisticsMonthAndYear(){ | 
|---|
|  |  |  | stLossAmount.statistics(statisticsYear, statisticsMonth, statistics4MonthYearStartId, statistics4MonthYearEndId) ; | 
|---|
|  |  |  | stIntakeAmount.statistics(statisticsYear, statisticsMonth, statistics4MonthYearStartId, statistics4MonthYearEndId) ; | 
|---|
|  |  |  | stClientAmount.statistics(statisticsYear, statisticsMonth, statistics4MonthYearStartId, statistics4MonthYearEndId) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //stChargeByIc.statistics4MonthAndYear(statisticsYear, statisticsMonth); | 
|---|
|  |  |  | //stChargeByClient.statistics4MonthAndYear(statisticsYear, statisticsMonth); | 
|---|
|  |  |  | //stConsumeByIc.statistics4MonthAndYear(statisticsYear, statisticsMonth); | 
|---|
|  |  |  | //stConsumeByClient.statistics4MonthAndYear(statisticsYear, statisticsMonth); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|