|
|
@@ -7,6 +7,7 @@ import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import space.apps.moudules.basic.util.SortOrderUtil;
|
|
|
import space.core.apps.common.bean.AppUser;
|
|
|
import space.core.db.jdbc.GeneralDBAccess;
|
|
|
import space.core.db.jdbc.SqlCommandImpl;
|
|
|
@@ -30,12 +31,13 @@ public class AppWebsiteManageUtil {
|
|
|
* @date 2020年02月09日
|
|
|
*/
|
|
|
public static List<Map<String, Object>> getManageWebsiteListByAppUser(GeneralDBAccess gdba, AppUser appUser) throws Exception {
|
|
|
- String sql = "Select websiteid, name from website where dcode = 61 "
|
|
|
+ String sql = "Select websiteid, name, sort_number from website where dcode = 61 "
|
|
|
+ " and websiteid in (Select websiteid from website_manage where "
|
|
|
+ "(mtcode = 10000 and objectid = :departmentid) "
|
|
|
+ "or (mtcode = 10010 and objectid in (Select roleid from person_roles where personid = :rolePersonid) "
|
|
|
+ "or (mtcode = 10020 and objectid = :postid) "
|
|
|
- + "or (mtcode = 10030 and objectid = :personid)))";
|
|
|
+ + "or (mtcode = 10030 and objectid = :personid)))"
|
|
|
+ + " order by " + SortOrderUtil.manualSort("", "sort_number", "create_time", "websiteid");
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
sqlCmd.setString("departmentid", appUser.getDepartmentId()).setString("postid", appUser.getPostId())
|
|
|
.setString("rolePersonid", appUser.getUserId()).setString("personid", appUser.getUserId());
|
|
|
@@ -54,7 +56,10 @@ public class AppWebsiteManageUtil {
|
|
|
* @date 2020年02月09日
|
|
|
*/
|
|
|
public static List<Map<String, Object>> getManageNavigationListByAppUser(GeneralDBAccess gdba, AppUser appUser, Long wnmcode) throws Exception {
|
|
|
- String sql = "Select navigationid, websiteid, name, parent_nid, sort_number, wntcode from website_navigation where dcode = 61 and wnccode = 10000 and wntcode != 10000 "
|
|
|
+ String sql = "Select navigationid, websiteid, name, parent_nid, sort_number, create_time, wntcode, "
|
|
|
+ + "(select w.sort_number from website w where w.websiteid = website_navigation.websiteid) as website_sort_number, "
|
|
|
+ + "(select w.create_time from website w where w.websiteid = website_navigation.websiteid) as website_create_time "
|
|
|
+ + "from website_navigation where dcode = 61 and wnccode = 10000 and wntcode != 10000 "
|
|
|
+ " and websiteid in (Select websiteid from website where dcode = 61) "
|
|
|
+ " and (websiteid in (Select websiteid from website_manage where "
|
|
|
+ "(mtcode = 10000 and objectid = :websiteDepartmentid) "
|
|
|
@@ -66,7 +71,13 @@ public class AppWebsiteManageUtil {
|
|
|
+ "or (mtcode = 10010 and wnmcode = :wnmcode2 and objectid in (Select roleid from person_roles where personid = :navigationRolePersonid) "
|
|
|
+ "or (mtcode = 10020 and wnmcode = :wnmcode3 and objectid = :navigationPostid) "
|
|
|
+ "or (mtcode = 10030 and wnmcode = :wnmcode4 and objectid = :navigationPersonid)))) "
|
|
|
- + " order by websiteid asc, ifnull(parent_nid, 0) asc, sort_number asc, navigationid asc ";
|
|
|
+ + " order by "
|
|
|
+ + SortOrderUtil.manualSortByColumn(
|
|
|
+ "(select w.sort_number from website w where w.websiteid = website_navigation.websiteid)",
|
|
|
+ "(select w.create_time from website w where w.websiteid = website_navigation.websiteid)",
|
|
|
+ "websiteid")
|
|
|
+ + ", ifnull(parent_nid, 0) asc, "
|
|
|
+ + SortOrderUtil.manualSort("", "sort_number", "create_time", "navigationid");
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
sqlCmd.setString("wnmcode1", wnmcode).setString("wnmcode2", wnmcode).setString("wnmcode3", wnmcode).setString("wnmcode4", wnmcode)
|
|
|
.setString("websiteDepartmentid", appUser.getDepartmentId()).setString("websitePostid", appUser.getPostId())
|
|
|
@@ -119,7 +130,10 @@ public class AppWebsiteManageUtil {
|
|
|
}
|
|
|
|
|
|
private static Map<String, Object> getNavigationMapById(GeneralDBAccess gdba, String navigationId) throws Exception {
|
|
|
- String sql = "Select navigationid, websiteid, name, parent_nid, sort_number, wntcode from website_navigation where dcode = 61 and wnccode = 10000 and navigationid = :navigationid";
|
|
|
+ String sql = "Select navigationid, websiteid, name, parent_nid, sort_number, create_time, wntcode, "
|
|
|
+ + "(select w.sort_number from website w where w.websiteid = website_navigation.websiteid) as website_sort_number, "
|
|
|
+ + "(select w.create_time from website w where w.websiteid = website_navigation.websiteid) as website_create_time "
|
|
|
+ + "from website_navigation where dcode = 61 and wnccode = 10000 and navigationid = :navigationid";
|
|
|
SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
sqlCmd.setString("navigationid", navigationId);
|
|
|
return gdba.selectAsMap(sqlCmd);
|
|
|
@@ -129,7 +143,9 @@ public class AppWebsiteManageUtil {
|
|
|
Collections.sort(navigationList, new Comparator<Map<String, Object>>() {
|
|
|
@Override
|
|
|
public int compare(Map<String, Object> left, Map<String, Object> right) {
|
|
|
- int websiteCompare = compareLong(left.get("websiteid"), right.get("websiteid"));
|
|
|
+ int websiteCompare = compareManualSort(left.get("website_sort_number"), right.get("website_sort_number"),
|
|
|
+ left.get("website_create_time"), right.get("website_create_time"),
|
|
|
+ left.get("websiteid"), right.get("websiteid"));
|
|
|
if (websiteCompare != 0) {
|
|
|
return websiteCompare;
|
|
|
}
|
|
|
@@ -137,21 +153,57 @@ public class AppWebsiteManageUtil {
|
|
|
if (parentCompare != 0) {
|
|
|
return parentCompare;
|
|
|
}
|
|
|
- int sortCompare = compareLong(left.get("sort_number"), right.get("sort_number"));
|
|
|
- if (sortCompare != 0) {
|
|
|
- return sortCompare;
|
|
|
- }
|
|
|
- return compareLong(left.get("navigationid"), right.get("navigationid"));
|
|
|
+ return compareManualSort(left.get("sort_number"), right.get("sort_number"),
|
|
|
+ left.get("create_time"), right.get("create_time"),
|
|
|
+ left.get("navigationid"), right.get("navigationid"));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private static int compareManualSort(Object leftSortNumber, Object rightSortNumber, Object leftCreateTime,
|
|
|
+ Object rightCreateTime, Object leftId, Object rightId) {
|
|
|
+ int validSortCompare = compareLong(getValidSortRank(leftSortNumber), getValidSortRank(rightSortNumber));
|
|
|
+ if (validSortCompare != 0) {
|
|
|
+ return validSortCompare;
|
|
|
+ }
|
|
|
+ if (isValidSort(leftSortNumber) && isValidSort(rightSortNumber)) {
|
|
|
+ int sortCompare = compareLong(leftSortNumber, rightSortNumber);
|
|
|
+ if (sortCompare != 0) {
|
|
|
+ return sortCompare;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int timeCompare = compareStringDesc(leftCreateTime, rightCreateTime);
|
|
|
+ if (timeCompare != 0) {
|
|
|
+ return timeCompare;
|
|
|
+ }
|
|
|
+ return compareLongDesc(leftId, rightId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Long getValidSortRank(Object sortNumber) {
|
|
|
+ return isValidSort(sortNumber) ? 0L : 1L;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean isValidSort(Object sortNumber) {
|
|
|
+ Long value = toLong(sortNumber);
|
|
|
+ return value != null && value > 0 && value != 9999L;
|
|
|
+ }
|
|
|
+
|
|
|
private static int compareLong(Object left, Object right) {
|
|
|
Long leftLong = toLong(left);
|
|
|
Long rightLong = toLong(right);
|
|
|
return leftLong.compareTo(rightLong);
|
|
|
}
|
|
|
|
|
|
+ private static int compareLongDesc(Object left, Object right) {
|
|
|
+ return compareLong(right, left);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int compareStringDesc(Object left, Object right) {
|
|
|
+ String leftString = left == null ? "" : left.toString();
|
|
|
+ String rightString = right == null ? "" : right.toString();
|
|
|
+ return rightString.compareTo(leftString);
|
|
|
+ }
|
|
|
+
|
|
|
private static Long toLong(Object value) {
|
|
|
if (value == null || value.toString().length() == 0) {
|
|
|
return 0L;
|