| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package space.apps.moudules.website.services;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import space.apps.moudules.website.util.WebsiteGuestAccessUtil;
- import space.core.apps.common.BaseTransaction;
- import space.core.common.utils.StringUtil;
- import space.core.db.jdbc.GeneralDBAccess;
- import space.core.db.jdbc.SqlCommandImpl;
- /**
- * 栏目游客权限配置。
- */
- public class NavigationGuestManageService extends BaseTransaction {
- private static final long serialVersionUID = 1L;
- public void getGuestAccessSetting() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Long navigationId = getParameterToLong("navigationid");
- int guestAccessFlag = WebsiteGuestAccessUtil.getNavigationGuestAccessFlag(gdba, navigationId);
- List<Long> accountIds = WebsiteGuestAccessUtil.getNavigationAllowedAccountIds(gdba, navigationId);
- Map<String, Object> data = new HashMap<String, Object>();
- data.put("guestAccessFlag", guestAccessFlag);
- data.put("guestAccountIds", WebsiteGuestAccessUtil.joinIds(accountIds));
- write(getResponseSuccessDataPackage(data).toJson());
- }
- public String saveGuestAccess() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Long navigationId = getParameterToLong("navigationid");
- String guestAccessFlag = getParameter("guestAccessFlag");
- String guestAccountIds = getParameter("guestAccountIds");
- if (navigationId == null) {
- setResponsePackage(getResponseErrorMsgPackage("栏目不能为空"));
- return DEFAULT_FORWARD;
- }
- int flag = "1".equals(guestAccessFlag) || "true".equalsIgnoreCase(guestAccessFlag)
- ? WebsiteGuestAccessUtil.GUEST_ACCESS_PROTECTED
- : WebsiteGuestAccessUtil.GUEST_ACCESS_PUBLIC;
- WebsiteGuestAccessUtil.updateNavigationGuestAccessFlag(gdba, navigationId, flag);
- WebsiteGuestAccessUtil.replaceNavigationGuestAccess(gdba, navigationId, guestAccountIds, getAppUser().getUserId());
- mirrorGuestAccessToInternalJumpTarget(gdba, navigationId, flag, guestAccountIds);
- gdba.commit();
- setResponsePackage(getResponseSuccessMsgPackage("保存成功"));
- return DEFAULT_FORWARD;
- }
- public void saveArticleGuestAccessApi() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Long articleId = getParameterToLong("articleid");
- String guestAccessFlag = getParameter("guestAccessFlag");
- String guestAccountIds = getParameter("guestAccountIds");
- if (articleId == null) {
- write(getResponseErrorMsgPackage("文章不能为空").toJson());
- return;
- }
- int flag = "1".equals(guestAccessFlag) || "true".equalsIgnoreCase(guestAccessFlag)
- ? WebsiteGuestAccessUtil.ARTICLE_GUEST_STANDALONE
- : WebsiteGuestAccessUtil.ARTICLE_GUEST_FOLLOW_NAV;
- WebsiteGuestAccessUtil.updateArticleGuestAccessFlag(gdba, articleId, flag);
- if (flag == WebsiteGuestAccessUtil.ARTICLE_GUEST_STANDALONE) {
- WebsiteGuestAccessUtil.replaceArticleGuestAccess(gdba, articleId, guestAccountIds, getAppUser().getUserId());
- } else {
- WebsiteGuestAccessUtil.replaceArticleGuestAccess(gdba, articleId, "", getAppUser().getUserId());
- }
- gdba.commit();
- write(getResponseSuccessMsgPackage("保存成功").toJson());
- }
- public void getArticleGuestAccessSetting() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Long articleId = getParameterToLong("articleid");
- int guestAccessFlag = WebsiteGuestAccessUtil.getArticleGuestAccessFlag(gdba, articleId);
- List<Long> accountIds = WebsiteGuestAccessUtil.getArticleAllowedAccountIds(gdba, articleId);
- Map<String, Object> data = new HashMap<String, Object>();
- data.put("guestAccessFlag", guestAccessFlag);
- data.put("guestAccountIds", WebsiteGuestAccessUtil.joinIds(accountIds));
- write(getResponseSuccessDataPackage(data).toJson());
- }
- public void getWebsiteIdByNavigationApi() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Long navigationId = getParameterToLong("navigationid");
- String sql = " select websiteid from website_navigation where navigationid = :navigationid ";
- SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
- sqlCmd.setString("navigationid", navigationId);
- Map<String, Object> row = gdba.selectAsMap(sqlCmd);
- Map<String, Object> data = new HashMap<String, Object>();
- if (row != null) {
- data.put("websiteid", row.get("websiteid"));
- }
- write(getResponseSuccessDataPackage(data).toJson());
- }
- /**
- * 自定义链接(站内跳转)在后台勾选游客权限时,同步到 jump_url 对应的真实列表栏目。
- */
- private void mirrorGuestAccessToInternalJumpTarget(GeneralDBAccess gdba, Long navigationId, int flag,
- String guestAccountIds) throws Exception {
- String sql = " select websiteid, wntcode, jump_url from website_navigation where navigationid = :navigationid ";
- SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
- sqlCmd.setString("navigationid", navigationId);
- Map<String, Object> row = gdba.selectAsMap(sqlCmd);
- if (row == null || row.isEmpty()) {
- return;
- }
- Object wntcodeObj = row.get("wntcode");
- Object websiteIdObj = row.get("websiteid");
- Object jumpUrlObj = row.get("jump_url");
- if (wntcodeObj == null || websiteIdObj == null || jumpUrlObj == null) {
- return;
- }
- if (Long.parseLong(wntcodeObj.toString()) != 10030L) {
- return;
- }
- String jumpUrl = jumpUrlObj.toString().trim();
- if (StringUtil.isNull(jumpUrl) || jumpUrl.startsWith("http://") || jumpUrl.startsWith("https://")
- || jumpUrl.startsWith("javascript:")) {
- return;
- }
- String targetSql = " select navigationid from website_navigation where websiteid = :websiteid and dcode = 61 and url = :url limit 1 ";
- SqlCommandImpl targetCmd = new SqlCommandImpl(targetSql);
- targetCmd.setString("websiteid", websiteIdObj).setString("url", jumpUrl);
- Map<String, Object> targetRow = gdba.selectAsMap(targetCmd);
- if (targetRow == null || targetRow.get("navigationid") == null) {
- return;
- }
- Long targetNavigationId = Long.valueOf(targetRow.get("navigationid").toString());
- if (targetNavigationId.equals(navigationId)) {
- return;
- }
- WebsiteGuestAccessUtil.updateNavigationGuestAccessFlag(gdba, targetNavigationId, flag);
- WebsiteGuestAccessUtil.replaceNavigationGuestAccess(gdba, targetNavigationId, guestAccountIds,
- getAppUser().getUserId());
- }
- }
|