DocumentServiceImpl.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. package jnpf.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.github.yulichang.toolkit.JoinWrappers;
  8. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  9. import jnpf.base.UserInfo;
  10. import jnpf.base.entity.SuperBaseEntity;
  11. import jnpf.base.service.SuperServiceImpl;
  12. import jnpf.config.ConfigValueUtil;
  13. import jnpf.constant.PermissionConst;
  14. import jnpf.emnus.SysParamEnum;
  15. import jnpf.entity.DocumentEntity;
  16. import jnpf.entity.DocumentLogEntity;
  17. import jnpf.entity.DocumentShareEntity;
  18. import jnpf.mapper.DocumentMapper;
  19. import jnpf.message.entity.SynThirdInfoEntity;
  20. import jnpf.model.document.DocumentListVO;
  21. import jnpf.model.document.DocumentShareForm;
  22. import jnpf.model.document.DocumentTrashListVO;
  23. import jnpf.model.document.FlowFileModel;
  24. import jnpf.permission.entity.OrganizeEntity;
  25. import jnpf.permission.entity.PositionEntity;
  26. import jnpf.permission.entity.UserEntity;
  27. import jnpf.permission.entity.UserRelationEntity;
  28. import jnpf.permission.service.*;
  29. import jnpf.service.DocumentLogService;
  30. import jnpf.service.DocumentService;
  31. import jnpf.service.DocumentShareService;
  32. import jnpf.util.FileUtil;
  33. import jnpf.util.RandomUtil;
  34. import jnpf.util.StringUtil;
  35. import jnpf.util.UserProvider;
  36. import org.apache.commons.collections4.CollectionUtils;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.stereotype.Service;
  39. import org.springframework.transaction.annotation.Transactional;
  40. import java.util.*;
  41. import java.util.stream.Collectors;
  42. import java.util.stream.Stream;
  43. /**
  44. * 知识文档
  45. *
  46. * @author JNPF开发平台组
  47. * @copyright 引迈信息技术有限公司
  48. * @date 2019年9月26日 上午9:18
  49. */
  50. @Service
  51. public class DocumentServiceImpl extends SuperServiceImpl<DocumentMapper, DocumentEntity> implements DocumentService {
  52. @Autowired
  53. private DocumentShareService documentShareService;
  54. @Autowired
  55. private UserService userService;
  56. @Autowired
  57. private PositionService positionService;
  58. @Autowired
  59. private OrganizeService organizeService;
  60. @Autowired
  61. private ConfigValueUtil configValueUtil;
  62. @Autowired
  63. private DocumentLogService documentLogService;
  64. @Override
  65. public List<DocumentEntity> getFolderList() {
  66. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  67. queryWrapper.lambda()
  68. .eq(DocumentEntity::getCreatorUserId, UserProvider.getUser().getUserId())
  69. .eq(DocumentEntity::getType, 0)
  70. .eq(DocumentEntity::getEnabledMark, 1)
  71. .orderByDesc(DocumentEntity::getCreatorTime);
  72. return this.list(queryWrapper);
  73. }
  74. @Override
  75. public List<DocumentEntity> getAllList(String parentId) {
  76. return this.getChildList(parentId, false);
  77. }
  78. @Override
  79. public List<DocumentEntity> getChildList(String parentId, boolean isShare) {
  80. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  81. if (!isShare) {
  82. queryWrapper.lambda().eq(DocumentEntity::getCreatorUserId, UserProvider.getUser().getUserId());
  83. }
  84. queryWrapper.lambda()
  85. .eq(DocumentEntity::getEnabledMark, 1)
  86. .eq(DocumentEntity::getParentId, parentId)
  87. .orderByAsc(DocumentEntity::getType)
  88. .orderByDesc(DocumentEntity::getCreatorTime);
  89. return this.list(queryWrapper);
  90. }
  91. @Override
  92. public List<DocumentListVO> getChildListUserName(String parentId, boolean isShare) {
  93. MPJLambdaWrapper<DocumentEntity> queryWrapper = JoinWrappers.lambda(DocumentEntity.class);
  94. queryWrapper.leftJoin(UserEntity.class, SuperBaseEntity.SuperIBaseEntity::getId, DocumentEntity::getCreatorUserId);
  95. queryWrapper.selectAs(UserEntity::getRealName, DocumentListVO::getCreatorUserName);
  96. queryWrapper.selectAs(UserEntity::getAccount, DocumentListVO::getCreatorUserAccount);
  97. queryWrapper.selectAs(DocumentEntity::getId, DocumentListVO::getId);
  98. queryWrapper.selectAs(DocumentEntity::getCreatorUserId, DocumentListVO::getCreatorUserId);
  99. queryWrapper.selectAs(DocumentEntity::getType, DocumentListVO::getType);
  100. queryWrapper.selectAs(DocumentEntity::getFilePath, DocumentListVO::getFilePath);
  101. queryWrapper.selectAs(DocumentEntity::getUploaderUrl, DocumentListVO::getUploaderUrl);
  102. queryWrapper.selectAs(DocumentEntity::getIsShare, DocumentListVO::getIsShare);
  103. queryWrapper.selectAs(DocumentEntity::getCreatorTime, DocumentListVO::getCreatorTime);
  104. queryWrapper.selectAs(DocumentEntity::getFullName, DocumentListVO::getFullName);
  105. queryWrapper.selectAs(DocumentEntity::getParentId, DocumentListVO::getParentId);
  106. queryWrapper.selectAs(DocumentEntity::getShareTime, DocumentListVO::getShareTime);
  107. queryWrapper.selectAs(DocumentEntity::getFileExtension, DocumentListVO::getFileExtension);
  108. queryWrapper.selectAs(DocumentEntity::getFileSize, DocumentListVO::getFileSize);
  109. if (!isShare) {
  110. queryWrapper.and(t -> t.eq(DocumentEntity::getCreatorUserId, UserProvider.getUser().getUserId()));
  111. }
  112. queryWrapper.and(t -> t.eq(DocumentEntity::getEnabledMark, 1)
  113. .eq(DocumentEntity::getParentId, parentId));
  114. queryWrapper.orderByAsc(DocumentEntity::getType);
  115. queryWrapper.orderByAsc(DocumentEntity::getCreatorTime);
  116. return this.selectJoinList(DocumentListVO.class, queryWrapper);
  117. }
  118. @Override
  119. public List<DocumentEntity> getAllList(String parentId, String userId) {
  120. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  121. queryWrapper.lambda()
  122. .eq(DocumentEntity::getEnabledMark, 1)
  123. .eq(DocumentEntity::getParentId, parentId)
  124. .eq(DocumentEntity::getCreatorUserId, userId)
  125. .orderByAsc(DocumentEntity::getType)
  126. .orderByDesc(DocumentEntity::getCreatorTime);
  127. return this.list(queryWrapper);
  128. }
  129. @Override
  130. public List<DocumentEntity> getSearchAllList(String keyword) {
  131. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  132. if (StringUtil.isNotEmpty(keyword)) {
  133. queryWrapper.lambda().like(DocumentEntity::getFullName, keyword);
  134. queryWrapper.lambda().eq(DocumentEntity::getType, 1);
  135. }
  136. queryWrapper.lambda()
  137. .eq(DocumentEntity::getCreatorUserId, UserProvider.getUser().getUserId())
  138. .eq(DocumentEntity::getEnabledMark, 1)
  139. .orderByAsc(DocumentEntity::getType)
  140. .orderByDesc(DocumentEntity::getCreatorTime);
  141. return this.list(queryWrapper);
  142. }
  143. @Override
  144. public List<DocumentTrashListVO> getTrashList(String keyword) {
  145. MPJLambdaWrapper<DocumentLogEntity> wrapper = new MPJLambdaWrapper<>(DocumentLogEntity.class)
  146. .leftJoin(DocumentEntity.class, DocumentEntity::getId, DocumentLogEntity::getDocumentId)
  147. .select(DocumentLogEntity::getId, DocumentLogEntity::getDocumentId)
  148. .select(DocumentEntity::getFullName, DocumentEntity::getDeleteTime, DocumentEntity::getFileSize,
  149. DocumentEntity::getType, DocumentEntity::getFileExtension);
  150. if (StringUtil.isNotEmpty(keyword)) {
  151. wrapper.like(DocumentEntity::getFullName, keyword);
  152. // wrapper.eq(DocumentEntity::getType, 1);
  153. }
  154. wrapper.eq(DocumentLogEntity::getCreatorUserId, UserProvider.getUser().getUserId());
  155. wrapper.orderByAsc(DocumentEntity::getType).orderByDesc(DocumentLogEntity::getCreatorTime);
  156. List<DocumentTrashListVO> list = documentLogService.selectJoinList(DocumentTrashListVO.class, wrapper);
  157. return list;
  158. }
  159. @Override
  160. public List<DocumentEntity> getShareOutList() {
  161. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  162. queryWrapper.lambda()
  163. .eq(DocumentEntity::getCreatorUserId, UserProvider.getUser().getUserId())
  164. .eq(DocumentEntity::getEnabledMark, 1)
  165. .gt(DocumentEntity::getIsShare, 0)
  166. .orderByAsc(DocumentEntity::getType)
  167. .orderByDesc(DocumentEntity::getShareTime);
  168. return this.list(queryWrapper);
  169. }
  170. @Override
  171. public List<DocumentShareEntity> getShareTomeList() {
  172. UserInfo user = UserProvider.getUser();
  173. //获取用户角色
  174. List<String> roleIds = getRoleIds(user);
  175. //获取用户组织
  176. List<String> organizeIds = getOrganizeIds(user);
  177. //获取用户岗位
  178. List<String> permissionIds = getPermissionIds(user);
  179. //获取用户组
  180. List<String> userGroupIds = getUserGroupIds(user);
  181. roleIds.addAll(organizeIds);
  182. roleIds.addAll(permissionIds);
  183. roleIds.addAll(userGroupIds);
  184. roleIds.add(user.getUserId() + "--" + PermissionConst.USER);
  185. QueryWrapper<DocumentShareEntity> shareWrapper = new QueryWrapper<>();
  186. shareWrapper.lambda().in(DocumentShareEntity::getShareUserId, roleIds);
  187. return documentShareService.list(shareWrapper);
  188. }
  189. private List<String> getUserGroupIds(UserInfo user) {
  190. return user.getGroupIds().stream()
  191. .map(item -> item + "--" + PermissionConst.GROUP).collect(Collectors.toList());
  192. }
  193. /**
  194. * 获取用户所在岗位ids
  195. *
  196. * @param userInfo 用户信息
  197. * @return 用户岗位ids
  198. */
  199. private List<String> getPermissionIds(UserInfo userInfo) {
  200. List<PositionEntity> list = positionService.list();
  201. List<String> collect = userInfo.getPositionIds();
  202. List<String> strings = collect.stream()
  203. .flatMap(item -> Stream.of(
  204. item + "--" + SysParamEnum.POS.getCode(),
  205. item + "--" + SysParamEnum.SUBPOS.getCode(),
  206. item + "--" + SysParamEnum.PROGENYPOS.getCode()
  207. ))
  208. .collect(Collectors.toList());
  209. List<String> fatherPositionList = findFatherPositionList(collect, list);
  210. fatherPositionList.addAll(strings);
  211. return fatherPositionList.stream().distinct().collect(Collectors.toList());
  212. }
  213. /**
  214. * 获取用户所在组织ids
  215. *
  216. * @param userInfo 用户
  217. * @return 返回用户所在组织ids
  218. */
  219. private List<String> getOrganizeIds(UserInfo userInfo) {
  220. List<OrganizeEntity> list = organizeService.list();
  221. List<String> collect = userInfo.getOrganizeIds();
  222. List<String> strings = collect.stream()
  223. .map(item -> item + "--" + SysParamEnum.ORG.getCode())
  224. .collect(Collectors.toList());
  225. List<String> stringArrayList = findFatherOrganizeList(collect, list);
  226. stringArrayList.addAll(strings);
  227. return stringArrayList.stream().distinct().collect(Collectors.toList());
  228. }
  229. private List<String> findFatherOrganizeList(List<String> collect, List<OrganizeEntity> list) {
  230. List<String> stringArrayList = new ArrayList<>();
  231. List<String> grandFatherList = new ArrayList<>();
  232. for (String string : collect) {
  233. List<OrganizeEntity> collected = list.stream().filter(item -> item.getId().equals(string))
  234. .collect(Collectors.toList());
  235. if (collected.isEmpty() || "-1".equals(collected.get(0).getParentId())
  236. || StringUtil.isEmpty(collected.get(0).getParentId())) {
  237. continue;
  238. }
  239. OrganizeEntity info = collected.get(0);
  240. grandFatherList.add(info.getParentId());
  241. String faId = info.getParentId() + "--" + SysParamEnum.SUBORG.getCode();
  242. String grandFaId = info.getParentId() + "--" + SysParamEnum.PROGENYORG.getCode();
  243. stringArrayList.add(faId);
  244. stringArrayList.add(grandFaId);
  245. }
  246. for (String string : grandFatherList) {
  247. List<OrganizeEntity> collected = list.stream().filter(item -> item.getId().equals(string))
  248. .collect(Collectors.toList());
  249. if (collected.isEmpty() || "-1".equals(collected.get(0).getParentId())
  250. || StringUtil.isEmpty(collected.get(0).getParentId())) {
  251. continue;
  252. }
  253. OrganizeEntity info = collected.get(0);
  254. String gfaId = info.getParentId() + "--" + SysParamEnum.PROGENYORG.getCode();
  255. stringArrayList.add(gfaId);
  256. }
  257. return stringArrayList;
  258. }
  259. private List<String> findFatherPositionList(List<String> collect, List<PositionEntity> list) {
  260. List<String> stringArrayList = new ArrayList<>();
  261. List<String> grandFatherList = new ArrayList<>();
  262. for (String string : collect) {
  263. List<PositionEntity> collected = list.stream().filter(item -> item.getId().equals(string))
  264. .collect(Collectors.toList());
  265. if (collected.isEmpty() || "-1".equals(collected.get(0).getParentId())
  266. || StringUtil.isEmpty(collected.get(0).getParentId())) {
  267. continue;
  268. }
  269. PositionEntity info = collected.get(0);
  270. grandFatherList.add(info.getParentId());
  271. String faId = info.getParentId() + "--" + SysParamEnum.SUBPOS.getCode();
  272. String grandFaId = info.getParentId() + "--" + SysParamEnum.PROGENYPOS.getCode();
  273. stringArrayList.add(faId);
  274. stringArrayList.add(grandFaId);
  275. }
  276. for (String string : grandFatherList) {
  277. List<PositionEntity> collected = list.stream().filter(item -> item.getId().equals(string))
  278. .collect(Collectors.toList());
  279. if (collected.isEmpty() || "-1".equals(collected.get(0).getParentId())
  280. || StringUtil.isEmpty(collected.get(0).getParentId())) {
  281. continue;
  282. }
  283. PositionEntity info = collected.get(0);
  284. String gfaId = info.getParentId() + "--" + SysParamEnum.PROGENYPOS.getCode();
  285. stringArrayList.add(gfaId);
  286. }
  287. return stringArrayList;
  288. }
  289. /**
  290. * 获取用户所有角色
  291. *
  292. * @param userInfo 用户id
  293. * @return 返回用户所有角色
  294. */
  295. private List<String> getRoleIds(UserInfo userInfo) {
  296. return userInfo.getRoleIds().stream()
  297. .map(item -> item + "--" + PermissionConst.ROLE).collect(Collectors.toList());
  298. }
  299. @Override
  300. public List<DocumentEntity> getInfoByIds(List<String> ids) {
  301. if (CollectionUtils.isNotEmpty(ids)) {
  302. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  303. queryWrapper.lambda().in(DocumentEntity::getId, ids);
  304. queryWrapper.lambda().eq(DocumentEntity::getEnabledMark, 1);
  305. queryWrapper.lambda().orderByAsc(DocumentEntity::getType)
  306. .orderByDesc(DocumentEntity::getCreatorTime);
  307. return this.list(queryWrapper);
  308. }
  309. return new ArrayList<>();
  310. }
  311. @Override
  312. public List<DocumentShareEntity> getShareUserList(String documentId) {
  313. QueryWrapper<DocumentShareEntity> queryWrapper = new QueryWrapper<>();
  314. queryWrapper.lambda().eq(DocumentShareEntity::getDocumentId, documentId);
  315. return documentShareService.list(queryWrapper);
  316. }
  317. @Override
  318. public DocumentEntity getInfo(String id) {
  319. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  320. queryWrapper.lambda().eq(DocumentEntity::getId, id);
  321. return this.getOne(queryWrapper);
  322. }
  323. @Override
  324. public void delete(DocumentEntity entity) {
  325. entity.setDeleteTime(new Date());
  326. entity.setDeleteUserId(UserProvider.getUser().getUserId());
  327. entity.setEnabledMark(0);
  328. this.updateById(entity);
  329. }
  330. @Override
  331. public void create(DocumentEntity entity) {
  332. entity.setId(RandomUtil.uuId());
  333. if (StringUtil.isBlank(entity.getCreatorUserId())) {
  334. entity.setCreatorUserId(UserProvider.getUser().getUserId());
  335. }
  336. entity.setEnabledMark(1);
  337. this.save(entity);
  338. }
  339. @Override
  340. public boolean update(String id, DocumentEntity entity) {
  341. entity.setId(id);
  342. entity.setLastModifyTime(new Date());
  343. entity.setLastModifyUserId(UserProvider.getUser().getUserId());
  344. return this.updateById(entity);
  345. }
  346. @Override
  347. @Transactional
  348. public void sharecreate(DocumentShareForm documentShareForm) {
  349. List<String> ids = documentShareForm.getIds();
  350. List<String> userIds = documentShareForm.getUserIds();
  351. String creatorUserId = documentShareForm.getCreatorUserId();
  352. if (CollectionUtils.isEmpty(ids) || CollectionUtils.isEmpty(userIds)) {
  353. return;
  354. }
  355. for (String docId : ids) {
  356. DocumentEntity entity = this.getInfo(docId);
  357. if (entity != null) {
  358. //共享当前文件或者文件夹(文件夹内部文件可以直接查询)
  359. int n = (entity.getIsShare() == null ? 0 : entity.getIsShare()) + userIds.size();
  360. entity.setIsShare(n);
  361. entity.setShareTime(new Date());
  362. this.updateById(entity);
  363. for (String userId : userIds) {
  364. DocumentShareEntity one = documentShareService.getByDocIdAndShareUserId(docId, userId);
  365. if (one != null) {
  366. one.setShareTime(new Date());
  367. documentShareService.updateById(one);
  368. continue;
  369. }
  370. DocumentShareEntity documentShare = new DocumentShareEntity();
  371. documentShare.setId(RandomUtil.uuId());
  372. documentShare.setDocumentId(docId);
  373. documentShare.setShareUserId(userId);
  374. documentShare.setShareTime(new Date());
  375. documentShare.setCreatorUserId(creatorUserId);
  376. documentShareService.save(documentShare);
  377. }
  378. }
  379. }
  380. }
  381. @Override
  382. @Transactional
  383. public void shareCancel(List<String> documentIds) {
  384. for (String documentId : documentIds) {
  385. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  386. queryWrapper.lambda().eq(DocumentEntity::getId, documentId);
  387. DocumentEntity entity = this.getOne(queryWrapper);
  388. if (entity != null) {
  389. entity.setIsShare(0);
  390. entity.setShareTime(new Date());
  391. this.updateById(entity);
  392. QueryWrapper<DocumentShareEntity> wrapper = new QueryWrapper<>();
  393. wrapper.lambda().eq(DocumentShareEntity::getDocumentId, documentId);
  394. documentShareService.remove(wrapper);
  395. }
  396. }
  397. }
  398. @Override
  399. @Transactional
  400. public void shareAdjustment(String id, List<String> userIds) {
  401. DocumentEntity entity = this.getInfo(id);
  402. if (entity != null) {
  403. entity.setIsShare(userIds.size());
  404. entity.setShareTime(new Date());
  405. this.updateById(entity);
  406. QueryWrapper<DocumentShareEntity> wrapper = new QueryWrapper<>();
  407. wrapper.lambda().eq(DocumentShareEntity::getDocumentId, entity.getId());
  408. documentShareService.remove(wrapper);
  409. for (String userId : userIds) {
  410. DocumentShareEntity documentShare = new DocumentShareEntity();
  411. documentShare.setId(RandomUtil.uuId());
  412. documentShare.setDocumentId(id);
  413. documentShare.setShareUserId(userId);
  414. documentShare.setShareTime(new Date());
  415. documentShareService.save(documentShare);
  416. }
  417. }
  418. }
  419. @Override
  420. @Transactional
  421. public void trashdelete(List<String> folderIds) {
  422. List<String> pathList = new ArrayList<>();
  423. for (String logId : folderIds) {
  424. DocumentLogEntity logEntity = documentLogService.getById(logId);
  425. DocumentEntity entity = this.getInfo(logEntity.getDocumentId());
  426. if (entity != null) {
  427. if (Objects.equals(entity.getType(), 0)) {
  428. String childDocument = logEntity.getChildDocument();
  429. String[] allFile = childDocument.split(",");
  430. for (String item : allFile) {
  431. this.removeById(item);
  432. }
  433. } else {
  434. this.removeById(logEntity.getDocumentId());
  435. }
  436. pathList.add(configValueUtil.getDocumentFilePath() + entity.getFilePath());
  437. }
  438. documentLogService.removeById(logEntity);
  439. }
  440. //先移除数据再移除文件,以便回滚(移除文件夹里面的文件也会删除所以不用递归)
  441. for (String path : pathList) {
  442. FileUtil.deleteFile(path);
  443. }
  444. }
  445. @Override
  446. @Transactional
  447. public void trashRecoveryConstainSrc(List<String> ids) {
  448. for (String logId : ids) {
  449. DocumentLogEntity logEntity = documentLogService.getById(logId);
  450. if (logEntity == null) {
  451. continue;
  452. }
  453. DocumentEntity entity = this.getInfo(logEntity.getDocumentId());
  454. if (entity != null) {
  455. if (!"0".equals(entity.getParentId())) {
  456. //查询父级菜单是否存在,如果存在还原到原菜单里,如果不存在则放在最外层
  457. DocumentEntity parentInfo = this.getInfo(entity.getParentId());
  458. if (parentInfo == null || Objects.equals(parentInfo.getEnabledMark(), 0)) {
  459. this.trashRecovery(entity.getId(), true);
  460. } else {
  461. this.trashRecovery(entity.getId(), false);
  462. }
  463. } else {
  464. this.trashRecovery(entity.getId(), false);
  465. }
  466. String childDocument = logEntity.getChildDocument();
  467. List<String> childList = Arrays.asList(childDocument.split(",")).stream().filter(t -> !t.equals(entity.getId())).collect(Collectors.toList());
  468. //还原文件夹内的所有文件。
  469. for (String item : childList) {
  470. this.trashRecovery(item, false);
  471. }
  472. }
  473. documentLogService.removeById(logEntity);
  474. }
  475. }
  476. @Override
  477. public boolean trashRecovery(String id, boolean initParent) {
  478. UpdateWrapper<DocumentEntity> updateWrapper = new UpdateWrapper<>();
  479. if (initParent) {
  480. updateWrapper.lambda().set(DocumentEntity::getParentId, "0");
  481. }
  482. updateWrapper.lambda().set(DocumentEntity::getEnabledMark, 1);
  483. updateWrapper.lambda().set(DocumentEntity::getDeleteTime, null);
  484. updateWrapper.lambda().set(DocumentEntity::getDeleteUserId, null);
  485. updateWrapper.lambda().eq(DocumentEntity::getId, id);
  486. return this.update(updateWrapper);
  487. }
  488. @Override
  489. public boolean moveTo(String id, String toId) {
  490. DocumentEntity entity = this.getInfo(id);
  491. if (entity != null) {
  492. entity.setParentId(toId);
  493. this.updateById(entity);
  494. return true;
  495. }
  496. return false;
  497. }
  498. @Override
  499. public boolean isExistByFullName(String fullName, String id, String parentId) {
  500. String userId = UserProvider.getUser().getUserId();
  501. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  502. queryWrapper.lambda().eq(DocumentEntity::getFullName, fullName).eq(DocumentEntity::getEnabledMark, 1).eq(DocumentEntity::getCreatorUserId, userId);
  503. queryWrapper.lambda().eq(DocumentEntity::getParentId, parentId);
  504. if (!StringUtil.isEmpty(id)) {
  505. queryWrapper.lambda().ne(DocumentEntity::getId, id);
  506. }
  507. return this.count(queryWrapper) > 0;
  508. }
  509. @Override
  510. public void getChildSrcList(String pId, List<DocumentEntity> list, Integer enabledMark) {
  511. QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
  512. if (enabledMark != null) {
  513. queryWrapper.lambda().eq(DocumentEntity::getEnabledMark, enabledMark);
  514. }
  515. queryWrapper.lambda()
  516. .eq(DocumentEntity::getParentId, pId)
  517. .orderByAsc(DocumentEntity::getType)
  518. .orderByDesc(DocumentEntity::getCreatorTime);
  519. List<DocumentEntity> allList = this.list(queryWrapper);
  520. if (CollectionUtils.isNotEmpty(allList)) {
  521. list.addAll(allList);
  522. for (DocumentEntity doc : allList) {
  523. this.getChildSrcList(doc.getId(), list, enabledMark);
  524. }
  525. }
  526. }
  527. @Override
  528. public DocumentShareEntity getShareByParentId(String parentId) {
  529. List<DocumentShareEntity> shareTomeList = this.getShareTomeList();
  530. return this.getDocByParentId(parentId, shareTomeList);
  531. }
  532. public DocumentShareEntity getDocByParentId(String parentId, List<DocumentShareEntity> shareTomeList) {
  533. List<DocumentShareEntity> collect = shareTomeList.stream().filter(t -> t.getDocumentId().equals(parentId))
  534. .collect(Collectors.toList());
  535. if (CollectionUtils.isNotEmpty(collect)) {
  536. return collect.get(0);
  537. }
  538. DocumentEntity info = this.getInfo(parentId);
  539. return getDocByParentId(info.getParentId(), shareTomeList);
  540. }
  541. @Override
  542. public List<Map<String, Object>> getFlowFile(FlowFileModel model) {
  543. String userId = model.getUserId();
  544. String templateId = model.getTemplateId();
  545. QueryWrapper<DocumentShareEntity> shareWrapper = new QueryWrapper<>();
  546. shareWrapper.lambda().like(DocumentShareEntity::getShareUserId, userId);
  547. List<DocumentShareEntity> shareList = documentShareService.list(shareWrapper);
  548. List<String> docIds = new ArrayList<>();
  549. if (CollectionUtil.isNotEmpty(shareList)) {
  550. docIds = shareList.stream().map(DocumentShareEntity::getDocumentId).collect(Collectors.toList());
  551. }
  552. QueryWrapper<DocumentEntity> wrapper = new QueryWrapper<>();
  553. wrapper.lambda().eq(DocumentEntity::getEnabledMark, 1).like(DocumentEntity::getDescription, templateId);
  554. List<String> finalDocIds = docIds;
  555. wrapper.lambda().and(t -> {
  556. t.eq(DocumentEntity::getCreatorUserId, userId);
  557. if (!finalDocIds.isEmpty()) {
  558. t.or(e -> e.in(DocumentEntity::getId, finalDocIds));
  559. }
  560. });
  561. wrapper.lambda().orderByDesc(DocumentEntity::getCreatorTime);
  562. Page<DocumentEntity> page = this.page(new Page<>(1, 5), wrapper);
  563. List<DocumentEntity> documentList = page.getRecords();
  564. List<Map<String, Object>> list = new ArrayList<>();
  565. if (!documentList.isEmpty()) {
  566. for (DocumentEntity document : documentList) {
  567. Map<String, Object> map = new HashMap<>();
  568. map.put("id", document.getId());
  569. map.put("fileName", document.getFullName());
  570. map.put("fileDate", document.getCreatorTime());
  571. map.put("uploaderUrl", document.getUploaderUrl());
  572. list.add(map);
  573. }
  574. }
  575. return list;
  576. }
  577. }