/src/main/java/cn/javaeye/lonlysky/lforum/service/admin/AdminForumManager.java
Java | 809 lines | 507 code | 103 blank | 199 comment | 102 complexity | a86f46c10a4698838a00cb9244c406ef MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
- package cn.javaeye.lonlysky.lforum.service.admin;
-
- import java.util.List;
-
- import org.hibernate.SessionFactory;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springside.modules.orm.hibernate.SimpleHibernateTemplate;
-
- import cn.javaeye.lonlysky.lforum.GlobalsKeys;
- import cn.javaeye.lonlysky.lforum.cache.LForumCache;
- import cn.javaeye.lonlysky.lforum.comm.utils.Utils;
- import cn.javaeye.lonlysky.lforum.entity.forum.Admingroups;
- import cn.javaeye.lonlysky.lforum.entity.forum.Forums;
- import cn.javaeye.lonlysky.lforum.entity.forum.Moderators;
- import cn.javaeye.lonlysky.lforum.entity.forum.Users;
- import cn.javaeye.lonlysky.lforum.service.ForumManager;
- import cn.javaeye.lonlysky.lforum.service.UserManager;
-
- /**
- * ?????????
- *
- * @author fishkang
- *
- */
- @Service
- @Transactional
- public class AdminForumManager {
-
- private static final Logger logger = LoggerFactory.getLogger(AdminForumManager.class);
- private SimpleHibernateTemplate<Forums, Integer> forumDAO;
- private SimpleHibernateTemplate<Moderators, Integer> moderatorDAO;
-
- @Autowired
- private ForumManager forumManager;
-
- @Autowired
- private UserManager userManager;
-
- @Autowired
- public void setSessionFactory(SessionFactory sessionFactory) {
- forumDAO = new SimpleHibernateTemplate<Forums, Integer>(sessionFactory, Forums.class);
- moderatorDAO = new SimpleHibernateTemplate<Moderators, Integer>(sessionFactory, Moderators.class);
- }
-
- /**
- * ?????????(layer)????(parentidlist)??
- */
- public void setForumslayer() {
- List<Forums> forumList = forumManager.getForumList();
- for (Forums forum : forumList) {
- int layer = 0;
- String parentidlist = "";
- int parentid = forum.getForums().getFid();
-
- //???(??)??????????
- if (parentid == 0) {
- // forum.setLayer(layer);
- // forum.setParentidlist("0");
- // forumManager.updateForum(forum);
- System.out.println("?????????:" + forum.getFid());
- forumDAO
- .createQuery("update Forums set layer=?,parentidlist=? where fid=?", layer, "0", forum.getFid())
- .executeUpdate();
- continue;
- }
-
- do { //????????(layer)????(parentidlist)??
- int tmp = parentid;
- parentid = Utils.null2Int(forumDAO.findUnique("select forums.fid from Forums where fid=?", parentid));
- layer++;
- if (parentid != 0) {
- parentidlist = tmp + "," + parentidlist;
- } else {
- parentidlist = tmp + "," + parentidlist;
- // forum.setLayer(layer);
- // forum.setParentidlist(parentidlist.substring(0, parentidlist.length() - 1));
- // forumManager.updateForum(forum);
- System.out.println("??????" + forum.getFid() + ",??:" + layer + ",??ID???"
- + parentidlist.substring(0, parentidlist.length() - 1));
- forumDAO.createQuery("update Forums set layer=?,parentidlist=? where fid=?", layer,
- parentidlist.substring(0, parentidlist.length() - 1), forum.getFid()).executeUpdate();
- break;
- }
- } while (true);
- }
- if (logger.isDebugEnabled()) {
- logger.debug("?????????(layer)????(parentidlist)??");
- }
-
- }
-
- public static String childNode = "0";
-
- /**
- * ?????????????
- * @param correntfid ??
- * @return ??????,??:1,2,3,4,
- */
- @SuppressWarnings("unchecked")
- public String findChildNode(int correntfid) {
- synchronized (childNode) {
-
- List<Object> list = forumDAO.find("select fid from Forums where forums.fid=? order by displayorder asc",
- correntfid);
-
- childNode = childNode + "," + correntfid;
-
- if (list.size() > 0) {
- //????
- for (Object object : list) {
- findChildNode(Utils.null2Int(object));
- }
- }
- if (logger.isDebugEnabled()) {
- logger.debug("???????{}", childNode);
- }
- return childNode;
- }
- }
-
- /**
- * ????????????
- */
- public void setForumsSubForumCountAndDispalyorder() {
- if (logger.isDebugEnabled()) {
- logger.debug("????????????");
- }
- List<Forums> forumList = forumManager.getForumList();
- for (Forums forum : forumList) {
- int subcount = forumDAO.find("select fid from Forums where forums.fid=?", forum.getFid()).size();
- // forumDAO.createQuery("update Forums set subforumcount=? where fid=?", subcount, forum.getFid())
- // .executeUpdate();
- forum.setSubforumcount(subcount);
- forumManager.updateForum(forum);
- System.out.println("?????????" + forum.getSubforumcount() + ",???" + forum.getFid());
- }
-
- if (forumList.size() == 1)
- return;
-
- int displayorder = 1;
- String fidlist;
- for (Forums forum : forumManager.getForumList("forums.fid=0")) {
- if (forum.getForums().getFid() == 0) {
- childNode = "0";
- fidlist = ("," + findChildNode(forum.getFid())).replace(",0,", "");
- for (String fidstr : fidlist.split(",")) {
- // forumDAO.createQuery("update Forums set displayorder=? where fid=?", displayorder,
- // Utils.null2Int(fidstr)).executeUpdate();
- Forums forums = forumDAO.get(Utils.null2Int(fidstr));
- forums.setDisplayorder(displayorder);
- forumManager.updateForum(forums);
- System.out.println("?????" + forums.getFid() + "?????" + forums.getDisplayorder());
- displayorder++;
- }
-
- }
- }
- }
-
- /**
- * ??????
- * @param currentfid ??????id
- * @param targetfid ??????id
- * @param isaschildnode ?????????
- * @return
- */
- @Transactional(readOnly = false)
- public void moveForumsPos(int currentfid, int targetfid, boolean isaschildnode) {
- if (logger.isDebugEnabled()) {
- logger.debug("????,?????{},?????{},????????" + isaschildnode, currentfid, targetfid);
- }
- //???????????
- Forums currentForum = forumDAO.get(currentfid);
-
- //???????????
- Forums targetForum = forumDAO.get(targetfid);
-
- //???????????
- if (forumDAO.find("select fid from Forums where forums.fid=?", currentfid).size() > 0) {
- System.out.println("??????????");
- if (isaschildnode) { //?????????
- //?????????(??)??????????????1(?????????????)
- forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=?",
- (targetForum.getDisplayorder() + 1)).executeUpdate();
-
- //?????????????
- currentForum.setForums(targetForum);
- currentForum.setDisplayorder(targetForum.getDisplayorder() + 1);
- // forumDAO.createQuery("update Forums set forums.fid=?,displayorder=? where fid=?", targetForum.getFid(),
- // targetForum.getDisplayorder() + 1, currentfid).executeUpdate();
- } else { //????????,???????????
- //?????????????????????????1(?????????????)
- forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=? or fid=?",
- targetForum.getDisplayorder(), targetForum.getFid()).executeUpdate();
- //?????????????
- currentForum.setForums(targetForum.getForums());
- currentForum.setDisplayorder(targetForum.getDisplayorder());
- // forumDAO.createQuery("update Forums set forums.fid=?,displayorder=? where fid=?",
- // targetForum.getForums().getFid(), targetForum.getDisplayorder(), currentfid).executeUpdate();
-
- }
-
- //???????????????????
- if (currentForum.getTopics_1() != 0 && currentForum.getTopics_1() > 0
- && (currentForum.getPosts() != 0 && currentForum.getPosts() > 0)) {
- if (!currentForum.getParentidlist().trim().equals("")) {
- forumDAO.createQuery(
- "update Forums set topics_1=topics_1-" + currentForum.getTopics_1() + ",posts=posts-"
- + currentForum.getPosts() + " where fid in("
- + currentForum.getParentidlist().trim() + ")").executeUpdate();
- }
- if (!targetForum.getParentidlist().trim().equals("")) {
- forumDAO.createQuery(
- "update Forums set topics_1=topics_1+" + currentForum.getTopics_1() + ",posts=posts+"
- + currentForum.getPosts() + " where fid in(" + targetForum.getParentidlist().trim()
- + ")").executeUpdate();
- }
- }
- } else { //??????????
- System.out.println("??????????");
- //????????????
- forumDAO.createQuery("update Forums set subforumcount=subforumcount-1 where fid=?",
- currentForum.getForums().getFid()).executeUpdate();
-
- //???????????????????1 [?????????]
- if (isaschildnode) { //?????????
- //????????????????
- if ((currentForum.getTopics_1() != 0) && (currentForum.getTopics_1() > 0)
- && (currentForum.getPosts() != 0) && (currentForum.getPosts() > 0)) {
- forumDAO.createQuery(
- "update Forums set topics_1=topics_1-" + currentForum.getTopics_1() + ",posts=posts-"
- + currentForum.getPosts() + " where fid in("
- + currentForum.getParentidlist().trim() + ")").executeUpdate();
- if (!targetForum.getParentidlist().trim().equals("0")) {
- forumDAO.createQuery(
- "update Forums set topics_1=topics_1+" + currentForum.getTopics_1() + ",posts=posts+"
- + currentForum.getPosts() + " where fid in("
- + targetForum.getParentidlist().trim() + "," + targetfid + ")").executeUpdate();
- }
- }
-
- //???????????????????????1(?????????????)
- forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=?",
- targetForum.getDisplayorder() + 1).executeUpdate();
-
- //????????????
- targetForum.setSubforumcount(targetForum.getSubforumcount() + 1);
- // forumDAO.createQuery("update Forums set subforumcount=subforumcount+1 where fid=?", targetfid)
- // .executeUpdate();
-
- String parentidlist = null;
- if (targetForum.getParentidlist().trim().equals("0")) {
- parentidlist = targetfid + "";
- } else {
- parentidlist = targetForum.getParentidlist().trim() + "," + targetfid;
- }
-
- //?????????????
- currentForum.setForums(targetForum);
- currentForum.setLayer(targetForum.getLayer() + 1);
- currentForum.setPathlist(targetForum.getPathlist().trim() + "<a href=\"showforum.action?forumid="
- + currentfid + "\">" + currentForum.getName().trim().replace("'", "''") + "</a>");
- currentForum.setParentidlist(parentidlist);
- currentForum.setDisplayorder(targetForum.getDisplayorder() + 1);
- System.out.println("??????????" + currentForum.getLayer());
- // forumDAO.createQuery(
- // "update Forums set forums.fid=?,layer=?,pathlist=?,parentidlist=?,displayorder=? where fid=?",
- // targetForum.getFid(),
- // targetForum.getLayer() + 1,
- // targetForum.getPathlist().trim() + "<a href=\"showforum.action?forumid=" + currentfid + "\">"
- // + currentForum.getName().trim().replace("'", "''") + "</a>", parentidlist,
- // targetForum.getDisplayorder() + 1, currentfid).executeUpdate();
-
- } else { //????????,???????????
- //????????????????
- if ((currentForum.getTopics_1() != 0) && (currentForum.getTopics_1() > 0)
- && (currentForum.getPosts() != 0) && (currentForum.getPosts() > 0)) {
- forumDAO.createQuery(
- "update Forums set topics_1=topics_1-" + currentForum.getTopics_1() + ",posts=posts-"
- + currentForum.getPosts() + " where fid in("
- + currentForum.getParentidlist().trim() + ")").executeUpdate();
- forumDAO.createQuery(
- "update Forums set topics_1=topics_1+" + currentForum.getTopics_1() + ",posts=posts+"
- + currentForum.getPosts() + " where fid in(" + targetForum.getParentidlist().trim()
- + ")").executeUpdate();
-
- }
-
- //?????????????????????????1(?????????????)
- forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=? or fid=?",
- targetForum.getDisplayorder() + 1, targetForum.getFid()).executeUpdate();
-
- //????????????
- forumDAO.createQuery("update Forums set subforumcount=subforumcount+1 where fid=?",
- targetForum.getForums().getFid()).executeUpdate();
- String parentpathlist = Utils.null2String(forumDAO.findUnique(
- "select pathlist from Forums where fid=?", targetForum.getForums().getFid()));
-
- //?????????????
- currentForum.setForums(targetForum.getForums());
- currentForum.setLayer(targetForum.getLayer());
- currentForum.setPathlist(parentpathlist + "<a href=\"showforum.action?forumid=" + currentfid + "\">"
- + currentForum.getName().trim() + "</a>");
- currentForum.setParentidlist(targetForum.getParentidlist().trim());
- currentForum.setDisplayorder(targetForum.getDisplayorder());
- // forumDAO.createQuery(
- // "update Forums set forums.fid=?,layer=?,pathlist=?,parentidlist=?,displayorder=? where fid=?",
- // targetForum.getForums().getFid(),
- // targetForum.getLayer(),
- // parentpathlist + "<a href=\"showforum.action?forumid=" + currentfid + "\">"
- // + currentForum.getName().trim() + "</a>", targetForum.getParentidlist().trim(),
- // targetForum.getDisplayorder(), currentfid).executeUpdate();
- }
- }
- forumManager.updateForum(currentForum);
- forumManager.updateForum(targetForum);
- }
-
- /**
- * ??????
- * @param currentfid ??????id
- * @param targetfid ??????id
- * @param isaschildnode ?????????
- * @return
- */
- public boolean movingForumsPos(int currentfid, int targetfid, boolean isaschildnode) {
- moveForumsPos(currentfid, targetfid, isaschildnode);
- setForumslayer();
- setForumsSubForumCountAndDispalyorder();
- setForumsPathList();
-
- LForumCache.getInstance().removeCache("ForumListBoxOptions");
- LForumCache.getInstance().removeCache("ForumList");
- return true;
- }
-
- /**
- * ???????????(pathlist)??
- */
- @Transactional(readOnly = false)
- public void setForumsPathList() {
- List<Forums> forumList = forumManager.getForumList();
- for (Forums forum : forumList) {
- String pathlist = "";
-
- if (forum.getParentidlist().trim().equals("0")) {
-
- pathlist = "<a href=\"showforum.action?forumid=" + forum.getFid() + "\">" + forum.getName().trim()
- + "</a>";
- } else {
- for (String parentid : forum.getParentidlist().trim().split(",")) {
- if (!parentid.trim().equals("")) {
- Forums tmpForums = forumDAO.get(Utils.null2Int(parentid));
- if (tmpForums != null) {
-
- pathlist += "<a href=\"showforum.action?forumid=" + tmpForums.getFid() + "\">"
- + tmpForums.getName().trim() + "</a>";
- }
- }
- }
-
- pathlist += "<a href=\"showforum.action?forumid=" + forum.getFid() + "\">" + forum.getName().trim()
- + "</a>";
- }
-
- forum.setPathlist(pathlist);
- forumManager.updateForum(forum);
- if (logger.isDebugEnabled()) {
- logger.debug("???? {} ??? {}", forum.getFid(), forum.getPathlist());
- }
- }
- }
-
- /**
- * ???????????
- * @return
- */
- @SuppressWarnings("unchecked")
- public List<Object[]> getForumTree() {
- return forumDAO.find("select fid,name from Forums");
- }
-
- /**
- * ???????????????displayorder???
- * @param minDisplayOrder
- */
- public void updateForumsDisplayOrder(int minDisplayOrder) {
- forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>?", minDisplayOrder);
- }
-
- /**
- * ??????????????
- * @param foruminfo
- * @return
- */
- public String insertForumsInf(Forums foruminfo) {
- forumDAO.save(foruminfo);
-
- setForumsPathList();
- LForumCache.getInstance().removeCache("ForumListBoxOptions");
- LForumCache.getInstance().removeCache("ForumList");
- LForumCache.getInstance().removeCache("HotForumList");
- LForumCache.getInstance().removeCache("ForumHotTopicList");
- LForumCache.getInstance().removeCache("ForumNewTopicList");
- if (logger.isDebugEnabled()) {
- logger.debug("???????? {} ??", foruminfo.getFid());
- }
- return setForumsModerators(foruminfo.getFid(), foruminfo.getForumfields().getModerators(), foruminfo
- .getInheritedmod());
-
- }
-
- /**
- * ??????????
- * @param fid ???????id
- * @param moderators ??????????(?:?","???)
- * @param inheritedmod ???????? 1??? 0????
- * @return
- */
- public String setForumsModerators(int fid, String moderators, int inheritedmod) {
- deleteModeratorByFid(fid);
-
- //???????
- if (inheritedmod == 1) {
- int parentid = fid;
- String parendidlist = "-1";
- while (true) {
- parentid = Utils.null2Int(forumDAO.findUnique(
- "select forums.fid from Forums where inheritedmod=1 and fid=?", fid));
- if (parentid == -1) {
- break;
- }
- if (parentid == 0) {
- break;
- }
-
- parendidlist = parendidlist + "," + parentid;
-
- }
-
- int count = 1;
- for (Users user : getUidModeratorByFid(parendidlist)) {
- addModerator(user, fid, count, 1);
- count++;
- }
- }
-
- insertForumsModerators(fid, moderators, 1, 0);
-
- return updateUserInfoWithModerator(moderators);
- }
-
- /**
- * ?????????????????????
- * @param moderators ??????????(?:?","???)
- * @return ???????????
- */
- public String updateUserInfoWithModerator(String moderators) {
- moderators = moderators == null ? "" : moderators;
- String usernamenoexsit = "";
- Object obj = new Object();
- for (String moderator : moderators.split(",")) {
- if (!moderator.equals("")) {
- //?????????????,??????????
- if (GlobalsKeys.SYSTEM_USERNAME.equals(moderator)) {
- continue;
- }
-
- obj = getModeratorInfo(moderator);
- if (obj != null) {
- Object[] objects = (Object[]) obj;
- int groupid = Utils.null2Int(objects[1]);
- if ((groupid <= 3) && (groupid > 0))
- continue; //?????,????,???
- else {
- int radminid = Utils.null2Int(forumDAO.findUnique(
- "select admingroups.admingid from Usergroups where groupid=?", groupid));
- if (radminid <= 0)
- setModerator(moderator);
- else
- continue;
- }
- } else {
- usernamenoexsit = usernamenoexsit + moderator + ",";
- }
- }
-
- }
-
- AdminCacheManager.reSetModeratorList();
-
- return usernamenoexsit;
- }
-
- public void setModerator(String moderator) {
- forumDAO.createQuery("update Users set admingroups.admingid=3,usergroups.groupid=3 where username=?",
- moderator.trim()).executeUpdate();
- forumDAO.createQuery("update Online set admingroups.admingid=3,usergroups.groupid=3 where username=?",
- moderator.trim()).executeUpdate();
- }
-
- /**
- * ??????
- * @param moderator ????
- * @return
- */
- public Object getModeratorInfo(String moderator) {
- return moderatorDAO
- .createQuery(
- "select uid,usergroups.groupid from Users where usergroups.groupid<>7 and usergroups.groupid<>8 and username=?",
- moderator).setMaxResults(1).uniqueResult();
- }
-
- /**
- * ???????????????
- * @param fid ???????????????
- * @param moderators ??????????(?:?","???)
- * @param displayorder ????
- * @param inherited ????????
- */
- @Transactional(readOnly = false)
- public void insertForumsModerators(int fid, String moderators, int displayorder, int inherited) {
- moderators = moderators == null ? "" : moderators;
- int count = displayorder;
- Forums forums = forumDAO.get(fid);
- //?????????
- String usernamelist = "";
- //???????????
- for (String username : moderators.split(",")) {
- if (!username.trim().equals("")) {
- Object object = forumDAO.createQuery(
- "select uid from Users where usergroups.groupid<>7 and usergroups.groupid<>8 and username=?",
- username).setMaxResults(1).uniqueResult();
- //??????????
- if (object != null) {
- Moderators moderator = new Moderators();
- moderator.setDisplayorder(count);
- moderator.setForums(forums);
- moderator.setInherited(inherited);
- moderator.setUsers(new Users(Utils.null2Int(object)));
- moderatorDAO.save(moderator);
- usernamelist = usernamelist + username.trim() + ",";
- count++;
- }
- }
- }
-
- if (!usernamelist.equals("")) {
- forums.getForumfields().setModerators(moderators);
- } else {
- forums.getForumfields().setModerators("");
- }
- forumDAO.save(forums);
- AdminCacheManager.reSetModeratorList();
- }
-
- /**
- * ??????
- * @param users ??
- * @param fid ??ID
- * @param displayorder ????
- * @param inherited ???????? 1??? 0????
- */
- public void addModerator(Users users, int fid, int displayorder, int inherited) {
- Forums forums = new Forums();
- forums.setFid(fid);
-
- Moderators moderators = new Moderators();
- moderators.setDisplayorder(displayorder);
- moderators.setForums(forums);
- moderators.setInherited(inherited);
- moderators.setUsers(users);
-
- moderatorDAO.save(moderators);
-
- if (logger.isDebugEnabled()) {
- logger.debug("???? {} ?? {} ??", fid, moderators.getId());
- }
- }
-
- /**
- * ??????????
- * @param fidlist
- * @return
- */
- @SuppressWarnings("unchecked")
- public List<Users> getUidModeratorByFid(String fidlist) {
- if (logger.isDebugEnabled()) {
- logger.debug("??????{}????", fidlist);
- }
- return forumDAO.find("select distinct users from Moderators where forums.fid in(" + fidlist + ")");
- }
-
- /**
- * ???????????
- *
- * @param fid
- */
- public void deleteModeratorByFid(int fid) {
- forumDAO.createQuery("delete from Moderators where forums.fid=?", fid).executeUpdate();
- }
-
- /**
- * ??????ID???????
- * @param fid ??ID
- * @return ??
- */
- public boolean isExistSubForum(int fid) {
- int count = Utils.null2Int(forumDAO.findUnique("select count(fid) from Forums where forums.fid=?", fid), 0);
- return count > 0 ? true : false;
- }
-
- /**
- * ????fid?????
- * @param fid ?????????fid
- * @return
- */
- @Transactional(readOnly = false)
- public boolean deleteForumsByFid(int fid) {
- if (isExistSubForum(fid)) {
- return false;
- }
- //??????????
- Forums forums = forumDAO.get(fid);
-
- //????????????????,??1??
- forumDAO.createQuery("update Forums set displayorder=displayorder-1 where displayorder>?",
- forums.getDisplayorder()).executeUpdate();
-
- //????????????
- forumDAO
- .createQuery("update Forums set subforumcount=subforumcount-1 where fid=?", forums.getForums().getFid())
- .executeUpdate();
-
- //?????????
- forumDAO.createQuery("delete from Polls where topics.tid in(select tid from Topics where forums.fid=?)", fid)
- .executeUpdate();
-
- //???????????
- forumDAO
- .createQuery(
- "delete from Attachments where topics.tid in(select tid from Topics where forums.fid=? or postid.pid in(select pid from Posts where forums.fid=?))",
- fid, fid).executeUpdate();
-
- //??????
- forumDAO.createQuery("delete from Posts where forums.fid=?", fid).executeUpdate();
-
- //??????
- forumDAO.createQuery("delete from Topics where forums.fid=?", fid).executeUpdate();
-
- //??????
- forumDAO.delete(forums);
-
- //????????????
- forumDAO.createQuery("delete from Moderators where forums.fid=?", fid).executeUpdate();
-
- LForumCache.getInstance().removeCache("ForumListBoxOptions");
- LForumCache.getInstance().removeCache("ForumList");
-
- if (logger.isDebugEnabled()) {
- logger.debug("?????? {} ??", fid);
- }
- return true;
- }
-
- /**
- * ?????????????
- * @param fid
- * @return
- */
- public int getTopForum(int fid) {
- return Utils.null2Int(forumDAO.createQuery("select fid from Forums where forums.fid=0 and fid=?", fid), -1);
- }
-
- /**
- * ????
- * @param sourcefid ????
- * @param targetfid ??????
- * @return
- */
- @Transactional(readOnly = false)
- public boolean combinationForums(int sourcefid, int targetfid) {
- if (isExistSubForum(sourcefid)) {
- return false;
- } else {
- childNode = "0";
- String fidlist = ("," + findChildNode(targetfid)).replace(",0,", "");
-
- //??????????
- forumDAO.createQuery("update Topics set forums.fid=? where forums.fid=?", targetfid, sourcefid)
- .executeUpdate();
-
- //???????????
- int totaltopics = Utils.null2Int(forumDAO.findUnique("select count(tid) from Topics where forums.fid in ("
- + fidlist + ")"), 0);
- int totalposts = 0;
-
- forumDAO.createQuery("update Posts set forums.fid=? where forums.fid=?", targetfid, sourcefid)
- .executeUpdate();
-
- //???????????
- totalposts = totalposts
- + Utils.null2Int(forumDAO.findUnique("select count(pid) from Posts where forums.fid in (" + fidlist
- + ")"), 0);
-
- // ??????
- Forums targetForum = forumDAO.get(targetfid);
- Forums sourceForum = forumDAO.get(sourcefid);
-
- targetForum.setTopics_1(totaltopics);
- targetForum.setPosts(totalposts);
-
- //????????????????,??1??
- forumDAO.createQuery("update Forums set displayorder=displayorder-1 where displayorder>?",
- sourceForum.getDisplayorder()).executeUpdate();
-
- //????????????
- forumDAO.createQuery("update Forums set subforumcount=subforumcount-1 where fid=?",
- sourceForum.getForums().getFid()).executeUpdate();
-
- //???????
- forumDAO.delete(sourceForum);
- forumManager.updateForum(targetForum);
-
- LForumCache.getInstance().removeCache("ForumListBoxOptions");
- LForumCache.getInstance().removeCache("ForumList");
- if (logger.isDebugEnabled()) {
- logger.debug("???? {} ????? {}", sourcefid, targetfid);
- }
- return true;
- }
- }
-
- /**
- * ????UID???????????
- * @param currentfid ??
- * @param uid UID
- * @return ?????-1
- */
- public int getUidInModeratorsByUid(int currentfid, int uid) {
- return Utils.null2Int(forumDAO.createQuery(
- "select users.uid from Moderators where forums.fid<>? and users.uid=?", currentfid, uid)
- .setMaxResults(1).uniqueResult());
- }
-
- /**
- * ??????????????,????????
- * @param oldmoderators ?????(?:?","???)
- * @param newmoderators ?????(?:?","???)
- * @param currentfid ???????fid
- */
- public void compareOldAndNewModerator(String oldmoderators, String newmoderators, int currentfid) {
- if (Utils.null2String(oldmoderators).equals("")) {
- return;
- }
-
- //??????????????????
- for (String oldmoderator : oldmoderators.split(",")) {
- if ((!oldmoderator.equals("")) && ("," + newmoderators + ",").indexOf("," + oldmoderator + ",") < 0) //?????????????????????????????
- {
- Object[] objects = userManager.getUidAdminIdByUsername(oldmoderator);
- if (objects != null) //??????
- {
- int uid = Utils.null2Int(objects[0]);
- int radminid = Utils.null2Int(objects[1]);
-
- //???????????? ,???????
- if ((getUidInModeratorsByUid(currentfid, uid) != -1) && (radminid != 1)) {
- Users userinfo = userManager.getUserInfo(uid);
-
- forumDAO.createQuery("update Online] SET usergroups.groupid=? where users.uid=?", userinfo
- .getUsergroups().getGroupid(), uid);
- Admingroups admingroups = new Admingroups();
- admingroups.setAdmingid(0);
- userinfo.setAdmingroups(admingroups);
- userManager.updateUserInfo(userinfo);
- }
- }
- }
- }
- }
-
- /**
- * ??????(??)?????
- * @param forums
- * @return
- */
- public String saveForumsInf(Forums forums) {
- forumManager.updateForum(forums);
- setForumsPathList();
-
- LForumCache.getInstance().removeCache("ForumListBoxOptions");
- LForumCache.getInstance().removeCache("ForumList");
- LForumCache.getInstance().removeCache("TopicTypesOption" + forums.getFid());
- LForumCache.getInstance().removeCache("TopicTypesLink" + forums.getFid());
- LForumCache.getInstance().removeCache("HotForumList");
- LForumCache.getInstance().removeCache("ForumHotTopicList");
- LForumCache.getInstance().removeCache("ForumNewTopicList");
- if (logger.isDebugEnabled()) {
- logger.debug("?????? {} ??", forums.getFid());
- }
- return setForumsModerators(forums.getFid(), forums.getForumfields().getModerators(), forums.getInheritedmod());
- }
- }