Solving the last bug from downCode.

This commit is contained in:
little-cat-sweet 2021-11-19 16:42:25 +08:00
parent e26004fd17
commit f55f0595d8
3 changed files with 56 additions and 54 deletions

View File

@ -110,7 +110,8 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"; String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/";
List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId); List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId);
List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls); List<String> 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")); File file = new File(environment.getProperty("img.url"));
//储存路径 //储存路径
long l = System.currentTimeMillis(); long l = System.currentTimeMillis();
@ -214,6 +215,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
//test //test
// public void downMaterialBy11(Long pileId) throws Exception { // public void downMaterialBy11(Long pileId) throws Exception {
// //
//
// List<Map<String,Object>> list = xhpcDownCodeMapper.selectExcelDataByPileId(pileId); // List<Map<String,Object>> list = xhpcDownCodeMapper.selectExcelDataByPileId(pileId);
// System.out.println(list); // System.out.println(list);
// File file1 = new File("Material"); // File file1 = new File("Material");
@ -268,8 +270,8 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
// fos.close(); // fos.close();
// String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"; // String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/";
// List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId); // List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId);
// System.out.println(imgUrls);
// List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls); // List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls);
// System.out.println(list1);
// DownMaterialUtil.saveImageToDisk1(list1,file2,imgUrls); // DownMaterialUtil.saveImageToDisk1(list1,file2,imgUrls);
// File file = new File(file1.getAbsolutePath()); // File file = new File(file1.getAbsolutePath());
// DownMaterialUtil.fileToZip(file); // DownMaterialUtil.fileToZip(file);
@ -350,8 +352,6 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
// String url=environment.getProperty("img.url")+l; // String url=environment.getProperty("img.url")+l;
// //
// DownMaterialUtil.fileToZip(file,url); // DownMaterialUtil.fileToZip(file,url);
//
// return "Material"+l+".zip";
// } // }
static boolean delFile(File file) { static boolean delFile(File file) {

View File

@ -48,6 +48,7 @@ public class DownMaterialUtil {
for(int i = 0; i < urls.size(); i ++) { for(int i = 0; i < urls.size(); i ++) {
InputStream inputStream = getInputStream(urls.get(i)); InputStream inputStream = getInputStream(urls.get(i));
if (null == inputStream) continue;
byte[] data = new byte[1024]; byte[] data = new byte[1024];
int len = 0; int len = 0;
FileOutputStream fileOutputStream = null; FileOutputStream fileOutputStream = null;
@ -64,7 +65,7 @@ public class DownMaterialUtil {
System.out.println(real); System.out.println(real);
System.out.println(file.getName() + "/" + real); System.out.println(file.getName() + "/" + real);
fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "/" + real); fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "/" + real);
System.out.println(file.getAbsoluteFile());
while ((len = inputStream.read(data)) != -1) { while ((len = inputStream.read(data)) != -1) {
fileOutputStream.write(data, 0, len); fileOutputStream.write(data, 0, len);
} }
@ -72,13 +73,11 @@ public class DownMaterialUtil {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (inputStream != null) {
try { try {
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
}
if (fileOutputStream != null) { if (fileOutputStream != null) {
try { try {
fileOutputStream.close(); fileOutputStream.close();
@ -91,48 +90,51 @@ public class DownMaterialUtil {
} }
} }
public static void saveImageToDisk1(List<String> urls, File file, List<String> imgNames) { // public static void saveImageToDisk1(List<String> urls, File file, List<String> imgNames) {
//
for (int i = 0; i < urls.size(); i++) { // for (int i = 0; i < urls.size(); i++) {
InputStream inputStream = getInputStream(urls.get(i)); // InputStream inputStream = getInputStream(urls.get(i));
byte[] data = new byte[1024]; // if(null == inputStream) continue;
int len = 0; // System.out.println(inputStream);
FileOutputStream fileOutputStream = null; // byte[] data = new byte[1024];
try { // int len = 0;
String str = imgNames.get(i); // FileOutputStream fileOutputStream = null;
int poke = 0; // try {
for (int j = str.length() - 1; j >= 0; j--) { // String str = imgNames.get(i);
if (str.charAt(j) == 47) { // int poke = 0;
poke = j; // for (int j = str.length() - 1; j >= 0; j--) {
break; // if (str.charAt(j) == 47) {
} // poke = j;
} // break;
String real = str.substring(poke + 1); // }
System.out.println(real); // }
System.out.println(file.getName() + "\\" + real); // String real = str.substring(poke + 1);
fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "\\" + real); // System.out.println(real);
} catch (IOException e) { // System.out.println(file.getName() + "\\" + real);
e.printStackTrace(); // fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "\\" + real);
} finally { // while ((len = inputStream.read(data)) != -1) {
// fileOutputStream.write(data, 0, len);
if (inputStream != null) { // }
try { // } catch (IOException e) {
inputStream.close(); // e.printStackTrace();
} catch (IOException e) { // } finally {
e.printStackTrace(); //
} // try {
} // inputStream.close();
if (fileOutputStream != null) { // } catch (IOException e) {
try { // e.printStackTrace();
fileOutputStream.close(); // }
} catch (IOException e) { // if (fileOutputStream != null) {
e.printStackTrace(); // try {
} // fileOutputStream.close();
} // } catch (IOException e) {
System.out.println("success"); // e.printStackTrace();
} // }
} // }
} // System.out.println("success");
// }
// }
// }
public static void fileToZip(File sourceFile) throws Exception { public static void fileToZip(File sourceFile) throws Exception {

View File

@ -26,7 +26,7 @@ spring:
#二维码Logo图片获取位置 #二维码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" destPath: "/www/wwwroot/www.scxhua.cn/xhpc-charging-stion/XiaoHuaFullImgs"
#生成的最终完整图片的存放位置: #生成的最终完整图片的存放位置: