From d1f26741bddf6f512d62c0100d42c52be8d37e76 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 06 二月 2021 15:35:40 +0800
Subject: [PATCH] 工具类优化

---
 fanli/src/main/java/com/yeshi/fanli/util/Utils.java |  757 +++++++++++++++++++++++++++------------------------------
 1 files changed, 359 insertions(+), 398 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/Utils.java b/fanli/src/main/java/com/yeshi/fanli/util/Utils.java
index c19b2e0..40ae556 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/Utils.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/Utils.java
@@ -1,398 +1,359 @@
-package com.yeshi.fanli.util;
-
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Document;
-
-import com.yeshi.fanli.entity.admin.GoodsClassAdmin;
-import com.yeshi.fanli.entity.admin.HotSearchAdmin;
-import com.yeshi.fanli.entity.admin.RecommendBannerAdmin;
-import com.yeshi.fanli.entity.admin.RecommendSectionAdmin;
-import com.yeshi.fanli.entity.admin.RecommendSpecialAdmin;
-import com.yeshi.fanli.entity.bus.recommend.RecommendSection;
-import com.yeshi.fanli.entity.bus.recommend.RecommendSectionGoods;
-import com.yeshi.fanli.entity.common.AdminUser;
-import org.yeshi.utils.taobao.TbImgUtil;
-
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
-public class Utils {
-
-	private static final String ANDROID = "ANDROID";
-	private static final String IOS = "IOS";
-	private static final String WEB = "WEB";
-
-	private static final Map<String, String> map = new HashMap<String, String>();
-
-	static {
-		map.put("1", ANDROID);
-		map.put("2", IOS);
-		map.put("3", WEB);
-	}
-
-	public static Map<String, String> getMap() {
-		return map;
-	}
-
-	public static boolean isEmailUrlRight(String email, String sign, long time) {
-		if (StringUtil.Md5(email + time + "WEIJU2016xxx").equalsIgnoreCase(sign)
-				&& Math.abs(System.currentTimeMillis() - time) < 1000 * 60 * 60 * 2) {
-			return true;
-		}
-		return false;
-	}
-
-	public static String getUrlPageTitle(String url) {
-		try {
-			Document doc = Jsoup.connect(url).timeout(1000 * 60).get();
-			return doc.title();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-		return "";
-	}
-
-	public static AdminUser getAdminUser(HttpServletRequest request) {
-		AdminUser adminUser = (AdminUser) request.getSession().getAttribute("ADMIN_USERINFO");
-		return adminUser;
-	}
-
-	public static boolean signIsRight(String devicename, String imei, String sign) {
-		return sign.equalsIgnoreCase(StringUtil.Md5(devicename + imei + "WEIju2016888xx3"));
-	}
-
-	public static Map<String, Object> sort(Map<String, Integer> map) {
-		// 閫氳繃ArrayList鏋勶拷?鍑芥暟鎶妋ap.entrySet()杞崲鎴恖ist
-		List<Map.Entry<String, Object>> list = new ArrayList<Map.Entry<String, Object>>((Collection) map.entrySet());
-		// 閫氳繃姣旇緝鍣ㄥ疄鐜版瘮杈冩帓锟�?
-		Collections.sort(list, new Comparator<Map.Entry<String, Object>>() {
-			public int compare(Map.Entry<String, Object> mapping1, Map.Entry<String, Object> mapping2) {
-				return mapping1.getKey().compareTo(mapping2.getKey());
-			}
-		});
-
-		Map<String, Object> newMap = new TreeMap<String, Object>();
-		for (Entry<String, Object> entry : list) {
-			newMap.put(entry.getKey(), entry.getValue());
-		}
-		return newMap;
-	}
-
-	@SuppressWarnings("unchecked")
-	public static void sort(List list) {
-		if (list == null || list.size() == 0) {
-			return;
-		}
-		if (list.get(0) instanceof RecommendSection) {
-			Collections.sort(list, new Comparator<RecommendSection>() {
-				public int compare(RecommendSection o1, RecommendSection o2) {
-					return o1.getOrderby() - o2.getOrderby();
-				}
-			});
-		} else if (list.get(0) instanceof RecommendSectionGoods) {
-			Collections.sort(list, new Comparator<RecommendSectionGoods>() {
-				public int compare(RecommendSectionGoods o1, RecommendSectionGoods o2) {
-					return o1.getOrderby() - o2.getOrderby();
-				}
-			});
-		}
-		return;
-	}
-
-	@SuppressWarnings("unchecked")
-	public static Map orderBy(Map map) {
-		if (map.size() == 0) {
-			return map;
-		}
-
-		Collection values = map.values();
-		Object obj = null;
-		for (Object object : values) {
-			obj = object;
-			break;
-		}
-		if (obj instanceof RecommendBannerAdmin) {
-
-			// 閫氳繃ArrayList鏋勶拷?鍑芥暟鎶妋ap.entrySet()杞崲鎴恖ist
-			List<Map.Entry<Long, RecommendBannerAdmin>> list = new ArrayList<Map.Entry<Long, RecommendBannerAdmin>>(
-					(Collection) map.entrySet());
-			// 閫氳繃姣旇緝鍣ㄥ疄鐜版瘮杈冩帓锟�?
-			Collections.sort(list, new Comparator<Map.Entry<Long, RecommendBannerAdmin>>() {
-				public int compare(Map.Entry<Long, RecommendBannerAdmin> mapping1,
-						Map.Entry<Long, RecommendBannerAdmin> mapping2) {
-					int orderby1 = mapping1.getValue().getRecommendBanner().getOrderby();
-					int orderby2 = mapping2.getValue().getRecommendBanner().getOrderby();
-					return orderby1 - orderby2;
-				}
-			});
-			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
-			for (Entry<Long, RecommendBannerAdmin> entry : list) {
-				newMap.put(entry.getKey(), entry.getValue());
-			}
-			return newMap;
-		} else if (obj instanceof RecommendSpecialAdmin) {
-			List<Map.Entry<Long, RecommendSpecialAdmin>> list = new ArrayList<Map.Entry<Long, RecommendSpecialAdmin>>(
-					(Collection) map.entrySet());
-			Collections.sort(list, new Comparator<Map.Entry<Long, RecommendSpecialAdmin>>() {
-				public int compare(Map.Entry<Long, RecommendSpecialAdmin> mapping1,
-						Map.Entry<Long, RecommendSpecialAdmin> mapping2) {
-					int orderby1 = mapping1.getValue().getRecommendSpecial().getOrderby();
-					int orderby2 = mapping2.getValue().getRecommendSpecial().getOrderby();
-					return orderby1 - orderby2;
-				}
-			});
-			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
-			for (Entry<Long, RecommendSpecialAdmin> entry : list) {
-				newMap.put(entry.getKey(), entry.getValue());
-			}
-			return newMap;
-		} else if (obj instanceof HotSearchAdmin) {
-			List<Map.Entry<Long, HotSearchAdmin>> list = new ArrayList<Map.Entry<Long, HotSearchAdmin>>(
-					(Collection) map.entrySet());
-			Collections.sort(list, new Comparator<Map.Entry<Long, HotSearchAdmin>>() {
-				public int compare(Map.Entry<Long, HotSearchAdmin> mapping1, Map.Entry<Long, HotSearchAdmin> mapping2) {
-					int orderby1 = mapping1.getValue().getHotSearch().getOrderby();
-					int orderby2 = mapping2.getValue().getHotSearch().getOrderby();
-					return orderby1 - orderby2;
-				}
-			});
-			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
-			for (Entry<Long, HotSearchAdmin> entry : list) {
-				newMap.put(entry.getKey(), entry.getValue());
-			}
-			return newMap;
-		} else if (obj instanceof GoodsClassAdmin) {
-			List<Map.Entry<Long, GoodsClassAdmin>> list = new ArrayList<Map.Entry<Long, GoodsClassAdmin>>(
-					(Collection) map.entrySet());
-			Collections.sort(list, new Comparator<Map.Entry<Long, GoodsClassAdmin>>() {
-				public int compare(Map.Entry<Long, GoodsClassAdmin> mapping1,
-						Map.Entry<Long, GoodsClassAdmin> mapping2) {
-					int orderby1 = mapping1.getValue().getGoodsClass().getOrderby();
-					int orderby2 = mapping2.getValue().getGoodsClass().getOrderby();
-					return orderby1 - orderby2;
-				}
-			});
-			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
-			for (Entry<Long, GoodsClassAdmin> entry : list) {
-				newMap.put(entry.getKey(), entry.getValue());
-			}
-			return newMap;
-		} else if (obj instanceof RecommendSectionAdmin) {
-			List<Map.Entry<Long, RecommendSectionAdmin>> list = new ArrayList<Map.Entry<Long, RecommendSectionAdmin>>(
-					(Collection) map.entrySet());
-			Collections.sort(list, new Comparator<Map.Entry<Long, RecommendSectionAdmin>>() {
-				public int compare(Map.Entry<Long, RecommendSectionAdmin> mapping1,
-						Map.Entry<Long, RecommendSectionAdmin> mapping2) {
-					int orderby1 = mapping1.getValue().getRecommendSection().getOrderby();
-					int orderby2 = mapping2.getValue().getRecommendSection().getOrderby();
-					return orderby1 - orderby2;
-				}
-			});
-			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
-			for (Entry<Long, RecommendSectionAdmin> entry : list) {
-				newMap.put(entry.getKey(), entry.getValue());
-			}
-			return newMap;
-		}
-		return map;
-	}
-
-	public static List<String> getDateMonthList(Date beginDate, Date endDate) {
-		Calendar endCalendar = Calendar.getInstance();
-		endCalendar.setTime(endDate);
-
-		Calendar beginCalendar = Calendar.getInstance();
-		beginCalendar.setTime(beginDate);
-
-		int month = beginCalendar.get(Calendar.MONTH) - endCalendar.get(Calendar.MONTH);
-		List<String> list = new ArrayList<String>();
-		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
-		for (int ii = month; ii < 0; ii++) {
-			Calendar ca = Calendar.getInstance();
-			ca.set(Calendar.DAY_OF_MONTH, 1);
-			ca.set(Calendar.MONTH, (ca.get(Calendar.MONTH)) + ii + 1);
-			String format = dateFormat.format(ca.getTime());
-			list.add(format);
-		}
-		return list;
-	}
-
-	public static List<String> getDateMonthList(int month, Date date) {
-		List<String> list = new ArrayList<String>();
-		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
-		Calendar ca;
-		for (int ii = -month; ii < 0; ii++) {
-			ca = Calendar.getInstance();
-			ca.setTime(date);
-			ca.set(Calendar.DAY_OF_MONTH, 1);
-			ca.set(Calendar.MONTH, (ca.get(Calendar.MONTH)) + ii + 1);
-			String format = dateFormat.format(ca.getTime());
-			list.add(format);
-		}
-		return list;
-	}
-
-	public static int countMonths(String date1, String date2) throws ParseException {
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-
-		Calendar c1 = Calendar.getInstance();
-		Calendar c2 = Calendar.getInstance();
-
-		c1.setTime(sdf.parse(date1));
-		c2.setTime(sdf.parse(date2));
-
-		int year = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
-
-		// 锟�?锟斤拷鏃ユ湡鑻ュ皬鏈堢粨鏉熸棩锟�?
-		if (year < 0) {
-			year = -year;
-			return year * 12 + c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH);
-		}
-
-		return year * 12 + c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
-	}
-
-	public static int countDay(String date1, String date2) throws ParseException {
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-
-		Calendar c1 = Calendar.getInstance();
-		Calendar c2 = Calendar.getInstance();
-
-		c1.setTime(sdf.parse(date1));
-		c2.setTime(sdf.parse(date2));
-		int day = ((Long) ((c2.getTimeInMillis() - c1.getTimeInMillis()) / 86400000)).intValue();
-		return day;
-	}
-
-	public static String imgSize(String jsonStr) {
-		JSONObject json = JSONObject.fromObject(jsonStr);
-		String picUrl = (String) json.opt("pictUrl");
-		if (picUrl.contains("alicdn") || picUrl.contains("tbcdn")) {
-			picUrl = TbImgUtil.getTBSize320Img(picUrl);
-		}
-		json.element("pictUrl", picUrl);
-		return json.toString();
-	}
-
-	public static String imgListSize(String jsonStr) {
-		JSONArray json = JSONArray.fromObject(jsonStr);
-		for (Object object : json) {
-			String picUrl = (String) ((JSONObject) object).opt("pictUrl");
-			if (picUrl.contains("alicdn") || picUrl.contains("tbcdn")) {
-				picUrl = TbImgUtil.getTBSize320Img(picUrl);
-			}
-			((JSONObject) object).element("pictUrl", picUrl);
-		}
-		return json.toString();
-	}
-
-	public static Map<String, String> parseURL(String url) {
-
-		String URL_REGEX = "(((http|https)://)|(www\\.))[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,4})?(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
-		Pattern p = Pattern.compile(URL_REGEX);
-		Matcher matcher = p.matcher(url);
-		boolean b = matcher.matches();
-		Map<String, String> map = new HashMap<String, String>();
-		if (!b) {
-			return map;
-		}
-		if (!url.contains("?")) {
-			return map;
-		}
-
-		String params = url.substring(url.indexOf("?") + 1);
-		if (params == null || "".equals(params)) {
-			return map;
-		}
-
-		String[] paramArr = params.split("&");
-
-		for (String arr : paramArr) {
-			String[] kv = arr.split("=");
-			if (kv.length == 1) {
-				kv[1] = "";
-			}
-			map.put(kv[0], kv[1]);
-		}
-
-		return map;
-	}
-
-	public static double random(double mix) {
-		return (Math.random() * 20) + mix;
-	}
-
-	public static String getStarString(String content, int begin, int end) {
-
-		if (begin >= content.length() || begin < 0) {
-			return content;
-		}
-		if (end >= content.length() || end < 0) {
-			return content;
-		}
-		if (begin >= end) {
-			return content;
-		}
-		String starStr = "";
-		for (int i = begin; i < end; i++) {
-			starStr = starStr + "*";
-		}
-		return content.substring(0, begin) + starStr + content.substring(end, content.length());
-
-	}
-
-	public static boolean isNum(String content) {
-		if (content == null) {
-			return false;
-		}
-		String regex = "\\d+";
-		Pattern compile = Pattern.compile(regex);
-		Matcher matcher = compile.matcher(content);
-		return matcher.matches();
-	}
-
-	public static boolean isOrderNum(String order) {
-		if (order == null) {
-			return false;
-		}
-		String regex = "\\d{16,}";
-		Pattern compile = Pattern.compile(regex);
-		Matcher matcher = compile.matcher(order);
-		return matcher.matches();
-	}
-
-	public static boolean isUserOrder(String existOrder, String lostOrder) {
-		if (existOrder.length() < 16 || lostOrder.length() < 16) {
-			return false;
-		}
-		String existNum = existOrder.substring(existOrder.length() - 6);
-		String lostOrderNum = lostOrder.substring(lostOrder.length() - 6);
-
-		if (existNum.equals(lostOrderNum)) {
-			return true;
-		}
-
-		return false;
-	}
-
-}
+package com.yeshi.fanli.util;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.yeshi.utils.taobao.TbImgUtil;
+
+import com.yeshi.fanli.entity.admin.GoodsClassAdmin;
+import com.yeshi.fanli.entity.admin.HotSearchAdmin;
+import com.yeshi.fanli.entity.admin.RecommendBannerAdmin;
+import com.yeshi.fanli.entity.admin.RecommendSpecialAdmin;
+import com.yeshi.fanli.entity.common.AdminUser;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class Utils {
+
+	private static final String ANDROID = "ANDROID";
+	private static final String IOS = "IOS";
+	private static final String WEB = "WEB";
+
+	private static final Map<String, String> map = new HashMap<String, String>();
+
+	static {
+		map.put("1", ANDROID);
+		map.put("2", IOS);
+		map.put("3", WEB);
+	}
+
+	public static Map<String, String> getMap() {
+		return map;
+	}
+
+	public static boolean isEmailUrlRight(String email, String sign, long time) {
+		if (StringUtil.Md5(email + time + "WEIJU2016xxx").equalsIgnoreCase(sign)
+				&& Math.abs(System.currentTimeMillis() - time) < 1000 * 60 * 60 * 2) {
+			return true;
+		}
+		return false;
+	}
+
+	public static String getUrlPageTitle(String url) {
+		try {
+			Document doc = Jsoup.connect(url).timeout(1000 * 60).get();
+			return doc.title();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return "";
+	}
+
+	public static AdminUser getAdminUser(HttpServletRequest request) {
+		AdminUser adminUser = (AdminUser) request.getSession().getAttribute("ADMIN_USERINFO");
+		return adminUser;
+	}
+
+	public static boolean signIsRight(String devicename, String imei, String sign) {
+		return sign.equalsIgnoreCase(StringUtil.Md5(devicename + imei + "WEIju2016888xx3"));
+	}
+
+	public static Map<String, Object> sort(Map<String, Integer> map) {
+		// 閫氳繃ArrayList鏋勶拷?鍑芥暟鎶妋ap.entrySet()杞崲鎴恖ist
+		List<Map.Entry<String, Object>> list = new ArrayList<Map.Entry<String, Object>>((Collection) map.entrySet());
+		// 閫氳繃姣旇緝鍣ㄥ疄鐜版瘮杈冩帓锟�?
+		Collections.sort(list, new Comparator<Map.Entry<String, Object>>() {
+			public int compare(Map.Entry<String, Object> mapping1, Map.Entry<String, Object> mapping2) {
+				return mapping1.getKey().compareTo(mapping2.getKey());
+			}
+		});
+
+		Map<String, Object> newMap = new TreeMap<String, Object>();
+		for (Entry<String, Object> entry : list) {
+			newMap.put(entry.getKey(), entry.getValue());
+		}
+		return newMap;
+	}
+
+
+	@SuppressWarnings("unchecked")
+	public static Map orderBy(Map map) {
+		if (map.size() == 0) {
+			return map;
+		}
+
+		Collection values = map.values();
+		Object obj = null;
+		for (Object object : values) {
+			obj = object;
+			break;
+		}
+		if (obj instanceof RecommendBannerAdmin) {
+
+			// 閫氳繃ArrayList鏋勶拷?鍑芥暟鎶妋ap.entrySet()杞崲鎴恖ist
+			List<Map.Entry<Long, RecommendBannerAdmin>> list = new ArrayList<Map.Entry<Long, RecommendBannerAdmin>>(
+					(Collection) map.entrySet());
+			// 閫氳繃姣旇緝鍣ㄥ疄鐜版瘮杈冩帓锟�?
+			Collections.sort(list, new Comparator<Map.Entry<Long, RecommendBannerAdmin>>() {
+				public int compare(Map.Entry<Long, RecommendBannerAdmin> mapping1,
+						Map.Entry<Long, RecommendBannerAdmin> mapping2) {
+					int orderby1 = mapping1.getValue().getRecommendBanner().getOrderby();
+					int orderby2 = mapping2.getValue().getRecommendBanner().getOrderby();
+					return orderby1 - orderby2;
+				}
+			});
+			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
+			for (Entry<Long, RecommendBannerAdmin> entry : list) {
+				newMap.put(entry.getKey(), entry.getValue());
+			}
+			return newMap;
+		} else if (obj instanceof RecommendSpecialAdmin) {
+			List<Map.Entry<Long, RecommendSpecialAdmin>> list = new ArrayList<Map.Entry<Long, RecommendSpecialAdmin>>(
+					(Collection) map.entrySet());
+			Collections.sort(list, new Comparator<Map.Entry<Long, RecommendSpecialAdmin>>() {
+				public int compare(Map.Entry<Long, RecommendSpecialAdmin> mapping1,
+						Map.Entry<Long, RecommendSpecialAdmin> mapping2) {
+					int orderby1 = mapping1.getValue().getRecommendSpecial().getOrderby();
+					int orderby2 = mapping2.getValue().getRecommendSpecial().getOrderby();
+					return orderby1 - orderby2;
+				}
+			});
+			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
+			for (Entry<Long, RecommendSpecialAdmin> entry : list) {
+				newMap.put(entry.getKey(), entry.getValue());
+			}
+			return newMap;
+		} else if (obj instanceof HotSearchAdmin) {
+			List<Map.Entry<Long, HotSearchAdmin>> list = new ArrayList<Map.Entry<Long, HotSearchAdmin>>(
+					(Collection) map.entrySet());
+			Collections.sort(list, new Comparator<Map.Entry<Long, HotSearchAdmin>>() {
+				public int compare(Map.Entry<Long, HotSearchAdmin> mapping1, Map.Entry<Long, HotSearchAdmin> mapping2) {
+					int orderby1 = mapping1.getValue().getHotSearch().getOrderby();
+					int orderby2 = mapping2.getValue().getHotSearch().getOrderby();
+					return orderby1 - orderby2;
+				}
+			});
+			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
+			for (Entry<Long, HotSearchAdmin> entry : list) {
+				newMap.put(entry.getKey(), entry.getValue());
+			}
+			return newMap;
+		} else if (obj instanceof GoodsClassAdmin) {
+			List<Map.Entry<Long, GoodsClassAdmin>> list = new ArrayList<Map.Entry<Long, GoodsClassAdmin>>(
+					(Collection) map.entrySet());
+			Collections.sort(list, new Comparator<Map.Entry<Long, GoodsClassAdmin>>() {
+				public int compare(Map.Entry<Long, GoodsClassAdmin> mapping1,
+						Map.Entry<Long, GoodsClassAdmin> mapping2) {
+					int orderby1 = mapping1.getValue().getGoodsClass().getOrderby();
+					int orderby2 = mapping2.getValue().getGoodsClass().getOrderby();
+					return orderby1 - orderby2;
+				}
+			});
+			LinkedHashMap<Long, Object> newMap = new LinkedHashMap<Long, Object>();
+			for (Entry<Long, GoodsClassAdmin> entry : list) {
+				newMap.put(entry.getKey(), entry.getValue());
+			}
+			return newMap;
+		}
+		return map;
+	}
+
+	public static List<String> getDateMonthList(Date beginDate, Date endDate) {
+		Calendar endCalendar = Calendar.getInstance();
+		endCalendar.setTime(endDate);
+
+		Calendar beginCalendar = Calendar.getInstance();
+		beginCalendar.setTime(beginDate);
+
+		int month = beginCalendar.get(Calendar.MONTH) - endCalendar.get(Calendar.MONTH);
+		List<String> list = new ArrayList<String>();
+		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
+		for (int ii = month; ii < 0; ii++) {
+			Calendar ca = Calendar.getInstance();
+			ca.set(Calendar.DAY_OF_MONTH, 1);
+			ca.set(Calendar.MONTH, (ca.get(Calendar.MONTH)) + ii + 1);
+			String format = dateFormat.format(ca.getTime());
+			list.add(format);
+		}
+		return list;
+	}
+
+	public static List<String> getDateMonthList(int month, Date date) {
+		List<String> list = new ArrayList<String>();
+		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
+		Calendar ca;
+		for (int ii = -month; ii < 0; ii++) {
+			ca = Calendar.getInstance();
+			ca.setTime(date);
+			ca.set(Calendar.DAY_OF_MONTH, 1);
+			ca.set(Calendar.MONTH, (ca.get(Calendar.MONTH)) + ii + 1);
+			String format = dateFormat.format(ca.getTime());
+			list.add(format);
+		}
+		return list;
+	}
+
+	public static int countMonths(String date1, String date2) throws ParseException {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+		Calendar c1 = Calendar.getInstance();
+		Calendar c2 = Calendar.getInstance();
+
+		c1.setTime(sdf.parse(date1));
+		c2.setTime(sdf.parse(date2));
+
+		int year = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
+
+		// 锟�?锟斤拷鏃ユ湡鑻ュ皬鏈堢粨鏉熸棩锟�?
+		if (year < 0) {
+			year = -year;
+			return year * 12 + c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH);
+		}
+
+		return year * 12 + c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
+	}
+
+	public static int countDay(String date1, String date2) throws ParseException {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+		Calendar c1 = Calendar.getInstance();
+		Calendar c2 = Calendar.getInstance();
+
+		c1.setTime(sdf.parse(date1));
+		c2.setTime(sdf.parse(date2));
+		int day = ((Long) ((c2.getTimeInMillis() - c1.getTimeInMillis()) / 86400000)).intValue();
+		return day;
+	}
+
+	public static String imgSize(String jsonStr) {
+		JSONObject json = JSONObject.fromObject(jsonStr);
+		String picUrl = (String) json.opt("pictUrl");
+		if (picUrl.contains("alicdn") || picUrl.contains("tbcdn")) {
+			picUrl = TbImgUtil.getTBSize320Img(picUrl);
+		}
+		json.element("pictUrl", picUrl);
+		return json.toString();
+	}
+
+	public static String imgListSize(String jsonStr) {
+		JSONArray json = JSONArray.fromObject(jsonStr);
+		for (Object object : json) {
+			String picUrl = (String) ((JSONObject) object).opt("pictUrl");
+			if (picUrl.contains("alicdn") || picUrl.contains("tbcdn")) {
+				picUrl = TbImgUtil.getTBSize320Img(picUrl);
+			}
+			((JSONObject) object).element("pictUrl", picUrl);
+		}
+		return json.toString();
+	}
+
+	public static Map<String, String> parseURL(String url) {
+
+		String URL_REGEX = "(((http|https)://)|(www\\.))[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,4})?(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
+		Pattern p = Pattern.compile(URL_REGEX);
+		Matcher matcher = p.matcher(url);
+		boolean b = matcher.matches();
+		Map<String, String> map = new HashMap<String, String>();
+		if (!b) {
+			return map;
+		}
+		if (!url.contains("?")) {
+			return map;
+		}
+
+		String params = url.substring(url.indexOf("?") + 1);
+		if (params == null || "".equals(params)) {
+			return map;
+		}
+
+		String[] paramArr = params.split("&");
+
+		for (String arr : paramArr) {
+			String[] kv = arr.split("=");
+			if (kv.length == 1) {
+				kv[1] = "";
+			}
+			map.put(kv[0], kv[1]);
+		}
+
+		return map;
+	}
+
+	public static double random(double mix) {
+		return (Math.random() * 20) + mix;
+	}
+
+	public static String getStarString(String content, int begin, int end) {
+
+		if (begin >= content.length() || begin < 0) {
+			return content;
+		}
+		if (end >= content.length() || end < 0) {
+			return content;
+		}
+		if (begin >= end) {
+			return content;
+		}
+		String starStr = "";
+		for (int i = begin; i < end; i++) {
+			starStr = starStr + "*";
+		}
+		return content.substring(0, begin) + starStr + content.substring(end, content.length());
+
+	}
+
+	public static boolean isNum(String content) {
+		if (content == null) {
+			return false;
+		}
+		String regex = "\\d+";
+		Pattern compile = Pattern.compile(regex);
+		Matcher matcher = compile.matcher(content);
+		return matcher.matches();
+	}
+
+	public static boolean isOrderNum(String order) {
+		if (order == null) {
+			return false;
+		}
+		String regex = "\\d{16,}";
+		Pattern compile = Pattern.compile(regex);
+		Matcher matcher = compile.matcher(order);
+		return matcher.matches();
+	}
+
+	public static boolean isUserOrder(String existOrder, String lostOrder) {
+		if (existOrder.length() < 16 || lostOrder.length() < 16) {
+			return false;
+		}
+		String existNum = existOrder.substring(existOrder.length() - 6);
+		String lostOrderNum = lostOrder.substring(lostOrder.length() - 6);
+
+		if (existNum.equals(lostOrderNum)) {
+			return true;
+		}
+
+		return false;
+	}
+
+}

--
Gitblit v1.8.0