PageRenderTime 51ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/cn/javaeye/lonlysky/lforum/service/admin/AdminForumManager.java

http://fishkang.googlecode.com/
Java | 809 lines | 507 code | 103 blank | 199 comment | 102 complexity | a86f46c10a4698838a00cb9244c406ef MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. package cn.javaeye.lonlysky.lforum.service.admin;
  2. import java.util.List;
  3. import org.hibernate.SessionFactory;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import org.springside.modules.orm.hibernate.SimpleHibernateTemplate;
  10. import cn.javaeye.lonlysky.lforum.GlobalsKeys;
  11. import cn.javaeye.lonlysky.lforum.cache.LForumCache;
  12. import cn.javaeye.lonlysky.lforum.comm.utils.Utils;
  13. import cn.javaeye.lonlysky.lforum.entity.forum.Admingroups;
  14. import cn.javaeye.lonlysky.lforum.entity.forum.Forums;
  15. import cn.javaeye.lonlysky.lforum.entity.forum.Moderators;
  16. import cn.javaeye.lonlysky.lforum.entity.forum.Users;
  17. import cn.javaeye.lonlysky.lforum.service.ForumManager;
  18. import cn.javaeye.lonlysky.lforum.service.UserManager;
  19. /**
  20. * ?????????
  21. *
  22. * @author fishkang
  23. *
  24. */
  25. @Service
  26. @Transactional
  27. public class AdminForumManager {
  28. private static final Logger logger = LoggerFactory.getLogger(AdminForumManager.class);
  29. private SimpleHibernateTemplate<Forums, Integer> forumDAO;
  30. private SimpleHibernateTemplate<Moderators, Integer> moderatorDAO;
  31. @Autowired
  32. private ForumManager forumManager;
  33. @Autowired
  34. private UserManager userManager;
  35. @Autowired
  36. public void setSessionFactory(SessionFactory sessionFactory) {
  37. forumDAO = new SimpleHibernateTemplate<Forums, Integer>(sessionFactory, Forums.class);
  38. moderatorDAO = new SimpleHibernateTemplate<Moderators, Integer>(sessionFactory, Moderators.class);
  39. }
  40. /**
  41. * ?????????(layer)????(parentidlist)??
  42. */
  43. public void setForumslayer() {
  44. List<Forums> forumList = forumManager.getForumList();
  45. for (Forums forum : forumList) {
  46. int layer = 0;
  47. String parentidlist = "";
  48. int parentid = forum.getForums().getFid();
  49. //???(??)??????????
  50. if (parentid == 0) {
  51. // forum.setLayer(layer);
  52. // forum.setParentidlist("0");
  53. // forumManager.updateForum(forum);
  54. System.out.println("?????????:" + forum.getFid());
  55. forumDAO
  56. .createQuery("update Forums set layer=?,parentidlist=? where fid=?", layer, "0", forum.getFid())
  57. .executeUpdate();
  58. continue;
  59. }
  60. do { //????????(layer)????(parentidlist)??
  61. int tmp = parentid;
  62. parentid = Utils.null2Int(forumDAO.findUnique("select forums.fid from Forums where fid=?", parentid));
  63. layer++;
  64. if (parentid != 0) {
  65. parentidlist = tmp + "," + parentidlist;
  66. } else {
  67. parentidlist = tmp + "," + parentidlist;
  68. // forum.setLayer(layer);
  69. // forum.setParentidlist(parentidlist.substring(0, parentidlist.length() - 1));
  70. // forumManager.updateForum(forum);
  71. System.out.println("??????" + forum.getFid() + ",??:" + layer + ",??ID???"
  72. + parentidlist.substring(0, parentidlist.length() - 1));
  73. forumDAO.createQuery("update Forums set layer=?,parentidlist=? where fid=?", layer,
  74. parentidlist.substring(0, parentidlist.length() - 1), forum.getFid()).executeUpdate();
  75. break;
  76. }
  77. } while (true);
  78. }
  79. if (logger.isDebugEnabled()) {
  80. logger.debug("?????????(layer)????(parentidlist)??");
  81. }
  82. }
  83. public static String childNode = "0";
  84. /**
  85. * ?????????????
  86. * @param correntfid ??
  87. * @return ??????,??:1,2,3,4,
  88. */
  89. @SuppressWarnings("unchecked")
  90. public String findChildNode(int correntfid) {
  91. synchronized (childNode) {
  92. List<Object> list = forumDAO.find("select fid from Forums where forums.fid=? order by displayorder asc",
  93. correntfid);
  94. childNode = childNode + "," + correntfid;
  95. if (list.size() > 0) {
  96. //????
  97. for (Object object : list) {
  98. findChildNode(Utils.null2Int(object));
  99. }
  100. }
  101. if (logger.isDebugEnabled()) {
  102. logger.debug("???????{}", childNode);
  103. }
  104. return childNode;
  105. }
  106. }
  107. /**
  108. * ????????????
  109. */
  110. public void setForumsSubForumCountAndDispalyorder() {
  111. if (logger.isDebugEnabled()) {
  112. logger.debug("????????????");
  113. }
  114. List<Forums> forumList = forumManager.getForumList();
  115. for (Forums forum : forumList) {
  116. int subcount = forumDAO.find("select fid from Forums where forums.fid=?", forum.getFid()).size();
  117. // forumDAO.createQuery("update Forums set subforumcount=? where fid=?", subcount, forum.getFid())
  118. // .executeUpdate();
  119. forum.setSubforumcount(subcount);
  120. forumManager.updateForum(forum);
  121. System.out.println("?????????" + forum.getSubforumcount() + ",???" + forum.getFid());
  122. }
  123. if (forumList.size() == 1)
  124. return;
  125. int displayorder = 1;
  126. String fidlist;
  127. for (Forums forum : forumManager.getForumList("forums.fid=0")) {
  128. if (forum.getForums().getFid() == 0) {
  129. childNode = "0";
  130. fidlist = ("," + findChildNode(forum.getFid())).replace(",0,", "");
  131. for (String fidstr : fidlist.split(",")) {
  132. // forumDAO.createQuery("update Forums set displayorder=? where fid=?", displayorder,
  133. // Utils.null2Int(fidstr)).executeUpdate();
  134. Forums forums = forumDAO.get(Utils.null2Int(fidstr));
  135. forums.setDisplayorder(displayorder);
  136. forumManager.updateForum(forums);
  137. System.out.println("?????" + forums.getFid() + "?????" + forums.getDisplayorder());
  138. displayorder++;
  139. }
  140. }
  141. }
  142. }
  143. /**
  144. * ??????
  145. * @param currentfid ??????id
  146. * @param targetfid ??????id
  147. * @param isaschildnode ?????????
  148. * @return
  149. */
  150. @Transactional(readOnly = false)
  151. public void moveForumsPos(int currentfid, int targetfid, boolean isaschildnode) {
  152. if (logger.isDebugEnabled()) {
  153. logger.debug("????,?????{},?????{},????????" + isaschildnode, currentfid, targetfid);
  154. }
  155. //???????????
  156. Forums currentForum = forumDAO.get(currentfid);
  157. //???????????
  158. Forums targetForum = forumDAO.get(targetfid);
  159. //???????????
  160. if (forumDAO.find("select fid from Forums where forums.fid=?", currentfid).size() > 0) {
  161. System.out.println("??????????");
  162. if (isaschildnode) { //?????????
  163. //?????????(??)??????????????1(?????????????)
  164. forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=?",
  165. (targetForum.getDisplayorder() + 1)).executeUpdate();
  166. //?????????????
  167. currentForum.setForums(targetForum);
  168. currentForum.setDisplayorder(targetForum.getDisplayorder() + 1);
  169. // forumDAO.createQuery("update Forums set forums.fid=?,displayorder=? where fid=?", targetForum.getFid(),
  170. // targetForum.getDisplayorder() + 1, currentfid).executeUpdate();
  171. } else { //????????,???????????
  172. //?????????????????????????1(?????????????)
  173. forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=? or fid=?",
  174. targetForum.getDisplayorder(), targetForum.getFid()).executeUpdate();
  175. //?????????????
  176. currentForum.setForums(targetForum.getForums());
  177. currentForum.setDisplayorder(targetForum.getDisplayorder());
  178. // forumDAO.createQuery("update Forums set forums.fid=?,displayorder=? where fid=?",
  179. // targetForum.getForums().getFid(), targetForum.getDisplayorder(), currentfid).executeUpdate();
  180. }
  181. //???????????????????
  182. if (currentForum.getTopics_1() != 0 && currentForum.getTopics_1() > 0
  183. && (currentForum.getPosts() != 0 && currentForum.getPosts() > 0)) {
  184. if (!currentForum.getParentidlist().trim().equals("")) {
  185. forumDAO.createQuery(
  186. "update Forums set topics_1=topics_1-" + currentForum.getTopics_1() + ",posts=posts-"
  187. + currentForum.getPosts() + " where fid in("
  188. + currentForum.getParentidlist().trim() + ")").executeUpdate();
  189. }
  190. if (!targetForum.getParentidlist().trim().equals("")) {
  191. forumDAO.createQuery(
  192. "update Forums set topics_1=topics_1+" + currentForum.getTopics_1() + ",posts=posts+"
  193. + currentForum.getPosts() + " where fid in(" + targetForum.getParentidlist().trim()
  194. + ")").executeUpdate();
  195. }
  196. }
  197. } else { //??????????
  198. System.out.println("??????????");
  199. //????????????
  200. forumDAO.createQuery("update Forums set subforumcount=subforumcount-1 where fid=?",
  201. currentForum.getForums().getFid()).executeUpdate();
  202. //???????????????????1 [?????????]
  203. if (isaschildnode) { //?????????
  204. //????????????????
  205. if ((currentForum.getTopics_1() != 0) && (currentForum.getTopics_1() > 0)
  206. && (currentForum.getPosts() != 0) && (currentForum.getPosts() > 0)) {
  207. forumDAO.createQuery(
  208. "update Forums set topics_1=topics_1-" + currentForum.getTopics_1() + ",posts=posts-"
  209. + currentForum.getPosts() + " where fid in("
  210. + currentForum.getParentidlist().trim() + ")").executeUpdate();
  211. if (!targetForum.getParentidlist().trim().equals("0")) {
  212. forumDAO.createQuery(
  213. "update Forums set topics_1=topics_1+" + currentForum.getTopics_1() + ",posts=posts+"
  214. + currentForum.getPosts() + " where fid in("
  215. + targetForum.getParentidlist().trim() + "," + targetfid + ")").executeUpdate();
  216. }
  217. }
  218. //???????????????????????1(?????????????)
  219. forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=?",
  220. targetForum.getDisplayorder() + 1).executeUpdate();
  221. //????????????
  222. targetForum.setSubforumcount(targetForum.getSubforumcount() + 1);
  223. // forumDAO.createQuery("update Forums set subforumcount=subforumcount+1 where fid=?", targetfid)
  224. // .executeUpdate();
  225. String parentidlist = null;
  226. if (targetForum.getParentidlist().trim().equals("0")) {
  227. parentidlist = targetfid + "";
  228. } else {
  229. parentidlist = targetForum.getParentidlist().trim() + "," + targetfid;
  230. }
  231. //?????????????
  232. currentForum.setForums(targetForum);
  233. currentForum.setLayer(targetForum.getLayer() + 1);
  234. currentForum.setPathlist(targetForum.getPathlist().trim() + "<a href=\"showforum.action?forumid="
  235. + currentfid + "\">" + currentForum.getName().trim().replace("'", "''") + "</a>");
  236. currentForum.setParentidlist(parentidlist);
  237. currentForum.setDisplayorder(targetForum.getDisplayorder() + 1);
  238. System.out.println("??????????" + currentForum.getLayer());
  239. // forumDAO.createQuery(
  240. // "update Forums set forums.fid=?,layer=?,pathlist=?,parentidlist=?,displayorder=? where fid=?",
  241. // targetForum.getFid(),
  242. // targetForum.getLayer() + 1,
  243. // targetForum.getPathlist().trim() + "<a href=\"showforum.action?forumid=" + currentfid + "\">"
  244. // + currentForum.getName().trim().replace("'", "''") + "</a>", parentidlist,
  245. // targetForum.getDisplayorder() + 1, currentfid).executeUpdate();
  246. } else { //????????,???????????
  247. //????????????????
  248. if ((currentForum.getTopics_1() != 0) && (currentForum.getTopics_1() > 0)
  249. && (currentForum.getPosts() != 0) && (currentForum.getPosts() > 0)) {
  250. forumDAO.createQuery(
  251. "update Forums set topics_1=topics_1-" + currentForum.getTopics_1() + ",posts=posts-"
  252. + currentForum.getPosts() + " where fid in("
  253. + currentForum.getParentidlist().trim() + ")").executeUpdate();
  254. forumDAO.createQuery(
  255. "update Forums set topics_1=topics_1+" + currentForum.getTopics_1() + ",posts=posts+"
  256. + currentForum.getPosts() + " where fid in(" + targetForum.getParentidlist().trim()
  257. + ")").executeUpdate();
  258. }
  259. //?????????????????????????1(?????????????)
  260. forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>=? or fid=?",
  261. targetForum.getDisplayorder() + 1, targetForum.getFid()).executeUpdate();
  262. //????????????
  263. forumDAO.createQuery("update Forums set subforumcount=subforumcount+1 where fid=?",
  264. targetForum.getForums().getFid()).executeUpdate();
  265. String parentpathlist = Utils.null2String(forumDAO.findUnique(
  266. "select pathlist from Forums where fid=?", targetForum.getForums().getFid()));
  267. //?????????????
  268. currentForum.setForums(targetForum.getForums());
  269. currentForum.setLayer(targetForum.getLayer());
  270. currentForum.setPathlist(parentpathlist + "<a href=\"showforum.action?forumid=" + currentfid + "\">"
  271. + currentForum.getName().trim() + "</a>");
  272. currentForum.setParentidlist(targetForum.getParentidlist().trim());
  273. currentForum.setDisplayorder(targetForum.getDisplayorder());
  274. // forumDAO.createQuery(
  275. // "update Forums set forums.fid=?,layer=?,pathlist=?,parentidlist=?,displayorder=? where fid=?",
  276. // targetForum.getForums().getFid(),
  277. // targetForum.getLayer(),
  278. // parentpathlist + "<a href=\"showforum.action?forumid=" + currentfid + "\">"
  279. // + currentForum.getName().trim() + "</a>", targetForum.getParentidlist().trim(),
  280. // targetForum.getDisplayorder(), currentfid).executeUpdate();
  281. }
  282. }
  283. forumManager.updateForum(currentForum);
  284. forumManager.updateForum(targetForum);
  285. }
  286. /**
  287. * ??????
  288. * @param currentfid ??????id
  289. * @param targetfid ??????id
  290. * @param isaschildnode ?????????
  291. * @return
  292. */
  293. public boolean movingForumsPos(int currentfid, int targetfid, boolean isaschildnode) {
  294. moveForumsPos(currentfid, targetfid, isaschildnode);
  295. setForumslayer();
  296. setForumsSubForumCountAndDispalyorder();
  297. setForumsPathList();
  298. LForumCache.getInstance().removeCache("ForumListBoxOptions");
  299. LForumCache.getInstance().removeCache("ForumList");
  300. return true;
  301. }
  302. /**
  303. * ???????????(pathlist)??
  304. */
  305. @Transactional(readOnly = false)
  306. public void setForumsPathList() {
  307. List<Forums> forumList = forumManager.getForumList();
  308. for (Forums forum : forumList) {
  309. String pathlist = "";
  310. if (forum.getParentidlist().trim().equals("0")) {
  311. pathlist = "<a href=\"showforum.action?forumid=" + forum.getFid() + "\">" + forum.getName().trim()
  312. + "</a>";
  313. } else {
  314. for (String parentid : forum.getParentidlist().trim().split(",")) {
  315. if (!parentid.trim().equals("")) {
  316. Forums tmpForums = forumDAO.get(Utils.null2Int(parentid));
  317. if (tmpForums != null) {
  318. pathlist += "<a href=\"showforum.action?forumid=" + tmpForums.getFid() + "\">"
  319. + tmpForums.getName().trim() + "</a>";
  320. }
  321. }
  322. }
  323. pathlist += "<a href=\"showforum.action?forumid=" + forum.getFid() + "\">" + forum.getName().trim()
  324. + "</a>";
  325. }
  326. forum.setPathlist(pathlist);
  327. forumManager.updateForum(forum);
  328. if (logger.isDebugEnabled()) {
  329. logger.debug("???? {} ??? {}", forum.getFid(), forum.getPathlist());
  330. }
  331. }
  332. }
  333. /**
  334. * ???????????
  335. * @return
  336. */
  337. @SuppressWarnings("unchecked")
  338. public List<Object[]> getForumTree() {
  339. return forumDAO.find("select fid,name from Forums");
  340. }
  341. /**
  342. * ???????????????displayorder???
  343. * @param minDisplayOrder
  344. */
  345. public void updateForumsDisplayOrder(int minDisplayOrder) {
  346. forumDAO.createQuery("update Forums set displayorder=displayorder+1 where displayorder>?", minDisplayOrder);
  347. }
  348. /**
  349. * ??????????????
  350. * @param foruminfo
  351. * @return
  352. */
  353. public String insertForumsInf(Forums foruminfo) {
  354. forumDAO.save(foruminfo);
  355. setForumsPathList();
  356. LForumCache.getInstance().removeCache("ForumListBoxOptions");
  357. LForumCache.getInstance().removeCache("ForumList");
  358. LForumCache.getInstance().removeCache("HotForumList");
  359. LForumCache.getInstance().removeCache("ForumHotTopicList");
  360. LForumCache.getInstance().removeCache("ForumNewTopicList");
  361. if (logger.isDebugEnabled()) {
  362. logger.debug("???????? {} ??", foruminfo.getFid());
  363. }
  364. return setForumsModerators(foruminfo.getFid(), foruminfo.getForumfields().getModerators(), foruminfo
  365. .getInheritedmod());
  366. }
  367. /**
  368. * ??????????
  369. * @param fid ???????id
  370. * @param moderators ??????????(?:?","???)
  371. * @param inheritedmod ???????? 1??? 0????
  372. * @return
  373. */
  374. public String setForumsModerators(int fid, String moderators, int inheritedmod) {
  375. deleteModeratorByFid(fid);
  376. //???????
  377. if (inheritedmod == 1) {
  378. int parentid = fid;
  379. String parendidlist = "-1";
  380. while (true) {
  381. parentid = Utils.null2Int(forumDAO.findUnique(
  382. "select forums.fid from Forums where inheritedmod=1 and fid=?", fid));
  383. if (parentid == -1) {
  384. break;
  385. }
  386. if (parentid == 0) {
  387. break;
  388. }
  389. parendidlist = parendidlist + "," + parentid;
  390. }
  391. int count = 1;
  392. for (Users user : getUidModeratorByFid(parendidlist)) {
  393. addModerator(user, fid, count, 1);
  394. count++;
  395. }
  396. }
  397. insertForumsModerators(fid, moderators, 1, 0);
  398. return updateUserInfoWithModerator(moderators);
  399. }
  400. /**
  401. * ?????????????????????
  402. * @param moderators ??????????(?:?","???)
  403. * @return ???????????
  404. */
  405. public String updateUserInfoWithModerator(String moderators) {
  406. moderators = moderators == null ? "" : moderators;
  407. String usernamenoexsit = "";
  408. Object obj = new Object();
  409. for (String moderator : moderators.split(",")) {
  410. if (!moderator.equals("")) {
  411. //?????????????,??????????
  412. if (GlobalsKeys.SYSTEM_USERNAME.equals(moderator)) {
  413. continue;
  414. }
  415. obj = getModeratorInfo(moderator);
  416. if (obj != null) {
  417. Object[] objects = (Object[]) obj;
  418. int groupid = Utils.null2Int(objects[1]);
  419. if ((groupid <= 3) && (groupid > 0))
  420. continue; //?????,????,???
  421. else {
  422. int radminid = Utils.null2Int(forumDAO.findUnique(
  423. "select admingroups.admingid from Usergroups where groupid=?", groupid));
  424. if (radminid <= 0)
  425. setModerator(moderator);
  426. else
  427. continue;
  428. }
  429. } else {
  430. usernamenoexsit = usernamenoexsit + moderator + ",";
  431. }
  432. }
  433. }
  434. AdminCacheManager.reSetModeratorList();
  435. return usernamenoexsit;
  436. }
  437. public void setModerator(String moderator) {
  438. forumDAO.createQuery("update Users set admingroups.admingid=3,usergroups.groupid=3 where username=?",
  439. moderator.trim()).executeUpdate();
  440. forumDAO.createQuery("update Online set admingroups.admingid=3,usergroups.groupid=3 where username=?",
  441. moderator.trim()).executeUpdate();
  442. }
  443. /**
  444. * ??????
  445. * @param moderator ????
  446. * @return
  447. */
  448. public Object getModeratorInfo(String moderator) {
  449. return moderatorDAO
  450. .createQuery(
  451. "select uid,usergroups.groupid from Users where usergroups.groupid<>7 and usergroups.groupid<>8 and username=?",
  452. moderator).setMaxResults(1).uniqueResult();
  453. }
  454. /**
  455. * ???????????????
  456. * @param fid ???????????????
  457. * @param moderators ??????????(?:?","???)
  458. * @param displayorder ????
  459. * @param inherited ????????
  460. */
  461. @Transactional(readOnly = false)
  462. public void insertForumsModerators(int fid, String moderators, int displayorder, int inherited) {
  463. moderators = moderators == null ? "" : moderators;
  464. int count = displayorder;
  465. Forums forums = forumDAO.get(fid);
  466. //?????????
  467. String usernamelist = "";
  468. //???????????
  469. for (String username : moderators.split(",")) {
  470. if (!username.trim().equals("")) {
  471. Object object = forumDAO.createQuery(
  472. "select uid from Users where usergroups.groupid<>7 and usergroups.groupid<>8 and username=?",
  473. username).setMaxResults(1).uniqueResult();
  474. //??????????
  475. if (object != null) {
  476. Moderators moderator = new Moderators();
  477. moderator.setDisplayorder(count);
  478. moderator.setForums(forums);
  479. moderator.setInherited(inherited);
  480. moderator.setUsers(new Users(Utils.null2Int(object)));
  481. moderatorDAO.save(moderator);
  482. usernamelist = usernamelist + username.trim() + ",";
  483. count++;
  484. }
  485. }
  486. }
  487. if (!usernamelist.equals("")) {
  488. forums.getForumfields().setModerators(moderators);
  489. } else {
  490. forums.getForumfields().setModerators("");
  491. }
  492. forumDAO.save(forums);
  493. AdminCacheManager.reSetModeratorList();
  494. }
  495. /**
  496. * ??????
  497. * @param users ??
  498. * @param fid ??ID
  499. * @param displayorder ????
  500. * @param inherited ???????? 1??? 0????
  501. */
  502. public void addModerator(Users users, int fid, int displayorder, int inherited) {
  503. Forums forums = new Forums();
  504. forums.setFid(fid);
  505. Moderators moderators = new Moderators();
  506. moderators.setDisplayorder(displayorder);
  507. moderators.setForums(forums);
  508. moderators.setInherited(inherited);
  509. moderators.setUsers(users);
  510. moderatorDAO.save(moderators);
  511. if (logger.isDebugEnabled()) {
  512. logger.debug("???? {} ?? {} ??", fid, moderators.getId());
  513. }
  514. }
  515. /**
  516. * ??????????
  517. * @param fidlist
  518. * @return
  519. */
  520. @SuppressWarnings("unchecked")
  521. public List<Users> getUidModeratorByFid(String fidlist) {
  522. if (logger.isDebugEnabled()) {
  523. logger.debug("??????{}????", fidlist);
  524. }
  525. return forumDAO.find("select distinct users from Moderators where forums.fid in(" + fidlist + ")");
  526. }
  527. /**
  528. * ???????????
  529. *
  530. * @param fid
  531. */
  532. public void deleteModeratorByFid(int fid) {
  533. forumDAO.createQuery("delete from Moderators where forums.fid=?", fid).executeUpdate();
  534. }
  535. /**
  536. * ??????ID???????
  537. * @param fid ??ID
  538. * @return ??
  539. */
  540. public boolean isExistSubForum(int fid) {
  541. int count = Utils.null2Int(forumDAO.findUnique("select count(fid) from Forums where forums.fid=?", fid), 0);
  542. return count > 0 ? true : false;
  543. }
  544. /**
  545. * ????fid?????
  546. * @param fid ?????????fid
  547. * @return
  548. */
  549. @Transactional(readOnly = false)
  550. public boolean deleteForumsByFid(int fid) {
  551. if (isExistSubForum(fid)) {
  552. return false;
  553. }
  554. //??????????
  555. Forums forums = forumDAO.get(fid);
  556. //????????????????,??1??
  557. forumDAO.createQuery("update Forums set displayorder=displayorder-1 where displayorder>?",
  558. forums.getDisplayorder()).executeUpdate();
  559. //????????????
  560. forumDAO
  561. .createQuery("update Forums set subforumcount=subforumcount-1 where fid=?", forums.getForums().getFid())
  562. .executeUpdate();
  563. //?????????
  564. forumDAO.createQuery("delete from Polls where topics.tid in(select tid from Topics where forums.fid=?)", fid)
  565. .executeUpdate();
  566. //???????????
  567. forumDAO
  568. .createQuery(
  569. "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=?))",
  570. fid, fid).executeUpdate();
  571. //??????
  572. forumDAO.createQuery("delete from Posts where forums.fid=?", fid).executeUpdate();
  573. //??????
  574. forumDAO.createQuery("delete from Topics where forums.fid=?", fid).executeUpdate();
  575. //??????
  576. forumDAO.delete(forums);
  577. //????????????
  578. forumDAO.createQuery("delete from Moderators where forums.fid=?", fid).executeUpdate();
  579. LForumCache.getInstance().removeCache("ForumListBoxOptions");
  580. LForumCache.getInstance().removeCache("ForumList");
  581. if (logger.isDebugEnabled()) {
  582. logger.debug("?????? {} ??", fid);
  583. }
  584. return true;
  585. }
  586. /**
  587. * ?????????????
  588. * @param fid
  589. * @return
  590. */
  591. public int getTopForum(int fid) {
  592. return Utils.null2Int(forumDAO.createQuery("select fid from Forums where forums.fid=0 and fid=?", fid), -1);
  593. }
  594. /**
  595. * ????
  596. * @param sourcefid ????
  597. * @param targetfid ??????
  598. * @return
  599. */
  600. @Transactional(readOnly = false)
  601. public boolean combinationForums(int sourcefid, int targetfid) {
  602. if (isExistSubForum(sourcefid)) {
  603. return false;
  604. } else {
  605. childNode = "0";
  606. String fidlist = ("," + findChildNode(targetfid)).replace(",0,", "");
  607. //??????????
  608. forumDAO.createQuery("update Topics set forums.fid=? where forums.fid=?", targetfid, sourcefid)
  609. .executeUpdate();
  610. //???????????
  611. int totaltopics = Utils.null2Int(forumDAO.findUnique("select count(tid) from Topics where forums.fid in ("
  612. + fidlist + ")"), 0);
  613. int totalposts = 0;
  614. forumDAO.createQuery("update Posts set forums.fid=? where forums.fid=?", targetfid, sourcefid)
  615. .executeUpdate();
  616. //???????????
  617. totalposts = totalposts
  618. + Utils.null2Int(forumDAO.findUnique("select count(pid) from Posts where forums.fid in (" + fidlist
  619. + ")"), 0);
  620. // ??????
  621. Forums targetForum = forumDAO.get(targetfid);
  622. Forums sourceForum = forumDAO.get(sourcefid);
  623. targetForum.setTopics_1(totaltopics);
  624. targetForum.setPosts(totalposts);
  625. //????????????????,??1??
  626. forumDAO.createQuery("update Forums set displayorder=displayorder-1 where displayorder>?",
  627. sourceForum.getDisplayorder()).executeUpdate();
  628. //????????????
  629. forumDAO.createQuery("update Forums set subforumcount=subforumcount-1 where fid=?",
  630. sourceForum.getForums().getFid()).executeUpdate();
  631. //???????
  632. forumDAO.delete(sourceForum);
  633. forumManager.updateForum(targetForum);
  634. LForumCache.getInstance().removeCache("ForumListBoxOptions");
  635. LForumCache.getInstance().removeCache("ForumList");
  636. if (logger.isDebugEnabled()) {
  637. logger.debug("???? {} ????? {}", sourcefid, targetfid);
  638. }
  639. return true;
  640. }
  641. }
  642. /**
  643. * ????UID???????????
  644. * @param currentfid ??
  645. * @param uid UID
  646. * @return ?????-1
  647. */
  648. public int getUidInModeratorsByUid(int currentfid, int uid) {
  649. return Utils.null2Int(forumDAO.createQuery(
  650. "select users.uid from Moderators where forums.fid<>? and users.uid=?", currentfid, uid)
  651. .setMaxResults(1).uniqueResult());
  652. }
  653. /**
  654. * ??????????????,????????
  655. * @param oldmoderators ?????(?:?","???)
  656. * @param newmoderators ?????(?:?","???)
  657. * @param currentfid ???????fid
  658. */
  659. public void compareOldAndNewModerator(String oldmoderators, String newmoderators, int currentfid) {
  660. if (Utils.null2String(oldmoderators).equals("")) {
  661. return;
  662. }
  663. //??????????????????
  664. for (String oldmoderator : oldmoderators.split(",")) {
  665. if ((!oldmoderator.equals("")) && ("," + newmoderators + ",").indexOf("," + oldmoderator + ",") < 0) //?????????????????????????????
  666. {
  667. Object[] objects = userManager.getUidAdminIdByUsername(oldmoderator);
  668. if (objects != null) //??????
  669. {
  670. int uid = Utils.null2Int(objects[0]);
  671. int radminid = Utils.null2Int(objects[1]);
  672. //???????????? ,???????
  673. if ((getUidInModeratorsByUid(currentfid, uid) != -1) && (radminid != 1)) {
  674. Users userinfo = userManager.getUserInfo(uid);
  675. forumDAO.createQuery("update Online] SET usergroups.groupid=? where users.uid=?", userinfo
  676. .getUsergroups().getGroupid(), uid);
  677. Admingroups admingroups = new Admingroups();
  678. admingroups.setAdmingid(0);
  679. userinfo.setAdmingroups(admingroups);
  680. userManager.updateUserInfo(userinfo);
  681. }
  682. }
  683. }
  684. }
  685. }
  686. /**
  687. * ??????(??)?????
  688. * @param forums
  689. * @return
  690. */
  691. public String saveForumsInf(Forums forums) {
  692. forumManager.updateForum(forums);
  693. setForumsPathList();
  694. LForumCache.getInstance().removeCache("ForumListBoxOptions");
  695. LForumCache.getInstance().removeCache("ForumList");
  696. LForumCache.getInstance().removeCache("TopicTypesOption" + forums.getFid());
  697. LForumCache.getInstance().removeCache("TopicTypesLink" + forums.getFid());
  698. LForumCache.getInstance().removeCache("HotForumList");
  699. LForumCache.getInstance().removeCache("ForumHotTopicList");
  700. LForumCache.getInstance().removeCache("ForumNewTopicList");
  701. if (logger.isDebugEnabled()) {
  702. logger.debug("?????? {} ??", forums.getFid());
  703. }
  704. return setForumsModerators(forums.getFid(), forums.getForumfields().getModerators(), forums.getInheritedmod());
  705. }
  706. }