mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-08 17:12:28 +08:00
【v3.8.3】底层core的一些功能修改
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>jeecg-system-api</artifactId>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<version>3.8.2</version>
|
||||
<version>3.8.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口表
|
||||
|
||||
@ -322,7 +322,7 @@ public class SysAnnouncementController {
|
||||
try {
|
||||
// 同步企业微信、钉钉的消息通知
|
||||
Response<String> dtResponse = dingtalkService.sendActionCardMessage(sysAnnouncement, null, true);
|
||||
wechatEnterpriseService.sendTextCardMessage(sysAnnouncement, true);
|
||||
wechatEnterpriseService.sendTextCardMessage(sysAnnouncement, null,true);
|
||||
|
||||
if (dtResponse != null && dtResponse.isSuccess()) {
|
||||
String taskId = dtResponse.getResult();
|
||||
@ -726,6 +726,18 @@ public class SysAnnouncementController {
|
||||
return Result.ok("公告消息访问次数+1次");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量下载文件
|
||||
* @param id
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@GetMapping("/downLoadFiles")
|
||||
public void downLoadFiles(@RequestParam(name="id") String id,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response){
|
||||
sysAnnouncementService.downLoadFiles(id,request,response);
|
||||
}
|
||||
/**
|
||||
* 根据异常信息确定友好的错误提示
|
||||
*/
|
||||
|
||||
@ -1,14 +1,19 @@
|
||||
package org.jeecg.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.archivers.zip.Zip64Mode;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.FileDownloadUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.config.JeecgBaseConfig;
|
||||
import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
|
||||
import org.jeecg.modules.system.entity.SysAnnouncement;
|
||||
import org.jeecg.modules.system.entity.SysAnnouncementSend;
|
||||
@ -23,6 +28,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
@ -51,7 +60,9 @@ public class SysAnnouncementServiceImpl extends ServiceImpl<SysAnnouncementMappe
|
||||
private SysAnnouncementSendMapper sysAnnouncementSendMapper;
|
||||
@Autowired
|
||||
private ISysAnnouncementSendService sysAnnouncementSendService;
|
||||
|
||||
@Autowired
|
||||
private JeecgBaseConfig jeecgBaseConfig;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void saveAnnouncement(SysAnnouncement sysAnnouncement) {
|
||||
@ -251,4 +262,64 @@ public class SysAnnouncementServiceImpl extends ServiceImpl<SysAnnouncementMappe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量下载文件
|
||||
* @param id
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@Override
|
||||
public void downLoadFiles(String id, HttpServletRequest request, HttpServletResponse response) {
|
||||
// 参数校验
|
||||
if (oConvertUtils.isEmpty(id)) {
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取文章信息
|
||||
SysAnnouncement sysAnnouncement = this.baseMapper.selectById(id);
|
||||
if (oConvertUtils.isEmpty(sysAnnouncement)) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
//设置HTTP响应头:准备文件下载
|
||||
response.reset();
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("application/force-download");
|
||||
ZipArchiveOutputStream zous = null;
|
||||
try {
|
||||
// 生成ZIP文件名:使用文章标题+时间戳避免重名
|
||||
String title = sysAnnouncement.getTitile() + new Date().getTime();
|
||||
String zipName = URLEncoder.encode( title + ".zip", "UTF-8").replaceAll("\\+", "%20");
|
||||
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + zipName);
|
||||
// 创建ZIP输出流:直接输出到HTTP响应流
|
||||
zous = new ZipArchiveOutputStream(response.getOutputStream());
|
||||
zous.setUseZip64(Zip64Mode.AsNeeded);// 支持大文件
|
||||
|
||||
// 批量下载文件
|
||||
String[] fileUrls = sysAnnouncement.getFiles().split(",");
|
||||
// 遍历所有文件URL
|
||||
for (int i = 0; i < fileUrls.length; i++) {
|
||||
String fileUrl = fileUrls[i].trim();
|
||||
if (oConvertUtils.isEmpty(fileUrl)) {
|
||||
continue;
|
||||
}
|
||||
// 生成ZIP内文件名:避免重名,添加序号
|
||||
String fileName = FileDownloadUtils.generateFileName(fileUrl, i, fileUrls.length);
|
||||
String uploadUrl = jeecgBaseConfig.getPath().getUpload();
|
||||
// 下载单个文件并添加到ZIP
|
||||
FileDownloadUtils.downLoadSingleFile(fileUrl,fileName,uploadUrl, zous);
|
||||
}
|
||||
// 完成ZIP写入
|
||||
zous.finish();
|
||||
// 刷新缓冲区确保数据发送
|
||||
response.flushBuffer();
|
||||
} catch (IOException e) {
|
||||
log.error("文件下载失败"+e.getMessage(), e);
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
} finally {
|
||||
// 确保流关闭,防止资源泄漏
|
||||
IoUtil.close(zous);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,19 +3,21 @@ package org.jeecg.modules.openapi.test;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
|
||||
public class SampleOpenApiTest {
|
||||
private final String base_url = "http://localhost:8080/jeecg-boot";
|
||||
private final String appKey = "ak-pFjyNHWRsJEFWlu6";
|
||||
private final String searchKey = "4hV5dBrZtmGAtPdbA5yseaeKRYNpzGsS";
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
// 根据部门ID查询用户
|
||||
|
||||
Reference in New Issue
Block a user