将生成二维码压缩包添加定时删除任务
This commit is contained in:
parent
4c7c67602a
commit
d932701401
@ -1,5 +1,6 @@
|
||||
package com.xhpc.charging.station.utils.img;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
@ -63,15 +64,17 @@ public class DownMaterialUtil {
|
||||
|
||||
for (int i = 0; i < urls.size(); i++) {
|
||||
InputStream inputStream = getInputStream(urls.get(i));
|
||||
if (null == inputStream) continue;
|
||||
if (null == inputStream) {
|
||||
continue;
|
||||
}
|
||||
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){
|
||||
for (int j = str.length() - 1; j >= 0; j--) {
|
||||
if (str.charAt(j) == 47) {
|
||||
poke = j;
|
||||
break;
|
||||
}
|
||||
@ -168,17 +171,40 @@ public class DownMaterialUtil {
|
||||
|
||||
/**
|
||||
* 负责定时删除服务器上面下载下来的二维码压缩包
|
||||
* 每个月25号早上3点执行
|
||||
* 每天早上4点执行
|
||||
*
|
||||
* @author WH
|
||||
* @date 2021/11/24 15:50
|
||||
* @since version-1.0
|
||||
*/
|
||||
@Scheduled(cron = "0 0 3 25 * ?")
|
||||
public void deleteZips() {
|
||||
@Scheduled(cron = "0 0 4 * * ?")
|
||||
public static void deleteZips() {
|
||||
|
||||
System.out.println(DateUtil.now() + " " + "二维码压缩包清理程序启动");
|
||||
//遍历指定文件夹下的所有图片 dist
|
||||
// new File(environment.getProperty(""))
|
||||
// todo
|
||||
Environment environment = new DownMaterialUtil().environment;
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,4 +36,7 @@ destPath: "/www/wwwroot/xhpc.scxhua.com/xhpc-charging-stion/XiaoHuaFullImgs"
|
||||
fullImgDestPath: "/www/wwwroot/xhpc.scxhua.com/xhpc-charging-stion/XiaoHuaFullImgs/"
|
||||
#底图图片存放位置:
|
||||
#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"
|
||||
Loading…
x
Reference in New Issue
Block a user