Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -23,7 +23,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@SpringBootTest
|
||||
public class TestMessage {
|
||||
|
||||
@Resource
|
||||
@@ -31,16 +31,18 @@ public class TestMessage {
|
||||
|
||||
@Test
|
||||
public void testMessagePublish() {
|
||||
MessageEntity messageEntity = new MessageEntity();
|
||||
messageEntity.setMessageTitle("测试批量发送标题")
|
||||
.setMessageType(MessageTypeEnum.SYSTEM_MESSAGE.getValue())
|
||||
.setId(UUID.randomUUID10())
|
||||
.setContent("测试测试最后一次")
|
||||
.setDelFlag(0)
|
||||
.setCreateUser("ZGGJP3N7FT")
|
||||
.setCreateDate(new Date());
|
||||
List<String> userIds = new ArrayList<>();
|
||||
userIds.add("ZGGJP3N7FT");
|
||||
messageService.publishMessage(messageEntity, false, userIds);
|
||||
for (int i = 0; i < 20; i++) {
|
||||
MessageEntity messageEntity = new MessageEntity();
|
||||
messageEntity.setMessageTitle("测试发送标题" + java.util.UUID.randomUUID())
|
||||
.setMessageType(MessageTypeEnum.SYSTEM_MESSAGE.getValue())
|
||||
.setId(UUID.randomUUID10())
|
||||
.setContent("测试测试站内信内容" + java.util.UUID.randomUUID())
|
||||
.setDelFlag(0)
|
||||
.setCreateUser("ZGGJP3N7FT")
|
||||
.setCreateDate(new Date());
|
||||
List<String> userIds = new ArrayList<>();
|
||||
userIds.add("ZGGJP3N7FT");
|
||||
messageService.publishMessage(messageEntity, false, userIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
+167
-3
@@ -3,6 +3,7 @@ package com.adc.da.report.controller;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.adc.da.login.util.UserUtils;
|
||||
import com.adc.da.report.annotation.ReportLog;
|
||||
import com.adc.da.report.constant.ReportConstants;
|
||||
import com.adc.da.report.dao.mysql.ReportDao;
|
||||
import com.adc.da.report.dao.mysql.ReportLogBookDao;
|
||||
import com.adc.da.report.eo.*;
|
||||
@@ -253,6 +254,13 @@ public class ReportManageConroller {
|
||||
@ApiOperation("获取报告预览")
|
||||
@GetMapping("/getReportHtml")
|
||||
public ResponseMessage getReportHtml(@RequestParam String reportId, @RequestParam String fileId) {
|
||||
//判断要预览的是不是excel文件
|
||||
FileEntity file = fileService.getFile(fileId);
|
||||
String fileType = file.getFileType();
|
||||
if (ReportConstants.FILE_EXTENSIONS_XLS.equalsIgnoreCase(fileType) || ReportConstants.FILE_EXTENSIONS_XLSX.equalsIgnoreCase(fileType)) {
|
||||
return Result.error("无法预览excel文件");
|
||||
}
|
||||
|
||||
String html = reportService.reportHtml(reportId, fileId);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", html);
|
||||
@@ -411,12 +419,12 @@ public class ReportManageConroller {
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* 下载文件(禁止下载Excel)
|
||||
* @param response
|
||||
* @param fileIds
|
||||
* @throws IOException
|
||||
*/
|
||||
@ApiOperation(value = "|下载文件")
|
||||
@ApiOperation(value = "下载文件(禁止下载Excel)")
|
||||
@GetMapping("/download")
|
||||
public void download(HttpServletResponse response, String[] fileIds, String reportId) throws IOException {
|
||||
List<String> fileIdList = new ArrayList<>();
|
||||
@@ -445,7 +453,7 @@ public class ReportManageConroller {
|
||||
//判断是从列表页面下载 还是预览页面下载
|
||||
if (CollectionUtils.isEmpty(fileIdList)) {
|
||||
//列表点击下载按钮
|
||||
downLoadFileIds = fileService.getDownloadFileIds(reportId);
|
||||
downLoadFileIds = fileService.getDownloadFileIdsWithoutExcel(reportId);
|
||||
if (CollectionUtils.isEmpty(downLoadFileIds)) {
|
||||
log.info("无法下载,原因可能是无可下载文件(xls/xlsx文件无法下载)");
|
||||
try {
|
||||
@@ -571,6 +579,162 @@ public class ReportManageConroller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param response
|
||||
* @param fileIds
|
||||
* @throws IOException
|
||||
*/
|
||||
@ApiOperation(value = "下载文件")
|
||||
@GetMapping("/downloadAll")
|
||||
public void downloadAll(HttpServletResponse response, String[] fileIds, String reportId) throws IOException {
|
||||
List<String> fileIdList = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(fileIds)) {
|
||||
fileIdList = Arrays.asList(fileIds);
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(reportId)) {
|
||||
throw new AdcDaBaseException("缺少报告id");
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(reportId)) {
|
||||
//校验权限
|
||||
if (!reportService.isAllowDownload(UserUtils.getUserId(), reportId)) {
|
||||
throw new AdcDaBaseException("无此报告下载权限");
|
||||
}
|
||||
}
|
||||
|
||||
//待下载的文件id List
|
||||
List<String> downLoadFileIds;
|
||||
String reportName = reportDao.selectById(reportId).getName();
|
||||
String folderName = reportName + ".zip";
|
||||
// 获取编码后的文件名
|
||||
String encodedZipName = URLEncoder.encode(folderName, "UTF-8");
|
||||
|
||||
//判断是从列表页面下载 还是预览页面下载
|
||||
if (CollectionUtils.isEmpty(fileIdList)) {
|
||||
//列表点击下载按钮
|
||||
downLoadFileIds = fileService.getDownloadFileIds(reportId);
|
||||
if (CollectionUtils.isEmpty(downLoadFileIds)) {
|
||||
try {
|
||||
// 设置响应头信息
|
||||
response.setContentType("application/zip");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + encodedZipName);
|
||||
response.setHeader("Content-Transfer-Encoding", "binary");
|
||||
response.setHeader("Pragma", "public");
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
response.setHeader("Expires", "0");
|
||||
|
||||
// 创建空的ZipOutputStream
|
||||
ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream());
|
||||
// 添加空文件夹条目
|
||||
ZipEntry emptyDirectoryEntry = new ZipEntry(reportName + "/");
|
||||
zipOutputStream.putNextEntry(emptyDirectoryEntry);
|
||||
zipOutputStream.close();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//预览点击下载按钮
|
||||
downLoadFileIds = fileIdList;
|
||||
}
|
||||
|
||||
//如果只下载一个文件,则不压缩
|
||||
if (downLoadFileIds.size() == 1) {
|
||||
String fileId = downLoadFileIds.get(0);
|
||||
try {
|
||||
FileEntity entity = fileService.getFile(fileId);
|
||||
String fileName = entity.getFileName();
|
||||
// 获取编码后的文件名
|
||||
String encodedFileName = URLEncoder.encode(fileName, "UTF-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName);
|
||||
|
||||
//PDF文件需要加水印
|
||||
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||
String path = uploadFile + entity.getSavePath();
|
||||
FileOutputStream outputStream = new FileOutputStream(path);
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||
if ("hwobs".equals(uploadType)) {
|
||||
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream);
|
||||
} else if ("alioss".equals(uploadType)) {
|
||||
ossClientUtil.getFileFromOSS(entity.getSavePath(), outputStream);
|
||||
} else if ("local".equals(uploadType)) {
|
||||
localFileUtil.getFileFromLocal(entity.getSavePath(), outputStream);
|
||||
}
|
||||
//给文件添加水印
|
||||
waterMarkUtil.addWatermarkToPdfAndWriteToResponse(new FileInputStream(path), response);
|
||||
outputStream.close();
|
||||
} else {
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs 本地:local
|
||||
if ("hwobs".equals(uploadType)){
|
||||
obsBootUtil.downFile(entity.getSavePath(), response);
|
||||
}else if ("alioss".equals(uploadType)){
|
||||
ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response);
|
||||
}else if ("local".equals(uploadType)){
|
||||
localFileUtil.downFile(entity.getSavePath(), response);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.info(ex.getMessage(),ex);
|
||||
}
|
||||
} else {
|
||||
List<String> filePaths = new ArrayList<>();
|
||||
// 设置响应头信息
|
||||
response.setContentType("application/zip");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + encodedZipName);
|
||||
response.setHeader("Content-Transfer-Encoding", "binary");
|
||||
response.setHeader("Pragma", "public");
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
response.setHeader("Expires", "0");
|
||||
|
||||
for (String fileId : downLoadFileIds) {
|
||||
try {
|
||||
FileEntity entity = fileService.getFile(fileId);
|
||||
String fileName = entity.getFileName();
|
||||
|
||||
String path = uploadFile + entity.getSavePath();
|
||||
FileOutputStream outputStream = new FileOutputStream(path);
|
||||
filePaths.add(path);
|
||||
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||
if ("hwobs".equals(uploadType)) {
|
||||
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream);
|
||||
} else if ("alioss".equals(uploadType)) {
|
||||
ossClientUtil.getFileFromOSS(entity.getSavePath(), outputStream);
|
||||
} else if ("local".equals(uploadType)) {
|
||||
localFileUtil.getFileFromLocal(entity.getSavePath(), outputStream);
|
||||
}
|
||||
//PDF文件需要加水印
|
||||
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||
waterMarkUtil.savePdfToFile(new FileInputStream(path), path);
|
||||
}
|
||||
outputStream.close();
|
||||
} catch (Exception ex) {
|
||||
log.info(ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
//将文件压缩 写入Response
|
||||
localFileUtil.compressFiles(filePaths, response);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(reportId)){
|
||||
ReportLogBook reportLog = new ReportLogBook();
|
||||
reportLog.setId(UUID.randomUUID().toString().replaceAll("-",""));
|
||||
reportLog.setReportId(reportId);
|
||||
reportLog.setType(2);
|
||||
reportLog.setUpdateTime(new Date());
|
||||
reportLog.setUserId(UserUtils.getUserId());
|
||||
reportLogBookDao.insert(reportLog);
|
||||
|
||||
//报告日志管理
|
||||
ReportEntity reportEntity = reportDao.selectById(reportId);
|
||||
reportLog(reportEntity.getName(),"下载");
|
||||
}
|
||||
}
|
||||
|
||||
public void reportLog(String reportName,String desc){
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
LogEntity entity = new LogEntity();
|
||||
|
||||
@@ -10,5 +10,8 @@ import java.util.List;
|
||||
* @Date 2021/6/28 15:19
|
||||
*/
|
||||
public interface FileDao extends BaseMapper<FileEntity> {
|
||||
|
||||
List<String> getDownloadFileIdsWithoutExcel(String reportId);
|
||||
|
||||
List<String> getDownloadFileIds(String reportId);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ public interface IFileService {
|
||||
*/
|
||||
boolean hasExcelFileId(List<String> fileIds);
|
||||
|
||||
/**
|
||||
* 根据报告id返回所有可以下载的文件id(不要excel的)
|
||||
*/
|
||||
List<String> getDownloadFileIdsWithoutExcel(String reportId);
|
||||
|
||||
/**
|
||||
* 根据报告id返回所有可以下载的文件id
|
||||
* @param reportId
|
||||
|
||||
@@ -197,6 +197,11 @@ public class IFileServiceImpl implements IFileService {
|
||||
return hasExcelFileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDownloadFileIdsWithoutExcel(String reportId) {
|
||||
return fileDao.getDownloadFileIdsWithoutExcel(reportId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDownloadFileIds(String reportId) {
|
||||
return fileDao.getDownloadFileIds(reportId);
|
||||
|
||||
@@ -408,6 +408,7 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
LambdaQueryWrapper<ReportContentEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(ReportContentEntity::getReportId, idList);
|
||||
iReportContentService.remove(wrapper);
|
||||
//TODO 删除文件关联
|
||||
return nameList;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.adc.da.report.dao.mysql.FileDao">
|
||||
|
||||
<select id="getDownloadFileIds" resultType="string">
|
||||
<select id="getDownloadFileIdsWithoutExcel" resultType="string">
|
||||
SELECT
|
||||
f.FILE_ID
|
||||
FROM
|
||||
@@ -17,4 +17,14 @@
|
||||
AND
|
||||
f.FILE_TYPE != "xlsx"
|
||||
</select>
|
||||
|
||||
<select id="getDownloadFileIds" resultType="string">
|
||||
SELECT
|
||||
f.FILE_ID
|
||||
FROM
|
||||
`ts_file` AS f
|
||||
LEFT JOIN ts_report_file AS rf ON f.FILE_ID = rf.file_id
|
||||
WHERE
|
||||
rf.report_id = #{reportId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -48,7 +48,7 @@ public class DictItemController {
|
||||
*/
|
||||
@ApiOperation(value = "修改数据字典记录")
|
||||
@PutMapping("/edit")
|
||||
public ResponseMessage edit(@RequestBody DictItemVo dictItemVo) {
|
||||
public ResponseMessage edit(@Valid @RequestBody DictItemVo dictItemVo) {
|
||||
return dictItemService.edit(dictItemVo);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DictItemController {
|
||||
*/
|
||||
@ApiOperation(value = "新增数据字典记录")
|
||||
@PostMapping("/add")
|
||||
public ResponseMessage add(@RequestBody DictItemVo dictItemVo) {
|
||||
public ResponseMessage add(@Valid @RequestBody DictItemVo dictItemVo) {
|
||||
return dictItemService.add(dictItemVo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,11 @@ public class DictItemServiceImpl extends ServiceImpl<DictItemDao, DictItemEntity
|
||||
|
||||
@Override
|
||||
public ResponseMessage edit(DictItemVo dictItemVo) {
|
||||
//判断传入的选项名是否重复
|
||||
if (dictItemNameDuplicate(dictItemVo.getItemName())) {
|
||||
return Result.error("重复选项名");
|
||||
}
|
||||
|
||||
try {
|
||||
DictItemEntity dictItemEntity = new DictItemEntity();
|
||||
BeanUtil.copyProperties(dictItemVo, dictItemEntity);
|
||||
@@ -89,6 +94,11 @@ public class DictItemServiceImpl extends ServiceImpl<DictItemDao, DictItemEntity
|
||||
return Result.success("删除成功");
|
||||
}
|
||||
|
||||
public boolean dictItemNameDuplicate(String dictItemName) {
|
||||
List<DictItemEntity> item = query().like("item_name", dictItemName).list();
|
||||
return item.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseMessage add(DictItemVo dictItemVo) {
|
||||
//判断上级字典id是否存在
|
||||
@@ -100,7 +110,10 @@ public class DictItemServiceImpl extends ServiceImpl<DictItemDao, DictItemEntity
|
||||
if (dictEntity == null) {
|
||||
return Result.error("上级字典id无效");
|
||||
}
|
||||
|
||||
//判断传入的选项名是否重复
|
||||
if (dictItemNameDuplicate(dictItemVo.getItemName())) {
|
||||
return Result.error("重复选项名");
|
||||
}
|
||||
try {
|
||||
DictItemEntity dictItemEntity = BeanCopyUtils.copyBean(dictItemVo, DictItemEntity.class);
|
||||
dictItemEntity.setId(UUID.randomUUID10())
|
||||
|
||||
@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author CaiHaohan
|
||||
*/
|
||||
@@ -40,6 +42,7 @@ public class DictItemVo {
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@NotNull(message = "缺少排序字段")
|
||||
private Double itemOrder;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user