一个操作里面选有两个函数体:第一个先在热点表里进行选择,选择了几个给出几个;然后不足45个后面的再根据浏览量选择
public List<CompositionInfo> selectRecommendCompositionList()
{
List<CompositionInfo> compositionlist = new LinkedList<CompositionInfo>();
String sql = "SELECT mp.uucaid, get_uuca_name(mp.uucaid), compositiontype, " +
"compositeid, get_uuca_image(mp.uucaid), get_uuca_counter(mp.uucaid), uuca.datetime " +
"FROM mannual_pops mp,user_upload_composition_activity uuca " +
"WHERE mp.uucaid = uuca.uucaid AND uuca.valid = 1 " +
"ORDER BY mp.popvalue desc " +
"LIMIT 0, 45";
try {
java.sql.PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next())
{
CompositionInfo onecomposition = new CompositionInfo();
onecomposition.setUucaid(rs.getLong(1));
onecomposition.setCompositioname(rs.getString(2));
onecomposition.setType(rs.getInt(3));
onecomposition.setCompositeid(rs.getLong(4));
onecomposition.setImage(rs.getString(5));
onecomposition.setCounter(rs.getLong(6));
onecomposition.setDatetime(getDateFormat(rs.getTimestamp(7)));
compositionlist.add(onecomposition);
}
rs.close();
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
int count = compositionlist.size();
int leftcount = 45 - count;
sql = "SELECT uucaid, title, compositiontype, compositeid, imageurl, counter, DATETIME " +
"FROM composition_details " +
"WHERE compositiontype != 3 and valid=1 AND uucaid NOT IN (SELECT uucaid FROM mannual_pops) " +
"ORDER BY counter DESC " +
"LIMIT 0, ?";
try {
java.sql.PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, leftcount);
ResultSet rs=ps.executeQuery();
while(rs.next())
{
CompositionInfo onecomposition = new CompositionInfo();
onecomposition.setUucaid(rs.getLong(1));
onecomposition.setCompositioname(rs.getString(2));
onecomposition.setType(rs.getInt(3));
onecomposition.setCompositeid(rs.getLong(4));
onecomposition.setImage(rs.getString(5));
onecomposition.setCounter(rs.getLong(6));
onecomposition.setDatetime(getDateFormat(rs.getTimestamp(7)));
compositionlist.add(onecomposition);
}
rs.close();
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return compositionlist;
}