Solving a bug from downCode.
This commit is contained in:
parent
6cdf792381
commit
2d93c365b9
@ -44,14 +44,26 @@ public class XhpcDownCodeController extends BaseController {
|
||||
|
||||
String s = iXhpcDownCodeService.downMaterialBy(pileId);
|
||||
|
||||
return AjaxResult.success(environment.getProperty("img.getUrl")+s);
|
||||
return AjaxResult.success(environment.getProperty("img.getUrl") + s);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/downMaterialByStationId")
|
||||
public AjaxResult downMaterialByStationId(@RequestParam Long stationId) throws Exception{
|
||||
public AjaxResult downMaterialByStationId(@RequestParam Long stationId) throws Exception {
|
||||
|
||||
String s =iXhpcDownCodeService.downMaterialByStationId(stationId);
|
||||
String s = iXhpcDownCodeService.downMaterialByStationId(stationId);
|
||||
|
||||
return AjaxResult.success(environment.getProperty("img.getUrl")+s);
|
||||
return AjaxResult.success(environment.getProperty("img.getUrl") + s);
|
||||
}
|
||||
|
||||
// @GetMapping(value = "/downMaterialByPileId1")
|
||||
// public void downMaterialBy1(@RequestParam Long pileId) throws Exception {
|
||||
//
|
||||
// iXhpcDownCodeService.downMaterialBy11(pileId);
|
||||
// }
|
||||
//
|
||||
// @GetMapping(value = "/downMaterialByStationId1")
|
||||
// public void downMaterialByStationId1(@RequestParam Long stationId) throws Exception{
|
||||
//
|
||||
// iXhpcDownCodeService.downMaterialByStationId11(stationId);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.xhpc.charging.station.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@ -10,6 +11,7 @@ import java.util.Map;
|
||||
* User: HongYun
|
||||
* Date:2021-09-30 15
|
||||
*/
|
||||
@Mapper
|
||||
public interface XhpcDownCodeMapper {
|
||||
|
||||
List<Map<String, Object>> selectStationsBy(@Param(value = "stationName") String stationName);
|
||||
|
||||
@ -17,4 +17,8 @@ public interface IXhpcDownCodeService {
|
||||
String downMaterialBy(Long pileId) throws Exception;
|
||||
|
||||
String downMaterialByStationId(Long stationId) throws Exception;
|
||||
//
|
||||
// void downMaterialBy11(Long pileId) throws Exception;
|
||||
//
|
||||
// void downMaterialByStationId11(Long stationId) throws Exception;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
File file1 = new File(environment.getProperty("img.url"));
|
||||
File file2 = new File(file1, "pictures");
|
||||
if(file1.exists()){
|
||||
deleteFiles(file1);
|
||||
delFile(file1);
|
||||
}
|
||||
boolean flag = file1.mkdir();
|
||||
if(! flag) {
|
||||
@ -129,7 +129,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
File file1 = new File("Material");
|
||||
File file2 = new File(file1, "pictures");
|
||||
if (file1.exists()) {
|
||||
deleteFiles(file1);
|
||||
delFile(file1);
|
||||
}
|
||||
boolean flag = file1.mkdir();
|
||||
if (!flag) {
|
||||
@ -211,4 +211,162 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
}
|
||||
//System.out.println("外层文件:"+file.getName()+"--------"+file.delete());
|
||||
}
|
||||
//test
|
||||
// public void downMaterialBy11(Long pileId) throws Exception {
|
||||
//
|
||||
// List<Map<String,Object>> list = xhpcDownCodeMapper.selectExcelDataByPileId(pileId);
|
||||
// System.out.println(list);
|
||||
// File file1 = new File("Material");
|
||||
// File file2 = new File(file1, "pictures");
|
||||
// if(file1.exists()){
|
||||
// delFile(file1);
|
||||
// }
|
||||
// boolean flag = file1.mkdir();
|
||||
// if(! flag) {
|
||||
// System.out.println(file1.getName()+"文件夹创建失败!");
|
||||
// return;
|
||||
// }
|
||||
// boolean flag1 = file2.mkdir();
|
||||
// if(! flag1){
|
||||
// System.out.println(file2.getName() + "文件夹创建失败");
|
||||
// }
|
||||
// //1、创建excel文档对象
|
||||
// HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
// //2、创建sheet页
|
||||
// HSSFSheet sheet = workbook.createSheet("第一页");
|
||||
// //3、创建头部第一行
|
||||
// HSSFRow headRow = sheet.createRow(0);
|
||||
// HSSFCell cell;
|
||||
// String[] header = new String[] {"终端名称","归属电站","终端编码","电桩编码","终端类型(1直流(慢) 2交流(快)","电桩功率(KM)"};
|
||||
// for (int i = 0; i < header.length; i++) {
|
||||
// cell = headRow.createCell(i);
|
||||
// cell.setCellValue(header[i]);
|
||||
// }
|
||||
// //4、填写数据
|
||||
// HSSFRow dataRow;
|
||||
// HSSFCell dataCell;
|
||||
// String[] values = {"tName", "sName", "tSN", "psn", "type", "power"};
|
||||
// int valuesLength = values.length;
|
||||
// for(int i = 1; i <= list.size(); i ++){
|
||||
// Map<String,Object> map = list.get(i - 1);
|
||||
// if(null != map) {
|
||||
// dataRow = sheet.createRow(i);
|
||||
// for(int j = 0; j < valuesLength; j ++){
|
||||
// if(null != map.get(values[j])){
|
||||
// dataCell = dataRow.createCell(j);
|
||||
// String s = String.valueOf(map.get(values[j]));
|
||||
// dataCell.setCellValue(s);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// System.out.println(list);
|
||||
// //5、写入
|
||||
// OutputStream fos = new FileOutputStream(file1.getAbsoluteFile() + "\\data.xls");
|
||||
// workbook.write(fos);
|
||||
// workbook.close();
|
||||
// fos.close();
|
||||
// String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/";
|
||||
// List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId);
|
||||
// System.out.println(imgUrls);
|
||||
// List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls);
|
||||
// DownMaterialUtil.saveImageToDisk1(list1,file2,imgUrls);
|
||||
// File file = new File(file1.getAbsolutePath());
|
||||
// DownMaterialUtil.fileToZip(file);
|
||||
// System.out.println("success");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void downMaterialByStationId11(Long stationId) throws Exception {
|
||||
//
|
||||
// List<Map<String, Object>> list = xhpcDownCodeMapper.selectExcelDataByStationId(stationId);
|
||||
// System.out.println(list);
|
||||
// File file1 = new File("Material");
|
||||
// File file2 = new File(file1, "pictures");
|
||||
// if (file1.exists()) {
|
||||
// delFile(file1);
|
||||
// }
|
||||
// boolean flag = file1.mkdir();
|
||||
// if (!flag) {
|
||||
// System.out.println(file1.getName() + "文件夹创建失败!");
|
||||
// }
|
||||
// boolean flag1 = file2.mkdir();
|
||||
// if (!flag1) {
|
||||
// System.out.println(file2.getName() + "文件夹创建失败");
|
||||
// }
|
||||
// //1、创建excel文档对象
|
||||
// HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
// //2、创建sheet页
|
||||
// HSSFSheet sheet = workbook.createSheet("第一页");
|
||||
// //3、创建头部第一行
|
||||
// HSSFRow headRow = sheet.createRow(0);
|
||||
// HSSFCell cell;
|
||||
// String[] header = new String[]{"终端名称", "归属电站", "终端编码", "电桩编码", "终端类型(1直流(快) 2交流(慢)", "电桩功率(KM)"};
|
||||
// for (int i = 0; i < header.length; i++) {
|
||||
// cell = headRow.createCell(i);
|
||||
// cell.setCellValue(header[i]);
|
||||
// }
|
||||
// //4、填写数据
|
||||
// HSSFRow dataRow;
|
||||
// HSSFCell dataCell;
|
||||
// String[] values = {"tName", "sName", "tSN", "psn", "type", "power"};
|
||||
// int valuesLength = values.length;
|
||||
// for (int i = 1; i <= list.size(); i++) {
|
||||
// Map<String, Object> map = list.get(i - 1);
|
||||
// if (null != map) {
|
||||
// dataRow = sheet.createRow(i);
|
||||
// for (int j = 0; j < valuesLength; j++) {
|
||||
// if (null != map.get(values[j])) {
|
||||
// dataCell = dataRow.createCell(j);
|
||||
// String s = String.valueOf(map.get(values[j]));
|
||||
// if (j==4) {
|
||||
// if("1".equals(s)){
|
||||
// dataCell.setCellValue("直流");
|
||||
// }else{
|
||||
// dataCell.setCellValue("交流");
|
||||
// }
|
||||
// }else{
|
||||
// dataCell.setCellValue(s);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// //5、写入
|
||||
// OutputStream fos = new FileOutputStream(file1.getAbsoluteFile() + "\\data.xls");
|
||||
// workbook.write(fos);
|
||||
// workbook.close();
|
||||
// fos.close();
|
||||
// String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/";
|
||||
// List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByStation(stationId);
|
||||
// List<String> list1 = DownMaterialUtil.getDownLoadUrls(left, imgUrls);
|
||||
// DownMaterialUtil.saveImageToDisk1(list1, file2, imgUrls);
|
||||
// File file = new File(file1.getAbsolutePath());
|
||||
// DownMaterialUtil.fileToZip(file);
|
||||
// System.out.println("success");
|
||||
// File file = new File(file1);
|
||||
// //储存路径
|
||||
// long l = System.currentTimeMillis();
|
||||
// String url=environment.getProperty("img.url")+l;
|
||||
//
|
||||
// DownMaterialUtil.fileToZip(file,url);
|
||||
//
|
||||
// return "Material"+l+".zip";
|
||||
// }
|
||||
|
||||
static boolean delFile(File file) {
|
||||
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
if (null != files) {
|
||||
for (File f : files) {
|
||||
delFile(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,67 @@ public class DownMaterialUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void fileToZip(File sourceFile,String url) throws Exception {
|
||||
public static void saveImageToDisk1(List<String> urls, File file, List<String> 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 fileToZip(File sourceFile) throws Exception {
|
||||
|
||||
if (!sourceFile.exists()) {
|
||||
throw new RuntimeException("不存在");
|
||||
}
|
||||
if (!sourceFile.isDirectory()) {
|
||||
throw new RuntimeException("不是文件夹");
|
||||
}
|
||||
//zip文件生成位置
|
||||
File zipFile = new File(sourceFile.getAbsolutePath() + ".zip");
|
||||
FileOutputStream fos = new FileOutputStream(zipFile);
|
||||
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos));
|
||||
fileToZip(zos, sourceFile, "");
|
||||
zos.close();
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public static void fileToZip(File sourceFile, String url) throws Exception {
|
||||
|
||||
if (!sourceFile.exists()) {
|
||||
throw new RuntimeException("不存在");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user