压缩下载
This commit is contained in:
parent
3e09ea7d39
commit
6df5b4c98a
|
|
@ -23,7 +23,7 @@ import java.util.Map;
|
|||
* @author:cwchen
|
||||
* @date:2025-04-07-13:23
|
||||
* @version:1.0
|
||||
* @description:文件下载
|
||||
* @description:原图/水印图片文件下载
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/download")
|
||||
|
|
|
|||
|
|
@ -132,4 +132,22 @@ public interface SynthesisQueryDao {
|
|||
* @date 2025/4/8 9:37
|
||||
*/
|
||||
void addTaskDownload(@Param("taskId") String taskId, @Param("nowTime") String nowTime,@Param("filePath") String filePath);
|
||||
|
||||
/**
|
||||
* 查询图片未生成水印照片的数据
|
||||
* @param proId
|
||||
* @return List<SynthesisQueryVo>
|
||||
* @author cwchen
|
||||
* @date 2025/4/8 16:32
|
||||
*/
|
||||
List<SynthesisQueryVo> generateWatermark(String proId);
|
||||
|
||||
/**
|
||||
* 批量更新水印照片地址
|
||||
* @param list
|
||||
* @return void
|
||||
* @author cwchen
|
||||
* @date 2025/4/8 16:40
|
||||
*/
|
||||
void updateBatchSyData(List<SynthesisQueryVo> list);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ 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.ProClassifyStatisticDetailVo;
|
||||
import com.bonus.imgTool.backstage.entity.SynthesisQueryVo;
|
||||
import com.bonus.imgTool.utils.DateTimeHelper;
|
||||
import com.bonus.imgTool.utils.HighQualityWatermark;
|
||||
import com.bonus.imgTool.utils.SystemUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -21,6 +23,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
|
@ -60,6 +63,10 @@ public class DownloadService {
|
|||
tempDirPath = Paths.get(tempDir, taskId);
|
||||
Files.createDirectories(tempDirPath);
|
||||
Path zipFilePath = tempDirPath.resolve(proName + ".zip");
|
||||
// 生成图片水印
|
||||
if(Objects.equals(type,"2")){
|
||||
generateWatermark(proId);
|
||||
}
|
||||
// 获取照片列表
|
||||
List<Photo> photos = getPhotosForAlbum(proId,type);
|
||||
int total = photos.size();
|
||||
|
|
@ -143,6 +150,43 @@ public class DownloadService {
|
|||
return filePath != null ? new File(filePath) : null;
|
||||
}
|
||||
|
||||
private void generateWatermark(String proId) {
|
||||
try {
|
||||
// 查询图片未生成水印照片的数据
|
||||
List<SynthesisQueryVo> list = Optional.ofNullable(synthesisQueryDao.generateWatermark(proId)).orElseGet(ArrayList::new);
|
||||
list.forEach(item->{
|
||||
String path = SystemUtils.getUploadPath() + item.getOriginalFilePath();
|
||||
if (new File(path).exists()) {
|
||||
String syPath = generateWatermarkData(item);
|
||||
item.setWatermarkFilePath(syPath);
|
||||
}
|
||||
});
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
synthesisQueryDao.updateBatchSyData(list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(),e);
|
||||
}
|
||||
}
|
||||
|
||||
public String generateWatermarkData(SynthesisQueryVo vo){
|
||||
// 准备多行水印文本
|
||||
List<String> watermarkLines = new ArrayList<>();
|
||||
String uploadTime = new SimpleDateFormat("yyyy-MM-dd").format(vo.getUploadTime());
|
||||
watermarkLines.add(uploadTime);
|
||||
watermarkLines.add(vo.getProName().replaceAll("(.{18})", "$1@@"));
|
||||
watermarkLines.add(vo.getUploadTypeName());
|
||||
String sourceTypeName = null;
|
||||
if (Objects.equals(vo.getSourceType(), "9")) {
|
||||
sourceTypeName = vo.getTitle();
|
||||
} else {
|
||||
sourceTypeName = vo.getSourceTypeName().split("-")[1];
|
||||
}
|
||||
watermarkLines.add(sourceTypeName);
|
||||
String localPath = SystemUtils.getUploadPath() +File.separator+ vo.getOriginalFilePath();
|
||||
return HighQualityWatermark.generateWatermark(watermarkLines,localPath);
|
||||
}
|
||||
|
||||
private List<Photo> getPhotosForAlbum(String proId,String type) {
|
||||
// 实现获取照片列表的逻辑
|
||||
// 返回包含所有照片路径的列表
|
||||
|
|
@ -176,4 +220,5 @@ public class DownloadService {
|
|||
void onComplete(String taskId, String downloadUrl);
|
||||
void onError(String taskId, String message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -418,7 +418,7 @@
|
|||
</if>
|
||||
AND tcq.is_active = '1'
|
||||
</where>
|
||||
ORDER BY tcq.update_time DESC
|
||||
ORDER BY tcq.create_time DESC
|
||||
</select>
|
||||
<!--获取图片-->
|
||||
<select id="getImgs" resultType="com.bonus.imgTool.backstage.entity.SynthesisQueryVo">
|
||||
|
|
@ -465,6 +465,30 @@
|
|||
WHERE tcq.pro_id = #{proId} AND tcq.is_active = '1'
|
||||
ORDER BY sfr.create_time DESC
|
||||
</select>
|
||||
<!--查询图片未生成水印照片的数据-->
|
||||
<select id="generateWatermark" resultType="com.bonus.imgTool.backstage.entity.SynthesisQueryVo">
|
||||
SELECT sfr.id,
|
||||
sfr.original_file_path AS originalFilePath,
|
||||
sfr.compress_file_path AS compressFilePath,
|
||||
sfr.watermark_file_path AS watermarkFilePath,
|
||||
sfr.upload_type AS uploadType,
|
||||
CASE sfr.upload_type WHEN '1' THEN '安全违章' WHEN '2' THEN '质量检查' WHEN '3' THEN '安全措施落实'
|
||||
WHEN '4' THEN '协调照片' WHEN '5' THEN '重要事项及宣传类' ELSE '' END AS uploadTypeName,
|
||||
sfr.create_time AS uploadTime,
|
||||
source_type AS sourceType,
|
||||
A.dict_name AS sourceTypeName,
|
||||
tcq.title,
|
||||
tcq.pro_name AS proName
|
||||
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 (
|
||||
SELECT sd.dict_value,sd.dict_name
|
||||
FROM sys_distinct sd
|
||||
LEFT JOIN sys_distinct sd2 ON sd.p_id = sd2.id
|
||||
WHERE sd2.dict_code = 'file_source_type' AND sd.del_flag = 0
|
||||
) A ON A.dict_value = sfr.source_type
|
||||
WHERE tcq.pro_id = #{proId} AND tcq.is_active = '1' AND sfr.watermark_file_path IS NULL
|
||||
</select>
|
||||
<!--收藏/取消收藏图片-->
|
||||
<update id="collectData">
|
||||
<if test="collectType == 1">
|
||||
|
|
@ -512,4 +536,12 @@
|
|||
where id = #{id}
|
||||
|
||||
</update>
|
||||
<!--批量更新水印照片地址-->
|
||||
<update id="updateBatchSyData">
|
||||
<foreach collection="list" item="item" separator=";">
|
||||
UPDATE sys_file_resource
|
||||
SET watermark_file_path = #{item.watermarkFilePath}
|
||||
WHERE id = #{item.id}
|
||||
</foreach>
|
||||
</update>
|
||||
</mapper>
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 593 B |
|
|
@ -248,3 +248,20 @@ function resetData() {
|
|||
$(this).removeClass('type-num-check');
|
||||
})
|
||||
}
|
||||
|
||||
/**刷新数据*/
|
||||
function refreshData(){
|
||||
layer.msg("数据刷新中,请稍候...", {icon: 16, scrollbar: false, time: 1000,});
|
||||
pageNum = 1;
|
||||
$('#keyWord').val('');
|
||||
highSearchData = {};
|
||||
$('.type-num').each(function () {
|
||||
$(this).removeClass('type-num-check');
|
||||
})
|
||||
initImgNum();
|
||||
dataFlow({
|
||||
pageNum: pageNum,
|
||||
pageSize: pageSize,
|
||||
queryType: queryType
|
||||
});
|
||||
}
|
||||
|
|
@ -66,8 +66,8 @@
|
|||
}
|
||||
</style>
|
||||
<body>
|
||||
<h3 id="title">照片下载中心</h3>
|
||||
<p>点击下方按钮下载所有照片</p>
|
||||
<h3 id="title"></h3>
|
||||
<p>点击下方按钮下载所有照片<span style="color: red;">(请勿关闭浏览器和浏览器窗口)</span></p>
|
||||
|
||||
<button id="downloadBtn">下载照片压缩包</button>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<div id="main-box">
|
||||
<!--搜索-->
|
||||
<div id="search-box">
|
||||
<form class="layui-form">
|
||||
<form class="layui-form" onsubmit="return false;">
|
||||
<div class="layui-form-item layout">
|
||||
<div class="layui-input-group">
|
||||
<input style="width: 600px;" type="text" id="keyWord" name="keyWord" placeholder="搜索标题"
|
||||
|
|
@ -31,6 +31,9 @@
|
|||
<img src="../../img/synthesisQuery/high_search.png" alt="高级筛选">
|
||||
<p>高级筛选</p>
|
||||
</div>
|
||||
<div class="layui-inline layout" style="margin-bottom: 0;cursor: pointer;">
|
||||
<img onclick="refreshData()" title="数据刷新" src="../../img/synthesisQuery/refresh-icon.png" alt="数据刷新">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue