?? online.java
字號(hào):
package oa.main;
import java.text.*;
import java.util.*;
import java.lang.*;
public class Online
{
public static Hashtable onlines = new Hashtable ( ) ;
//COUNT12345表示該人的短消息數(shù)量
//TIME12345表示該人的最后一次在線時(shí)間
//NEW12345是否有新消息
static
{
init ( ) ;
}
//初始化Tomcat時(shí)讀取每一個(gè)人的短消息數(shù)量,并且設(shè)置登陸時(shí)間為當(dāng)前時(shí)間前某一個(gè)時(shí)間
public static void init ( )
{
oa.bean.SmsBean sbean = new oa.bean.SmsBean ( ) ;
String sql = " select zz_zgb.zgbh,count(sms.id) as num "
+" from zz_zgb,sms "
+" where zz_zgb.zgbh=sms.receiver "
+" and sms.isread='0' "
+" group by zz_zgb.zgbh "
+" union "
+" select zgbh,0 "
+" from zz_zgb "
+" where zgbh not in "
+" (select zz_zgb.zgbh "
+" from zz_zgb,sms "
+" where zz_zgb.zgbh=sms.receiver "
+" and sms.isread='0' ) " ;
Vector vect = sbean.getDataBySql ( sql ) ;
for ( int i = 0 ; i < vect.size ( ) ; i++ )
{
Hashtable h = ( Hashtable ) vect.get ( i ) ;
onlines.put ( "COUNT" + ( String ) h.get ( "ZGBH" ) , ( String ) h.get ( "NUM" ) ) ;
onlines.put ( "NEW" + ( String ) h.get ( "ZGBH" ) , "0" ) ;
onlines.put ( "TIME" + ( String ) h.get ( "ZGBH" ) , "1970-01-01 00:00:00" ) ;
}
sbean.closeConn ( ) ;
}
//取得某人的短消息數(shù)量
public static int getSMSCount ( String uid )
{
String temp = ( String ) onlines.get ( "COUNT" + uid ) ;
if ( temp == null || temp.equals ( "" ) )
{
return -1 ;
}
else
{
return Integer.parseInt ( temp ) ;
}
}
//取得某人是否有新短消息
public static String getSMSNew ( String uid )
{
String temp = ( String ) onlines.get ( "NEW" + uid ) ;
if ( temp == null )
{
return "" ;
}
else
{
return temp ;
}
}
//取得默認(rèn)的最后在線時(shí)間
public static String getOnlineLastTime ( String uid )
{
String temp = ( String ) onlines.get ( "TIME" + uid ) ;
if ( temp == null || temp.equals ( "" ) )
{
return "1970-01-01 00:00:00" ;
}
else
{
return temp ;
}
}
//取得某人的新消息數(shù)量
public static int getDBSMSCount ( String uid )
{
int count = 0 ;
oa.bean.SmsBean sbean = new oa.bean.SmsBean ( ) ;
String sql = " select count(id) as sum from sms where receiver='" + uid + "' and isread='0' " ;
Vector vect = sbean.getDataBySql ( sql ) ;
if(vect.size()>0)
{
Hashtable h = ( Hashtable ) vect.get ( 0 ) ;
count = Integer.parseInt( ( String ) h.get ( "SUM" ) );
}
sbean.closeConn ( ) ;
return count ;
}
//在刪除某個(gè)發(fā)送者的消息之前,對(duì)他的所有接收者重新計(jì)算
public static void dealSenderTo ( String uid , String days )
{
oa.bean.SmsBean sbean = new oa.bean.SmsBean ( ) ;
String sql = " select receiver,count(id) as num from sms where sender='"+uid+"' and isread='0' and trunc(to_number(to_char(sysdate-to_date(sendtime,'YYYY-MM-DD HH24:MI:SS'))))>"+days+" group by receiver " ;
Vector vect = sbean.getDataBySql ( sql ) ;
for ( int i = 0 ; i < vect.size ( ) ; i++ )
{
Hashtable h = ( Hashtable ) vect.get ( i ) ;
String receiver = ( String ) h.get ( "RECEIVER" ) ;
int count = getSMSCount ( uid ) ;
count = count - Integer.parseInt ( ( String ) h.get ( "NUM" ) ) ;
onlines.put ( "COUNT" + receiver, count + "" ) ;
}
sbean.closeConn ( ) ;
}
//按照ID號(hào)重新處理
public static void dealofID ( String id )
{
oa.bean.SmsBean sbean = new oa.bean.SmsBean ( ) ;
String sql = " select distinct receiver from sms where id in ("+id+") " ;
Vector vect = sbean.getDataBySql ( sql ) ;
for ( int i = 0 ; i < vect.size ( ) ; i++ )
{
Hashtable h = ( Hashtable ) vect.get ( i ) ;
setSMSCount ( ( String ) h.get ( "RECEIVER" ) );
}
sbean.closeConn ( ) ;
}
//刪除
public static void DelofID ( String id )
{
oa.bean.SmsBean sbean = new oa.bean.SmsBean ( ) ;
String sql = " select receiver,count(id) as num from sms where id in("+id+") and isread='0' group by receiver " ;
Vector vect = sbean.getDataBySql ( sql ) ;
for ( int i = 0 ; i < vect.size ( ) ; i++ )
{
Hashtable h = ( Hashtable ) vect.get ( i ) ;
String receiver = ( String ) h.get ( "RECEIVER" ) ;
int count = getSMSCount ( receiver ) ;
count = count - Integer.parseInt ( ( String ) h.get ( "NUM" ) ) ;
onlines.put ( "COUNT" + receiver, count + "" ) ;
}
sbean.closeConn ( ) ;
}
public static void dealofSenderdel ( String id )
{
oa.bean.SmsBean sbean = new oa.bean.SmsBean ( ) ;
String sql = " select receiver,count(id) as num from sms where sender in("+id+") and isread='0' group by receiver " ;
Vector vect = sbean.getDataBySql ( sql ) ;
for ( int i = 0 ; i < vect.size ( ) ; i++ )
{
Hashtable h = ( Hashtable ) vect.get ( i ) ;
String receiver = ( String ) h.get ( "RECEIVER" ) ;
int count = getSMSCount ( receiver ) ;
count = count - Integer.parseInt ( ( String ) h.get ( "NUM" ) ) ;
onlines.put ( "COUNT" + receiver, count + "" ) ;
}
sbean.closeConn ( ) ;
}
//按照sender重新處理
public static void dealofSender ( String senderid )
{
oa.bean.SmsBean sbean = new oa.bean.SmsBean ( ) ;
String sql = " select distinct receiver from sms where sender='"+senderid+"'" ;
Vector vect = sbean.getDataBySql ( sql ) ;
for ( int i = 0 ; i < vect.size ( ) ; i++ )
{
Hashtable h = ( Hashtable ) vect.get ( i ) ;
setSMSCount ( ( String ) h.get ( "RECEIVER" ) );
}
sbean.closeConn ( ) ;
}
//按照receiver重新處理
public static void dealofReceiver ( String receiverid )
{
DealString ds = new DealString ( ) ;
String temp[] = ds.splitStr ( receiverid , ',' ) ;
for ( int i = 0 ; i < temp.length ; i++ )
{
setSMSCount ( temp[i] );
}
}
//設(shè)置某人的短消息數(shù)量+1
public static void add1SMSCount ( String uid )
{
//先查詢?cè)撊耸欠裨?jīng)有記錄,若沒有查庫(kù)
int count = getSMSCount ( uid ) ;
if ( count == -1 )
{
count = getDBSMSCount ( uid ) ;
}
count ++ ;
onlines.put ( "COUNT" + uid , count + "" ) ;
}
//設(shè)置有新短消息
public static void addSMSNew ( String uid )
{
onlines.put ( "NEW" + uid , "1" ) ;
}
//設(shè)置有新短消息
public static void delSMSNew ( String uid )
{
onlines.put ( "NEW" + uid , "0" ) ;
}
public static void setSMSCount ( String uid , int count )
{
onlines.put ( "COUNT" + uid , count + "" ) ;
}
public static void setSMSCount ( String uid )
{
int count = getDBSMSCount ( uid ) ;
onlines.put ( "COUNT" + uid , count + "" ) ;
}
//設(shè)置某人的短消息數(shù)量-1
public static void del1SMSCount ( String uid )
{
//先查詢?cè)撊耸欠裨?jīng)有記錄,若沒有查庫(kù)
int count = getSMSCount ( uid ) ;
if ( count > 0 )
{
count -- ;
onlines.put ( "COUNT" + uid , count + "" ) ;
}
}
//設(shè)置某人的最近在線時(shí)間
public static void setOnlineLastTime ( String uid )
{
oa.main.DealString ds = new oa.main.DealString ( ) ;
onlines.put ( "TIME" + uid , ds.getDateTime ( ) ) ;
}
public static void main ( String args[] )
{
System.out.println(Online.getSMSCount("997"));
}
//查詢某一個(gè)人
};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -