1、文档、工具独立调整

This commit is contained in:
pan 2024-09-05 21:26:23 +08:00
parent 6f70344177
commit 3d679da3c3
16 changed files with 230 additions and 42 deletions

View File

@ -85,6 +85,18 @@
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-local</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-transformer-msoffice-word</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
<build>

View File

@ -7,9 +7,14 @@ import com.rzdata.common.utils.StringUtils;
import com.rzdata.common.utils.file.FileUploadUtils;
import com.rzdata.common.utils.file.FileUtils;
import com.rzdata.framework.config.ServerConfig;
import com.rzdata.web.domain.Attachment;
import com.rzdata.web.domain.FileOperationRequest;
import com.rzdata.web.service.IAttachmentService;
import com.rzdata.web.service.impl.AttachmentServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@ -37,9 +42,13 @@ public class CommonController
@Autowired
private ServerConfig serverConfig;
@Autowired
private IAttachmentService attachmentService;
private static final String FILE_DELIMETER = ",";
/**
* 通用下载请求
*
@ -166,6 +175,21 @@ public class CommonController
}
/**
* 预览下载
* txtpdfword(docdocx格式)
*/
@PostMapping("/preview/download")
public ResponseEntity<byte[]> resourceDownload(@RequestBody Attachment attachment)
{
byte[] bytes = attachmentService.loadFileAsBytes(attachment);
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + attachment.getFileOldName() + "\"")
.body(bytes);
}
@PostMapping("/initUpload")
public ResponseEntity<Map<String, String>> initUpload(@RequestParam("fileName") String fileName) {
// 上传文件路径

View File

@ -45,7 +45,7 @@ public class DocumentController extends BaseController
* 导出文档资源信息列表
*/
@Log(title = "【文档资源信息】", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('document:export')")
@PreAuthorize("@ss.hasPermi('document:list')")
@PostMapping("/export")
public void export(HttpServletResponse response, Document document)
{
@ -122,8 +122,8 @@ public class DocumentController extends BaseController
}
@GetMapping("/all/list")
public AjaxResult allList(Document Document)
@PostMapping("/export/word/list")
public AjaxResult exportWordList(Document Document)
{
List<Document> list = documentService.selectAllList(Document);
return AjaxResult.success(list);

View File

@ -94,6 +94,7 @@ public class ToolController extends BaseController
* 导出工具信息列表
*/
@Log(title = "工具信息", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('tool:list')")
@PostMapping("/export")
public void export(HttpServletResponse response, Tool tTool)
{
@ -108,7 +109,8 @@ public class ToolController extends BaseController
* 导出工具信息列表
*/
@Log(title = "工具信息", businessType = BusinessType.EXPORT)
@GetMapping("/export/word/list")
@PreAuthorize("@ss.hasPermi('tool:list')")
@PostMapping("/export/word/list")
public AjaxResult exportWordList(Tool tool)
{
List<Tool> list = toolService.selectAllList(tool);
@ -194,8 +196,6 @@ public class ToolController extends BaseController
//办结
if(RecordStatusEnum.DONE.getCode().equals(tTool.getRecordStatus())){
//更新文档状态
toolService.updateDocPushStatus(tTool);
//给消息中心发送消息
toolService.sendTzMessage(tTool);
}

View File

@ -32,6 +32,10 @@ public class Attachment extends BaseEntity
@Excel(name = "业务类型")
private String bizType;
/** 文件路径 */
@Excel(name = "文件路径")
private String filePath;
/** 文件URL */
@Excel(name = "文件URL")
private String fileUrl;

View File

@ -37,9 +37,11 @@ public class Document extends BaseEntity {
private String docType;
/** 文档负责人 */
@Excel(name = "负责人")
private String docPrincipals;
/** 文档负责人名称 */
private String docPrincipalsName;
/** 归属单位 **/
@Excel(name = "归属单位")
private String docRespDeptName;
@ -109,4 +111,8 @@ public class Document extends BaseEntity {
private String docSourceName;
private String statusName;
private String createNowTime;
private List<Attachment> attachmentList;
/** 主键 **/
private List<String> docIdList;
}

View File

@ -0,0 +1,20 @@
package com.rzdata.web.domain;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class FileOperationRequest {
private String id;
private String name;
private Boolean isLocal;
/** preview:预览download:下载 **/
private String type;
/**
* 模板下载类型
* 1: 导入模板
* 2示例请求模板
*/
private String templateDownloadType;
}

View File

@ -111,4 +111,6 @@ public class Tool extends BaseEntity
private String toolTypeName;
/** 状态名称 **/
private String statusName;
/** 主键 **/
private List<String> toolIdList;
}

View File

@ -1,6 +1,7 @@
package com.rzdata.web.service;
import com.rzdata.web.domain.Attachment;
import com.rzdata.web.domain.FileOperationRequest;
import java.util.List;
@ -74,4 +75,6 @@ public interface IAttachmentService
* @return
*/
public int batchInsert(List<Attachment> batch);
byte[] loadFileAsBytes(Attachment attachment);
}

View File

@ -1,10 +1,21 @@
package com.rzdata.web.service.impl;
import java.io.*;
import java.util.List;
import cn.hutool.core.util.ObjectUtil;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
import com.rzdata.common.config.JaConfig;
import com.rzdata.common.constant.Constants;
import com.rzdata.common.exception.ServiceException;
import com.rzdata.common.utils.StringUtils;
import com.rzdata.web.domain.Attachment;
import com.rzdata.web.domain.FileOperationRequest;
import com.rzdata.web.mapper.AttachmentMapper;
import com.rzdata.web.service.IAttachmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -14,6 +25,7 @@ import org.springframework.stereotype.Service;
* @author panchichun
* @date 2024-08-28
*/
@Slf4j
@Service
public class AttachmentServiceImpl implements IAttachmentService
{
@ -94,7 +106,7 @@ public class AttachmentServiceImpl implements IAttachmentService
/**
* 批量删除附件
*
* @param ids 需要删除的附件主键
* @param businessIds 需要删除的附件主键
* @return 结果
*/
@Override
@ -119,4 +131,64 @@ public class AttachmentServiceImpl implements IAttachmentService
public int batchInsert(List<Attachment> batch) {
return attachmentMapper.batchInsert(batch);
}
@Override
public byte[] loadFileAsBytes(Attachment attachment) {
// 本地资源路径
String localPath = JaConfig.getProfile();
// 全路径
String uploadPath = localPath + StringUtils.substringAfter(attachment.getFilePath(), Constants.RESOURCE_PREFIX);
String fileName = attachment.getFileOldName();
File file = null;
if (fileName.endsWith(Constants.FILE_TYPE_DOC)) {
//获取doc名称转换为pdf名称
String fileNameDocx = fileName.substring(0, fileName.lastIndexOf(Constants.SYMBOL_POINT));
fileNameDocx += Constants.FILE_TYPE_PDF;
//获取转换的路径
String pathDocx = uploadPath.substring(0, uploadPath.lastIndexOf('/') + 1) + fileNameDocx;
file = new File(pathDocx);
if (!file.exists()) {
convertDocToPdf(uploadPath,pathDocx);
// 再次检查转换后的文件是否存在
if (!file.exists()) {
throw new ServiceException("转换后的文件不存在");
}
}
}else{
file = new File(uploadPath);
}
byte[] result = null;
try (FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);) {
byte[] b = new byte[1000];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
result = bos.toByteArray();
} catch (Exception ex) {
log.error("AttachmentServiceImpl-->loadFileAsBytes----ex###", ex);
}
return result;
}
/**
* word文件doc格式转换为pdf文件
* @param docPath
* @param pdfPath
*/
public static void convertDocToPdf(String docPath, String pdfPath){
File file = new File(docPath);
File outputFile = new File(pdfPath);
try (InputStream docxInputStream = new FileInputStream(file);
OutputStream outputStream = new FileOutputStream(outputFile)) {
IConverter converter = LocalConverter.builder().build();
converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
} catch (IOException e) {
log.error("AttachmentServiceImpl-->convertDocToPdf----e###", e);
throw new ServiceException("转换异常");
}
}
}

View File

@ -2,6 +2,7 @@ package com.rzdata.web.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
@ -24,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
@ -52,6 +54,9 @@ public class DocumentServiceImpl implements IDocumentService
@Autowired
private ISysDeptService sysDeptService;
@Autowired
private Snowflake snowflake;
/**
* 查询请填写功能名称
*
@ -166,22 +171,45 @@ public class DocumentServiceImpl implements IDocumentService
document.setIsDeleted(Constants.STR_ZERO);
document.setCreateTime(new Date());
int result = documentMapper.insertDocument(document);
if(ObjectUtil.isNotEmpty(document.getAttachment())){
Attachment attachment = document.getAttachment();
attachment.setId(IdUtil.simpleUUID());
attachment.setCreateBy(SecurityUtils.getLoginUser().getUsername());
attachment.setBusinessId(docId);
attachment.setBizType(Constants.DOC_TYPE_DOC);
attachment.setDel(Constants.STR_ZERO);
attachment.setCreateDate(new Date());
attachmentService.insertAttachment(attachment);
}
addFileList(document);
if(result > 0){
return docId;
}
return null;
}
@Transactional(rollbackFor = Exception.class)
public void delFile(Document document) {
List<String> toolIds = Collections.singletonList(document.getDocId());
attachmentService.deleteAttachmentByBusinessId(toolIds);
}
@Transactional(rollbackFor = Exception.class)
public void addFileList(Document document) {
List<Attachment> attachmentList = document.getAttachmentList();
if(CollUtil.isEmpty(attachmentList)){
return;
}
for (Attachment attachment : attachmentList) {
attachment.setId(String.valueOf(snowflake.nextId()));
attachment.setBusinessId(document.getDocId());
attachment.setBizType(Constants.DOC_TYPE_DOC);
attachment.setDel(Constants.STR_ZERO);
attachment.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
attachment.setCreateDate(new Date());
}
// 使用AtomicInteger来跟踪索引
AtomicInteger counter = new AtomicInteger(0);
// 使用Stream API进行分组
Map<Integer, List<Attachment>> grouped = attachmentList.stream()
.collect(Collectors.groupingBy(
e -> counter.getAndIncrement() / 500
));
// 对每个子列表进行批量插入
grouped.values().forEach(batch -> attachmentService.batchInsert(batch));
}
/**
* 修改请填写功能名称
*
@ -196,24 +224,8 @@ public class DocumentServiceImpl implements IDocumentService
document.setUpdateById(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
document.setUpdateTime(new Date());
int result = documentMapper.updateDocument(document);
Attachment attParam = document.getAttachment();
if(ObjectUtil.isNotEmpty(attParam) && StrUtil.isBlank(attParam.getId())){
Attachment att = new Attachment();
att.setBusinessId(document.getDocId());
att.setDel(Constants.STR_ONE);
attachmentService.updateAttachmentByBusinessId(att);
Attachment attachment = document.getAttachment();
attachment.setId(IdUtil.simpleUUID());
attachment.setCreateBy(SecurityUtils.getLoginUser().getUsername());
attachment.setBusinessId(document.getDocId());
attachment.setBizType(Constants.DOC_TYPE_DOC);
attachment.setDel(Constants.STR_ZERO);
attachment.setCreateDate(new Date());
attachmentService.insertAttachment(attachment);
}
delFile(document);
addFileList(document);
return result;
}

View File

@ -137,8 +137,8 @@ public class ToolServiceImpl implements IToolService
tool.setUpdateBy(SecurityUtils.getUserId().toString());
tool.setUpdateTime(DateUtils.getNowDate());
int result = toolMapper.updateTool(tool);
delFile(tool);
addFileList(tool);
/* delFile(tool);
addFileList(tool);*/
return result;
}

View File

@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="id" column="id" />
<result property="bizType" column="biz_type" />
<result property="fileUrl" column="file_url" />
<result property="filePath" column="file_path" />
<result property="fileOldName" column="file_old_name" />
<result property="fileNewName" column="file_new_name" />
<result property="suffixType" column="suffix_type" />
@ -25,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectAttachmentVo">
select id, biz_type, file_url, file_old_name, file_new_name, suffix_type,
select id, biz_type, file_path, file_url, file_old_name, file_new_name, suffix_type,
file_size, business_id, sorts, remark, del, create_by, create_date,
update_by, update_date, failure_time, file_old_name as file_name
from t_attachment
@ -35,6 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectAttachmentVo"/>
<where>
<if test="bizType != null and bizType != ''"> and biz_type = #{bizType}</if>
<if test="filePath != null and filePath != ''"> and file_path = #{filePath}</if>
<if test="fileUrl != null and fileUrl != ''"> and file_url = #{fileUrl}</if>
<if test="fileOldName != null and fileOldName != ''"> and file_old_name like concat('%', #{fileOldName}, '%')</if>
<if test="fileNewName != null and fileNewName != ''"> and file_new_name like concat('%', #{fileNewName}, '%')</if>
@ -65,6 +67,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="bizType != null">biz_type,</if>
<if test="filePath != null">file_path,</if>
<if test="fileUrl != null">file_url,</if>
<if test="fileOldName != null">file_old_name,</if>
<if test="fileNewName != null">file_new_name,</if>
@ -83,6 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="bizType != null">#{bizType},</if>
<if test="filePath != null">#{filePath},</if>
<if test="fileUrl != null">#{fileUrl},</if>
<if test="fileOldName != null">#{fileOldName},</if>
<if test="fileNewName != null">#{fileNewName},</if>
@ -105,6 +109,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
<if test="bizType != null">biz_type = #{bizType},</if>
<if test="fileUrl != null">file_url = #{fileUrl},</if>
<if test="filePath != null">file_path = #{filePath},</if>
<if test="fileOldName != null">file_old_name = #{fileOldName},</if>
<if test="fileNewName != null">file_new_name = #{fileNewName},</if>
<if test="suffixType != null">suffix_type = #{suffixType},</if>
@ -128,6 +133,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
<if test="bizType != null">biz_type = #{bizType},</if>
<if test="fileUrl != null">file_url = #{fileUrl},</if>
<if test="filePath != null">file_path = #{filePath},</if>
<if test="fileOldName != null">file_old_name = #{fileOldName},</if>
<if test="fileNewName != null">file_new_name = #{fileNewName},</if>
<if test="suffixType != null">suffix_type = #{suffixType},</if>
@ -164,10 +170,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO t_attachment (id, biz_type, file_url, file_old_name, file_new_name, suffix_type, file_size, business_id, sorts, remark, del, create_by, create_date)
INSERT INTO t_attachment (id, biz_type, file_path, file_url, file_old_name, file_new_name, suffix_type, file_size, business_id, sorts, remark, del, create_by, create_date)
VALUES
<foreach item="item" index="index" collection="attachmentList" open="(" separator="),(" close=")">
#{item.id}, #{item.bizType}, #{item.fileUrl}, #{item.fileOldName}, #{item.fileNewName}, #{item.suffixType}, #{item.fileSize}, #{item.businessId}, #{item.sorts}, #{item.remark}, #{item.del}, #{item.createBy}, #{item.createDate}
#{item.id}, #{item.bizType}, #{item.filePath}, #{item.fileUrl}, #{item.fileOldName}, #{item.fileNewName}, #{item.suffixType}, #{item.fileSize}, #{item.businessId}, #{item.sorts}, #{item.remark}, #{item.del}, #{item.createBy}, #{item.createDate}
</foreach>
</insert>
</mapper>

View File

@ -10,6 +10,7 @@
<result property="docName" column="doc_name" />
<result property="docType" column="doc_type" />
<result property="docPrincipals" column="doc_principals" />
<result property="docPrincipalsName" column="doc_principals_name" />
<result property="docRespDept" column="doc_resp_dept" />
<result property="docSource" column="doc_source" />
<result property="docStatus" column="doc_status" />
@ -30,7 +31,7 @@
<sql id="selectDocumentVo">
select doc_id, doc_code, doc_name, doc_type, doc_principals, doc_resp_dept,
doc_source, doc_status, doc_url, create_by, create_time,
doc_source, doc_status, doc_url, create_by, create_time,doc_principals_name,
update_by, update_time, remark, doc_category_id,is_deleted,tool_id from t_document
</sql>
@ -58,6 +59,13 @@
<if test="createById != null and createById != '' and permission != true">
AND (td.create_by_id = #{createById} or td.doc_status = 'yfb')
</if>
<if test="docIdList != null and docIdList.size() > 0">
and td.doc_id in
<foreach item="id" index="index" collection="docIdList" open="(" separator="," close=")">
#{id}
</foreach>
</if>
and td.is_deleted = '0'
</where>
order by td.create_time desc
@ -76,6 +84,7 @@
<if test="docName != null">doc_name,</if>
<if test="docType != null">doc_type,</if>
<if test="docPrincipals != null">doc_principals,</if>
<if test="docPrincipalsName != null">doc_principals_name,</if>
<if test="docRespDept != null">doc_resp_dept,</if>
<if test="docSource != null">doc_source,</if>
<if test="docStatus != null">doc_status,</if>
@ -97,6 +106,7 @@
<if test="docName != null">#{docName},</if>
<if test="docType != null">#{docType},</if>
<if test="docPrincipals != null">#{docPrincipals},</if>
<if test="docPrincipalsName != null">#{docPrincipalsName},</if>
<if test="docRespDept != null">#{docRespDept},</if>
<if test="docSource != null">#{docSource},</if>
<if test="docStatus != null">#{docStatus},</if>
@ -121,6 +131,7 @@
<if test="docName != null">doc_name = #{docName},</if>
<if test="docType != null">doc_type = #{docType},</if>
<if test="docPrincipals != null">doc_principals = #{docPrincipals},</if>
<if test="docPrincipalsName != null">doc_principals_name = #{docPrincipalsName},</if>
<if test="docRespDept != null">doc_resp_dept = #{docRespDept},</if>
<if test="docSource != null">doc_source = #{docSource},</if>
<if test="docStatus != null">doc_status = #{docStatus},</if>

View File

@ -178,6 +178,12 @@
<if test="recordStatus != null and recordStatus != ''">
AND u.record_status = #{recordStatus}
</if>
<if test="toolIdList != null and toolIdList.size() > 0">
and u.tool_id in
<foreach item="id" index="index" collection="toolIdList" open="(" separator="," close=")">
#{id}
</foreach>
</if>
${params.dataScope}
order by create_time desc
</select>

View File

@ -214,4 +214,14 @@ public class Constants
/** 申请查看素哟偶数据 **/
public static final String APPLY_VIEW_ALL_PERMISSION = "system:apply:all:view";
public static final String FILE_DOWNLOAD = "download";
public static final String FILE_PREVIEW = "preview";
public static final String FILE_TYPE_DOC = ".doc";
public static final String FILE_TYPE_PDF = ".pdf";
public static final String SYMBOL_POINT = ".";
/**
* URL路径符
*/
public final static String SEPARATOR ="/";
}