⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mymanageaction.java

📁 论坛软件系统亦称电子公告板(BBS)系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package cn.jsprun.struts.foreg.actions;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import cn.jsprun.api.Tenpayapi;
import cn.jsprun.domain.Members;
import cn.jsprun.service.system.DataBaseService;
import cn.jsprun.utils.BeanFactory;
import cn.jsprun.utils.Common;
import cn.jsprun.utils.DataParse;

public class MyManageAction extends DispatchAction {
	private DataParse dataParse = (DataParse) BeanFactory.getBean("dataParse");
	private DataBaseService dataBaseService = (DataBaseService) BeanFactory.getBean("dataBaseService");
	@SuppressWarnings("unchecked")
	public ActionForward toMyIndex(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		int uid = (Integer) session.getAttribute("jsprun_uid");
		setExtcredits(request);
		int srchfid = Common.toDigit(request.getParameter("srchfid"), 10000000000L, 0L).intValue();
		String threadadd = null;
		String postadd = null;
		if (srchfid > 0) {
			threadadd = "AND t.fid='" + srchfid + "'";
			postadd = "AND p.fid='" + srchfid + "'";
		}else{
			threadadd = "";
			postadd = "";
		}
		List<Map<String, String>> threadlists = dataBaseService.executeQuery("SELECT m.tid, t.subject, t.fid, t.displayorder, t.lastposter, t.lastpost, t.closed ,f.name FROM jrun_mythreads m, jrun_threads t ,jrun_forums f WHERE m.uid="+ uid+ " AND m.tid=t.tid AND t.fid=f.fid "+ threadadd+ " ORDER BY m.dateline DESC LIMIT 5");
		this.setAttribute(request, session, threadlists, "threadlists");
		List<Map<String, String>> postlists = dataBaseService.executeQuery("SELECT m.tid,m.pid, p.fid, p.invisible,t.subject,t.lastposter,t.lastpost,f.name FROM jrun_myposts m INNER JOIN jrun_posts p ON p.pid=m.pid "+ postadd+ " INNER JOIN jrun_threads t ON t.tid=m.tid ,jrun_forums f WHERE m.uid="+ uid+ " AND p.fid=f.fid ORDER BY m.dateline DESC LIMIT 5");
		this.setAttribute(request, session, postlists, "postlists");
		return mapping.findForward("toMy");
	}
	public ActionForward toMyThreads(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		int uid = (Integer) session.getAttribute("jsprun_uid");
		setExtcredits(request);
		int srchfid = Common.toDigit(request.getParameter("srchfid"),10000000000L, 0L).intValue();
		String threadadd = null;
		String extrafid = null;
		if (srchfid > 0) {
			threadadd = "AND t.fid='" + srchfid + "'";
			extrafid = "&amp;srchfid=" + srchfid;
			request.setAttribute("extrafid", extrafid);
		}else{
			threadadd ="";
			extrafid="";
		}		
		Map<String, Integer> multi = this.multi(request, response,uid, "SELECT COUNT(*) count FROM jrun_mythreads m, jrun_threads t WHERE m.uid=" + uid + " " + threadadd+ " AND m.tid=t.tid","my.jsp?item=threads" + extrafid);
		List<Map<String, String>> threadlists = dataBaseService.executeQuery("SELECT m.tid, t.subject, t.fid, t.displayorder, t.lastposter, t.lastpost, t.closed ,f.name FROM jrun_mythreads m, jrun_threads t ,jrun_forums f WHERE m.uid="+ uid+ " AND m.tid=t.tid AND t.fid=f.fid "+ threadadd+ "ORDER BY m.dateline DESC LIMIT "+ multi.get("start_limit")+ ", " + multi.get("perpage"));
		this.setAttribute(request, session, threadlists, "threadlists");
		return mapping.findForward("toMy");
	}
	public ActionForward toMyPosts(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		int uid = (Integer) session.getAttribute("jsprun_uid");
		this.setExtcredits(request);
		int srchfid = Common.toDigit(request.getParameter("srchfid"),10000000000L, 0L).intValue();
		String postadd = null;
		String extrafid = null;
		if (srchfid > 0) {
			postadd = "AND p.fid='" + srchfid + "'";
			extrafid = "&amp;srchfid=" + srchfid;
			request.setAttribute("extrafid", extrafid);
		}else{
			postadd = "";
			extrafid = "";
		}
		Map<String, Integer> multi = this.multi(request, response, uid, "SELECT COUNT(*) count FROM jrun_myposts m INNER JOIN jrun_posts p ON p.pid=m.pid " + postadd + " INNER JOIN jrun_threads t ON t.tid=m.tid WHERE m.uid = " + uid,"my.jsp?item=posts" + extrafid);
		List<Map<String, String>> postlists = dataBaseService.executeQuery("SELECT m.uid, m.tid, m.pid, p.fid, p.invisible, p.dateline,t.subject,t.lastposter,t.lastpost,f.name FROM jrun_myposts m INNER JOIN jrun_posts p ON p.pid=m.pid "+ postadd+ " INNER JOIN jrun_threads t ON t.tid=m.tid ,jrun_forums f WHERE m.uid="+ uid+ " AND p.fid=f.fid ORDER BY m.dateline DESC LIMIT "+ multi.get("start_limit") + ", " + multi.get("perpage"));
		this.setAttribute(request, session, postlists, "postlists");
		return mapping.findForward("toMy");
	}
	@SuppressWarnings("unchecked")
	public ActionForward toMyFavorites(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		int uid = (Integer) session.getAttribute("jsprun_uid");
		this.setExtcredits(request);
		int srchfid = Common.toDigit(request.getParameter("srchfid"),10000000000L, 0L).intValue();
		String threadadd = null;
		String extrafid =null;
		if (srchfid > 0) {
			threadadd = "AND t.fid='" + srchfid + "'";
			extrafid = "&amp;srchfid=" + srchfid;
			request.setAttribute("extrafid", extrafid);
		}else{
			threadadd = "";
			extrafid = "";
		}
		Map<String, String> settings = (Map<String, String>) request.getAttribute("settings");
		String favsubmit = request.getParameter("favsubmit");
		String tid = request.getParameter("tid");
		String fid = request.getParameter("fid");
		String type = request.getParameter("type");
		String ftid = "thread".equals(type) || tid != null ? "tid" : "fid";
		type = "thread".equals(type) || tid != null ? "thread" : "forum";
		if ((tid != null || fid != null) && favsubmit == null) {
			response.setContentType("text/html");
			response.setHeader("Cache-Control", "no-store");  
			response.setHeader("Program", "no-cache");  
			response.setDateHeader("Expirse", 0);
			List<Map<String, String>> count = dataBaseService.executeQuery("SELECT COUNT(*) count FROM jrun_favorites WHERE uid='" + uid + "' AND " + ftid + ">'0'");
			int size = (count != null && count.size() > 0 ? Integer.valueOf(count.get(0).get("count")) : 0);
			int maxfavorites = Integer.valueOf(settings.get("maxfavorites"));
			String message = null;
			if (size >= maxfavorites) {
				message = "您的收藏夹已满,请在继续操作前删除一些不用的收藏。";
			} else {
				String value = "thread".equals(type) || tid != null ? tid : fid;
				count = dataBaseService.executeQuery("SELECT COUNT(*) count  FROM jrun_favorites WHERE uid='" + uid + "' AND " + ftid + "="+ value);
				size = (count != null && count.size() > 0 ? Integer.valueOf(count.get(0).get("count")) : 0);
				if (size > 0) {
					message = "您过去已经收藏过这个主题或版块。";
				} else {
					dataBaseService.runQuery("INSERT INTO jrun_favorites (uid, " + ftid+ ") VALUES ('" + uid + "', '" + value + "')",true);
					message = "指定主题或版块已成功添加到收藏夹中。";
				}
			}
			try {
				response.getWriter().write(message);
			} catch (IOException e) {
				e.printStackTrace();
			}
			return mapping.findForward("null");
		} else {
			if (favsubmit != null) {
				String[] delete = request.getParameterValues("delete");
				if (delete != null) {
					StringBuffer ids=new StringBuffer(delete.length);
					for (String id : delete) {
						ids.append(id+",");
					}
					if (ids.length()>0) {
						ids.deleteCharAt(ids.length()-1);
						dataBaseService.runQuery("DELETE FROM jrun_favorites WHERE uid=" + uid + " AND " + ftid+ " IN ( " + ids + " )",true);
					}
					delete=null;
					ids=null;
				}
				request.setAttribute("successInfo", "'收藏夹已成功更新,现在将转入更新后的收藏夹。");
				request.setAttribute("requestPath","my.jsp?item=favorites&type=" + type);
				return mapping.findForward("showMessage");

			} else {
				if ("forum".equals(type)) {
					Map<String, Integer> multi = this.multi(request, response,uid, "SELECT COUNT(*) count FROM jrun_favorites fav, jrun_forums f WHERE fav.uid = " + uid+ " AND fav.fid=f.fid", "my.jsp?item=favorites&type=forum");
					List<Map<String, String>> favlists = dataBaseService.executeQuery("SELECT f.fid, f.name, f.threads, f.posts, f.todayposts, f.lastpost FROM jrun_favorites fav, jrun_forums f WHERE fav.fid=f.fid AND fav.uid="+ uid+ " ORDER BY f.lastpost DESC LIMIT "+ multi.get("start_limit")+ ", "+ multi.get("perpage"));
					request.setAttribute("favlists", favlists != null&& favlists.size() > 0 ? favlists : null);
					favlists=null;
					return mapping.findForward("toMy");					
				} else {
					Map<String, Integer> multi = this.multi(request, response,uid, "SELECT COUNT(*) count FROM jrun_favorites fav, jrun_threads t	WHERE fav.uid = " + uid+ " AND fav.tid=t.tid AND t.displayorder>='0'"+ threadadd, "my.jsp?item=favorites&type=thread"+ extrafid);
					List<Map<String, String>> favlists = dataBaseService.executeQuery("SELECT t.tid, t.fid, t.subject, t.replies, t.lastpost, t.lastposter, f.name FROM jrun_favorites fav, jrun_threads t, jrun_forums f WHERE fav.tid=t.tid AND t.displayorder>='0' AND fav.uid="	+ uid+ " AND t.fid=f.fid "+ threadadd+ " ORDER BY t.lastpost DESC LIMIT "+ multi.get("start_limit")+ ", "+ multi.get("perpage"));
					this.setAttribute(request, session, favlists, "favlists");
					return mapping.findForward("toMy");
				}
			}
		}
	}
	@SuppressWarnings("unchecked")
	public ActionForward toMySubscriptions(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) {
		HttpSession session = request.getSession();
		int uid = (Integer) session.getAttribute("jsprun_uid");
		this.setExtcredits(request);
		int srchfid = Common.toDigit(request.getParameter("srchfid"),10000000000L, 0L).intValue();
		String threadadd = null;
		String extrafid = null;
		if (srchfid > 0) {
			threadadd = "AND t.fid='" + srchfid + "'";
			extrafid = "&amp;srchfid=" + srchfid;
			request.setAttribute("extrafid", extrafid);
		}else{
			threadadd = "";
			extrafid = "";
		}
		String subadd = request.getParameter("subadd");
		if (subadd != null) {
			response.setContentType("text/html");
			response.setHeader("Cache-Control", "no-store");  
			response.setHeader("Program", "no-cache");  
			response.setDateHeader("Expirse", 0);
			List<Map<String, String>> sublists = dataBaseService.executeQuery("SELECT price FROM jrun_threads WHERE tid="+subadd);
			if(sublists!=null){
				List<Map<String, String>> paymentlist = dataBaseService.executeQuery("SELECT tid FROM jrun_paymentlog WHERE tid='"+subadd+"' AND uid="+uid);
				if(paymentlist==null){
					try {
						response.getWriter().write("对不起,您无权订阅该主题。");
						return null;
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				paymentlist=null;
				List<Map<String, String>> countlist = dataBaseService.executeQuery("SELECT COUNT(*) count FROM jrun_subscriptions WHERE uid="+uid);
				String maxsuscription = ((Map<String, String>) request.getAttribute("settings")).get("maxsubscriptions");
				if(countlist!=null && Integer.valueOf(countlist.get(0).get("count"))>=Integer.valueOf(maxsuscription)){
					try {
						response.getWriter().write("您的订阅列表已满,请在继续操作前删除一些不用的订阅。");
						return null;
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				List<Map<String, String>> subscriptlist = dataBaseService.executeQuery("SELECT tid FROM jrun_subscriptions WHERE tid='"+subadd+"' AND uid='"+uid+"' LIMIT 1");
				if(subscriptlist!=null && subscriptlist.size()>0){
					try {
						response.getWriter().write("您过去已经订阅过这个主题。");
						return null;
					} catch (IOException e) {
						e.printStackTrace();
					}
				}else{
					dataBaseService.runQuery("INSERT INTO jrun_subscriptions (uid, tid,lastnotify) VALUES ('"+uid+"', '"+subadd+"', '0')",true);
					try {
						response.getWriter().write("您选择的主题已经成功订阅。");
						return null;
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -