|
@@ -1,20 +1,25 @@
|
|
package com.gqy.document.service.impl;
|
|
package com.gqy.document.service.impl;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.gqy.common.core.domain.AjaxResult;
|
|
import com.gqy.common.core.domain.AjaxResult;
|
|
|
|
+import com.gqy.common.core.domain.AjaxResultCQY;
|
|
import com.gqy.common.core.text.Convert;
|
|
import com.gqy.common.core.text.Convert;
|
|
import com.gqy.common.exception.ServiceException;
|
|
import com.gqy.common.exception.ServiceException;
|
|
import com.gqy.common.utils.*;
|
|
import com.gqy.common.utils.*;
|
|
|
|
+import com.gqy.document.domain.ProductDocument;
|
|
import com.gqy.document.domain.vo.PageResult;
|
|
import com.gqy.document.domain.vo.PageResult;
|
|
import com.gqy.document.domain.Document;
|
|
import com.gqy.document.domain.Document;
|
|
import com.gqy.document.domain.ProjectDocument;
|
|
import com.gqy.document.domain.ProjectDocument;
|
|
import com.gqy.document.mapper.DocumentMapper;
|
|
import com.gqy.document.mapper.DocumentMapper;
|
|
|
|
+import com.gqy.document.mapper.ProductDocumentMapper;
|
|
import com.gqy.document.mapper.ProjectDocumentMapper;
|
|
import com.gqy.document.mapper.ProjectDocumentMapper;
|
|
import com.gqy.document.service.IDocumentService;
|
|
import com.gqy.document.service.IDocumentService;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -41,10 +46,75 @@ public class DcDocumentServiceImpl implements IDocumentService
|
|
@Autowired
|
|
@Autowired
|
|
private ProjectDocumentMapper projectDocumentMapper;
|
|
private ProjectDocumentMapper projectDocumentMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductDocumentMapper productDocumentMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新文档
|
|
|
|
+ * @param document
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Transactional
|
|
|
|
+ public AjaxResultCQY updateDocument(Document document) {
|
|
|
|
+ try {
|
|
|
|
+ log.info("开始更新文档信息, 文档ID: {}", document.getId());
|
|
|
|
+ // 1. 检查文档是否存在
|
|
|
|
+ Document existDoc = documentMapper.info(document.getId());
|
|
|
|
+ if (existDoc == null) {
|
|
|
|
+ log.warn("文档不存在, 文档ID: {}", document.getId());
|
|
|
|
+ return AjaxResultCQY.error("更新文档信息失败:文档不存在");
|
|
|
|
+ }
|
|
|
|
+ // 2. 更新文档基本信息
|
|
|
|
+ log.info("更新文档基本信息: {}", document);
|
|
|
|
+ int rows = documentMapper.updateDocument(document);
|
|
|
|
+ if (rows <= 0) {
|
|
|
|
+ return AjaxResultCQY.error("更新文档基本信息失败");
|
|
|
|
+ }
|
|
|
|
+ // 3. 更新产品关联
|
|
|
|
+ log.info("开始更新文档产品关联, 文档ID: {}", document.getId());
|
|
|
|
+ productDocumentMapper.deleteProductDocumentByDocId(document.getId());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(document.getLinks())) {
|
|
|
|
+
|
|
|
|
+ List<ProductDocument> productDocs = document.getLinks().stream()
|
|
|
|
+ .map(productId -> {
|
|
|
|
+ ProductDocument pd = new ProductDocument();
|
|
|
|
+ pd.setDocument_id(document.getId());
|
|
|
|
+ pd.setProduct_id(Long.valueOf(productId));
|
|
|
|
+ pd.setStatus(5);
|
|
|
|
+ return pd;
|
|
|
|
+ })
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ productDocumentMapper.batchInsertProductDocument(productDocs);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ log.info("开始更新文档项目关联, 文档ID: {}", document.getId());
|
|
|
|
+ projectDocumentMapper.deleteProjectDocumentByDocId(document.getId());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(document.getProjects())) {
|
|
|
|
+ List<ProjectDocument> projectDocs = document.getProjects().stream().map(projectId -> {
|
|
|
|
+ ProjectDocument pd = new ProjectDocument();
|
|
|
|
+ pd.setDoc_id(document.getId());
|
|
|
|
+ pd.setProject_id(Long.valueOf(projectId));
|
|
|
|
+ pd.setStatus(5);
|
|
|
|
+ return pd;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ projectDocumentMapper.batchInsertProjectDocument(projectDocs);
|
|
|
|
+ }
|
|
|
|
+ log.info("文档更新成功, 文档ID: {}", document.getId());
|
|
|
|
+ return AjaxResultCQY.success(document.getId());
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.error("更新文档失败, 文档ID: {}, 错误信息: {}", document.getId(), e.getMessage(), e);
|
|
|
|
+ return AjaxResultCQY.error("更新文档失败:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 创建文档
|
|
|
|
+ * @param request
|
|
|
|
+ * @param file
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@Transactional
|
|
@Transactional
|
|
- public AjaxResult create(Map request, MultipartFile file) {
|
|
|
|
|
|
+ public AjaxResultCQY create(Map request, MultipartFile file) {
|
|
try {
|
|
try {
|
|
// 1. 获取表单参数
|
|
// 1. 获取表单参数
|
|
String title = (String) request.get("title");
|
|
String title = (String) request.get("title");
|
|
@@ -55,7 +125,7 @@ public class DcDocumentServiceImpl implements IDocumentService
|
|
|
|
|
|
// 2. 参数校验
|
|
// 2. 参数校验
|
|
if (StringUtils.isEmpty(title)) {
|
|
if (StringUtils.isEmpty(title)) {
|
|
- return AjaxResult.error("文档标题不能为空");
|
|
|
|
|
|
+ return AjaxResultCQY.error("文档标题不能为空");
|
|
}
|
|
}
|
|
|
|
|
|
Integer templateFlag = Convert.toInt(isTemplate, 0);
|
|
Integer templateFlag = Convert.toInt(isTemplate, 0);
|
|
@@ -70,7 +140,7 @@ public class DcDocumentServiceImpl implements IDocumentService
|
|
Document existDoc = documentMapper.checkDocumentTitleUnique(title, templateFlag);
|
|
Document existDoc = documentMapper.checkDocumentTitleUnique(title, templateFlag);
|
|
if (StringUtils.isNotNull(existDoc)) {
|
|
if (StringUtils.isNotNull(existDoc)) {
|
|
String type = templateFlag == 1 ? "模板" : "文档";
|
|
String type = templateFlag == 1 ? "模板" : "文档";
|
|
- return AjaxResult.error(String.format("%s标题 '%s' 已存在", type, title));
|
|
|
|
|
|
+ return AjaxResultCQY.error(String.format("%s标题 '%s' 已存在", type, title));
|
|
}
|
|
}
|
|
|
|
|
|
// // 4. 处理文件上传
|
|
// // 4. 处理文件上传
|
|
@@ -102,7 +172,7 @@ public class DcDocumentServiceImpl implements IDocumentService
|
|
// 6. 保存文档
|
|
// 6. 保存文档
|
|
int rows = documentMapper.insertDocument(document);
|
|
int rows = documentMapper.insertDocument(document);
|
|
if (rows <= 0) {
|
|
if (rows <= 0) {
|
|
- return AjaxResult.error("创建文档失败");
|
|
|
|
|
|
+ return AjaxResultCQY.error("创建文档失败");
|
|
}
|
|
}
|
|
|
|
|
|
// 7. 处理项目关联
|
|
// 7. 处理项目关联
|
|
@@ -129,7 +199,7 @@ public class DcDocumentServiceImpl implements IDocumentService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return AjaxResult.success("创建成功", document.getId());
|
|
|
|
|
|
+ return AjaxResultCQY.success("创建成功", document.getId());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
throw new ServiceException("创建文档失败:" + e.getMessage());
|
|
throw new ServiceException("创建文档失败:" + e.getMessage());
|