Merge branch 'lixuetao'

This commit is contained in:
bupengxiang
2023-05-25 15:28:22 +08:00
43 changed files with 1677 additions and 388 deletions
@@ -0,0 +1,46 @@
package com.adc.da.report;
import com.adc.da.report.constant.MessageTypeEnum;
import com.adc.da.report.eo.MessageEntity;
import com.adc.da.report.service.IMessageService;
import com.adc.da.util.utils.UUID;
import io.github.swagger2markup.GroupBy;
import io.github.swagger2markup.Language;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class TestMessage {
@Resource
private IMessageService messageService;
@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);
}
}
@@ -0,0 +1,23 @@
package com.adc.da.report.constant;
import io.swagger.models.auth.In;
/**
* @author: CaiHaohan
* @Date: 2023/5/23 15:17
* @Description:
*/
public class MessageConstants {
/**
* 消息状态 未读
*/
public static final Integer UNREAD = 0;
/**
* 消息状态 已读
*/
public static final Integer READ = 1;
}
@@ -0,0 +1,40 @@
package com.adc.da.report.constant;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* @author: CaiHaohan
* @Date: 2023/5/24 10:44
* @Description:
*/
public enum MessageTypeEnum {
/**
* 系统消息
*/
SYSTEM_MESSAGE(0, "系统消息");
/**
* 对应值
*/
private Integer code;
/**
* 描述
*/
private String desc;
MessageTypeEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public Integer getValue() {
return code;
}
public String getDesc() {
return desc;
}
}
@@ -23,6 +23,15 @@ public class ReportConstants {
*/ */
public static final String NO_USER_PRIVACY_INVOLVED = "不涉及用户隐私"; public static final String NO_USER_PRIVACY_INVOLVED = "不涉及用户隐私";
/**
* 流程中
*/
public static final Integer IN_PROCESS = 1;
/**
* 不在流程中
*/
public static final Integer NOT_IN_PROCESS = 2;
} }
@@ -0,0 +1,49 @@
package com.adc.da.report.controller;
import com.adc.da.report.service.IMessageService;
import com.adc.da.report.vo.MessageQueryVo;
import com.adc.da.report.vo.MessageVo;
import com.adc.da.util.http.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
/**
* @Author caihaohan
* @Date 2021/11/9 13:46
*/
@Slf4j
@Api(tags = "站内信")
@RestController
@RequestMapping("/${restPath}/message")
public class MessageController {
@Resource
private IMessageService messageEntityService;
/**
* 站内信消息列表
* @return
*/
@ApiOperation("站内信消息列表")
@GetMapping("/list")
public ResponseMessage list(@Valid MessageQueryVo messageQueryVo) {
return messageEntityService.listByCurrentUser(messageQueryVo);
}
/**
* 全部已读
* @return
*/
@ApiOperation("全部已读接口")
@GetMapping("/allRead")
public ResponseMessage allRead() {
return messageEntityService.allRead();
}
}
@@ -5,10 +5,7 @@ import com.adc.da.login.util.UserUtils;
import com.adc.da.report.annotation.ReportLog; import com.adc.da.report.annotation.ReportLog;
import com.adc.da.report.dao.mysql.ReportDao; import com.adc.da.report.dao.mysql.ReportDao;
import com.adc.da.report.dao.mysql.ReportLogBookDao; import com.adc.da.report.dao.mysql.ReportLogBookDao;
import com.adc.da.report.eo.FileEntity; import com.adc.da.report.eo.*;
import com.adc.da.report.eo.LogEntity;
import com.adc.da.report.eo.ReportEntity;
import com.adc.da.report.eo.ReportLogBook;
import com.adc.da.report.service.IFileService; import com.adc.da.report.service.IFileService;
import com.adc.da.report.service.ILogService; import com.adc.da.report.service.ILogService;
import com.adc.da.report.service.IReportService; import com.adc.da.report.service.IReportService;
@@ -22,12 +19,14 @@ import com.adc.da.report.vo.ReportVo;
import com.adc.da.util.exception.AdcDaBaseException; import com.adc.da.util.exception.AdcDaBaseException;
import com.adc.da.util.http.ResponseMessage; import com.adc.da.util.http.ResponseMessage;
import com.adc.da.util.http.Result; import com.adc.da.util.http.Result;
import com.adc.da.util.utils.CollectionUtils;
import com.adc.da.util.utils.FileUtil; import com.adc.da.util.utils.FileUtil;
import com.adc.da.util.utils.StringUtils; import com.adc.da.util.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -41,11 +40,11 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.*; import java.io.*;
import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.zip.ZipOutputStream;
import static com.adc.da.report.constant.ReportConstants.FILE_EXTENSIONS_PDF; import static com.adc.da.report.constant.ReportConstants.FILE_EXTENSIONS_PDF;
@@ -245,19 +244,20 @@ public class ReportManageConroller {
/** /**
* 获取报告预览 * 获取报告预览
* @param id * @param reportId
* @param fileId
* @return * @return
*/ */
@ApiOperation("获取报告预览") @ApiOperation("获取报告预览")
@GetMapping("/getReportHtml/{id}") @GetMapping("/getReportHtml")
public ResponseMessage getReportHtml(@PathVariable("id") String id) { public ResponseMessage getReportHtml(@RequestParam String reportId, @RequestParam String fileId) {
String html = reportService.reportHtml(id); String html = reportService.reportHtml(reportId, fileId);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("content", html); map.put("content", html);
ReportLogBook reportLog = new ReportLogBook(); ReportLogBook reportLog = new ReportLogBook();
reportLog.setId(UUID.randomUUID().toString().replaceAll("-","")); reportLog.setId(UUID.randomUUID().toString().replaceAll("-",""));
reportLog.setReportId(id); reportLog.setReportId(reportId);
reportLog.setType(1); reportLog.setType(1);
reportLog.setUpdateTime(new Date()); reportLog.setUpdateTime(new Date());
reportLog.setUserId(UserUtils.getUserId()); reportLog.setUserId(UserUtils.getUserId());
@@ -298,31 +298,6 @@ public class ReportManageConroller {
return Result.success(); return Result.success();
} }
// TODO 测试完不需要的代码请删掉,然后再把这个TODO也删掉
/**
* 测试
*/
@ApiOperation("testtest")
@GetMapping("/test")
@Deprecated
public void ttt() {
stringRedisTemplate.boundValueOps("1121212").set("1212");
}
// TODO 测试完不需要的代码请删掉,然后再把这个TODO也删掉
@ApiOperation("testPath")
@GetMapping("/testPath")
@Deprecated
public ResponseMessage testPath() throws URISyntaxException {
HashMap<String, String> pathMap = new HashMap<>();
String jarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath();
String property = System.getProperty("user.dir");
pathMap.put("jarpath", jarPath);
pathMap.put("propertyPath", property);
return Result.success(pathMap);
}
/** /**
* 获取文件名 * 获取文件名
* @param fileId * @param fileId
@@ -344,57 +319,24 @@ public class ReportManageConroller {
@ApiOperation(value = "详情||上传文件") @ApiOperation(value = "详情||上传文件")
@PostMapping("/uploadFile") @PostMapping("/uploadFile")
public ResponseMessage<Map<String, Object>> uploadFile(MultipartFile file) throws IOException { public ResponseMessage<Map<String, Object>> uploadFile(MultipartFile file) throws IOException {
Map<String, Object> resultMap = new HashMap(); Map<String, Object> resultMap = fileService.uploadFile(file);
//上传路径
//此路径映射到localhost
String path = uploadFile;
String realName = file.getOriginalFilename();
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String date = dateFormat.format(now);
Random r = new Random();
String num = "";
for (int i = 0; i < 3; i++) {
int s = r.nextInt(10);
num += String.valueOf(s);
}
//获取上传文件名
String fileName = file.getOriginalFilename();
String contentType = file.getContentType();
String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
fileName = fileName.substring(0, fileName.lastIndexOf("."))+date + num + "." + ext;
log.info("fileName>>" + fileName);
try{
String result="";
// 上传方式:阿里云:alioss 华为云:hwobs
if ("hwobs".equals(uploadType)){
result = obsBootUtil.upload(file, fileName);
}else if ("alioss".equals(uploadType)) {
result = ossClientUtil.uploadFile2OSS(file.getInputStream(),fileName);
}else if ("local".equals(uploadType)) {
localFileUtil.saveFile(file.getInputStream(), fileName);
}
resultMap.put("key", date + num);
resultMap.put("value", path + "//" + fileName);
resultMap.put("name", realName);
}
catch (Exception e){
log.error(e.getMessage(),e);
}
FileEntity entity = new FileEntity();
entity.setContentType(contentType);
entity.setCreateTime(new Date());
entity.setFileName(realName);
entity.setFileType(ext);
entity.setFileSize(String.valueOf(file.getSize()));
entity.setFileId(date + num);
entity.setSavePath(fileName);
fileService.addFile(entity);
return Result.success(resultMap); return Result.success(resultMap);
} }
/**
* 批量上传文件
* @param files
* @return
* @throws IOException
*/
@ApiOperation(value = "批量上传文件")
@PostMapping("/batchUploadFile")
public ResponseMessage<List<Map<String, Object>>> batchUploadFile(@RequestParam("files") @ApiParam(value="上传文件",required=true) MultipartFile[] files) throws IOException {
List<Map<String, Object>> uploadFile = fileService.batchUploadFile(files);
return Result.success(uploadFile);
}
/** /**
* 上传图片 * 上传图片
* @param file * @param file
@@ -466,105 +408,157 @@ public class ReportManageConroller {
} }
// /**
// * 下载文件
// * @param response
// * @param fileId
// * @throws IOException
// */
// @ApiOperation(value = "|下载文件")
// @GetMapping("/download")
// public void downloadPic(HttpServletResponse response, String fileId) throws IOException {
//
// try {
// FileEntity entity = fileService.getFile(fileId);
// String fileName = entity.getFileName();
// String filename = URLEncoder.encode(fileName, "UTF-8");
// response.setHeader("Content-Disposition", "attachment;filename=" + filename);
// response.setContentType("application/x-download");
//// File file = new File(uploadFile, entity.getSavePath());
// // 上传方式:阿里云:alioss 华为云:hwobs
// 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);
// }
// if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
// String text = "text";
// PdfUtil.addWatermarkToPdf(response, text);
// }
// } catch (Exception ex) {
// log.info(ex.getMessage(),ex);
// }
// }
/** /**
* 下载文件 * 下载文件
* @param response * @param response
* @param fileId * @param fileIds
* @throws IOException * @throws IOException
*/ */
@ApiOperation(value = "|下载文件") @ApiOperation(value = "|下载文件")
@GetMapping("/download") @GetMapping("/download")
public void downloadPic(HttpServletResponse response, String fileId,String repostId) throws IOException { public void download(HttpServletResponse response, String[] fileIds, String reportId) throws IOException {
List<String> fileIdList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(fileIds)) {
fileIdList = Arrays.asList(fileIds);
}
if (StrUtil.isNotBlank(repostId)) { if (StrUtil.isBlank(reportId)) {
throw new AdcDaBaseException("缺少报告id");
}
if (StrUtil.isNotBlank(reportId)) {
//校验权限 //校验权限
if (!reportService.isAllowDownload(UserUtils.getUserId(), repostId)) { if (!reportService.isAllowDownload(UserUtils.getUserId(), reportId)) {
throw new AdcDaBaseException("无此报告下载权限"); throw new AdcDaBaseException("无此报告下载权限");
} }
} }
try { response.setContentType("application/x-download");
FileEntity entity = fileService.getFile(fileId); //待下载的文件id List
String fileName = entity.getFileName(); List<String> downLoadFileIds;
String filename = URLEncoder.encode(fileName, "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
response.setContentType("application/x-download");
//PDF文件需要加水印 //判断是从列表页面下载 还是预览页面下载
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) { if (CollectionUtils.isEmpty(fileIdList)) {
String path = uploadFile + entity.getSavePath(); //列表点击下载按钮
FileOutputStream outputStream = new FileOutputStream(path); downLoadFileIds = fileService.getDownloadFileIds(reportId);
// 上传方式:阿里云:alioss 华为云:hwobs if (CollectionUtils.isEmpty(downLoadFileIds)) {
if ("hwobs".equals(uploadType)) { log.info("无法下载,原因可能是无可下载文件(xls/xlsx文件无法下载)");
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream); String zipFileName = "empty.zip"; // 压缩文件名
} else if ("alioss".equals(uploadType)) { try {
ossClientUtil.getFileFromOSS(entity.getSavePath(), outputStream); // 设置响应头信息
} else if ("local".equals(uploadType)) { response.setContentType("application/zip");
localFileUtil.getFileFromLocal(entity.getSavePath(), outputStream); response.setHeader("Content-Disposition", "attachment; filename=" + zipFileName);
}
//给文件添加水印
waterMarkUtil.addWatermarkToPdf(new FileInputStream(path), response);
} else { // 创建空的ZipOutputStream
// 上传方式:阿里云:alioss 华为云:hwobs 本地:local ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream());
if ("hwobs".equals(uploadType)){ zipOutputStream.close();
obsBootUtil.downFile(entity.getSavePath(), response); return;
}else if ("alioss".equals(uploadType)){ } catch (IOException e) {
ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response); e.printStackTrace();
}else if ("local".equals(uploadType)){
localFileUtil.downFile(entity.getSavePath(), response);
} }
} }
} else {
} catch (Exception ex) { //检测是否要下载Excel文件
log.info(ex.getMessage(),ex); if (fileService.hasExcelFileId(fileIdList)) {
throw new AdcDaBaseException("不可以下载Excel文件");
}
//预览点击下载按钮
downLoadFileIds = fileIdList;
} }
if (StringUtils.isNotEmpty(repostId)){
//如果只下载一个文件,则不压缩
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<>();
String reportName = reportDao.selectById(reportId).getName() + ".zip";
// 获取编码后的文件名
String encodedFileName = URLEncoder.encode(reportName, "UTF-8");
// 设置响应头信息
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=" + encodedFileName);
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(); ReportLogBook reportLog = new ReportLogBook();
reportLog.setId(UUID.randomUUID().toString().replaceAll("-","")); reportLog.setId(UUID.randomUUID().toString().replaceAll("-",""));
reportLog.setReportId(repostId); reportLog.setReportId(reportId);
reportLog.setType(2); reportLog.setType(2);
reportLog.setUpdateTime(new Date()); reportLog.setUpdateTime(new Date());
reportLog.setUserId(UserUtils.getUserId()); reportLog.setUserId(UserUtils.getUserId());
reportLogBookDao.insert(reportLog); reportLogBookDao.insert(reportLog);
//报告日志管理 //报告日志管理
ReportEntity reportEntity = reportDao.selectById(repostId); ReportEntity reportEntity = reportDao.selectById(reportId);
reportLog(reportEntity.getName(),"下载"); reportLog(reportEntity.getName(),"下载");
} }
} }
@@ -607,4 +601,15 @@ public class ReportManageConroller {
return Result.success(act); return Result.success(act);
} }
/**
* 删除文件
* @return
* @throws ParseException
*/
@ApiOperation("删除文件")
@PostMapping("/delFile")
public ResponseMessage delFile(@RequestBody ReportFile reportFile) throws Exception {
reportService.delFile(reportFile);
return Result.success();
}
} }
@@ -3,9 +3,12 @@ package com.adc.da.report.dao.mysql;
import com.adc.da.report.eo.FileEntity; import com.adc.da.report.eo.FileEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/** /**
* @Author doudxw * @Author doudxw
* @Date 2021/6/28 15:19 * @Date 2021/6/28 15:19
*/ */
public interface FileDao extends BaseMapper<FileEntity> { public interface FileDao extends BaseMapper<FileEntity> {
List<String> getDownloadFileIds(String reportId);
} }
@@ -0,0 +1,30 @@
package com.adc.da.report.dao.mysql;
import com.adc.da.report.eo.MessageEntity;
import com.adc.da.report.vo.MessageQueryVo;
import com.adc.da.report.vo.MessageVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
/**
* @author ThinkBook
* @description 针对表【ts_message】的数据库操作Mapper
* @createDate 2023-05-23 11:22:15
* @Entity com.adc.da.report.eo.MessageEntityEntity
*/
public interface MessageDao extends BaseMapper<MessageEntity> {
/**
* 根据当前用户展示站内信列表
* @param page
* @param messageVo
* @param userId
* @return
*/
IPage<MessageVo> listByUser(IPage<MessageVo> page, @Param("vo") MessageQueryVo messageVo, @Param("userId") String userId);
}
@@ -0,0 +1,18 @@
package com.adc.da.report.dao.mysql;
import com.adc.da.report.eo.ReportFile;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ReportFileDao extends BaseMapper<ReportFile> {
void delByReportId(@Param("pageVO") ReportFile reportFile);
void actEndDelReport(@Param("reportId")String reportId);
void updateState(@Param("reportId")String dataId);
List<ReportFile> selectByReport(@Param("pageVO")ReportFile reportFile);
}
@@ -0,0 +1,18 @@
package com.adc.da.report.dao.mysql;
import com.adc.da.report.eo.UserMessageEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author ThinkBook
* @description 针对表【ts_user_message】的数据库操作Mapper
* @createDate 2023-05-23 11:30:04
* @Entity com.adc.da.report.eo.UserMessage
*/
public interface UserMessageDao extends BaseMapper<UserMessageEntity> {
}
@@ -0,0 +1,70 @@
package com.adc.da.report.eo;
import com.adc.da.report.constant.MessageTypeEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
*
* @author Caihaohan
* @TableName ts_message
*/
@TableName(value ="ts_message")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class MessageEntity implements Serializable {
/**
* 主键id
*/
@TableId(value = "id")
private String id;
/**
* 标题
*/
@TableField(value = "message_title")
private String messageTitle;
/**
* 内容
*/
@TableField(value = "content")
private String content;
/**
* 消息类型
*/
@TableField(value = "message_type")
private Integer messageType;
/**
* 发布人
*/
@TableField(value = "createUser")
private String createUser;
/**
* 发布时间
*/
@TableField(value = "createDate")
private Date createDate;
/**
* 删除标记(0未删除 1已删除)
*/
@TableField(value = "del_flag")
private Integer delFlag;
@TableField(exist = false)
private static final long serialVersionUID = 1314298673425876932L;
}
@@ -68,7 +68,7 @@ public class ReportEntity {
/** /**
* 文件id * 文件id
*/ */
@TableField("fileId") @TableField(exist = false)
private String fileId; private String fileId;
/** /**
@@ -109,4 +109,7 @@ public class ReportEntity {
@TableField(exist = false) @TableField(exist = false)
private List<List<String>> labelList; private List<List<String>> labelList;
@TableField(exist = false)
private List<ReportFile> fileList;
} }
@@ -0,0 +1,52 @@
package com.adc.da.report.eo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.List;
@Data
@TableName("TS_REPORT_FILE")
public class ReportFile {
@TableId(value = "id",type = IdType.INPUT)
private String id;
@TableField("report_id")
private String reportId;
@TableField("file_id")
private String fileId;
/**
* 状态 1 流程中 ,2 非流程中
*/
@TableField("state")
private Integer state;
@TableField(exist = false)
private List<String> rfIdList;
@TableField(exist = false)
private String fileName;
public ReportFile(String reportId){
this.reportId = reportId;
}
public ReportFile(String reportId,Integer state){
this.reportId = reportId;
this.state = state;
}
public ReportFile(){
}
}
@@ -94,7 +94,7 @@ public class TtReportManageAct {
/** /**
* 文件id * 文件id
*/ */
@TableField("fileId") @TableField(exist = false)
private String fileId; private String fileId;
@@ -128,10 +128,16 @@ public class TtReportManageAct {
@TableField("secrecy_last") @TableField("secrecy_last")
private Date secrecyLast; private Date secrecyLast;
@TableField("file_name") @TableField(exist = false)
private String rfId;
@TableField(exist = false)
private String fileName; private String fileName;
@TableField(exist = false) @TableField(exist = false)
private List<String> labelList; private List<String> labelList;
@TableField(exist = false)
private List<ReportFile> fileList;
} }
@@ -0,0 +1,56 @@
package com.adc.da.report.eo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
*
* @author ThinkBook
* @TableName ts_user_message
*/
@TableName(value ="ts_user_message")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class UserMessageEntity implements Serializable {
/**
* 主键id
*/
@TableId(value = "id")
private String id;
/**
* 用户id
*/
@TableField(value = "user_id")
private String userId;
/**
* 站内信id
*/
@TableField(value = "message_id")
private String messageId;
/**
* 阅读状态(0代表未读,1代表已读)
*/
@TableField(value = "read_type")
private Integer readType;
/**
* 删除标记(0未删除 1已删除)
*/
@TableField(value = "del_flag")
private Integer delFlag;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
@@ -2,6 +2,10 @@ package com.adc.da.report.service;
import com.adc.da.report.eo.FileEntity; import com.adc.da.report.eo.FileEntity;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
/** /**
* @Author doudxw * @Author doudxw
@@ -22,4 +26,21 @@ public interface IFileService {
*/ */
FileEntity getFile(String fileId); FileEntity getFile(String fileId);
List<Map<String, Object>> batchUploadFile(MultipartFile[] files);
/**
* 判断传进来的fileIds里有没有Excel的fileId
* @param fileIds
* @return
*/
boolean hasExcelFileId(List<String> fileIds);
/**
* 根据报告id返回所有可以下载的文件id
* @param reportId
* @return
*/
List<String> getDownloadFileIds(String reportId);
Map<String, Object> uploadFile(MultipartFile file);
} }
@@ -0,0 +1,36 @@
package com.adc.da.report.service;
import com.adc.da.report.eo.MessageEntity;
import com.adc.da.report.vo.MessageQueryVo;
import com.adc.da.util.http.ResponseMessage;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author ThinkBook
* @description 针对表【ts_message】的数据库操作Service
* @createDate 2023-05-23 11:22:15
*/
public interface IMessageService extends IService<MessageEntity> {
/**
* 返回当前用户的消息列表
* @return
*/
ResponseMessage listByCurrentUser(MessageQueryVo messageVo);
/**
* 全部已读接口
* @return
*/
ResponseMessage allRead();
/**
* 发布站内信(当用户数过多的时候谨慎使用发送给全部用户)
* @param message
* @param toAllUser
* @param userIds
*/
void publishMessage(MessageEntity message, boolean toAllUser, List<String> userIds);
}
@@ -3,7 +3,6 @@ package com.adc.da.report.service;
import com.adc.da.report.eo.ReportContentEntity; import com.adc.da.report.eo.ReportContentEntity;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
/** /**
@@ -18,7 +17,6 @@ public interface IReportContentService extends IService<ReportContentEntity> {
* 插入报告内容表 * 插入报告内容表
* *
* @param reportId 报告id * @param reportId 报告id
* @param fileId 文件id
*/ */
void insertReportContent(String reportId, String fileId) throws IOException; void insertReportContent(String reportId) throws IOException;
} }
@@ -0,0 +1,11 @@
package com.adc.da.report.service;
import com.adc.da.report.eo.ReportFile;
import com.baomidou.mybatisplus.extension.service.IService;
public interface IReportFileService extends IService<ReportFile> {
}
@@ -1,6 +1,7 @@
package com.adc.da.report.service; package com.adc.da.report.service;
import com.adc.da.report.eo.ReportEntity; import com.adc.da.report.eo.ReportEntity;
import com.adc.da.report.eo.ReportFile;
import com.adc.da.report.vo.ChangeUploaderVo; import com.adc.da.report.vo.ChangeUploaderVo;
import com.adc.da.report.vo.ReportQueryVo; import com.adc.da.report.vo.ReportQueryVo;
import com.adc.da.report.vo.ReportVo; import com.adc.da.report.vo.ReportVo;
@@ -41,10 +42,11 @@ public interface IReportService {
/** /**
* 获取报告htmlString * 获取报告htmlString
* @param id * @param reportId
* @param fileId
* @return * @return
*/ */
String reportHtml(String id); String reportHtml(String reportId, String fileId);
IPage<ReportVo> addReportPage(ReportQueryVo vo) throws Exception; IPage<ReportVo> addReportPage(ReportQueryVo vo) throws Exception;
@@ -95,4 +97,7 @@ public interface IReportService {
* @return * @return
*/ */
ResponseMessage changeUploader(ChangeUploaderVo changeUploaderVo); ResponseMessage changeUploader(ChangeUploaderVo changeUploaderVo);
void delFile(ReportFile reportFile);
} }
@@ -0,0 +1,13 @@
package com.adc.da.report.service;
import com.adc.da.report.eo.UserMessageEntity;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author ThinkBook
* @description 针对表【ts_user_message】的数据库操作Service
* @createDate 2023-05-23 11:30:04
*/
public interface IUserMessageService extends IService<UserMessageEntity> {
}
@@ -1,21 +1,53 @@
package com.adc.da.report.service.impl; package com.adc.da.report.service.impl;
import com.adc.da.report.constant.ReportConstants;
import com.adc.da.report.dao.mysql.FileDao; import com.adc.da.report.dao.mysql.FileDao;
import com.adc.da.report.eo.FileEntity; import com.adc.da.report.eo.FileEntity;
import com.adc.da.report.service.IFileService; import com.adc.da.report.service.IFileService;
import javax.annotation.Resource; import com.adc.da.report.util.LocalFileUtil;
import com.adc.da.report.util.OSSClientUtil;
import com.adc.da.report.util.ObsBootUtil;
import com.adc.da.util.utils.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
/** /**
* @Author doudxw * @Author doudxw
* @Date 2021/11/8 15:00 * @Date 2021/11/8 15:00
*/ */
@Service @Service
@Slf4j
public class IFileServiceImpl implements IFileService { public class IFileServiceImpl implements IFileService {
@Resource @Resource
private FileDao fileDao; private FileDao fileDao;
@Value("${uploadFile}")
private String uploadFile;
@Value("${picPath}")
private String picPath;
@Value("${uploadType}")
private String uploadType;
@Autowired
private ObsBootUtil obsBootUtil;
@Autowired
private LocalFileUtil localFileUtil;
@Resource
private OSSClientUtil ossClientUtil;
/** /**
* 添加文件 * 添加文件
@@ -36,4 +68,137 @@ public class IFileServiceImpl implements IFileService {
FileEntity fileEntity = fileDao.selectById(fileId); FileEntity fileEntity = fileDao.selectById(fileId);
return fileEntity; return fileEntity;
} }
@Override
@Transactional
public List<Map<String, Object>> batchUploadFile(MultipartFile[] files) {
List<Map<String, Object>> resultList = new ArrayList<>();
for (MultipartFile file : files) {
Map<String, Object> resultMap = new HashMap();
//上传路径
//此路径映射到localhost
String path = uploadFile;
String realName = file.getOriginalFilename();
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String date = dateFormat.format(now);
Random r = new Random();
String num = "";
for (int i = 0; i < 3; i++) {
int s = r.nextInt(10);
num += String.valueOf(s);
}
//获取上传文件名
String fileName = file.getOriginalFilename();
String contentType = file.getContentType();
String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
fileName = fileName.substring(0, fileName.lastIndexOf("."))+date + num + "." + ext;
log.info("fileName>>" + fileName);
try{
String result="";
// 上传方式:阿里云:alioss 华为云:hwobs
if ("hwobs".equals(uploadType)){
result = obsBootUtil.upload(file, fileName);
}else if ("alioss".equals(uploadType)) {
result = ossClientUtil.uploadFile2OSS(file.getInputStream(),fileName);
}else if ("local".equals(uploadType)) {
localFileUtil.saveFile(file.getInputStream(), fileName);
}
resultMap.put("key", date + num);
resultMap.put("value", path + "//" + fileName);
resultMap.put("name", realName);
resultList.add(resultMap);
}
catch (Exception e){
log.error(e.getMessage(),e);
}
FileEntity entity = new FileEntity();
entity.setContentType(contentType);
entity.setCreateTime(new Date());
entity.setFileName(realName);
entity.setFileType(ext);
entity.setFileSize(String.valueOf(file.getSize()));
entity.setFileId(date + num);
entity.setSavePath(fileName);
this.addFile(entity);
}
return resultList;
}
@Override
@Synchronized
public Map<String, Object> uploadFile(MultipartFile file) {
Map<String, Object> resultMap = new HashMap();
//上传路径
//此路径映射到localhost
String path = uploadFile;
String realName = file.getOriginalFilename();
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String date = dateFormat.format(now);
Random r = new Random();
String num = "";
for (int i = 0; i < 3; i++) {
int s = r.nextInt(10);
num += String.valueOf(s);
}
//获取上传文件名
String fileName = file.getOriginalFilename();
String contentType = file.getContentType();
String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
fileName = fileName.substring(0, fileName.lastIndexOf("."))+date + num + "." + ext;
log.info("fileName>>" + fileName);
try{
String result="";
// 上传方式:阿里云:alioss 华为云:hwobs
if ("hwobs".equals(uploadType)){
result = obsBootUtil.upload(file, fileName);
}else if ("alioss".equals(uploadType)) {
result = ossClientUtil.uploadFile2OSS(file.getInputStream(),fileName);
}else if ("local".equals(uploadType)) {
localFileUtil.saveFile(file.getInputStream(), fileName);
}
resultMap.put("id", date + num);
resultMap.put("value", path + "//" + fileName);
resultMap.put("name", realName);
}
catch (Exception e){
log.error(e.getMessage(),e);
}
FileEntity entity = new FileEntity();
entity.setContentType(contentType);
entity.setCreateTime(new Date());
entity.setFileName(realName);
entity.setFileType(ext);
entity.setFileSize(String.valueOf(file.getSize()));
entity.setFileId(date + num);
entity.setSavePath(fileName);
this.addFile(entity);
return resultMap;
}
@Override
public boolean hasExcelFileId(List<String> fileIds) {
boolean hasExcelFileId = false;
LambdaQueryWrapper<FileEntity> fileEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
fileEntityLambdaQueryWrapper.in(FileEntity::getFileId, fileIds);
List<FileEntity> fileEntities = fileDao.selectList(fileEntityLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(fileEntities)) {
for (FileEntity fileEntity : fileEntities) {
if (ReportConstants.FILE_EXTENSIONS_XLS.equals(fileEntity.getFileType()) ||
ReportConstants.FILE_EXTENSIONS_XLSX.equals(fileEntity.getFileType())) {
hasExcelFileId = true;
break;
}
}
}
return hasExcelFileId;
}
@Override
public List<String> getDownloadFileIds(String reportId) {
return fileDao.getDownloadFileIds(reportId);
}
} }
@@ -0,0 +1,108 @@
package com.adc.da.report.service.impl;
import com.adc.da.login.util.UserUtils;
import com.adc.da.report.constant.MessageConstants;
import com.adc.da.report.constant.MessageTypeEnum;
import com.adc.da.report.constant.ReportConstants;
import com.adc.da.report.dao.mysql.UserMessageDao;
import com.adc.da.report.eo.UserMessageEntity;
import com.adc.da.report.service.IUserMessageService;
import com.adc.da.report.vo.MessageQueryVo;
import com.adc.da.report.vo.MessageVo;
import com.adc.da.sys.dao.mysql.UserEODao;
import com.adc.da.sys.entity.UserEO;
import com.adc.da.sys.service.iservice.IUserEoService;
import com.adc.da.util.exception.AdcDaBaseException;
import com.adc.da.util.http.ResponseMessage;
import com.adc.da.util.http.Result;
import com.adc.da.util.utils.UUID;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.adc.da.report.eo.MessageEntity;
import com.adc.da.report.service.IMessageService;
import com.adc.da.report.dao.mysql.MessageDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author ThinkBook
* @description 针对表【ts_message】的数据库操作Service实现
* @createDate 2023-05-23 11:22:15
*/
@Service
public class IMessageServiceImpl extends ServiceImpl<MessageDao, MessageEntity>
implements IMessageService {
@Resource
private MessageDao messageDao;
@Resource
private IUserMessageService userMessageService;
@Resource
private UserEODao userEODao;
@Override
public ResponseMessage listByCurrentUser(MessageQueryVo messageVo) {
IPage<MessageVo> page = new Page<>();
page.setCurrent(messageVo.getPageNo());
page.setSize(messageVo.getPageSize());
IPage<MessageVo> list = messageDao.listByUser(page, messageVo, UserUtils.getUserId());
return Result.success(list);
}
@Override
public ResponseMessage allRead() {
LambdaUpdateWrapper<UserMessageEntity> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(UserMessageEntity::getReadType, MessageConstants.UNREAD);
wrapper.eq(UserMessageEntity::getUserId, UserUtils.getUserId());
wrapper.set(UserMessageEntity::getReadType, MessageConstants.READ);
userMessageService.update(wrapper);
return Result.success("全部已读");
}
@Override
@Transactional(rollbackFor = Exception.class)
public void publishMessage(MessageEntity message, boolean toAllUser, List<String> userIds) {
List<String> userEoIds = new ArrayList<>();
if (toAllUser) {
LambdaQueryWrapper<UserEO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserEO::getDelFlag, 0);
List<UserEO> userEOS = userEODao.selectList(lambdaQueryWrapper);
if (userEOS != null) {
userEoIds = userEOS.stream().map(UserEO::getUsid).collect(Collectors.toList());
}
} else {
userEoIds = userIds;
if (userEoIds.isEmpty()) {
throw new AdcDaBaseException("无指定发送的用户,无法发送站内信");
}
}
//保存消息信息
save(message);
List<UserMessageEntity> userMessageEntities = new ArrayList<>();
userEoIds.forEach(userId -> {
UserMessageEntity userMessageEntity = new UserMessageEntity();
userMessageEntity.setId(UUID.randomUUID10())
.setUserId(userId)
.setMessageId(message.getId())
.setReadType(MessageConstants.UNREAD)
.setDelFlag(0);
userMessageEntities.add(userMessageEntity);
});
userMessageService.saveBatch(userMessageEntities);
}
}
@@ -1,19 +1,22 @@
package com.adc.da.report.service.impl; package com.adc.da.report.service.impl;
import com.adc.da.report.dao.mysql.FileDao; import com.adc.da.report.dao.mysql.FileDao;
import com.adc.da.report.dao.mysql.ReportFileDao;
import com.adc.da.report.eo.FileEntity; import com.adc.da.report.eo.FileEntity;
import com.adc.da.report.eo.ReportFile;
import com.adc.da.report.util.FileContentUtil; import com.adc.da.report.util.FileContentUtil;
import com.adc.da.report.util.LocalFileUtil; import com.adc.da.report.util.LocalFileUtil;
import com.adc.da.report.util.OSSClientUtil; import com.adc.da.report.util.OSSClientUtil;
import com.adc.da.report.util.ObsBootUtil; import com.adc.da.report.util.ObsBootUtil;
import com.adc.da.util.utils.CollectionUtils;
import com.adc.da.util.utils.FileUtil; import com.adc.da.util.utils.FileUtil;
import com.adc.da.util.utils.UUID; import com.adc.da.util.utils.UUID;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.adc.da.report.eo.ReportContentEntity; import com.adc.da.report.eo.ReportContentEntity;
import com.adc.da.report.service.IReportContentService; import com.adc.da.report.service.IReportContentService;
import com.adc.da.report.dao.mysql.ReportContentDao; import com.adc.da.report.dao.mysql.ReportContentDao;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -22,6 +25,9 @@ import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author Caihaohan * @author Caihaohan
@@ -51,36 +57,51 @@ public class IReportContentServiceImpl extends ServiceImpl<ReportContentDao, Rep
@Resource @Resource
private FileDao fileDao; private FileDao fileDao;
@Resource
private ReportFileDao reportFileDao;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void insertReportContent(String reportId, String fileId) throws IOException { public void insertReportContent(String reportId) throws IOException {
//获取文件 LambdaQueryWrapper<ReportFile> reportFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
FileEntity fileEntity = fileDao.selectById(fileId); reportFileLambdaQueryWrapper.eq(ReportFile::getReportId, reportId);
String path = uploadFile + fileEntity.getSavePath(); reportFileLambdaQueryWrapper.eq(ReportFile::getState, 2);
FileOutputStream outputStream = new FileOutputStream(path); List<ReportFile> reportFiles = reportFileDao.selectList(reportFileLambdaQueryWrapper);
// 上传方式:阿里云:alioss 华为云:hwobs List<String> fileIds = new ArrayList<>();
if ("hwobs".equals(uploadType)) { if (CollectionUtils.isNotEmpty(reportFiles)) {
obsBootUtil.getFileFromOBS(fileEntity.getSavePath(), outputStream); fileIds = reportFiles.stream().map(ReportFile::getFileId).collect(Collectors.toList());
} else if ("alioss".equals(uploadType)) { }
ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream); StringBuilder content = new StringBuilder();
} else if ("local".equals(uploadType)) { for (String fileId : fileIds) {
localFileUtil.getFileFromLocal(fileEntity.getSavePath(), outputStream); //获取文件
FileEntity fileEntity = fileDao.selectById(fileId);
String path = uploadFile + fileEntity.getSavePath();
FileOutputStream outputStream = new FileOutputStream(path);
// 上传方式:阿里云:alioss 华为云:hwobs
if ("hwobs".equals(uploadType)) {
obsBootUtil.getFileFromOBS(fileEntity.getSavePath(), outputStream);
} else if ("alioss".equals(uploadType)) {
ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream);
} else if ("local".equals(uploadType)) {
localFileUtil.getFileFromLocal(fileEntity.getSavePath(), outputStream);
}
File file = new File(path);
//解析出内容
content.append(FileContentUtil.readFileContent(file));
//将文件删除
outputStream.close();
FileUtil.deleteFile(path);
} }
File file = new File(path);
//解析出内容
String content = FileContentUtil.readFileContent(file);
//将内容存入 //将内容存入
ReportContentEntity reportContent = query().eq("report_id", reportId).one(); ReportContentEntity reportContent = query().eq("report_id", reportId).one();
if (reportContent == null) { if (reportContent == null) {
ReportContentEntity reportContentEntity = new ReportContentEntity(UUID.randomUUID10(), reportId, content); ReportContentEntity reportContentEntity = new ReportContentEntity(UUID.randomUUID10(), reportId, content.toString());
save(reportContentEntity); save(reportContentEntity);
} else { } else {
reportContent.setReportContent(content); reportContent.setReportContent(content.toString());
saveOrUpdate(reportContent); saveOrUpdate(reportContent);
} }
//将文件删除
outputStream.close();
FileUtil.deleteFile(path);
} }
} }
@@ -0,0 +1,16 @@
package com.adc.da.report.service.impl;
import com.adc.da.report.dao.mysql.ReportFileDao;
import com.adc.da.report.eo.ReportFile;
import com.adc.da.report.service.IReportFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class IReportFileServiceImpl extends ServiceImpl<ReportFileDao, ReportFile>
implements IReportFileService {
}
@@ -6,6 +6,7 @@ import com.adc.da.login.util.UserUtils;
import com.adc.da.report.constant.ReportConstants; import com.adc.da.report.constant.ReportConstants;
import com.adc.da.report.dao.mysql.FileDao; import com.adc.da.report.dao.mysql.FileDao;
import com.adc.da.report.dao.mysql.ReportDao; import com.adc.da.report.dao.mysql.ReportDao;
import com.adc.da.report.dao.mysql.ReportFileDao;
import com.adc.da.report.dao.mysql.ReportLabelDao; import com.adc.da.report.dao.mysql.ReportLabelDao;
import com.adc.da.report.eo.*; import com.adc.da.report.eo.*;
import com.adc.da.report.service.*; import com.adc.da.report.service.*;
@@ -22,6 +23,7 @@ import com.adc.da.sys.entity.RoleEO;
import com.adc.da.sys.entity.UserEO; import com.adc.da.sys.entity.UserEO;
import com.adc.da.sys.service.MenuEOService; import com.adc.da.sys.service.MenuEOService;
import com.adc.da.sys.service.OrgEOService; import com.adc.da.sys.service.OrgEOService;
import com.adc.da.sys.util.BeanCopyUtils;
import com.adc.da.util.http.ResponseMessage; import com.adc.da.util.http.ResponseMessage;
import com.adc.da.util.http.Result; import com.adc.da.util.http.Result;
import com.adc.da.util.utils.CollectionUtils; import com.adc.da.util.utils.CollectionUtils;
@@ -128,6 +130,12 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
@Resource @Resource
private MenuEOService menuEOService; private MenuEOService menuEOService;
@Autowired
private IReportFileService iReportFileService;
@Autowired
private ReportFileDao reportFileDao;
@Override @Override
public void addOrUpdate(ReportEntity reportEntity) { public void addOrUpdate(ReportEntity reportEntity) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -143,6 +151,17 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
reportDao.insert(reportEntity); reportDao.insert(reportEntity);
} }
String reportId = reportEntity.getId(); String reportId = reportEntity.getId();
//文件
reportFileDao.delByReportId(new ReportFile(reportId,2));
List<ReportFile> reportFiles = new ArrayList<>();
for (ReportFile reportFile : reportEntity.getFileList()) {
reportFile.setId(UUID.randomUUID().replace("-",""));
reportFile.setReportId(reportId);
// reportFile.setFileId(s);
reportFile.setState(2);
reportFiles.add(reportFile);
}
iReportFileService.saveBatch(reportFiles);
//插入报表标签关系表 //插入报表标签关系表
//修改报表标签关系表(先删后增) //修改报表标签关系表(先删后增)
iReportLabelService.deleteReportLabelByReportId(new String[]{reportId}); iReportLabelService.deleteReportLabelByReportId(new String[]{reportId});
@@ -156,13 +175,13 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
labelList.add(reportLabelEntity); labelList.add(reportLabelEntity);
} }
iReportLabelService.saveBatch(labelList); iReportLabelService.saveBatch(labelList);
//插入报表内容表 }
try { //插入报表内容表
iReportContentService.insertReportContent(reportId, reportEntity.getFileId()); try {
log.info("抽取报告内容"); iReportContentService.insertReportContent(reportId);
} catch (IOException e) { log.info("抽取报告内容");
log.error("获取报告内容失败", e); } catch (IOException e) {
} log.error("获取报告内容失败", e);
} }
} }
@@ -181,6 +200,11 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
return Result.success("修改成功"); return Result.success("修改成功");
} }
@Override
public void delFile(ReportFile reportFile) {
reportFileDao.deleteBatchIds(reportFile.getRfIdList());
}
/** /**
* 新增或编辑报告 * 新增或编辑报告
* *
@@ -267,8 +291,6 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
reportLabelDao.insert(reportLabelEntity); reportLabelDao.insert(reportLabelEntity);
}); });
//TODO 插入报表内容表(先删后增)
//删除power_apply表中的对应权限 //删除power_apply表中的对应权限
iPowerApplyService.deleteByReportId(entity.getId()); iPowerApplyService.deleteByReportId(entity.getId());
@@ -400,18 +422,18 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
/** /**
* 报告html * 报告html
* *
* @param id * @param reportId
* @param fileId
* @return * @return
*/ */
@Override @Override
public String reportHtml(String id) { public String reportHtml(String reportId, String fileId) {
try { try {
ReportEntity entity = reportDao.selectById(id); String key = reportId + fileId;
String key = entity.getId() + "-" + entity.getFileId();
String html = stringRedisTemplate.boundValueOps(key).get(); String html = stringRedisTemplate.boundValueOps(key).get();
//没有的话就生成 //没有的话就生成
if (StrUtil.isBlank(html)) { if (StrUtil.isBlank(html)) {
html = createHtmlString(entity.getFileId()); html = createHtmlString(fileId);
log.info("执行完成html" + html); log.info("执行完成html" + html);
@@ -529,38 +551,38 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
}); });
} }
list.getRecords().forEach(c -> { // list.getRecords().forEach(c -> {
FileEntity fileEntity = Optional.ofNullable(fileDao.selectById(c.getFileId())).orElse(new FileEntity()); // FileEntity fileEntity = Optional.ofNullable(fileDao.selectById(c.getFileId())).orElse(new FileEntity());
if (StringUtils.isEmpty(fileEntity.getFileType())) { // if (StringUtils.isEmpty(fileEntity.getFileType())) {
c.setFileType(null); // c.setFileType(null);
} // }
//ppt文件 // //ppt文件
else if (ReportConstants.FILE_EXTENSIONS_PPT.equalsIgnoreCase(fileEntity.getFileType()) || // else if (ReportConstants.FILE_EXTENSIONS_PPT.equalsIgnoreCase(fileEntity.getFileType()) ||
ReportConstants.FILE_EXTENSIONS_PPTX.equalsIgnoreCase(fileEntity.getFileType())) { // ReportConstants.FILE_EXTENSIONS_PPTX.equalsIgnoreCase(fileEntity.getFileType())) {
c.setFileType("1"); // c.setFileType("1");
} // }
//excel文件 // //excel文件
else if (ReportConstants.FILE_EXTENSIONS_XLS.equalsIgnoreCase(fileEntity.getFileType()) || // else if (ReportConstants.FILE_EXTENSIONS_XLS.equalsIgnoreCase(fileEntity.getFileType()) ||
ReportConstants.FILE_EXTENSIONS_XLSX.equalsIgnoreCase(fileEntity.getFileType())) { // ReportConstants.FILE_EXTENSIONS_XLSX.equalsIgnoreCase(fileEntity.getFileType())) {
c.setFileType("2"); // c.setFileType("2");
} // }
//pdf文件 // //pdf文件
else if (ReportConstants.FILE_EXTENSIONS_PDF.equalsIgnoreCase(fileEntity.getFileType())) { // else if (ReportConstants.FILE_EXTENSIONS_PDF.equalsIgnoreCase(fileEntity.getFileType())) {
c.setFileType("3"); // c.setFileType("3");
} // }
//word文件 // //word文件
else { // else {
c.setFileType("4"); // c.setFileType("4");
} // }
//
//文件大小 // //文件大小
c.setFileSize(StringUtils.isNotEmpty(fileEntity.getFileSize()) // c.setFileSize(StringUtils.isNotEmpty(fileEntity.getFileSize())
? String.valueOf(Integer.parseInt(fileEntity.getFileSize()) / 1024) + "kb" : "0kb"); // ? String.valueOf(Integer.parseInt(fileEntity.getFileSize()) / 1024) + "kb" : "0kb");
c.setFileName(fileEntity.getFileName()); // c.setFileName(fileEntity.getFileName());
// List<String> userIdList = reportUserDao.selectList( // List<String> userIdList = reportUserDao.selectList(
// new QueryWrapper<ReportUserEntity>().eq("reportId", c.getId())) // new QueryWrapper<ReportUserEntity>().eq("reportId", c.getId()))
// .stream().map(ReportUserEntity::getUserId).collect(Collectors.toList()); // .stream().map(ReportUserEntity::getUserId).collect(Collectors.toList());
}); // });
return list; return list;
} }
@@ -612,38 +634,38 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
} }
}); });
list.getRecords().forEach(c -> { // list.getRecords().forEach(c -> {
FileEntity fileEntity = Optional.ofNullable(fileDao.selectById(c.getFileId())).orElse(new FileEntity()); // FileEntity fileEntity = Optional.ofNullable(fileDao.selectById(c.getFileId())).orElse(new FileEntity());
if (StringUtils.isEmpty(fileEntity.getFileType())) { // if (StringUtils.isEmpty(fileEntity.getFileType())) {
c.setFileType(null); // c.setFileType(null);
} // }
//ppt文件 // //ppt文件
else if (ReportConstants.FILE_EXTENSIONS_PPT.equalsIgnoreCase(fileEntity.getFileType()) || // else if (ReportConstants.FILE_EXTENSIONS_PPT.equalsIgnoreCase(fileEntity.getFileType()) ||
ReportConstants.FILE_EXTENSIONS_PPTX.equalsIgnoreCase(fileEntity.getFileType())) { // ReportConstants.FILE_EXTENSIONS_PPTX.equalsIgnoreCase(fileEntity.getFileType())) {
c.setFileType("1"); // c.setFileType("1");
} // }
//excel文件 // //excel文件
else if (ReportConstants.FILE_EXTENSIONS_XLS.equalsIgnoreCase(fileEntity.getFileType()) || // else if (ReportConstants.FILE_EXTENSIONS_XLS.equalsIgnoreCase(fileEntity.getFileType()) ||
ReportConstants.FILE_EXTENSIONS_XLSX.equalsIgnoreCase(fileEntity.getFileType())) { // ReportConstants.FILE_EXTENSIONS_XLSX.equalsIgnoreCase(fileEntity.getFileType())) {
c.setFileType("2"); // c.setFileType("2");
} // }
//pdf文件 // //pdf文件
else if (ReportConstants.FILE_EXTENSIONS_PDF.equalsIgnoreCase(fileEntity.getFileType())) { // else if (ReportConstants.FILE_EXTENSIONS_PDF.equalsIgnoreCase(fileEntity.getFileType())) {
c.setFileType("3"); // c.setFileType("3");
} // }
//word文件 // //word文件
else { // else {
c.setFileType("4"); // c.setFileType("4");
} // }
//
//文件大小 // //文件大小
c.setFileSize(StringUtils.isNotEmpty(fileEntity.getFileSize()) // c.setFileSize(StringUtils.isNotEmpty(fileEntity.getFileSize())
? String.valueOf(Integer.parseInt(fileEntity.getFileSize()) / 1024) + "kb" : "0kb"); // ? String.valueOf(Integer.parseInt(fileEntity.getFileSize()) / 1024) + "kb" : "0kb");
c.setFileName(fileEntity.getFileName()); // c.setFileName(fileEntity.getFileName());
// List<String> userIdList = reportUserDao.selectList( // List<String> userIdList = reportUserDao.selectList(
// new QueryWrapper<ReportUserEntity>().eq("reportId", c.getId())) // new QueryWrapper<ReportUserEntity>().eq("reportId", c.getId()))
// .stream().map(ReportUserEntity::getUserId).collect(Collectors.toList()); // .stream().map(ReportUserEntity::getUserId).collect(Collectors.toList());
}); // });
return list; return list;
} }
@@ -716,6 +738,22 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
@Override @Override
public ResponseMessage reportDetail(String reportId) { public ResponseMessage reportDetail(String reportId) {
ReportDetailVo reportDetailVo = reportDao.reportDetail(reportId); ReportDetailVo reportDetailVo = reportDao.reportDetail(reportId);
//设置文件信息
LambdaQueryWrapper<ReportFile> reportFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
reportFileLambdaQueryWrapper.eq(ReportFile::getReportId, reportDetailVo.getId());
reportFileLambdaQueryWrapper.eq(ReportFile::getState, ReportConstants.NOT_IN_PROCESS);
List<ReportFile> reportFiles = reportFileDao.selectList(reportFileLambdaQueryWrapper);
List<String> fileIds = new ArrayList<>();
if (reportFiles != null) {
fileIds = reportFiles.stream().map(ReportFile::getFileId).collect(Collectors.toList());
}
if (CollectionUtils.isNotEmpty(fileIds)) {
List<FileEntity> fileEntities = fileDao.selectBatchIds(fileIds);
List<ReportFile> fileVos = BeanCopyUtils.copyBeanList(fileEntities, ReportFile.class);
reportDetailVo.setFileList(fileVos);
}
//设置部门名称 //设置部门名称
String department = reportDetailVo.getDepartment(); String department = reportDetailVo.getDepartment();
if (StrUtil.isNotBlank(department)) { if (StrUtil.isNotBlank(department)) {
@@ -5,12 +5,14 @@ import cn.hutool.core.bean.BeanUtil;
import com.adc.da.login.util.UserUtils; import com.adc.da.login.util.UserUtils;
import com.adc.da.report.dao.mysql.PowerApplyDao; import com.adc.da.report.dao.mysql.PowerApplyDao;
import com.adc.da.report.dao.mysql.ReportDao; import com.adc.da.report.dao.mysql.ReportDao;
import com.adc.da.report.dao.mysql.ReportFileDao;
import com.adc.da.report.dao.mysql.TtReportManageActDao; import com.adc.da.report.dao.mysql.TtReportManageActDao;
import com.adc.da.report.eo.LogEntity; import com.adc.da.report.eo.LogEntity;
import com.adc.da.report.eo.ReportEntity; import com.adc.da.report.eo.ReportEntity;
import com.adc.da.report.eo.TtReportManageAct; import com.adc.da.report.eo.TtReportManageAct;
import com.adc.da.report.service.ILogService; import com.adc.da.report.service.ILogService;
import com.adc.da.report.service.IReportContentService; import com.adc.da.report.service.IReportContentService;
import com.adc.da.report.service.IReportFileService;
import com.adc.da.report.service.ITtReportManageActService; import com.adc.da.report.service.ITtReportManageActService;
import com.adc.da.report.vo.DeleteParamRequestVO; import com.adc.da.report.vo.DeleteParamRequestVO;
import com.adc.da.report.vo.TtReportManageActPageVO; import com.adc.da.report.vo.TtReportManageActPageVO;
@@ -51,7 +53,11 @@ public class ITtReportManageActServiceImpl extends ServiceImpl<TtReportManageAct
@Resource @Resource
private IReportContentService iReportContentService; private IReportContentService iReportContentService;
@Autowired
private IReportFileService iReportFileService;
@Autowired
private ReportFileDao reportFileDao;
/** /**
* @param ttReportManageActPageVO * @param ttReportManageActPageVO
* @return <com.adc.da.report.entity.TtReportManageAct> * @return <com.adc.da.report.entity.TtReportManageAct>
@@ -152,8 +158,12 @@ public class ITtReportManageActServiceImpl extends ServiceImpl<TtReportManageAct
reportDao.updateById(reportEntity1); reportDao.updateById(reportEntity1);
reportLog(reportEntity.getName(),"编辑"); reportLog(reportEntity.getName(),"编辑");
} }
// 文件
reportFileDao.actEndDelReport(ttReportManageAct.getDataId());
reportFileDao.updateState(ttReportManageAct.getDataId());
try { try {
iReportContentService.insertReportContent(ttReportManageAct.getDataId(), ttReportManageAct.getFileId()); iReportContentService.insertReportContent(ttReportManageAct.getDataId());
log.info("抽取报告内容"); log.info("抽取报告内容");
} catch (IOException e) { } catch (IOException e) {
log.error("获取报告内容失败", e); log.error("获取报告内容失败", e);
@@ -0,0 +1,22 @@
package com.adc.da.report.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.adc.da.report.eo.UserMessageEntity;
import com.adc.da.report.service.IUserMessageService;
import com.adc.da.report.dao.mysql.UserMessageDao;
import org.springframework.stereotype.Service;
/**
* @author ThinkBook
* @description 针对表【ts_user_message】的数据库操作Service实现
* @createDate 2023-05-23 11:30:04
*/
@Service
public class IUserMessageServiceImpl extends ServiceImpl<UserMessageDao, UserMessageEntity>
implements IUserMessageService {
}
@@ -5,11 +5,11 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import com.adc.da.report.constant.ReportConstants; import com.adc.da.report.constant.ReportConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hslf.usermodel.HSLFShape; import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFSlide; import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFTextShape; import org.apache.poi.hslf.usermodel.HSLFTextShape;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XMLSlideShow;
@@ -22,7 +22,6 @@ import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.PDFTextStripper;
@@ -31,6 +30,7 @@ import org.apache.pdfbox.text.PDFTextStripper;
* *
* @author caihaohan * @author caihaohan
*/ */
@Slf4j
public class FileContentUtil { public class FileContentUtil {
public static String readFileContent(File file) throws IOException { public static String readFileContent(File file) throws IOException {
@@ -39,55 +39,58 @@ public class FileContentUtil {
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
try {
switch (fileExtension) { switch (fileExtension) {
case ReportConstants.FILE_EXTENSIONS_XLS: case ReportConstants.FILE_EXTENSIONS_XLS:
HSSFWorkbook workbookXls = new HSSFWorkbook(fis); HSSFWorkbook workbookXls = new HSSFWorkbook(fis);
content = new StringBuilder(readExcelContent(workbookXls)); content = new StringBuilder(readExcelContent(workbookXls));
break; break;
case ReportConstants.FILE_EXTENSIONS_XLSX: case ReportConstants.FILE_EXTENSIONS_XLSX:
XSSFWorkbook workbookXlsx = new XSSFWorkbook(fis); XSSFWorkbook workbookXlsx = new XSSFWorkbook(fis);
content = new StringBuilder(readExcelContent(workbookXlsx)); content = new StringBuilder(readExcelContent(workbookXlsx));
break; break;
case ReportConstants.FILE_EXTENSIONS_DOC: case ReportConstants.FILE_EXTENSIONS_DOC:
HWPFDocument documentDoc = new HWPFDocument(fis); HWPFDocument documentDoc = new HWPFDocument(fis);
WordExtractor extractorDoc = new WordExtractor(documentDoc); WordExtractor extractorDoc = new WordExtractor(documentDoc);
content = new StringBuilder(extractorDoc.getText()); content = new StringBuilder(extractorDoc.getText());
break; break;
case ReportConstants.FILE_EXTENSIONS_DOCX: case ReportConstants.FILE_EXTENSIONS_DOCX:
XWPFDocument documentDocx = new XWPFDocument(fis); XWPFDocument documentDocx = new XWPFDocument(fis);
XWPFWordExtractor extractorDocx = new XWPFWordExtractor(documentDocx); XWPFWordExtractor extractorDocx = new XWPFWordExtractor(documentDocx);
content = new StringBuilder(extractorDocx.getText()); content = new StringBuilder(extractorDocx.getText());
break; break;
case ReportConstants.FILE_EXTENSIONS_PPT: case ReportConstants.FILE_EXTENSIONS_PPT:
HSLFSlideShow ppt = new HSLFSlideShow(fis); HSLFSlideShow ppt = new HSLFSlideShow(fis);
for (HSLFSlide slide : ppt.getSlides()) { for (HSLFSlide slide : ppt.getSlides()) {
for (HSLFShape shape : slide.getShapes()) { for (HSLFShape shape : slide.getShapes()) {
if (shape instanceof HSLFTextShape) { if (shape instanceof HSLFTextShape) {
HSLFTextShape textShape = (HSLFTextShape) shape; HSLFTextShape textShape = (HSLFTextShape) shape;
content.append(textShape.getText()).append("\n"); content.append(textShape.getText()).append("\n");
}
} }
} }
} break;
break; case ReportConstants.FILE_EXTENSIONS_PPTX:
case ReportConstants.FILE_EXTENSIONS_PPTX: XMLSlideShow pptx = new XMLSlideShow(fis);
XMLSlideShow pptx = new XMLSlideShow(fis); for (XSLFSlide slide : pptx.getSlides()) {
for (XSLFSlide slide : pptx.getSlides()) { for (XSLFShape shape : slide.getShapes()) {
for (XSLFShape shape : slide.getShapes()) { if (shape instanceof XSLFTextShape) {
if (shape instanceof XSLFTextShape) { XSLFTextShape textShape = (XSLFTextShape) shape;
XSLFTextShape textShape = (XSLFTextShape) shape; content.append(textShape.getText()).append("\n");
content.append(textShape.getText()).append("\n"); }
} }
} }
} break;
break; case ReportConstants.FILE_EXTENSIONS_PDF:
case ReportConstants.FILE_EXTENSIONS_PDF: PDDocument document = PDDocument.load(fis);
PDDocument document = PDDocument.load(fis); PDFTextStripper stripper = new PDFTextStripper();
PDFTextStripper stripper = new PDFTextStripper(); content = new StringBuilder(stripper.getText(document));
content = new StringBuilder(stripper.getText(document)); default:
default: }
} catch (Exception e) {
fis.close();
log.info("文件内容抽取失败,原因可能是上传的文件为空文件");
} }
fis.close();
return content.toString(); return content.toString();
} }
@@ -10,6 +10,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* @author Caihaohan * @author Caihaohan
@@ -24,6 +27,39 @@ public class LocalFileUtil {
@Value("${localFilePath}") @Value("${localFilePath}")
private String localFilePath; private String localFilePath;
public void compressFiles(List<String> filePaths, HttpServletResponse response) {
try {
// 创建输出流
OutputStream outputStream = response.getOutputStream();
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
byte[] buffer = new byte[1024];
for (String filePath : filePaths) {
File sourceFile = new File(filePath);
ZipEntry zipEntry = new ZipEntry(sourceFile.getName());
zipOutputStream.putNextEntry(zipEntry);
FileInputStream fileInputStream = new FileInputStream(sourceFile);
int len;
while ((len = fileInputStream.read(buffer)) > 0) {
zipOutputStream.write(buffer, 0, len);
}
fileInputStream.close();
zipOutputStream.closeEntry();
}
zipOutputStream.close();
System.out.println("文件成功压缩成ZIP格式并写入 HttpServletResponse");
} catch (IOException e) {
e.printStackTrace();
}
}
public void saveFile(InputStream fileInputStream, String fileName) throws IOException { public void saveFile(InputStream fileInputStream, String fileName) throws IOException {
String path = localFilePath + fileName; String path = localFilePath + fileName;
FileOutputStream fileOutputStream = new FileOutputStream(path); FileOutputStream fileOutputStream = new FileOutputStream(path);
@@ -21,6 +21,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.awt.*; import java.awt.*;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.time.LocalDate; import java.time.LocalDate;
@@ -52,49 +53,62 @@ public class WaterMarkUtil {
return configValue + " " + userName + " " + formattedDate; return configValue + " " + userName + " " + formattedDate;
} }
public void addWatermarkToPdf(FileInputStream inputStream, HttpServletResponse response) throws IOException { public PDDocument addWatermarkToPdf(FileInputStream inputStream) throws IOException {
String watermarkText = getWaterMarkConfig(); String watermarkText = getWaterMarkConfig();
// 加载PDF文档 PDDocument document = PDDocument.load(inputStream);
try (PDDocument document = PDDocument.load(inputStream)) {
// 设置水印字体、字体大小、颜色和透明度
ClassPathResource fontResource = new ClassPathResource("fonts/SourceHanSerif-VF.ttf");
PDType0Font font = PDType0Font.load(document, fontResource.getInputStream());
float fontSize = 13.0f;
Color color = new Color(100, 100, 100, 0);
PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState();
graphicsState.setNonStrokingAlphaConstant(0.4f);
graphicsState.setStrokingAlphaConstant(0.4f);
// 遍历每一页并添加水印 // 设置水印字体、字体大小、颜色和透明度
for (PDPage page : document.getPages()) { ClassPathResource fontResource = new ClassPathResource("fonts/SourceHanSerif-VF.ttf");
// 获取页面尺寸以计算水印位置 PDType0Font font = PDType0Font.load(document, fontResource.getInputStream());
PDRectangle pageSize = page.getMediaBox(); float fontSize = 13.0f;
float xStep = pageSize.getWidth() / 4; Color color = new Color(100, 100, 100, 0);
float yStep = pageSize.getHeight() / 4; PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState();
float rotationInRadians = (float) Math.toRadians(20); graphicsState.setNonStrokingAlphaConstant(0.4f);
graphicsState.setStrokingAlphaConstant(0.4f);
for (float xPosition = pageSize.getLowerLeftX(); xPosition <= pageSize.getWidth(); xPosition += xStep) { // 遍历每一页并添加水印
for (float yPosition = pageSize.getLowerLeftY(); yPosition <= pageSize.getHeight(); yPosition += yStep) { for (PDPage page : document.getPages()) {
// 创建内容流并设置图形状态参数 // 获取页面尺寸以计算水印位置
try (PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, true)) { PDRectangle pageSize = page.getMediaBox();
contentStream.setGraphicsStateParameters(graphicsState); float xStep = pageSize.getWidth() / 4;
contentStream.setFont(font, fontSize); float yStep = pageSize.getHeight() / 4;
contentStream.setNonStrokingColor(color); float rotationInRadians = (float) Math.toRadians(20);
contentStream.beginText();
contentStream.setRenderingMode(RenderingMode.FILL); for (float xPosition = pageSize.getLowerLeftX(); xPosition <= pageSize.getWidth(); xPosition += xStep) {
// 设置水印文本的旋转和位置 for (float yPosition = pageSize.getLowerLeftY(); yPosition <= pageSize.getHeight(); yPosition += yStep) {
contentStream.setTextMatrix(Matrix.getRotateInstance(rotationInRadians, xPosition, yPosition)); // 创建内容流并设置图形状态参数
contentStream.showText(watermarkText); try (PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, true)) {
contentStream.endText(); contentStream.setGraphicsStateParameters(graphicsState);
} contentStream.setFont(font, fontSize);
contentStream.setNonStrokingColor(color);
contentStream.beginText();
contentStream.setRenderingMode(RenderingMode.FILL);
// 设置水印文本的旋转和位置
contentStream.setTextMatrix(Matrix.getRotateInstance(rotationInRadians, xPosition, yPosition));
contentStream.showText(watermarkText);
contentStream.endText();
} }
} }
} }
}
return document;
}
// 将处理后的PDF写入HTTP响应
try (OutputStream outputStream = response.getOutputStream()) { public void savePdfToFile(FileInputStream inputStream, String outputPath) throws IOException {
document.save(outputStream); PDDocument pdDocument = addWatermarkToPdf(inputStream);
} try (FileOutputStream outputStream = new FileOutputStream(outputPath)) {
pdDocument.save(outputStream);
} }
} }
public void addWatermarkToPdfAndWriteToResponse(FileInputStream inputStream, HttpServletResponse response) throws IOException {
PDDocument document = addWatermarkToPdf(inputStream);
try (OutputStream outputStream = response.getOutputStream()) {
document.save(outputStream);
}
document.close();
}
} }
@@ -0,0 +1,21 @@
package com.adc.da.report.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FileVo {
/**
* 文件主键id
*/
private String fileId;
/**
* 文件名
*/
private String fileName;
}
@@ -0,0 +1,41 @@
package com.adc.da.report.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* @author: CaiHaohan
* @Date: 2023/5/23 14:14
* @Description:
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MessageQueryVo {
/**
* 标题
*/
private String messageTitle;
/**
* 发布人姓名
*/
private String createUserName;
/**
* 页数
*/
@Min(1)
private int pageNo;
/**
* 每页数量
*/
@NotNull
private int pageSize;
}
@@ -0,0 +1,79 @@
package com.adc.da.report.vo;
import com.adc.da.report.constant.MessageTypeEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author: CaiHaohan
* @Date: 2023/5/23 11:54
* @Description:
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class MessageVo {
/**
* 关系表的id
*/
private String id;
/**
* 标题
*/
private String messageTitle;
/**
* 内容
*/
private String content;
/**
* 消息类型
*/
private Integer messageType;
/**
* 消息类型
*/
private String messageTypeDesc;
/**
* 发布时间
*/
private Date createDate;
/**
* 创建用户id
*/
private String createUser;
/**
* 消息id
*/
private String messageId;
/**
* 阅读状态(0未读 1已读)
*/
private Integer readType;
public void setMessageType(Integer messageType) {
this.messageType = messageType;
switch (messageType) {
case 0:
this.messageTypeDesc = MessageTypeEnum.SYSTEM_MESSAGE.getDesc();
break;
default:
this.messageTypeDesc = "未知";
}
}
}
@@ -1,5 +1,7 @@
package com.adc.da.report.vo; package com.adc.da.report.vo;
import com.adc.da.report.eo.ReportFile;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -65,13 +67,6 @@ public class ReportDetailVo {
*/ */
private String privacyLevel; private String privacyLevel;
/**
* 文件id
*/
private String fileId;
private String fileName;
/** /**
* 创建人id * 创建人id
*/ */
@@ -111,4 +106,9 @@ public class ReportDetailVo {
* 保密到期日期 * 保密到期日期
*/ */
private Date secrecyLast; private Date secrecyLast;
@TableField(exist = false)
private List<ReportFile> fileList;
} }
@@ -1,5 +1,7 @@
package com.adc.da.report.vo; package com.adc.da.report.vo;
import com.adc.da.report.eo.ReportFile;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@@ -46,16 +48,6 @@ public class ReportVo {
*/ */
private String year; private String year;
/**
* 文件id
*/
private String fileId;
/**
* 文件名称
*/
private String fileName;
/** /**
* 文件类型 * 文件类型
*/ */
@@ -135,5 +127,6 @@ public class ReportVo {
private Integer isAct; private Integer isAct;
private String prcType; private String prcType;
@TableField(exist = false)
private List<ReportFile> fileList;
} }
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.adc.da.report.dao.mysql.FileDao">
<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}
AND
f.FILE_TYPE != "xls"
AND
f.FILE_TYPE != "xlsx"
</select>
</mapper>
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.adc.da.report.dao.mysql.MessageDao">
<resultMap id="BaseResultMap" type="com.adc.da.report.eo.MessageEntity">
<id property="id" column="id" jdbcType="VARCHAR"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="messageType" column="message_type" jdbcType="TINYINT"/>
<result property="createDate" column="createDate" jdbcType="TIMESTAMP"/>
<result property="delFlag" column="del_flag" jdbcType="TINYINT"/>
</resultMap>
<sql id="Base_Column_List">
id,content,message_type,
createDate,del_flag
</sql>
<select id="listByUser" resultType="com.adc.da.report.vo.MessageVo">
SELECT
um.id AS Id,
um.user_id AS userId,
um.message_id AS messageId,
um.read_type AS readType,
m.message_title AS messageTitle,
m.content AS content,
m.message_type AS messageType,
m.createDate AS createDate,
m.createUser AS createUser
FROM
ts_user_message AS um
LEFT JOIN ts_message AS m ON um.message_id = m.id
LEFT JOIN ts_user AS u ON m.createUser = u.USID
WHERE
um.del_flag = 0
AND
um.user_id = #{userId}
<!--全文模糊搜索-->
<if test="vo.messageTitle !='' and vo.messageTitle != null">
AND m.message_title like CONCAT(CONCAT('%', #{vo.messageTitle}), '%')
</if>
<if test="vo.createUserName !='' and vo.createUserName != null">
AND u.USNAME like CONCAT(CONCAT('%', #{vo.createUserName}), '%')
</if>
ORDER BY
um.read_type ASC
</select>
</mapper>
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.adc.da.report.dao.mysql.ReportFileDao">
<update id="updateState">
update ts_report_file set state = 2
where report_id = #{reportId}
</update>
<delete id="actEndDelReport">
delete from ts_report_file
<where>
report_id = #{reportId}
and state = 2
</where>
</delete>
<delete id="delByReportId">
delete from ts_report_file
<where>
<if test="pageVO.reportId !=null and pageVO.reportId !=''">
AND report_id = #{pageVO.reportId}
</if>
<if test="pageVO.state !=null">
AND state = #{pageVO.state}
</if>
</where>
</delete>
<select id="selectByReport" resultType="com.adc.da.report.eo.ReportFile">
select rf.*,f.file_name as fileName from ts_report_file rf
LEFT JOIN ts_file f on f.FILE_ID = rf.file_id
<where>
<if test="pageVO.reportId !=null and pageVO.reportId !=''">
AND report_id = #{pageVO.reportId}
</if>
<if test="pageVO.state !=null">
AND state = #{pageVO.state}
</if>
</where>
</select>
</mapper>
@@ -1,15 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.adc.da.report.dao.mysql.ReportDao"> <mapper namespace="com.adc.da.report.dao.mysql.ReportDao">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.adc.da.report.vo.ReportDetailVo">
<result column="id" property="id" />
<result column="name" property="name" />
<result column="uploaderName" property="uploaderName" />
<result column="keycontent" property="keyContent" />
<result column="maincontent" property="mainContent" />
<result column="department" property="department" />
<result column="departmentName" property="departmentName" />
<result column="year" property="year" />
<result column="confidentialLevel" property="confidentialLevel" />
<result column="privacyLevel" property="privacyLevel" />
<result column="createUserId" property="createUserId" />
<result column="secrecy_last" property="secrecyLast" />
<collection property="fileList" ofType="com.adc.da.report.eo.ReportFile">
<result column="fileId" property="fileId" />
<result column="fileName" property="fileName" />
<result column="rfId" property="id" />
</collection>
</resultMap>
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultReportVoMap" type="com.adc.da.report.vo.ReportVo">
<result column="id" property="id" />
<result column="name" property="name" />
<result column="keycontent" property="keyContent" />
<result column="maincontent" property="mainContent" />
<result column="department" property="department" />
<result column="year" property="year" />
<result column="confidentialLevel" property="confidentialLevel" />
<result column="privacyLevel" property="privacyLevel" />
<result column="createUserId" property="createUserId" />
<result column="uploader" property="uploader" />
<result column="createDate" property="createDate" />
<result column="thumbUp" property="thumbUp" />
<result column="clicks" property="clicks" />
<result column="download" property="download" />
<result column="reportRating" property="reportRating" />
<result column="isAct" property="isAct" />
<collection property="fileList" ofType="com.adc.da.report.eo.ReportFile">
<result column="fileId" property="fileId" />
<result column="fileName" property="fileName" />
<result column="rfId" property="id" />
</collection>
</resultMap>
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="BaseColumnList"> <sql id="BaseColumnList">
id, name, keycontent, maincontent, department, year, fileId, confidentialLevel, privacyLevel, id, name, keycontent, maincontent, department, year, confidentialLevel, privacyLevel,
createUserId, createDate, updateDate, del_flag,secrecy_last createUserId, createDate, updateDate, del_flag,secrecy_last
</sql> </sql>
<sql id="BaseColumnValue"> <sql id="BaseColumnValue">
#{Vo.id},#{Vo.name},#{Vo.keycontent},#{Vo.maincontent},#{Vo.department},#{Vo.year},#{Vo.fileId}, #{Vo.id},#{Vo.name},#{Vo.keycontent},#{Vo.maincontent},#{Vo.department},#{Vo.year},
#{Vo.confidentialLevel},#{Vo.privacyLevel}, #{Vo.confidentialLevel},#{Vo.privacyLevel},
#{Vo.createUserId}, #{Vo.createUserId},
#{Vo.createDate},#{Vo.updateDate},#{Vo.del_flag}, #{Vo.createDate},#{Vo.updateDate},#{Vo.del_flag},
@@ -19,7 +65,7 @@
<insert id="saveReportAct"> <insert id="saveReportAct">
insert into TT_REPORT_MANAGE (<include refid="BaseColumnList"/>) insert into TT_REPORT_MANAGE (<include refid="BaseColumnList"/>)
value ( value (
#{Vo.dataId},#{Vo.name},#{Vo.keyContent},#{Vo.mainContent},#{Vo.department},#{Vo.year},#{Vo.fileId}, #{Vo.dataId},#{Vo.name},#{Vo.keyContent},#{Vo.mainContent},#{Vo.department},#{Vo.year},
#{Vo.confidentialLevel},#{Vo.privacyLevel}, #{Vo.confidentialLevel},#{Vo.privacyLevel},
#{Vo.createUserId}, #{Vo.createUserId},
#{Vo.createDate},#{Vo.updateDate},#{Vo.delFlag}, #{Vo.createDate},#{Vo.updateDate},#{Vo.delFlag},
@@ -45,7 +91,6 @@
eo.maincontent, eo.maincontent,
eo.DEPARTMENT, eo.DEPARTMENT,
eo.YEAR, eo.YEAR,
eo.fileid,
eo.confidentialLevel, eo.confidentialLevel,
eo.privacyLevel, eo.privacyLevel,
eo.createUserId, eo.createUserId,
@@ -91,7 +136,7 @@
</select> </select>
<select id="page" resultType="com.adc.da.report.vo.ReportVo"> <select id="page" resultMap="BaseResultReportVoMap">
SELECT SELECT
eo.id AS id, eo.id AS id,
@@ -100,7 +145,6 @@
eo.maincontent AS mainContent, eo.maincontent AS mainContent,
eo.DEPARTMENT AS department, eo.DEPARTMENT AS department,
eo.`YEAR` AS `year`, eo.`YEAR` AS `year`,
eo.fileid AS fileId,
eo.confidentialLevel AS confidentialLevel, eo.confidentialLevel AS confidentialLevel,
eo.privacyLevel AS privacyLevel, eo.privacyLevel AS privacyLevel,
eo.createUserId AS createUserId, eo.createUserId AS createUserId,
@@ -113,6 +157,8 @@
IF(bpn.id is null,1, IF(bpn.id is null,1,
IF(bpn.SUBMIT_STATUS = 1 and bpn.CREAT_USER = #{pageVO.usid} ,0,1) IF(bpn.SUBMIT_STATUS = 1 and bpn.CREAT_USER = #{pageVO.usid} ,0,1)
) as isAct ) as isAct
,
f.FILE_ID as fileId, f.file_name as fileName ,rf.id as rfId
FROM FROM
TT_REPORT_MANAGE eo TT_REPORT_MANAGE eo
LEFT JOIN ts_report_content rc ON eo.id = rc.report_id LEFT JOIN ts_report_content rc ON eo.id = rc.report_id
@@ -122,6 +168,8 @@
LEFT JOIN (SELECT report_id, COUNT(id) AS download FROM report_log_book WHERE type = 2 GROUP BY report_id) AS downloadCount ON eo.id = downloadCount.report_id LEFT JOIN (SELECT report_id, COUNT(id) AS download FROM report_log_book WHERE type = 2 GROUP BY report_id) AS downloadCount ON eo.id = downloadCount.report_id
LEFT JOIN ts_report_user_rating AS trur ON eo.id = trur.report_id LEFT JOIN ts_report_user_rating AS trur ON eo.id = trur.report_id
LEFT JOIN bus_process_name as bpn on bpn.data_id = eo.id and bpn.prc_type != '5' LEFT JOIN bus_process_name as bpn on bpn.data_id = eo.id and bpn.prc_type != '5'
LEFT JOIN ts_report_file rf on rf.report_id = eo.id and rf.state = 2
LEFT JOIN ts_file f on f.FILE_ID = rf.file_id
WHERE WHERE
eo.DEL_FLAG = 0 eo.DEL_FLAG = 0
<!--全文模糊搜索--> <!--全文模糊搜索-->
@@ -175,7 +223,6 @@
t.year, t.year,
t.name, t.name,
t.keycontent, t.keycontent,
t.fileId,
t.createDate, t.createDate,
t.department, t.department,
t.maincontent, t.maincontent,
@@ -274,7 +321,7 @@
</select> </select>
<select id="reportDetail" resultType="com.adc.da.report.vo.ReportDetailVo"> <select id="reportDetail" resultMap="BaseResultMap">
SELECT SELECT
rm.id AS id, rm.id AS id,
rm.name AS `name`, rm.name AS `name`,
@@ -284,18 +331,19 @@
rm.maincontent AS maincontent, rm.maincontent AS maincontent,
rm.department AS department, rm.department AS department,
rm.`year` AS `year`, rm.`year` AS `year`,
rm.fileId AS fileId,
f.file_name as fileName,
rm.confidentialLevel AS confidentialLevel, rm.confidentialLevel AS confidentialLevel,
rm.privacyLevel AS privacyLevel, rm.privacyLevel AS privacyLevel,
rm.secrecy_last AS secrecyLast rm.secrecy_last AS secrecyLast,
f.FILE_ID as fileId, f.file_name as fileName ,rf.id as rfId
FROM `tt_report_manage` AS rm FROM `tt_report_manage` AS rm
LEFT JOIN ts_user AS u ON u.USID = rm.createUserId LEFT JOIN ts_user AS u ON u.USID = rm.createUserId
LEFT JOIN ts_org as org on org.id = rm.department LEFT JOIN ts_org as org on org.id = rm.department
LEFT JOIN ts_file as f on rm.fileId=f.file_id LEFT JOIN ts_report_file rf on rf.report_id = rm.id and rf.state = 2
LEFT JOIN ts_file f on f.FILE_ID = rf.file_id
WHERE rm.id = #{reportId} WHERE rm.id = #{reportId}
AND rm.del_flag = 0 AND rm.del_flag = 0
</select> </select>
<select id="selectDDL" resultType="com.adc.da.report.eo.ReportEntity"> <select id="selectDDL" resultType="com.adc.da.report.eo.ReportEntity">
SELECT * FROM tt_report_manage WHERE secrecy_last &lt;= NOW() SELECT * FROM tt_report_manage WHERE secrecy_last &lt;= NOW()
</select> </select>
@@ -15,7 +15,6 @@
<result column="department" property="department" /> <result column="department" property="department" />
<result column="departmentName" property="departmentName" /> <result column="departmentName" property="departmentName" />
<result column="year" property="year" /> <result column="year" property="year" />
<result column="fileId" property="fileId" />
<result column="confidentialLevel" property="confidentialLevel" /> <result column="confidentialLevel" property="confidentialLevel" />
<result column="privacyLevel" property="privacyLevel" /> <result column="privacyLevel" property="privacyLevel" />
<result column="createUserId" property="createUserId" /> <result column="createUserId" property="createUserId" />
@@ -23,7 +22,11 @@
<result column="updateDate" property="updateDate" /> <result column="updateDate" property="updateDate" />
<result column="del_flag" property="delFlag" /> <result column="del_flag" property="delFlag" />
<result column="secrecy_last" property="secrecyLast" /> <result column="secrecy_last" property="secrecyLast" />
<result column="file_name" property="fileName" /> <collection property="fileList" ofType="com.adc.da.report.eo.ReportFile">
<result column="fileId" property="fileId" />
<result column="fileName" property="fileName" />
<result column="rfId" property="id" />
</collection>
</resultMap> </resultMap>
<!--表名信息--> <!--表名信息-->
@@ -34,9 +37,9 @@
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="BaseColumnList"> <sql id="BaseColumnList">
id, id,
task_id, prc_id, data_id,report_id ,name, keycontent, maincontent, department, year, fileId, confidentialLevel, task_id, prc_id, data_id,report_id ,name, keycontent, maincontent, department, year, confidentialLevel,
privacyLevel, createUserId, createDate, updateDate, del_flag privacyLevel, createUserId, createDate, updateDate, del_flag
,secrecy_last,file_name ,secrecy_last
</sql> </sql>
<!-- 查询条件 --> <!-- 查询条件 -->
@@ -71,9 +74,6 @@
<if test="pageVO.year !=null and pageVO.year !=''"> <if test="pageVO.year !=null and pageVO.year !=''">
AND year LIKE CONCAT(CONCAT('%',#{pageVO.year}),'%') AND year LIKE CONCAT(CONCAT('%',#{pageVO.year}),'%')
</if> </if>
<if test="pageVO.fileId !=null and pageVO.fileId !=''">
AND fileId LIKE CONCAT(CONCAT('%',#{pageVO.fileId}),'%')
</if>
<if test="pageVO.confidentialLevel !=null and pageVO.confidentialLevel !=''"> <if test="pageVO.confidentialLevel !=null and pageVO.confidentialLevel !=''">
AND confidentialLevel LIKE CONCAT(CONCAT('%',#{pageVO.confidentialLevel}),'%') AND confidentialLevel LIKE CONCAT(CONCAT('%',#{pageVO.confidentialLevel}),'%')
</if> </if>
@@ -133,12 +133,16 @@
<select id="selectByDataId" resultMap="BaseResultMap"> <select id="selectByDataId" resultMap="BaseResultMap">
SELECT SELECT
a.id, a.id,
task_id, prc_id, data_id,report_id, name, keycontent, maincontent, department, task_id, prc_id, data_id,a.report_id, name, keycontent, maincontent, department,
org.LONG_NAME as departmentName, org.LONG_NAME as departmentName,
year, fileId, confidentialLevel, privacyLevel, createUserId, createDate, updateDate, del_flag year,f.FILE_ID as fileId, f.file_name as fileName ,rf.id as rfId, confidentialLevel, privacyLevel, createUserId,
,secrecy_last,file_name createDate,
updateDate, a.del_flag
,secrecy_last
FROM <include refid="TableName"/> a FROM <include refid="TableName"/> a
LEFT JOIN ts_org org on a.department = org.id LEFT JOIN ts_org org on a.department = org.id
LEFT JOIN ts_report_file rf on rf.report_id = a.data_id and rf.state = 1
LEFT JOIN ts_file f on f.FILE_ID = rf.file_id
<where> <where>
data_id = #{dataId} data_id = #{dataId}
</where> </where>
@@ -146,12 +150,16 @@
<select id="selectByPrcId" resultMap="BaseResultMap"> <select id="selectByPrcId" resultMap="BaseResultMap">
SELECT SELECT
a.id, a.id,
task_id, prc_id, data_id,report_id, name, keycontent, maincontent, department, task_id, prc_id, data_id,a.report_id, name, keycontent, maincontent, department,
org.LONG_NAME as departmentName, org.LONG_NAME as departmentName,
year, fileId, confidentialLevel, privacyLevel, createUserId, createDate, updateDate, del_flag year,f.FILE_ID as fileId, f.file_name as fileName ,rf.id as rfId ,confidentialLevel, privacyLevel, createUserId,
,secrecy_last,file_name createDate,
updateDate, a.del_flag
,secrecy_last
FROM <include refid="TableName"/> a FROM <include refid="TableName"/> a
LEFT JOIN ts_org org on a.department = org.id LEFT JOIN ts_org org on a.department = org.id
LEFT JOIN ts_report_file rf on rf.report_id = a.data_id and rf.state = 1
LEFT JOIN ts_file f on f.FILE_ID = rf.file_id
<where> <where>
prc_id = #{prcId} prc_id = #{prcId}
</where> </where>
@@ -1,12 +1,15 @@
package com.adc.da.wkflow.business_activiti.service; package com.adc.da.wkflow.business_activiti.service;
import com.adc.da.report.dao.mysql.PowerApplyActDao; import com.adc.da.report.dao.mysql.PowerApplyActDao;
import com.adc.da.report.dao.mysql.ReportFileDao;
import com.adc.da.report.dao.mysql.ReportLabelDao; import com.adc.da.report.dao.mysql.ReportLabelDao;
import com.adc.da.report.dao.mysql.TtReportManageActDao; import com.adc.da.report.dao.mysql.TtReportManageActDao;
import com.adc.da.report.eo.PowerApplyAct; import com.adc.da.report.eo.PowerApplyAct;
import com.adc.da.report.eo.ReportFile;
import com.adc.da.report.eo.ReportLabelEntity; import com.adc.da.report.eo.ReportLabelEntity;
import com.adc.da.report.eo.TtReportManageAct; import com.adc.da.report.eo.TtReportManageAct;
import com.adc.da.report.service.IPowerApplyActService; import com.adc.da.report.service.IPowerApplyActService;
import com.adc.da.report.service.IReportFileService;
import com.adc.da.report.service.IReportLabelService; import com.adc.da.report.service.IReportLabelService;
import com.adc.da.report.service.ITtReportManageActService; import com.adc.da.report.service.ITtReportManageActService;
import com.adc.da.util.exception.AdcDaBaseException; import com.adc.da.util.exception.AdcDaBaseException;
@@ -19,7 +22,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service @Service
public class ActivitDefineService { public class ActivitDefineService {
@@ -42,7 +48,11 @@ public class ActivitDefineService {
private ReportLabelDao reportLabelDao; private ReportLabelDao reportLabelDao;
@Autowired @Autowired
private IReportLabelService iReportLabelService; private IReportLabelService iReportLabelService;
@Autowired
private IReportFileService iReportFileService;
@Autowired
private ReportFileDao reportFileDao;
//保存data数据 //保存data数据
public String saveOrUpdateDate(String prcType, String dataJson,String taskId,String prcId,String reportId) { public String saveOrUpdateDate(String prcType, String dataJson,String taskId,String prcId,String reportId) {
if (StringUtils.isBlank(reportId)){ if (StringUtils.isBlank(reportId)){
@@ -115,6 +125,17 @@ public class ActivitDefineService {
} }
iReportLabelService.saveBatch(labelList); iReportLabelService.saveBatch(labelList);
} }
// 文件
reportFileDao.delByReportId(new ReportFile(reportId,1));
List<ReportFile> reportFiles = new ArrayList<>();
for (ReportFile reportFile : ttReportManageAct.getFileList()) {
reportFile.setId(UUID.randomUUID().toString().replace("-",""));
reportFile.setReportId(ttReportManageAct.getDataId());
// reportFile.setFileId(s);
reportFile.setState(1);
reportFiles.add(reportFile);
}
iReportFileService.saveBatch(reportFiles);
}else if ("5".equals(prcType)){ }else if ("5".equals(prcType)){
// 编辑 // 编辑
TtReportManageAct ttReportManageAct = JSONObject.parseObject(dataJson, TtReportManageAct.class); TtReportManageAct ttReportManageAct = JSONObject.parseObject(dataJson, TtReportManageAct.class);
@@ -138,6 +159,17 @@ public class ActivitDefineService {
} }
iReportLabelService.saveBatch(labelList); iReportLabelService.saveBatch(labelList);
} }
// 文件
reportFileDao.delByReportId(new ReportFile(reportId,1));
List<ReportFile> reportFiles = new ArrayList<>();
for (ReportFile reportFile : ttReportManageAct.getFileList()) {
reportFile.setId(UUID.randomUUID().toString().replace("-",""));
reportFile.setReportId(ttReportManageAct.getDataId());
// reportFile.setFileId(s);
reportFile.setState(1);
reportFiles.add(reportFile);
}
iReportFileService.saveBatch(reportFiles);
}else { }else {
throw new AdcDaBaseException("没有流程类型"+prcType); throw new AdcDaBaseException("没有流程类型"+prcType);
} }
@@ -2,11 +2,9 @@ package com.adc.da.wkflow.business_activiti.task;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.adc.da.login.util.UserUtils; import com.adc.da.login.util.UserUtils;
import com.adc.da.report.dao.mysql.PowerApplyActDao; import com.adc.da.report.dao.mysql.*;
import com.adc.da.report.dao.mysql.ReportDao;
import com.adc.da.report.dao.mysql.TreeLabelDao;
import com.adc.da.report.dao.mysql.TtReportManageActDao;
import com.adc.da.report.eo.ReportEntity; import com.adc.da.report.eo.ReportEntity;
import com.adc.da.report.eo.ReportFile;
import com.adc.da.report.eo.TtReportManageAct; import com.adc.da.report.eo.TtReportManageAct;
import com.adc.da.report.vo.PowerApplyActPageVO; import com.adc.da.report.vo.PowerApplyActPageVO;
import com.adc.da.sys.service.iservice.IUserEoService; import com.adc.da.sys.service.iservice.IUserEoService;
@@ -87,6 +85,9 @@ public class TodoTaskController {
@Autowired @Autowired
private TtReportManageActDao ttReportManageActDao; private TtReportManageActDao ttReportManageActDao;
@Autowired
private ReportFileDao reportFileDao;
@Autowired @Autowired
private ReportDao reportDao; private ReportDao reportDao;
@@ -619,6 +620,12 @@ public class TodoTaskController {
}else { }else {
ttReportManageAct = ttReportManageActDao.selectByPrcId(pId); ttReportManageAct = ttReportManageActDao.selectByPrcId(pId);
} }
// 为空说明流程已经结束
if (ttReportManageAct.getFileList().size() == 0){
List<ReportFile> reportFiles =
reportFileDao.selectByReport(new ReportFile(ttReportManageAct.getDataId(),2));
ttReportManageAct.setFileList(reportFiles);
}
List<String> labelList = treeLableDao.selectIdByReport(ttReportManageAct.getDataId()); List<String> labelList = treeLableDao.selectIdByReport(ttReportManageAct.getDataId());
ttReportManageAct.setLabelList(labelList); ttReportManageAct.setLabelList(labelList);
String string = JSONArray.toJSONString(ttReportManageAct); String string = JSONArray.toJSONString(ttReportManageAct);
@@ -633,6 +640,12 @@ public class TodoTaskController {
}else { }else {
ttReportManageAct = ttReportManageActDao.selectByPrcId(pId); ttReportManageAct = ttReportManageActDao.selectByPrcId(pId);
} }
// 为空说明流程已经结束
if (ttReportManageAct.getFileList().size() == 0){
List<ReportFile> reportFiles =
reportFileDao.selectByReport(new ReportFile(ttReportManageAct.getDataId(),2));
ttReportManageAct.setFileList(reportFiles);
}
List<String> labelList = treeLableDao.selectIdByReport(ttReportManageAct.getDataId()); List<String> labelList = treeLableDao.selectIdByReport(ttReportManageAct.getDataId());
ttReportManageAct.setLabelList(labelList); ttReportManageAct.setLabelList(labelList);
String string = JSONArray.toJSONString(ttReportManageAct); String string = JSONArray.toJSONString(ttReportManageAct);