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

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

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

    馬光軍--------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 {

        
    /**
         * 定時運行的方法
         
    */
        
    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+"】分類文獻信息" ;
                            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>
        
        
    <!--定義定時執(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)鍵在配置此表達式 每天中午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)定時運行程序!

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

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


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 亚洲中文字幕无码一区| 无码国产精品一区二区免费16| 日韩免费无码视频一区二区三区| 亚洲欧洲一区二区三区| 99精品一区二区免费视频| 亚洲成a人片在线观看天堂无码 | 国产99久久亚洲综合精品| 噼里啪啦电影在线观看免费高清| 午夜亚洲国产精品福利| 久久久久无码精品亚洲日韩| 最新亚洲成av人免费看| 中文字幕亚洲综合小综合在线| 亚洲第一区在线观看| 日本zzzzwww大片免费| 久久久久亚洲精品天堂| 免费观看激色视频网站(性色)| 国产精品亚洲天堂| 亚洲精品在线播放视频| 亚洲一区二区三区国产精品| 2019中文字幕在线电影免费 | 一个人免费观看视频在线中文| 亚洲欧洲日产国产最新| 国产亚洲一区二区三区在线不卡| 一级免费黄色毛片| 亚洲中文字幕无码久久2020| 国产综合成人亚洲区| 国产免费福利体检区久久| 自拍偷自拍亚洲精品偷一| 色婷婷7777免费视频在线观看| 2020年亚洲天天爽天天噜| 亚洲最大激情中文字幕| 午夜网站免费版在线观看| 亚洲av日韩综合一区久热| 亚洲色四在线视频观看| 久久久久噜噜噜亚洲熟女综合| 免费看美女让人桶尿口| 免费看国产成年无码AV片| 午夜免费福利片观看| 97在线视频免费公开视频| 男女污污污超污视频免费在线看| 国产亚洲sss在线播放|