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

📄 subscribeservice.java

📁 手机业务程序例子
💻 JAVA
字号:
/*
 * SubscribeService.java
 *
 * Created on 2003年4月7日, 下午2:59
 */

package mobile.smsservice;
import gnu.getopt.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import mobile.smsserver.*;

/**
 *
 * @author  Administrator
 */
public class SubscribeService extends Service 
{
    	public static final String defaultPropertyFile= "/opt/smsserver/conf/mobile/smsservice/subscribe.properties";
	private String applicationDir;
	private static ServletAPI client;
        private Properties prop;
        
        private Vector dzService;
        
    /** Creates a new instance of SubscribeService */
    public SubscribeService(String PropertyFile) throws ServiceException
    {
         super(PropertyFile);
	 initLogger("SubscribeService");
         dzService=new Vector();
        
         try
	 {
            loadService();   
	    client= ServletAPI.getInstance();
            client.setServlet("unicomservlet");
	 }
         catch(MyServletException e)
	{
	     throw new ServiceException(e.getMessage());
	}
	log.info("SubscribeService ready");
    }
    
    private void loadService()
    {
            try{
                    prop=new Properties();
                    String serviceFile=serviceProperty.getProperty("service.file");
                    prop.load(new FileInputStream(serviceFile));
                    Enumeration e=prop.keys();
                    while(e.hasMoreElements())
                    {
                        String key=(String)e.nextElement();
                        String value=prop.getProperty(key);
                        dzService.add(value);
                     }
            }
            catch(Exception  e)
            {
                e.printStackTrace();
                log.error(e);
            }
    }
            
    
     /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        String propertyFileName=null;
	Getopt g= new Getopt( "SubscribeService", 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;
			}
		}
        	SubscribeService service=null;
		try
		{
			//System.out.println(propertyFileName);
			if( propertyFileName==null)
				service= new SubscribeService(defaultPropertyFile);
			else
				service= new SubscribeService(propertyFileName);
			service.connectDatabase();
			service.execute();
			service.disconnectDatabase();
			
		} catch(ServiceException e)
		{
			e.printStackTrace();
			System.err.println("Service init error:"+e.getMessage());
			System.exit(-1);
		}
    }
    
    public void execute() throws ServiceException 
    {
        String service,billingservice,hbillingservice;
         if( conn==null)
		throw new ServiceException("no database connection!");
	try
	{
	     Statement st= conn.createStatement();
            
             String operator=null;
	     for(int index=0;index<dzService.size();index++)
             {
                 
                 service=(String)dzService.get(index);
                 billingservice=service+"bill";
                 hbillingservice=service+"hbill";
                 
                 log.debug("Subscribe service:"+service);
		 ResultSet rs= st.executeQuery("select * from smsservice where enabled=1 and service='"+service+"'");
		 String srcTerm;
		 Calendar now=Calendar.getInstance();
		 int currentmonth=now.get(2);
                
		while( rs.next())
		{
		   srcTerm= rs.getString("srcterm");
                   operator=rs.getString("operator");
                   java.util.Date registerTime=rs.getDate("registertime");
                   if(registerTime.getDate()>15 && registerTime.getMonth()==currentmonth)
                       client.sendASCIIText(null,srcTerm, srcTerm, "fee information",hbillingservice,operator);
                   else
                       client.sendASCIIText(null,srcTerm, srcTerm, "fee information",billingservice,operator);
                   
                   log.debug("user:"+srcTerm+"   service:"+billingservice+"  operator:"+operator);
		}
                rs.close();
                log.debug("Unsubscribe service:"+service);
                
                rs=st.executeQuery("select srcterm,service,unsubscribetime,operator from smsservice where enabled=2 and service='"+service+"'");
                while(rs.next())
                {
                   srcTerm=rs.getString("srcterm");
                   operator=rs.getString("operator");    
                   java.util.Date unsubTime=rs.getDate("unsubscribetime");
                   
                   if(unsubTime.getDate()<15)
                       client.sendASCIIText(null,srcTerm, srcTerm, "fee information",hbillingservice,operator);
                    else
                           client.sendASCIIText(null,srcTerm,srcTerm,"fee information",billingservice,operator);
                   log.debug("user:"+srcTerm+"   service:"+billingservice+"  operator:"+operator);
                   //Reserve for extension 
               }                      
                 //cancle subscribed service,set enabled 0 if enabled=2
                 st.executeUpdate("update smsservice set enabled=0 where enabled=2 and service='"+service+"'"); 
              }
     }catch(Exception e)
	{
		e.printStackTrace();
		log.error(e);
	}
    }
    
    

    public static void printHelpMessage()
   {
	//p:c:f:a:d:s:t:eubh
	System.out.println("Sample: subscribeservice.sh -p subscribeservice.properties");
	System.out.println("p: property file name");
	System.out.println("h: this help message");
    }
}

⌨️ 快捷键说明

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