| | |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | private static Logger log = LogManager.getLogger(Test.class.getName()) ; |
| | | |
| | | private StLoss stLoss ; |
| | | |
| | | private StIntake stIntake ; |
| | | |
| | | private StClient stClient ; |
| | | private StChargeByIc stChargeByIc ; |
| | | private StChargeByClient stChargeByClient ; |
| | | private StConsumeByIc stConsumeByIc ; |
| | | private StConsumeByClient stConsumeByClient ; |
| | | |
| | | private Integer statisticsYear; |
| | | private Integer statisticsMonth; |
| | | private Integer statisticsDay; |
| | | private Long statisticsStartId ; |
| | | private Long statisticsEndId ; |
| | | private Date statisticsStartDt ; |
| | | private Date statisticsEndDt ; |
| | | |
| | | @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){ |
| | | stChargeByIc = SpringContextUtil.getBean(StChargeByIc.class); |
| | | stChargeByClient = SpringContextUtil.getBean(StChargeByClient.class); |
| | | stConsumeByIc = SpringContextUtil.getBean(StConsumeByIc.class); |
| | | stConsumeByClient = SpringContextUtil.getBean(StConsumeByClient.class); |
| | | if(stLoss != null && stIntake != null && stClient != 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] ;//统计日 |
| | | statisticsStartId = IDLongGenerator.generateOneDayStartId(statisticsYear, statisticsMonth, 1) ; |
| | | statisticsEndId = IDLongGenerator.generateOneDayEndId(statisticsYear, statisticsMonth, DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; |
| | | statisticsStartDt = DateTime.startOfDay(statisticsYear, statisticsMonth, statisticsDay) ; |
| | | statisticsEndDt = DateTime.endOfDay(statisticsYear, statisticsMonth, statisticsDay) ; |
| | | //统计日的量 |
| | | doStatisticsDay() ; |
| | | |
| | | int[] ymd = DateTime.yyyy_MM_dd_2_ymdGroup(DateTime.yyyy_MM_dd()) ; |
| | | if(ymd[2] == 1){ |
| | | //统计上个月的 |
| | |
| | | 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) ; |
| | | statisticsEndId = IDLongGenerator.generateOneDayEndId(statisticsYear, statisticsMonth, DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; |
| | | statisticsStartDt = DateTime.startOfDay(statisticsYear, statisticsMonth, 1) ; |
| | | statisticsEndDt = 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) ; |
| | | statisticsEndId = IDLongGenerator.generateOneDayEndId(ymd[0], ymd[1], DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; |
| | | statisticsStartDt = DateTime.startOfDay(statisticsYear, statisticsMonth, 1) ; |
| | | statisticsEndDt = DateTime.endOfDay(statisticsYear, statisticsMonth, DateTime.endDayOfMonth(statisticsYear, statisticsMonth)) ; |
| | | } |
| | | doStatistics() ; |
| | | doStatisticsMonthAndYear() ; |
| | | }else{ |
| | | log.error("未能从Spring容器中得到统计bean"); |
| | | } |
| | |
| | | /** |
| | | * 统计 |
| | | */ |
| | | private void doStatistics(){ |
| | | private void doStatisticsDay(){ |
| | | List<Org.OrgVo> orgList = Org.OrgList ; |
| | | if(orgList != null && orgList.size() >0){ |
| | | for(Org.OrgVo vo : orgList){ |
| | | DataSourceContext.set(vo.tag);//设置数据源 |
| | | stChargeByIc.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statisticsStartId, statisticsEndId); |
| | | stChargeByClient.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statisticsStartId, statisticsEndId); |
| | | stConsumeByIc.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statisticsStartDt, statisticsEndDt); |
| | | stConsumeByClient.statistics4Day(statisticsYear, statisticsMonth, statisticsDay, statisticsStartDt, statisticsEndDt); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 统计 |
| | | */ |
| | | private void doStatisticsMonthAndYear(){ |
| | | List<Org.OrgVo> orgList = Org.OrgList ; |
| | | if(orgList != null && orgList.size() >0){ |
| | | for(Org.OrgVo vo : orgList){ |
| | |
| | | stLoss.statistics(statisticsYear, statisticsMonth, statisticsStartId, statisticsEndId) ; |
| | | stIntake.statistics(statisticsYear, statisticsMonth, statisticsStartId, statisticsEndId) ; |
| | | stClient.statistics(statisticsYear, statisticsMonth, statisticsStartId, statisticsEndId) ; |
| | | |
| | | stChargeByIc.statistics4MonthAndYear(statisticsYear, statisticsMonth); |
| | | stChargeByClient.statistics4MonthAndYear(statisticsYear, statisticsMonth); |
| | | stConsumeByIc.statistics4MonthAndYear(statisticsYear, statisticsMonth); |
| | | stConsumeByClient.statistics4MonthAndYear(statisticsYear, statisticsMonth); |
| | | } |
| | | } |
| | | } |