%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %> <% request.setCharacterEncoding("utf-8"); %> <%@ page import="java.util.*,net.sf.json.*" %> <%@ include file="SQL.jsp" %> <% // 如果未登录先登录 String user = "" + session.getAttribute("user"); String groupId = "" + session.getAttribute("groupId"); String groupName = "" + session.getAttribute("groupName"); if(user.equals("null") || groupId.equals("null")){ response.sendRedirect("./login.html"); return; } // 如果不是该部门的员工 String _groupId = "" + request.getParameter("g"); if(!_groupId.equals("9") && !_groupId.equals(groupId) && !user.equals("admin@qq.com")){ response.sendRedirect("./home.html"); return; } // 页号 int pn = 1; int pSize = 5; double _total = 0; int total = 0; String _pn = "" + request.getParameter("pn"); if(!_pn.equals("null")){ pn = Integer.parseInt(_pn); pn = pn <= 0 ? 1 : pn; } // 连接数据库获取信息 SQL sql = new SQL(); // 部门信息 String exec_group_1 = "create or replace view infos_group1 as select groups.g_img,groups.g_id,count(u_id) as pNum from user right join groups on user.g_id=groups.g_id group by groups.g_id"; String exec_group_2 = "create or replace view infos_group2 as select max(thread.t_time) as tTime,threads.t_id,groups.g_id,groups.g_name,count(threads.t_id) as tNum from threads right join groups on threads.g_id=groups.g_id left join thread on threads.t_id=thread.t_id group by groups.g_id"; String exec_group_3 = "select * from infos_group1 inner join infos_group2 on infos_group1.g_id=infos_group2.g_id where infos_group1.g_id='"+_groupId+"'"; String g_name = "", g_img = "", pNum = "", tNum = "", tTime = ""; // 部门主题列表信息 String exec_thread1 = "create or replace view infosThread1 as select threads.g_id,threads.u_id,threads.t_id,count(r_id) as remarkNums from threads left join remarks on threads.t_id=remarks.t_id where threads.t_state='1' group by t_id having g_id='" + _groupId + "'"; String exec_thread2_all = "create or replace view infosThread2 as select user.u_id,user.u_name as ut_name,thread.t_title,thread.t_time,infosThread1.g_id,infosThread1.t_id,infosThread1.remarkNums from thread inner join infosThread1 on thread.t_id=infosThread1.t_id inner join user on user.u_id=infosThread1.u_id"; String exec_thread2_getAll = "select * from infosThread2"; String exec_thread2 = "create or replace view infosThread2 as select user.u_id,user.u_name as ut_name,thread.t_title,thread.t_time,infosThread1.g_id,infosThread1.t_id,infosThread1.remarkNums from thread inner join infosThread1 on thread.t_id=infosThread1.t_id inner join user on user.u_id=infosThread1.u_id where user.u_state_thread='1' and user.u_state_user='1' order by t_time desc limit " + (pn-1)*pSize+","+pSize; String exec_thread3 = "select ut_name,t_title,t_time,infosThread2.g_id,infosThread2.t_id,remarkNums,user.u_name as ur_name,r_time from infosThread2 left join remarks on infosThread2.t_id=remarks.t_id left join remark on remark.r_id=remarks.r_id left join user on remark.u_id=user.u_id group by infosThread2.t_id order by r_time desc,remarkNums desc,t_time desc"; List list_t_id = new ArrayList(); List list_t_title = new ArrayList(); List list_ut_name = new ArrayList(); List list_t_time = new ArrayList(); List list_remarkNums = new ArrayList(); List list_ur_name = new ArrayList(); List list_r_time = new ArrayList(); if(sql.connect()){ // 获取部门信息 sql.executeUpdate(exec_group_1); sql.executeUpdate(exec_group_2); ResultSet rs = sql.executeQuery(exec_group_3); while(rs.next()){ g_img = rs.getString("g_img"); g_name = rs.getString("g_name"); pNum = rs.getString("pNum"); tNum = rs.getString("tNum"); tTime = "" + rs.getTimestamp("tTime"); } if(tTime.equals("null")){ tTime = "1970-01-01 00:00:00"; } // 获取部门主题信息 sql.executeUpdate(exec_thread1); // 先求总记录 sql.executeUpdate(exec_thread2_all); rs = sql.executeQuery(exec_thread2_getAll); while(rs.next()){ _total = rs.getRow(); } total = (int)(Math.ceil(_total/pSize)); if(pn > total && total!= 0){ response.sendRedirect("./thread.jsp?g="+_groupId+"&pn="+total); return; } sql.executeUpdate(exec_thread2); rs = sql.executeQuery(exec_thread3); while(rs.next()){ list_t_id.add("" + rs.getInt("t_id")); list_t_title.add(rs.getString("t_title")); list_ut_name.add(rs.getString("ut_name")); list_t_time.add("" + rs.getTimestamp("t_time")); list_remarkNums.add(rs.getString("remarkNums")); String _ur_name = "" + rs.getString("ur_name"); if(_ur_name.equals("null")){ _ur_name = "无"; } String _r_time = "" + rs.getTimestamp("r_time"); if(_r_time.equals("null")){ _r_time = "1970-01-01 00:00:00"; } list_ur_name.add(_ur_name); list_r_time.add(_r_time); } }else{ System.out.println("Connect Error!"); } %> TRICELL - 论坛公共区 导航 主页 业务 论坛 个人 关于 登录/注册 管理员 TOP 部门: 昵称: 主题数: 性别: <%=g_name%> 会员数:<%=pNum%> 主题数:<%=tNum%> <%=tTime%> 发布主题 发布新主题>> × 请选择部门区: 公共区 <%=groupName%> 请输入主题: 请输入主题描述: 发布 发布成功,请刷新查看 <%=g_name%>最新主题>> 主题 作者 回复 最后回复 <% Iterator it_t_id = list_t_id.iterator(); if(it_t_id.hasNext()) { Iterator it_desc = list_t_title.iterator(); Iterator it_ut_name = list_ut_name.iterator(); Iterator it_t_time = list_t_time.iterator(); Iterator it_remarkNums = list_remarkNums.iterator(); Iterator it_ur_name = list_ur_name.iterator(); Iterator it_r_time = list_r_time.iterator(); String _href = ""; while(it_t_id.hasNext()){ _href = "./thread_info.jsp?g="+ _groupId+"&t="+it_t_id.next(); %> <%=it_desc.next()%> <%=it_ut_name.next()%> <%=it_t_time.next()%> <%=it_remarkNums.next()%> <%=it_ur_name.next()%> <%=it_r_time.next()%> <% } } %> <% // 页数逻辑 .dn 为 display:none String pre_dn = "dn", one_dn = "dn", two_dn = "dn", three_dn = "dn", four_dn = "dn", five_dn = "dn", next_dn = "dn"; int first_pn = 0, pre_pn = 0, one_pn = 1, two_pn = 2, three_pn = 3, four_pn = 4, five_pn = 5, next_pn = total, last_pn = total; // 5个页数显隐 one_dn = total >= 1 ? "" : "dn"; two_dn = total >= 2 ? "" : "dn"; three_dn = total >= 3 ? "" : "dn"; four_dn = total >= 4 ? "" : "dn"; five_dn = total >= 5 ? "" : "dn"; // 上一页下一页显隐 if(total >=2){ if(pn > 1){ pre_dn = ""; }else{ pre_dn = "dn"; } if(pn < total){ next_dn = ""; }else{ next_dn = "dn"; } } // 页数值 pre_pn = pn - 1; next_pn = pn + 1; first_pn = 1; last_pn = total; //如果超过5页就去中间(符合取中间) if(total > 5 && pn <= total && pn - 2 > 0 && pn + 2 < total){ one_pn = pn - 2; two_pn = pn - 1; three_pn = pn; four_pn = pn + 1; five_pn = pn + 2; } // 后方不符合 else if(total > 5 && pn <= total && pn - 2 > 0){ int posR = pn + 1 < total ? 1 : 0; one_pn = pn + posR - 4; two_pn = pn + posR - 3; three_pn = pn + posR - 2; four_pn = pn + posR - 1; five_pn = pn + posR; } // 前方不符合 else if(total > 5 && pn <= total && pn + 2 < total){ int posL = pn - 1 > 0 ? 1 : 0; one_pn = pn - posL; two_pn = pn - posL + 1; three_pn = pn - posL + 2; four_pn = pn - posL + 3; five_pn = pn - posL + 4; } %> 首页 上一页 <%=one_pn%> <%=two_pn%> <%=three_pn%> <%=four_pn%> <%=five_pn%> 下一页 末页 总页数:<%=total%> 跳页
部门:
昵称:
主题数:
性别:
会员数:<%=pNum%> 主题数:<%=tNum%>
<%=tTime%>
请选择部门区: 公共区 <%=groupName%>
请输入主题:
请输入主题描述:
发布 发布成功,请刷新查看
<%=g_name%>最新主题>>