From a272e0601850cb035d6f41d432a9c93250ad6e1f Mon Sep 17 00:00:00 2001 From: pan <380711010@qq.com> Date: Wed, 28 Aug 2024 17:40:03 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=AE=A1=E7=90=86=202=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/common/CommonController.java | 84 +++++++- .../document/DocumentCategoryController.java | 116 +++++++++++ .../java/com/rzdata/web/domain/Document.java | 109 +---------- .../web/mapper/DocumentCategoryMapper.java | 62 ++++++ .../web/service/IDocumentCategoryService.java | 71 +++++++ .../impl/DocumentCategoryServiceImpl.java | 183 ++++++++++++++++++ .../mapper/DocumentCategoryMapper.xml | 100 ++++++++++ .../main/resources/mapper/DocumentMapper.xml | 13 +- .../rzdata/common/config/SnowflakeConfig.java | 26 +++ .../common/core/domain/DocumentCategory.java | 54 ++++++ .../rzdata/common/core/domain/TreeSelect.java | 36 ++-- .../common/utils/file/FileUploadUtils.java | 48 +++++ 12 files changed, 769 insertions(+), 133 deletions(-) create mode 100644 tool-tech-admin/src/main/java/com/rzdata/web/controller/document/DocumentCategoryController.java create mode 100644 tool-tech-admin/src/main/java/com/rzdata/web/mapper/DocumentCategoryMapper.java create mode 100644 tool-tech-admin/src/main/java/com/rzdata/web/service/IDocumentCategoryService.java create mode 100644 tool-tech-admin/src/main/java/com/rzdata/web/service/impl/DocumentCategoryServiceImpl.java create mode 100644 tool-tech-admin/src/main/resources/mapper/DocumentCategoryMapper.xml create mode 100644 tool-tech-common/src/main/java/com/rzdata/common/config/SnowflakeConfig.java create mode 100644 tool-tech-common/src/main/java/com/rzdata/common/core/domain/DocumentCategory.java diff --git a/tool-tech-admin/src/main/java/com/rzdata/web/controller/common/CommonController.java b/tool-tech-admin/src/main/java/com/rzdata/web/controller/common/CommonController.java index 8d840cb..9bdf2ac 100644 --- a/tool-tech-admin/src/main/java/com/rzdata/web/controller/common/CommonController.java +++ b/tool-tech-admin/src/main/java/com/rzdata/web/controller/common/CommonController.java @@ -1,17 +1,25 @@ package com.rzdata.web.controller.common; -import java.util.ArrayList; -import java.util.List; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import com.rzdata.common.config.JaConfig; import com.rzdata.common.constant.Constants; @@ -160,4 +168,68 @@ public class CommonController log.error("下载文件失败", e); } } + + + @PostMapping("/initUpload") + public ResponseEntity> initUpload(@RequestParam("fileName") String fileName) { + // 上传文件路径 + String filePath = JaConfig.getUploadPath(); + String uploadId = UUID.randomUUID().toString(); + // 创建临时目录用于存放分片文件 + new File(filePath + "/" + uploadId).mkdirs(); + Map response = new HashMap<>(); + response.put("uploadId", uploadId); + return ResponseEntity.ok(response); + } + + @PostMapping("/uploadChunk") + public ResponseEntity> uploadChunk( + @RequestParam("chunkFile") MultipartFile chunkFile, + @RequestParam("uploadId") String uploadId, + @RequestParam("chunkId") int chunkId) { + String filePath = JaConfig.getUploadPath(); + String chunkFilePath = filePath + "/" + uploadId + "/" + chunkId; + try { + chunkFile.transferTo(new File(chunkFilePath)); + Map response = new HashMap<>(); + response.put("status", "200"); + return ResponseEntity.ok(response); + } catch (IOException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + } + + @PostMapping("/mergeFile") + public ResponseEntity> mergeFile(@RequestParam("uploadId") String uploadId, + @RequestParam("fileName") String fileName) { + String filePath = JaConfig.getUploadPath(); + //String finalFilePath = FileUploadUtils.generateMergedFilePath(filePath, fileName); + String fileNamePath = FileUploadUtils.getFilePath(filePath, fileName); + String finalFilePath = filePath + fileNamePath.replace("profile/upload/", "") ; + File dir = new File(filePath + "/" + uploadId); + File[] chunkFiles = dir.listFiles(); + + // 按文件名(即chunkId)排序 + Arrays.sort(chunkFiles, Comparator.comparingInt(f -> Integer.parseInt(f.getName()))); + + try (FileOutputStream fos = new FileOutputStream(finalFilePath)) { + for (File chunk : chunkFiles) { + Files.copy(chunk.toPath(), fos); + } + + Map response = new HashMap<>(); + String url = serverConfig.getUrl() + fileNamePath; + response.put("url", url); + response.put("fileUrl", finalFilePath); + response.put("fileNamePath", fileNamePath); + return ResponseEntity.ok(response); + } catch (IOException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } finally { + // 清理临时文件 + Arrays.stream(chunkFiles).forEach(File::delete); + dir.delete(); + } + } + } diff --git a/tool-tech-admin/src/main/java/com/rzdata/web/controller/document/DocumentCategoryController.java b/tool-tech-admin/src/main/java/com/rzdata/web/controller/document/DocumentCategoryController.java new file mode 100644 index 0000000..da8098d --- /dev/null +++ b/tool-tech-admin/src/main/java/com/rzdata/web/controller/document/DocumentCategoryController.java @@ -0,0 +1,116 @@ +package com.rzdata.web.controller.document; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import com.rzdata.common.core.domain.DocumentCategory; +import com.rzdata.web.service.IDocumentCategoryService; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.rzdata.common.annotation.Log; +import com.rzdata.common.core.controller.BaseController; +import com.rzdata.common.core.domain.AjaxResult; +import com.rzdata.common.enums.BusinessType; +import com.rzdata.common.utils.poi.ExcelUtil; +import com.rzdata.common.core.page.TableDataInfo; + +/** + * 文档资源分类管理Controller + * + * @author spongepan + * @date 2024-08-27 + */ +@RestController +@RequestMapping("/system/category") +public class DocumentCategoryController extends BaseController +{ + @Autowired + private IDocumentCategoryService documentCategoryService; + + /** + * 查询文档资源分类管理列表 + */ + @PreAuthorize("@ss.hasPermi('system:category:list')") + @GetMapping("/list") + public TableDataInfo list(DocumentCategory documentCategory) + { + startPage(); + List list = documentCategoryService.selectDocumentCategoryList(documentCategory); + return getDataTable(list); + } + + /** + * 导出文档资源分类管理列表 + */ + @PreAuthorize("@ss.hasPermi('system:category:export')") + @Log(title = "文档资源分类管理", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, DocumentCategory documentCategory) + { + List list = documentCategoryService.selectDocumentCategoryList(documentCategory); + ExcelUtil util = new ExcelUtil(DocumentCategory.class); + util.exportExcel(response, list, "文档资源分类管理数据"); + } + + /** + * 获取文档资源分类管理详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:category:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") String id) + { + return success(documentCategoryService.selectDocumentCategoryById(id)); + } + + /** + * 新增文档资源分类管理 + */ + @PreAuthorize("@ss.hasPermi('system:category:add')") + @Log(title = "文档资源分类管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody DocumentCategory documentCategory) + { + return toAjax(documentCategoryService.insertDocumentCategory(documentCategory)); + } + + /** + * 修改文档资源分类管理 + */ + @PreAuthorize("@ss.hasPermi('system:category:edit')") + @Log(title = "文档资源分类管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody DocumentCategory documentCategory) + { + return toAjax(documentCategoryService.updateDocumentCategory(documentCategory)); + } + + /** + * 删除文档资源分类管理 + */ + @PreAuthorize("@ss.hasPermi('system:category:remove')") + @Log(title = "文档资源分类管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) + { + return toAjax(documentCategoryService.deleteDocumentCategoryByIds(ids)); + } + + + /** + * 获取文档分类树列表 + */ + @PreAuthorize("@ss.hasPermi('system:category:tree:list')") + @GetMapping("/documentTree") + public AjaxResult deptTree(DocumentCategory documentCategory) + { + return success(documentCategoryService.selectDocumentTreeList(documentCategory)); + } +} diff --git a/tool-tech-admin/src/main/java/com/rzdata/web/domain/Document.java b/tool-tech-admin/src/main/java/com/rzdata/web/domain/Document.java index 2d21e0c..ee1684a 100644 --- a/tool-tech-admin/src/main/java/com/rzdata/web/domain/Document.java +++ b/tool-tech-admin/src/main/java/com/rzdata/web/domain/Document.java @@ -2,6 +2,7 @@ package com.rzdata.web.domain; import com.rzdata.common.annotation.Excel; import com.rzdata.common.core.domain.BaseEntity; +import lombok.Data; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -11,6 +12,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; * @author ja * @date 2024-07-08 */ +@Data public class Document extends BaseEntity { private static final long serialVersionUID = 1L; @@ -49,106 +51,11 @@ public class Document extends BaseEntity { @Excel(name = "文档地址") private String docUrl; - public void setDocId(String docId) - { - this.docId = docId; - } + /** 备注 */ + @Excel(name = "备注") + private String remark; - public String getDocId() - { - return docId; - } - public void setDocCode(String docCode) - { - this.docCode = docCode; - } - - public String getDocCode() - { - return docCode; - } - public void setDocName(String docName) - { - this.docName = docName; - } - - public String getDocName() - { - return docName; - } - public void setDocType(String docType) - { - this.docType = docType; - } - - public String getDocType() - { - return docType; - } - public void setDocPrincipals(String docPrincipals) - { - this.docPrincipals = docPrincipals; - } - - public String getDocPrincipals() - { - return docPrincipals; - } - public void setDocRespDept(String docRespDept) - { - this.docRespDept = docRespDept; - } - - public String getDocRespDept() - { - return docRespDept; - } - public void setDocSource(String docSource) - { - this.docSource = docSource; - } - - public String getDocSource() - { - return docSource; - } - - public void setDocStatus(String docStatus) - { - this.docStatus = docStatus; - } - - public String getDocStatus() - { - return docStatus; - } - - public void setDocUrl(String docUrl) - { - this.docUrl = docUrl; - } - - public String getDocUrl() - { - return docUrl; - } - - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - .append("docId", getDocId()) - .append("docCode", getDocCode()) - .append("docName", getDocName()) - .append("docType", getDocType()) - .append("docPrincipals", getDocPrincipals()) - .append("docRespDept", getDocRespDept()) - .append("docSource", getDocSource()) - .append("docStatus", getDocStatus()) - .append("docUrl", getDocUrl()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .toString(); - } + /** 文档分类id */ + @Excel(name = "文档分类id") + private String docCategoryId; } diff --git a/tool-tech-admin/src/main/java/com/rzdata/web/mapper/DocumentCategoryMapper.java b/tool-tech-admin/src/main/java/com/rzdata/web/mapper/DocumentCategoryMapper.java new file mode 100644 index 0000000..106574c --- /dev/null +++ b/tool-tech-admin/src/main/java/com/rzdata/web/mapper/DocumentCategoryMapper.java @@ -0,0 +1,62 @@ +package com.rzdata.web.mapper; + +import com.rzdata.common.core.domain.DocumentCategory; + +import java.util.List; + +/** + * 文档资源分类管理Mapper接口 + * + * @author spongepan + * @date 2024-08-27 + */ +public interface DocumentCategoryMapper +{ + /** + * 查询文档资源分类管理 + * + * @param id 文档资源分类管理主键 + * @return 文档资源分类管理 + */ + public DocumentCategory selectDocumentCategoryById(String id); + + /** + * 查询文档资源分类管理列表 + * + * @param documentCategory 文档资源分类管理 + * @return 文档资源分类管理集合 + */ + public List selectDocumentCategoryList(DocumentCategory documentCategory); + + /** + * 新增文档资源分类管理 + * + * @param documentCategory 文档资源分类管理 + * @return 结果 + */ + public int insertDocumentCategory(DocumentCategory documentCategory); + + /** + * 修改文档资源分类管理 + * + * @param documentCategory 文档资源分类管理 + * @return 结果 + */ + public int updateDocumentCategory(DocumentCategory documentCategory); + + /** + * 删除文档资源分类管理 + * + * @param id 文档资源分类管理主键 + * @return 结果 + */ + public int deleteDocumentCategoryById(String id); + + /** + * 批量删除文档资源分类管理 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteDocumentCategoryByIds(String[] ids); +} diff --git a/tool-tech-admin/src/main/java/com/rzdata/web/service/IDocumentCategoryService.java b/tool-tech-admin/src/main/java/com/rzdata/web/service/IDocumentCategoryService.java new file mode 100644 index 0000000..1f6931b --- /dev/null +++ b/tool-tech-admin/src/main/java/com/rzdata/web/service/IDocumentCategoryService.java @@ -0,0 +1,71 @@ +package com.rzdata.web.service; + +import com.rzdata.common.core.domain.TreeSelect; +import com.rzdata.common.core.domain.DocumentCategory; + +import java.util.List; + +/** + * 文档资源分类管理Service接口 + * + * @author spongepan + * @date 2024-08-27 + */ +public interface IDocumentCategoryService +{ + /** + * 查询文档资源分类管理 + * + * @param id 文档资源分类管理主键 + * @return 文档资源分类管理 + */ + public DocumentCategory selectDocumentCategoryById(String id); + + /** + * 查询文档资源分类管理列表 + * + * @param documentCategory 文档资源分类管理 + * @return 文档资源分类管理集合 + */ + public List selectDocumentCategoryList(DocumentCategory documentCategory); + + /** + * 新增文档资源分类管理 + * + * @param documentCategory 文档资源分类管理 + * @return 结果 + */ + public int insertDocumentCategory(DocumentCategory documentCategory); + + /** + * 修改文档资源分类管理 + * + * @param documentCategory 文档资源分类管理 + * @return 结果 + */ + public int updateDocumentCategory(DocumentCategory documentCategory); + + /** + * 批量删除文档资源分类管理 + * + * @param ids 需要删除的文档资源分类管理主键集合 + * @return 结果 + */ + public int deleteDocumentCategoryByIds(String[] ids); + + /** + * 删除文档资源分类管理信息 + * + * @param id 文档资源分类管理主键 + * @return 结果 + */ + public int deleteDocumentCategoryById(String id); + + + /** + * 获取文档资源树 + * @param documentCategory + * @return + */ + List selectDocumentTreeList(DocumentCategory documentCategory); +} diff --git a/tool-tech-admin/src/main/java/com/rzdata/web/service/impl/DocumentCategoryServiceImpl.java b/tool-tech-admin/src/main/java/com/rzdata/web/service/impl/DocumentCategoryServiceImpl.java new file mode 100644 index 0000000..85ee4da --- /dev/null +++ b/tool-tech-admin/src/main/java/com/rzdata/web/service/impl/DocumentCategoryServiceImpl.java @@ -0,0 +1,183 @@ +package com.rzdata.web.service.impl; + +import cn.hutool.core.lang.Snowflake; +import com.rzdata.common.core.domain.TreeSelect; +import com.rzdata.common.utils.DateUtils; +import com.rzdata.common.utils.SecurityUtils; +import com.rzdata.common.utils.StringUtils; +import com.rzdata.common.core.domain.DocumentCategory; +import com.rzdata.web.mapper.DocumentCategoryMapper; +import com.rzdata.web.service.IDocumentCategoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 文档资源分类管理Service业务层处理 + * + * @author spongepan + * @date 2024-08-27 + */ +@Service +public class DocumentCategoryServiceImpl implements IDocumentCategoryService +{ + @Autowired + private DocumentCategoryMapper documentCategoryMapper; + + @Autowired + private Snowflake snowflake; + + /** + * 查询文档资源分类管理 + * + * @param id 文档资源分类管理主键 + * @return 文档资源分类管理 + */ + @Override + public DocumentCategory selectDocumentCategoryById(String id) + { + return documentCategoryMapper.selectDocumentCategoryById(id); + } + + /** + * 查询文档资源分类管理列表 + * + * @param documentCategory 文档资源分类管理 + * @return 文档资源分类管理 + */ + @Override + public List selectDocumentCategoryList(DocumentCategory documentCategory) + { + return documentCategoryMapper.selectDocumentCategoryList(documentCategory); + } + + /** + * 新增文档资源分类管理 + * + * @param documentCategory 文档资源分类管理 + * @return 结果 + */ + @Override + public int insertDocumentCategory(DocumentCategory documentCategory) + { + documentCategory.setId(String.valueOf(snowflake.nextId())); + documentCategory.setCreateTime(DateUtils.getNowDate()); + documentCategory.setCreateBy(SecurityUtils.getLoginUser().getUsername()); + documentCategory.setCreateById(String.valueOf(SecurityUtils.getLoginUser().getUserId())); + return documentCategoryMapper.insertDocumentCategory(documentCategory); + } + + /** + * 修改文档资源分类管理 + * + * @param documentCategory 文档资源分类管理 + * @return 结果 + */ + @Override + public int updateDocumentCategory(DocumentCategory documentCategory) + { + documentCategory.setUpdateTime(DateUtils.getNowDate()); + return documentCategoryMapper.updateDocumentCategory(documentCategory); + } + + /** + * 批量删除文档资源分类管理 + * + * @param ids 需要删除的文档资源分类管理主键 + * @return 结果 + */ + @Override + public int deleteDocumentCategoryByIds(String[] ids) + { + return documentCategoryMapper.deleteDocumentCategoryByIds(ids); + } + + /** + * 删除文档资源分类管理信息 + * + * @param id 文档资源分类管理主键 + * @return 结果 + */ + @Override + public int deleteDocumentCategoryById(String id) + { + return documentCategoryMapper.deleteDocumentCategoryById(id); + } + + @Override + public List selectDocumentTreeList(DocumentCategory documentCategory) { + List documentCategoryList = documentCategoryMapper.selectDocumentCategoryList(documentCategory); + return buildDeptTreeSelect(documentCategoryList); + } + + public List buildDeptTreeSelect(List documentCategory) + { + List docCategoryTree = buildDeptTree(documentCategory); + return docCategoryTree.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + public List buildDeptTree(List documentCategoryList) + { + List returnList = new ArrayList(); + List tempList = documentCategoryList.stream().map(DocumentCategory::getId).collect(Collectors.toList()); + for (DocumentCategory documentCategory : documentCategoryList) + { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(documentCategory.getParentId())) + { + recursionFn(documentCategoryList, documentCategory); + returnList.add(documentCategory); + } + } + if (returnList.isEmpty()) + { + returnList = documentCategoryList; + } + return returnList; + } + + /** + * 递归列表 + */ + private void recursionFn(List list, DocumentCategory t) + { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (DocumentCategory tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + private List getChildList(List list, DocumentCategory t) + { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) + { + DocumentCategory n = (DocumentCategory) it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().equals(t.getId())) + { + tlist.add(n); + } + } + return tlist; + } + + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, DocumentCategory t) + { + return getChildList(list, t).size() > 0; + } +} diff --git a/tool-tech-admin/src/main/resources/mapper/DocumentCategoryMapper.xml b/tool-tech-admin/src/main/resources/mapper/DocumentCategoryMapper.xml new file mode 100644 index 0000000..5685bec --- /dev/null +++ b/tool-tech-admin/src/main/resources/mapper/DocumentCategoryMapper.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + select id, category_name, category_description, parent_id, create_by, create_by_id, create_time, + update_by, update_by_id, update_time, types from t_document_category + + + + + + + + insert into t_document_category + + id, + category_name, + category_description, + parent_id, + create_by, + create_by_id, + create_time, + update_by, + update_by_id, + update_time, + types, + + + #{id}, + #{categoryName}, + #{categoryDescription}, + #{parentId}, + #{createBy}, + #{createById}, + #{createTime}, + #{updateBy}, + #{updateById}, + #{updateTime}, + #{types}, + + + + + update t_document_category + + category_name = #{categoryName}, + category_description = #{categoryDescription}, + parent_id = #{parentId}, + create_by = #{createBy}, + create_by_id = #{createById}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_by_id = #{updateById}, + update_time = #{updateTime}, + types = #{types}, + + where id = #{id} + + + + delete from t_document_category where id = #{id} + + + + delete from t_document_category where id in + + #{id} + + + \ No newline at end of file diff --git a/tool-tech-admin/src/main/resources/mapper/DocumentMapper.xml b/tool-tech-admin/src/main/resources/mapper/DocumentMapper.xml index d4673b3..d2079e3 100644 --- a/tool-tech-admin/src/main/resources/mapper/DocumentMapper.xml +++ b/tool-tech-admin/src/main/resources/mapper/DocumentMapper.xml @@ -18,10 +18,14 @@ + + - select doc_id, doc_code, doc_name, doc_type, doc_principals, doc_resp_dept, doc_source, doc_status, doc_url, create_by, create_time, update_by, update_time from t_document + select doc_id, doc_code, doc_name, doc_type, doc_principals, doc_resp_dept, + doc_source, doc_status, doc_url, create_by, create_time, + update_by, update_time, remark, doc_category_id from t_document @@ -58,6 +63,8 @@ create_time, update_by, update_time, + remark, + doc_category_id, #{docId}, @@ -73,6 +80,8 @@ #{createTime}, #{updateBy}, #{updateTime}, + #{remark}, + #{doc_category_id}, @@ -91,6 +100,8 @@ create_time = #{createTime}, update_by = #{updateBy}, update_time = #{updateTime}, + remark = #{remark}, + docCategoryId = #{doc_category_id}, where doc_id = #{docId} diff --git a/tool-tech-common/src/main/java/com/rzdata/common/config/SnowflakeConfig.java b/tool-tech-common/src/main/java/com/rzdata/common/config/SnowflakeConfig.java new file mode 100644 index 0000000..9d5239f --- /dev/null +++ b/tool-tech-common/src/main/java/com/rzdata/common/config/SnowflakeConfig.java @@ -0,0 +1,26 @@ +package com.rzdata.common.config; + +import cn.hutool.core.lang.Snowflake; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 雪花算法订单号生成 + * @author lanhai + */ +@Configuration +public class SnowflakeConfig { + + @Value("${application.datacenterId}") + private Long datacenterId; + + @Value("${application.workerId}") + private Long workerId; + + @Bean + public Snowflake snowflake() { + return new Snowflake(workerId, datacenterId); + } + +} diff --git a/tool-tech-common/src/main/java/com/rzdata/common/core/domain/DocumentCategory.java b/tool-tech-common/src/main/java/com/rzdata/common/core/domain/DocumentCategory.java new file mode 100644 index 0000000..ce7ff3a --- /dev/null +++ b/tool-tech-common/src/main/java/com/rzdata/common/core/domain/DocumentCategory.java @@ -0,0 +1,54 @@ +package com.rzdata.common.core.domain; + +import com.rzdata.common.annotation.Excel; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 文档资源分类管理对象 t_document_category + * + * @author spongepan + * @date 2024-08-27 + */ +@Data +public class DocumentCategory extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键ID */ + private String id; + + /** 分类名称 */ + @Excel(name = "分类名称") + private String categoryName; + + /** 分类描述 */ + @Excel(name = "分类描述") + private String categoryDescription; + + /** 父分类ID,如果是一级分类,则为空 */ + @Excel(name = "父分类ID,如果是一级分类,则为空") + private String parentId; + + /** 创建人id */ + @Excel(name = "创建人id") + private String createById; + + /** 更新人id */ + @Excel(name = "更新人id") + private String updateById; + + /** 类型(system:系统,user:用户创建) */ + @Excel(name = "类型") + private String types; + + /** 文档分类id */ + @Excel(name = "文档分类id") + private String docCategoryId; + + /** 子分类 */ + private List children = new ArrayList(); + +} diff --git a/tool-tech-common/src/main/java/com/rzdata/common/core/domain/TreeSelect.java b/tool-tech-common/src/main/java/com/rzdata/common/core/domain/TreeSelect.java index 952babf..1a7afbe 100644 --- a/tool-tech-common/src/main/java/com/rzdata/common/core/domain/TreeSelect.java +++ b/tool-tech-common/src/main/java/com/rzdata/common/core/domain/TreeSelect.java @@ -6,12 +6,14 @@ import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonInclude; import com.rzdata.common.core.domain.entity.SysDept; import com.rzdata.common.core.domain.entity.SysMenu; +import lombok.Data; /** * Treeselect树结构实体类 * * @author ruoyi */ +@Data public class TreeSelect implements Serializable { private static final long serialVersionUID = 1L; @@ -22,6 +24,9 @@ public class TreeSelect implements Serializable /** 节点名称 */ private String label; + /** 类型 */ + private String types; + /** 子节点 */ @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children; @@ -45,33 +50,14 @@ public class TreeSelect implements Serializable this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } - public Long getId() + + public TreeSelect(DocumentCategory docCategory) { - return id; + this.id = Long.valueOf(docCategory.getId()); + this.label = docCategory.getCategoryName(); + this.types = docCategory.getTypes(); + this.children = docCategory.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } - public void setId(Long id) - { - this.id = id; - } - public String getLabel() - { - return label; - } - - public void setLabel(String label) - { - this.label = label; - } - - public List getChildren() - { - return children; - } - - public void setChildren(List children) - { - this.children = children; - } } diff --git a/tool-tech-common/src/main/java/com/rzdata/common/utils/file/FileUploadUtils.java b/tool-tech-common/src/main/java/com/rzdata/common/utils/file/FileUploadUtils.java index d18b825..f2714b7 100644 --- a/tool-tech-common/src/main/java/com/rzdata/common/utils/file/FileUploadUtils.java +++ b/tool-tech-common/src/main/java/com/rzdata/common/utils/file/FileUploadUtils.java @@ -5,6 +5,8 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.Objects; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; import com.rzdata.common.listener.PutObjectProgressListener; import org.apache.commons.io.FilenameUtils; import org.springframework.util.Assert; @@ -280,4 +282,50 @@ public class FileUploadUtils } return extension; } + + /** + * 生成合并后的文件路径 + * + * @param baseDir 文件存储根目录 + * @param fileName 上传的文件名 + * @return 合并后文件的完整路径 + */ + public static String generateMergedFilePath(String baseDir, String fileName) { + // 获取当前日期路径 + String datePath = DateUtil.today().replace("-", "/"); + + // 获取文件的基本名称和扩展名 + String baseName = StrUtil.subBefore(fileName, ".", true); + String extension = StrUtil.subAfter(fileName, ".", true); + + // 生成唯一文件名,使用时间戳 + String uniqueFileName = baseName + "_" + System.currentTimeMillis() + "." + extension; + + // 合并文件路径: baseDir/yyyy/MM/dd/uploadId/uniqueFileName + String mergedFilePath = Paths.get(baseDir, datePath, uniqueFileName).toString(); + + return mergedFilePath; + } + + + /** + * 获取文件名称 + * + * @param baseDir 文件存储根目录 + * @param fileNames 上传的文件名 + * @return 合并后文件的完整路径 + */ + public static String getFilePath(String baseDir, String fileNames) { + String extension = StrUtil.subAfter(fileNames, ".", true); + + String fileName = StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), + FilenameUtils.getBaseName(fileNames), Seq.getId(Seq.uploadSeqType), extension);; + + try { + return getPathFileName(baseDir, fileName); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } }