|
|
@@ -1,7 +1,10 @@
|
|
|
package space.apps.moudules.website.services;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
@@ -31,6 +34,10 @@ import space.core.db.jdbc.SqlCommandImpl;
|
|
|
public class NavigationService extends BaseTransaction {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
+ private static final String COLLEGE_RED_TEMPLATE_CONFIG = "ffkjcollegered1";
|
|
|
+ private static final String COLLEGE_HOME_GROUP_IDCARD = "FFKJ_COLLEGE_HOME_GROUP";
|
|
|
+ private static final String COLLEGE_TOP_CUSTOM_IDCARD = "FFKJ_COLLEGE_SCHOOL_HOME";
|
|
|
+ private static final String COLLEGE_BOTTOM_CUSTOM_IDCARD = "FFKJ_COLLEGE_FOOTER_LINKS";
|
|
|
|
|
|
static Logger log = LogManager.getLogger(NavigationService.class);
|
|
|
|
|
|
@@ -57,6 +64,7 @@ public class NavigationService extends BaseTransaction {
|
|
|
|
|
|
gdba.insertByBean(wn);
|
|
|
inheritManageFromParent(gdba, wn);
|
|
|
+ normalizeCollegeRedHomeNavigationSort(gdba, wn.getWebsiteid(), wn.getParentNid(), null);
|
|
|
gdba.commit();
|
|
|
clearWebsiteFrontCache(wn);
|
|
|
|
|
|
@@ -108,6 +116,9 @@ public class NavigationService extends BaseTransaction {
|
|
|
AppNavigationUtil.generateNavURI(gdba, wn);
|
|
|
|
|
|
gdba.updateById(wn);
|
|
|
+ normalizeCollegeRedHomeNavigationSort(gdba, oldWn == null ? null : oldWn.getWebsiteid(),
|
|
|
+ oldWn == null ? null : oldWn.getParentNid(), null);
|
|
|
+ normalizeCollegeRedHomeNavigationSort(gdba, wn.getWebsiteid(), wn.getParentNid(), null);
|
|
|
gdba.commit();
|
|
|
clearWebsiteFrontCache(oldWn);
|
|
|
clearWebsiteFrontCache(wn);
|
|
|
@@ -424,7 +435,11 @@ public class NavigationService extends BaseTransaction {
|
|
|
gdba.selectById(sortedWn);
|
|
|
}
|
|
|
|
|
|
- CURDUtil.sortDataNumber(gdba, "website_navigation", dataIdAry, "navigationid", "sort_number", false);
|
|
|
+ boolean normalized = sortedWn != null && normalizeCollegeRedHomeNavigationSort(gdba, sortedWn.getWebsiteid(),
|
|
|
+ sortedWn.getParentNid(), dataIdAry);
|
|
|
+ if (!normalized) {
|
|
|
+ CURDUtil.sortDataNumber(gdba, "website_navigation", dataIdAry, "navigationid", "sort_number", false);
|
|
|
+ }
|
|
|
gdba.commit();
|
|
|
clearWebsiteFrontCache(sortedWn);
|
|
|
|
|
|
@@ -501,4 +516,118 @@ public class NavigationService extends BaseTransaction {
|
|
|
write(getResponseSuccessDataPackage(wn).toJson());
|
|
|
}
|
|
|
|
|
|
+ private boolean normalizeCollegeRedHomeNavigationSort(GeneralDBAccess gdba, Long websiteid, Long parentNid,
|
|
|
+ String[] sortedIdAry) throws Exception {
|
|
|
+ if (!isCollegeRedHomeGroupChild(gdba, websiteid, parentNid)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> childList = getCollegeRedHomeChildNavigation(gdba, websiteid, parentNid);
|
|
|
+ if (childList == null || childList.size() == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long topCustomId = null;
|
|
|
+ Long bottomCustomId = null;
|
|
|
+ Set<Long> childIdSet = new HashSet<Long>();
|
|
|
+ for (Map<String, Object> child : childList) {
|
|
|
+ Long navigationId = getLongValue(child.get("navigationid"));
|
|
|
+ if (navigationId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ childIdSet.add(navigationId);
|
|
|
+ if (COLLEGE_TOP_CUSTOM_IDCARD.equals(getStringValue(child.get("idcard")))) {
|
|
|
+ topCustomId = navigationId;
|
|
|
+ } else if (COLLEGE_BOTTOM_CUSTOM_IDCARD.equals(getStringValue(child.get("idcard")))) {
|
|
|
+ bottomCustomId = navigationId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> middleIdList = new ArrayList<Long>();
|
|
|
+ Set<Long> usedMiddleIdSet = new HashSet<Long>();
|
|
|
+ if (sortedIdAry != null) {
|
|
|
+ for (String sortedId : sortedIdAry) {
|
|
|
+ Long navigationId = getLongValue(sortedId);
|
|
|
+ if (navigationId == null || !childIdSet.contains(navigationId)
|
|
|
+ || navigationId.equals(topCustomId) || navigationId.equals(bottomCustomId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ middleIdList.add(navigationId);
|
|
|
+ usedMiddleIdSet.add(navigationId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map<String, Object> child : childList) {
|
|
|
+ Long navigationId = getLongValue(child.get("navigationid"));
|
|
|
+ if (navigationId == null || navigationId.equals(topCustomId) || navigationId.equals(bottomCustomId)
|
|
|
+ || usedMiddleIdSet.contains(navigationId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ middleIdList.add(navigationId);
|
|
|
+ usedMiddleIdSet.add(navigationId);
|
|
|
+ }
|
|
|
+
|
|
|
+ long sortNumber = 1L;
|
|
|
+ if (topCustomId != null) {
|
|
|
+ updateNavigationSortNumber(gdba, topCustomId, sortNumber++);
|
|
|
+ }
|
|
|
+ for (Long middleId : middleIdList) {
|
|
|
+ updateNavigationSortNumber(gdba, middleId, sortNumber++);
|
|
|
+ }
|
|
|
+ if (bottomCustomId != null) {
|
|
|
+ updateNavigationSortNumber(gdba, bottomCustomId, sortNumber);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isCollegeRedHomeGroupChild(GeneralDBAccess gdba, Long websiteid, Long parentNid) throws Exception {
|
|
|
+ if (websiteid == null || parentNid == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String sql = "SELECT COUNT(*) AS count FROM website_navigation home "
|
|
|
+ + "JOIN website w ON w.websiteid = home.websiteid "
|
|
|
+ + "JOIN website_template wt ON wt.wtid = w.wtid "
|
|
|
+ + "WHERE home.dcode <> 72 AND home.wnccode = 10000 "
|
|
|
+ + "AND home.websiteid = :websiteid AND home.navigationid = :parentNid "
|
|
|
+ + "AND home.idcard = :homeIdcard AND wt.config = :templateConfig";
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
+ sqlCmd.setString("websiteid", websiteid).setString("parentNid", parentNid)
|
|
|
+ .setString("homeIdcard", COLLEGE_HOME_GROUP_IDCARD)
|
|
|
+ .setString("templateConfig", COLLEGE_RED_TEMPLATE_CONFIG);
|
|
|
+ Map<String, Object> result = gdba.selectAsMap(sqlCmd);
|
|
|
+ return result != null && getLongValue(result.get("count")) != null && getLongValue(result.get("count")) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> getCollegeRedHomeChildNavigation(GeneralDBAccess gdba, Long websiteid,
|
|
|
+ Long parentNid) throws Exception {
|
|
|
+ String sql = "SELECT navigationid, idcard FROM website_navigation "
|
|
|
+ + "WHERE dcode <> 72 AND wnccode = 10000 AND websiteid = :websiteid AND parent_nid = :parentNid "
|
|
|
+ + "ORDER BY sort_number ASC, create_time ASC, navigationid ASC";
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
+ sqlCmd.setString("websiteid", websiteid).setString("parentNid", parentNid);
|
|
|
+ return gdba.selectAsMapList(sqlCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateNavigationSortNumber(GeneralDBAccess gdba, Long navigationId, Long sortNumber) throws Exception {
|
|
|
+ String sql = "UPDATE website_navigation SET sort_number = :sortNumber WHERE navigationid = :navigationId";
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
+ sqlCmd.setString("sortNumber", sortNumber).setString("navigationId", navigationId);
|
|
|
+ gdba.modify(sqlCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long getLongValue(Object value) {
|
|
|
+ if (value == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return Long.valueOf(value.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getStringValue(Object value) {
|
|
|
+ return value == null ? "" : value.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|