馬光軍--------BLOG

          BlogJava 聯(lián)系 聚合 管理
            1 Posts :: 25 Stories :: 5 Comments :: 0 Trackbacks
          (1)ScheduledTimer.java:
          package com.strongit.zwjc.infopush.vo;

          import java.util.Calendar;
          import java.util.Date;
          import java.util.List;

          import com.strongit.zwjc.common.dao.BaseDAO;
          import com.strongit.zwjc.infopush.po.Afficheinfo;
          import com.strongit.zwjc.infopush.po.InfopushDocClass;
          import com.strongit.zwjc.infopush.po.Performance;
          import com.strongit.zwjc.util.TimeKit1;

          /**
           * 定一個定時查詢的類
           
          */

          public class ScheduledTimer {

              
          /**
               * 定時運(yùn)行的方法
               
          */
              
          private BaseDAO baseDaoImpl;

              @SuppressWarnings({ 
          "unchecked""deprecation" })
              
          public void startRun() throws Exception {
                  
          // 第一,查詢類型表中的規(guī)則
                  Calendar now = Calendar.getInstance();
                  @SuppressWarnings(
          "unused")
                  
          int nowDay = now.get(Calendar.DAY_OF_MONTH);
                  
          int nowMonth = now.get(Calendar.MONTH) + 1;
                  List
          <InfopushDocClass> InfopushClassList = this.baseDaoImpl
                          .findAll(InfopushDocClass.
          class);
                  String docPushRule 
          = "monthly:15";
                  @SuppressWarnings(
          "unused")
                  String monthly 
          = "";
                  String strDay 
          = "";
                  
          int intDay = 0;
                  String classId 
          = "";
                  String className 
          = "" ;
                  String orgId 
          = "";
                  String orgName 
          = "orgName" ;
                  
          //InfopushDoc infopushDoc = null;
                  List infopushDocList = null ;
                  Performance performance 
          = null ;
                  Afficheinfo afficheinfo 
          = null ;
                  String strSfficheinfo 
          = "" ;
                  List
          <Performance> performanceList = null ;
                  Date performanceDate 
          = TimeKit1.getDateByString(TimeKit1.now("short"));
                  
          for (InfopushDocClass infopushDocClass : InfopushClassList) {
                      docPushRule 
          = infopushDocClass.getDocPushRule();
                      classId 
          = infopushDocClass.getClassId();
                      orgId 
          = infopushDocClass.getOrgId();
                      monthly 
          = docPushRule.split(":")[0];
                      strDay 
          = docPushRule.split(":")[1];
                      intDay 
          = Integer.parseInt(strDay);
                      
          //此方法只能適應(yīng)與 月報
                      if (nowDay == intDay) {
                          infopushDocList 
          = this.baseDaoImpl
                                  .findAll(
          "FROM InfopushDoc idoc where idoc.infopushDocClass.classId='"
                                          
          + classId
                                          
          + "' and idoc.orgId = '"
                                          
          + orgId
                                          
          + "'");
                          
                          
          int totalsize = infopushDocList.size() ;
                          
                          performanceList 
          = this.baseDaoImpl.findAll(Performance.class);
                          
          if(totalsize>0){
                              
          boolean flag = false ;
                              
          for(Performance performance2:performanceList){
                                  
          int performanceMonth = performance2.getPerformanceDate().getMonth()+1 ;
                                  
          if(nowMonth==performanceMonth){
                                      flag 
          = true ;
                                      
          break ;
                                  }
                              }
                              
          if(flag){
                              }
          else{
          //                        有數(shù)據(jù) 加分
                                  className = infopushDocClass.getClassName() ;
                                  orgName 
          = infopushDocClass.getOrgName() ;
                                  performance 
          = new Performance() ;
                                  performance.setClassId(classId);
                                  performance.setOrgId(orgId);
                                  performance.setOrgName(orgName);
                                  performance.setClassName(className);
                                  performance.setPerformanceDate(performanceDate);
                                  performance.setScore(Long.valueOf(
          "1"));
                                  
          this.baseDaoImpl.insert(performance);
                              }
                          }
          else{
                              
          boolean flag = false ;
                              
          for(Performance performance2:performanceList){
                                  
          int performanceMonth = performance2.getPerformanceDate().getMonth()+1 ;
                                  
          if(nowMonth==performanceMonth){
                                      flag 
          = true ;
                                      
          break ;
                                  }
                              }
                              
          if(flag){
                              }
          else{
          //                        沒有數(shù)據(jù) 為0分,并且通報
                                  orgName = infopushDocClass.getOrgName() ;
                                  className 
          = infopushDocClass.getClassName() ;
                                  performance 
          = new Performance() ;
                                  performance.setClassId(classId);
                                  performance.setClassName(className);
                                  performance.setOrgId(orgId);
                                  performance.setOrgName(orgName);
                                  performance.setPerformanceDate(performanceDate);
                                  performance.setScore(Long.valueOf(
          "0"));
                                  
          this.baseDaoImpl.insert(performance);
                                  
                                  className 
          = infopushDocClass.getClassName() ;
                                  afficheinfo 
          = new Afficheinfo() ;
                                  afficheinfo.setClassId(classId);
                                  afficheinfo.setOrgId(orgId);
                                  afficheinfo.setAfficheinfoDate(performanceDate);
                                  strSfficheinfo 
          = ""+TimeKit1.getNowDate()+"】【"+orgName+"】未推送【"+className+"】分類文獻(xiàn)信息" ;
                                  afficheinfo.setAfficheInfo(strSfficheinfo);
                                  afficheinfo.setClassName(className);
                                  afficheinfo.setOrgName(orgName);
                                  
          this.baseDaoImpl.insert(afficheinfo);
                              }
                          }
                      }
                  }
                  System.out.println(
          "成功插入??!");
              }

              
          public BaseDAO getBaseDaoImpl() {
                  
          return baseDaoImpl;
              }

              
          public void setBaseDaoImpl(BaseDAO baseDaoImpl) {
                  
          this.baseDaoImpl = baseDaoImpl;
              }

          }
          applicationContext-infopush-timer.xml:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

              
          <!-- 定時運(yùn)行的類 -->
              
          <bean id="scheduledTimer"
                  class
          ="com.strongit.zwjc.infopush.vo.ScheduledTimer">
                  
          <property name="baseDaoImpl">
                      
          <ref bean="baseDAO" />
                  
          </property>
              
          </bean>
              
              
          <!--定義定時執(zhí)行ScheduledTimer類中  的startRun()方法-->
              
          <bean id="scheduledTask"
                  class
          ="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                  
          <property name="targetObject">
                      
          <ref bean="scheduledTimer" />
                  
          </property>
                  
          <property name="targetMethod">
                      
          <value>startRun</value>
                  
          </property>
              
          </bean>

              
          <!--觸發(fā)器的bean的設(shè)置,在這里我們設(shè)置了我們要觸發(fā)的jobDetail是哪個。
                  這里我們定義了要觸發(fā)的jobDetail,即觸發(fā)器去觸發(fā)哪個bean..并且我們還定義了觸發(fā)的時間
          -->
              
          <bean id="cronTrigger"
                  class
          ="org.springframework.scheduling.quartz.CronTriggerBean">
                  
          <property name="jobDetail">
                      
          <ref bean="scheduledTask" />
                  
          </property>
                  
          <property name="cronExpression">
          <!--             關(guān)鍵在配置此表達(dá)式 每天中午12點鐘整觸發(fā)事件-->
                      
          <value>0 0 12 * * ?</value>
                  
          </property>
              
          </bean>

              
          <!--管理觸發(fā)器的總設(shè)置,可以放置多個觸發(fā)器。-->
              
          <bean autowire="no"
                  class
          ="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                  
          <property name="triggers">
                      
          <list>
                          
          <ref bean="cronTrigger" />
                      
          </list>
                  
          </property>
              
          </bean>

          </beans>

          兩者結(jié)合就能實現(xiàn)定時運(yùn)行程序!

          posted on 2008-12-02 22:27 馬光軍 閱讀(1351) 評論(0)  編輯  收藏 所屬分類: Spring2.xSpring1.x

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 客服| 潜山县| 札达县| 乌拉特前旗| 如东县| 巨野县| 东丽区| 崇礼县| 卓尼县| 张家川| 永吉县| 房山区| 麦盖提县| 敦化市| 河源市| 建宁县| 东港市| 土默特右旗| 土默特左旗| 资源县| 安徽省| 尖扎县| 荆州市| 普兰店市| 龙陵县| 湛江市| 开鲁县| 仁怀市| 通州区| 栖霞市| 雷州市| 莫力| 万荣县| 成武县| 华容县| 龙州县| 武威市| 望都县| 吴桥县| 麻江县| 东兰县|