|
|
package update;
|
|
|
import support.ConnectionSql;
|
|
|
|
|
|
import java.sql.*;
|
|
|
import java.util.*;
|
|
|
import java.util.Date;
|
|
|
|
|
|
public class StatisticsPostsCount {
|
|
|
String tablename="match_simple";
|
|
|
String column1="score";
|
|
|
String column2="favoriteCount";
|
|
|
String column3="viewCount";
|
|
|
String column4="answerCount";
|
|
|
String column5="postsCount";
|
|
|
String proj_name="proj_name";
|
|
|
String tag="tag";
|
|
|
String posts_split_tags="posts_split_tags";
|
|
|
String posts_id="posts_id";
|
|
|
String posts="posts";
|
|
|
String id="id";
|
|
|
String postTypeId="postTypeId";
|
|
|
Connection conn=new ConnectionSql("ossean_db").connection();
|
|
|
public StatisticsPostsCount() {
|
|
|
// TODO Auto-generated constructor stub
|
|
|
}
|
|
|
public StatisticsPostsCount(String tablename,String coulumn1,String coulumn2,String coulumn3,String coulumn4,String coulumn5) {
|
|
|
// TODO Auto-generated constructor stub
|
|
|
this.tablename=tablename;
|
|
|
this.column1=coulumn1;
|
|
|
this.column2=coulumn2;
|
|
|
this.column3=coulumn3;
|
|
|
this.column4=coulumn4;
|
|
|
this.column5=coulumn5;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计每个项目对应的帖子数,帖子的总回复数,获赞数,收藏数,浏览数:(psotsCount,answerCount,score,favoriteCount,viewCount)
|
|
|
* 从match_simple读出项目和匹配的标签,根据标签在split_posts_tags表找出posts_id,统计每个posts的count
|
|
|
*/
|
|
|
public boolean cal_count() {
|
|
|
try {
|
|
|
conn.setAutoCommit(false);
|
|
|
Statement st1=conn.createStatement();
|
|
|
Statement st2;
|
|
|
Statement st3;
|
|
|
String sql="select "+proj_name+","+tag+" from "+tablename;
|
|
|
ResultSet rs1=st1.executeQuery(sql);
|
|
|
ResultSet rs2;
|
|
|
ResultSet rs3;
|
|
|
System.out.print("start\t\t\t");System.out.println(new Date());
|
|
|
|
|
|
while(rs1.next()){
|
|
|
String temp_proj_name="'"+rs1.getString(proj_name)+"'";
|
|
|
String temp_tag="'"+rs1.getString(tag)+"'";
|
|
|
st2=conn.createStatement();
|
|
|
sql="select "+posts_id+" from "+posts_split_tags+" where "+tag+" = "+temp_tag;
|
|
|
rs2=st2.executeQuery(sql); //查询post_split_tags得到posts_id
|
|
|
int data1=0,data2=0,data3=0,data4=0,data5=0;
|
|
|
while(rs2.next()){
|
|
|
int temp_posts_id=rs2.getInt(posts_id);
|
|
|
st3=conn.createStatement();
|
|
|
sql="select "+column1+","+column2+","+column3+","+column4+" from "+posts+" where "+id+" = "+temp_posts_id;
|
|
|
rs3=st3.executeQuery(sql);
|
|
|
while(rs3.next()){
|
|
|
data1+=rs3.getInt(column1);
|
|
|
data2+=rs3.getInt(column2);
|
|
|
data3+=rs3.getInt(column3);
|
|
|
data4+=rs3.getInt(column4);
|
|
|
data5++;
|
|
|
|
|
|
}
|
|
|
rs3.close();
|
|
|
st3.close();
|
|
|
}
|
|
|
rs2.close();
|
|
|
sql="update "+tablename+" set "+column1+"="+data1+","+column2+"="+data2+","+column3+"="+data3+","+column4+"="+data4+","+column5+"="+data5+" where "+proj_name+" = "+temp_proj_name;
|
|
|
st2.execute(sql);
|
|
|
st2.close();
|
|
|
System.out.print(temp_proj_name+"\t\t");
|
|
|
System.out.println(new Date());
|
|
|
|
|
|
}
|
|
|
rs1.close();
|
|
|
st1.close();
|
|
|
conn.commit();
|
|
|
conn.close();
|
|
|
System.out.println("down");
|
|
|
} catch (Exception e) {
|
|
|
// TODO: handle exception
|
|
|
e.printStackTrace();
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
StatisticsPostsCount statisticsPostsCount=new StatisticsPostsCount();
|
|
|
statisticsPostsCount.cal_count();
|
|
|
}
|
|
|
}
|