|
|
@@ -0,0 +1,346 @@
|
|
|
+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.List;
|
|
|
+import java.util.Map;
|
|
|
+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_LINK_NAV_IDCARD = "FFKJ_COLLEGE_FOOTER_LINKS";
|
|
|
+ private static final String DEFAULT_SCHOOL_HOME_NAME = "学校首页";
|
|
|
+ private static final String DEFAULT_SCHOOL_HOME_URL = "http://ffkj-screen-red.localhost:4188/";
|
|
|
+ private static final String DEFAULT_SITE_HOME_NAME = "本站首页";
|
|
|
+ private static final String DEFAULT_SITE_HOME_URL = "/";
|
|
|
+
|
|
|
+ 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, true);
|
|
|
+ setNavView(gdba, website, "collegeIntroNmv", "FFKJ_COLLEGE_MAJOR_NAV", 5, false);
|
|
|
+ setNavView(gdba, website, "collegeFeatureNmv", "FFKJ_COLLEGE_FEATURE", 5, true);
|
|
|
+ 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);
|
|
|
+ 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 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 a.release_time DESC, a.articleid DESC 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>();
|
|
|
+
|
|
|
+ addSectionByIDCard(gdba, website, sectionList, "FFKJ_COLLEGE_MAJOR_NAV");
|
|
|
+ addSectionByIDCard(gdba, website, sectionList, "FFKJ_COLLEGE_FEATURE");
|
|
|
+
|
|
|
+ List<Map<String, Object>> homeChildNavList = getHomeChildNavigation(gdba, website);
|
|
|
+ if (homeChildNavList != null) {
|
|
|
+ for (Map<String, Object> navMap : homeChildNavList) {
|
|
|
+ if (!isDynamicHomeSection(navMap)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ sectionList.add(buildNavigationMiniView(gdba, navMap, 5));
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 单个自定义栏目数据异常时跳过,避免影响首页其他栏目。
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ setRequestAttribute("collegeHomeSectionRows", groupSections(sectionList, 2));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addSectionByIDCard(GeneralDBAccess gdba, Website website, List<NavigationMiniView> sectionList,
|
|
|
+ String idcard) throws Exception {
|
|
|
+ try {
|
|
|
+ Map<String, Object> navMap = WebsiteTemplateNavUtil.getNavigationByIDCardAsMap(gdba, website, idcard);
|
|
|
+ if (navMap == null || navMap.get("navigationid") == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sectionList.add(buildNavigationMiniView(gdba, navMap, 5));
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 示例栏目缺失时跳过,避免影响后台自定义栏目继续展示。
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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_MAJOR".equals(idcard) || "FFKJ_COLLEGE_FEATURE".equals(idcard)
|
|
|
+ || UTILITY_LINK_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()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|