⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportservice.java

📁 手机业务程序例子
💻 JAVA
字号:
/*
 * SmsReport.java
 *
 * Created on 2003年4月14日, 下午5:27
 */

package mobile.smsservice;
import gnu.getopt.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import mobile.smsserver.*;
/**
 *
 * @author  Administrator
 */
public class ReportService extends Service {
    public static final String defaultPropertyFile= "/opt/smsserver/conf/mobile/smsservice/reportservice.properties";
    /** Creates a new instance of SmsReport */
    public ReportService(String propertyFile) throws ServiceException
    {
         super(propertyFile);
	 initLogger("ReportService");
         log.info("reportservice succeed in initizing!");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        String propertyFileName=null;
	Getopt g= new Getopt( "ReportService", args, "p:s:h");
	int c;
	while((c=g.getopt())!=-1)
	{
		switch (c)
		{
			case 'p':
				propertyFileName= g.getOptarg();
				break;
			case '?':
		        case 'h':
				SubscribeService.printHelpMessage();
				System.exit(0);
				break;
			}
		}
        	ReportService report=null;
		try
		{
			if( propertyFileName==null)
				report= new ReportService(defaultPropertyFile);
			else
				report= new ReportService(propertyFileName);
                        
                        report.connectDatabase();
			report.execute();
			report.disconnectDatabase();
			
		} catch(ServiceException e)
		{
			e.printStackTrace();
			System.err.println("reportservice init error:"+e.getMessage());
			System.exit(-1);
		}
    }
    
    public void execute() throws ServiceException
    {
        int nCorpid=0;
        int nStamp=0;
        int nSequence=0;
        int reportType=0;
        String srcTerm=null;
        int nState=0;
        int nErrorCode=0;
        int nField=0;
        if( conn==null)
	     throw new ServiceException("no database connection!");
        try{
               Statement dbst= conn.createStatement();
               String directory=serviceProperty.getProperty("service.logfile");
               Calendar now=Calendar.getInstance();
               now.add(Calendar.DATE,-1);
               java.util.Date beforenow=now.getTime();
               SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
               // Format the current date by the SimpleDateFormat object parameter
               final String dateString = sdf.format(beforenow);
             
               File dir= new File( directory);
	          if( ! dir.exists())
		     log.warn("Directory do not exist:"+directory);
	       if( dir.isDirectory())
		{
			log.info("Reloading application file!");
			File fs[]= dir.listFiles( new FilenameFilter()
			{
				public boolean accept(File dir, String name)
				{
					if( name.endsWith(dateString))
						return true;
					else
						return false;
				}
			});
			for( int i=0;i<fs.length;i++)
			{
				log.info("Loading report file:"+fs[i].getName());
		                RandomAccessFile reportfile=new RandomAccessFile(fs[i],"r");
                                String record=null;
                                while((record=reportfile.readLine())!=null)
                               { 
                                  StringTokenizer st = new StringTokenizer(record);
                                  while (st.hasMoreTokens())
                                  {
                                        switch(nField)
                                        {
                                           case 0:
                                              nCorpid=Integer.parseInt(st.nextToken());
                                              break;
                                           case 1:
                                              nStamp=Integer.parseInt(st.nextToken());
                                              break;
                                           case 2:
                                              nSequence=Integer.parseInt(st.nextToken());
                                              break;
                                          case 3:
                                              reportType=Integer.parseInt(st.nextToken());
                                              break;
                                          case 4:
                                             srcTerm=st.nextToken();
                                             break;
                                          case 5:
                                             nState=Integer.parseInt(st.nextToken());
                                             break;
                                          case 6:
                                            nErrorCode=Integer.parseInt(st.nextToken());
                                            break;
                                 }
                                 nField++;
                               }
                                  if(nState!=0)
                                  {
                                       dbst.executeUpdate("update gatewaylog set enable=0 where sourceid="+nCorpid+" and stamp="+nStamp+" and sequnceno="+nSequence);
                                       log.debug("CorpId:"+nCorpid+" stamp:"+nStamp+" Sequence:"+nSequence);
                                  }
                               nField=0;
                       }
                       reportfile.close();
                     }
                      dbst.close();
              }
            }
              catch(Exception e)
              {
                   e.printStackTrace();
              }
         }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -