| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- package space.apps.moudules.website.template.ffkjcollegered1;
- import apps.pojo.Article;
- import apps.pojo.Website;
- import apps.pojo.WebsiteNavigation;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import space.apps.moudules.basic.util.SortOrderUtil;
- import space.apps.moudules.website.template.common.WebsiteArticleManager;
- import space.apps.moudules.website.template.common.WebsiteCommonService;
- import space.apps.moudules.website.template.common.WebsiteNavManager;
- import space.apps.moudules.website.template.common.WebsiteTmplateConstvars.navigationType;
- import space.apps.moudules.website.template.common.bean.NavigationMiniView;
- import space.apps.moudules.website.template.util.WebsiteTemplateArticleUtil;
- import space.apps.moudules.website.template.util.WebsiteTemplateNavUtil;
- import space.core.apps.common.BaseTransaction;
- import space.core.db.bean.base.PageBean;
- import space.core.db.jdbc.GeneralDBAccess;
- import space.core.db.jdbc.SqlCommandImpl;
- /**
- * 非繁二级网站模板-红色服务。
- */
- public class WebSiteArticleService extends BaseTransaction {
- private static final long serialVersionUID = 1L;
- private static final String SCREEN_RED_THEME_CLASS = "screen-red-theme";
- private static final String HOME_GROUP_NAV_IDCARD = "FFKJ_COLLEGE_HOME_GROUP";
- private static final String UTILITY_LINK_NAV_IDCARD = "FFKJ_COLLEGE_SCHOOL_HOME";
- private static final String FOOTER_INFO_NAV_IDCARD = "FFKJ_COLLEGE_FOOTER_INFO";
- private static final String FOOTER_LINK_NAV_IDCARD = "FFKJ_COLLEGE_FOOTER_LINKS";
- private static final String INITIAL_TITLE_SUFFIX = "【初始】";
- private static final String DEFAULT_SCHOOL_HOME_NAME = "学校首页";
- private static final String DEFAULT_SCHOOL_HOME_URL = "https://hxcs.feifan.net/";
- private static final String DEFAULT_SITE_HOME_NAME = "本站首页";
- private static final String DEFAULT_SITE_HOME_URL = "/";
- private static final String DEFAULT_FOOTER_ADDRESS = "中国 广东省广州市从化城鳌大道东772号";
- private static final String DEFAULT_FOOTER_OFFICE_PHONE = "校办电话:020-87868999";
- private static final String DEFAULT_FOOTER_ADMISSION_PHONE = "招生电话:020-87865222";
- private static final String DEFAULT_FOOTER_EMPLOYMENT_PHONE = "就业办:020-87868935";
- private static final String DEFAULT_FOOTER_COPYRIGHT_ENGLISH =
- "Copyright © Guangzhou Huaxia Vocational College All Rights Reserved";
- private static final String DEFAULT_FOOTER_BEIAN_TEXT = "粤ICP备12042111号";
- private static final String DEFAULT_FOOTER_BEIAN_URL = "https://beian.miit.gov.cn/";
- public String controller() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Website website = getWebsite();
- setThemeAttributes(gdba, website);
- WebsiteNavigation nav = WebsiteNavManager.getNavigationByURI(gdba, website, getRequest().getRequestURI());
- if (nav != null && navigationType.CATALOG.getCode().equals(nav.getWntcode())) {
- setCatalogAttributes(gdba, website, nav);
- return "toCatalog";
- }
- return WebsiteCommonService.controller(gdba, website, 10, getRequest());
- }
- public String details() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Website website = getWebsite();
- setThemeAttributes(gdba, website);
- String forward = WebsiteCommonService.details(gdba, website, getRequest());
- setArticleExtras(gdba, website);
- return forward;
- }
- public String index() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Website website = getWebsite();
- WebsiteCommonService.selectHeadNavigation(gdba, website, getRequest());
- setRequestAttribute("website", website);
- setThemeAttributes(gdba, website);
- setNavView(gdba, website, "collegeHeroNmv", "FFKJ_COLLEGE_HOME_HERO", 3, true);
- setNavView(gdba, website, "collegeNewsNmv", "FFKJ_COLLEGE_NEWS", 5, false);
- setNavView(gdba, website, "collegeNoticeNmv", "FFKJ_COLLEGE_NOTICE", 4, false);
- setNavView(gdba, website, "collegeMajorNmv", "FFKJ_COLLEGE_MAJOR", 4, false);
- setHomeSectionRows(gdba, website);
- return DEFAULT_FORWARD;
- }
- public String search() throws Exception {
- GeneralDBAccess gdba = getGdbaInstance();
- Website website = getWebsite();
- String forward = WebsiteCommonService.search(gdba, website, getRequest(), 10);
- setThemeAttributes(gdba, website);
- return forward;
- }
- private void setThemeAttributes(GeneralDBAccess gdba, Website website) {
- setRequestAttribute("portalThemeClass", SCREEN_RED_THEME_CLASS);
- setRequestAttribute("portalThemeStyle", buildPortalThemeStyle(website));
- setUtilityLinks(gdba, website);
- setFooterInfo(gdba, website);
- setFooterLinks(gdba, website);
- }
- private String buildPortalThemeStyle(Website website) {
- String themeColor = getThemeColor(website);
- if (themeColor.length() == 0) {
- return "";
- }
- int[] rgb = parseHexColor(themeColor);
- int[] darkRgb = blendColor(rgb, new int[] { 0, 0, 0 }, 0.2);
- int[] brightRgb = blendColor(rgb, new int[] { 255, 255, 255 }, 0.14);
- String darkColor = toHexColor(darkRgb);
- String brightColor = toHexColor(brightRgb);
- return "body.screen-red-theme,.screen-red-theme{--hx-red:" + themeColor + ";--hx-red-dark:"
- + darkColor + ";--hx-red-bright:" + brightColor + ";--hx-red-rgb:" + toRgbText(rgb)
- + ";--hx-red-dark-rgb:" + toRgbText(darkRgb) + ";--hx-red-bright-rgb:"
- + toRgbText(brightRgb) + ";}";
- }
- private String getThemeColor(Website website) {
- if (website == null || website.getWhiteLogoFile() == null) {
- return "";
- }
- String value = website.getWhiteLogoFile().trim();
- if (!value.matches("#[0-9a-fA-F]{6}")) {
- return "";
- }
- return value.toLowerCase();
- }
- private int[] parseHexColor(String hexColor) {
- return new int[] { Integer.parseInt(hexColor.substring(1, 3), 16),
- Integer.parseInt(hexColor.substring(3, 5), 16),
- Integer.parseInt(hexColor.substring(5, 7), 16) };
- }
- private int[] blendColor(int[] sourceRgb, int[] targetRgb, double ratio) {
- int[] result = new int[3];
- for (int index = 0; index < result.length; index++) {
- result[index] = clampColor((int) Math.round(sourceRgb[index] * (1 - ratio) + targetRgb[index] * ratio));
- }
- return result;
- }
- private int clampColor(int value) {
- if (value < 0) {
- return 0;
- }
- if (value > 255) {
- return 255;
- }
- return value;
- }
- private String toHexColor(int[] rgb) {
- return "#" + toHexPart(rgb[0]) + toHexPart(rgb[1]) + toHexPart(rgb[2]);
- }
- private String toHexPart(int value) {
- String hex = Integer.toHexString(clampColor(value));
- return hex.length() == 1 ? "0" + hex : hex;
- }
- private String toRgbText(int[] rgb) {
- return rgb[0] + ", " + rgb[1] + ", " + rgb[2];
- }
- private void setUtilityLinks(GeneralDBAccess gdba, Website website) {
- String schoolHomeName = DEFAULT_SCHOOL_HOME_NAME;
- String schoolHomeUrl = DEFAULT_SCHOOL_HOME_URL;
- String siteHomeName = DEFAULT_SITE_HOME_NAME;
- String siteHomeUrl = DEFAULT_SITE_HOME_URL;
- try {
- setRequestAttribute("utilityLinksNmv",
- WebsiteNavManager.getArticleListByNavIDCard(gdba, website, UTILITY_LINK_NAV_IDCARD, 8));
- Map<String, Object> schoolHome = getUtilityLinkArticle(gdba, website, DEFAULT_SCHOOL_HOME_NAME);
- schoolHomeName = firstNotBlank(schoolHome.get("title"), schoolHomeName);
- schoolHomeUrl = firstNotBlank(schoolHome.get("url"), schoolHomeUrl);
- Map<String, Object> siteHome = getUtilityLinkArticle(gdba, website, DEFAULT_SITE_HOME_NAME);
- siteHomeName = firstNotBlank(siteHome.get("title"), siteHomeName);
- siteHomeUrl = firstNotBlank(siteHome.get("url"), siteHomeUrl);
- } catch (Exception e) {
- // 缺少隐藏栏目或文章时保持默认入口,不影响页面打开。
- setRequestAttribute("utilityLinksNmv", new NavigationMiniView());
- }
- setRequestAttribute("schoolHomeName", schoolHomeName);
- setRequestAttribute("schoolHomeUrl", schoolHomeUrl);
- setRequestAttribute("siteHomeName", siteHomeName);
- setRequestAttribute("siteHomeUrl", siteHomeUrl);
- }
- private void setFooterInfo(GeneralDBAccess gdba, Website website) {
- String websiteName = website == null ? "" : firstNotBlank(website.getName(), "");
- String footerAddress = DEFAULT_FOOTER_ADDRESS;
- String footerOfficePhone = DEFAULT_FOOTER_OFFICE_PHONE;
- String footerAdmissionPhone = DEFAULT_FOOTER_ADMISSION_PHONE;
- String footerEmploymentPhone = DEFAULT_FOOTER_EMPLOYMENT_PHONE;
- String footerOwner = "版权所有:" + websiteName;
- String footerLogo = "";
- String footerLogoAlt = websiteName;
- String footerCopyright = DEFAULT_FOOTER_COPYRIGHT_ENGLISH;
- String footerBeianText = DEFAULT_FOOTER_BEIAN_TEXT;
- String footerBeianUrl = DEFAULT_FOOTER_BEIAN_URL;
- try {
- NavigationMiniView footerInfoNmv = WebsiteNavManager.getArticleListByNavIDCard(gdba, website,
- FOOTER_INFO_NAV_IDCARD, 16);
- setRequestAttribute("footerInfoNmv", footerInfoNmv);
- Map<String, Map<String, Object>> footerInfoArticleMap = buildFooterInfoArticleMap(footerInfoNmv);
- footerAddress = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "地址"), footerAddress);
- footerOfficePhone = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "校办电话"), footerOfficePhone);
- footerAdmissionPhone = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "招生电话"),
- footerAdmissionPhone);
- footerEmploymentPhone = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "就业办"),
- footerEmploymentPhone);
- footerOwner = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "版权所有"), footerOwner);
- footerLogo = firstNotBlank(getFooterInfoThumbnail(footerInfoArticleMap, "底部LOGO"), footerLogo);
- footerLogoAlt = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "底部LOGO"), footerLogoAlt);
- footerCopyright = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "版权英文"), footerCopyright);
- footerBeianText = firstNotBlank(getFooterInfoDesc(footerInfoArticleMap, "备案信息"), footerBeianText);
- footerBeianUrl = firstNotBlank(getFooterInfoUrl(footerInfoArticleMap, "备案信息"), footerBeianUrl);
- } catch (Exception e) {
- setRequestAttribute("footerInfoNmv", new NavigationMiniView());
- }
- setRequestAttribute("footerAddressText", footerAddress);
- setRequestAttribute("footerOfficePhoneText", footerOfficePhone);
- setRequestAttribute("footerAdmissionPhoneText", footerAdmissionPhone);
- setRequestAttribute("footerEmploymentPhoneText", footerEmploymentPhone);
- setRequestAttribute("footerOwnerText", footerOwner);
- setRequestAttribute("footerLogoUrl", footerLogo);
- setRequestAttribute("footerLogoAlt", footerLogoAlt);
- setRequestAttribute("footerCopyrightText", footerCopyright);
- setRequestAttribute("footerBeianText", footerBeianText);
- setRequestAttribute("footerBeianUrl", footerBeianUrl);
- }
- private Map<String, Map<String, Object>> buildFooterInfoArticleMap(NavigationMiniView footerInfoNmv) {
- Map<String, Map<String, Object>> footerInfoArticleMap = new HashMap<String, Map<String, Object>>();
- if (footerInfoNmv == null || footerInfoNmv.getArticleList() == null) {
- return footerInfoArticleMap;
- }
- for (Map<String, Object> articleMap : footerInfoNmv.getArticleList()) {
- if (articleMap == null || articleMap.get("title") == null) {
- continue;
- }
- String title = normalizeFooterInfoTitle(articleMap.get("title").toString());
- if (title.length() > 0 && !footerInfoArticleMap.containsKey(title)) {
- footerInfoArticleMap.put(title, articleMap);
- }
- }
- return footerInfoArticleMap;
- }
- private String normalizeFooterInfoTitle(String title) {
- if (title == null) {
- return "";
- }
- String normalizedTitle = title.trim();
- while (normalizedTitle.endsWith(INITIAL_TITLE_SUFFIX)) {
- normalizedTitle = normalizedTitle.substring(0, normalizedTitle.length() - INITIAL_TITLE_SUFFIX.length())
- .trim();
- }
- return normalizedTitle;
- }
- private Object getFooterInfoDesc(Map<String, Map<String, Object>> footerInfoArticleMap, String title) {
- return getFooterInfoField(footerInfoArticleMap, title, "desc");
- }
- private Object getFooterInfoThumbnail(Map<String, Map<String, Object>> footerInfoArticleMap, String title) {
- return getFooterInfoField(footerInfoArticleMap, title, "thumbnail");
- }
- private Object getFooterInfoUrl(Map<String, Map<String, Object>> footerInfoArticleMap, String title) {
- return getFooterInfoField(footerInfoArticleMap, title, "url");
- }
- private Object getFooterInfoField(Map<String, Map<String, Object>> footerInfoArticleMap, String title, String field) {
- if (footerInfoArticleMap == null || !footerInfoArticleMap.containsKey(title)) {
- return null;
- }
- return footerInfoArticleMap.get(title).get(field);
- }
- private void setFooterLinks(GeneralDBAccess gdba, Website website) {
- try {
- setRequestAttribute("footerLinksNmv",
- WebsiteNavManager.getArticleListByNavIDCard(gdba, website, FOOTER_LINK_NAV_IDCARD, 8));
- } catch (Exception e) {
- setRequestAttribute("footerLinksNmv", new NavigationMiniView());
- }
- }
- private Map<String, Object> getUtilityLinkArticle(GeneralDBAccess gdba, Website website, String title)
- throws Exception {
- String sql = "SELECT a.title, a.url FROM article a "
- + "JOIN website_navigation wn ON wn.navigationid = a.navigationid "
- + "WHERE a.dcode = 61 AND a.ascode = '10010' AND a.`release` = 1 "
- + "AND wn.dcode = 61 AND wn.wnccode = 10000 "
- + "AND wn.websiteid = :websiteid AND wn.idcard = :idcard "
- + "AND a.title = :title "
- + "ORDER BY " + SortOrderUtil.articleSort("a") + " LIMIT 1";
- SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
- sqlCmd.setString("websiteid", website.getWebsiteid()).setString("idcard", UTILITY_LINK_NAV_IDCARD)
- .setString("title", title);
- Map<String, Object> article = gdba.selectAsMap(sqlCmd);
- return article == null ? new java.util.HashMap<String, Object>() : article;
- }
- private String firstNotBlank(Object value, String fallback) {
- if (value == null) {
- return fallback;
- }
- String text = value.toString().trim();
- return text.length() == 0 ? fallback : text;
- }
- private void setNavView(GeneralDBAccess gdba, Website website, String attrName, String idcard, int size,
- boolean thumbnailOnly) throws Exception {
- try {
- NavigationMiniView nmv = thumbnailOnly
- ? WebsiteNavManager.getArticleThumbnailListByNavIDCard(gdba, website, idcard, size)
- : WebsiteNavManager.getArticleListByNavIDCard(gdba, website, idcard, size);
- setRequestAttribute(attrName, nmv);
- } catch (Exception e) {
- setRequestAttribute(attrName, new NavigationMiniView());
- }
- }
- private void setHomeSectionRows(GeneralDBAccess gdba, Website website) throws Exception {
- List<NavigationMiniView> sectionList = new ArrayList<NavigationMiniView>();
- List<Map<String, Object>> homeChildNavList = getHomeChildNavigation(gdba, website);
- if (homeChildNavList != null) {
- for (Map<String, Object> navMap : getHomeSectionNavigationList(homeChildNavList)) {
- if (!isDynamicHomeSection(navMap)) {
- continue;
- }
- try {
- NavigationMiniView section = buildNavigationMiniView(gdba, navMap, 5);
- sectionList.add(section);
- } catch (Exception e) {
- // 单个自定义栏目数据异常时跳过,避免影响首页其他栏目。
- }
- }
- }
- setRequestAttribute("collegeHomeSectionRows", groupSections(sectionList, 2));
- }
- private List<Map<String, Object>> getHomeSectionNavigationList(List<Map<String, Object>> homeChildNavList) {
- List<Map<String, Object>> sectionNavList = new ArrayList<Map<String, Object>>();
- boolean topBoundaryFound = false;
- for (Map<String, Object> navMap : homeChildNavList) {
- if (hasIDCard(navMap, UTILITY_LINK_NAV_IDCARD)) {
- topBoundaryFound = true;
- continue;
- }
- if (hasIDCard(navMap, FOOTER_LINK_NAV_IDCARD)) {
- if (topBoundaryFound) {
- break;
- }
- continue;
- }
- if (topBoundaryFound) {
- sectionNavList.add(navMap);
- }
- }
- if (topBoundaryFound) {
- return sectionNavList;
- }
- return homeChildNavList;
- }
- private boolean hasIDCard(Map<String, Object> navMap, String idcard) {
- return navMap != null && navMap.get("idcard") != null && idcard.equals(navMap.get("idcard").toString());
- }
- private List<Map<String, Object>> getHomeChildNavigation(GeneralDBAccess gdba, Website website) throws Exception {
- Map<String, Object> homeGroupMap = WebsiteTemplateNavUtil.getNavigationByIDCardAsMap(gdba, website,
- HOME_GROUP_NAV_IDCARD);
- if (homeGroupMap == null || homeGroupMap.get("navigationid") == null) {
- return null;
- }
- return WebsiteTemplateNavUtil.getWebsiteALLConcealTerminalNav(gdba, website,
- Long.valueOf(homeGroupMap.get("navigationid").toString()));
- }
- private boolean isDynamicHomeSection(Map<String, Object> navMap) {
- if (navMap == null || navMap.get("idcard") == null || navMap.get("wntcode") == null) {
- return false;
- }
- String idcard = navMap.get("idcard").toString();
- if ("FFKJ_COLLEGE_HOME_HERO".equals(idcard) || "FFKJ_COLLEGE_NEWS".equals(idcard)
- || "FFKJ_COLLEGE_NOTICE".equals(idcard) || "FFKJ_COLLEGE_MAJOR".equals(idcard)
- || UTILITY_LINK_NAV_IDCARD.equals(idcard) || FOOTER_INFO_NAV_IDCARD.equals(idcard)
- || FOOTER_LINK_NAV_IDCARD.equals(idcard)) {
- return false;
- }
- return navigationType.LIST.getCode().toString().equals(navMap.get("wntcode").toString());
- }
- private NavigationMiniView buildNavigationMiniView(GeneralDBAccess gdba, Map<String, Object> navMap, int size)
- throws Exception {
- normalizeNavigationMap(gdba, navMap);
- PageBean pb = new PageBean();
- pb.setRowCountPerPage(size);
- List<Map<String, Object>> articleList = WebsiteTemplateArticleUtil.getArticleList(gdba,
- Long.valueOf(navMap.get("navigationid").toString()), pb);
- return new NavigationMiniView(navMap, articleList);
- }
- private void normalizeNavigationMap(GeneralDBAccess gdba, Map<String, Object> navMap) throws Exception {
- if (navMap == null) {
- return;
- }
- if (navMap.get("href") == null) {
- navMap.put("href", WebsiteTemplateNavUtil.getNavigationHref(gdba, navMap));
- }
- if (navMap.get("target") == null && navMap.get("wnjtcode") != null) {
- navMap.put("target", WebsiteTemplateNavUtil.jumpTypeCodeToTargetValue(navMap.get("wnjtcode").toString()));
- }
- }
- private List<List<NavigationMiniView>> groupSections(List<NavigationMiniView> sectionList, int groupSize) {
- List<List<NavigationMiniView>> rows = new ArrayList<List<NavigationMiniView>>();
- if (sectionList == null || sectionList.size() == 0) {
- return rows;
- }
- for (int index = 0; index < sectionList.size(); index += groupSize) {
- List<NavigationMiniView> row = new ArrayList<NavigationMiniView>();
- for (int offset = 0; offset < groupSize && index + offset < sectionList.size(); offset++) {
- row.add(sectionList.get(index + offset));
- }
- rows.add(row);
- }
- return rows;
- }
- private void setArticleExtras(GeneralDBAccess gdba, Website website) throws Exception {
- Article article = WebsiteArticleManager.getArticleByRequest(gdba, website, getRequest());
- if (article != null) {
- setRequestAttribute("articleThumbnail", article.getThumbnail());
- setRequestAttribute("articleReadCount", article.getReadCount());
- }
- }
- private void setCatalogAttributes(GeneralDBAccess gdba, Website website, WebsiteNavigation nav) throws Exception {
- WebsiteCommonService.selectHeadNavigation(gdba, website, getRequest());
- setRequestAttribute("website", website);
- setRequestAttribute("navigation", nav);
- List<WebsiteNavigation> crumbs = WebsiteNavManager.getNavParentList(gdba, website, nav.getNavigationid());
- setRequestAttribute("crumbsNavList", crumbs);
- setRequestAttribute("crumbsNavListSize", crumbs == null ? 0 : crumbs.size() - 1);
- setRequestAttribute("childrenNavList", WebsiteNavManager.getChildrenNavigation(gdba, website, nav.getNavigationid()));
- setRequestAttribute("navMiniViewList", WebsiteNavManager.getChildrenNavigationMiniView(gdba, website, nav.getNavigationid()));
- if (nav.getParentNid() != null) {
- WebsiteNavigation parNav = WebsiteNavManager.getNavigationByID(gdba, website, nav.getParentNid());
- setRequestAttribute("parNavigation", parNav);
- setRequestAttribute("brotherNavList", WebsiteNavManager.getChildrenNavigation(gdba, website, nav.getParentNid()));
- }
- }
- }
|