解决二维码下载小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);
|
||||
|
||||
/**
|
||||
* 用于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);
|
||||
|
||||
/**
|
||||
* 查询出场站下面的未删除的终端的图片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);
|
||||
|
||||
/**
|
||||
* 查找场站下方有图片的终端的相关的信息存入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);
|
||||
|
||||
}
|
||||
|
||||
@ -106,11 +106,10 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
workbook.write(fos);
|
||||
workbook.close();
|
||||
fos.close();
|
||||
String left = environment.getProperty("img.imgPrefix");
|
||||
String imgPrefixUrl = environment.getProperty("img.imgPrefix");
|
||||
List<String> imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId);
|
||||
List<String> list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls);
|
||||
System.out.println(list1);
|
||||
DownMaterialUtil.saveImageToDisk(list1, file2, imgUrls);
|
||||
List<String> fullImgUrlList = DownMaterialUtil.getDownLoadUrls(imgPrefixUrl, imgUrls);
|
||||
DownMaterialUtil.saveImageToDisk(fullImgUrlList, file2, imgUrls);
|
||||
File file = new File(environment.getProperty("img.url"));
|
||||
//储存路径
|
||||
long l = System.currentTimeMillis();
|
||||
@ -126,7 +125,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
|
||||
//查找场站下方有图片的终端的相关的信息
|
||||
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");
|
||||
if (file1.exists()) {
|
||||
delFile(file1);
|
||||
@ -178,16 +177,14 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService {
|
||||
}
|
||||
}
|
||||
//5、写入
|
||||
//更改nocos上的输出位置
|
||||
OutputStream fos = new FileOutputStream(environment.getProperty("img.url") + "/data.xls");
|
||||
|
||||
workbook.write(fos);
|
||||
workbook.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> list1 = DownMaterialUtil.getDownLoadUrls(left, imgUrls);
|
||||
DownMaterialUtil.saveImageToDisk(list1, file2, imgUrls);
|
||||
List<String> fullImgUrlList = DownMaterialUtil.getDownLoadUrls(imgPrefixUrl, imgUrls);
|
||||
DownMaterialUtil.saveImageToDisk(fullImgUrlList, file2, imgUrls);
|
||||
File file = new File(environment.getProperty("img.url"));
|
||||
//储存路径
|
||||
long l = System.currentTimeMillis();
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
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.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@ -14,7 +19,12 @@ import java.util.zip.ZipOutputStream;
|
||||
* User: HongYun
|
||||
* Date:2021-10-09 10
|
||||
*/
|
||||
@Component
|
||||
public class DownMaterialUtil {
|
||||
|
||||
@Autowired
|
||||
Environment environment;
|
||||
|
||||
public static InputStream getInputStream(String urlImg) {
|
||||
|
||||
InputStream inputStream = null;
|
||||
@ -41,6 +51,14 @@ public class DownMaterialUtil {
|
||||
}
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存图片到磁盘上
|
||||
*
|
||||
* @param urls
|
||||
* @param file
|
||||
* @param imgNames
|
||||
*/
|
||||
public static void saveImageToDisk(List<String> urls, File file, List<String> imgNames) {
|
||||
|
||||
for (int i = 0; i < urls.size(); i++) {
|
||||
@ -127,11 +145,40 @@ public class DownMaterialUtil {
|
||||
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<>();
|
||||
for (String s : imgUrl) {
|
||||
res.add(left + s);
|
||||
for (String s : imgUrls) {
|
||||
res.add(imgPrefixUrl + s);
|
||||
}
|
||||
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 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 p.charging_pile_id = #{pileId}
|
||||
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 p.charging_pile_id = #{pileId}
|
||||
AND p.del_flag = 0
|
||||
AND t.del_flag = 0
|
||||
|
||||
</select>
|
||||
|
||||
<select id="selectExcelDataByStationId" resultType="map">
|
||||
|
||||
SELECT terminal.NAME AS tName,
|
||||
station.NAME AS sName,
|
||||
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_station AS station ON station.charging_station_id = pile.charging_station_id
|
||||
WHERE station.charging_station_id = #{stationId}
|
||||
AND terminal.del_flag = 0
|
||||
AND pile.del_flag = 0
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUrlsByPile" resultType="java.lang.String">
|
||||
|
||||
select i.url
|
||||
from xhpc_img as i left join xhpc_terminal as t
|
||||
on i.terminal_id = t.terminal_id
|
||||
where t.terminal_id in (
|
||||
select terminal_id
|
||||
from xhpc_terminal
|
||||
where charging_pile_id = #{pileId}
|
||||
SELECT i.url
|
||||
FROM xhpc_img AS i
|
||||
LEFT JOIN xhpc_terminal AS t ON i.terminal_id = t.terminal_id
|
||||
WHERE t.terminal_id IN (
|
||||
SELECT terminal_id
|
||||
FROM xhpc_terminal
|
||||
WHERE charging_pile_id = #{pileId}
|
||||
)
|
||||
AND t.del_flag = 0
|
||||
|
||||
</select>
|
||||
|
||||
<select id="selectUrlsByStation" resultType="java.lang.String">
|
||||
|
||||
select i.url
|
||||
from xhpc_img as i left join xhpc_terminal as t
|
||||
on i.terminal_id = t.terminal_id
|
||||
where t.terminal_id in (
|
||||
select terminal_id
|
||||
from xhpc_terminal
|
||||
where charging_station_id = #{stationId}
|
||||
SELECT i.url
|
||||
FROM xhpc_img AS i
|
||||
LEFT JOIN xhpc_terminal AS t ON i.terminal_id = t.terminal_id
|
||||
WHERE t.terminal_id IN (
|
||||
SELECT terminal_id
|
||||
FROM xhpc_terminal
|
||||
WHERE charging_station_id = #{stationId}
|
||||
)
|
||||
AND t.del_flag = 0
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
x
Reference in New Issue
Block a user