package sy.timingTask; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; import oracle.sql.DATE; import org.springframework.beans.factory.annotation.Autowired; import sy.pageModel.Json; import sy.pageModel.Online; import sy.service.OnlineServiceI; import com.alibaba.druid.support.http.stat.WebAppStatManager; import com.alibaba.fastjson.JSON; public class OnlineJob { //来自druid.jar private final WebAppStatManager webAppStatManager = WebAppStatManager.getInstance(); private OnlineServiceI onlineService; public OnlineServiceI getOnlineService() { return onlineService; } @Autowired public void setOnlineService(OnlineServiceI onlineService) { this.onlineService = onlineService; } @SuppressWarnings("unchecked") public void onlineofuser() { //来自druid.jar中 获得session信息 List<Map<String, Object>> list = webAppStatManager.getSessionStatData(); Online online = new Online(); //查询数据库中在线用户 List<Online> listonline = onlineService.datagrid(online).getRows(); boolean result =false; for(int j=0;j<listonline.size();j++ ) { result = false; for(int i = 0;i<list.size();i++) { Map<String, Object> map = list.get(i); //map.get("Principal")得到的是登录系统的用户 //map.get("RemoteAddress")得到远程访问的ip地址 if(map.get("Principal")!=null&&!("").equals(map.get("Principal"))) { if(map.get("Principal").equals(listonline.get(j).getLoginname())&&map.get("RemoteAddress").equals(listonline.get(j).getIp())) { Long currenttime = new Date().getTime(); System.out.println(currenttime +" - "+((Date)map.get("LastAccessTime")).getTime()+" = "+ (currenttime-((Date)map.get("LastAccessTime")).getTime())); if(currenttime-((Date)map.get("LastAccessTime")).getTime()<1000*60*5)//因为页面有ajax每10秒就发送请求,所以5分钟没有访问,则是关闭浏览器 { System.out.println(map.get("Principal")+"---"+map.get("RemoteAddress")); result=true ; break; } } } } if(!result) { //根据IP和用户,删除数据库中的信息 onlineService.deleteTonlineByLoginNameAndIp(listonline.get(j).getLoginname(),listonline.get(j).getIp()); } } } }

yyw520 LV2
2020年6月22日
qiheideguang LV18
2019年10月17日
cafebabeio LV1
2019年10月14日
jisen LV7
2019年5月10日
月之氏族 LV23
2019年3月21日
jianjianzhang LV1
2018年6月16日
wxjwhqwy LV29
2018年6月3日
394934420 LV1
2018年3月16日
a364462221 LV1
2018年3月8日
liuna9876 LV7
2017年9月19日

denglu123321 LV4
2023年12月27日
cc900118 LV17
2022年12月5日
lcjz99 LV11
2022年9月28日
a3870764722a LV22
2022年7月12日
740330437 LV1
2022年6月19日
Hachi6 LV13
2022年6月16日
无敌波 LV1
2021年9月14日
xiaoding1999 LV7
2021年7月15日
王天麟 LV12
2021年1月22日
一哥simon LV1
2021年1月5日