📄 statvarsservice.java
字号:
package cn.jsprun.foreg.service;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.Map.Entry;
import org.apache.struts.util.MessageResources;
import cn.jsprun.dao.DataBaseDao;
import cn.jsprun.dao.StatsDao;
import cn.jsprun.dao.StatvarsDao;
import cn.jsprun.domain.Stats;
import cn.jsprun.domain.StatsId;
import cn.jsprun.domain.Statvars;
import cn.jsprun.domain.StatvarsId;
import cn.jsprun.foreg.vo.statistic.CompositorInfo;
import cn.jsprun.foreg.vo.statistic.PageInfo;
import cn.jsprun.foreg.vo.statistic.PageInfoWithImage;
import cn.jsprun.foreg.vo.statistic.Stats_CompositorVO;
import cn.jsprun.foreg.vo.statistic.Stats_agentVO;
import cn.jsprun.foreg.vo.statistic.Stats_creditComposidorVO;
import cn.jsprun.foreg.vo.statistic.Stats_mainVO;
import cn.jsprun.foreg.vo.statistic.Stats_forumsrankVO;
import cn.jsprun.foreg.vo.statistic.Stats_manageStatisticVO;
import cn.jsprun.foreg.vo.statistic.Stats_manageTeamVO;
import cn.jsprun.foreg.vo.statistic.Stats_navbarVO;
import cn.jsprun.foreg.vo.statistic.Stats_onlineCompositorVO;
import cn.jsprun.foreg.vo.statistic.Stats_postsLogVO;
import cn.jsprun.foreg.vo.statistic.Stats_tradeCompositorVO;
import cn.jsprun.foreg.vo.statistic.Stats_viewsVO;
import cn.jsprun.foreg.vo.statistic.SubPostlog;
import cn.jsprun.foreg.vo.statistic.Stats_creditComposidorVO.LineObject;
import cn.jsprun.foreg.vo.statistic.Stats_creditComposidorVO.LineObject.CreditInfo;
import cn.jsprun.foreg.vo.statistic.Stats_manageStatisticVO.ContentInfo;
import cn.jsprun.foreg.vo.statistic.Stats_manageStatisticVO.TimeInfo;
import cn.jsprun.foreg.vo.statistic.Stats_manageTeamVO.ForumTableGroup;
import cn.jsprun.foreg.vo.statistic.Stats_manageTeamVO.ForumTableGroup.Forum;
import cn.jsprun.utils.BeanFactory;
import cn.jsprun.utils.Common;
import cn.jsprun.utils.DataParse;
public class StatvarsService {
private final String tableprefix = "jrun_";
private static DecimalFormat df = new DecimalFormat("0.00");
public boolean allowAccess(Map<String,String> groupMap){
String allowviewstatString = groupMap.get("allowviewstats");
if(allowviewstatString!=null){
Byte allowviewstats = Byte.valueOf(allowviewstatString);
if(allowviewstats==1){
return true;
}else{
return false;
}
}else{
return true;
}
}
public boolean checkUserid(String uid){
List<Map<String,String>> tempML = ((DataBaseDao)BeanFactory.getBean("dataBaseDao")).executeQuery("SELECT username FROM "+tableprefix+"members WHERE uid='"+uid+"' AND adminid>'0'");
return tempML != null && tempML.size()>0;
}
public Stats_mainVO getFinalStats_mainVO(Map<String, String> settingsMap,int timestamp,float timeoffset){
String tempS = settingsMap.get("statstatus");
boolean statstatus = tempS!=null && !"".equals(tempS) && !"0".equals(tempS);
tempS = settingsMap.get("modworkstatus");
boolean modworkstatus = tempS!=null && !"".equals(tempS) && !"0".equals(tempS);
DataBaseDao dataBaseDao = (DataBaseDao)BeanFactory.getBean("dataBaseDao");
Map<String,String> statvars = getFinalMap("main",dataBaseDao);
tempS = statvars.get("lastupdate");
int lastupdate = tempS == null ? 0 : Integer.parseInt(tempS);
Double statscachelife = Double.valueOf(settingsMap.get("statscachelife"));
statscachelife = statscachelife * 60;
List<String> newstatvars = new ArrayList<String>();
if(timestamp - lastupdate > statscachelife){
statvars.clear();
statvars.put("lastupdate", timestamp+"");
newstatvars.add("'main', 'lastupdate', '"+timestamp+"'");
}
Stats_mainVO stats_mainVO = new Stats_mainVO();
tempS = statvars.get("forums");
if(tempS != null){
stats_mainVO.setFormsCount(tempS);
}else{
tempS = getForumCount(dataBaseDao);
stats_mainVO.setFormsCount(tempS);
newstatvars.add("'main', 'forums', '"+tempS+"'");
}
tempS = statvars.get("threads");
if(tempS != null){
stats_mainVO.setThreadNum(tempS);
}else{
tempS = getThreadCount(dataBaseDao);
stats_mainVO.setThreadNum(tempS);
newstatvars.add("'main', 'threads', '"+tempS+"'");
}
tempS = statvars.get("runtime");
String tempS2 = statvars.get("posts");
if(tempS != null && tempS2 != null){
stats_mainVO.setRuntime(tempS);
stats_mainVO.setPostsNum(tempS2);
}else{
Map<String,String> tm = getRunTimeAdPost(dataBaseDao);
tempS = tm.get("rt");
tempS2 = tm.get("ct");
stats_mainVO.setRuntime(tempS);
stats_mainVO.setPostsNum(tempS2);
newstatvars.add("'main', 'runtime', '"+tempS+"'");
newstatvars.add("'main', 'posts', '"+tempS2+"'");
}
tempS = statvars.get("members");
if(tempS!=null){
stats_mainVO.setMembersNum(tempS);
}else{
tempS = getMemberCount(dataBaseDao);
stats_mainVO.setMembersNum(tempS);
newstatvars.add("'main', 'members', '"+tempS+"'");
}
tempS = statvars.get("postsaddtoday");
if(tempS != null){
stats_mainVO.setAddPostsInLast24(tempS);
}else{
tempS = getAddPostsInLast24(dataBaseDao,timestamp);
stats_mainVO.setAddPostsInLast24(tempS);
newstatvars.add("'main', 'postsaddtoday', '"+tempS+"'");
}
tempS = statvars.get("membersaddtoday");
if(tempS != null){
stats_mainVO.setAddMemberInLast24(tempS);
}else{
tempS = getAddMemberInLast24(dataBaseDao,timestamp);
stats_mainVO.setAddMemberInLast24(tempS);
newstatvars.add("'main', 'membersaddtoday', '"+tempS+"'");
}
tempS = statvars.get("admins");
if(tempS != null){
stats_mainVO.setMemberOfManageNum(tempS);
}else{
tempS = getAdminNum(dataBaseDao);
stats_mainVO.setMemberOfManageNum(tempS);
newstatvars.add("'main', 'admins', '"+tempS+"'");
}
tempS = statvars.get("memnonpost");
if(tempS != null){
stats_mainVO.setMembersOfNoPostsNum(tempS);
}else{
tempS = getNonPost(dataBaseDao);
stats_mainVO.setMembersOfNoPostsNum(tempS);
newstatvars.add("'main', 'memnonpost', '"+tempS+"'");
}
tempS = statvars.get("hotforum");
if(tempS != null){
Map<String,String> beanModuleInfo = ((DataParse)BeanFactory.getBean("dataParse")).characterParse(tempS,false);
stats_mainVO.setBestModule(beanModuleInfo.get("name"));
stats_mainVO.setBestModuleID(beanModuleInfo.get("fid"));
stats_mainVO.setBestModuleThreadNum(beanModuleInfo.get("threads"));
stats_mainVO.setBestModulePostsNum(beanModuleInfo.get("posts"));
}else{
Map<String,String> tm = getHotforumInfo(dataBaseDao);
stats_mainVO.setBestModule(tm.get("name"));
stats_mainVO.setBestModuleID(tm.get("fid"));
stats_mainVO.setBestModuleThreadNum(tm.get("threads"));
stats_mainVO.setBestModulePostsNum(tm.get("posts"));
newstatvars.add("'main', 'hotforum', '"+((DataParse)BeanFactory.getBean("dataParse")).combinationChar(tm)+"'");
}
tempS = statvars.get("bestmem");
tempS2 = statvars.get("bestmemposts");
if(tempS != null && tempS2 != null){
stats_mainVO.setBestMem(tempS);
stats_mainVO.setBestMemPosts(tempS2);
}else{
Map<String,String> tm = getBestMenInfo(dataBaseDao,timestamp);
tempS = tm.get("author");
tempS2 = tm.get("posts");
stats_mainVO.setBestMem(tempS);
stats_mainVO.setBestMemPosts(tempS2);
newstatvars.add("'main', 'bestmem', '"+tempS+"'");
newstatvars.add("'main', 'bestmemposts', '"+tempS2+"'");
}
stats_mainVO.setNewMemberName(settingsMap.get("lastmember"));
stats_mainVO.setShowFluxSurvey(statstatus);
SimpleDateFormat formatToDate = new SimpleDateFormat("yyyyMM");
SimpleDateFormat formatToString = new SimpleDateFormat("yyyy 年 MM 月");
StatsDao statsDao=((StatsDao)BeanFactory.getBean("statsDao"));
if(statstatus){
Map<String,Stats> mapTemp = statsDao.workForFluxStatistic();
Stats statsMonth = mapTemp.get("month");
String accessMaxMonth = null;
String accessMaxMonthNum = null;
if(statsMonth!=null){
accessMaxMonth = statsMonth.getId().getVariable();
Date date = null;
try {
date = formatToDate.parse(accessMaxMonth);
accessMaxMonth = formatToString.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
date = null;
accessMaxMonthNum = statsMonth.getCount().toString();
}
stats_mainVO.setAllPageFlux(mapTemp.get("hits").getCount().toString());
stats_mainVO.setMemberOfAccess(mapTemp.get("members").getCount().toString());
stats_mainVO.setVisitorOfAccess(mapTemp.get("guests").getCount().toString());
stats_mainVO.setAccessMaxNum(accessMaxMonth);
stats_mainVO.setAllPageFluxOfMonth(accessMaxMonthNum);
String maxHour = mapTemp.get("hour").getId().getVariable();
stats_mainVO.setAccessTime(maxHour+" - "+(Integer.parseInt(maxHour)+1));
stats_mainVO.setAccessTimeAllFlux(mapTemp.get("hour").getCount().toString());
List<Stats> statsList = statsDao.getStatsByType("month");
statsDao=null;
formatToString.applyPattern("yyyy - MM ");
String monthTemp = null;
PageInfo pageInfo = null;
float maxPercent = 0F;
float tempf = 0F;
float hits = (float)(mapTemp.get("hits").getCount());
List<PageInfo> pageInfoList = stats_mainVO.getMonthFlux();
if(statsList != null){
try {
for(Stats tempStats : statsList){
pageInfo = new PageInfo();
tempf = (tempStats.getCount()/hits)*100;
maxPercent = tempf>maxPercent?tempf:maxPercent;
monthTemp = formatToString.format(formatToDate.parse(tempStats.getId().getVariable()));
pageInfo.setNum(tempStats.getCount().toString());
pageInfo.setNumPercent(number_format(mapTemp.get("hits").getCount(), tempStats.getCount()));
pageInfo.setInformation(monthTemp);
pageInfoList.add(pageInfo);
}
} catch (ParseException e) {
e.printStackTrace();
}
for(PageInfo pageInfo2 : pageInfoList){
setPageInfoMaxLengh(maxPercent, pageInfo2);
}
}
}else{
StatsId statsId = new StatsId();
statsId.setType("total");
statsId.setVariable("hits");
Stats stats = statsDao.getStatsById(statsId);
statsDao=null;
statsId= null;
stats_mainVO.setAllPageFlux(stats.getCount().toString());
setSubPostlog(stats_mainVO.getSubPostLog(), newstatvars,dataBaseDao,formatToDate,timestamp,timeoffset);
}
updateNewStatvars(newstatvars, dataBaseDao);
String lastupdateString = statvars.get("lastupdate");
statvars = null;
int lastUpdate = lastupdateString!=null?Integer.parseInt(lastupdateString):0;
int nextUpdate = lastUpdate + statscachelife.intValue();
formatToString.applyPattern("yyyy-MM-dd HH:mm");
stats_mainVO.setLastTime(Common.gmdate(formatToString, lastUpdate, timeoffset));
stats_mainVO.setNextTime(Common.gmdate(formatToString, nextUpdate, timeoffset));
setNavbarVO(stats_mainVO.getNavbar(), statstatus, modworkstatus, "stats");
return stats_mainVO;
}
public Stats_forumsrankVO getForumCompositor(Map<String,String> settingMap,int timestamp,float timeoffset){
Double statscachelife = Double.valueOf(settingMap.get("statscachelife"));
statscachelife = statscachelife * 60;
String tempS = settingMap.get("statstatus");
boolean statstatus = tempS!=null && !tempS.equals("0")&& !tempS.equals("");
tempS = settingMap.get("modworkstatus");
boolean modworkstatus = tempS!=null && !tempS.equals("") && !tempS.equals("0");
SimpleDateFormat dateFormat = new SimpleDateFormat();
List<String> newstatvars = new ArrayList<String>();
DataBaseDao dataBaseDao = ((DataBaseDao)BeanFactory.getBean("dataBaseDao"));
Map<String,String> statvars = getFinalMap("forumsrank",dataBaseDao);
tempS = statvars.get("lastupdate");
int lastupdate = tempS == null ? 0 : Integer.parseInt(tempS);
if(timestamp - lastupdate > statscachelife){
statvars.clear();
statvars.put("lastupdate", timestamp+"");
newstatvars.add("'forumsrank', 'lastupdate', '"+timestamp+"'");
}
DataParse dataParse = ((DataParse)BeanFactory.getBean("dataParse"));
Map<Integer,Map<String,String>> threads = null;
Map<Integer,Map<String,String>> posts = null;
Map<Integer,Map<String,String>> thismonth = null;
Map<Integer,Map<String,String>> today = null;
List<Map<String,String>> tempML = null;
int tempI = 0;
tempS = statvars.get("threads");
if(tempS!=null){
threads = dataParse.characterParse(tempS, false);
}else{
tempML = dataBaseDao.executeQuery("SELECT fid, name, threads FROM "+tableprefix+"forums WHERE status>0 AND type<>'group' ORDER BY threads DESC LIMIT 0, 20");
if(tempML!=null){
threads = new HashMap<Integer, Map<String,String>>();
for(Map<String,String> tempM : tempML){
threads.put(tempI, tempM);
tempI++;
}
}
statvars.put("forums", tempI+"");
newstatvars.add("'forumsrank', 'threads', '"+dataParse.combinationChar(threads)+"'");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -