wuweihao 3 سال پیش
والد
کامیت
a133b05f88

+ 1 - 1
gis_application/src/main/resources/application.properties

@@ -1,4 +1,4 @@
-server.port=8005
+server.port=8015
 
 spring.profiles.active=dev
 

+ 5 - 2
gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
 
 
 /**
@@ -25,9 +26,11 @@ public class FileUtils {
     @Autowired
     ConfigConstant configConstant;
 
+    // 确保同一时间上传文件的唯一性
+    private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger();
+
     public boolean checkFile(MultipartFile file) {
         //设置允许上传文件类型
-//        String suffixList = ".jpg,.gif,.png,.ico,.bmp,.jpeg,.zip,.zp,.rar,.mp3,.mp4,.avi,.mov,.4dage,.wav,.wma,.m4a";
         String suffixList = configConstant.serverFileFallow;
         // 获取文件后缀
         if(file == null){
@@ -68,7 +71,7 @@ public class FileUtils {
              newName = RegexUtil.getPinyinName(fileName);
         } else {
             String suffix = StringUtils.substringAfterLast(fileName, ".");
-            newName = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS") + "." + suffix;
+            newName =  DateUtils.getDateTime() + ATOMIC_INTEGER.incrementAndGet() + "." + suffix;
         }
 
         savePath = configConstant.serverBasePath + savePath + "/" + newName;

+ 123 - 0
startJar.sh

@@ -0,0 +1,123 @@
+APP_NAME=wx_lvdao.jar # 应用名称
+APP_PORT=8015    #应用端口
+
+usage() {
+    echo "case: sh run.sh [start|stop|restart|status]"
+    echo "请类似这样执行 ./*.sh start   or  ./*sh restart"
+    exit 1
+}
+
+checkEnv(){
+      if [ -z "${APP_NAME}" ] || [ -z "${APP_DEBUG}" ]; then #判断pid是否为空
+           if [[ $1 = 'pro' ]];   then
+                        echo "pro start"
+                        #APP_NAME=changeing-prod.jar
+                        #APP_DEBUG=5526
+                      elif  [[ $1 = 'sit' ]] ; then
+                        echo "sit start"
+                        #APP_NAME=changeing-uat.jar
+                        #APP_DEBUG=5520
+                      elif  [[ $1 = 'uat' ]] ; then
+                        echo "uat start"
+                        #APP_NAME=changeing-devuat.jar
+                        #APP_DEBUG=5526
+                      else
+                        echo "没有设置环境"
+            fi
+     # else
+         #    echo "已经设置-${APP_NAME}-${APP_DEBUG}"
+     fi
+}
+
+# 判断当前服务是否已经启动的函数
+is_exist(){
+    checkEnv $1
+    pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' ` #根据ps 命令查询当前服务的进程号 赋值给pid"
+    if [ -z "${pid}" ]; then #判断pid是否为空
+        echo "pid 不存在"
+        return 1
+    else
+        echo "pid 存在"
+        return 0
+    fi
+}
+
+
+start(){
+    checkEnv $1
+    is_exist
+    if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号打印出来
+        echo "${APP_NAME} running. pid=${pid}"
+    else
+        nohup java -jar -Xmx3072M -Xms512M ./$APP_NAME --spring.profiles.active=$1 --server.port=$APP_PORT > logs.log 2>error.log &  # 说明pid为空
+        # 执行java -jar 命令启动服务
+        echo "${APP_NAME} started启动"
+    fi
+}
+
+
+stop(){
+    echo "执行 stop 方法"
+    checkEnv $1
+    is_exist
+    if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号杀死
+        kill -9 $pid
+        echo "${pid} stopped-停止"
+    else
+        echo "${APP_NAME} 没有运行"
+    fi
+}
+
+
+status(){
+    echo "执行 status 方法"
+    checkEnv $1
+    is_exist
+    if [ $? -eq "0" ]; then
+        echo "${APP_NAME} running-启动. Pid is ${pid}"
+    else
+        echo "${APP_NAME} 没有运行"
+    fi
+}
+
+
+# 重启命令其实就是先执行关闭命令 再执行重启命令
+restart(){
+        echo "执行 restart 方法"
+        checkEnv $1
+        is_exist
+        if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号杀死
+            kill -9 $pid
+            echo "${pid} stopped-停止"
+        else
+            echo "${APP_NAME} 没有运行"
+        fi
+        sleep 5
+        is_exist
+        if [ $? -eq "0" ]; then    # [$? -eq "0"] 说明pid不等于空 说明服务正在运行中,将进程号打印出来
+            echo "${APP_NAME} running. pid=${pid}"
+        else
+            nohup java -jar -Xmx3072M -Xms512M ./$APP_NAME --spring.profiles.active=$1 --server.port=$APP_PORT > logs.log 2>error.log &  # 说明pid为空
+            echo "${APP_NAME} started启动"
+        fi
+}
+
+
+# 这里的$1 取的是当前输入命令 的第二个参数 ./start.sh start
+case "$1" in
+    "start")
+        start $2
+        ;;
+    "stop")
+        stop $2
+        ;;
+    "status")
+        status $2
+        ;;
+    "restart")
+        restart $2
+        ;;
+    *)
+    usage
+    ;;
+esac