修复下载二维码列表展示终端个数错误问题,
修复下载二维码阿里云数据冗余问题, 仍然有五个bug,后续修复
This commit is contained in:
parent
4b9f46cba4
commit
cccec12c80
@ -1,7 +1,9 @@
|
|||||||
package com.xhpc.charging.station.service;
|
package com.xhpc.charging.station.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.aliyun.oss.OSSClient;
|
||||||
|
import com.aliyun.oss.model.*;
|
||||||
import com.xhpc.charging.station.mapper.XhpcChargingPileMapper;
|
import com.xhpc.charging.station.mapper.XhpcChargingPileMapper;
|
||||||
import com.xhpc.charging.station.mapper.XhpcChargingStationMapper;
|
|
||||||
import com.xhpc.charging.station.mapper.XhpcImgMapper;
|
import com.xhpc.charging.station.mapper.XhpcImgMapper;
|
||||||
import com.xhpc.charging.station.mapper.XhpcTerminalMapper;
|
import com.xhpc.charging.station.mapper.XhpcTerminalMapper;
|
||||||
import com.xhpc.charging.station.utils.img.QrImgUtils;
|
import com.xhpc.charging.station.utils.img.QrImgUtils;
|
||||||
@ -16,8 +18,12 @@ import org.springframework.core.env.Environment;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.aliyun.oss.internal.OSSConstants.URL_ENCODING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yuyang
|
* @author yuyang
|
||||||
* @date 2021/7/27 14:36
|
* @date 2021/7/27 14:36
|
||||||
@ -180,6 +186,8 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
|
|||||||
Long rateModelId = xhpcChargingPile.getRateModelId();
|
Long rateModelId = xhpcChargingPile.getRateModelId();
|
||||||
Long chargingStationId = xhpcChargingPile.getChargingStationId();
|
Long chargingStationId = xhpcChargingPile.getChargingStationId();
|
||||||
if (xhpcChargingPile.getGunNumber() > 0) {
|
if (xhpcChargingPile.getGunNumber() > 0) {
|
||||||
|
// 删除阿里云上面之前可能存在的桩图片文件夹
|
||||||
|
clearRepetition(environment, serialNumber);
|
||||||
for (int i = 1; i <= xhpcChargingPile.getGunNumber(); i++) {
|
for (int i = 1; i <= xhpcChargingPile.getGunNumber(); i++) {
|
||||||
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i, number + 1, xhpcChargingPile.getConnectorType());
|
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i, number + 1, xhpcChargingPile.getConnectorType());
|
||||||
}
|
}
|
||||||
@ -240,12 +248,58 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载对应终端的二维码图片
|
* 下载对应终端的二维码图片
|
||||||
|
*
|
||||||
* @param terminalIds
|
* @param terminalIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> downloadsTerminalImgs(List<Integer> terminalIds) {
|
public List<Map<String, Object>> downloadsTerminalImgs(List<Integer> terminalIds) {
|
||||||
|
|
||||||
return xhpcImgMapper.selectImgUrlByTerminal_id(terminalIds);
|
return xhpcImgMapper.selectImgUrlByTerminal_id(terminalIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理阿里云中冗余的二维码图片数据
|
||||||
|
* <p>
|
||||||
|
* 该方法会根据传入的桩名称<param>prefix<param>,
|
||||||
|
* 到阿里云上去删除指定的桩下面的所有终端二维码(包括其本身)
|
||||||
|
*
|
||||||
|
* @param environment nacos环境对象
|
||||||
|
* @param prefix 桩的名称
|
||||||
|
*/
|
||||||
|
public static void clearRepetition(Environment environment, String prefix) {
|
||||||
|
|
||||||
|
OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key"));
|
||||||
|
String bucketName = environment.getProperty("oss.bucket-name");
|
||||||
|
System.out.println("==》桩:" + prefix + "图片冗余正在清理");
|
||||||
|
prefix = prefix + "/";
|
||||||
|
String nextMarker = null;
|
||||||
|
ObjectListing objectListing = null;
|
||||||
|
do {
|
||||||
|
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName)
|
||||||
|
.withPrefix(prefix)
|
||||||
|
.withMarker(nextMarker);
|
||||||
|
objectListing = ossClient.listObjects(listObjectsRequest);
|
||||||
|
if (objectListing.getObjectSummaries().size() > 0) {
|
||||||
|
List<String> keys = new ArrayList<String>();
|
||||||
|
for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
|
||||||
|
keys.add(s.getKey());
|
||||||
|
}
|
||||||
|
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName).withKeys(keys).withEncodingType(URL_ENCODING);
|
||||||
|
DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(deleteObjectsRequest);
|
||||||
|
List<String> deletedObjects = deleteObjectsResult.getDeletedObjects();
|
||||||
|
try {
|
||||||
|
for (String obj : deletedObjects) {
|
||||||
|
String deleteObj = URLDecoder.decode(obj, "UTF-8");
|
||||||
|
System.out.println(deleteObj);
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nextMarker = objectListing.getNextMarker();
|
||||||
|
} while (objectListing.isTruncated());
|
||||||
|
System.out.println(DateUtil.now() + "==》图片冗余清理执行成功");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,21 +2,14 @@ package com.xhpc.charging.station.utils.img;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.aliyun.oss.OSSClient;
|
import com.aliyun.oss.OSSClient;
|
||||||
import com.aliyun.oss.model.*;
|
|
||||||
import com.xhpc.charging.station.mapper.XhpcImgMapper;
|
import com.xhpc.charging.station.mapper.XhpcImgMapper;
|
||||||
import com.xhpc.common.domain.XhpcTerminal;
|
import com.xhpc.common.domain.XhpcTerminal;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.aliyun.oss.internal.OSSConstants.URL_ENCODING;
|
|
||||||
|
|
||||||
public class QrImgUtils {
|
public class QrImgUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,23 +21,19 @@ public class QrImgUtils {
|
|||||||
* @Since version-1.0
|
* @Since version-1.0
|
||||||
*/
|
*/
|
||||||
public static void uploadImg(XhpcTerminal xhpcTerminal, String serialNumber, Environment environment, XhpcImgMapper xhpcImgMapper, String chargingStationName, int forIndex, Map<Integer,Character> letterMap, String name) {
|
public static void uploadImg(XhpcTerminal xhpcTerminal, String serialNumber, Environment environment, XhpcImgMapper xhpcImgMapper, String chargingStationName, int forIndex, Map<Integer,Character> letterMap, String name) {
|
||||||
|
|
||||||
//生成桩的二维码图片
|
//生成桩的二维码图片
|
||||||
//1.生成二维码链接内容:
|
//1.生成二维码链接内容:
|
||||||
StringBuilder prefix = new StringBuilder("https://www.scxhua.cn?pNum=");
|
StringBuilder prefix = new StringBuilder("https://www.scxhua.cn?pNum=");
|
||||||
String QrContent = prefix.append(xhpcTerminal.getSerialNumber()).toString();
|
String QrContent = prefix.append(xhpcTerminal.getSerialNumber()).toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//2.生成二维码图片:
|
//2.生成二维码图片:
|
||||||
//2.1生成指定规则的图片名
|
//2.1生成指定规则的图片名
|
||||||
String qrFileName = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS") + serialNumber + ".png";
|
String qrFileName = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS") + serialNumber + ".png";
|
||||||
//2.2获取生成的二维码图片
|
//2.2获取生成的二维码图片
|
||||||
File QrCode = QRCodeUtil.encode(QrContent, environment.getProperty("imgPath"), environment.getProperty("destPath"), true, qrFileName);
|
File QrCode = QRCodeUtil.encode(QrContent, environment.getProperty("imgPath"), environment.getProperty("destPath"), true, qrFileName);
|
||||||
|
|
||||||
//3.拼接成完整图片
|
//3.拼接成完整图片
|
||||||
//3.1生成指定规则的图片名
|
//3.1生成指定规则的图片名
|
||||||
String finallyImgFileName = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS") + serialNumber + ".png";
|
String finallyImgFileName = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS") + serialNumber + ".png";
|
||||||
|
|
||||||
new ImageUtil().fastCreateImg(
|
new ImageUtil().fastCreateImg(
|
||||||
new File(environment.getProperty("bottomImg")),
|
new File(environment.getProperty("bottomImg")),
|
||||||
QrCode,
|
QrCode,
|
||||||
@ -54,21 +43,14 @@ public class QrImgUtils {
|
|||||||
String.valueOf(letterMap.get(forIndex)),
|
String.valueOf(letterMap.get(forIndex)),
|
||||||
new File(environment.getProperty("fullImgDestPath") + finallyImgFileName)
|
new File(environment.getProperty("fullImgDestPath") + finallyImgFileName)
|
||||||
);
|
);
|
||||||
|
|
||||||
System.out.println("===================》完整二维码图片生成成功");
|
System.out.println("===================》完整二维码图片生成成功");
|
||||||
|
|
||||||
//4.上传图片至服务器
|
//4.上传图片至服务器
|
||||||
// 创建OSSClient实例
|
// 创建OSSClient实例
|
||||||
OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key"));
|
OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key"));
|
||||||
// 删除阿里云上面之前可能存在的桩图片文件夹
|
|
||||||
String pileNumber = serialNumber.substring(0, 14);
|
|
||||||
clearRepetition(ossClient, environment, pileNumber);
|
|
||||||
// 上传文件流
|
// 上传文件流
|
||||||
ossClient.putObject(environment.getProperty("oss.bucket-name"), xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, new File(environment.getProperty("destPath") + File.separatorChar + finallyImgFileName));
|
ossClient.putObject(environment.getProperty("oss.bucket-name"), xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, new File(environment.getProperty("destPath") + File.separatorChar + finallyImgFileName));
|
||||||
ossClient.shutdown();
|
ossClient.shutdown();
|
||||||
|
|
||||||
System.out.println("===================》将完整二维码上传至阿里云成功");
|
System.out.println("===================》将完整二维码上传至阿里云成功");
|
||||||
|
|
||||||
//5.将放在阿里云上的生成的图片的路径和图片所对应的终端的id放入数据库xhpc_img表中
|
//5.将放在阿里云上的生成的图片的路径和图片所对应的终端的id放入数据库xhpc_img表中
|
||||||
Long terminalId = xhpcTerminal.getTerminalId();
|
Long terminalId = xhpcTerminal.getTerminalId();
|
||||||
xhpcImgMapper.insert(xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, terminalId);
|
xhpcImgMapper.insert(xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, terminalId);
|
||||||
@ -86,49 +68,4 @@ public class QrImgUtils {
|
|||||||
System.out.println("二维码生成图片失败,请检查生成二维码所需要的资源路径是否正确");
|
System.out.println("二维码生成图片失败,请检查生成二维码所需要的资源路径是否正确");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理阿里云中冗余的二维码图片数据
|
|
||||||
* <p>
|
|
||||||
* 该方法会根据传入的桩名称<param>prefix<param>,
|
|
||||||
* 到阿里云上去删除指定的桩下面的所有终端二维码(包括其本身)
|
|
||||||
*
|
|
||||||
* @param ossClient 阿里云oss存储对象
|
|
||||||
* @param environment nacos环境对象
|
|
||||||
* @param prefix 桩的名称
|
|
||||||
*/
|
|
||||||
public static void clearRepetition(OSSClient ossClient, Environment environment, String prefix) {
|
|
||||||
|
|
||||||
String bucketName = environment.getProperty("oss.bucket-name");
|
|
||||||
System.out.println("==》桩:" + prefix + "图片冗余正在清理");
|
|
||||||
prefix = prefix + "/";
|
|
||||||
String nextMarker = null;
|
|
||||||
ObjectListing objectListing = null;
|
|
||||||
do {
|
|
||||||
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName)
|
|
||||||
.withPrefix(prefix)
|
|
||||||
.withMarker(nextMarker);
|
|
||||||
objectListing = ossClient.listObjects(listObjectsRequest);
|
|
||||||
if (objectListing.getObjectSummaries().size() > 0) {
|
|
||||||
List<String> keys = new ArrayList<String>();
|
|
||||||
for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
|
|
||||||
keys.add(s.getKey());
|
|
||||||
}
|
|
||||||
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName).withKeys(keys).withEncodingType(URL_ENCODING);
|
|
||||||
DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(deleteObjectsRequest);
|
|
||||||
List<String> deletedObjects = deleteObjectsResult.getDeletedObjects();
|
|
||||||
try {
|
|
||||||
for (String obj : deletedObjects) {
|
|
||||||
String deleteObj = URLDecoder.decode(obj, "UTF-8");
|
|
||||||
System.out.println(deleteObj);
|
|
||||||
}
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nextMarker = objectListing.getNextMarker();
|
|
||||||
} while (objectListing.isTruncated());
|
|
||||||
System.out.println(DateUtil.now() + "==》图片冗余清理执行成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
on xcs.operator_id = xo.operator_id
|
on xcs.operator_id = xo.operator_id
|
||||||
left join xhpc_terminal as xt
|
left join xhpc_terminal as xt
|
||||||
on xcs.charging_station_id = xt.charging_station_id
|
on xcs.charging_station_id = xt.charging_station_id
|
||||||
where xo.del_flag = 0
|
where xo.del_flag = 0 and xt.del_flag = 0
|
||||||
<if test="null != stationName and '' != stationName">
|
<if test="null != stationName and '' != stationName">
|
||||||
and xcs.name like concat('%',#{stationName},'%')
|
and xcs.name like concat('%',#{stationName},'%')
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user