DocServiceImpl.java 31 KB

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