DcDocumentServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. package com.gqy.document.service.impl;
  2. import java.util.*;
  3. import java.util.stream.Collectors;
  4. import com.alibaba.fastjson2.JSONArray;
  5. import com.github.pagehelper.PageHelper;
  6. import com.github.pagehelper.PageInfo;
  7. import com.gqy.common.constant.Constants;
  8. import com.gqy.common.core.domain.AjaxResult;
  9. import com.gqy.common.core.domain.AjaxResultCQY;
  10. import com.gqy.common.core.text.Convert;
  11. import com.gqy.common.exception.ServiceException;
  12. import com.gqy.common.utils.*;
  13. import com.gqy.document.domain.DcDocument;
  14. import com.gqy.document.domain.ProductDocument;
  15. import com.gqy.document.domain.vo.PageResult;
  16. import com.gqy.document.domain.Document;
  17. import com.gqy.document.domain.ProjectDocument;
  18. import com.gqy.document.mapper.DcProductMapper;
  19. import com.gqy.document.mapper.DocumentMapper;
  20. import com.gqy.document.mapper.ProductDocumentMapper;
  21. import com.gqy.document.mapper.ProjectDocumentMapper;
  22. import com.gqy.document.service.IDocumentService;
  23. import org.apache.commons.collections4.CollectionUtils;
  24. import org.apache.poi.ss.usermodel.IconMultiStateFormatting;
  25. import org.slf4j.Logger;
  26. import org.slf4j.LoggerFactory;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import javax.servlet.http.HttpServletRequest;
  32. /**
  33. * 【请填写功能名称】Service业务层处理
  34. *
  35. * @author raycos
  36. * @date 2024-10-30
  37. */
  38. @Service
  39. public class DcDocumentServiceImpl implements IDocumentService
  40. {
  41. private static final Logger log = LoggerFactory.getLogger(DcDocumentServiceImpl.class);
  42. @Autowired
  43. private DocumentMapper documentMapper;
  44. /**
  45. * 查询
  46. * @param page
  47. * @param pageSize
  48. * @param dcDocument
  49. * @return
  50. */
  51. public PageResult selectDcDocumentList(Integer page, Integer pageSize, DcDocument dcDocument,Map maps){
  52. PageHelper.startPage(page, pageSize);
  53. List<DcDocument> list = documentMapper.selectDcDocumentList(dcDocument);
  54. //isContentShow true 显示 false 不显现
  55. boolean isContentShow = false;
  56. if (maps != null && maps.get("isContentShow") != null) {
  57. isContentShow = (boolean) maps.get("isContentShow");
  58. }
  59. if (!isContentShow && list != null) {
  60. for (DcDocument dcDocument1 : list) {
  61. if (dcDocument1 != null) {
  62. dcDocument1.setDcm_data("");
  63. }
  64. }
  65. }
  66. PageInfo<DcDocument> pageInfo = new PageInfo<>(list);
  67. return new PageResult(
  68. pageInfo.getPageNum(),
  69. pageInfo.getPageSize(),
  70. pageInfo.getPages(),
  71. pageInfo.getTotal(),
  72. pageInfo.getList()
  73. );
  74. }
  75. public List<DcDocument> selectDcDocumentList(DcDocument dcDocument) {
  76. return documentMapper.selectDcDocumentList(dcDocument);
  77. }
  78. /**
  79. * 插入
  80. * @param dcDocument
  81. * @return
  82. */
  83. public int insertDcDocument(DcDocument dcDocument) {
  84. dcDocument.setDcm_status(Constants.status_5);
  85. return documentMapper.insertDcDocument(dcDocument);
  86. }
  87. /**
  88. * 更新
  89. * @param dcDocument
  90. * @return
  91. */
  92. public int updateDcDocument(DcDocument dcDocument) {
  93. return documentMapper.updateDcDocument(dcDocument);
  94. }
  95. /**
  96. * 删除
  97. * @param id
  98. * @return
  99. */
  100. public int deleteDcDocumentById(Long id){
  101. DcDocument dcDocument = documentMapper.selectDcDocumentByDcmId(id);
  102. dcDocument.setDcm_status(Constants.status_4);
  103. return documentMapper.updateDcDocument(dcDocument);
  104. }
  105. /**
  106. *
  107. * chax
  108. * @param id
  109. * @return
  110. */
  111. public DcDocument selectDcDocumentByDcmId(Long id){
  112. return documentMapper.selectDcDocumentByDcmId(id);
  113. }
  114. // @Autowired
  115. // private DocumentMapper documentMapper;
  116. //
  117. // @Autowired
  118. // private ProjectDocumentMapper projectDocumentMapper;
  119. //
  120. // @Autowired
  121. // private ProductDocumentMapper productDocumentMapper;
  122. //
  123. // /**
  124. // * 更新文档
  125. // * @param document
  126. // * @return
  127. // */
  128. // @Transactional
  129. // public AjaxResultCQY updateDocument(Document document) {
  130. //// try {
  131. //// log.info("开始更新文档信息, 文档ID: {}", document.getId());
  132. //// // 1. 检查文档是否存在
  133. //// Document existDoc = documentMapper.info(document.getId());
  134. //// if (existDoc == null) {
  135. //// log.warn("文档不存在, 文档ID: {}", document.getId());
  136. //// return AjaxResultCQY.error("更新文档信息失败:文档不存在");
  137. //// }
  138. //// // 2. 更新文档基本信息
  139. //// log.info("更新文档基本信息: {}", document);
  140. //// int rows = documentMapper.updateDocument(document);
  141. //// if (rows <= 0) {
  142. //// return AjaxResultCQY.error("更新文档基本信息失败");
  143. //// }
  144. //// // 3. 更新产品关联
  145. //// log.info("开始更新文档产品关联, 文档ID: {}", document.getId());
  146. //// productDocumentMapper.deleteProductDocumentByDocId(document.getId());
  147. //// if (CollectionUtils.isNotEmpty(document.getLinks())) {
  148. ////
  149. //// List<ProductDocument> productDocs = document.getLinks().stream()
  150. //// .map(productId -> {
  151. //// ProductDocument pd = new ProductDocument();
  152. //// pd.setDocument_id(document.getId());
  153. //// pd.setProduct_id(Long.valueOf(productId));
  154. //// pd.setStatus(5);
  155. //// return pd;
  156. //// })
  157. //// .collect(Collectors.toList());
  158. //// productDocumentMapper.batchInsertProductDocument(productDocs);
  159. //// }
  160. ////
  161. //// log.info("开始更新文档项目关联, 文档ID: {}", document.getId());
  162. //// projectDocumentMapper.deleteProjectDocumentByDocId(document.getId());
  163. //// if (CollectionUtils.isNotEmpty(document.getProjects())) {
  164. //// List<ProjectDocument> projectDocs = document.getProjects().stream().map(projectId -> {
  165. //// ProjectDocument pd = new ProjectDocument();
  166. //// pd.setDoc_id(document.getId());
  167. //// pd.setProject_id(Long.valueOf(projectId));
  168. //// pd.setStatus(5);
  169. //// return pd;
  170. //// }).collect(Collectors.toList());
  171. //// projectDocumentMapper.batchInsertProjectDocument(projectDocs);
  172. //// }
  173. //// log.info("文档更新成功, 文档ID: {}", document.getId());
  174. //// return AjaxResultCQY.success(document.getId());
  175. //// }catch (Exception e){
  176. //// log.error("更新文档失败, 文档ID: {}, 错误信息: {}", document.getId(), e.getMessage(), e);
  177. //// return AjaxResultCQY.error("更新文档失败:" + e.getMessage());
  178. //// }
  179. // return null;
  180. // }
  181. //
  182. // /**
  183. // * 创建文档
  184. // * @param request
  185. // * @param file
  186. // * @return
  187. // */
  188. // @Transactional
  189. // public AjaxResultCQY create(Map request, MultipartFile file) {
  190. //// try {
  191. //// // 1. 获取表单参数
  192. //// String title = (String) request.get("title");
  193. //// String data = (String)request.get("data");
  194. //// Integer isTemplate = (Integer)request.get("is_template");
  195. //// Integer status = (Integer)request.get("status");
  196. //// String projects = (String)request.get("projects");
  197. ////
  198. //// // 2. 参数校验
  199. //// if (StringUtils.isEmpty(title)) {
  200. //// return AjaxResultCQY.error("文档标题不能为空");
  201. //// }
  202. ////
  203. //// Integer templateFlag = Convert.toInt(isTemplate, 0);
  204. ////// if (templateFlag == 0 && StringUtils.isEmpty(request.get("category_id").toString())) {
  205. ////// return AjaxResult.error("保存文档时,分类不能为空");
  206. ////// }
  207. ////
  208. //// // Integer categoryId = Integer.valueOf(request.get("category_id").toString());
  209. ////
  210. ////
  211. //// // 3. 检查标题是否重复
  212. //// Document existDoc = documentMapper.checkDocumentTitleUnique(title, templateFlag);
  213. //// if (StringUtils.isNotNull(existDoc)) {
  214. //// String type = templateFlag == 1 ? "模板" : "文档";
  215. //// return AjaxResultCQY.error(String.format("%s标题 '%s' 已存在", type, title));
  216. //// }
  217. ////
  218. ////// // 4. 处理文件上传
  219. ////// String fileUrl = "";
  220. ////// if (file != null && !file.isEmpty()) {
  221. ////// SysFile sysFile = sysFileService.uploadFile(file);
  222. ////// if (sysFile != null) {
  223. ////// fileUrl = sysFile.getUrl();
  224. ////// // 如果是文本文件,尝试读取内容
  225. ////// if (FileTypeUtils.isText(file.getOriginalFilename())) {
  226. ////// data = FileUtils.readString(file);
  227. ////// }
  228. ////// }
  229. ////// }
  230. ////
  231. //// // 5. 创建文档对象
  232. //// Document document = new Document();
  233. //// document.setTitle(title);
  234. ////// document.setData(StringUtils.isNotEmpty(data) ? data : fileUrl);
  235. //// document.setData(StringUtils.isNotEmpty(data) ? data : "");
  236. //// document.setUser_id(SecurityUtils.getUserId());
  237. //// //document.setCategory_id( Long.valueOf(categoryId));
  238. //// document.setIs_template(templateFlag);
  239. //// document.setStatus(Convert.toInt(status, 5));
  240. //// document.setCreateTime(DateUtils.getNowDate());
  241. //// document.setUpdateTime(DateUtils.getNowDate());
  242. //// document.setCreateBy(SecurityUtils.getUsername());
  243. ////
  244. //// // 6. 保存文档
  245. //// int rows = documentMapper.insertDocument(document);
  246. //// if (rows <= 0) {
  247. //// return AjaxResultCQY.error("创建文档失败");
  248. //// }
  249. ////
  250. //// // 7. 处理项目关联
  251. //// if (StringUtils.isNotEmpty(projects)) {
  252. //// try {
  253. //// JSONArray projectArray = JSONArray.parseArray(projects);
  254. //// List<ProjectDocument> projectDocList = new ArrayList<>();
  255. ////
  256. //// for (int i = 0; i < projectArray.size(); i++) {
  257. //// ProjectDocument pd = new ProjectDocument();
  258. //// pd.setDoc_id(document.getId());
  259. //// pd.setProject_id(projectArray.getLong(i));
  260. //// pd.setStatus(5);
  261. //// pd.setCreate_time(DateUtils.getNowDate());
  262. //// pd.setCreate_by(SecurityUtils.getUsername());
  263. //// projectDocList.add(pd);
  264. //// }
  265. ////
  266. //// if (!projectDocList.isEmpty()) {
  267. //// projectDocumentMapper.batchInsertProjectDocument(projectDocList);
  268. //// }
  269. //// } catch (Exception e) {
  270. //// throw new ServiceException("处理项目关联失败");
  271. //// }
  272. //// }
  273. ////
  274. //// return AjaxResultCQY.success("创建成功", document.getId());
  275. //// } catch (Exception e) {
  276. //// e.printStackTrace();
  277. //// throw new ServiceException("创建文档失败:" + e.getMessage());
  278. //// }
  279. // return null;
  280. // }
  281. //
  282. // @Override
  283. // public PageResult pageDocument(Integer page, Integer pageSize, Document document) {
  284. // try {
  285. // // 1. 设置分页参数
  286. // PageHelper.startPage(page, pageSize);
  287. //
  288. // // 2. 执行查询
  289. // List<Map<String, Object>> list = documentMapper.pageDocument(document);
  290. //
  291. // // 3. 获取分页信息
  292. // PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
  293. //
  294. // // 4. 封装并返回结果
  295. // return new PageResult(
  296. // pageInfo.getPageNum(),
  297. // pageInfo.getPageSize(),
  298. // pageInfo.getPages(),
  299. // pageInfo.getTotal(),
  300. // pageInfo.getList()
  301. // );
  302. //
  303. // } catch (Exception e) {
  304. // log.error("查询文档列表失败", e);
  305. // return new PageResult(page, pageSize);
  306. // }
  307. //
  308. // }
  309. //
  310. // /**
  311. // * 查询文档列表
  312. // * @param page
  313. // * @param pageSize
  314. // * @param document
  315. // * @return
  316. // */
  317. // public PageResult searchlistDoc(Integer page, Integer pageSize,Document document) {
  318. ////
  319. //// try {
  320. //// // 1. 设置分页参数
  321. //// PageHelper.startPage(page, pageSize);
  322. //// // 2. 执行查询
  323. //// List<Document> list = documentMapper.selectDocumentList(document);
  324. //// // 3. 获取分页信息
  325. //// PageInfo<Document> pageInfo = new PageInfo<>(list);
  326. //// // 4. 封装并返回结果
  327. //// return new PageResult(
  328. //// pageInfo.getPageNum(),
  329. //// pageInfo.getPageSize(),
  330. //// pageInfo.getPages(),
  331. //// pageInfo.getTotal(),
  332. //// pageInfo.getList()
  333. //// );
  334. ////
  335. //// } catch (Exception e) {
  336. //// log.error("查询文档列表失败", e);
  337. //// return new PageResult(page, pageSize);
  338. //// }
  339. // return null;
  340. // }
  341. //
  342. //
  343. // /**
  344. // * 查询文档详情
  345. // *
  346. // * @param id 文档ID
  347. // * @return 文档信息
  348. // */
  349. // public Map<String, Object> info(Long id) {
  350. // Document doc = documentMapper.info(id);
  351. // Map<String, Object> result = new HashMap<>();
  352. // result.put("id", doc.getId());
  353. // result.put("title", doc.getTitle());
  354. // result.put("data", doc.getData());
  355. // // result.put("user_id", doc.getUserId());
  356. //
  357. // // 获取关联产品
  358. // result.put("linkProduct", documentMapper.selectProductDocumentsByDocId(id));
  359. // result.put("links", "");
  360. //
  361. // // 获取关联项目
  362. // result.put("linkProject", documentMapper.selectProjectDocumentsByDocId(id));
  363. // result.put("projects", "");
  364. //
  365. // result.put("category_id", doc.getCategory_id());
  366. // result.put("createTime", doc.getCreateTime());
  367. // result.put("status", doc.getStatus());
  368. // result.put("is_template", doc.getIs_template());
  369. //
  370. // return result;
  371. // }
  372. //
  373. // /**
  374. // * 查询文档列表
  375. // *
  376. // * @param document 文档信息
  377. // * @return 文档集合
  378. // */
  379. // public List<Document> searchList(Document document){
  380. // return documentMapper.searchList(document);
  381. // }
  382. }