DocServiceImpl.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. package com.ads.business.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import com.ads.business.dao.DocDao;
  6. import com.ads.business.dao.DocRoleDao;
  7. import com.ads.business.dao.TypeRoleDao;
  8. import com.ads.business.entity.*;
  9. import com.ads.business.service.*;
  10. import com.ads.business.service.data.GetLoginOutData;
  11. import com.ads.business.service.model.request.DocListRequest;
  12. import com.ads.business.service.model.request.DocRequest;
  13. import com.ads.business.service.model.response.CheckAuthResponse;
  14. import com.ads.business.service.model.response.DocListResponse;
  15. import com.ads.business.service.model.response.DocResponse;
  16. import com.ads.business.service.model.response.PdfDetailResponse;
  17. import com.ads.common.data.GetPictureConfigInData;
  18. import com.ads.common.data.JsonResult;
  19. import com.ads.common.data.PageInfo;
  20. import com.ads.common.exception.BusinessException;
  21. import com.ads.common.util.OnlineUserUtils;
  22. import com.ads.common.util.PageUtils;
  23. import com.ads.common.util.PdfUtil;
  24. import com.ads.common.util.UtilMessage;
  25. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  26. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  27. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  28. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  29. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  30. import lombok.extern.slf4j.Slf4j;
  31. import org.apache.commons.lang3.StringUtils;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.beans.factory.annotation.Value;
  34. import org.springframework.stereotype.Service;
  35. import org.springframework.transaction.annotation.Transactional;
  36. import javax.annotation.Resource;
  37. import javax.servlet.http.HttpServletRequest;
  38. import java.io.BufferedOutputStream;
  39. import java.io.File;
  40. import java.io.FileNotFoundException;
  41. import java.io.FileOutputStream;
  42. import java.util.ArrayList;
  43. import java.util.Date;
  44. import java.util.List;
  45. import java.util.Map;
  46. import java.util.stream.Collectors;
  47. /**
  48. * <p>
  49. * 服务实现类
  50. * </p>
  51. *
  52. * @author hou
  53. * @since 2021-10-21
  54. */
  55. @Slf4j
  56. @Service
  57. public class DocServiceImpl extends ServiceImpl<DocDao, Doc> implements DocService {
  58. @Resource
  59. private DocTypeService docTypeService;
  60. @Value("${doc.linkUrl}")
  61. private String linkUrl;
  62. @Resource
  63. private DocHistoryService docHistoryService;
  64. @Resource
  65. private TypeRoleService typeRoleService;
  66. @Autowired
  67. private GetPictureConfigInData pictureConfig;
  68. @Resource
  69. private DocRoleService docRoleService;
  70. @Resource
  71. private DocRoleDao docRoleDao;
  72. @Resource
  73. private DocConversationRelService docConversationRelService;
  74. @Resource
  75. private ConversationUserRelService conversationUserRelService;
  76. @Resource
  77. private DocTypeConversationRelService docTypeConversationRelService;
  78. @Resource
  79. private ConversationService conversationService;
  80. @Resource
  81. private TypeRoleDao typeRoleDao;
  82. @Override
  83. @Transactional(rollbackFor = Exception.class)
  84. public String addDoc(DocRequest inData) {
  85. String message = checkBean(inData, false);
  86. if (StringUtils.isNotEmpty(message)) {
  87. return message;
  88. }
  89. int count = this.count(new LambdaQueryWrapper<Doc>()
  90. .eq(Doc::getTypeId, inData.getTypeId())
  91. .eq(Doc::getName, inData.getName()));
  92. if (count > 0) {
  93. throw new BusinessException("同一分类下,文件名称已存在!");
  94. }
  95. Doc doc = new Doc();
  96. BeanUtil.copyProperties(inData, doc);
  97. GetLoginOutData userInfo = OnlineUserUtils.get();
  98. if (null != userInfo) {
  99. doc.setCreateUser(Long.valueOf(userInfo.getUserId()));
  100. }
  101. doc.setCreateTime(new Date());
  102. doc.setUpdateTime(new Date());
  103. this.baseMapper.insert(doc);
  104. ArrayList<DocRole> docRoles = new ArrayList<>();
  105. if (CollectionUtil.isNotEmpty(inData.getRole())) {
  106. inData.getRole().stream().distinct().forEach(e -> {
  107. DocRole docRole = new DocRole();
  108. docRole.setDocId(doc.getId());
  109. docRole.setMobile(e);
  110. docRoles.add(docRole);
  111. });
  112. docRoleDao.insertBatch(docRoles);
  113. }
  114. Doc updoc = new Doc();
  115. updoc.setId(doc.getId());
  116. updoc.setLinkUrl(linkUrl + doc.getId() + "&showmenu=false");
  117. this.updateById(updoc);
  118. DocHistory docHistory = new DocHistory();
  119. BeanUtil.copyProperties(doc, docHistory);
  120. docHistory.setId(null);
  121. docHistory.setDocId(doc.getId());
  122. docHistoryService.save(docHistory);
  123. //新增文件会话关系
  124. if (CollectionUtil.isNotEmpty(inData.getConversationList())) {
  125. List<DocConversationRel> list = new ArrayList<>();
  126. inData.getConversationList().stream().forEach(conversationRequest -> {
  127. DocConversationRel docConversationRel = new DocConversationRel();
  128. docConversationRel.setDocId(doc.getId());
  129. docConversationRel.setChatId(conversationRequest.getChatId());
  130. docConversationRel.setOpenConversationId(conversationRequest.getOpenConversationId());
  131. list.add(docConversationRel);
  132. });
  133. docConversationRelService.saveBatch(list);
  134. }
  135. return null;
  136. }
  137. @Override
  138. @Transactional(rollbackFor = Exception.class)
  139. public String updateDoc(DocRequest inData) {
  140. String message = checkBean(inData, true);
  141. if (StringUtils.isNotEmpty(message)) {
  142. return message;
  143. }
  144. Doc doc = this.baseMapper.selectById(Long.valueOf(inData.getId()));
  145. Boolean flag = false;
  146. if (!inData.getDocUrl().equals(doc.getDocUrl())) {
  147. flag = true;
  148. }
  149. int count = this.count(new LambdaQueryWrapper<Doc>()
  150. .eq(Doc::getTypeId, inData.getTypeId())
  151. .eq(Doc::getName, inData.getName())
  152. .notIn(Doc::getId, inData.getId()));
  153. if (count > 0) {
  154. throw new BusinessException("同一分类下,文件名称已存在!");
  155. }
  156. BeanUtil.copyProperties(inData, doc);
  157. doc.setId(Long.valueOf(inData.getId()));
  158. GetLoginOutData userInfo = OnlineUserUtils.get();
  159. if (null != userInfo) {
  160. doc.setUpdateUser(Long.valueOf(userInfo.getUserId()));
  161. }
  162. doc.setUpdateTime(new Date());
  163. this.baseMapper.updateById(doc);
  164. docRoleService.remove(Wrappers.lambdaQuery(DocRole.class).eq(DocRole::getDocId, doc.getId()));
  165. if (CollectionUtil.isNotEmpty(inData.getRole())) {
  166. ArrayList<DocRole> docRoles = new ArrayList<>();
  167. inData.getRole().stream().distinct().forEach(e -> {
  168. DocRole docRole = new DocRole();
  169. docRole.setDocId(doc.getId());
  170. docRole.setMobile(e);
  171. docRoles.add(docRole);
  172. });
  173. docRoleDao.insertBatch(docRoles);
  174. }
  175. if (flag) {
  176. DocHistory docHistory = new DocHistory();
  177. BeanUtil.copyProperties(doc, docHistory);
  178. docHistory.setCreateTime(new Date());
  179. docHistory.setCreateUser(Long.valueOf(userInfo.getUserId()));
  180. docHistory.setDocId(doc.getId());
  181. docHistory.setId(null);
  182. docHistoryService.save(docHistory);
  183. }
  184. //根据文件ID删除
  185. docConversationRelService.remove(new LambdaQueryWrapper<DocConversationRel>()
  186. .eq(DocConversationRel::getDocId, inData.getId()));
  187. //新增文件会话关系
  188. if (CollectionUtil.isNotEmpty(inData.getConversationList())) {
  189. //新增
  190. List<DocConversationRel> list = new ArrayList<>();
  191. inData.getConversationList().stream().forEach(conversationRequest -> {
  192. DocConversationRel docConversationRel = new DocConversationRel();
  193. docConversationRel.setDocId(doc.getId());
  194. docConversationRel.setChatId(conversationRequest.getChatId());
  195. docConversationRel.setOpenConversationId(conversationRequest.getOpenConversationId());
  196. list.add(docConversationRel);
  197. });
  198. docConversationRelService.saveBatch(list);
  199. }
  200. return null;
  201. }
  202. @Override
  203. public DocResponse detail(Long docId) {
  204. DocResponse outData = new DocResponse();
  205. Doc doc = this.baseMapper.selectById(docId);
  206. if (null != doc) {
  207. BeanUtil.copyProperties(doc, outData);
  208. outData.setFileName(doc.getDocUrl().substring(doc.getDocUrl().lastIndexOf("/") + 1));
  209. }
  210. List<DocRole> list = docRoleService.list(Wrappers.lambdaQuery(DocRole.class).eq(DocRole::getDocId, doc.getId()));
  211. if (CollectionUtil.isNotEmpty(list)) {
  212. List<String> roles = list.stream().map(DocRole::getMobile).collect(Collectors.toList());
  213. outData.setRole(roles);
  214. }
  215. List<DocConversationRel> docRels = docConversationRelService.list(new LambdaQueryWrapper<DocConversationRel>().eq(DocConversationRel::getDocId, docId));
  216. if (CollectionUtil.isNotEmpty(docRels)) {
  217. outData.setConversationList(docRels);
  218. }
  219. return outData;
  220. }
  221. @Override
  222. public JsonResult pdfDetail(HttpServletRequest request, Long docId, String userNo) {
  223. GetLoginOutData userInfo = OnlineUserUtils.get();
  224. if (null == userInfo) {
  225. return JsonResult.fail("您没有登录");
  226. }
  227. if (StringUtils.isEmpty(userInfo.getMobile())) {
  228. return JsonResult.fail(1000, "请重新登录");
  229. }
  230. //水印 姓名+手机号后四位
  231. String watermark = userInfo.getName() + userInfo.getMobile().substring(userInfo.getMobile().length() - 5);
  232. Doc doc = this.baseMapper.selectById(docId);
  233. if (null == doc) {
  234. throw new BusinessException("当前文件信息不存在!");
  235. }
  236. if (doc.getStatus() == 0) {
  237. return JsonResult.fail(1000, "当前文件已禁用,请启用后查看!");
  238. }
  239. DocType docType = docTypeService.getById(doc.getTypeId());
  240. if (ObjectUtil.isEmpty(docType)) {
  241. return JsonResult.fail("当前文件说在分类信息不存在");
  242. }
  243. if (docType.getStatus() == 0) {
  244. return JsonResult.fail(1000, "当前文件所在分类已禁用,请启用后查看!");
  245. }
  246. //userInfo.setMobile("18896995753");
  247. //userInfo.setMobile("15261532462");
  248. if (StringUtils.isEmpty(userInfo.getMobile())) {
  249. return JsonResult.fail(1000, "请退出重新登录钉钉");
  250. }
  251. log.info("获取文件详情信息--校验会话权限");
  252. List<DocTypeConversationRel> typeList = docTypeConversationRelService.list(new LambdaQueryWrapper<DocTypeConversationRel>()
  253. .eq(DocTypeConversationRel::getTypeId, docType.getTypeId()));
  254. List<String> typeRoleMobiles = typeRoleDao.getListByTypeId(Long.valueOf(docType.getTypeId()));
  255. //手机号不为空,群组为空
  256. if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
  257. if (!typeRoleMobiles.contains(userInfo.getMobile())) {
  258. return JsonResult.fail(1000, "您没有当前文件的查看权限");
  259. }
  260. Boolean res = checkAuthDetail(userInfo, doc);
  261. if (res) {
  262. return JsonResult.fail(1000, "您没有当前文件的查看权限");
  263. }
  264. }
  265. //手机号不为空,群组不为空
  266. if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
  267. List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
  268. conversationMobiles.addAll(typeRoleMobiles);
  269. if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
  270. return JsonResult.fail(1000, "您没有当前文件的查看权限");
  271. }
  272. Boolean res = checkAuthDetail(userInfo, doc);
  273. if (res) {
  274. return JsonResult.fail(1000, "您没有当前文件的查看权限");
  275. }
  276. }
  277. //手机号为空,群组不为空
  278. if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
  279. List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
  280. if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
  281. return JsonResult.fail(1000, "您没有当前文件的查看权限");
  282. }
  283. Boolean res = checkAuthDetail(userInfo, doc);
  284. if (res) {
  285. return JsonResult.fail(1000, "您没有当前文件的查看权限");
  286. }
  287. }
  288. //手机号为空,群组为空
  289. if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
  290. Boolean res = checkAuthDetail(userInfo, doc);
  291. if (res) {
  292. return JsonResult.fail(1000, "您没有当前文件的查看权限");
  293. }
  294. }
  295. log.info("校验权限结束!");
  296. String fileName = doc.getName();
  297. String docUrl = doc.getDocUrl();
  298. String path = request.getScheme() + "://" + request.getServerName() + ":" + "19050" + request.getContextPath() + "/";
  299. String filePath = pictureConfig.getServerBasePath() + "/" + pictureConfig.getUploadPath() + "/" + userNo + "/" + docId + fileName + ".pdf";
  300. String createPath = pictureConfig.getBasePath() + "/" + pictureConfig.getUploadPath() + "/" + userNo + "/" + docId + fileName + ".pdf";
  301. File fromFile = new File(createPath);
  302. //判断目标文件所在的目录是否存在
  303. if (!fromFile.getParentFile().exists()) {
  304. //如果目标文件所在的目录不存在,则创建父目录
  305. fromFile.getParentFile().mkdirs();
  306. }
  307. if (fromFile.exists()) {
  308. fromFile.delete();
  309. }
  310. try {
  311. PdfUtil.setWatermark(new BufferedOutputStream(new FileOutputStream(new File(createPath))), docUrl, watermark);
  312. } catch (FileNotFoundException e) {
  313. e.printStackTrace();
  314. throw new BusinessException("生成pdf文件水印有异常!");
  315. }
  316. log.info("pdfDetail--文件路径:{}", path + filePath);
  317. PdfDetailResponse rs = new PdfDetailResponse();
  318. rs.setPath(path + filePath);
  319. rs.setFileName(fileName);
  320. return JsonResult.success(rs, UtilMessage.GET_MESSAGE_SUCCESS);
  321. }
  322. @Transactional(rollbackFor = Exception.class)
  323. @Override
  324. public JsonResult updateSwitch(Long id, Integer status) {
  325. Doc docdb = this.getById(id);
  326. if (ObjectUtil.isEmpty(docdb)) {
  327. throw new BusinessException(UtilMessage.DATA_EMPTY);
  328. }
  329. if (docdb.getStatus().equals(status) && status == 1) {
  330. throw new BusinessException("文件分类已启用,请勿重复操作!");
  331. }
  332. if (docdb.getStatus().equals(status) && status == 0) {
  333. throw new BusinessException("文件分类已禁用,请勿重复操作!");
  334. }
  335. Doc doc = new Doc();
  336. doc.setId(id);
  337. doc.setStatus(status);
  338. this.updateById(doc);
  339. String msg;
  340. if (status == 1) {
  341. msg = UtilMessage.ENABLE_MESSAGE_SUCCESS;
  342. } else {
  343. msg = UtilMessage.DISABLE_MESSAGE_SUCCESS;
  344. }
  345. return JsonResult.success(null, msg);
  346. }
  347. /**
  348. * 获取文件列表信息
  349. *
  350. * @param request 列表查询参数信息
  351. * @param type 1 移动端
  352. * @return 文件参数结果信息
  353. */
  354. @Override
  355. public JsonResult docList(DocListRequest request, Integer type) {
  356. if (null == request) {
  357. return JsonResult.fail("请输入文件分类信息");
  358. }
  359. if (type == 1) {
  360. DocType docType = docTypeService.getById(request.getTypeId());
  361. if (ObjectUtil.isEmpty(docType)) {
  362. return JsonResult.fail("文件分类信息不存在");
  363. }
  364. if (docType.getStatus() == 0) {
  365. return JsonResult.fail(1000, "当前文件分类已禁用,请启用后查看!");
  366. }
  367. if (StringUtils.isEmpty(request.getTypeId())) {
  368. return JsonResult.fail("请输入文件分类信息");
  369. }
  370. GetLoginOutData userInfo = OnlineUserUtils.get();
  371. if (null == userInfo) {
  372. return JsonResult.fail("您没有登录");
  373. }
  374. //userInfo.setMobile("18896995753");
  375. //userInfo.setMobile("15261532462");
  376. if (StringUtils.isEmpty(userInfo.getMobile())) {
  377. return JsonResult.fail(1000, "请退出重新登录钉钉");
  378. }
  379. List<Doc> docList = this.list(new LambdaQueryWrapper<Doc>().eq(Doc::getTypeId, request.getTypeId()).eq(Doc::getStatus, 1));
  380. log.info("获取文件列表信息--校验会话分类权限");
  381. List<DocTypeConversationRel> typeList = docTypeConversationRelService.list(new LambdaQueryWrapper<DocTypeConversationRel>()
  382. .eq(DocTypeConversationRel::getTypeId, request.getTypeId()));
  383. List<String> typeRoleMobiles = typeRoleDao.getListByTypeId(Long.valueOf(request.getTypeId()));
  384. //手机号不为空,群组为空
  385. if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
  386. if (!typeRoleMobiles.contains(userInfo.getMobile())) {
  387. return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
  388. }
  389. List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
  390. if (CollectionUtil.isEmpty(newList)) {
  391. return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
  392. } else {
  393. return JsonResult.success(new PageInfo<>(newList), UtilMessage.GET_MESSAGE_SUCCESS);
  394. }
  395. }
  396. //手机号不为空,群组不为空
  397. if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
  398. List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
  399. conversationMobiles.addAll(typeRoleMobiles);
  400. if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
  401. return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
  402. }
  403. List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
  404. if (CollectionUtil.isEmpty(newList)) {
  405. return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
  406. } else {
  407. return JsonResult.success(new PageUtils(newList, newList.size(), request.getPageSize(), request.getPage())
  408. , UtilMessage.GET_MESSAGE_SUCCESS);
  409. }
  410. }
  411. //手机号为空,群组不为空
  412. if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
  413. List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
  414. if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
  415. return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
  416. }
  417. List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
  418. if (CollectionUtil.isEmpty(newList)) {
  419. return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
  420. } else {
  421. return JsonResult.success(new PageUtils(newList, newList.size(), request.getPageSize(), request.getPage())
  422. , UtilMessage.GET_MESSAGE_SUCCESS);
  423. }
  424. }
  425. //手机号为空,群组为空
  426. if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
  427. List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
  428. if (CollectionUtil.isEmpty(newList)) {
  429. return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
  430. } else {
  431. return JsonResult.success(new PageUtils(newList, newList.size(), request.getPageSize(), request.getPage())
  432. , UtilMessage.GET_MESSAGE_SUCCESS);
  433. }
  434. }
  435. return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
  436. } else {
  437. Long currPage = request.getPage() == null ? 1 : request.getPage().longValue();
  438. Long pageSize = request.getPageSize() == null ? 10 : request.getPageSize().longValue();
  439. Page<DocListResponse> page = new Page<>(currPage, pageSize);
  440. QueryWrapper<DocListResponse> wrapper = new QueryWrapper();
  441. if (StringUtils.isNotBlank(request.getTypeId())) {
  442. wrapper.eq("hdt.type_id", Long.valueOf(request.getTypeId()));
  443. }
  444. if (StringUtils.isNotBlank(request.getName())) {
  445. wrapper.like("hd.name", request.getName());
  446. }
  447. Integer status;
  448. if (type == 1) {
  449. status = type;
  450. } else {
  451. status = request.getStatus();
  452. }
  453. if (null != status) {
  454. wrapper.eq("hd.status", status);
  455. }
  456. wrapper.orderByDesc("hd.create_time");
  457. if (type == 1) {
  458. List<DocListResponse> list = this.baseMapper.findList(wrapper);
  459. if (CollectionUtil.isEmpty(list)) {
  460. return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
  461. }
  462. String mobile = OnlineUserUtils.get().getMobile();
  463. log.info("获取文件列表信息----mobile={}", mobile);
  464. List<String> docIds = list.stream().map(DocListResponse::getId).collect(Collectors.toList());
  465. List<DocRole> docRoles = docRoleDao.selectList(Wrappers.lambdaQuery(DocRole.class).in(DocRole::getDocId, docIds));
  466. Map<Long, List<DocRole>> docRoleMap = docRoles.stream().collect(Collectors.groupingBy(DocRole::getDocId));
  467. List<DocListResponse> responses = new ArrayList<>();
  468. list.forEach(e -> {
  469. List<DocRole> roleList = docRoleMap.get(Long.valueOf(e.getId()));
  470. if (CollectionUtil.isEmpty(roleList)) {
  471. responses.add(e);
  472. } else {
  473. List<String> mobiles = roleList.stream().map(DocRole::getMobile).collect(Collectors.toList());
  474. if (mobiles.contains(OnlineUserUtils.get().getMobile())) {
  475. responses.add(e);
  476. }
  477. }
  478. });
  479. return JsonResult.success(new PageUtils(new Page<DocListResponse>(1, responses.size()
  480. , responses.size()).setRecords(responses)), UtilMessage.GET_MESSAGE_SUCCESS);
  481. } else {
  482. return JsonResult.success(new PageUtils(this.baseMapper.findPage(page, wrapper)), UtilMessage.GET_MESSAGE_SUCCESS);
  483. }
  484. }
  485. }
  486. private List<CheckAuthResponse> checkAuth(GetLoginOutData userInfo, List<Doc> docList) {
  487. List<CheckAuthResponse> newList = new ArrayList<>();
  488. //校验分类下手机号
  489. if (CollectionUtil.isNotEmpty(docList)) {
  490. for (Doc doc : docList) {
  491. //群组
  492. List<DocConversationRel> docConversationRels = docConversationRelService.list(new LambdaQueryWrapper<DocConversationRel>()
  493. .eq(DocConversationRel::getDocId, doc.getId()));
  494. //权限手机号
  495. List<String> docRoleMobiles = docRoleDao.getMobileList(doc.getId());
  496. //手机号不为空,群组为空
  497. if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isEmpty(docConversationRels)) {
  498. if (!docRoleMobiles.contains(userInfo.getMobile())) {
  499. if (docList.size() == 1) {
  500. return newList;
  501. }
  502. continue;
  503. }
  504. }
  505. //手机号不为空,群组不为空
  506. if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
  507. //群组内所有人手机号
  508. List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId());
  509. docRoleMobiles.addAll(docConversationMobiles);
  510. if (!docRoleMobiles.contains(userInfo.getMobile())) {
  511. if (docList.size() == 1) {
  512. return newList;
  513. }
  514. continue;
  515. }
  516. }
  517. //手机号为空,群组不为空
  518. if (CollectionUtil.isEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
  519. //群组内所有人手机号
  520. List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId());
  521. if (!docConversationMobiles.contains(userInfo.getMobile())) {
  522. if (docList.size() == 1) {
  523. return newList;
  524. }
  525. continue;
  526. }
  527. }
  528. CheckAuthResponse rs = new CheckAuthResponse();
  529. rs.setId(doc.getId().toString());
  530. rs.setTypeId(doc.getTypeId().toString());
  531. rs.setFileSize(doc.getFileSize());
  532. rs.setName(doc.getName());
  533. //手机号为空,群组为空 根据分类权限
  534. newList.add(rs);
  535. }
  536. }
  537. return newList;
  538. }
  539. private boolean checkAuthDetail(GetLoginOutData userInfo, Doc doc) {
  540. //校验分类下手机号
  541. //群组
  542. List<DocConversationRel> docConversationRels = docConversationRelService.list(new LambdaQueryWrapper<DocConversationRel>()
  543. .eq(DocConversationRel::getDocId, doc.getId()));
  544. //权限手机号
  545. List<String> docRoleMobiles = docRoleDao.getMobileList(doc.getId());
  546. //手机号不为空,群组为空
  547. if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isEmpty(docConversationRels)) {
  548. if (!docRoleMobiles.contains(userInfo.getMobile())) {
  549. return true;
  550. }
  551. }
  552. //手机号不为空,群组不为空
  553. if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
  554. //群组内所有人手机号
  555. List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId());
  556. docRoleMobiles.addAll(docConversationMobiles);
  557. if (!docRoleMobiles.contains(userInfo.getMobile())) {
  558. return true;
  559. }
  560. }
  561. //手机号为空,群组不为空
  562. if (CollectionUtil.isEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
  563. //群组内所有人手机号
  564. List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId());
  565. if (!docConversationMobiles.contains(userInfo.getMobile())) {
  566. return true;
  567. }
  568. }
  569. CheckAuthResponse rs = new CheckAuthResponse();
  570. rs.setId(doc.getId().toString());
  571. rs.setTypeId(doc.getTypeId().toString());
  572. rs.setFileSize(doc.getFileSize());
  573. rs.setName(doc.getName());
  574. //手机号为空,群组为空 根据分类权限
  575. return false;
  576. }
  577. /**
  578. * 验证实体的必填项是否已经填写
  579. *
  580. * @param inData 实体参数
  581. * @return message 验证结果集
  582. */
  583. private String checkBean(DocRequest inData, Boolean mark) {
  584. String message = "";
  585. if (mark && null == inData.getId()) {
  586. message = "编辑文件时,Id不能为空!";
  587. }
  588. if (null == inData.getTypeId()) {
  589. message = "文件分类不能为空!";
  590. }
  591. if (StringUtils.isEmpty(inData.getName())) {
  592. message = "文件名称不能为空!";
  593. }
  594. if (StringUtils.isEmpty(inData.getFileSize())) {
  595. message = "上传的文件不能为空!";
  596. }
  597. return message;
  598. }
  599. }