将生成二维码压缩包添加定时删除任务

This commit is contained in:
wen 2021-11-26 17:22:13 +08:00
parent 4c7c67602a
commit d932701401
2 changed files with 38 additions and 9 deletions

View File

@ -1,5 +1,6 @@
package com.xhpc.charging.station.utils.img; package com.xhpc.charging.station.utils.img;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@ -63,15 +64,17 @@ public class DownMaterialUtil {
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];
int len = 0; int len = 0;
FileOutputStream fileOutputStream = null; FileOutputStream fileOutputStream = null;
try { try {
String str = imgNames.get(i); String str = imgNames.get(i);
int poke = 0; int poke = 0;
for(int j = str.length() - 1; j >= 0; j --){ for (int j = str.length() - 1; j >= 0; j--) {
if(str.charAt(j) == 47){ if (str.charAt(j) == 47) {
poke = j; poke = j;
break; break;
} }
@ -168,17 +171,40 @@ public class DownMaterialUtil {
/** /**
* 负责定时删除服务器上面下载下来的二维码压缩包 * 负责定时删除服务器上面下载下来的二维码压缩包
* 个月25号早上3点执行 * 天早上4点执行
* *
* @author WH * @author WH
* @date 2021/11/24 15:50 * @date 2021/11/24 15:50
* @since version-1.0 * @since version-1.0
*/ */
@Scheduled(cron = "0 0 3 25 * ?") @Scheduled(cron = "0 0 4 * * ?")
public void deleteZips() { public static void deleteZips() {
System.out.println(DateUtil.now() + " " + "二维码压缩包清理程序启动");
//遍历指定文件夹下的所有图片 dist //遍历指定文件夹下的所有图片 dist
// new File(environment.getProperty("")) Environment environment = new DownMaterialUtil().environment;
// todo String zipLocation = environment.getProperty("zipLocation");
if (zipLocation == null) {
throw new RuntimeException("bootstrap.yml文件中的zipLocation位置不对请检查");
}
File zipDirectory = new File(zipLocation);
File[] zipFile = zipDirectory.listFiles();
if (zipFile == null) {
System.out.println("没有二维码压缩包可以删除");
return;
}
for (File file : zipFile) {
if (file.getName().contains("QRcodeMaterial")) {
file.delete();
System.out.println(DateUtil.now() + " " + file.getName() + "已被删除");
}
}
System.out.println(DateUtil.now() + " " + "二维码压缩包清理程序结束");
}
public static void main(String[] args) {
deleteZips();
} }
} }

View File

@ -37,3 +37,6 @@ fullImgDestPath: "/www/wwwroot/xhpc.scxhua.com/xhpc-charging-stion/XiaoHuaFullIm
#底图图片存放位置: #底图图片存放位置:
#bottomImg: "D:\\Enterprise_Resources\\XiaoHuaMaterialImgs\\BottomImg.png" #bottomImg: "D:\\Enterprise_Resources\\XiaoHuaMaterialImgs\\BottomImg.png"
bottomImg: "/www/wwwroot/xhpc.scxhua.com/xhpc-charging-stion/BottomImg.png" bottomImg: "/www/wwwroot/xhpc.scxhua.com/xhpc-charging-stion/BottomImg.png"
#生成的二维码zip包位置
#zipLocation: "D:\\Enterprise_Resources\\QrZip"
zipLocation: "/www/wwwroot/xhpc.scxhua.com/dist"