会议资料下载
This commit is contained in:
+40
-11
@@ -8,8 +8,10 @@ import com.budwk.app.base.utils.CommonDownloadUtil;
|
||||
import com.budwk.app.flow.enums.ProcessInstanceStateEnum;
|
||||
import com.budwk.app.sys.models.Sys_file;
|
||||
import com.budwk.app.sys.utils.SysFileMinIoUtil;
|
||||
import com.budwk.app.zhgh.democratic.grassrootscongress.models.GrassrootsCongressMaterialsInfo;
|
||||
import com.budwk.app.zhgh.democratic.grassrootscongress.models.GrassrootsCongressMeetingInfo;
|
||||
import com.budwk.app.zhgh.democratic.grassrootscongress.param.GrassrootsCongressPageForm;
|
||||
import com.budwk.app.zhgh.democratic.grassrootscongress.service.GrassrootsCongressMeetingService;
|
||||
import com.budwk.app.zhgh.democratic.grassrootscongress.service.GrassrootsCongressService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -20,6 +22,7 @@ import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
@@ -27,6 +30,7 @@ import org.nutz.mvc.annotation.Ok;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@@ -41,6 +45,9 @@ public class GrassrootsCongressMaterialStatisticsController {
|
||||
@Inject
|
||||
private GrassrootsCongressService grassrootsCongressService;
|
||||
|
||||
@Inject
|
||||
private GrassrootsCongressMeetingService grassrootsCongressMeetingService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/zhgh/democratic/grassrootscongress/material/statistics/index.html")
|
||||
@SaCheckPermission("grassrootsCongress.material.statistics")
|
||||
@@ -92,25 +99,47 @@ public class GrassrootsCongressMaterialStatisticsController {
|
||||
cnd.andEX("YEAR(info.createdTime)", "=", pageForm.getYear());
|
||||
cnd.desc("info.createdTime");
|
||||
sql.setCondition(cnd);
|
||||
List<GrassrootsCongressMeetingInfo> list = grassrootsCongressService.listEntity(sql);
|
||||
List<GrassrootsCongressMaterialsInfo> list = grassrootsCongressMeetingService.listEntity(sql);
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ZipOutputStream zipOutputStream = new ZipOutputStream(bos);
|
||||
for (GrassrootsCongressMeetingInfo info : list) {
|
||||
// 循环下载文件
|
||||
List<JSONObject> files = info.getFiles();
|
||||
for (JSONObject file : files) {
|
||||
Sys_file sysFile = grassrootsCongressService.dao().fetch(Sys_file.class, Cnd.where(Sys_file::getDownloadPath, "=", file.get("url")));
|
||||
byte[] bytes = SysFileMinIoUtil.getFileBytes(sysFile.getBucket(), sysFile.getStoragePath());
|
||||
|
||||
ZipEntry zipEntry = new ZipEntry(sysFile.getName());
|
||||
zipOutputStream.putNextEntry(zipEntry);
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
|
||||
zipOutputStream.write(bytes);
|
||||
zipOutputStream.closeEntry();
|
||||
List<JSONObject> fileJsonList = list.stream().map(GrassrootsCongressMaterialsInfo::getFiles).flatMap(v -> v.stream().map(item -> item)).toList();
|
||||
|
||||
for (JSONObject file : fileJsonList) {
|
||||
if (Lang.isEmpty(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 人才,非常人才,优秀人才 666
|
||||
Sys_file sysFile = grassrootsCongressMeetingService.dao().fetch(Sys_file.class, Cnd.where(Sys_file::getDownloadPath, "=", file.get("url")));
|
||||
|
||||
if (Lang.isEmpty(sysFile)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte[] bytes = SysFileMinIoUtil.getFileBytes(sysFile.getBucket(), sysFile.getStoragePath());
|
||||
|
||||
String fileName = sysFile.getName();
|
||||
|
||||
if (fileNames.contains(fileName)) {
|
||||
String finalFileName = fileName;
|
||||
long count = fileNames.stream().filter(name -> name.equals(finalFileName)).count();
|
||||
fileName = count + fileName;
|
||||
}
|
||||
|
||||
ZipEntry zipEntry = new ZipEntry(fileName);
|
||||
zipOutputStream.putNextEntry(zipEntry);
|
||||
|
||||
zipOutputStream.write(bytes);
|
||||
zipOutputStream.closeEntry();
|
||||
|
||||
fileNames.add(fileName);
|
||||
}
|
||||
|
||||
zipOutputStream.close();
|
||||
CommonDownloadUtil.download("资料汇总压缩包.zip", bos.toByteArray(), response);
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user