123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- package com.ads.business.service.impl;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollectionUtil;
- import cn.hutool.core.util.ObjectUtil;
- import com.ads.business.dao.DocDao;
- import com.ads.business.dao.DocRoleDao;
- import com.ads.business.dao.DocTypeConversationRelDao;
- import com.ads.business.dao.TypeRoleDao;
- import com.ads.business.entity.*;
- import com.ads.business.service.*;
- import com.ads.business.service.data.GetLoginOutData;
- import com.ads.business.service.model.request.DocListRequest;
- import com.ads.business.service.model.request.DocRequest;
- import com.ads.business.service.model.response.CheckAuthResponse;
- import com.ads.business.service.model.response.DocListResponse;
- import com.ads.business.service.model.response.DocResponse;
- import com.ads.business.service.model.response.PdfDetailResponse;
- import com.ads.common.data.GetPictureConfigInData;
- import com.ads.common.data.JsonResult;
- import com.ads.common.data.PageInfo;
- import com.ads.common.exception.BusinessException;
- import com.ads.common.util.OnlineUserUtils;
- import com.ads.common.util.PageUtils;
- import com.ads.common.util.PdfUtil;
- import com.ads.common.util.UtilMessage;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.CollectionUtils;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.util.*;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author hou
- * @since 2021-10-21
- */
- @Slf4j
- @Service
- public class DocServiceImpl extends ServiceImpl<DocDao, Doc> implements DocService {
- @Resource
- private DocTypeService docTypeService;
- @Value("${doc.linkUrl}")
- private String linkUrl;
- @Resource
- private DocHistoryService docHistoryService;
- @Resource
- private TypeRoleService typeRoleService;
- @Autowired
- private GetPictureConfigInData pictureConfig;
- @Resource
- private DocRoleService docRoleService;
- @Resource
- private DocRoleDao docRoleDao;
- @Resource
- private DocConversationRelService docConversationRelService;
- @Resource
- private ConversationUserRelService conversationUserRelService;
- @Resource
- private DocTypeConversationRelService docTypeConversationRelService;
- @Resource
- private DocTypeConversationRelDao docTypeConversationRelDao;
- @Resource
- private ConversationService conversationService;
- @Resource
- private TypeRoleDao typeRoleDao;
- @Override
- @Transactional(rollbackFor = Exception.class)
- public String addDoc(DocRequest inData) {
- String message = checkBean(inData, false);
- if (StringUtils.isNotEmpty(message)) {
- return message;
- }
- int count = this.count(new LambdaQueryWrapper<Doc>()
- .eq(Doc::getTypeId, inData.getTypeId())
- .eq(Doc::getName, inData.getName()));
- if (count > 0) {
- throw new BusinessException("同一分类下,文件名称已存在!");
- }
- Doc doc = new Doc();
- BeanUtil.copyProperties(inData, doc);
- GetLoginOutData userInfo = OnlineUserUtils.get();
- if (null != userInfo) {
- doc.setCreateUser(Long.valueOf(userInfo.getUserId()));
- }
- doc.setCreateTime(new Date());
- doc.setUpdateTime(new Date());
- this.baseMapper.insert(doc);
- ArrayList<DocRole> docRoles = new ArrayList<>();
- if (CollectionUtil.isNotEmpty(inData.getRole())) {
- inData.getRole().stream().distinct().forEach(e -> {
- DocRole docRole = new DocRole();
- docRole.setDocId(doc.getId());
- docRole.setMobile(e);
- docRoles.add(docRole);
- });
- docRoleDao.insertBatch(docRoles);
- }
- Doc updoc = new Doc();
- updoc.setId(doc.getId());
- updoc.setLinkUrl(linkUrl + doc.getId() + "&showmenu=false");
- this.updateById(updoc);
- DocHistory docHistory = new DocHistory();
- BeanUtil.copyProperties(doc, docHistory);
- docHistory.setId(null);
- docHistory.setDocId(doc.getId());
- docHistoryService.save(docHistory);
- //新增文件会话关系
- if (CollectionUtil.isNotEmpty(inData.getConversationList())) {
- List<DocConversationRel> list = new ArrayList<>();
- inData.getConversationList().stream().forEach(conversationRequest -> {
- DocConversationRel docConversationRel = new DocConversationRel();
- docConversationRel.setDocId(doc.getId());
- docConversationRel.setChatId(conversationRequest.getChatId());
- docConversationRel.setOpenConversationId(conversationRequest.getOpenConversationId());
- list.add(docConversationRel);
- });
- docConversationRelService.saveBatch(list);
- }
- return null;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public String updateDoc(DocRequest inData) {
- String message = checkBean(inData, true);
- if (StringUtils.isNotEmpty(message)) {
- return message;
- }
- Doc doc = this.baseMapper.selectById(Long.valueOf(inData.getId()));
- Boolean flag = false;
- if (!inData.getDocUrl().equals(doc.getDocUrl())) {
- flag = true;
- }
- int count = this.count(new LambdaQueryWrapper<Doc>()
- .eq(Doc::getTypeId, inData.getTypeId())
- .eq(Doc::getName, inData.getName())
- .notIn(Doc::getId, inData.getId()));
- if (count > 0) {
- throw new BusinessException("同一分类下,文件名称已存在!");
- }
- BeanUtil.copyProperties(inData, doc);
- doc.setId(Long.valueOf(inData.getId()));
- GetLoginOutData userInfo = OnlineUserUtils.get();
- if (null != userInfo) {
- doc.setUpdateUser(Long.valueOf(userInfo.getUserId()));
- }
- doc.setUpdateTime(new Date());
- this.baseMapper.updateById(doc);
- docRoleService.remove(Wrappers.lambdaQuery(DocRole.class).eq(DocRole::getDocId, doc.getId()));
- if (CollectionUtil.isNotEmpty(inData.getRole())) {
- ArrayList<DocRole> docRoles = new ArrayList<>();
- inData.getRole().stream().distinct().forEach(e -> {
- DocRole docRole = new DocRole();
- docRole.setDocId(doc.getId());
- docRole.setMobile(e);
- docRoles.add(docRole);
- });
- docRoleDao.insertBatch(docRoles);
- }
- if (flag) {
- //不相等,那么删除当前目录的下的文件
- File imageFile = new File(getImageFilePath(doc.getId()));
- File pdfFile = new File(getImageFilePath(doc.getId())+".pdf");
- if(imageFile.exists()){
- imageFile.delete();
- }
- if(pdfFile.exists()){
- pdfFile.delete();
- }
- DocHistory docHistory = new DocHistory();
- BeanUtil.copyProperties(doc, docHistory);
- docHistory.setCreateTime(new Date());
- docHistory.setCreateUser(Long.valueOf(userInfo.getUserId()));
- docHistory.setDocId(doc.getId());
- docHistory.setId(null);
- docHistoryService.save(docHistory);
- }
- //根据文件ID删除
- docConversationRelService.remove(new LambdaQueryWrapper<DocConversationRel>()
- .eq(DocConversationRel::getDocId, inData.getId()));
- //新增文件会话关系
- if (CollectionUtil.isNotEmpty(inData.getConversationList())) {
- //新增
- List<DocConversationRel> list = new ArrayList<>();
- inData.getConversationList().stream().forEach(conversationRequest -> {
- DocConversationRel docConversationRel = new DocConversationRel();
- docConversationRel.setDocId(doc.getId());
- docConversationRel.setChatId(conversationRequest.getChatId());
- docConversationRel.setOpenConversationId(conversationRequest.getOpenConversationId());
- list.add(docConversationRel);
- });
- docConversationRelService.saveBatch(list);
- }
- return null;
- }
- @Override
- public DocResponse detail(Long docId) {
- DocResponse outData = new DocResponse();
- Doc doc = this.baseMapper.selectById(docId);
- if (null != doc) {
- BeanUtil.copyProperties(doc, outData);
- outData.setFileName(doc.getDocUrl().substring(doc.getDocUrl().lastIndexOf("/") + 1));
- }
- List<DocRole> list = docRoleService.list(Wrappers.lambdaQuery(DocRole.class).eq(DocRole::getDocId, doc.getId()));
- if (CollectionUtil.isNotEmpty(list)) {
- List<String> roles = list.stream().map(DocRole::getMobile).collect(Collectors.toList());
- outData.setRole(roles);
- }
- List<DocConversationRel> docRels = docConversationRelService.list(new LambdaQueryWrapper<DocConversationRel>().eq(DocConversationRel::getDocId, docId));
- if (CollectionUtil.isNotEmpty(docRels)) {
- outData.setConversationList(docRels);
- }
- return outData;
- }
- private Doc auth(Long docId,GetLoginOutData userInfo){
- if (StringUtils.isEmpty(userInfo.getMobile())) {
- throw new BusinessException("请重新登录");
- }
- Doc doc = this.baseMapper.selectById(docId);
- if (null == doc) {
- throw new BusinessException("当前文件信息不存在!");
- }
- if (doc.getStatus() == 0) {
- throw new BusinessException("当前文件已禁用,请启用后查看!");
- }
- DocType docType = docTypeService.getById(doc.getTypeId());
- if (ObjectUtil.isEmpty(docType)) {
- throw new BusinessException("当前文件说在分类信息不存在");
- }
- if (docType.getStatus() == 0) {
- throw new BusinessException("当前文件所在分类已禁用,请启用后查看!");
- }
- //userInfo.setMobile("18896995753");
- //userInfo.setMobile("15261532462");
- if (StringUtils.isEmpty(userInfo.getMobile())) {
- throw new BusinessException("请退出重新登录钉钉");
- }
- log.info("获取文件详情信息--校验会话权限");
- List<DocTypeConversationRel> typeList = docTypeConversationRelDao.getListByMobile(docType.getTypeId(),userInfo.getMobile());
- List<String> typeRoleMobiles = typeRoleDao.getListByTypeId(docType.getTypeId(),userInfo.getMobile());
- //手机号不为空,群组为空
- if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
- if (!typeRoleMobiles.contains(userInfo.getMobile())) {
- throw new BusinessException("您没有当前文件的查看权限");
- }
- Boolean res = checkAuthDetail(userInfo, doc);
- if (res) {
- throw new BusinessException("您没有当前文件的查看权限");
- }
- }
- //手机号不为空,群组不为空
- if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
- List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
- conversationMobiles.addAll(typeRoleMobiles);
- if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
- throw new BusinessException("您没有当前文件的查看权限");
- }
- Boolean res = checkAuthDetail(userInfo, doc);
- if (res) {
- throw new BusinessException("您没有当前文件的查看权限");
- }
- }
- //手机号为空,群组不为空
- if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
- List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
- if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
- throw new BusinessException("您没有当前文件的查看权限");
- }
- Boolean res = checkAuthDetail(userInfo, doc);
- if (res) {
- throw new BusinessException("您没有当前文件的查看权限");
- }
- }
- //手机号为空,群组为空
- if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
- Boolean res = checkAuthDetail(userInfo, doc);
- if (res) {
- throw new BusinessException("您没有当前文件的查看权限");
- }
- }
- log.info("校验权限结束!");
- return doc;
- }
- private String getImageFilePath(Long docId){
- return pictureConfig.getServerBasePath() +"/"+ pictureConfig.getUploadPath() + "/produce/" + docId;
- }
- @Override
- public JsonResult pdfDetail(HttpServletRequest request, Long docId, String userNo) {
- GetLoginOutData userInfo = OnlineUserUtils.get();
- if (null == userInfo) {
- return JsonResult.fail("您没有登录");
- }
- Doc doc = auth(docId,userInfo);
- //水印 姓名+手机号后四位
- String watermark = "沪上阿姨SOP";
- String fileName = doc.getName();
- String docUrl = doc.getDocUrl();
- String domain = pictureConfig.getServerPath();
- String path = domain + request.getContextPath() + "/";
- String filePath = pictureConfig.getServerBasePath() +"/"+ pictureConfig.getUploadPath() + "/produce/" + docId + ".pdf";
- String imageFilePath = getImageFilePath(docId) + "/";
- String createPath = pictureConfig.getBasePath() + "/" + pictureConfig.getUploadPath() + "/produce/" + docId + ".pdf";
- File fromFile = new File(createPath);
- //判断目标文件所在的目录是否存在
- if (!fromFile.getParentFile().exists()) {
- //如果目标文件所在的目录不存在,则创建父目录
- fromFile.getParentFile().mkdirs();
- }
- String pictureFilePath = docUrl.replace(domain+pictureConfig.getServerBasePath(),pictureConfig.getBasePath());
- if(!new File(pictureFilePath).exists()){
- throw new BusinessException("当前图片不存在"+pictureFilePath+"&"+domain+"&"+pictureConfig.getBasePath());
- }
- if (!fromFile.exists()) {
- try {
- PdfUtil.setWatermark(new BufferedOutputStream(new FileOutputStream(new File(createPath))), pictureFilePath, watermark);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- throw new BusinessException("生成pdf文件水印有异常!");
- }
- }
- log.info("pdfDetail--文件路径:{}", path + filePath);
- log.info("createPath---路径:{}", createPath);
- // 生成图片
- LinkedList<String> images = getPdfImages(createPath, path + imageFilePath);
- int pdfNumberPage = PdfUtil.getPdfNumberPage(createPath);
- if (images.size() != pdfNumberPage) {
- int pageSize = PdfUtil.toImages(createPath);
- log.info("toImages :" + pageSize);
- if (pageSize > 0) {
- for (int i = 1; i <= pageSize; i++) {
- images.add(path + imageFilePath + i + ".png");
- }
- }
- }
- PdfDetailResponse rs = new PdfDetailResponse();
- rs.setPath(path + filePath);
- rs.setFileName(fileName);
- rs.setImageFiles(images);
- rs.setWatermark(userInfo.getName() + userInfo.getMobile().substring(userInfo.getMobile().length() - 5));
- return JsonResult.success(rs, UtilMessage.GET_MESSAGE_SUCCESS);
- }
- @Transactional(rollbackFor = Exception.class)
- @Override
- public JsonResult updateSwitch(Long id, Integer status) {
- Doc docdb = this.getById(id);
- if (ObjectUtil.isEmpty(docdb)) {
- throw new BusinessException(UtilMessage.DATA_EMPTY);
- }
- if (docdb.getStatus().equals(status) && status == 1) {
- throw new BusinessException("文件分类已启用,请勿重复操作!");
- }
- if (docdb.getStatus().equals(status) && status == 0) {
- throw new BusinessException("文件分类已禁用,请勿重复操作!");
- }
- Doc doc = new Doc();
- doc.setId(id);
- doc.setStatus(status);
- this.updateById(doc);
- String msg;
- if (status == 1) {
- msg = UtilMessage.ENABLE_MESSAGE_SUCCESS;
- } else {
- msg = UtilMessage.DISABLE_MESSAGE_SUCCESS;
- }
- return JsonResult.success(null, msg);
- }
- /**
- * 获取文件列表信息
- *
- * @param request 列表查询参数信息
- * @param type 1 移动端
- * @return 文件参数结果信息
- */
- @Override
- public JsonResult docList(DocListRequest request, Integer type) {
- if (null == request) {
- return JsonResult.fail("请输入文件分类信息");
- }
- if (type == 1) {
- DocType docType = docTypeService.getById(request.getTypeId());
- if (ObjectUtil.isEmpty(docType)) {
- return JsonResult.fail("文件分类信息不存在");
- }
- if (docType.getStatus() == 0) {
- return JsonResult.fail(1000, "当前文件分类已禁用,请启用后查看!");
- }
- if (StringUtils.isEmpty(request.getTypeId())) {
- return JsonResult.fail("请输入文件分类信息");
- }
- GetLoginOutData userInfo = OnlineUserUtils.get();
- if (null == userInfo) {
- return JsonResult.fail("您没有登录");
- }
- //userInfo.setMobile("18896995753");
- //userInfo.setMobile("15261532462");
- if (StringUtils.isEmpty(userInfo.getMobile())) {
- return JsonResult.fail(1000, "请退出重新登录钉钉");
- }
- List<Doc> docList = this.list(new LambdaQueryWrapper<Doc>().eq(Doc::getTypeId, request.getTypeId()).eq(Doc::getStatus, 1));
- log.info("获取文件列表信息--校验会话分类权限");
- List<DocTypeConversationRel> typeList = docTypeConversationRelDao.getListByMobile(Long.parseLong(request.getTypeId()),userInfo.getMobile());
- List<String> typeRoleMobiles = typeRoleDao.getListByTypeId(Long.parseLong(request.getTypeId()),userInfo.getMobile());
- //手机号不为空,群组为空
- if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
- if (!typeRoleMobiles.contains(userInfo.getMobile())) {
- return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
- }
- List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
- if (CollectionUtil.isEmpty(newList)) {
- return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
- } else {
- return JsonResult.success(new PageInfo<>(newList), UtilMessage.GET_MESSAGE_SUCCESS);
- }
- }
- //手机号不为空,群组不为空
- if (CollectionUtil.isNotEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
- List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
- conversationMobiles.addAll(typeRoleMobiles);
- if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
- return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
- }
- List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
- if (CollectionUtil.isEmpty(newList)) {
- return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
- } else {
- return JsonResult.success(new PageUtils(newList, newList.size(), request.getPageSize(), request.getPage())
- , UtilMessage.GET_MESSAGE_SUCCESS);
- }
- }
- //手机号为空,群组不为空
- if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isNotEmpty(typeList)) {
- List<String> conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
- if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
- return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
- }
- List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
- if (CollectionUtil.isEmpty(newList)) {
- return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
- } else {
- return JsonResult.success(new PageUtils(newList, newList.size(), request.getPageSize(), request.getPage())
- , UtilMessage.GET_MESSAGE_SUCCESS);
- }
- }
- //手机号为空,群组为空
- if (CollectionUtil.isEmpty(typeRoleMobiles) && CollectionUtil.isEmpty(typeList)) {
- List<CheckAuthResponse> newList = checkAuth(userInfo, docList);
- if (CollectionUtil.isEmpty(newList)) {
- return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
- } else {
- return JsonResult.success(new PageUtils(newList, newList.size(), request.getPageSize(), request.getPage())
- , UtilMessage.GET_MESSAGE_SUCCESS);
- }
- }
- return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
- } else {
- Long currPage = request.getPage() == null ? 1 : request.getPage().longValue();
- Long pageSize = request.getPageSize() == null ? 10 : request.getPageSize().longValue();
- Page<DocListResponse> page = new Page<>(currPage, pageSize);
- QueryWrapper<DocListResponse> wrapper = new QueryWrapper();
- if (StringUtils.isNotBlank(request.getTypeId())) {
- wrapper.eq("hdt.type_id", Long.valueOf(request.getTypeId()));
- }
- if (StringUtils.isNotBlank(request.getName())) {
- wrapper.like("hd.name", request.getName());
- }
- Integer status;
- if (type == 1) {
- status = type;
- } else {
- status = request.getStatus();
- }
- if (null != status) {
- wrapper.eq("hd.status", status);
- }
- wrapper.orderByDesc("hd.create_time");
- if (type == 1) {
- List<DocListResponse> list = this.baseMapper.findList(wrapper);
- if (CollectionUtil.isEmpty(list)) {
- return JsonResult.success(new PageUtils(new Page<>(1, 0)), UtilMessage.GET_MESSAGE_SUCCESS);
- }
- String mobile = OnlineUserUtils.get().getMobile();
- log.info("获取文件列表信息----mobile={}", mobile);
- List<String> docIds = list.stream().map(DocListResponse::getId).collect(Collectors.toList());
- List<DocRole> docRoles = docRoleDao.selectList(Wrappers.lambdaQuery(DocRole.class).in(DocRole::getDocId, docIds));
- Map<Long, List<DocRole>> docRoleMap = docRoles.stream().collect(Collectors.groupingBy(DocRole::getDocId));
- List<DocListResponse> responses = new ArrayList<>();
- list.forEach(e -> {
- List<DocRole> roleList = docRoleMap.get(Long.valueOf(e.getId()));
- if (CollectionUtil.isEmpty(roleList)) {
- responses.add(e);
- } else {
- List<String> mobiles = roleList.stream().map(DocRole::getMobile).collect(Collectors.toList());
- if (mobiles.contains(OnlineUserUtils.get().getMobile())) {
- responses.add(e);
- }
- }
- });
- return JsonResult.success(new PageUtils(new Page<DocListResponse>(1, responses.size()
- , responses.size()).setRecords(responses)), UtilMessage.GET_MESSAGE_SUCCESS);
- } else {
- return JsonResult.success(new PageUtils(this.baseMapper.findPage(page, wrapper)), UtilMessage.GET_MESSAGE_SUCCESS);
- }
- }
- }
- private List<CheckAuthResponse> checkAuth(GetLoginOutData userInfo, List<Doc> docList) {
- List<CheckAuthResponse> newList = new ArrayList<>();
- //校验分类下手机号
- if (CollectionUtil.isNotEmpty(docList)) {
- for (Doc doc : docList) {
- //群组
- List<DocConversationRel> docConversationRels = docConversationRelService.list(new LambdaQueryWrapper<DocConversationRel>()
- .eq(DocConversationRel::getDocId, doc.getId()));
- //权限手机号
- List<String> docRoleMobiles = docRoleDao.getMobileList(doc.getId());
- //手机号不为空,群组为空
- if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isEmpty(docConversationRels)) {
- if (!docRoleMobiles.contains(userInfo.getMobile())) {
- continue;
- }
- }
- //手机号不为空,群组不为空
- if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
- //群组内所有人手机号
- List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId(),userInfo.getMobile());
- docRoleMobiles.addAll(docConversationMobiles);
- if (!docRoleMobiles.contains(userInfo.getMobile())) {
- continue;
- }
- }
- //手机号为空,群组不为空
- if (CollectionUtil.isEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
- //群组内所有人手机号
- List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId(),userInfo.getMobile());
- if (!docConversationMobiles.contains(userInfo.getMobile())) {
- continue;
- }
- }
- CheckAuthResponse rs = new CheckAuthResponse();
- rs.setId(doc.getId().toString());
- rs.setTypeId(doc.getTypeId().toString());
- rs.setFileSize(doc.getFileSize());
- rs.setName(doc.getName());
- //手机号为空,群组为空 根据分类权限
- newList.add(rs);
- }
- }
- return newList;
- }
- private boolean checkAuthDetail(GetLoginOutData userInfo, Doc doc) {
- //校验分类下手机号
- //群组
- List<DocConversationRel> docConversationRels = docConversationRelService.list(new LambdaQueryWrapper<DocConversationRel>()
- .eq(DocConversationRel::getDocId, doc.getId()));
- //权限手机号
- List<String> docRoleMobiles = docRoleDao.getMobileList(doc.getId());
- //手机号不为空,群组为空
- if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isEmpty(docConversationRels)) {
- if (!docRoleMobiles.contains(userInfo.getMobile())) {
- return true;
- }
- }
- //手机号不为空,群组不为空
- if (CollectionUtil.isNotEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
- //群组内所有人手机号
- List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId(),userInfo.getMobile());
- docRoleMobiles.addAll(docConversationMobiles);
- if (!docRoleMobiles.contains(userInfo.getMobile())) {
- return true;
- }
- }
- //手机号为空,群组不为空
- if (CollectionUtil.isEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
- //群组内所有人手机号
- List<String> docConversationMobiles = docConversationRelService.getListByDocId(doc.getId(),userInfo.getMobile());
- if (!docConversationMobiles.contains(userInfo.getMobile())) {
- return true;
- }
- }
- CheckAuthResponse rs = new CheckAuthResponse();
- rs.setId(doc.getId().toString());
- rs.setTypeId(doc.getTypeId().toString());
- rs.setFileSize(doc.getFileSize());
- rs.setName(doc.getName());
- //手机号为空,群组为空 根据分类权限
- return false;
- }
- /**
- * 验证实体的必填项是否已经填写
- *
- * @param inData 实体参数
- * @return message 验证结果集
- */
- private String checkBean(DocRequest inData, Boolean mark) {
- String message = "";
- if (mark && null == inData.getId()) {
- message = "编辑文件时,Id不能为空!";
- }
- if (null == inData.getTypeId()) {
- message = "文件分类不能为空!";
- }
- if (StringUtils.isEmpty(inData.getName())) {
- message = "文件名称不能为空!";
- }
- if (StringUtils.isEmpty(inData.getFileSize())) {
- message = "上传的文件不能为空!";
- }
- return message;
- }
- public LinkedList<String> getPdfImages(String pdfPath, String parentPath) {
- LinkedList<String> images = new LinkedList<>();
- File imagesDirectory = new File(pdfPath.substring(0, pdfPath.lastIndexOf('.')));
- log.info("imagesDirectory exists:" + imagesDirectory.exists());
- if (imagesDirectory.exists()) {
- File[] files = imagesDirectory.listFiles();
- if (null != files && files.length > 0) {
- for (int i = 1; i <= files.length; i++) {
- images.add(parentPath + i + ".png");
- }
- }
- }
- return images;
- }
- }
|