Pārlūkot izejas kodu

refactor 补充常量,修正对应枚举类

黎有为 1 gadu atpakaļ
vecāks
revīzija
de41e2ce94

+ 4 - 3
base-boot/pom.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <artifactId>citygis-boot</artifactId>
@@ -65,4 +66,4 @@
         </plugins>
     </build>
 
-</project>
+</project>

+ 82 - 0
common-boot/src/main/java/com/citygis/common/boot/constant/constant.java

@@ -0,0 +1,82 @@
+package com.citygis.common.boot.constant;
+
+public interface constant {
+    interface STRING {
+        String COMMA = ",";
+        String PERIOD = ".";
+        String EXCLAMATION = "!";
+        String QUERY = "?";
+        String COMMA_ZH = ",";
+        String PERIOD_ZH = "。";
+        String EXCLAMATION_ZH = "!";
+        String QUERY_ZH = "?";
+    }
+
+    interface DATE {
+        /**
+         * 默认时间格式
+         */
+        String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss.ff";
+        /**
+         * timestamp格式
+         */
+        String TIMESTAMP_FORMAT = "yyyy-MM-dd HH24:MI:ss.ff";
+        /**
+         * 简易时间格式
+         */
+        String SIMPLE_DATE_FORMAT = "yyyyMMddHHmmss";
+    }
+
+    interface DIRECTORY {
+        String IS_NOT_VALID_DIRECTORY = "不是一个有效目录%n";
+        String IS_NOT_EXIST = "路径不存在%n";
+        String DIRECTORY_CLEAN_FAIL = "文件[{}]清理失败,也许正在被占用。";
+    }
+
+    interface ENUM {
+        String VALUE_NOT_BE_NULL = "value值不能为空。";
+        String CLASS_NOT_BE_ENUM_OBJECT = "不是一个有效的枚举对象。";
+        String CLASS_NOT_BE_ENUM = "不是一个有效枚举类型";
+        String NO_MATCH_ENUM_OBJECT = "当前枚举类没有枚举对象。";
+    }
+
+    interface FILE {
+        String PATH_NOT_EXIST_OR_INVALID = "路径:[{}] 不存在或不是一个有效文件。";
+    }
+
+    interface NET_ASSIST {
+        String IP_HEADER = "X-Forwarded-For";
+        String PROXY_CLIENT_IP_HEADER = "Proxy-Client-IP";
+        String WL_PROXY_CLIENT_IP_HEADER = "WL-Proxy-Client-IP";
+        String HTTP_CLIENT_IP_HEADER = "HTTP_CLIENT_IP";
+        String HTTP_X_FORWARDED_FOR_HEADER = "HTTP_X_FORWARDED_FOR";
+        String UNKNOWN = "unknown";
+        String WECHAT_BUILT_IN_BROWSER = "micromessenger";
+        String[] MOBILE_AGENTS = { "iphone", "android", "phone", "mobile", "wap", "netfront", "java", "opera mobi",
+                "opera mini", "ucweb",
+                "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod", "nokia", "samsung",
+                "palmsource", "xda", "pieplus",
+                "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio",
+                "hosin", "huawei", "novarra",
+                "coolpad", "webos", "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson",
+                "philips", "sagem", "wellcom",
+                "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee",
+                "portalmmm", "jig browser",
+                "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca",
+                "amoi", "audi", "avan", "benq",
+                "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq",
+                "java", "jigs", "kddi", "keji", "leno",
+                "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp",
+                "nec-", "newt", "noki", "oper",
+                "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-",
+                "send", "seri", "sgh-", "shar", "sie-",
+                "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tsm-", "upg1", "upsi", "vk-v",
+                "voda", "wap-", "wapa", "wapi", "wapp",
+                "wapr", "webc", "winw", "winw", "xda", "xda-", "googlebot-mobile" };
+    }
+
+    interface PATH {
+        String PATH_NOT_EXIST = "路径{}不存在%n";
+        String PATH_NOT_VALID_FILE = "路径{}不是一个有效文件%n";
+    }
+}

+ 4 - 11
common-boot/src/main/java/com/citygis/common/boot/util/DateUtil.java

@@ -3,6 +3,8 @@ package com.citygis.common.boot.util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.citygis.common.boot.constant.constant;
+
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
@@ -14,15 +16,6 @@ import java.util.Date;
 public final class DateUtil {
     private static final Logger LOG = LoggerFactory.getLogger(DateUtil.class);
 
-    /**
-     * 默认时间格式
-     */
-    public static String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss.ff";
-    /**
-     * timestamp格式
-     */
-    public static String TIMESTAMP_FORMAT = "yyyy-MM-dd HH24:MI:ss.ff";
-
     /**
      * 获取当前服务器毫秒时间
      *
@@ -40,7 +33,7 @@ public final class DateUtil {
     public static String currentTime() {
         Date now = new Date();
         // 格式化
-        SimpleDateFormat sim = new SimpleDateFormat("yyyyMMddHHmmss");
+        SimpleDateFormat sim = new SimpleDateFormat(constant.DATE.SIMPLE_DATE_FORMAT);
         return sim.format(now);
     }
 
@@ -52,7 +45,7 @@ public final class DateUtil {
      */
     public static Date parseDate(String str) {
         try {
-            return new SimpleDateFormat(DEFAULT_FORMAT).parse(str);
+            return new SimpleDateFormat(constant.DATE.DEFAULT_FORMAT).parse(str);
         } catch (ParseException e) {
             LOG.error(e.getMessage(), e);
             return null;

+ 26 - 22
common-boot/src/main/java/com/citygis/common/boot/util/DirectoryUtil.java

@@ -1,12 +1,14 @@
 package com.citygis.common.boot.util;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.File;
 import java.util.List;
 import java.util.Objects;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.citygis.common.boot.constant.constant;
+
 /**
  * 目录工具类
  */
@@ -40,11 +42,11 @@ public final class DirectoryUtil {
             if (file.isDirectory()) {
                 return true;
             } else {
-                System.err.printf("[%s] 不是一个有效目录%n", dir);
+                LOG.error(dir + constant.DIRECTORY.IS_NOT_VALID_DIRECTORY);
                 return false;
             }
         }
-        System.err.printf("[%s] 路径不存在%n", dir);
+        LOG.error(dir + constant.DIRECTORY.IS_NOT_EXIST);
         return false;
     }
 
@@ -79,11 +81,11 @@ public final class DirectoryUtil {
     public static void deleteSubDirAndFiles(String rootDir, boolean deleteRoot) {
         File file = new File(rootDir);
         if (!file.exists()) {
-            System.out.printf("%s 目录不存在%n", rootDir);
+            LOG.info(rootDir + constant.DIRECTORY.IS_NOT_EXIST);
             return;
         }
         if (!file.isDirectory()) {
-            System.out.printf("%s 不是一个目录%n", rootDir);
+            LOG.info(rootDir + constant.DIRECTORY.IS_NOT_VALID_DIRECTORY);
             return;
         }
         if (deleteRoot) {
@@ -112,7 +114,7 @@ public final class DirectoryUtil {
             }
         }
         if (!file.delete()) {
-            LOG.warn("文件[{}]清理失败,也许正在被占用。", file.getAbsolutePath());
+            LOG.warn(constant.DIRECTORY.DIRECTORY_CLEAN_FAIL, file.getAbsolutePath());
         }
     }
 
@@ -125,11 +127,11 @@ public final class DirectoryUtil {
     public static File[] getFiles(String directory) {
         File file = new File(directory);
         if (!file.exists()) {
-            System.err.printf("[%s]目录不存在%n", directory);
+            LOG.error(directory + constant.DIRECTORY.IS_NOT_EXIST);
             return null;
         }
         if (!file.isDirectory()) {
-            return new File[]{file};
+            return new File[] { file };
         }
         return file.listFiles();
     }
@@ -144,11 +146,11 @@ public final class DirectoryUtil {
     public static File[] getFiles(String directory, String suffix) {
         File file = new File(directory);
         if (!file.exists()) {
-            System.err.printf("[%s]目录不存在%n", directory);
+            LOG.error(directory + constant.DIRECTORY.IS_NOT_EXIST);
             return null;
         }
         if (!file.isDirectory()) {
-            return new File[]{file};
+            return new File[] { file };
         }
         return file.listFiles((dir, name) -> name.toLowerCase().endsWith(suffix.toLowerCase()));
     }
@@ -163,11 +165,11 @@ public final class DirectoryUtil {
     public static File[] getFiles(String directory, List<String> suffixes) {
         File file = new File(directory);
         if (!file.exists()) {
-            System.err.printf("[%s]目录不存在%n", directory);
+            LOG.error(directory + constant.DIRECTORY.IS_NOT_EXIST);
             return null;
         }
         if (!file.isDirectory()) {
-            return new File[]{file};
+            return new File[] { file };
         }
         return file.listFiles((dir, name) -> suffixes.contains(PathUtil.getExtension(name, true)));
     }
@@ -176,18 +178,19 @@ public final class DirectoryUtil {
      * 通过正则表达式检索匹配文件集合
      *
      * @param directory 目录
-     * @param regex     正则表达式,the regular expression to which this string is to be matched。
+     * @param regex     正则表达式,the regular expression to which this string is to be
+     *                  matched。
      *                  例如:检索后缀为.zip和.rar,则输入:.*(.zip|.rar)
      * @return 文件集合
      */
     public static File[] getFilesByRegex(String directory, String regex) {
         File file = new File(directory);
         if (!file.exists()) {
-            System.err.printf("[%s]目录不存在%n", directory);
+            LOG.error(directory + constant.DIRECTORY.IS_NOT_EXIST);
             return null;
         }
         if (!file.isDirectory()) {
-            return new File[]{file};
+            return new File[] { file };
         }
         return file.listFiles((dir, name) -> name.matches(regex));
     }
@@ -196,18 +199,19 @@ public final class DirectoryUtil {
      * 获取文件路径列表
      *
      * @param directory 目录
-     * @param regex     正则表达式,the regular expression to which this string is to be matched。
+     * @param regex     正则表达式,the regular expression to which this string is to be
+     *                  matched。
      *                  例如:检索后缀为.zip和.rar,则输入:.*(.zip|.rar)
      * @return 文件路径列表
      */
     public static String[] getFilesPathByRegex(String directory, String regex) {
         File file = new File(directory);
         if (!file.exists()) {
-            System.err.printf("[%s]目录不存在%n", directory);
+            LOG.error(directory + constant.DIRECTORY.IS_NOT_EXIST);
             return null;
         }
         if (!file.isDirectory()) {
-            return new String[]{file.getAbsolutePath()};
+            return new String[] { file.getAbsolutePath() };
         }
         return file.list((dir, name) -> name.matches(regex));
     }
@@ -223,7 +227,7 @@ public final class DirectoryUtil {
         if (file.exists()) {
             return file.getParentFile();
         }
-        LOG.warn(String.format("路径[%s]不存在。", path));
+        LOG.warn(path + constant.DIRECTORY.IS_NOT_EXIST);
         return null;
     }
 
@@ -238,7 +242,7 @@ public final class DirectoryUtil {
         if (file.exists()) {
             return file.getParent();
         }
-        LOG.warn(String.format("路径[%s]不存在。", path));
+        LOG.warn(path + constant.DIRECTORY.IS_NOT_EXIST);
         return null;
     }
 }

+ 18 - 13
common-boot/src/main/java/com/citygis/common/boot/util/EnumUtil.java

@@ -1,18 +1,23 @@
 package com.citygis.common.boot.util;
 
-import com.citygis.common.boot.enums.SystemStatusCodeEnum;
-import com.citygis.common.boot.exception.BusinessException;
-
 import java.util.Arrays;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Predicate;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.citygis.common.boot.constant.constant;
+import com.citygis.common.boot.enums.SystemStatusCodeEnum;
+import com.citygis.common.boot.exception.BusinessException;
+
 /**
  * 枚举工具类
  */
 public final class EnumUtil {
+    private final static Logger LOG = LoggerFactory.getLogger(EnumUtil.class);
 
     /**
      * 判断值是否是枚举有效值
@@ -24,15 +29,15 @@ public final class EnumUtil {
     public static <T> boolean isDefined(Class<T> clz, Object value) {
         if (null == value) {
             throw new BusinessException(
-                    SystemStatusCodeEnum.ERROR, "value值不能为空。");
+                    SystemStatusCodeEnum.ERROR, constant.ENUM.VALUE_NOT_BE_NULL);
         }
         if (!clz.isEnum()) {
             throw new BusinessException(
-                    SystemStatusCodeEnum.ERROR, "clz不是一个有效的枚举对象。");
+                    SystemStatusCodeEnum.ERROR, constant.ENUM.CLASS_NOT_BE_ENUM_OBJECT);
         }
         T[] objects = clz.getEnumConstants();
         if (null == objects) {
-            System.out.println("当前枚举类没有枚举对象。");
+            LOG.info(constant.ENUM.NO_MATCH_ENUM_OBJECT);
             return false;
         }
         for (T sub : objects) {
@@ -46,17 +51,17 @@ public final class EnumUtil {
     /**
      * 根据枚举名称判断是否是一个指定类型的有效枚举对象
      *
-     * @param clz 类型
+     * @param clz  类型
      * @param name 枚举名称
      * @return 是否是一个指定类型的有效枚举对象
      */
     public static <T> boolean isDefinedByName(Class<T> clz, String name) {
         if (!clz.isEnum()) {
-            throw new BusinessException(SystemStatusCodeEnum.ERROR, "clz不是一个有效的枚举对象。");
+            throw new BusinessException(SystemStatusCodeEnum.ERROR, constant.ENUM.CLASS_NOT_BE_ENUM_OBJECT);
         }
         T[] objects = clz.getEnumConstants();
         if (null == objects) {
-            System.out.println("当前枚举类没有枚举对象。");
+            LOG.info(constant.ENUM.NO_MATCH_ENUM_OBJECT);
             return false;
         }
         for (T sub : objects) {
@@ -76,7 +81,7 @@ public final class EnumUtil {
      */
     public static <T extends Enum<T>> T getEnumObjByName(Class<T> type, String name) {
         if (!type.isEnum()) {
-            throw new BusinessException(SystemStatusCodeEnum.ERROR, "不是一个有效枚举类型");
+            throw new BusinessException(SystemStatusCodeEnum.ERROR, constant.ENUM.CLASS_NOT_BE_ENUM);
         }
         return Enum.valueOf(type, name);
     }
@@ -84,13 +89,13 @@ public final class EnumUtil {
     /**
      * 根据枚举值获取枚举对象
      *
-     * @param type 类型
+     * @param type  类型
      * @param value 枚举值
      * @return 枚举对象
      */
     public static <T extends Enum<T>> T getEnumObjByValue(Class<T> type, int value) {
         if (!type.isEnum()) {
-            throw new BusinessException(SystemStatusCodeEnum.ERROR, "不是一个有效枚举类型");
+            throw new BusinessException(SystemStatusCodeEnum.ERROR, constant.ENUM.CLASS_NOT_BE_ENUM);
         }
         return getEnumObject(type, e -> e.ordinal() == value);
     }
@@ -104,7 +109,7 @@ public final class EnumUtil {
      */
     public static <T extends Enum<T>> T getEnumObject(Class<T> type, Predicate<T> predicate) {
         if (!type.isEnum()) {
-            throw new BusinessException(SystemStatusCodeEnum.ERROR, "不是一个有效枚举类型");
+            throw new BusinessException(SystemStatusCodeEnum.ERROR, constant.ENUM.CLASS_NOT_BE_ENUM);
         }
         Map<Class<T>, Object> map = new ConcurrentHashMap<>();
         Object obj = map.get(type);

+ 13 - 5
common-boot/src/main/java/com/citygis/common/boot/util/FileUtil.java

@@ -1,15 +1,23 @@
 package com.citygis.common.boot.util;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
 import java.nio.channels.FileChannel;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.util.Objects;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.citygis.common.boot.constant.constant;
+
 /**
  * 文件工具类
  */
@@ -122,7 +130,7 @@ public final class FileUtil {
         if (file.exists() && file.isFile()) {
             return file.length();
         }
-        System.out.println("路径:[" + filePath + "] 不存在或不是一个有效文件。");
+        LOG.info(constant.FILE.PATH_NOT_EXIST_OR_INVALID, filePath);
         return 0L;
     }
 

+ 24 - 32
common-boot/src/main/java/com/citygis/common/boot/util/NetAssist.java

@@ -1,13 +1,16 @@
 package com.citygis.common.boot.util;
 
-import com.citygis.common.boot.define.HttpHeaderNames;
-import com.citygis.common.boot.enums.UserAgentTypeEnum;
-import jakarta.servlet.http.HttpServletRequest;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
+import com.citygis.common.boot.constant.constant;
+import com.citygis.common.boot.define.HttpHeaderNames;
+import com.citygis.common.boot.enums.UserAgentTypeEnum;
+
+import jakarta.servlet.http.HttpServletRequest;
 
 /**
  * net帮助类
@@ -27,7 +30,7 @@ public final class NetAssist {
         } catch (UnknownHostException e) {
             LOG.error(e.getMessage(), e);
         }
-        return "";
+        return StringUtil.EMPTY;
     }
 
     /**
@@ -41,23 +44,12 @@ public final class NetAssist {
             return UserAgentTypeEnum.UNKNOWN;
         }
         userAgent = userAgent.toLowerCase();
-        String[] mobileAgents = {"iphone", "android", "phone", "mobile", "wap", "netfront", "java", "opera mobi", "opera mini", "ucweb",
-                "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod", "nokia", "samsung", "palmsource", "xda", "pieplus",
-                "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra",
-                "coolpad", "webos", "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem", "wellcom",
-                "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee", "portalmmm", "jig browser",
-                "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq",
-                "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno",
-                "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper",
-                "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-",
-                "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp",
-                "wapr", "webc", "winw", "winw", "xda", "xda-", "googlebot-mobile"};
-        for (String mobileAgent : mobileAgents) {
+        for (String mobileAgent : constant.NET_ASSIST.MOBILE_AGENTS) {
             if (userAgent.toLowerCase().contains(mobileAgent)) {
                 return UserAgentTypeEnum.MOBILE;
             }
         }
-        if (userAgent.indexOf("micromessenger") > 0) {
+        if (userAgent.indexOf(constant.NET_ASSIST.WECHAT_BUILT_IN_BROWSER) > 0) {
             return UserAgentTypeEnum.WECHAT;
         }
         return UserAgentTypeEnum.BROWSER;
@@ -70,27 +62,27 @@ public final class NetAssist {
      * @return 主机IP地址
      */
     public static String getClientIpAddress(HttpServletRequest request) {
-        String ip = request.getHeader("X-Forwarded-For");
-        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-                ip = request.getHeader("Proxy-Client-IP");
+        String ip = request.getHeader(constant.NET_ASSIST.IP_HEADER);
+        if (ip == null || ip.length() == 0 || constant.NET_ASSIST.UNKNOWN.equalsIgnoreCase(ip)) {
+            if (ip == null || ip.length() == 0 || constant.NET_ASSIST.UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader(constant.NET_ASSIST.PROXY_CLIENT_IP_HEADER);
             }
-            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-                ip = request.getHeader("WL-Proxy-Client-IP");
+            if (ip == null || ip.length() == 0 || constant.NET_ASSIST.UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader(constant.NET_ASSIST.WL_PROXY_CLIENT_IP_HEADER);
             }
-            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-                ip = request.getHeader("HTTP_CLIENT_IP");
+            if (ip == null || ip.length() == 0 || constant.NET_ASSIST.UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader(constant.NET_ASSIST.HTTP_CLIENT_IP_HEADER);
             }
-            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-                ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+            if (ip == null || ip.length() == 0 || constant.NET_ASSIST.UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader(constant.NET_ASSIST.HTTP_X_FORWARDED_FOR_HEADER);
             }
-            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            if (ip == null || ip.length() == 0 || constant.NET_ASSIST.UNKNOWN.equalsIgnoreCase(ip)) {
                 ip = request.getRemoteAddr();
             }
         } else if (ip.length() > 15) {
-            String[] ips = ip.split(",");
+            String[] ips = ip.split(constant.STRING.COMMA);
             for (String s : ips) {
-                if (!("unknown".equalsIgnoreCase(s))) {
+                if (!(constant.NET_ASSIST.UNKNOWN.equalsIgnoreCase(s))) {
                     ip = s;
                     break;
                 }

+ 17 - 11
common-boot/src/main/java/com/citygis/common/boot/util/PathUtil.java

@@ -3,10 +3,16 @@ package com.citygis.common.boot.util;
 import java.io.File;
 import java.nio.file.Paths;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.citygis.common.boot.constant.constant;
+
 /**
  * 路径工具类
  */
 public final class PathUtil {
+    private final static Logger LOG = LoggerFactory.getLogger(PathUtil.class);
 
     /**
      * 组合路径
@@ -38,7 +44,7 @@ public final class PathUtil {
             // 如果是文件,则返回所在目录文件夹的名称
             return file.getParentFile().getName();
         }
-        return "";
+        return StringUtil.EMPTY;
     }
 
     /**
@@ -55,7 +61,7 @@ public final class PathUtil {
             }
             return file.getParent();
         }
-        return "";
+        return StringUtil.EMPTY;
     }
 
     /**
@@ -68,18 +74,18 @@ public final class PathUtil {
     public static String getExtension(String filePath, boolean haveDot) {
         File file = new File(filePath);
         if (!file.exists()) {
-            System.err.printf("路径[%s]不存在%n", filePath);
-            return "";
+            LOG.error(constant.PATH.PATH_NOT_EXIST, filePath);
+            return StringUtil.EMPTY;
         }
         if (file.isDirectory()) {
-            System.err.printf("路径[%s]不是一个有效文件%n", filePath);
-            return "";
+            LOG.error(constant.PATH.PATH_NOT_VALID_FILE, filePath);
+            return StringUtil.EMPTY;
         }
         String fileName = file.getName();
         if (haveDot) {
-            return fileName.substring(fileName.lastIndexOf("."));
+            return fileName.substring(fileName.lastIndexOf(constant.STRING.PERIOD));
         }
-        return fileName.substring(fileName.lastIndexOf(".") + 1);
+        return fileName.substring(fileName.lastIndexOf(constant.STRING.PERIOD) + 1);
     }
 
     /**
@@ -93,7 +99,7 @@ public final class PathUtil {
         if (file.exists()) {
             return file.getName();
         }
-        return "";
+        return StringUtil.EMPTY;
     }
 
     /**
@@ -105,8 +111,8 @@ public final class PathUtil {
     public static String getFileNameWithoutExtension(String filePath) {
         File file = new File(filePath);
         if (file.exists()) {
-            return file.getName().substring(0, file.getName().lastIndexOf("."));
+            return file.getName().substring(0, file.getName().lastIndexOf(constant.STRING.PERIOD));
         }
-        return "";
+        return StringUtil.EMPTY;
     }
 }

+ 14 - 10
common-boot/src/main/java/com/citygis/common/boot/util/StringUtil.java

@@ -6,6 +6,8 @@ import cn.hutool.core.util.StrUtil;
  * 字符串工具类
  */
 public final class StringUtil {
+    public final static String EMPTY = StringUtil.EMPTY;
+
     /**
      * 判断是否NULL或空字符串
      *
@@ -57,12 +59,13 @@ public final class StringUtil {
         StringBuilder sb = null;
         while (strLen < totalWidth) {
             sb = new StringBuilder();
-            sb.append(str).append(paddingChar);//右补0
+            sb.append(str).append(paddingChar);// 右补0
             str = sb.toString();
             strLen = str.length();
         }
         return str;
     }
+
     /**
      * 不足位往左填充字符
      *
@@ -84,33 +87,35 @@ public final class StringUtil {
     }
 
     /**
-     * 格式化字符串。如果value为null,则返回空字符串"";否则返回value.toString。
+     * 格式化字符串。如果value为null,则返回空字符串StringUtil.EMPTY;否则返回value.toString。
      * 不直接使用String.valueOf
+     * 
      * @param value 字符串
      * @return 格式化结果
      */
     public static String valueOf(Object value) {
         if (null == value) {
-            return "";
+            return StringUtil.EMPTY;
         }
         return value.toString();
     }
 
     /**
      * 截取字符串
+     * 
      * @param startIndex 起始索引号,从0开始
-     * @param length 截取长度
+     * @param length     截取长度
      * @return 截取结果
      */
     public static String substring(String str, int startIndex, int length) {
         if (isNullOrEmpty(str)) {
-            return "";
+            return StringUtil.EMPTY;
         }
         if (startIndex >= str.length()) {
-            return "";
+            return StringUtil.EMPTY;
         }
         if (startIndex + length >= str.length()) {
-            return "";
+            return StringUtil.EMPTY;
         }
         return str.substring(startIndex, startIndex + length);
     }
@@ -119,8 +124,8 @@ public final class StringUtil {
      * 是否以指定字符串结尾(忽略大小写)
      * 如果给定的字符串和开头字符串都为null则返回true,否则任意一个值为null返回false
      *
-     * @param str          被监测字符串
-     * @param suffix       结尾字符串
+     * @param str    被监测字符串
+     * @param suffix 结尾字符串
      * @return 是否以指定字符串结尾
      */
     public static boolean endWithIgnoreCase(String str, String suffix) {
@@ -130,4 +135,3 @@ public final class StringUtil {
         return StrUtil.endWith(str, suffix, true);
     }
 }
-

+ 9 - 4
pom.xml

@@ -1,12 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         <version>3.1.0</version>
-        <relativePath/> <!-- lookup parent from repository -->
+        <relativePath /> <!-- lookup parent from repository -->
     </parent>
 
     <artifactId>citygis-boot</artifactId>
@@ -21,6 +22,10 @@
     </modules>
     <properties>
         <java.version>17</java.version>
+        <maven.test.skip>true</maven.test.skip>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <maven.compiler.release>17</maven.compiler.release>
         <spring-boot.verison>2.7.11</spring-boot.verison>
         <spring-cloud.version>2021.0.4</spring-cloud.version>
         <spring-cloud-alibaba.version>2021.0.4.0</spring-cloud-alibaba.version>
@@ -148,4 +153,4 @@
         </snapshotRepository>
     </distributionManagement>
 
-</project>
+</project>