From f55f0595d878df7eea63257949bd997640aa3bc8 Mon Sep 17 00:00:00 2001 From: little-cat-sweet <851891179@qq.com> Date: Fri, 19 Nov 2021 16:42:25 +0800 Subject: [PATCH] Solving the last bug from downCode. --- .../service/XhpcDownCodeServiceImpl.java | 8 +- .../station/utils/img/DownMaterialUtil.java | 100 +++++++++--------- .../src/main/resources/bootstrap.yml | 2 +- 3 files changed, 56 insertions(+), 54 deletions(-) diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java index 1a186ac8..5cefac05 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java @@ -110,7 +110,8 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"; List imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId); List list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls); - DownMaterialUtil.saveImageToDisk(list1,file2,imgUrls); + System.out.println(list1); + DownMaterialUtil.saveImageToDisk(list1, file2, imgUrls); File file = new File(environment.getProperty("img.url")); //储存路径 long l = System.currentTimeMillis(); @@ -214,6 +215,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { //test // public void downMaterialBy11(Long pileId) throws Exception { // +// // List> list = xhpcDownCodeMapper.selectExcelDataByPileId(pileId); // System.out.println(list); // File file1 = new File("Material"); @@ -268,8 +270,8 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { // fos.close(); // String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"; // List imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId); -// System.out.println(imgUrls); // List list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls); +// System.out.println(list1); // DownMaterialUtil.saveImageToDisk1(list1,file2,imgUrls); // File file = new File(file1.getAbsolutePath()); // DownMaterialUtil.fileToZip(file); @@ -350,8 +352,6 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { // String url=environment.getProperty("img.url")+l; // // DownMaterialUtil.fileToZip(file,url); -// -// return "Material"+l+".zip"; // } static boolean delFile(File file) { diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java index 38726c47..a67f95b0 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java @@ -48,6 +48,7 @@ public class DownMaterialUtil { for(int i = 0; i < urls.size(); i ++) { InputStream inputStream = getInputStream(urls.get(i)); + if (null == inputStream) continue; byte[] data = new byte[1024]; int len = 0; FileOutputStream fileOutputStream = null; @@ -64,7 +65,7 @@ public class DownMaterialUtil { System.out.println(real); System.out.println(file.getName() + "/" + real); fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "/" + real); - + System.out.println(file.getAbsoluteFile()); while ((len = inputStream.read(data)) != -1) { fileOutputStream.write(data, 0, len); } @@ -72,12 +73,10 @@ public class DownMaterialUtil { e.printStackTrace(); } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); } if (fileOutputStream != null) { try { @@ -91,48 +90,51 @@ public class DownMaterialUtil { } } - public static void saveImageToDisk1(List urls, File file, List imgNames) { - - for (int i = 0; i < urls.size(); i++) { - InputStream inputStream = getInputStream(urls.get(i)); - byte[] data = new byte[1024]; - int len = 0; - FileOutputStream fileOutputStream = null; - try { - String str = imgNames.get(i); - int poke = 0; - for (int j = str.length() - 1; j >= 0; j--) { - if (str.charAt(j) == 47) { - poke = j; - break; - } - } - String real = str.substring(poke + 1); - System.out.println(real); - System.out.println(file.getName() + "\\" + real); - fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "\\" + real); - } catch (IOException e) { - e.printStackTrace(); - } finally { - - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (fileOutputStream != null) { - try { - fileOutputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - System.out.println("success"); - } - } - } +// public static void saveImageToDisk1(List urls, File file, List imgNames) { +// +// for (int i = 0; i < urls.size(); i++) { +// InputStream inputStream = getInputStream(urls.get(i)); +// if(null == inputStream) continue; +// System.out.println(inputStream); +// byte[] data = new byte[1024]; +// int len = 0; +// FileOutputStream fileOutputStream = null; +// try { +// String str = imgNames.get(i); +// int poke = 0; +// for (int j = str.length() - 1; j >= 0; j--) { +// if (str.charAt(j) == 47) { +// poke = j; +// break; +// } +// } +// String real = str.substring(poke + 1); +// System.out.println(real); +// System.out.println(file.getName() + "\\" + real); +// fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "\\" + real); +// while ((len = inputStream.read(data)) != -1) { +// fileOutputStream.write(data, 0, len); +// } +// } catch (IOException e) { +// e.printStackTrace(); +// } finally { +// +// try { +// inputStream.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// if (fileOutputStream != null) { +// try { +// fileOutputStream.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// System.out.println("success"); +// } +// } +// } public static void fileToZip(File sourceFile) throws Exception { diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml b/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml index 996b0e32..cb9e520f 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/bootstrap.yml @@ -26,7 +26,7 @@ spring: #二维码Logo图片获取位置: -imgPath: "/www/wwwroot/www.scxhua.cn/xhpc-charging-stion/logo.png" +imgPath: "/www/wwwroot/xhpc.scxhua.com/xhpc-charging-stion/logo.png" #生成的二维码存放位置: destPath: "/www/wwwroot/www.scxhua.cn/xhpc-charging-stion/XiaoHuaFullImgs" #生成的最终完整图片的存放位置: