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

📄 tagsaction.java

📁 论坛软件系统亦称电子公告板(BBS)系统
💻 JAVA
字号:
package cn.jsprun.struts.foreg.actions;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

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.domain.Members;
import cn.jsprun.domain.Tags;
import cn.jsprun.service.posts.TagsService;
import cn.jsprun.service.system.DataBaseService;
import cn.jsprun.utils.BeanFactory;
import cn.jsprun.utils.Common;

public class TagsAction extends DispatchAction {
	private TagsService tagService = (TagsService) BeanFactory.getBean("tagService");
	private DataBaseService dataBaseService = (DataBaseService) BeanFactory.getBean("dataBaseService");

	@SuppressWarnings("unchecked")
	public ActionForward toDistags(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		Map<String, String> settings = (Map<String, String>) request.getAttribute("settings");
		int viewthreadtags=Common.toDigit(settings.get("viewthreadtags"));
		List<Map<String,String>> hottaglist=dataBaseService.executeQuery("SELECT tagname,total FROM jrun_tags WHERE closed=0 ORDER BY total DESC LIMIT "+viewthreadtags);
		if(hottaglist!=null&&hottaglist.size()>0){
			for (Map<String, String> hottag : hottaglist) {
				hottag.put("tagnameenc", Common.encode(hottag.get("tagname")));
			}
			request.setAttribute("hottaglist", hottaglist);
		}
		int count=Integer.valueOf(dataBaseService.executeQuery("SELECT count(*) count FROM jrun_tags WHERE closed=0").get(0).get("count"));
		Random random = Common.random;
		int randlimit=(count<=viewthreadtags)?0:random.nextInt(count - viewthreadtags);
		List<Map<String,String>> randtaglist=dataBaseService.executeQuery("SELECT tagname,total FROM jrun_tags WHERE closed=0 LIMIT "+randlimit+","+viewthreadtags);
		if(randtaglist!=null&&randtaglist.size()>0){
			for (Map<String, String> randtag : randtaglist) {
				randtag.put("tagnameenc", Common.encode(randtag.get("tagname")));
			}
			request.setAttribute("randtaglist", randtaglist);
		}
		return mapping.findForward("todistags");
	}
	@SuppressWarnings("unchecked")
	public ActionForward toThreadtags(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String name = request.getParameter("name");
		Tags tag = tagService.findTagsByName(name);
		if (name != null && !name.equals("")) {
			HttpSession session=request.getSession();
			Members member=(Members)session.getAttribute("user");
			Map<String,String> settings=(Map<String,String>)request.getAttribute("settings");
			int count=Integer.valueOf(dataBaseService.executeQuery("SELECT count(*) count FROM jrun_threadtags WHERE tagname='"+name+"'").get(0).get("count"));
			int tpp = member != null && member.getTpp() > 0 ? member.getTpp(): Integer.valueOf(settings.get("topicperpage"));
			int page =Common.toDigit(request.getParameter("page"),2147483647l,1l).intValue();
			Map<String,Integer> multiInfo=Common.getMultiInfo(count, tpp, page);
			page=multiInfo.get("curpage");
			int start_limit=multiInfo.get("start_limit");
			Map<String,Object> multi=Common.multi(count, tpp, page, "tag.jsp?name=" + Common.encode(name), 0, 10, true, false, null, false);
			request.setAttribute("multi", multi);
			List<Map<String,String>> dislist = null;int delcount = 0;
			List<Map<String,String>>threadtaglist = dataBaseService.executeQuery("select s.tid as ttid,t.*,f.name from jrun_threadtags as s left join jrun_threads as t on s.tid=t.tid left join jrun_forums as f on t.fid=f.fid where s.tagname='"+name+"' limit "+start_limit+","+tpp);
			if (threadtaglist != null && threadtaglist.size() > 0) {
				dislist = new ArrayList<Map<String,String>>();
				for (Map<String,String> tags : threadtaglist) {
					if (tags.get("subject") != null && !tags.get("subject").equals("")) {
						dislist.add(tags);
					}else{
						delcount++;
						dataBaseService.runQuery("delete from jrun_threadtags where tid="+tags.get("ttid"));
					}
				}
			}
			if(tag!=null && delcount>0){
				if(delcount>tag.getTotal()){
					tagService.deleteTags(tag);
				}else{
					tag.setTotal(tag.getTotal()-delcount);
					tagService.updateTags(tag);
				}
			}
			threadtaglist = null;
			request.setAttribute("dislist", dislist);
			request.setAttribute("name", name);
		}
		return mapping.findForward("todisthreads");
	}
}

⌨️ 快捷键说明

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