DocServiceImpl.java 31 KB

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