DocInfoServiceImpl.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package com.doc.biz.service.impl;
  2. import com.doc.biz.domain.DocFavorite;
  3. import com.doc.biz.domain.DocInfo;
  4. import com.doc.biz.mapper.DocInfoMapper;
  5. import com.doc.biz.service.*;
  6. import com.doc.biz.vo.DocumentVO;
  7. import com.doc.common.utils.DateUtils;
  8. import com.doc.common.utils.SecurityUtils;
  9. import com.doc.common.utils.StringUtils;
  10. import org.springframework.stereotype.Service;
  11. import javax.annotation.Resource;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. /**
  15. * 文件基本信息表Service业务层处理
  16. *
  17. * @author wukai
  18. * @date 2023-08-15
  19. */
  20. @Service
  21. public class DocInfoServiceImpl implements IDocInfoService {
  22. @Resource
  23. private DocInfoMapper docInfoMapper;
  24. @Resource
  25. private IElasticSearchService elasticSearchService;
  26. @Resource
  27. private IDocSpaceService spaceService;
  28. @Resource
  29. private IDocFavoriteService favoriteService;
  30. @Resource
  31. private IDocDirService dirService;
  32. /**
  33. * 查询文件基本信息表
  34. *
  35. * @param docId 文件基本信息表主键
  36. * @return 文件基本信息表
  37. */
  38. @Override
  39. public DocInfo selectDocInfoByDocId(Long docId) {
  40. DocInfo info = docInfoMapper.selectDocInfoByDocId(docId);
  41. if (info != null) {
  42. String unloading = "l0400";
  43. //是否允许转存
  44. info.setUnloading(dirService.hasRole(info.getDirId(), unloading));
  45. }
  46. return info;
  47. }
  48. /**
  49. * 通过fileID查询文件基本信息
  50. *
  51. * @param fileId mongo文件ID
  52. */
  53. @Override
  54. public DocInfo selectDocInfoByFileId(String fileId) {
  55. return docInfoMapper.selectDocInfoByFileId(fileId);
  56. }
  57. /**
  58. * only office更新文件内容
  59. *
  60. * @param info 文件信息
  61. */
  62. @Override
  63. public void updateDocInfoByOnlyOffice(DocInfo info) {
  64. info.setUpdateTime(DateUtils.getNowDate());
  65. docInfoMapper.updateDocInfo(info);
  66. if (StringUtils.isNotEmpty(info.getFileId())) {
  67. elasticSearchService.save(info);
  68. }
  69. //改变空间容量
  70. spaceService.updateUsedCap(info.getSpaceId());
  71. }
  72. /**
  73. * 文件上传之后的操作
  74. *
  75. * @param vo 上传对象
  76. * @param spaceId 空间ID
  77. * @param dirId 目录ID
  78. * @return 对象
  79. */
  80. @Override
  81. public DocInfo upload(DocumentVO vo, Long spaceId, Long dirId) {
  82. DocInfo docInfo = new DocInfo();
  83. docInfo.setSpaceId(spaceId);
  84. docInfo.setDirId(dirId);
  85. docInfo.setFileId(vo.getFileId());
  86. docInfo.setFileName(vo.getFileName());
  87. docInfo.setFileSize(vo.getFileSize());
  88. docInfo.setFileType(vo.getSuffix());
  89. docInfo.setCreateBy(SecurityUtils.getUsername());
  90. insertDocInfo(docInfo);
  91. return docInfo;
  92. }
  93. /**
  94. * 查询文件基本信息表列表
  95. *
  96. * @param docInfo 文件基本信息表
  97. * @return 文件基本信息表
  98. */
  99. @Override
  100. public List<DocInfo> selectDocInfoList(DocInfo docInfo) {
  101. List<DocInfo> list = docInfoMapper.selectDocInfoList(docInfo);
  102. List<Long> favorites = new ArrayList<>();
  103. DocFavorite favorite = new DocFavorite();
  104. favorite.setOwner(SecurityUtils.getUserId());
  105. favorite.setIsFolder("N");
  106. favoriteService.selectDocFavoriteList(favorite).forEach(f -> {
  107. favorites.add(f.getRelaId());
  108. });
  109. list.forEach(i -> {
  110. if (favorites.contains(i.getDocId())) {
  111. i.setIsFavorite("Y");
  112. } else {
  113. i.setIsFavorite("N");
  114. }
  115. });
  116. return list;
  117. }
  118. /**
  119. * 新增文件基本信息表
  120. *
  121. * @param docInfo 文件基本信息表
  122. * @return 结果
  123. */
  124. @Override
  125. public int insertDocInfo(DocInfo docInfo) {
  126. docInfo.setCreateTime(DateUtils.getNowDate());
  127. checkDuplicateNames(docInfo);
  128. int i = docInfoMapper.insertDocInfo(docInfo);
  129. String allowSearch = "l0300";
  130. if (dirService.hasRole(docInfo.getDirId(), allowSearch)) {
  131. //只有允许全文搜索的才会存入ES库,否则不存入
  132. elasticSearchService.save(docInfo);
  133. }
  134. //改变空间容量
  135. spaceService.updateUsedCap(docInfo.getSpaceId());
  136. return i;
  137. }
  138. /**
  139. * 检查重名
  140. *
  141. * @param docInfo 文件信息
  142. */
  143. private void checkDuplicateNames(DocInfo docInfo) {
  144. DocInfo query = new DocInfo();
  145. query.setDirId(docInfo.getDirId());
  146. query.setFileName(docInfo.getFileName());
  147. List list = selectDocInfoList(query);
  148. if (list.size() > 0) {
  149. String fileName = docInfo.getFileName();
  150. fileName = fileName + "-" + DateUtils.dateTimeNow();
  151. docInfo.setFileName(fileName);
  152. }
  153. }
  154. /**
  155. * 修改文件基本信息表
  156. *
  157. * @param docInfo 文件基本信息表
  158. * @return 结果
  159. */
  160. @Override
  161. public int updateDocInfo(DocInfo docInfo) {
  162. checkDuplicateNames(docInfo);
  163. docInfo.setUpdateTime(DateUtils.getNowDate());
  164. int i = docInfoMapper.updateDocInfo(docInfo);
  165. return i;
  166. }
  167. /**
  168. * 批量删除文件基本信息表
  169. *
  170. * @param docIds 需要删除的文件基本信息表主键
  171. * @return 结果
  172. */
  173. @Override
  174. public int deleteDocInfoByDocIds(Long[] docIds) {
  175. List<Long> spaceIds = new ArrayList<>();
  176. for (Long docId : docIds) {
  177. DocInfo docInfo = selectDocInfoByDocId(docId);
  178. spaceIds.add(docInfo.getSpaceId());
  179. }
  180. int i = docInfoMapper.deleteDocInfoByDocIds(docIds);
  181. //改变空间容量
  182. for (Long spaceId : spaceIds) {
  183. spaceService.updateUsedCap(spaceId);
  184. }
  185. return i;
  186. }
  187. /**
  188. * 删除文件基本信息表信息
  189. *
  190. * @param docId 文件基本信息表主键
  191. * @return 结果
  192. */
  193. @Override
  194. public int deleteDocInfoByDocId(Long docId) {
  195. DocInfo docInfo = selectDocInfoByDocId(docId);
  196. int i = docInfoMapper.deleteDocInfoByDocId(docId);
  197. //改变空间容量
  198. spaceService.updateUsedCap(docInfo.getSpaceId());
  199. return i;
  200. }
  201. }