NavigationGuestManageService.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package space.apps.moudules.website.services;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import space.apps.moudules.website.util.WebsiteGuestAccessUtil;
  6. import space.core.apps.common.BaseTransaction;
  7. import space.core.common.utils.StringUtil;
  8. import space.core.db.jdbc.GeneralDBAccess;
  9. import space.core.db.jdbc.SqlCommandImpl;
  10. /**
  11. * 栏目游客权限配置。
  12. */
  13. public class NavigationGuestManageService extends BaseTransaction {
  14. private static final long serialVersionUID = 1L;
  15. public void getGuestAccessSetting() throws Exception {
  16. GeneralDBAccess gdba = getGdbaInstance();
  17. Long navigationId = getParameterToLong("navigationid");
  18. int guestAccessFlag = WebsiteGuestAccessUtil.getNavigationGuestAccessFlag(gdba, navigationId);
  19. List<Long> accountIds = WebsiteGuestAccessUtil.getNavigationAllowedAccountIds(gdba, navigationId);
  20. Map<String, Object> data = new HashMap<String, Object>();
  21. data.put("guestAccessFlag", guestAccessFlag);
  22. data.put("guestAccountIds", WebsiteGuestAccessUtil.joinIds(accountIds));
  23. write(getResponseSuccessDataPackage(data).toJson());
  24. }
  25. public String saveGuestAccess() throws Exception {
  26. GeneralDBAccess gdba = getGdbaInstance();
  27. Long navigationId = getParameterToLong("navigationid");
  28. String guestAccessFlag = getParameter("guestAccessFlag");
  29. String guestAccountIds = getParameter("guestAccountIds");
  30. if (navigationId == null) {
  31. setResponsePackage(getResponseErrorMsgPackage("栏目不能为空"));
  32. return DEFAULT_FORWARD;
  33. }
  34. int flag = "1".equals(guestAccessFlag) || "true".equalsIgnoreCase(guestAccessFlag)
  35. ? WebsiteGuestAccessUtil.GUEST_ACCESS_PROTECTED
  36. : WebsiteGuestAccessUtil.GUEST_ACCESS_PUBLIC;
  37. WebsiteGuestAccessUtil.updateNavigationGuestAccessFlag(gdba, navigationId, flag);
  38. WebsiteGuestAccessUtil.replaceNavigationGuestAccess(gdba, navigationId, guestAccountIds, getAppUser().getUserId());
  39. mirrorGuestAccessToInternalJumpTarget(gdba, navigationId, flag, guestAccountIds);
  40. gdba.commit();
  41. setResponsePackage(getResponseSuccessMsgPackage("保存成功"));
  42. return DEFAULT_FORWARD;
  43. }
  44. public void saveArticleGuestAccessApi() throws Exception {
  45. GeneralDBAccess gdba = getGdbaInstance();
  46. Long articleId = getParameterToLong("articleid");
  47. String guestAccessFlag = getParameter("guestAccessFlag");
  48. String guestAccountIds = getParameter("guestAccountIds");
  49. if (articleId == null) {
  50. write(getResponseErrorMsgPackage("文章不能为空").toJson());
  51. return;
  52. }
  53. int flag = "1".equals(guestAccessFlag) || "true".equalsIgnoreCase(guestAccessFlag)
  54. ? WebsiteGuestAccessUtil.ARTICLE_GUEST_STANDALONE
  55. : WebsiteGuestAccessUtil.ARTICLE_GUEST_FOLLOW_NAV;
  56. WebsiteGuestAccessUtil.updateArticleGuestAccessFlag(gdba, articleId, flag);
  57. if (flag == WebsiteGuestAccessUtil.ARTICLE_GUEST_STANDALONE) {
  58. WebsiteGuestAccessUtil.replaceArticleGuestAccess(gdba, articleId, guestAccountIds, getAppUser().getUserId());
  59. } else {
  60. WebsiteGuestAccessUtil.replaceArticleGuestAccess(gdba, articleId, "", getAppUser().getUserId());
  61. }
  62. gdba.commit();
  63. write(getResponseSuccessMsgPackage("保存成功").toJson());
  64. }
  65. public void getArticleGuestAccessSetting() throws Exception {
  66. GeneralDBAccess gdba = getGdbaInstance();
  67. Long articleId = getParameterToLong("articleid");
  68. int guestAccessFlag = WebsiteGuestAccessUtil.getArticleGuestAccessFlag(gdba, articleId);
  69. List<Long> accountIds = WebsiteGuestAccessUtil.getArticleAllowedAccountIds(gdba, articleId);
  70. Map<String, Object> data = new HashMap<String, Object>();
  71. data.put("guestAccessFlag", guestAccessFlag);
  72. data.put("guestAccountIds", WebsiteGuestAccessUtil.joinIds(accountIds));
  73. write(getResponseSuccessDataPackage(data).toJson());
  74. }
  75. public void getWebsiteIdByNavigationApi() throws Exception {
  76. GeneralDBAccess gdba = getGdbaInstance();
  77. Long navigationId = getParameterToLong("navigationid");
  78. String sql = " select websiteid from website_navigation where navigationid = :navigationid ";
  79. SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
  80. sqlCmd.setString("navigationid", navigationId);
  81. Map<String, Object> row = gdba.selectAsMap(sqlCmd);
  82. Map<String, Object> data = new HashMap<String, Object>();
  83. if (row != null) {
  84. data.put("websiteid", row.get("websiteid"));
  85. }
  86. write(getResponseSuccessDataPackage(data).toJson());
  87. }
  88. /**
  89. * 自定义链接(站内跳转)在后台勾选游客权限时,同步到 jump_url 对应的真实列表栏目。
  90. */
  91. private void mirrorGuestAccessToInternalJumpTarget(GeneralDBAccess gdba, Long navigationId, int flag,
  92. String guestAccountIds) throws Exception {
  93. String sql = " select websiteid, wntcode, jump_url from website_navigation where navigationid = :navigationid ";
  94. SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
  95. sqlCmd.setString("navigationid", navigationId);
  96. Map<String, Object> row = gdba.selectAsMap(sqlCmd);
  97. if (row == null || row.isEmpty()) {
  98. return;
  99. }
  100. Object wntcodeObj = row.get("wntcode");
  101. Object websiteIdObj = row.get("websiteid");
  102. Object jumpUrlObj = row.get("jump_url");
  103. if (wntcodeObj == null || websiteIdObj == null || jumpUrlObj == null) {
  104. return;
  105. }
  106. if (Long.parseLong(wntcodeObj.toString()) != 10030L) {
  107. return;
  108. }
  109. String jumpUrl = jumpUrlObj.toString().trim();
  110. if (StringUtil.isNull(jumpUrl) || jumpUrl.startsWith("http://") || jumpUrl.startsWith("https://")
  111. || jumpUrl.startsWith("javascript:")) {
  112. return;
  113. }
  114. String targetSql = " select navigationid from website_navigation where websiteid = :websiteid and dcode = 61 and url = :url limit 1 ";
  115. SqlCommandImpl targetCmd = new SqlCommandImpl(targetSql);
  116. targetCmd.setString("websiteid", websiteIdObj).setString("url", jumpUrl);
  117. Map<String, Object> targetRow = gdba.selectAsMap(targetCmd);
  118. if (targetRow == null || targetRow.get("navigationid") == null) {
  119. return;
  120. }
  121. Long targetNavigationId = Long.valueOf(targetRow.get("navigationid").toString());
  122. if (targetNavigationId.equals(navigationId)) {
  123. return;
  124. }
  125. WebsiteGuestAccessUtil.updateNavigationGuestAccessFlag(gdba, targetNavigationId, flag);
  126. WebsiteGuestAccessUtil.replaceNavigationGuestAccess(gdba, targetNavigationId, guestAccountIds,
  127. getAppUser().getUserId());
  128. }
  129. }