改为模糊查询
parent
8403d560ea
commit
29badb21bc
@ -0,0 +1,39 @@
|
|||||||
|
package com.sztzjy.resource_center.entity.admin;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author xcj
|
||||||
|
* @Date 2024/7/16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AdminCaseReturnDto {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty("数据名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("标签表ID")
|
||||||
|
private String labelId;
|
||||||
|
|
||||||
|
@ApiModelProperty("图片地址")
|
||||||
|
private String pictureUrl;
|
||||||
|
|
||||||
|
@ApiModelProperty("0下架 1上架")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@ApiModelProperty("内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@ApiModelProperty("目录")
|
||||||
|
private String catalog;
|
||||||
|
|
||||||
|
@ApiModelProperty("标签集")
|
||||||
|
private List<AdminDataLabel> adminDataLabels;
|
||||||
|
|
||||||
|
@ApiModelProperty("文件集")
|
||||||
|
private List<AdminFile> adminFiles;
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
package com.sztzjy.resource_center.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CompressUtil {
|
||||||
|
private static String filePath;
|
||||||
|
|
||||||
|
@Value("${file.path}")
|
||||||
|
public void setKey(String filePath) { //注意这里的set方法不能是静态的
|
||||||
|
CompressUtil.filePath = filePath;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 生成zip压缩文件
|
||||||
|
* @param filePaths
|
||||||
|
* @param zipFilePath
|
||||||
|
* @param keepDirStructure
|
||||||
|
*/
|
||||||
|
public static void compress(List<Map<String, String>> filePaths, String zipFilePath, Boolean keepDirStructure) {
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
File zipFile = new File(zipFilePath);
|
||||||
|
try {
|
||||||
|
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
|
||||||
|
for (int i = 0; i < filePaths.size(); i++) {
|
||||||
|
String relativeName = filePaths.get(i).get("name");
|
||||||
|
String relativePath = filePath+filePaths.get(i).get("file_url")+"/"+relativeName;
|
||||||
|
if (StringUtils.isEmpty(relativePath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
File sourceFile = new File(relativePath);
|
||||||
|
if (sourceFile == null || !sourceFile.exists()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FileInputStream fis = new FileInputStream(sourceFile);
|
||||||
|
if (keepDirStructure != null && keepDirStructure) {
|
||||||
|
zos.putNextEntry(new ZipEntry(relativePath));
|
||||||
|
} else {
|
||||||
|
zos.putNextEntry(new ZipEntry(i + "_" + relativeName));
|
||||||
|
}
|
||||||
|
int len;
|
||||||
|
while ((len = fis.read(buf)) > 0) {
|
||||||
|
zos.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
zos.closeEntry();
|
||||||
|
// zos.close();
|
||||||
|
}
|
||||||
|
zos.close();
|
||||||
|
if (!zipFile.exists()) {
|
||||||
|
zipFile.createNewFile();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载zip
|
||||||
|
*
|
||||||
|
* @param response
|
||||||
|
* @param zipName 浏览器header中zip名称
|
||||||
|
* @param zipFile zipFile文件
|
||||||
|
*/
|
||||||
|
public static void downloadZip(HttpServletResponse response, String zipName, File zipFile) {
|
||||||
|
//下载文件
|
||||||
|
try {
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
response.setContentType("application/zip");
|
||||||
|
response.setHeader("Content-Disposition", "attachment;FileName=" + zipName);
|
||||||
|
ServletOutputStream out = response.getOutputStream();
|
||||||
|
int len = 0;
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
FileInputStream fis = new FileInputStream(zipFile);
|
||||||
|
while ((len = fis.read(buffer)) > 0) {
|
||||||
|
out.write(buffer, 0, len);
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
fis.close();
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue