修复二维码场站下载功能
This commit is contained in:
parent
5e2ea9ddc9
commit
f4c5428321
@ -54,16 +54,4 @@ public class XhpcDownCodeController extends BaseController {
|
||||
|
||||
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);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -17,8 +17,4 @@ 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;
|
||||
}
|
||||
|
||||
@ -26,7 +26,6 @@ import java.util.Map;
|
||||
@Service
|
||||
public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private XhpcDownCodeMapper xhpcDownCodeMapper;
|
||||
|
||||
@ -107,7 +106,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
workbook.write(fos);
|
||||
workbook.close();
|
||||
fos.close();
|
||||
String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/";
|
||||
String left = environment.getProperty("img.imgPrefix");
|
||||
List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId);
|
||||
List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls);
|
||||
System.out.println(list1);
|
||||
@ -125,9 +124,9 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
@Override
|
||||
public String downMaterialByStationId(Long stationId) throws Exception {
|
||||
|
||||
//查找场站下方有图片的终端的相关的信息
|
||||
List<Map<String, Object>> list = xhpcDownCodeMapper.selectExcelDataByStationId(stationId);
|
||||
System.out.println(list);
|
||||
File file1 = new File("Material");
|
||||
File file1 = new File(environment.getProperty("img.url"), "Material");
|
||||
File file2 = new File(file1, "pictures");
|
||||
if (file1.exists()) {
|
||||
delFile(file1);
|
||||
@ -179,7 +178,9 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
}
|
||||
}
|
||||
//5、写入
|
||||
//更改nocos上的输出位置
|
||||
OutputStream fos = new FileOutputStream(environment.getProperty("img.url") + "/data.xls");
|
||||
|
||||
workbook.write(fos);
|
||||
workbook.close();
|
||||
fos.close();
|
||||
@ -197,163 +198,6 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
return "Material"+l+".zip";
|
||||
}
|
||||
|
||||
public void deleteFiles(File file){
|
||||
if (file.isDirectory()) {
|
||||
File[] files=file.listFiles();
|
||||
if (null != files) {
|
||||
for (File value : files) {
|
||||
if (value.isDirectory()) {
|
||||
deleteFiles(value);
|
||||
} else {
|
||||
//System.out.println("里层文件:" + value.getName() + "--------" + value.delete());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//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);
|
||||
// List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls);
|
||||
// System.out.println(list1);
|
||||
// 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);
|
||||
// }
|
||||
|
||||
static boolean delFile(File file) {
|
||||
|
||||
if (!file.exists()) {
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
package com.xhpc.charging.station.utils.img;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -43,7 +41,6 @@ public class DownMaterialUtil {
|
||||
}
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
public static void saveImageToDisk(List<String> urls, File file, List<String> imgNames) {
|
||||
|
||||
for(int i = 0; i < urls.size(); i ++) {
|
||||
@ -71,8 +68,8 @@ public class DownMaterialUtil {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("下载出错了");
|
||||
} finally {
|
||||
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
@ -85,74 +82,9 @@ public class DownMaterialUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("success");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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));
|
||||
// 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 {
|
||||
|
||||
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()) {
|
||||
@ -195,45 +127,6 @@ public class DownMaterialUtil {
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveToFile(String targetUrl,String destUrl) {
|
||||
|
||||
FileOutputStream fos = null;
|
||||
BufferedInputStream bis = null;
|
||||
HttpURLConnection httpUrl = null;
|
||||
URL url = null;
|
||||
int BUFFER_SIZE = 1024;
|
||||
byte[] buf = new byte[BUFFER_SIZE];
|
||||
int size = 0;
|
||||
try {
|
||||
url = new URL(targetUrl);
|
||||
httpUrl = (HttpURLConnection) url.openConnection();
|
||||
httpUrl.connect();
|
||||
bis = new BufferedInputStream(httpUrl.getInputStream());
|
||||
fos = new FileOutputStream(destUrl);
|
||||
while ((size = bis.read(buf)) != -1) {
|
||||
fos.write(buf, 0, size);
|
||||
}
|
||||
fos.flush();
|
||||
} catch (IOException | ClassCastException ignored) {
|
||||
} finally {
|
||||
try {
|
||||
if(null != fos) {
|
||||
fos.close();
|
||||
}
|
||||
if(null != bis) {
|
||||
bis.close();
|
||||
}
|
||||
if(null != httpUrl) {
|
||||
httpUrl.disconnect();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getDownLoadUrls(String left, List<String> imgUrl){
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String s : imgUrl) {
|
||||
@ -241,40 +134,4 @@ public class DownMaterialUtil {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以流的形式下载文件
|
||||
*
|
||||
* @param file
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
public static HttpServletResponse downloadZip(File file, HttpServletResponse response) {
|
||||
try {
|
||||
// 以流的形式下载文件。
|
||||
InputStream fis = new BufferedInputStream(new FileInputStream(file.getPath()));
|
||||
byte[] buffer = new byte[fis.available()];
|
||||
fis.read(buffer);
|
||||
fis.close();
|
||||
// 清空response
|
||||
response.reset();
|
||||
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
|
||||
response.setContentType("application/octet-stream");
|
||||
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
||||
toClient.write(buffer);
|
||||
toClient.flush();
|
||||
toClient.close();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
File f = new File(file.getPath());
|
||||
// f.delete();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
on xcs.operator_id = xo.operator_id
|
||||
left join xhpc_terminal as xt
|
||||
on xcs.charging_station_id = xt.charging_station_id
|
||||
where xo.status = 0 and xo.del_flag = 0
|
||||
where xo.del_flag = 0
|
||||
<if test="null != stationName and '' != stationName">
|
||||
and xcs.name like concat('%',#{stationName},'%')
|
||||
</if>
|
||||
@ -39,14 +39,17 @@
|
||||
</select>
|
||||
|
||||
<select id="selectExcelDataByStationId" resultType="map">
|
||||
|
||||
select t.name as tName, s.name as sName, t.serial_number as tSN, p.serial_number as psn,
|
||||
p.type, p.power
|
||||
from xhpc_terminal as t left join xhpc_charging_station as s
|
||||
on t.charging_station_id = s.charging_station_id
|
||||
left join xhpc_charging_pile as p
|
||||
on p.charging_pile_id = t.charging_pile_id
|
||||
where s.charging_station_id = #{stationId}
|
||||
SELECT terminal.NAME AS tName,
|
||||
station.NAME AS sName,
|
||||
terminal.serial_number AS tSN,
|
||||
pile.serial_number AS psn,
|
||||
pile.type,
|
||||
pile.power
|
||||
FROM xhpc_img AS img
|
||||
INNER JOIN xhpc_terminal AS terminal ON img.terminal_id = terminal.terminal_id
|
||||
INNER JOIN xhpc_charging_pile AS pile ON pile.charging_pile_id = terminal.charging_pile_id
|
||||
INNER JOIN xhpc_charging_station AS station ON station.charging_station_id = pile.charging_station_id
|
||||
WHERE station.charging_station_id = #{stationId}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user