<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

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

    BlogJava 聯系 聚合 管理
      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 {

        
    /**
         * 定時運行的方法
         
    */
        
    private BaseDAO baseDaoImpl;

        @SuppressWarnings({ 
    "unchecked""deprecation" })
        
    public void startRun() throws Exception {
            
    // 第一,查詢類型表中的規則
            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);
                
    //此方法只能適應與 月報
                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{
    //                        有數據 加分
                            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{
    //                        沒有數據 為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+"】分類文獻信息" ;
                            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">

        
    <!-- 定時運行的類 -->
        
    <bean id="scheduledTimer"
            class
    ="com.strongit.zwjc.infopush.vo.ScheduledTimer">
            
    <property name="baseDaoImpl">
                
    <ref bean="baseDAO" />
            
    </property>
        
    </bean>
        
        
    <!--定義定時執行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>

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

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

    </beans>

    兩者結合就能實現定時運行程序!

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

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲AⅤ无码一区二区三区在线| 免费av欧美国产在钱| 国产免费黄色大片| 亚洲国产欧美一区二区三区 | 亚洲中文字幕一区精品自拍| 精品福利一区二区三区免费视频| 久久久婷婷五月亚洲97号色| 59pao成国产成视频永久免费| 亚洲高清不卡视频| 免费国产成人高清在线观看网站| 激情亚洲一区国产精品| 国产精品视频永久免费播放| 亚洲国产成人手机在线观看| 国产网站在线免费观看| 一级做a毛片免费视频| 亚洲精品无码mv在线观看网站 | 毛片免费全部免费观看| 亚洲综合小说另类图片动图 | 在线观看片免费人成视频无码| 亚洲成AV人片在线观看无码 | 99热这里只有精品免费播放| 亚洲成人免费网址| 成人超污免费网站在线看| 美女啪啪网站又黄又免费| 亚洲免费日韩无码系列| 99精品视频免费观看| 亚洲深深色噜噜狠狠网站| 免费真实播放国产乱子伦| 99久久免费国产精品热| 亚洲国产成人久久| 免费看国产精品麻豆| 久久免费高清视频| 中文字幕精品三区无码亚洲| 亚洲AV之男人的天堂| 日韩精品久久久久久免费| 涩涩色中文综合亚洲| 亚洲一区二区女搞男| 免费看污成人午夜网站| 成人免费网站久久久| 亚洲大香伊人蕉在人依线| 亚洲成a人片在线观看老师|