解决二维码下载小bug,二维码下载功能正式可用
This commit is contained in:
parent
ef7e7b111e
commit
6ff420be92
@ -18,11 +18,49 @@ public interface XhpcDownCodeMapper {
|
|||||||
|
|
||||||
List<Map<String, Object>> selectPilesBy(@Param(value = "stationId") Long stationId);
|
List<Map<String, Object>> selectPilesBy(@Param(value = "stationId") Long stationId);
|
||||||
|
|
||||||
List<Map<String,Object>> selectExcelDataByPileId(@Param("pileId") Long pileId );
|
/**
|
||||||
|
* 用于excel表格中的信息,
|
||||||
|
* 根据桩的id,查找出未删除的对应的终端信息
|
||||||
|
*
|
||||||
|
* @param pileId 桩的id
|
||||||
|
* @return List<Map < String, Object>> 一个装着每条终端数据的List集合
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/11/25 13:46
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> selectExcelDataByPileId(@Param("pileId") Long pileId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询出桩下面的未删除的终端的图片url地址
|
||||||
|
*
|
||||||
|
* @param pileId 桩的id
|
||||||
|
* @return List<String> 一个装着每个终端url图片的List
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/11/25 14:02
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
List<String> selectUrlsByPile(@Param(value = "pileId") Long pileId);
|
List<String> selectUrlsByPile(@Param(value = "pileId") Long pileId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询出场站下面的未删除的终端的图片url地址
|
||||||
|
*
|
||||||
|
* @param stationId 场站id
|
||||||
|
* @return 返回装有终端url的List
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/11/25 15:24
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
List<String> selectUrlsByStation(@Param(value = "stationId") Long stationId);
|
List<String> selectUrlsByStation(@Param(value = "stationId") Long stationId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找场站下方有图片的终端的相关的信息存入excel表格中
|
||||||
|
*
|
||||||
|
* @param stationId 场站id
|
||||||
|
* @return 装有每一个终端信息的List集合
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/11/25 15:11
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
List<Map<String, Object>> selectExcelDataByStationId(@Param(value = "stationId") Long stationId);
|
List<Map<String, Object>> selectExcelDataByStationId(@Param(value = "stationId") Long stationId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,17 +106,16 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
|||||||
workbook.write(fos);
|
workbook.write(fos);
|
||||||
workbook.close();
|
workbook.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
String left = environment.getProperty("img.imgPrefix");
|
String imgPrefixUrl = environment.getProperty("img.imgPrefix");
|
||||||
List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId);
|
List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId);
|
||||||
List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls);
|
List<String> fullImgUrlList = DownMaterialUtil.getDownLoadUrls(imgPrefixUrl, imgUrls);
|
||||||
System.out.println(list1);
|
DownMaterialUtil.saveImageToDisk(fullImgUrlList, file2, imgUrls);
|
||||||
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();
|
||||||
String url=environment.getProperty("img.url")+l;
|
String url = environment.getProperty("img.url") + l;
|
||||||
|
|
||||||
DownMaterialUtil.fileToZip(file,url);
|
DownMaterialUtil.fileToZip(file, url);
|
||||||
|
|
||||||
return "QRcodeMaterial" + l + ".zip";
|
return "QRcodeMaterial" + l + ".zip";
|
||||||
}
|
}
|
||||||
@ -126,7 +125,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
|||||||
|
|
||||||
//查找场站下方有图片的终端的相关的信息
|
//查找场站下方有图片的终端的相关的信息
|
||||||
List<Map<String, Object>> list = xhpcDownCodeMapper.selectExcelDataByStationId(stationId);
|
List<Map<String, Object>> list = xhpcDownCodeMapper.selectExcelDataByStationId(stationId);
|
||||||
File file1 = new File(environment.getProperty("img.url"), "Material");
|
File file1 = new File(environment.getProperty("img.url"));
|
||||||
File file2 = new File(file1, "pictures");
|
File file2 = new File(file1, "pictures");
|
||||||
if (file1.exists()) {
|
if (file1.exists()) {
|
||||||
delFile(file1);
|
delFile(file1);
|
||||||
@ -178,22 +177,20 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//5、写入
|
//5、写入
|
||||||
//更改nocos上的输出位置
|
|
||||||
OutputStream fos = new FileOutputStream(environment.getProperty("img.url") + "/data.xls");
|
OutputStream fos = new FileOutputStream(environment.getProperty("img.url") + "/data.xls");
|
||||||
|
|
||||||
workbook.write(fos);
|
workbook.write(fos);
|
||||||
workbook.close();
|
workbook.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/";
|
String imgPrefixUrl = environment.getProperty("img.imgPrefix");
|
||||||
List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByStation(stationId);
|
List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByStation(stationId);
|
||||||
List<String> list1 = DownMaterialUtil.getDownLoadUrls(left, imgUrls);
|
List<String> fullImgUrlList = DownMaterialUtil.getDownLoadUrls(imgPrefixUrl, imgUrls);
|
||||||
DownMaterialUtil.saveImageToDisk(list1, file2, imgUrls);
|
DownMaterialUtil.saveImageToDisk(fullImgUrlList, 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();
|
||||||
String url=environment.getProperty("img.url")+l;
|
String url = environment.getProperty("img.url") + l;
|
||||||
|
|
||||||
DownMaterialUtil.fileToZip(file,url);
|
DownMaterialUtil.fileToZip(file, url);
|
||||||
|
|
||||||
return "QRcodeMaterial" + l + ".zip";
|
return "QRcodeMaterial" + l + ".zip";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
package com.xhpc.charging.station.utils.img;
|
package com.xhpc.charging.station.utils.img;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -14,7 +19,12 @@ import java.util.zip.ZipOutputStream;
|
|||||||
* User: HongYun
|
* User: HongYun
|
||||||
* Date:2021-10-09 10
|
* Date:2021-10-09 10
|
||||||
*/
|
*/
|
||||||
|
@Component
|
||||||
public class DownMaterialUtil {
|
public class DownMaterialUtil {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
Environment environment;
|
||||||
|
|
||||||
public static InputStream getInputStream(String urlImg) {
|
public static InputStream getInputStream(String urlImg) {
|
||||||
|
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
@ -41,9 +51,17 @@ public class DownMaterialUtil {
|
|||||||
}
|
}
|
||||||
return inputStream;
|
return inputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存图片到磁盘上
|
||||||
|
*
|
||||||
|
* @param urls
|
||||||
|
* @param file
|
||||||
|
* @param imgNames
|
||||||
|
*/
|
||||||
public static void saveImageToDisk(List<String> urls, File file, List<String> imgNames) {
|
public static void saveImageToDisk(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));
|
||||||
if (null == inputStream) continue;
|
if (null == inputStream) continue;
|
||||||
byte[] data = new byte[1024];
|
byte[] data = new byte[1024];
|
||||||
@ -127,11 +145,40 @@ public class DownMaterialUtil {
|
|||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static List<String> getDownLoadUrls(String left, List<String> imgUrl){
|
|
||||||
|
/**
|
||||||
|
* 拼接图片前缀和后缀,最终生成完整的下载路径
|
||||||
|
*
|
||||||
|
* @param imgUrls 图片后缀集合
|
||||||
|
* @param imgPrefixUrl 图片前缀
|
||||||
|
* @return List<String> 完整图片集合
|
||||||
|
* <p>
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/11/25 14:19
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
public static List<String> getDownLoadUrls(String imgPrefixUrl, List<String> imgUrls) {
|
||||||
|
|
||||||
List<String> res = new ArrayList<>();
|
List<String> res = new ArrayList<>();
|
||||||
for (String s : imgUrl) {
|
for (String s : imgUrls) {
|
||||||
res.add(left + s);
|
res.add(imgPrefixUrl + s);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 负责定时删除服务器上面下载下来的二维码压缩包
|
||||||
|
* 每个月25号早上3点执行
|
||||||
|
*
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/11/24 15:50
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 3 25 * ?")
|
||||||
|
public void deleteZips() {
|
||||||
|
//遍历指定文件夹下的所有图片 dist
|
||||||
|
// new File(environment.getProperty(""))
|
||||||
|
// todo
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,16 +29,23 @@
|
|||||||
|
|
||||||
<select id="selectExcelDataByPileId" resultType="map">
|
<select id="selectExcelDataByPileId" resultType="map">
|
||||||
|
|
||||||
select t.name as tName, s.name as sName, t.serial_number as tSN, p.serial_number as psn,
|
SELECT t.NAME AS tName,
|
||||||
p.type, p.power
|
s.NAME AS sName,
|
||||||
from xhpc_terminal as t left join xhpc_charging_station as s
|
t.serial_number AS tSN,
|
||||||
on t.charging_station_id = s.charging_station_id
|
p.serial_number AS psn,
|
||||||
left join xhpc_charging_pile as p
|
p.type,
|
||||||
on p.charging_pile_id = t.charging_pile_id
|
p.power
|
||||||
where p.charging_pile_id = #{pileId}
|
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 p.charging_pile_id = #{pileId}
|
||||||
|
AND p.del_flag = 0
|
||||||
|
AND t.del_flag = 0
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectExcelDataByStationId" resultType="map">
|
<select id="selectExcelDataByStationId" resultType="map">
|
||||||
|
|
||||||
SELECT terminal.NAME AS tName,
|
SELECT terminal.NAME AS tName,
|
||||||
station.NAME AS sName,
|
station.NAME AS sName,
|
||||||
terminal.serial_number AS tSN,
|
terminal.serial_number AS tSN,
|
||||||
@ -50,31 +57,38 @@
|
|||||||
INNER JOIN xhpc_charging_pile AS pile ON pile.charging_pile_id = terminal.charging_pile_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
|
INNER JOIN xhpc_charging_station AS station ON station.charging_station_id = pile.charging_station_id
|
||||||
WHERE station.charging_station_id = #{stationId}
|
WHERE station.charging_station_id = #{stationId}
|
||||||
|
AND terminal.del_flag = 0
|
||||||
|
AND pile.del_flag = 0
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<select id="selectUrlsByPile" resultType="java.lang.String">
|
<select id="selectUrlsByPile" resultType="java.lang.String">
|
||||||
|
|
||||||
select i.url
|
SELECT i.url
|
||||||
from xhpc_img as i left join xhpc_terminal as t
|
FROM xhpc_img AS i
|
||||||
on i.terminal_id = t.terminal_id
|
LEFT JOIN xhpc_terminal AS t ON i.terminal_id = t.terminal_id
|
||||||
where t.terminal_id in (
|
WHERE t.terminal_id IN (
|
||||||
select terminal_id
|
SELECT terminal_id
|
||||||
from xhpc_terminal
|
FROM xhpc_terminal
|
||||||
where charging_pile_id = #{pileId}
|
WHERE charging_pile_id = #{pileId}
|
||||||
)
|
)
|
||||||
|
AND t.del_flag = 0
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectUrlsByStation" resultType="java.lang.String">
|
<select id="selectUrlsByStation" resultType="java.lang.String">
|
||||||
|
|
||||||
select i.url
|
SELECT i.url
|
||||||
from xhpc_img as i left join xhpc_terminal as t
|
FROM xhpc_img AS i
|
||||||
on i.terminal_id = t.terminal_id
|
LEFT JOIN xhpc_terminal AS t ON i.terminal_id = t.terminal_id
|
||||||
where t.terminal_id in (
|
WHERE t.terminal_id IN (
|
||||||
select terminal_id
|
SELECT terminal_id
|
||||||
from xhpc_terminal
|
FROM xhpc_terminal
|
||||||
where charging_station_id = #{stationId}
|
WHERE charging_station_id = #{stationId}
|
||||||
)
|
)
|
||||||
|
AND t.del_flag = 0
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
x
Reference in New Issue
Block a user