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;
/**
*
* 服务实现类
*
*
* @author hou
* @since 2021-10-21
*/
@Slf4j
@Service
public class DocServiceImpl extends ServiceImpl 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()
.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 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 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()
.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 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()
.eq(DocConversationRel::getDocId, inData.getId()));
//新增文件会话关系
if (CollectionUtil.isNotEmpty(inData.getConversationList())) {
//新增
List 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 list = docRoleService.list(Wrappers.lambdaQuery(DocRole.class).eq(DocRole::getDocId, doc.getId()));
if (CollectionUtil.isNotEmpty(list)) {
List roles = list.stream().map(DocRole::getMobile).collect(Collectors.toList());
outData.setRole(roles);
}
List docRels = docConversationRelService.list(new LambdaQueryWrapper().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 typeList = docTypeConversationRelDao.getListByMobile(docType.getTypeId(),userInfo.getMobile());
List 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 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 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 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 docList = this.list(new LambdaQueryWrapper().eq(Doc::getTypeId, request.getTypeId()).eq(Doc::getStatus, 1));
log.info("获取文件列表信息--校验会话分类权限");
List typeList = docTypeConversationRelDao.getListByMobile(Long.parseLong(request.getTypeId()),userInfo.getMobile());
List 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 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 conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
conversationMobiles.addAll(typeRoleMobiles);
if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
}
List 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 conversationMobiles = docTypeConversationRelService.getListByTypeId(docType.getTypeId());
if (!conversationMobiles.contains(OnlineUserUtils.get().getMobile())) {
return JsonResult.fail(1000, "您没有当前文件分类的查看权限");
}
List 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 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 page = new Page<>(currPage, pageSize);
QueryWrapper 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 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 docIds = list.stream().map(DocListResponse::getId).collect(Collectors.toList());
List docRoles = docRoleDao.selectList(Wrappers.lambdaQuery(DocRole.class).in(DocRole::getDocId, docIds));
Map> docRoleMap = docRoles.stream().collect(Collectors.groupingBy(DocRole::getDocId));
List responses = new ArrayList<>();
list.forEach(e -> {
List roleList = docRoleMap.get(Long.valueOf(e.getId()));
if (CollectionUtil.isEmpty(roleList)) {
responses.add(e);
} else {
List 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(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 checkAuth(GetLoginOutData userInfo, List docList) {
List newList = new ArrayList<>();
//校验分类下手机号
if (CollectionUtil.isNotEmpty(docList)) {
for (Doc doc : docList) {
//群组
List docConversationRels = docConversationRelService.list(new LambdaQueryWrapper()
.eq(DocConversationRel::getDocId, doc.getId()));
//权限手机号
List 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 docConversationMobiles = docConversationRelService.getListByDocId(doc.getId(),userInfo.getMobile());
docRoleMobiles.addAll(docConversationMobiles);
if (!docRoleMobiles.contains(userInfo.getMobile())) {
continue;
}
}
//手机号为空,群组不为空
if (CollectionUtil.isEmpty(docRoleMobiles) && CollectionUtil.isNotEmpty(docConversationRels)) {
//群组内所有人手机号
List 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 docConversationRels = docConversationRelService.list(new LambdaQueryWrapper()
.eq(DocConversationRel::getDocId, doc.getId()));
//权限手机号
List 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 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 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 getPdfImages(String pdfPath, String parentPath) {
LinkedList 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;
}
}