压缩下载
This commit is contained in:
parent
6df5b4c98a
commit
a4835dcda7
|
|
@ -41,7 +41,7 @@ public class DownloadController {
|
||||||
|
|
||||||
@GetMapping(value = "/progress", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
@GetMapping(value = "/progress", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
public SseEmitter streamProgress(@RequestParam String taskId) {
|
public SseEmitter streamProgress(@RequestParam String taskId) {
|
||||||
SseEmitter emitter = new SseEmitter(3600000L); // 1小时超时
|
SseEmitter emitter = new SseEmitter(10800000L); // 3小时超时
|
||||||
|
|
||||||
downloadService.addProgressListener(taskId, new DownloadService.DownloadProgressListener() {
|
downloadService.addProgressListener(taskId, new DownloadService.DownloadProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bonus.imgTool.backstage.dao;
|
package com.bonus.imgTool.backstage.dao;
|
||||||
|
|
||||||
import com.bonus.imgTool.backstage.entity.*;
|
import com.bonus.imgTool.backstage.entity.*;
|
||||||
|
import com.bonus.imgTool.task.entity.DownloadTaskVo;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|
@ -125,13 +126,12 @@ public interface SynthesisQueryDao {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加下载任务
|
* 添加下载任务
|
||||||
* @param taskId
|
* @param taskVo
|
||||||
* @param nowTime
|
|
||||||
* @return void
|
* @return void
|
||||||
* @author cwchen
|
* @author cwchen
|
||||||
* @date 2025/4/8 9:37
|
* @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
|
* @date 2025/4/8 16:40
|
||||||
*/
|
*/
|
||||||
void updateBatchSyData(List<SynthesisQueryVo> list);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.bonus.imgTool.backstage.service;
|
||||||
import com.bonus.imgTool.backstage.dao.SynthesisQueryDao;
|
import com.bonus.imgTool.backstage.dao.SynthesisQueryDao;
|
||||||
import com.bonus.imgTool.backstage.entity.Photo;
|
import com.bonus.imgTool.backstage.entity.Photo;
|
||||||
import com.bonus.imgTool.backstage.entity.SynthesisQueryVo;
|
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.DateTimeHelper;
|
||||||
import com.bonus.imgTool.utils.HighQualityWatermark;
|
import com.bonus.imgTool.utils.HighQualityWatermark;
|
||||||
import com.bonus.imgTool.utils.SystemUtils;
|
import com.bonus.imgTool.utils.SystemUtils;
|
||||||
|
|
@ -67,6 +68,11 @@ public class DownloadService {
|
||||||
if(Objects.equals(type,"2")){
|
if(Objects.equals(type,"2")){
|
||||||
generateWatermark(proId);
|
generateWatermark(proId);
|
||||||
}
|
}
|
||||||
|
// 添加下载任务
|
||||||
|
DownloadTaskVo taskVo = new DownloadTaskVo();
|
||||||
|
taskVo.setTaskId(taskId);
|
||||||
|
taskVo.setTempFilePath(zipFilePath.toString());
|
||||||
|
synthesisQueryDao.addTaskDownload(taskVo);
|
||||||
// 获取照片列表
|
// 获取照片列表
|
||||||
List<Photo> photos = getPhotosForAlbum(proId,type);
|
List<Photo> photos = getPhotosForAlbum(proId,type);
|
||||||
int total = photos.size();
|
int total = photos.size();
|
||||||
|
|
@ -109,9 +115,10 @@ public class DownloadService {
|
||||||
taskFileMap.put(taskId, finalFilePath.toString());
|
taskFileMap.put(taskId, finalFilePath.toString());
|
||||||
// 通知完成
|
// 通知完成
|
||||||
notifyComplete(taskId, "/imgTool/api/download/file?taskId=" + taskId);
|
notifyComplete(taskId, "/imgTool/api/download/file?taskId=" + taskId);
|
||||||
// 添加下载任务
|
// 更新下载任务
|
||||||
String nowTime = DateTimeHelper.currentTwoHours();
|
String nowTime = DateTimeHelper.currentTwoHours();
|
||||||
synthesisQueryDao.addTaskDownload(taskId,nowTime,finalFilePath.toString());
|
taskVo.setFilePath(finalFilePath.toString());
|
||||||
|
synthesisQueryDao.updateTaskDownload(taskVo,nowTime);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("下载任务失败: " + taskId, e);
|
logger.error("下载任务失败: " + taskId, e);
|
||||||
notifyError(taskId, "文件生成失败: " + e.getMessage());
|
notifyError(taskId, "文件生成失败: " + e.getMessage());
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public class DeleteFileTask {
|
||||||
* 删除文件定时任务
|
* 删除文件定时任务
|
||||||
* 使用 cron 表达式指定每十分钟,执行一次
|
* 使用 cron 表达式指定每十分钟,执行一次
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 0/10 * ? * *")
|
@Scheduled(cron = "0 0/5 * ? * *")
|
||||||
@SchedulerLock(name = "StationMonthTask", lockAtMostFor = SCHEDULER_LOCK_MAX, lockAtLeastFor = SCHEDULER_LOCK_MIN)
|
@SchedulerLock(name = "StationMonthTask", lockAtMostFor = SCHEDULER_LOCK_MAX, lockAtLeastFor = SCHEDULER_LOCK_MIN)
|
||||||
@Async
|
@Async
|
||||||
public void getHomeCacheTask() {
|
public void getHomeCacheTask() {
|
||||||
|
|
@ -76,7 +76,6 @@ public class DeleteFileTask {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.toString(), e);
|
log.error(e.toString(), e);
|
||||||
}
|
}
|
||||||
// 删除该日期之前的文件夹
|
|
||||||
log.info("--------删除缓存文件定时任务执行完毕------");
|
log.info("--------删除缓存文件定时任务执行完毕------");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,6 @@ public class DownloadTaskVo {
|
||||||
private Date failureTime;
|
private Date failureTime;
|
||||||
/**是否删除*/
|
/**是否删除*/
|
||||||
private String delete;
|
private String delete;
|
||||||
|
/**临时路径*/
|
||||||
|
private String tempFilePath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ public class Constants
|
||||||
public static final Integer TYPE4 = 4;
|
public static final Integer TYPE4 = 4;
|
||||||
public static final Integer TRY_COUNT_NUM = 10;
|
public static final Integer TRY_COUNT_NUM = 10;
|
||||||
|
|
||||||
/**角色级别*/
|
/**角色级别 项目部级*/
|
||||||
public static final String ROLE_LEVEL = "0";
|
public static final String ROLE_LEVEL = "0";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,17 +70,15 @@
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
<!--添加下载任务-->
|
<!--添加下载任务-->
|
||||||
<insert id="addTaskDownload">
|
<insert id="addTaskDownload" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into tb_download_task
|
insert into tb_download_task
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="taskId != null and taskId != ''">task_id,</if>
|
<if test="taskId != null and taskId != ''">task_id,</if>
|
||||||
<if test="nowTime != null and nowTime != ''">failure_time,</if>
|
<if test="tempPath != null and tempPath != ''">temp_file_path,</if>
|
||||||
<if test="filePath != null and filePath != ''">file_path,</if>
|
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="taskId != null and taskId != ''">#{taskId},</if>
|
<if test="taskId != null and taskId != ''">#{taskId},</if>
|
||||||
<if test="nowTime != null and nowTime != ''">#{nowTime},</if>
|
<if test="tempPath != null and filePath != ''">#{tempPath},</if>
|
||||||
<if test="filePath != null and filePath != ''">#{filePath},</if>
|
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
<delete id="deleteComprehensiveQuery">
|
<delete id="deleteComprehensiveQuery">
|
||||||
|
|
@ -99,7 +97,7 @@
|
||||||
FROM tb_comprehensive_query tcq
|
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'
|
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'
|
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
|
AND tcq.pro_id IN
|
||||||
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
||||||
#{proId}
|
#{proId}
|
||||||
|
|
@ -216,7 +214,7 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</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
|
AND tcq.pro_id IN
|
||||||
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
||||||
#{proId}
|
#{proId}
|
||||||
|
|
@ -249,7 +247,7 @@
|
||||||
LEFT JOIN tb_project tp ON tcq.pro_id = tp.id
|
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'
|
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>
|
<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
|
AND tcq.pro_id IN
|
||||||
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
||||||
#{proId}
|
#{proId}
|
||||||
|
|
@ -300,7 +298,7 @@
|
||||||
AND tcq.upload_type = #{uploadType}
|
AND tcq.upload_type = #{uploadType}
|
||||||
</if>
|
</if>
|
||||||
</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
|
AND tcq.pro_id IN
|
||||||
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
||||||
#{proId}
|
#{proId}
|
||||||
|
|
@ -406,7 +404,7 @@
|
||||||
AND INSTR(tcq.title,#{title}) > 0 AND tcq.upload_type = '5'
|
AND INSTR(tcq.title,#{title}) > 0 AND tcq.upload_type = '5'
|
||||||
</if>
|
</if>
|
||||||
</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
|
AND tcq.pro_id IN
|
||||||
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
||||||
#{proId}
|
#{proId}
|
||||||
|
|
@ -544,4 +542,8 @@
|
||||||
WHERE id = #{item.id}
|
WHERE id = #{item.id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
<!--更新下载任务-->
|
||||||
|
<update id="updateTaskDownload">
|
||||||
|
UPDATE tb_download_task SET file_path = #{params.filePath},failure_time = #{nowTime} WHERE id = #{id}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,11 @@
|
||||||
file_path AS filePath
|
file_path AS filePath
|
||||||
FROM tb_download_task
|
FROM tb_download_task
|
||||||
WHERE is_delete = '1' AND NOW() > failure_time
|
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>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
SELECT id,name
|
SELECT id,name
|
||||||
FROM tb_project
|
FROM tb_project
|
||||||
<where>
|
<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
|
AND id IN
|
||||||
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
<foreach collection="proIds" item="proId" open="(" separator="," close=")">
|
||||||
#{proId}
|
#{proId}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
let proId = decryptCBC(getUrlParam('proId'));
|
let proId = decryptCBC(getUrlParam('proId'));
|
||||||
let type = decryptCBC(getUrlParam('type'));
|
let type = decryptCBC(getUrlParam('type'));
|
||||||
let title = decryptCBC(getUrlParam('title'));
|
let title = decryptCBC(decodeURIComponent(getUrlParam('title')));
|
||||||
let proName = decryptCBC(getUrlParam('proName'));
|
let proName = decryptCBC(decodeURIComponent(getUrlParam('proName')));
|
||||||
$('#title').html(proName +"-"+ title);
|
$('#title').html(proName +"-"+ title);
|
||||||
document.getElementById('downloadBtn').addEventListener('click', function() {
|
document.getElementById('downloadBtn').addEventListener('click', function() {
|
||||||
const btn = this;
|
const btn = this;
|
||||||
|
|
|
||||||
|
|
@ -208,5 +208,5 @@ function downloadExcel(){
|
||||||
/**下载原图/水印*/
|
/**下载原图/水印*/
|
||||||
function downloadFile(obj,type){
|
function downloadFile(obj,type){
|
||||||
let title = type === 1 ? "原图下载" : "水印下载";
|
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)));
|
||||||
}
|
}
|
||||||
|
|
@ -66,8 +66,10 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<body>
|
<body>
|
||||||
|
<h2><span style="color: red;">提示:请勿关闭浏览器和浏览器窗口!!!</span></h2>
|
||||||
<h3 id="title"></h3>
|
<h3 id="title"></h3>
|
||||||
<p>点击下方按钮下载所有照片<span style="color: red;">(请勿关闭浏览器和浏览器窗口)</span></p>
|
|
||||||
|
<p>点击下方按钮下载所有照</p>
|
||||||
|
|
||||||
<button id="downloadBtn">下载照片压缩包</button>
|
<button id="downloadBtn">下载照片压缩包</button>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<!-- <select id="project" lay-verify="required" name="project" class="form-control input-sm">-->
|
<!-- <select id="project" lay-verify="required" name="project" class="form-control input-sm">-->
|
||||||
<!-- </select>-->
|
<!-- </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>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue