123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- package com.gqy.document.service.impl;
- import java.util.*;
- import java.util.stream.Collectors;
- import com.alibaba.fastjson2.JSONArray;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.gqy.common.constant.Constants;
- 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.exception.ServiceException;
- import com.gqy.common.utils.*;
- import com.gqy.document.domain.DcDocument;
- import com.gqy.document.domain.ProductDocument;
- import com.gqy.document.domain.vo.PageResult;
- import com.gqy.document.domain.Document;
- import com.gqy.document.domain.ProjectDocument;
- import com.gqy.document.mapper.DcProductMapper;
- import com.gqy.document.mapper.DocumentMapper;
- import com.gqy.document.mapper.ProductDocumentMapper;
- import com.gqy.document.mapper.ProjectDocumentMapper;
- import com.gqy.document.service.IDocumentService;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.poi.ss.usermodel.IconMultiStateFormatting;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletRequest;
- /**
- * 【请填写功能名称】Service业务层处理
- *
- * @author raycos
- * @date 2024-10-30
- */
- @Service
- public class DcDocumentServiceImpl implements IDocumentService
- {
- private static final Logger log = LoggerFactory.getLogger(DcDocumentServiceImpl.class);
- @Autowired
- private DocumentMapper documentMapper;
- /**
- * 查询
- * @param page
- * @param pageSize
- * @param dcDocument
- * @return
- */
- public PageResult selectDcDocumentList(Integer page, Integer pageSize, DcDocument dcDocument,Map maps){
- PageHelper.startPage(page, pageSize);
- List<DcDocument> list = documentMapper.selectDcDocumentList(dcDocument);
- //isContentShow true 显示 false 不显现
- boolean isContentShow = false;
- if (maps != null && maps.get("isContentShow") != null) {
- isContentShow = (boolean) maps.get("isContentShow");
- }
- if (!isContentShow && list != null) {
- for (DcDocument dcDocument1 : list) {
- if (dcDocument1 != null) {
- dcDocument1.setDcm_data("");
- }
- }
- }
- PageInfo<DcDocument> pageInfo = new PageInfo<>(list);
- return new PageResult(
- pageInfo.getPageNum(),
- pageInfo.getPageSize(),
- pageInfo.getPages(),
- pageInfo.getTotal(),
- pageInfo.getList()
- );
- }
- public List<DcDocument> selectDcDocumentList(DcDocument dcDocument) {
- return documentMapper.selectDcDocumentList(dcDocument);
- }
- /**
- * 插入
- * @param dcDocument
- * @return
- */
- public int insertDcDocument(DcDocument dcDocument) {
- dcDocument.setDcm_status(Constants.status_5);
- return documentMapper.insertDcDocument(dcDocument);
- }
- /**
- * 更新
- * @param dcDocument
- * @return
- */
- public int updateDcDocument(DcDocument dcDocument) {
- return documentMapper.updateDcDocument(dcDocument);
- }
- /**
- * 删除
- * @param id
- * @return
- */
- public int deleteDcDocumentById(Long id){
- DcDocument dcDocument = documentMapper.selectDcDocumentByDcmId(id);
- dcDocument.setDcm_status(Constants.status_4);
- return documentMapper.updateDcDocument(dcDocument);
- }
- /**
- *
- * chax
- * @param id
- * @return
- */
- public DcDocument selectDcDocumentByDcmId(Long id){
- return documentMapper.selectDcDocumentByDcmId(id);
- }
- // @Autowired
- // private DocumentMapper documentMapper;
- //
- // @Autowired
- // 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());
- //// }
- // return null;
- // }
- //
- // /**
- // * 创建文档
- // * @param request
- // * @param file
- // * @return
- // */
- // @Transactional
- // public AjaxResultCQY create(Map request, MultipartFile file) {
- //// try {
- //// // 1. 获取表单参数
- //// String title = (String) request.get("title");
- //// String data = (String)request.get("data");
- //// Integer isTemplate = (Integer)request.get("is_template");
- //// Integer status = (Integer)request.get("status");
- //// String projects = (String)request.get("projects");
- ////
- //// // 2. 参数校验
- //// if (StringUtils.isEmpty(title)) {
- //// return AjaxResultCQY.error("文档标题不能为空");
- //// }
- ////
- //// Integer templateFlag = Convert.toInt(isTemplate, 0);
- ////// if (templateFlag == 0 && StringUtils.isEmpty(request.get("category_id").toString())) {
- ////// return AjaxResult.error("保存文档时,分类不能为空");
- ////// }
- ////
- //// // Integer categoryId = Integer.valueOf(request.get("category_id").toString());
- ////
- ////
- //// // 3. 检查标题是否重复
- //// Document existDoc = documentMapper.checkDocumentTitleUnique(title, templateFlag);
- //// if (StringUtils.isNotNull(existDoc)) {
- //// String type = templateFlag == 1 ? "模板" : "文档";
- //// return AjaxResultCQY.error(String.format("%s标题 '%s' 已存在", type, title));
- //// }
- ////
- ////// // 4. 处理文件上传
- ////// String fileUrl = "";
- ////// if (file != null && !file.isEmpty()) {
- ////// SysFile sysFile = sysFileService.uploadFile(file);
- ////// if (sysFile != null) {
- ////// fileUrl = sysFile.getUrl();
- ////// // 如果是文本文件,尝试读取内容
- ////// if (FileTypeUtils.isText(file.getOriginalFilename())) {
- ////// data = FileUtils.readString(file);
- ////// }
- ////// }
- ////// }
- ////
- //// // 5. 创建文档对象
- //// Document document = new Document();
- //// document.setTitle(title);
- ////// document.setData(StringUtils.isNotEmpty(data) ? data : fileUrl);
- //// document.setData(StringUtils.isNotEmpty(data) ? data : "");
- //// document.setUser_id(SecurityUtils.getUserId());
- //// //document.setCategory_id( Long.valueOf(categoryId));
- //// document.setIs_template(templateFlag);
- //// document.setStatus(Convert.toInt(status, 5));
- //// document.setCreateTime(DateUtils.getNowDate());
- //// document.setUpdateTime(DateUtils.getNowDate());
- //// document.setCreateBy(SecurityUtils.getUsername());
- ////
- //// // 6. 保存文档
- //// int rows = documentMapper.insertDocument(document);
- //// if (rows <= 0) {
- //// return AjaxResultCQY.error("创建文档失败");
- //// }
- ////
- //// // 7. 处理项目关联
- //// if (StringUtils.isNotEmpty(projects)) {
- //// try {
- //// JSONArray projectArray = JSONArray.parseArray(projects);
- //// List<ProjectDocument> projectDocList = new ArrayList<>();
- ////
- //// for (int i = 0; i < projectArray.size(); i++) {
- //// ProjectDocument pd = new ProjectDocument();
- //// pd.setDoc_id(document.getId());
- //// pd.setProject_id(projectArray.getLong(i));
- //// pd.setStatus(5);
- //// pd.setCreate_time(DateUtils.getNowDate());
- //// pd.setCreate_by(SecurityUtils.getUsername());
- //// projectDocList.add(pd);
- //// }
- ////
- //// if (!projectDocList.isEmpty()) {
- //// projectDocumentMapper.batchInsertProjectDocument(projectDocList);
- //// }
- //// } catch (Exception e) {
- //// throw new ServiceException("处理项目关联失败");
- //// }
- //// }
- ////
- //// return AjaxResultCQY.success("创建成功", document.getId());
- //// } catch (Exception e) {
- //// e.printStackTrace();
- //// throw new ServiceException("创建文档失败:" + e.getMessage());
- //// }
- // return null;
- // }
- //
- // @Override
- // public PageResult pageDocument(Integer page, Integer pageSize, Document document) {
- // try {
- // // 1. 设置分页参数
- // PageHelper.startPage(page, pageSize);
- //
- // // 2. 执行查询
- // List<Map<String, Object>> list = documentMapper.pageDocument(document);
- //
- // // 3. 获取分页信息
- // PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
- //
- // // 4. 封装并返回结果
- // return new PageResult(
- // pageInfo.getPageNum(),
- // pageInfo.getPageSize(),
- // pageInfo.getPages(),
- // pageInfo.getTotal(),
- // pageInfo.getList()
- // );
- //
- // } catch (Exception e) {
- // log.error("查询文档列表失败", e);
- // return new PageResult(page, pageSize);
- // }
- //
- // }
- //
- // /**
- // * 查询文档列表
- // * @param page
- // * @param pageSize
- // * @param document
- // * @return
- // */
- // public PageResult searchlistDoc(Integer page, Integer pageSize,Document document) {
- ////
- //// try {
- //// // 1. 设置分页参数
- //// PageHelper.startPage(page, pageSize);
- //// // 2. 执行查询
- //// List<Document> list = documentMapper.selectDocumentList(document);
- //// // 3. 获取分页信息
- //// PageInfo<Document> pageInfo = new PageInfo<>(list);
- //// // 4. 封装并返回结果
- //// return new PageResult(
- //// pageInfo.getPageNum(),
- //// pageInfo.getPageSize(),
- //// pageInfo.getPages(),
- //// pageInfo.getTotal(),
- //// pageInfo.getList()
- //// );
- ////
- //// } catch (Exception e) {
- //// log.error("查询文档列表失败", e);
- //// return new PageResult(page, pageSize);
- //// }
- // return null;
- // }
- //
- //
- // /**
- // * 查询文档详情
- // *
- // * @param id 文档ID
- // * @return 文档信息
- // */
- // public Map<String, Object> info(Long id) {
- // Document doc = documentMapper.info(id);
- // Map<String, Object> result = new HashMap<>();
- // result.put("id", doc.getId());
- // result.put("title", doc.getTitle());
- // result.put("data", doc.getData());
- // // result.put("user_id", doc.getUserId());
- //
- // // 获取关联产品
- // result.put("linkProduct", documentMapper.selectProductDocumentsByDocId(id));
- // result.put("links", "");
- //
- // // 获取关联项目
- // result.put("linkProject", documentMapper.selectProjectDocumentsByDocId(id));
- // result.put("projects", "");
- //
- // result.put("category_id", doc.getCategory_id());
- // result.put("createTime", doc.getCreateTime());
- // result.put("status", doc.getStatus());
- // result.put("is_template", doc.getIs_template());
- //
- // return result;
- // }
- //
- // /**
- // * 查询文档列表
- // *
- // * @param document 文档信息
- // * @return 文档集合
- // */
- // public List<Document> searchList(Document document){
- // return documentMapper.searchList(document);
- // }
- }
|