压缩下载

This commit is contained in:
cwchen 2025-04-08 17:47:55 +08:00
parent 6df5b4c98a
commit a4835dcda7
13 changed files with 53 additions and 25 deletions

View File

@ -41,7 +41,7 @@ public class DownloadController {
@GetMapping(value = "/progress", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter streamProgress(@RequestParam String taskId) {
SseEmitter emitter = new SseEmitter(3600000L); // 1小时超时
SseEmitter emitter = new SseEmitter(10800000L); // 3小时超时
downloadService.addProgressListener(taskId, new DownloadService.DownloadProgressListener() {
@Override

View File

@ -1,6 +1,7 @@
package com.bonus.imgTool.backstage.dao;
import com.bonus.imgTool.backstage.entity.*;
import com.bonus.imgTool.task.entity.DownloadTaskVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -125,13 +126,12 @@ public interface SynthesisQueryDao {
/**
* 添加下载任务
* @param taskId
* @param nowTime
* @param taskVo
* @return void
* @author cwchen
* @date 2025/4/8 9:37
*/
void addTaskDownload(@Param("taskId") String taskId, @Param("nowTime") String nowTime,@Param("filePath") String filePath);
void addTaskDownload(DownloadTaskVo taskVo);
/**
* 查询图片未生成水印照片的数据
@ -150,4 +150,14 @@ public interface SynthesisQueryDao {
* @date 2025/4/8 16:40
*/
void updateBatchSyData(List<SynthesisQueryVo> list);
/**
* 更新下载任务
* @param taskVo
* @param nowTime
* @return void
* @author cwchen
* @date 2025/4/8 16:40
*/
void updateTaskDownload(@Param("params") DownloadTaskVo taskVo,@Param("nowTime") String nowTime);
}

View File

@ -3,6 +3,7 @@ package com.bonus.imgTool.backstage.service;
import com.bonus.imgTool.backstage.dao.SynthesisQueryDao;
import com.bonus.imgTool.backstage.entity.Photo;
import com.bonus.imgTool.backstage.entity.SynthesisQueryVo;
import com.bonus.imgTool.task.entity.DownloadTaskVo;
import com.bonus.imgTool.utils.DateTimeHelper;
import com.bonus.imgTool.utils.HighQualityWatermark;
import com.bonus.imgTool.utils.SystemUtils;
@ -67,6 +68,11 @@ public class DownloadService {
if(Objects.equals(type,"2")){
generateWatermark(proId);
}
// 添加下载任务
DownloadTaskVo taskVo = new DownloadTaskVo();
taskVo.setTaskId(taskId);
taskVo.setTempFilePath(zipFilePath.toString());
synthesisQueryDao.addTaskDownload(taskVo);
// 获取照片列表
List<Photo> photos = getPhotosForAlbum(proId,type);
int total = photos.size();
@ -109,9 +115,10 @@ public class DownloadService {
taskFileMap.put(taskId, finalFilePath.toString());
// 通知完成
notifyComplete(taskId, "/imgTool/api/download/file?taskId=" + taskId);
// 添加下载任务
// 更新下载任务
String nowTime = DateTimeHelper.currentTwoHours();
synthesisQueryDao.addTaskDownload(taskId,nowTime,finalFilePath.toString());
taskVo.setFilePath(finalFilePath.toString());
synthesisQueryDao.updateTaskDownload(taskVo,nowTime);
} catch (Exception e) {
logger.error("下载任务失败: " + taskId, e);
notifyError(taskId, "文件生成失败: " + e.getMessage());

View File

@ -51,7 +51,7 @@ public class DeleteFileTask {
* 删除文件定时任务
* 使用 cron 表达式指定每十分钟执行一次
*/
@Scheduled(cron = "0 0/10 * ? * *")
@Scheduled(cron = "0 0/5 * ? * *")
@SchedulerLock(name = "StationMonthTask", lockAtMostFor = SCHEDULER_LOCK_MAX, lockAtLeastFor = SCHEDULER_LOCK_MIN)
@Async
public void getHomeCacheTask() {
@ -76,7 +76,6 @@ public class DeleteFileTask {
} catch (Exception e) {
log.error(e.toString(), e);
}
// 删除该日期之前的文件夹
log.info("--------删除缓存文件定时任务执行完毕------");
}

View File

@ -23,4 +23,6 @@ public class DownloadTaskVo {
private Date failureTime;
/**是否删除*/
private String delete;
/**临时路径*/
private String tempFilePath;
}

View File

@ -182,7 +182,7 @@ public class Constants
public static final Integer TYPE4 = 4;
public static final Integer TRY_COUNT_NUM = 10;
/**角色级别*/
/**角色级别 项目部级*/
public static final String ROLE_LEVEL = "0";

View File

@ -70,17 +70,15 @@
</trim>
</insert>
<!--添加下载任务-->
<insert id="addTaskDownload">
<insert id="addTaskDownload" useGeneratedKeys="true" keyProperty="id">
insert into tb_download_task
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="taskId != null and taskId != ''">task_id,</if>
<if test="nowTime != null and nowTime != ''">failure_time,</if>
<if test="filePath != null and filePath != ''">file_path,</if>
<if test="tempPath != null and tempPath != ''">temp_file_path,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="taskId != null and taskId != ''">#{taskId},</if>
<if test="nowTime != null and nowTime != ''">#{nowTime},</if>
<if test="filePath != null and filePath != ''">#{filePath},</if>
<if test="tempPath != null and filePath != ''">#{tempPath},</if>
</trim>
</insert>
<delete id="deleteComprehensiveQuery">
@ -99,7 +97,7 @@
FROM tb_comprehensive_query tcq
LEFT JOIN sys_file_resource sfr ON tcq.id = sfr.source_id AND tcq.upload_type = sfr.upload_type AND sfr.is_active = '1'
WHERE tcq.is_active = '1'
<if test="roleLevel = 0 and proIds != null and proIds.size() > 0">
<if test="roleLevel = '0' and proIds != null and proIds.size() > 0">
AND tcq.pro_id IN
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
#{proId}
@ -216,7 +214,7 @@
</foreach>
</if>
</if>
<if test="roleLevel = 0 and proIds != null and proIds.size() > 0">
<if test="roleLevel = '0' and proIds != null and proIds.size() > 0">
AND tcq.pro_id IN
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
#{proId}
@ -249,7 +247,7 @@
LEFT JOIN tb_project tp ON tcq.pro_id = tp.id
LEFT JOIN sys_file_resource sfr ON tcq.id = sfr.source_id AND tcq.upload_type = sfr.upload_type AND sfr.is_active = '1'
<where>
<if test="roleLevel = 0 and proIds != null and proIds.size() > 0">
<if test="roleLevel = '0' and proIds != null and proIds.size() > 0">
AND tcq.pro_id IN
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
#{proId}
@ -300,7 +298,7 @@
AND tcq.upload_type = #{uploadType}
</if>
</if>
<if test="roleLevel = 0 and proIds != null and proIds.size() > 0">
<if test="roleLevel = '0' and proIds != null and proIds.size() > 0">
AND tcq.pro_id IN
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
#{proId}
@ -406,7 +404,7 @@
AND INSTR(tcq.title,#{title}) > 0 AND tcq.upload_type = '5'
</if>
</if>
<if test="roleLevel = 0 and proIds != null and proIds.size() > 0">
<if test="roleLevel = '0' and proIds != null and proIds.size() > 0">
AND tcq.pro_id IN
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
#{proId}
@ -544,4 +542,8 @@
WHERE id = #{item.id}
</foreach>
</update>
<!--更新下载任务-->
<update id="updateTaskDownload">
UPDATE tb_download_task SET file_path = #{params.filePath},failure_time = #{nowTime} WHERE id = #{id}
</update>
</mapper>

View File

@ -18,5 +18,11 @@
file_path AS filePath
FROM tb_download_task
WHERE is_delete = '1' AND NOW() > failure_time
UNION ALL
SELECT id,
task_id AS taskId,
temp_file_path AS filePath
FROM tb_download_task
WHERE is_delete = '1' AND TIMESTAMPDIFF(HOUR, create_time, NOW()) > 6
</select>
</mapper>

View File

@ -51,7 +51,7 @@
SELECT id,name
FROM tb_project
<where>
<if test="roleLevel = 0 and proIds != null and proIds.size() > 0">
<if test="roleLevel = '0' and proIds != null and proIds.size() > 0">
AND id IN
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
#{proId}

View File

@ -1,7 +1,7 @@
let proId = decryptCBC(getUrlParam('proId'));
let type = decryptCBC(getUrlParam('type'));
let title = decryptCBC(getUrlParam('title'));
let proName = decryptCBC(getUrlParam('proName'));
let title = decryptCBC(decodeURIComponent(getUrlParam('title')));
let proName = decryptCBC(decodeURIComponent(getUrlParam('proName')));
$('#title').html(proName +"-"+ title);
document.getElementById('downloadBtn').addEventListener('click', function() {
const btn = this;

View File

@ -208,5 +208,5 @@ function downloadExcel(){
/**下载原图/水印*/
function downloadFile(obj,type){
let title = type === 1 ? "原图下载" : "水印下载";
window.open("./fileDownload.html?type="+encryptCBC(type)+"&proId="+encryptCBC(obj.proId) + "&title=" + encryptCBC(title) + "&proName=" + encryptCBC(obj.proName));
window.open("./fileDownload.html?type="+encryptCBC(type)+"&proId="+encryptCBC(obj.proId) + "&title=" + encryptCBC(encodeURIComponent(title)) + "&proName=" + encryptCBC(encodeURIComponent(obj.proName)));
}

View File

@ -66,8 +66,10 @@
}
</style>
<body>
<h2><span style="color: red;">提示:请勿关闭浏览器和浏览器窗口!!!</span></h2>
<h3 id="title"></h3>
<p>点击下方按钮下载所有照片<span style="color: red;">(请勿关闭浏览器和浏览器窗口)</span></p>
<p>点击下方按钮下载所有照</p>
<button id="downloadBtn">下载照片压缩包</button>

View File

@ -67,7 +67,7 @@
<div class="layui-input-inline">
<!-- <select id="project" lay-verify="required" name="project" class="form-control input-sm">-->
<!-- </select>-->
<select class="layui-select" name="project" id="project" xm-select="project" xm-select-show-count='3'>
<select name="project" xm-select-search xm-select-search-type="dl" id="project" xm-select="project" xm-select-show-count='3'>
</select>
</div>
</div>