📄 online.java
字号:
package oa.main;
import java.text.*;
import java.util.*;
import java.lang.*;
public class Online
{
public static Hashtable onlines = new Hashtable ( ) ;
//COUNT12345表示该人的短消息数量
//TIME12345表示该人的最后一次在线时间
//NEW12345是否有新消息
static
{
init ( ) ;
}
//初始化Tomcat时读取每一个人的短消息数量,并且设置登陆时间为当前时间前某一个时间
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 ( ) ;
}
//取得某人的短消息数量
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 ;
}
}
//取得默认的最后在线时间
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 ;
}
}
//取得某人的新消息数量
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 ;
}
//在删除某个发送者的消息之前,对他的所有接收者重新计算
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号重新处理
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] );
}
}
//设置某人的短消息数量+1
public static void add1SMSCount ( String uid )
{
//先查询该人是否曾经有记录,若没有查库
int count = getSMSCount ( uid ) ;
if ( count == -1 )
{
count = getDBSMSCount ( uid ) ;
}
count ++ ;
onlines.put ( "COUNT" + uid , count + "" ) ;
}
//设置有新短消息
public static void addSMSNew ( String uid )
{
onlines.put ( "NEW" + uid , "1" ) ;
}
//设置有新短消息
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 + "" ) ;
}
//设置某人的短消息数量-1
public static void del1SMSCount ( String uid )
{
//先查询该人是否曾经有记录,若没有查库
int count = getSMSCount ( uid ) ;
if ( count > 0 )
{
count -- ;
onlines.put ( "COUNT" + uid , count + "" ) ;
}
}
//设置某人的最近在线时间
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"));
}
//查询某一个人
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -