From a088987e7ab7005db1bb1da61dfc0cf420e02d78 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 17:11:28 +0800 Subject: [PATCH] 1 --- src/main/java/com/moon/server/entity/mn/Robbins8kmEntity.java | 4 src/main/java/com/moon/server/helper/AsyncHelper.java | 18 - src/main/java/com/moon/server/helper/RsaHelper.java | 80 ------ src/main/java/com/moon/server/helper/RestHelper.java | 70 ----- src/main/java/com/moon/server/entity/mn/MooncontourEntity.java | 4 src/main/java/com/moon/server/entity/mn/Lunarswirls180Entity.java | 4 src/main/java/com/moon/server/entity/shujian/DeleteResultEntity.java | 8 src/main/java/com/moon/server/helper/SpringContextHelper.java | 47 --- src/main/java/com/moon/server/helper/StringHelper.java | 98 -------- src/main/java/com/moon/server/helper/WebHelper.java | 111 --------- src/main/java/com/moon/server/helper/AesHelper.java | 71 ----- src/main/java/com/moon/server/entity/shujian/LayerResultEntity.java | 7 src/main/java/com/moon/server/helper/GdalHelper.java | 55 ---- src/main/java/com/moon/server/helper/GeoHelper.java | 30 -- src/main/java/com/moon/server/entity/mn/Wrinkleridges180Entity.java | 4 src/main/java/com/moon/server/helper/Md5Helper.java | 37 --- src/main/java/com/moon/server/helper/ExcelHelper.java | 31 -- 17 files changed, 17 insertions(+), 662 deletions(-) diff --git a/src/main/java/com/moon/server/entity/mn/Lunarswirls180Entity.java b/src/main/java/com/moon/server/entity/mn/Lunarswirls180Entity.java index 306dcc8..ef0db2e 100644 --- a/src/main/java/com/moon/server/entity/mn/Lunarswirls180Entity.java +++ b/src/main/java/com/moon/server/entity/mn/Lunarswirls180Entity.java @@ -9,10 +9,6 @@ import java.sql.Timestamp; import java.time.LocalDate; -/** - * Lunarswirls180 - * @author WWW - */ @Data @AllArgsConstructor @SuppressWarnings("ALL") diff --git a/src/main/java/com/moon/server/entity/mn/MooncontourEntity.java b/src/main/java/com/moon/server/entity/mn/MooncontourEntity.java index 0a4869b..2733cfe 100644 --- a/src/main/java/com/moon/server/entity/mn/MooncontourEntity.java +++ b/src/main/java/com/moon/server/entity/mn/MooncontourEntity.java @@ -9,10 +9,6 @@ import java.sql.Timestamp; import java.time.LocalDate; -/** - * Mooncontour - * @author WWW - */ @Data @AllArgsConstructor @SuppressWarnings("ALL") diff --git a/src/main/java/com/moon/server/entity/mn/Robbins8kmEntity.java b/src/main/java/com/moon/server/entity/mn/Robbins8kmEntity.java index b9a225a..f5d823a 100644 --- a/src/main/java/com/moon/server/entity/mn/Robbins8kmEntity.java +++ b/src/main/java/com/moon/server/entity/mn/Robbins8kmEntity.java @@ -9,10 +9,6 @@ import java.sql.Timestamp; import java.time.LocalDate; -/** - * Robbins8km - * @author WWW - */ @Data @AllArgsConstructor @SuppressWarnings("ALL") diff --git a/src/main/java/com/moon/server/entity/mn/Wrinkleridges180Entity.java b/src/main/java/com/moon/server/entity/mn/Wrinkleridges180Entity.java index ca9235c..ae75002 100644 --- a/src/main/java/com/moon/server/entity/mn/Wrinkleridges180Entity.java +++ b/src/main/java/com/moon/server/entity/mn/Wrinkleridges180Entity.java @@ -9,10 +9,6 @@ import java.sql.Timestamp; import java.time.LocalDate; -/** - * Wrinkleridges180 - * @author WWW - */ @Data @AllArgsConstructor @SuppressWarnings("ALL") diff --git a/src/main/java/com/moon/server/entity/shujian/DeleteResultEntity.java b/src/main/java/com/moon/server/entity/shujian/DeleteResultEntity.java index 2c2f020..92f9cca 100644 --- a/src/main/java/com/moon/server/entity/shujian/DeleteResultEntity.java +++ b/src/main/java/com/moon/server/entity/shujian/DeleteResultEntity.java @@ -4,13 +4,7 @@ import java.util.ArrayList; import java.util.List; -/** - * 鏁扮畝.鍒犻櫎-缁撴灉瀹炰綋绫� - * - * @author WWW - * @date 2023-09-01 - */ -@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming") +@SuppressWarnings("ALL") public class DeleteResultEntity implements Serializable { private static final long serialVersionUID = -6859400504807647005L; diff --git a/src/main/java/com/moon/server/entity/shujian/LayerResultEntity.java b/src/main/java/com/moon/server/entity/shujian/LayerResultEntity.java index 062cebe..23c48d0 100644 --- a/src/main/java/com/moon/server/entity/shujian/LayerResultEntity.java +++ b/src/main/java/com/moon/server/entity/shujian/LayerResultEntity.java @@ -2,12 +2,7 @@ import java.io.Serializable; -/** - * 鏁扮畝.鍒涘缓鍥惧眰-缁撴灉绫� - * @author WWW - * @date 2023-08-31 - */ -@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming") +@SuppressWarnings("ALL") public class LayerResultEntity implements Serializable { private static final long serialVersionUID = -1916127613292276655L; diff --git a/src/main/java/com/moon/server/helper/AesHelper.java b/src/main/java/com/moon/server/helper/AesHelper.java index 4610cd3..f606f3c 100644 --- a/src/main/java/com/moon/server/helper/AesHelper.java +++ b/src/main/java/com/moon/server/helper/AesHelper.java @@ -4,75 +4,30 @@ import javax.crypto.spec.SecretKeySpec; import java.util.Base64; -/** - * AES鍔犲瘑甯姪 - * @author WWW - */ -@SuppressWarnings("restriction") +@SuppressWarnings("ALL") public class AesHelper { - /** - * 瀵嗛挜闀垮害蹇呴』鏄�16 - */ private static final String DEFAULT_KEY = "A#s_lF_sErve_k.y"; private static final String KEY_ALGORITHM = "AES"; - /** - * 绠楁硶 - */ private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding"; - /** - * aes瑙e瘑 - * - * @param encrypt 鍐呭 - * @return - * @throws Exception - */ public static String decrypt(String encrypt) throws Exception { return decrypt(encrypt, DEFAULT_KEY); } - /** - * aes鍔犲瘑 - * - * @param content 鍐呭 - * @return - * @throws Exception - */ public static String encrypt(String content) throws Exception { return encrypt(content, DEFAULT_KEY); } - /** - * base 64 encode - * - * @param bytes 寰呯紪鐮佺殑byte[] - * @return 缂栫爜鍚庣殑base64 code - */ private static String base64Encode(byte[] bytes) { return Base64.getEncoder().encodeToString(bytes); } - /** - * base 64 decode - * - * @param base64Code 寰呰В鐮佺殑base64 code - * @return 瑙g爜鍚庣殑byte[] - * @throws Exception - */ private static byte[] base64Decode(String base64Code) { return StringHelper.isEmpty(base64Code) ? null : Base64.getDecoder().decode(base64Code); } - /** - * AES鍔犲瘑 - * - * @param content 寰呭姞瀵嗙殑鍐呭 - * @param encryptKey 鍔犲瘑瀵嗛挜 - * @return 鍔犲瘑鍚庣殑byte[] - * @throws Exception - */ private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception { // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM) // kGen.init(128) @@ -83,38 +38,14 @@ return cipher.doFinal(content.getBytes("utf-8")); } - /** - * AES鍔犲瘑涓篵ase 64 code - * - * @param content 寰呭姞瀵嗙殑鍐呭 - * @param encryptKey 鍔犲瘑瀵嗛挜 - * @return 鍔犲瘑鍚庣殑base 64 code - * @throws Exception - */ public static String encrypt(String content, String encryptKey) throws Exception { return base64Encode(aesEncryptToBytes(content, encryptKey)); } - /** - * 灏哹ase 64 code AES瑙e瘑 - * - * @param encryptStr 寰呰В瀵嗙殑base 64 code - * @param decryptKey 瑙e瘑瀵嗛挜 - * @return 瑙e瘑鍚庣殑string - * @throws Exception - */ public static String decrypt(String encryptStr, String decryptKey) throws Exception { return StringHelper.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey); } - /** - * AES瑙e瘑 - * - * @param encryptBytes 寰呰В瀵嗙殑byte[] - * @param decryptKey 瑙e瘑瀵嗛挜 - * @return 瑙e瘑鍚庣殑String - * @throws Exception - */ private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { // KeyGenerator kGen = KeyGenerator.getInstance(KEY_ALGORITHM) // kGen.init(128) diff --git a/src/main/java/com/moon/server/helper/AsyncHelper.java b/src/main/java/com/moon/server/helper/AsyncHelper.java index ac662f8..64b4219 100644 --- a/src/main/java/com/moon/server/helper/AsyncHelper.java +++ b/src/main/java/com/moon/server/helper/AsyncHelper.java @@ -9,15 +9,8 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -/** - * 寮傛甯姪绫� - * @author WWW - * @date 2023-07-10 - */ +@SuppressWarnings("ALL") public class AsyncHelper { - /** - * 鎿嶄綔寤惰繜10姣 - */ private final static int OPERATE_DELAY_TIME = 10; // private final static AsyncHelper INSTANCE = new AsyncHelper(); @@ -29,23 +22,14 @@ public AsyncHelper() { } - /** - * 鎵ц浠诲姟 - */ public void execute(TimerTask task) { executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); } - /** - * 鍏抽棴浠诲姟 - */ public void shutdown() { shutdownAndAwaitTermination(executor); } - /** - * 鍋滄浠诲姟绾跨▼姹� - */ public static void shutdownAndAwaitTermination(ExecutorService pool) { try { if (null == pool || pool.isShutdown()) { diff --git a/src/main/java/com/moon/server/helper/ExcelHelper.java b/src/main/java/com/moon/server/helper/ExcelHelper.java index bbb0791..6c5c6d5 100644 --- a/src/main/java/com/moon/server/helper/ExcelHelper.java +++ b/src/main/java/com/moon/server/helper/ExcelHelper.java @@ -14,18 +14,8 @@ import java.util.*; -/** - * Excel甯姪绫� - * @author WWW - */ +@SuppressWarnings("ALL") public class ExcelHelper { - /** - * 璇诲彇Excel - * - * @param pathName 鏂囦欢璺緞 - * @param <T> 娉涘瀷绫� - * @return 娉涘瀷绫婚泦鍚� - */ public static <T> List<T> readExcel(Class<?> clazz, String pathName) { ExcelHead head = getExcelHead(clazz); int headRowNumber = head == null ? 1 : head.headRows(); @@ -58,40 +48,21 @@ return list; } - /** - * 鑾峰彇Excel澶存敞瑙g被 - * - * @param clazz Class - * @param <T> 娉涘瀷绫� - * @return 澶磋鏁� - */ public static <T> ExcelHead getExcelHead(Class<?> clazz) { ExcelHead head = clazz.getAnnotation(ExcelHead.class); return head; } - /** - * 鍐欏叆Excel妯℃澘 - * - * @param source 婧愭枃浠讹紙妯℃澘锛� - * @param target 鐩綍鏂囦欢 - * @param map 鏁版嵁婧� - */ public static <T> void writeToTemplate(String source, String target, Map<String, List<T>> map) { - // 鏍规嵁妯℃澘鍐欏叆鏁版嵁锛屽鏋滅洰鏍囨枃浠朵笉瀛樺湪锛屽垯鑷姩鍒涘缓鏂囦欢 ExcelWriter excelWriter = EasyExcel.write(target).withTemplate(source).build(); - // 鍦ㄥ伐浣滅翱0涓啓鍏ユ暟鎹紝濡傛灉妯℃澘涓笉瀛樺湪缁冧範宸ヤ綔绨匡紝鍒欎細鍦ㄧ洰鏍囨枃浠朵腑鑷姩鍒涘缓 WriteSheet writeSheet = EasyExcel.writerSheet(0).build(); - // 鍨傜洿鍐欏叆鏁版嵁锛屽鏋滆姘村钩鍐欏叆锛屽皢VERTICAL鏇挎崲涓篐ORIZONTAL FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build(); - // 鍐欏叆鏁版嵁 map.forEach((k, v) -> excelWriter.fill(new FillWrapper(k, v), fillConfig, writeSheet)); - // 缁撴潫鍐欏叆 excelWriter.finish(); } } diff --git a/src/main/java/com/moon/server/helper/GdalHelper.java b/src/main/java/com/moon/server/helper/GdalHelper.java index 08ba1cc..4576d60 100644 --- a/src/main/java/com/moon/server/helper/GdalHelper.java +++ b/src/main/java/com/moon/server/helper/GdalHelper.java @@ -21,23 +21,16 @@ import java.util.List; import java.util.Map; -/** - * GDAL甯姪绫� - * @author WWW - */ @SuppressWarnings("ALL") public class GdalHelper { private final static Log log = LogFactory.getLog(GdalHelper.class); public static void init(String gdalPath) { - // 鏀寔涓枃璺緞 gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - // 灞炴�ц〃鏀寔涓枃锛欳P936 gdal.SetConfigOption("SHAPE_ENCODING", ""); gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); - // 閰嶇疆鐜鍙橀噺 if (!StringHelper.isEmpty(gdalPath)) { gdal.SetConfigOption("GDAL_DATA", gdalPath + File.separator + "gdal-data"); gdal.SetConfigOption("PROJ_LIB", gdalPath + File.separator + "proj7" + File.separator + "share"); @@ -50,17 +43,11 @@ } } - // 娉ㄥ唽鎵�鏈夌殑椹卞姩 gdal.AllRegister(); ogr.RegisterAll(); GeoHelper.initSr(); } - /** - * 璇诲彇tif鏂囦欢 - * - * @param fileName - */ public static void readTif(String fileName) { // 璇诲彇褰卞儚鏁版嵁 Dataset dataset = gdal.Open(fileName, gdalconstConstants.GA_ReadOnly); @@ -69,32 +56,23 @@ return; } - // providing various methods for a format specific driver. Driver driver = dataset.GetDriver(); System.out.println("driver name: " + driver.getLongName()); - // 璇诲彇褰卞儚淇℃伅 int xSize = dataset.getRasterXSize(); int ySzie = dataset.getRasterYSize(); int rasterCount = dataset.getRasterCount(); System.out.println("dataset xSize: " + xSize + ", ySzie = " + ySzie + ", rasterCount = " + rasterCount); Band band = dataset.GetRasterBand(1); - // the data type of the band. int type = band.GetRasterDataType(); System.out.println("data type = " + type + ", " + (type == gdalconstConstants.GDT_Byte)); - // Frees the native resource associated to a Dataset object and close the file. dataset.delete(); gdal.GDALDestroyDriverManager(); } - /** - * 璇诲彇shp鏂囦欢 - * - * @param filePath - */ public static void readShp(String filePath) { try { org.gdal.ogr.Driver driver = ogr.GetDriverByName("ESRI shapefile"); @@ -120,10 +98,8 @@ Map<String, Object> fieldMap = new HashMap(5); for (int i = 0, count = featureDefn.GetFieldCount(); i < count; i++) { FieldDefn fieldDefn = featureDefn.GetFieldDefn(i); - //寰楀埌灞炴�у瓧娈电被鍨� int fieldType = fieldDefn.GetFieldType(); String fieldTypeName = fieldDefn.GetFieldTypeName(fieldType); - //寰楀埌灞炴�у瓧娈靛悕绉� String fieldName = fieldDefn.GetName(); fieldMap.put(fieldTypeName, fieldName); @@ -159,20 +135,16 @@ dataSource = driver.Open(filePath, 0); int num = dataSource.GetLayerCount(); for (int i = 0; i < num; i++) { - // 鑾峰彇鍥惧眰 Layer layer = dataSource.GetLayer(i); - // 琛ㄥ悕绉� String strlayerName = layer.GetName(); - // 鑾峰彇鍥惧眰瑕佹暟涓暟 long count = layer.GetFeatureCount(); if (0 != count) { do { - // 鑾峰彇鍥惧眰涓嬬殑瑕佺礌 Feature feature = layer.GetNextFeature(); if (null == feature) { break; } - // 鑾峰彇杈圭晫鍧愭爣 + Geometry geometry = feature.GetGeometryRef(); if (geometry != null) { String geometryJson = geometry.ExportToJson(); @@ -192,7 +164,6 @@ } } Map map = new HashMap(5); - //鑾峰彇灞炴�� for (int p = 0; p < feature.GetFieldCount(); p++) { map.put(feature.GetFieldDefnRef(p).GetName(), getProperty(feature, p)); } @@ -214,11 +185,6 @@ } } - /** - * 璇诲彇gdb鏂囦欢 - * - * @param filePath - */ public static void readGdb(String filePath) { try { org.gdal.ogr.Driver driver = ogr.GetDriverByName("OpenFileGDB"); @@ -228,20 +194,16 @@ DataSource dataSource = driver.Open(filePath, 0); for (int i = 0, count = dataSource.GetLayerCount(); i < count; i++) { - // 鑾峰彇鍥惧眰 Layer layer = dataSource.GetLayer(i); System.out.println(i + "\t" + layer.GetName()); do { - // 鑾峰彇鍥惧眰涓嬬殑瑕佺礌 Feature feature = layer.GetNextFeature(); if (null == feature) { break; } - // 鑾峰彇鏍峰紡锛岃繖閲屾槸绌猴紝寰呯‘瀹� + System.out.println(feature.GetStyleString()); - // 鑾峰彇geometry锛屼篃鍙互ExportToWkb() gml绛夌瓑 System.out.println(feature.GetGeometryRef().ExportToWkt()); - // 鑾峰彇灞炴�� System.out.println("----------------------------------"); for (int p = 0; p < feature.GetFieldCount(); p++) { System.out.println(feature.GetFieldDefnRef(p).GetName() + "\t" + getProperty(feature, p)); @@ -275,26 +237,13 @@ } } - /** - * 灞炴�ц幏鍙栧櫒 - */ @FunctionalInterface private interface PropertyGetter { - /** - * 鑾峰彇灞炴�� - * - * @param feature - * @param index - * @return - */ Object get(Feature feature, int index); } private static final PropertyGetter STRING_PROPERTY_GETTER = (feature, index) -> feature.GetFieldAsString(index); - /** - * feature.GetFieldType(index)寰楀埌涓�涓睘鎬х被鍨嬬殑int鍊�,璇ュ�煎搴斿叿浣撶被鍨� - */ private static final PropertyGetter[] PROPERTY_GETTERS = new PropertyGetter[]{ // 0-Integer (feature, index) -> feature.GetFieldAsInteger(index), diff --git a/src/main/java/com/moon/server/helper/GeoHelper.java b/src/main/java/com/moon/server/helper/GeoHelper.java index faafbff..ac1403e 100644 --- a/src/main/java/com/moon/server/helper/GeoHelper.java +++ b/src/main/java/com/moon/server/helper/GeoHelper.java @@ -16,11 +16,7 @@ import java.awt.geom.Point2D; -/** - * Geo甯姪绫� - * @author WWW - * @date 2023-09-14 - */ +@SuppressWarnings("ALL") public class GeoHelper { public static SpatialReference sr4326; @@ -34,9 +30,6 @@ private final static Log log = LogFactory.getLog(GeoHelper.class); - /** - * 鍒濆鍖栧潗鏍囩郴 - */ public static void initSr() { try { sr4326 = new SpatialReference(); @@ -53,9 +46,6 @@ } } - /** - * 鑾峰彇璺濈 - */ public static double getDistance(double x1, double y1, double x2, double y2) { GeodeticCalculator geodeticCalculator = new GeodeticCalculator(crs104903); geodeticCalculator.setStartingGeographicPoint(x1, y1); @@ -64,9 +54,6 @@ return geodeticCalculator.getOrthodromicDistance(); } - /** - * 鑾峰彇璺濈2 - */ public static double getDistance2(double lon1, double lat1, double lon2, double lat2) { double radLat1 = Math.toRadians(lat1); double radLat2 = Math.toRadians(lat2); @@ -77,16 +64,10 @@ return s * MOON_RADIUS; } - /** - * 鑾峰彇鏂瑰悜瑙� - */ public static double getBearing(double x1, double y1, double x2, double y2) { return (90 - Math.toDegrees(Math.atan2(x2 - x1, y2 - y1)) + 360) % 360; } - /** - * 鑾峰彇瑙掑害 - */ public static double getAngle(double x1, double y1, double x2, double y2) { DirectPosition2D p1 = new DirectPosition2D(crs104903, x1, y1); DirectPosition2D p2 = new DirectPosition2D(crs104903, x2, y2); @@ -98,9 +79,6 @@ return gc.getAzimuth(); } - /** - * 鑾峰彇瑙掑害2 - */ public static double getAngle2(double x1, double y1, double x2, double y2) { DirectPosition2D p1 = new DirectPosition2D(x1, y1); DirectPosition2D p2 = new DirectPosition2D(x2, y2); @@ -112,9 +90,6 @@ return gc.getAzimuth(); } - /** - * 鏍规嵁璺濈鍜岃搴﹁幏鍙栫洰鏍囩偣 - */ public static Point2D getPointByDistanceAndAngle(double x, double y, double angle, double distance) { DirectPosition2D p1 = new DirectPosition2D(x, y); @@ -125,9 +100,6 @@ return gc.getDestinationGeographicPoint(); } - /** - * 鍧愭爣杞崲 - */ public static double[] csTransform(double x, double y, int epsg) throws Exception { CRSAuthorityFactory factory = CRS.getAuthorityFactory(true); CoordinateReferenceSystem target = factory.createCoordinateReferenceSystem("EPSG:4326"); diff --git a/src/main/java/com/moon/server/helper/Md5Helper.java b/src/main/java/com/moon/server/helper/Md5Helper.java index f9ef484..2239512 100644 --- a/src/main/java/com/moon/server/helper/Md5Helper.java +++ b/src/main/java/com/moon/server/helper/Md5Helper.java @@ -5,10 +5,7 @@ import java.security.MessageDigest; import java.util.Random; -/** - * MD5甯姪绫� - * @author WWW - */ +@SuppressWarnings("ALL") public class Md5Helper { private final static int M3 = 3; @@ -16,12 +13,6 @@ private final static int M48 = 48; - /** - * 鐢熸垚鍚湁闅忔満鐩愮殑瀵嗙爜 - * - * @param password - * @return - */ public static String generate(String password) { Random r = new Random(); StringBuilder sb = new StringBuilder(16); @@ -47,13 +38,6 @@ return new String(cs); } - /** - * 鏍¢獙瀵嗙爜鏄惁姝g‘ - * - * @param password - * @param md5 - * @return - */ public static boolean verify(String password, String md5) { char[] cs1 = new char[32]; char[] cs2 = new char[16]; @@ -67,12 +51,6 @@ return md5Hex(password + salt).equals(new String(cs1)); } - /** - * 鑾峰彇鍗佸叚杩涘埗瀛楃涓插舰寮忕殑MD5鎽樿 - * - * @param src - * @return - */ public static String md5Hex(String src) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); @@ -84,25 +62,12 @@ } } - /** - * 鍙嶈浆 - * - * @param pass - * @return - */ public static String reverse(String pass) { StringBuilder sb = new StringBuilder(pass); return sb.reverse().toString(); } - /** - * 楠岃瘉瀵嗙爜 - * - * @param originalPassword - * @param dbPassword - * @return - */ public static boolean validatePassword(String originalPassword, String dbPassword) { return verify(originalPassword, reverse(dbPassword)); } diff --git a/src/main/java/com/moon/server/helper/RestHelper.java b/src/main/java/com/moon/server/helper/RestHelper.java index 32828db..1e5e974 100644 --- a/src/main/java/com/moon/server/helper/RestHelper.java +++ b/src/main/java/com/moon/server/helper/RestHelper.java @@ -24,20 +24,12 @@ import java.util.List; import java.util.Map; -/** - * Rest鏈嶅姟甯姪绫� - * @author WWW - */ +@SuppressWarnings("ALL") public class RestHelper { private static RestTemplate restTemplate; private final static Log log = LogFactory.getLog(RestHelper.class); - /** - * 鑾峰彇RestTemplate - * - * @return RestTemplate - */ public static RestTemplate getRestTemplate() { if (restTemplate == null) { restTemplate = SpringContextHelper.getBean(RestTemplate.class); @@ -46,13 +38,6 @@ return restTemplate; } - /** - * Get璇锋眰-HttpURLConnection - * - * @param url URL鍦板潃 - * @return 瀛楃涓� - * @throws IOException IO寮傚父 - */ public static String getForConn(String url) throws IOException { BufferedReader br = null; HttpURLConnection conn = null; @@ -84,14 +69,6 @@ } } - /** - * Post璇锋眰-HttpURLConnection - * - * @param url URL鍦板潃 - * @param query 鏌ヨ鏉′欢 - * @return 瀛楃涓� - * @throws IOException IO寮傚父 - */ public static String postForConn(String url, String query) throws IOException { BufferedReader br = null; HttpURLConnection conn = null; @@ -100,7 +77,6 @@ URL restUrl = new URL(url); conn = (HttpURLConnection) restUrl.openConnection(); - // POST,GET,PUT,DELETE conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true); @@ -132,12 +108,6 @@ } } - /** - * Get璇锋眰-CloseableHttpClient - * - * @param uri Uri鍦板潃 - * @return 鍝嶅簲瀛楃涓� - */ public static String get(String uri) { try { CloseableHttpClient httpClient = HttpClients.custom().build(); @@ -145,7 +115,7 @@ HttpGet httpGet = new HttpGet(uri); CloseableHttpResponse closeResponse = httpClient.execute(httpGet); - // 鍙栧嚭杩斿洖浣� + HttpEntity entity = closeResponse.getEntity(); return EntityUtils.toString(entity, StaticData.TEXT_ENCODER); @@ -156,13 +126,6 @@ } } - /** - * Post璇锋眰-CloseableHttpClient - * - * @param uri Uri鍦板潃 - * @param postData 寰呭彂閫佹暟鎹� - * @return 鍝嶅簲瀛楃涓� - */ public static String post(String uri, List<NameValuePair> postData) { try { CloseableHttpClient httpClient = HttpClients.custom().build(); @@ -173,7 +136,6 @@ CloseableHttpResponse closeResponse = httpClient.execute(httpPost); - // 鍙栧嚭杩斿洖浣� HttpEntity entity = closeResponse.getEntity(); return EntityUtils.toString(entity, StaticData.TEXT_ENCODER); @@ -184,13 +146,6 @@ } } - /** - * 鑾峰彇閿欒淇℃伅 - * - * @param uri Uri鍦板潃 - * @param ex 寮傚父 - * @return 閿欒淇℃伅 - */ public static String getErrorInfo(String uri, Exception ex) { Map<String, Object> map = new LinkedHashMap<>(); map.put("result", null); @@ -202,63 +157,42 @@ return map.toString(); } - /** - * GET璇锋眰锛圧EST锛� - */ public static String getForRest(String uri) { RestTemplate rest = getRestTemplate(); return rest.getForObject(uri, String.class); } - /** - * GET璇锋眰锛圧EST锛� - */ public static <T> T getForRest(String uri, Class<T> clazz) { RestTemplate rest = getRestTemplate(); return rest.getForObject(uri, clazz); } - /** - * POST璇锋眰锛圧EST锛� - */ public static String postForRest(String uri, Map<String, Object> map) { RestTemplate rest = getRestTemplate(); return rest.postForObject(uri, map, String.class); } - /** - * POST璇锋眰锛圧EST锛� - */ public static <T> String postForRest(String uri, List<T> list) { RestTemplate rest = getRestTemplate(); return rest.postForObject(uri, list, String.class); } - /** - * POST璇锋眰锛圧EST锛� - */ public static <T> String postForRest(String uri, T t) { RestTemplate rest = getRestTemplate(); return rest.postForObject(uri, t, String.class); } - /** - * DELETE璇锋眰锛圧EST锛� - */ public static void deleteForRest(String uri) { RestTemplate rest = getRestTemplate(); rest.delete(uri); } - /** - * DELETE璇锋眰锛圧EST锛� - */ public static void deleteForRest(String uri, Map<String, Object> map) { RestTemplate rest = getRestTemplate(); diff --git a/src/main/java/com/moon/server/helper/RsaHelper.java b/src/main/java/com/moon/server/helper/RsaHelper.java index 172eb36..7040301 100644 --- a/src/main/java/com/moon/server/helper/RsaHelper.java +++ b/src/main/java/com/moon/server/helper/RsaHelper.java @@ -16,51 +16,24 @@ import java.util.HashMap; import java.util.Map; -/** - * RSA宸ュ叿绫� - * @author WWW - */ +@SuppressWarnings("ALL") public class RsaHelper { - /** - * 绉侀挜 - */ private static String privateKey; - /** - * 鍏挜 - */ private static String publicKey; - /** - * 瀵嗛挜绠楁硶 - */ private static final String KEY_ALGORITHM = "RSA"; - /** - * RSA瀵嗛挜闀垮害锛�1024 鎴� 2048 - */ private static final int DEFAULT_RSA_KEY_SIZE = 1024; - /** - * 鏃ュ織 - */ private final static Log log = LogFactory.getLog(RsaHelper.class); - /** - * 鐢熸垚鍏閽� - */ public static void generate() { Map<String, String> result = generateRsaKey(DEFAULT_RSA_KEY_SIZE); System.out.println("鍏挜涓猴細" + result.get("publicKey")); System.out.println("绉侀挜涓猴細" + result.get("privateKey")); } - /** - * 鑾峰彇RSA鍔犲瘑绉侀挜 - * - * @return - * @throws IOException - */ public static String getPrivateKey() throws IOException { if (privateKey == null) { InputStream inPrivate = new ClassPathResource("config" + File.separator + "rsa_private_key.txt").getInputStream(); @@ -71,12 +44,6 @@ return privateKey; } - /** - * 鑾峰彇RSA鍔犲瘑鍏挜 - * - * @return - * @throws IOException - */ public static String getPublicKey() throws IOException { if (publicKey == null) { InputStream inPrivate = new ClassPathResource("config" + File.separator + "rsa_public_key.txt").getInputStream(); @@ -87,13 +54,6 @@ return publicKey; } - /** - * 璇诲彇鏂囨湰鏂囦欢 - * - * @param fileName 鏂囦欢璺緞 - * @return - * @throws IOException - */ public static String readFile(String fileName) throws IOException { File file = new File(fileName); BufferedReader br = new BufferedReader(new FileReader(file)); @@ -109,13 +69,6 @@ return result.toString(); } - /** - * 鎶奿nputStream杞垚String - * - * @param is - * @return - * @throws IOException - */ private static String inputStream2String(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -130,28 +83,18 @@ return str; } - /** - * 鐢熸垚RSA鐨勫叕绉侀挜 - * - * @param keySize 1025 鎴� 2048 - * @return - */ public static Map<String, String> generateRsaKey(int keySize) { Map<String, String> result = new HashMap<>(2); try { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); - // 鍒濆鍖栧瘑閽ュ鐢熸垚鍣紝瀵嗛挜澶у皬涓�1024 2048浣� keyPairGen.initialize(keySize, new SecureRandom()); - // 鐢熸垚涓�涓瘑閽ュ锛屼繚瀛樺湪keyPair涓� KeyPair keyPair = keyPairGen.generateKeyPair(); - // 寰楀埌鍏挜瀛楃涓� String pub = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded())); result.put("publicKey", pub); - // 寰楀埌绉侀挜瀛楃涓� String pri = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded())); result.put("privateKey", pri); } catch (Exception ex) { @@ -161,22 +104,13 @@ return result; } - /** - * RSA绉侀挜瑙e瘑 - * - * @param str 鍔犲瘑鐨勫瓧绗︿覆 - * @return 瑙e瘑瀛楃涓� - * @throws Exception 鍔犲瘑杩囩▼涓殑寮傚父淇℃伅 - */ public static String decrypt(String str) throws Exception { - // 64浣嶈В鐮佸姞瀵嗗悗鐨勫瓧绗︿覆 byte[] inputByte = Base64.decodeBase64(str.getBytes(StandardCharsets.UTF_8)); - // Base64缂栫爜鐨勭閽� byte[] decoded = Base64.decodeBase64(getPrivateKey()); RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); - // RSA瑙e瘑锛歊SA/ECB/NoPadding + // RSA/ECB/NoPadding Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, priKey); @@ -185,20 +119,12 @@ return outStr; } - /** - * RSA鍏挜鍔犲瘑 - * - * @param str 闇�瑕佸姞瀵嗙殑瀛楃涓� - * @return 瀵嗘枃 - * @throws Exception 鍔犲瘑杩囩▼涓殑寮傚父淇℃伅 - */ public static String encrypt(String str) throws Exception { - // Base64缂栫爜鐨勫叕閽� byte[] decoded = Base64.decodeBase64(getPublicKey()); RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); - // RSA鍔犲瘑锛歊SA/ECB/NoPadding + // RSA/ECB/NoPadding Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); diff --git a/src/main/java/com/moon/server/helper/SpringContextHelper.java b/src/main/java/com/moon/server/helper/SpringContextHelper.java index c988023..783ae6e 100644 --- a/src/main/java/com/moon/server/helper/SpringContextHelper.java +++ b/src/main/java/com/moon/server/helper/SpringContextHelper.java @@ -5,81 +5,36 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; -/** - * Spring涓婁笅鏂囧府鍔╃被 - * @author WWW - */ @Component +@SuppressWarnings("ALL") public class SpringContextHelper implements ApplicationContextAware { private static ApplicationContext context = null; - /** - * 璁剧疆搴旂敤绋嬪簭涓婁笅鏂� - * - * @param applicationContext - * @throws BeansException - */ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { context = applicationContext; } - /** - * 鏍规嵁鍚嶇О鑾峰彇Bean - * - * @param name 绫诲悕绉� - * @return - */ public static <T> T getBean(String name) { return (T) context.getBean(name); } - /** - * 鏍规嵁绫诲瀷鑾峰彇Bean - * - * @param clazz 绫� - * @param <T> 娉涘瀷 - * @return - */ public static <T> T getBean(Class<T> clazz) { return context.getBean(clazz); } - /** - * 鍒ゆ柇鏄惁鍖呭惈瀵瑰簲鍚嶇О鐨凚ean瀵硅薄 - * - * @param name Bean鍚嶇О - * @return 鍖呭惈锛氳繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse銆� - */ public static boolean containsBean(String name) { return context.containsBean(name); } - /** - * 鑾峰彇瀵瑰簲Bean鍚嶇О鐨勭被鍨� - * - * @param name Bean鍚嶇О - * @return 杩斿洖瀵瑰簲鐨凚ean绫诲瀷 - */ public static Class<?> getType(String name) { return context.getType(name); } - /** - * 鑾峰彇涓婁笅鏂囧璞★紝鍙繘琛屽悇绉峉pring鐨勪笂涓嬫枃鎿嶄綔 - * - * @return Spring涓婁笅鏂囧璞� - */ public static ApplicationContext getContext() { return context; } - - /** - * 鑾峰彇褰撳墠鐜 - * - * @return Profile - */ public static String getActiveProfile() { return context.getEnvironment().getActiveProfiles()[0]; } diff --git a/src/main/java/com/moon/server/helper/StringHelper.java b/src/main/java/com/moon/server/helper/StringHelper.java index 593dfbc..a3adc61 100644 --- a/src/main/java/com/moon/server/helper/StringHelper.java +++ b/src/main/java/com/moon/server/helper/StringHelper.java @@ -11,70 +11,34 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * 瀛楃涓插府鍔╃被 - * @author WWW - */ +@SuppressWarnings("ALL") public class StringHelper { - /** - * 鏁板瓧姝e垯 - */ public static final Pattern NUMBER_PATTERN = Pattern.compile("-?\\d+(\\.\\d+)?"); - /** - * 鏍煎紡鍖栧綋鍓嶇郴缁熸棩鏈� 1 - */ public static final SimpleDateFormat YMD_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); - /** - * 鏍煎紡鍖栧綋鍓嶇郴缁熸棩鏈� 2 - */ public static final SimpleDateFormat YMDHMS_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - /** - * 鏍煎紡鍖栧綋鍓嶇郴缁熸棩鏈� 3 - */ public static final SimpleDateFormat YMD2_FORMAT = new SimpleDateFormat("yyyyMMdd"); - /** - * 鏍煎紡鍖栧綋鍓嶇郴缁熸棩鏈� 4 - */ public static final SimpleDateFormat YMDHMS2_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); - /** - * 鍒ゆ柇瀛楃涓�,鏄惁涓烘暣鏁� - */ public static boolean isInteger(String str) { return str != null && str.matches("[0-9]+"); } - /** - * 鍒ゆ柇瀛楃涓�,鏄惁涓烘诞鐐规暟 - */ public static boolean isNumeric(String str) { return str != null && str.matches("-?\\d+(\\.\\d+)?"); } - /** - * 鍒ゆ柇瀛楃涓�,鏄惁涓烘诞鐐规暟 - */ public static boolean isNumeric2(String str) { return str != null && NUMBER_PATTERN.matcher(str).matches(); } - /** - * 鏃ユ湡姝e垯 - */ public static Pattern datePattern = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/]((((0?[13578])|(1[02]))[\\-\\/]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/]((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/]((((0?[13578])|(1[02]))[\\-\\/]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/]((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$"); - /** - * SQL姝e垯 - */ public static Pattern sqlPattern = Pattern.compile("|and|exec|execute|insert|select|delete|update|count|drop|\\*|%|chr|mid|master|truncate|char|declare|sitename|net user|xp_cmdshell|;|or|-|\\+|,|like"); - /** - * 瀛楃涓茶浆涓烘棩鏈� - */ public static Date parseDate(String str) { try { return YMD_FORMAT.parse(str); @@ -83,9 +47,6 @@ } } - /** - * 瀛楃涓茶浆涓烘棩鏈熸椂闂� - */ public static Date parseTime(String str) { try { return YMDHMS_FORMAT.parse(str); @@ -94,53 +55,32 @@ } } - /** - * 鍒ゆ柇鍊兼槸鍚︿负鏃ユ湡鏍煎紡 - */ public static boolean isDate(String strDate) { Matcher m = datePattern.matcher(strDate); return m.matches(); } - /** - * 瀛楃涓诧紝鏄惁涓簄ull 鎴� "" - */ public static boolean isNull(String str) { return null == str || str.length() == 0; } - /** - * 瀛楃涓�,鏄惁涓虹┖null鍜岀┖鏍� - */ public static boolean isEmpty(String str) { return null == str || "".equals(str.trim()); } - /** - * 鑾峰彇 like 瀛楃涓� - */ public static String getLikeStr(String str) { return StringHelper.isEmpty(str) ? null : "%" + str.trim() + "%"; } - /** - * 鑾峰彇 like 瀛楃涓� - */ public static String getLikeUpperStr(String str) { return StringHelper.isEmpty(str) ? null : "%" + str.trim().toUpperCase() + "%"; } - /** - * 鑾峰彇 鍙砽ike 瀛楃涓� - */ public static String getRightLike(String str) { return StringHelper.isEmpty(str) ? null : str.trim() + "%"; } - /** - * 鑾峰彇鍥惧舰鐨刉KT瀛楃涓� - */ public static String getGeomWkt(String wkt) { if (StringHelper.isEmpty(wkt)) { return "null"; @@ -149,26 +89,14 @@ return String.format("ST_GeomFromText('%s')", wkt); } - /** - * 棣栧瓧姣嶅ぇ鍐� - */ public static String firstCharToUpperCase(String str) { return str.substring(0, 1).toUpperCase() + str.substring(1); } - /** - * 棣栧瓧姣嶅皬鍐� - */ public static String firstCharToLowerCase(String str) { return str.substring(0, 1).toLowerCase() + str.substring(1); } - /** - * 鍒ゆ柇鍊兼槸鍚﹀瓨鍦⊿QL娉ㄥ叆 - * - * @param str 瀛楃涓� - * @return 鏄�/鍚� - */ public static boolean isSqlInjection(String str) { if (null == str) { return false; @@ -179,38 +107,18 @@ return m.matches(); } - /** - * 鏍¢獙瀵嗙爜鏄�/鍚﹀悎娉� - * - * @param pwd 瀵嗙爜 - * @return 鏄�/鍚︿负鏃犳晥鐨� - */ public static boolean isPwdInvalid(String pwd) { return !Pattern.matches(StaticData.PWD_REG, pwd); } - /** - * 鑾峰彇GUID - */ public static String getGuid() { return UUID.randomUUID().toString(); } - /** - * 鑾峰彇鍒嗛挓宸暟 - */ public static long getMinuteDifference(Timestamp ts) { return (ts.getTime() - System.currentTimeMillis()) / 1000 / 60; } - /** - * 杩炴帴List闆嗗悎 - * - * @param list list 鏁存暟闆嗗悎 - * @param join join 杩炴帴瀛楃 - * @param <T> 娉涘瀷绫� - * @return 瀛楃涓� - */ public static <T> String join(List<T> list, String join) { if (null == list || list.isEmpty()) { return ""; @@ -224,16 +132,12 @@ } if (sb.length() > 0 && sb.lastIndexOf(join) == sb.length() - join.length()) { - // 鍒犻櫎浠庣储寮� start 寮�濮嬪埌 end 涔嬮棿鐨勫瓧绗︼紝鍗� 鍓嶅寘鎷� 鍚庝笉鍖呮嫭銆� sb.delete(sb.length() - join.length(), sb.length()); } return sb.toString(); } - /** - * 瀛楃涓茶浆鏁存暟闆嗗悎 - */ public static List<Integer> strToIntegers(String str) { if (StringHelper.isEmpty(str)) { return null; diff --git a/src/main/java/com/moon/server/helper/WebHelper.java b/src/main/java/com/moon/server/helper/WebHelper.java index 6f0fb3f..95ac2d1 100644 --- a/src/main/java/com/moon/server/helper/WebHelper.java +++ b/src/main/java/com/moon/server/helper/WebHelper.java @@ -22,10 +22,7 @@ import java.sql.Timestamp; import java.util.*; -/** - * Web甯姪绫� - * @author WWW - */ +@SuppressWarnings("ALL") public class WebHelper { private final static String UNKNOWN = "unknown"; @@ -33,25 +30,16 @@ private final static Log log = LogFactory.getLog(WebHelper.class); - /** - * 淇濈暀灏忔暟浣� - */ public static double round(double val, double size) { double power = Math.pow(10.0, size); return Math.round(val * power) / power; } - /** - * 鑾峰彇GUID - */ public static String getGuid() { return UUID.randomUUID().toString(); } - /** - * 鑾峰彇鐢ㄦ埛ip - */ public static String getIpAddress(HttpServletRequest request) { String ip = request.getHeader("X-Forwarded-For"); if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { @@ -94,16 +82,10 @@ return ip; } - /** - * 鑾峰彇褰撳墠鏃堕棿鐨凾imestamp - */ public static Timestamp getCurrentTimestamp() { return new Timestamp(System.currentTimeMillis()); } - /** - * 鑾峰彇褰撳墠鏃堕棿鎸囧畾鍒嗛挓鏁板悗鐨凾imestamp - */ public static Timestamp getTimestamp(int min) { Calendar now = Calendar.getInstance(); now.add(Calendar.MINUTE, min); @@ -111,9 +93,6 @@ return new Timestamp(now.getTimeInMillis()); } - /** - * 浠嶤ookie涓幏鍙杢oken - */ public static String getTokenFromCookie(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies == null || cookies.length == 0) { @@ -132,23 +111,14 @@ return null; } - /** - * 鍚慍ookie涓坊鍔爐oken - */ public static void saveToken2Cookie(String token, HttpServletRequest request, HttpServletResponse response) { - // 鍏堝垹闄� deleteCookies(request, response); - // 鍐嶄繚瀛� saveCookie(StaticData.TOKEN_COOKIE_KEY, token, response); } - /** - * 淇濆瓨Cookie - */ public static void saveCookie(String key, String value, HttpServletResponse response) { Cookie cookie = new Cookie(key, value); - // 璁剧疆cookie澶辨晥鏃堕棿锛屽崟浣嶄负绉� cookie.setMaxAge(SettingData.COOKIE_MAX_AGE); cookie.setHttpOnly(false); cookie.setPath("/"); @@ -158,9 +128,6 @@ response.addCookie(cookie); } - /** - * 鍒犻櫎cookie涓殑鍊� - */ public static void deleteCookie(String cookieKey, HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { @@ -174,9 +141,6 @@ } } - /** - * 鍒犻櫎鎵�鏈塁ookie - */ public static void deleteCookies(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { @@ -188,9 +152,6 @@ } } - /** - * 鏍规嵁閿幏鍙朇ookie鍊� - */ public static String getCookieByKey(String key, HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies == null || cookies.length == 0) { @@ -206,19 +167,13 @@ return null; } - /** - * 鑾峰彇Token - */ public static String getToken(HttpServletRequest request) { - // 1.浠巙rl鍙傛暟涓紝鑾峰彇token String token = request.getParameter(StaticData.TOKEN_KEY); - // 2.涓虹┖锛屽垯浠巋eader閲岃幏鍙� if (token == null) { token = request.getHeader(StaticData.TOKEN_KEY); } - // 3.杩樹负绌猴紝鍒欎粠cookie閲岃幏鍙� if (token == null) { token = getTokenFromCookie(request); } @@ -226,34 +181,22 @@ return token; } - /** - * 鑾峰彇Request - */ public static HttpServletRequest getRequest() { ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); return servletRequestAttributes.getRequest(); } - /** - * 鑾峰彇Response - */ public static HttpServletResponse getResponse() { ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); return servletRequestAttributes.getResponse(); } - /** - * 鑾峰彇Session - */ public static HttpSession getSession() { return getRequest().getSession(); } - /** - * 鑾峰彇鐪熷疄璺緞 - */ public static String getRealPath(String path) { HttpServletRequest req = getRequest(); ServletContext ctx = req.getSession().getServletContext(); @@ -261,9 +204,6 @@ return ctx.getRealPath("/" + path); } - /** - * 杈撳嚭str鑷冲墠绔� - */ public static boolean writeStr2Page(HttpServletResponse res, String str) { try { res.setContentType("application/json;charset=UTF-8"); @@ -283,50 +223,27 @@ return false; } - /** - * 杈撳嚭json鑷冲墠绔� - */ public static void writeJson2Page(HttpServletResponse res, String str) { String json = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, str)); writeStr2Page(res, json); } - /** - * 鑾峰彇閿欒JSON - */ public static String getErrJson(HttpStatus status, String msg) { return JSON.toJSONString(new ResponseMsg<String>(status, msg)); } - /** - * 鍐欏搷搴斾俊鎭� - */ public static void writeInfo(HttpStatus status, String info, HttpServletResponse res) { WebHelper.writeStr2Page(res, WebHelper.getErrJson(status, info)); } - /** - * 鑾峰彇闅忔満鏁存暟 - */ public static int getRandomInt(int min, int max) { return new Random().nextInt(max) % (max - min + 1) + min; } - /** - * 涓嬭浇鏂囦欢 - */ public static void download(String file, String fileName, HttpServletResponse res) throws Exception { download(file, fileName, false, res); } - /** - * 涓嬭浇鏂囦欢 - * - * @param file 鏂囦欢 - * @param fileName 鏂囦欢鍚� - * @param res 鍝嶅簲 - * @throws Exception 寮傚父 - */ public static void download(String file, String fileName, boolean inline, HttpServletResponse res) throws Exception { if (StringHelper.isEmpty(fileName)) { fileName = StringHelper.YMDHMS2_FORMAT.format(new Date()); @@ -334,39 +251,27 @@ fileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"); String dispose = inline ? "inline" : "attachment"; - // 璁剧疆鍝嶅簲澶翠腑鏂囦欢鐨勪笅杞芥柟寮忎负闄勪欢鏂瑰紡锛屼互鍙婅缃枃浠跺悕 res.setHeader("Content-Disposition", dispose + "; filename*=UTF-8''" + fileName); - // 璁剧疆鍝嶅簲澶寸殑缂栫爜鏍煎紡涓� UTF-8 res.setCharacterEncoding("UTF-8"); - // 閫氳繃response瀵硅薄璁剧疆鍝嶅簲鏁版嵁鏍煎紡(濡傦細"text/plain; charset=utf-8") String ext = FileHelper.getExtension(file); String mime = FileHelper.getMime(ext); res.setContentType(mime); - // 閫氳繃response瀵硅薄锛岃幏鍙栧埌杈撳嚭娴� ServletOutputStream outputStream = res.getOutputStream(); - // 瀹氫箟杈撳叆娴侊紝閫氳繃杈撳叆娴佽鍙栨枃浠跺唴瀹� FileInputStream fileInputStream = new FileInputStream(file); int len = 0; byte[] bytes = new byte[1024]; while ((len = fileInputStream.read(bytes)) != -1) { - // 閫氳繃杈撳叆娴佽鍙栨枃浠舵暟鎹紝鐒跺悗閫氳繃涓婅堪鐨勮緭鍑烘祦鍐欏洖娴忚鍣� outputStream.write(bytes, 0, len); outputStream.flush(); } - // 鍏抽棴璧勬簮 fileInputStream.close(); outputStream.close(); } - /** - * 鎵ц鍛戒护 - * - * @param cmd 鍛戒护 - */ public static void exec(String cmd) { try { Process process = Runtime.getRuntime().exec(cmd); @@ -376,13 +281,6 @@ } } - /** - * 鑾峰彇璇锋眰鐨勫弬鏁板�� - * - * @param req 璇锋眰 - * @param key 鍙傛暟鍚� - * @return 鍙傛暟鍊� - */ public static String getReqParamVal(HttpServletRequest req, String key) { Map<String, String[]> maps = req.getParameterMap(); for (Map.Entry<String, String[]> entry : maps.entrySet()) { @@ -394,13 +292,6 @@ return null; } - /** - * 鑾峰彇璇锋眰鐨勫弬鏁板�� - * - * @param req 璇锋眰 - * @param key 鍙傛暟鍚� - * @return 鍙傛暟鍊� - */ public static String[] getReqParamVals(HttpServletRequest req, String key) { Map<String, String[]> maps = req.getParameterMap(); for (Map.Entry<String, String[]> entry : maps.entrySet()) { -- Gitblit v1.9.3