批量下载后文件无法打开,下载内容为空bug修改
This commit is contained in:
parent
c74047eebc
commit
cd8c0a32e3
|
|
@ -93,9 +93,12 @@ public class CoursewareLibraryController {
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
stringBuilder.append(line);
|
stringBuilder.append(line);
|
||||||
}
|
}
|
||||||
String str=decord(stringBuilder.toString());
|
String str = decord(stringBuilder.toString());
|
||||||
|
if (str.startsWith("[") && str.endsWith("]")) {
|
||||||
|
str = str.substring(1, str.length() - 1);
|
||||||
|
}
|
||||||
String courseId = str.split("&")[0].split("=")[1];
|
String courseId = str.split("&")[0].split("=")[1];
|
||||||
String fileType =str.split("&")[1].split("=")[1];
|
String fileType = str.split("&")[1].split("=")[1];
|
||||||
if (!StaticVariableUtils.ONE.equals(fileType)) {
|
if (!StaticVariableUtils.ONE.equals(fileType)) {
|
||||||
dto.setCoursewareId(Integer.parseInt(courseId));
|
dto.setCoursewareId(Integer.parseInt(courseId));
|
||||||
}
|
}
|
||||||
|
|
@ -108,16 +111,17 @@ public class CoursewareLibraryController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String decord(String str){
|
public String decord(String str) {
|
||||||
try{
|
try {
|
||||||
return URLDecoder.decode(str, StandardCharsets.UTF_8.toString());
|
return URLDecoder.decode(str, StandardCharsets.UTF_8.toString());
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
log.error(e.toString(),e);
|
log.error(e.toString(), e);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 课件上传
|
* 课件上传
|
||||||
*
|
*
|
||||||
|
|
@ -146,6 +150,7 @@ public class CoursewareLibraryController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1.新增题库使用的tree 2.移动使用的tree
|
* 1.新增题库使用的tree 2.移动使用的tree
|
||||||
|
*
|
||||||
* @param dto
|
* @param dto
|
||||||
* @return AjaxResult
|
* @return AjaxResult
|
||||||
* @author cwchen
|
* @author cwchen
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -148,7 +151,7 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService {
|
||||||
if (Objects.equals(dto.getFileType(), BusinessConstants.FILE_TYPE)) {
|
if (Objects.equals(dto.getFileType(), BusinessConstants.FILE_TYPE)) {
|
||||||
// 多个文件下载
|
// 多个文件下载
|
||||||
CoursewareVo vo = new CoursewareVo();
|
CoursewareVo vo = new CoursewareVo();
|
||||||
String[] split = dto.getCourseId().split("%252C");
|
String[] split = dto.getCourseId().split("%2C");
|
||||||
List<CoursewareVo> list = mapper.getSelectFileToDownload(split);
|
List<CoursewareVo> list = mapper.getSelectFileToDownload(split);
|
||||||
|
|
||||||
downLoadBatchFile(response, list);
|
downLoadBatchFile(response, list);
|
||||||
|
|
@ -217,7 +220,7 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService {
|
||||||
String tempTime = "temp_" + System.currentTimeMillis();
|
String tempTime = "temp_" + System.currentTimeMillis();
|
||||||
String parentSourceFilePath = upload_path + File.separator + "coursewareZip";
|
String parentSourceFilePath = upload_path + File.separator + "coursewareZip";
|
||||||
if (!new File(parentSourceFilePath).exists()) {
|
if (!new File(parentSourceFilePath).exists()) {
|
||||||
new File(parentSourceFilePath).mkdir();
|
new File(parentSourceFilePath).mkdirs();
|
||||||
}
|
}
|
||||||
String sourceFilePath = parentSourceFilePath + File.separator + tempTime;
|
String sourceFilePath = parentSourceFilePath + File.separator + tempTime;
|
||||||
String zipFilePath = null;
|
String zipFilePath = null;
|
||||||
|
|
@ -245,13 +248,34 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService {
|
||||||
invokeAllTasks(testTaskExecutor,tasks);
|
invokeAllTasks(testTaskExecutor,tasks);
|
||||||
//对/usr/local/bonus/uploadPath/tempTime文件夹进行压缩
|
//对/usr/local/bonus/uploadPath/tempTime文件夹进行压缩
|
||||||
|
|
||||||
|
|
||||||
// Compress files into a zip
|
// Compress files into a zip
|
||||||
String zipFileName = "courseware_" + tempTime + ".zip";
|
String zipFileName = tempTime + ".zip";
|
||||||
zipFilePath = parentSourceFilePath + File.separator + zipFileName;
|
zipFilePath = parentSourceFilePath + File.separator + zipFileName;
|
||||||
zipFolderContents(sourceFilePath, zipFilePath);
|
zipFolder(sourceFilePath, zipFilePath);
|
||||||
// Set response headers
|
File zipFile = new File(zipFilePath);
|
||||||
|
if (!zipFile.exists() || zipFile.isDirectory()) {
|
||||||
|
response.sendError(HttpServletResponse.SC_NOT_FOUND, "文件不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
|
response.setContentType("application/zip");
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=" +
|
||||||
|
URLEncoder.encode(zipFileName, "UTF-8"));
|
||||||
|
response.setContentLength((int) zipFile.length());
|
||||||
|
|
||||||
|
try (InputStream is = new FileInputStream(zipFile);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = is.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// zipFolderContents(sourceFilePath, zipFilePath);
|
||||||
|
// Set response headers
|
||||||
|
/* response.setCharacterEncoding("utf-8");
|
||||||
response.setContentType("application/zip");
|
response.setContentType("application/zip");
|
||||||
response.setHeader("Content-Disposition", "attachment;filename="
|
response.setHeader("Content-Disposition", "attachment;filename="
|
||||||
.concat(String.valueOf(URLEncoder.encode(zipFileName, "UTF-8"))));
|
.concat(String.valueOf(URLEncoder.encode(zipFileName, "UTF-8"))));
|
||||||
|
|
@ -260,19 +284,39 @@ public class CoursewareLibraryServiceImpl implements CoursewareLibraryService {
|
||||||
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
|
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
|
||||||
File sourceFolder = new File(sourceFilePath);
|
File sourceFolder = new File(sourceFilePath);
|
||||||
compressFolderContents(sourceFolder, zos, "");
|
compressFolderContents(sourceFolder, zos, "");
|
||||||
}
|
}*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.toString(), e);
|
log.error(e.toString(), e);
|
||||||
throw new ServiceException("文件下载异常");
|
throw new ServiceException("文件下载异常");
|
||||||
} finally {
|
|
||||||
|
|
||||||
// FileUtil.deleteFolder(Paths.get(sourceFilePath));
|
|
||||||
// if (zipFilePath != null) {
|
|
||||||
// FileUtil.deleteFolder(Paths.get(zipFilePath));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void zipFolder(String sourceFolderPath, String zipFilePath) throws IOException {
|
||||||
|
Path sourcePath = Paths.get(sourceFolderPath);
|
||||||
|
if (!Files.exists(sourcePath) || !Files.isDirectory(sourcePath)) {
|
||||||
|
throw new IllegalArgumentException("源文件夹不存在或不是目录: " + sourceFolderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path zipPath = Paths.get(zipFilePath);
|
||||||
|
try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(zipPath))) {
|
||||||
|
Files.walk(sourcePath)
|
||||||
|
.filter(path -> !Files.isDirectory(path)) // 只处理文件,排除目录本身
|
||||||
|
.forEach(path -> {
|
||||||
|
try {
|
||||||
|
// 计算相对于源文件夹的相对路径
|
||||||
|
Path targetPath = sourcePath.relativize(path);
|
||||||
|
ZipEntry zipEntry = new ZipEntry(targetPath.toString().replace("\\", "/"));
|
||||||
|
zos.putNextEntry(zipEntry);
|
||||||
|
|
||||||
|
// 将文件内容写入 ZIP 输出流
|
||||||
|
Files.copy(path, zos);
|
||||||
|
|
||||||
|
zos.closeEntry();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("无法添加文件到ZIP: " + path + ", 错误信息: " + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
public static boolean zipFolderContents(String sourceFolderPath, String zipFilePath) {
|
public static boolean zipFolderContents(String sourceFolderPath, String zipFilePath) {
|
||||||
try {
|
try {
|
||||||
FileOutputStream fos = new FileOutputStream(zipFilePath);
|
FileOutputStream fos = new FileOutputStream(zipFilePath);
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,10 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
|
|
||||||
@Value("${user.url}")
|
@Value("${user.url}")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信内容处理
|
* 短信内容处理
|
||||||
|
*
|
||||||
* @param bean 实体
|
* @param bean 实体
|
||||||
* @return 短信内容
|
* @return 短信内容
|
||||||
*/
|
*/
|
||||||
|
|
@ -112,10 +114,10 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
private String getMessage(BaseBean bean) {
|
private String getMessage(BaseBean bean) {
|
||||||
String content;
|
String content;
|
||||||
if (StaticVariableUtils.ZERO_01.equals(bean.getUserType())) {
|
if (StaticVariableUtils.ZERO_01.equals(bean.getUserType())) {
|
||||||
content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:"+url+
|
content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:" + url +
|
||||||
";初始账号:" + bean.getUuid() + ",初始密码:" + supervisionPassword;
|
";初始账号:" + bean.getUuid() + ",初始密码:" + supervisionPassword;
|
||||||
} else {
|
} else {
|
||||||
content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:"+url+
|
content = bean.getProName() + "工程即将开工,请及时上传相关入场文件!浏览器网址:" + url +
|
||||||
"初始账号:" + bean.getUuid() + ",初始密码:" + contractorPassword;
|
"初始账号:" + bean.getUuid() + ",初始密码:" + contractorPassword;
|
||||||
}
|
}
|
||||||
return content;
|
return content;
|
||||||
|
|
@ -159,7 +161,7 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
projectMapper.delConsPersonToPcp(project);
|
projectMapper.delConsPersonToPcp(project);
|
||||||
projectMapper.delConsPersonToLk(project);
|
projectMapper.delConsPersonToLk(project);
|
||||||
|
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
log.error("Failed to delete project due to exception", e);
|
log.error("Failed to delete project due to exception", e);
|
||||||
}
|
}
|
||||||
|
|
@ -178,12 +180,12 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
//设置回滚点
|
//设置回滚点
|
||||||
Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
|
Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
|
||||||
try {
|
try {
|
||||||
if(StringHelper.isNullOrEmptyString(bean.getJlId())){
|
if (StringHelper.isNullOrEmptyString(bean.getJlId())) {
|
||||||
return AjaxResult.error("请先选择监理单位");
|
return AjaxResult.error("请先选择监理单位");
|
||||||
}else {
|
} else {
|
||||||
//对监理人员信息进行赋值
|
//对监理人员信息进行赋值
|
||||||
SupervisoryUnit unit= projectMapper.getSupervisoryUnitById(bean);
|
SupervisoryUnit unit = projectMapper.getSupervisoryUnitById(bean);
|
||||||
if(unit==null){
|
if (unit == null) {
|
||||||
return AjaxResult.error("监理单位不存在");
|
return AjaxResult.error("监理单位不存在");
|
||||||
}
|
}
|
||||||
bean.setJlUuid(unit.getJlUuid());
|
bean.setJlUuid(unit.getJlUuid());
|
||||||
|
|
@ -245,15 +247,16 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 手动进行回滚
|
// 手动进行回滚
|
||||||
TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
|
TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
|
||||||
log.error(e.toString(),e);
|
log.error(e.toString(), e);
|
||||||
}
|
}
|
||||||
return AjaxResult.error("添加总监人员失败,请联系管理员!");
|
return AjaxResult.error("添加总监人员失败,请联系管理员!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult addSupervisoryUnitUser(SupervisoryUnit bean) {
|
public AjaxResult addSupervisoryUnitUser(SupervisoryUnit bean) {
|
||||||
try{
|
try {
|
||||||
int nums=projectMapper.getSupervisoryUnitUser(bean);
|
int nums = projectMapper.getSupervisoryUnitUser(bean);
|
||||||
if(nums>0){
|
if (nums > 0) {
|
||||||
return AjaxResult.error("监理单位名称已存在");
|
return AjaxResult.error("监理单位名称已存在");
|
||||||
}
|
}
|
||||||
// 新增监理信息到人员表
|
// 新增监理信息到人员表
|
||||||
|
|
@ -261,36 +264,38 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
bean.setCreatePerson(SecurityUtils.getUsername());
|
bean.setCreatePerson(SecurityUtils.getUsername());
|
||||||
bean.setCreatePersonId(String.valueOf(SecurityUtils.getUserId()));
|
bean.setCreatePersonId(String.valueOf(SecurityUtils.getUserId()));
|
||||||
bean.setUuid(StringUtils.getUuid());
|
bean.setUuid(StringUtils.getUuid());
|
||||||
int successNum=projectMapper.addSupervisoryUnitUser(bean);
|
int successNum = projectMapper.addSupervisoryUnitUser(bean);
|
||||||
if(successNum<1){
|
if (successNum < 1) {
|
||||||
return AjaxResult.error("监理单位添加失败,请联系管理员");
|
return AjaxResult.error("监理单位添加失败,请联系管理员");
|
||||||
}
|
}
|
||||||
return AjaxResult.success("添加成功",bean);
|
return AjaxResult.success("添加成功", bean);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
log.error(e.toString(),e);
|
log.error(e.toString(), e);
|
||||||
}
|
}
|
||||||
return AjaxResult.error("监理单位添加失败,请联系管理员");
|
return AjaxResult.error("监理单位添加失败,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询工程必填项
|
* 查询工程必填项
|
||||||
|
*
|
||||||
* @param entity
|
* @param entity
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult getProRequest(Project entity) {
|
public AjaxResult getProRequest(Project entity) {
|
||||||
try{
|
try {
|
||||||
List<String> list=projectMapper.getProRequest(entity);
|
List<String> list = projectMapper.getProRequest(entity);
|
||||||
String data= String.join(",", list);
|
String data = String.join(",", list);
|
||||||
return AjaxResult.success(data);
|
return AjaxResult.success(data);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
log.error(e.toString(),e);
|
log.error(e.toString(), e);
|
||||||
}
|
}
|
||||||
return AjaxResult.error("查询参数异常");
|
return AjaxResult.error("查询参数异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增承包商单位
|
* 新增承包商单位
|
||||||
|
*
|
||||||
* @param bean 监理单位实体
|
* @param bean 监理单位实体
|
||||||
* @return 是否新增成功
|
* @return 是否新增成功
|
||||||
*/
|
*/
|
||||||
|
|
@ -528,6 +533,31 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
throw new RuntimeException("Failed to add address project");
|
throw new RuntimeException("Failed to add address project");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//插入承包商-工程关联信息(先删后增---临时先放开 后期可能会删除)
|
||||||
|
projectMapper.delConsProject(project);
|
||||||
|
projectMapper.delMaterialProject(project);
|
||||||
|
projectMapper.delConsPersonToPcp(project);
|
||||||
|
projectMapper.delConsPersonToLk(project);
|
||||||
|
for (int i = 0; i < project.getConsArr().size(); i++) {
|
||||||
|
project.setConsId(projectMapper.getConsUuid(project.getConsArr().get(i).getValue()));
|
||||||
|
project.setRelateUuid(StringUtils.getUuid());
|
||||||
|
result = projectMapper.addConsProject(project);
|
||||||
|
if (result <= 0) {
|
||||||
|
throw new RuntimeException("Failed to add cons project");
|
||||||
|
}
|
||||||
|
for (int j = 0; j < project.getConsArr().get(i).getCheckList().size(); j++) {
|
||||||
|
//插入材料-工程关联信息
|
||||||
|
project.setMaterialId(project.getConsArr().get(i).getCheckList().get(j));
|
||||||
|
project.setRelateUuid(StringUtils.getUuid());
|
||||||
|
project.setConsId(project.getConsArr().get(i).getValue());
|
||||||
|
result = projectMapper.addMaterialProject(project);
|
||||||
|
if (result <= 0) {
|
||||||
|
throw new RuntimeException("Failed to add material project");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO 获取承包商信息 --- 新增承包商信息到承包商人员表
|
||||||
|
addConsPerson(project);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = 0;
|
result = 0;
|
||||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
|
@ -536,7 +566,6 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入关联信息
|
* 插入关联信息
|
||||||
*
|
*
|
||||||
|
|
@ -588,6 +617,7 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增监理人员
|
* 新增监理人员
|
||||||
*
|
*
|
||||||
|
|
@ -603,6 +633,7 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
//插入关联表
|
//插入关联表
|
||||||
projectMapper.addSupPersonToLk(subPerson);
|
projectMapper.addSupPersonToLk(subPerson);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增承包商人员
|
* 新增承包商人员
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue