From 78b3206f65a315e337973cfc3546bec972ef6da1 Mon Sep 17 00:00:00 2001 From: hello-hao <923453645@qq.com> Date: Mon, 29 Nov 2021 11:27:26 +0800 Subject: [PATCH] :ambulance: --- .../cn/hellohao/config/GlobalConstant.java | 13 ++++ .../cn/hellohao/config/WebImgConfigurer.java | 2 +- .../java/cn/hellohao/pojo/FixedResources.java | 12 ---- .../hellohao/service/impl/FTPImageupload.java | 1 - src/main/java/cn/hellohao/utils/DeleImg.java | 59 ------------------- src/main/java/cn/hellohao/utils/FirstRun.java | 23 ++++++-- .../java/cn/hellohao/utils/LocUpdateImg.java | 5 +- src/main/resources/application.properties | 6 +- 8 files changed, 39 insertions(+), 82 deletions(-) create mode 100644 src/main/java/cn/hellohao/config/GlobalConstant.java delete mode 100644 src/main/java/cn/hellohao/pojo/FixedResources.java delete mode 100644 src/main/java/cn/hellohao/utils/DeleImg.java diff --git a/src/main/java/cn/hellohao/config/GlobalConstant.java b/src/main/java/cn/hellohao/config/GlobalConstant.java new file mode 100644 index 0000000..183e285 --- /dev/null +++ b/src/main/java/cn/hellohao/config/GlobalConstant.java @@ -0,0 +1,13 @@ +package cn.hellohao.config; + +import java.io.File; + +/** + * @author Hellohao + * @version 1.0 + * @date 29/11/2021 上午 10:35 + */ +public class GlobalConstant { + public static String SYSTYPE = "LINUX"; + public static String LOCPATH = File.separator + "HellohaoData"; +} diff --git a/src/main/java/cn/hellohao/config/WebImgConfigurer.java b/src/main/java/cn/hellohao/config/WebImgConfigurer.java index 7c87a40..b3d1f7c 100644 --- a/src/main/java/cn/hellohao/config/WebImgConfigurer.java +++ b/src/main/java/cn/hellohao/config/WebImgConfigurer.java @@ -12,7 +12,7 @@ public class WebImgConfigurer implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - String filePath = File.separator + "HellohaoData" + File.separator; + String filePath = GlobalConstant.LOCPATH + File.separator; registry.addResourceHandler("/ota/**").addResourceLocations("file:"+filePath); } diff --git a/src/main/java/cn/hellohao/pojo/FixedResources.java b/src/main/java/cn/hellohao/pojo/FixedResources.java deleted file mode 100644 index 0a4f4ce..0000000 --- a/src/main/java/cn/hellohao/pojo/FixedResources.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.hellohao.pojo; - -import java.io.File; - -/** - * @author Hellohao - * @version 1.0 - * @date 2020-04-04 2:12 - */ -public class FixedResources { - public static final String LOCPATH = File.separator + "HellohaoData"; -} diff --git a/src/main/java/cn/hellohao/service/impl/FTPImageupload.java b/src/main/java/cn/hellohao/service/impl/FTPImageupload.java index 840fd55..e110bb4 100644 --- a/src/main/java/cn/hellohao/service/impl/FTPImageupload.java +++ b/src/main/java/cn/hellohao/service/impl/FTPImageupload.java @@ -22,7 +22,6 @@ public class FTPImageupload { public ReturnImage ImageuploadFTP(Map fileMap, String username,Integer keyID) { ReturnImage returnImage = new ReturnImage(); - Keys key = null; String[] host = key.getEndpoint().split("\\:"); String h = host[0]; Integer p = Integer.parseInt(host[1]); diff --git a/src/main/java/cn/hellohao/utils/DeleImg.java b/src/main/java/cn/hellohao/utils/DeleImg.java deleted file mode 100644 index a7c779b..0000000 --- a/src/main/java/cn/hellohao/utils/DeleImg.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.hellohao.utils; - - -import java.io.*; - -public class DeleImg { - public static void charu(String imgUrlText) { - String filePath =File.separator + "HellohaoData" ; - File file = new File(filePath); - File file1 = new File(filePath+File.separator+"img.ini"); - if(!file.exists()){ - file.mkdirs(); - } - if(!file1.exists()){ - try { - file1.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - FileWriter fw = null; - try { - //如果文件存在,则追加内容;如果文件不存在,则创建文件 - fw = new FileWriter(file1, true); - } catch (IOException e) { - e.printStackTrace(); - } - PrintWriter pw = new PrintWriter(fw); - pw.println(imgUrlText); - pw.flush(); - try { - fw.flush(); - pw.close(); - fw.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - // 读取文件内容 - public static String readFile(String path) {//路径 - File file = new File(path); - StringBuilder result = new StringBuilder(); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));//构造一个BufferedReader类来读取文件 - String s = null; - while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行 - result.append(System.lineSeparator() + s); - Print.Normal( s); - } - br.close(); - } catch (Exception e) { - e.printStackTrace(); - } - return result.toString(); - } - -} diff --git a/src/main/java/cn/hellohao/utils/FirstRun.java b/src/main/java/cn/hellohao/utils/FirstRun.java index b7b10c9..65c5424 100644 --- a/src/main/java/cn/hellohao/utils/FirstRun.java +++ b/src/main/java/cn/hellohao/utils/FirstRun.java @@ -1,5 +1,6 @@ package cn.hellohao.utils; +import cn.hellohao.config.GlobalConstant; import org.omg.CORBA.Environment; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; @@ -8,6 +9,7 @@ import org.springframework.context.annotation.Configuration; import java.io.File; import java.sql.SQLException; +import java.util.Properties; import java.util.UUID; /** @@ -28,7 +30,8 @@ public class FirstRun implements InitializingBean { private String jdbcurl; @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { + isWindows(); RunSqlScript.USERNAME = jdbcusername; RunSqlScript.PASSWORD = jdbcpass; RunSqlScript.DBURL = jdbcurl; @@ -95,6 +98,8 @@ public class FirstRun implements InitializingBean { RunSqlScript.RunInsert(inddx_md5key); RunSqlScript.RunInsert("UPDATE `keys` SET `Endpoint` = '0' WHERE `id` = 8"); Print.Normal("Stage success"); + + clears(); } //检查表是否存在,后边加'imgdata' and column_name = 'explains' 检查字段是否存在 @@ -124,11 +129,11 @@ public class FirstRun implements InitializingBean { private String compressed = "alter table imgdata row_format=compressed"; private void clears(){ - File file1 = new File(File.separator+"HellohaoData"+File.separator+"hellohaotempimg"); - File file2 = new File(File.separator+"HellohaoData"+File.separator+"hellohaotempwatermarimg"); + File file1 = new File(GlobalConstant.LOCPATH+File.separator+"hellohaotempimg"); + File file2 = new File(GlobalConstant.LOCPATH+File.separator+"hellohaotempwatermarimg"); //判断目录有没有创建 - File file = new File(File.separator+"HellohaoData"); + File file = new File(GlobalConstant.LOCPATH); if(!file.exists()){ file.mkdirs(); file1.mkdirs(); @@ -143,4 +148,14 @@ public class FirstRun implements InitializingBean { } + public boolean isWindows() { + System.out.println("当前系统类型:"+System.getProperties().getProperty("os.name").toUpperCase()); + if(System.getProperties().getProperty("os.name").toUpperCase().contains("MAC")){ + GlobalConstant.SYSTYPE = "MAC"; + Properties props=System.getProperties(); + GlobalConstant.LOCPATH = props.getProperty("user.home")+File.separator+".HellohaoData"; + } + return System.getProperties().getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1; + } + } diff --git a/src/main/java/cn/hellohao/utils/LocUpdateImg.java b/src/main/java/cn/hellohao/utils/LocUpdateImg.java index 54bb493..dd4c1d6 100644 --- a/src/main/java/cn/hellohao/utils/LocUpdateImg.java +++ b/src/main/java/cn/hellohao/utils/LocUpdateImg.java @@ -1,5 +1,6 @@ package cn.hellohao.utils; +import cn.hellohao.config.GlobalConstant; import cn.hellohao.pojo.Keys; import cn.hellohao.pojo.ReturnImage; import cn.hellohao.pojo.UploadConfig; @@ -16,7 +17,7 @@ public class LocUpdateImg { public static boolean deleteLOCImg(String imagename){ boolean isDele = false; try { - String filePath =File.separator + "HellohaoData" + File.separator+imagename; + String filePath = GlobalConstant.LOCPATH + File.separator+imagename; File file = new File(filePath); isDele = file.delete(); }catch (Exception e){ @@ -30,7 +31,7 @@ public class LocUpdateImg { KeysServiceImpl keysService = SpringContextHolder.getBean(KeysServiceImpl.class); final Keys key = keysService.selectKeys(keyID); ReturnImage returnImage = new ReturnImage(); - String filePath =File.separator + "HellohaoData" + File.separator; + String filePath =GlobalConstant.LOCPATH + File.separator; File file = null; for (Map.Entry entry : fileMap.entrySet()) { String ShortUID = SetText.getShortUuid(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fd3b593..7fe8d64 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,12 +7,12 @@ spring.datasource.url=jdbc:mysql://localhost:3306/tbed?useUnicode=true&character #端口 server.port=8089 #前端域名需要带协议头http(s):// -CROS_ALLOWED_ORIGINS=http://localhost:8080 +CROS_ALLOWED_ORIGINS=http://127.0.0.1:8080 #下边的配置项不需要修改。 -logging.config=classpath:logback-spring.xml -logging.file.path=/HellohaoData/tbedlog +#logging.config=classpath:logback-spring.xml +#logging.file.path=/HellohaoData/tbedlog spring.thymeleaf.suffix=.html mybatis.configuration.map-underscore-to-camel-case=true mybatis.mapper-locations=classpath:mapper/*.xml