From 223f2236dc80e043fa7fed44060824f3615ed7af Mon Sep 17 00:00:00 2001 From: zhangqinlin <983410zql> Date: Fri, 17 Dec 2021 14:40:50 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=89=8B=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PayCaseCommitteeServiceImpl.java | 8 +- .../controller/PayMeetingController.java | 250 ++++++++++-------- 2 files changed, 140 insertions(+), 118 deletions(-) diff --git a/jero-boot-incoming-payment/src/main/java/com/jero/data/service/impl/PayCaseCommitteeServiceImpl.java b/jero-boot-incoming-payment/src/main/java/com/jero/data/service/impl/PayCaseCommitteeServiceImpl.java index e1e29625..697258c0 100644 --- a/jero-boot-incoming-payment/src/main/java/com/jero/data/service/impl/PayCaseCommitteeServiceImpl.java +++ b/jero-boot-incoming-payment/src/main/java/com/jero/data/service/impl/PayCaseCommitteeServiceImpl.java @@ -6,10 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jero.common.exception.JeroBootException; -import com.jero.common.util.Assert; -import com.jero.common.util.CommonUtils; -import com.jero.common.util.PasswordUtil; -import com.jero.common.util.RedisUtil; +import com.jero.common.util.*; import com.jero.company.service.IPayContactsManagementService; import com.jero.data.entity.DetailForCaseCommittee; import com.jero.data.entity.PayCaseCommittee; @@ -99,6 +96,9 @@ public class PayCaseCommitteeServiceImpl extends ServiceImpl -// if(meetingMinute) -// List meetingMinuteList = Arrays.asList(meetingMinute.split(",")); -// List meetingMinuteList = Arrays.asList(meetingMinute.split(",")); -// // 查询数据表数据是否存在 -// LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); -// queryWrapper.eq(OSSFile::getId,id); -// OSSFile ossFile = ossFileService.getOne(queryWrapper); -// if( null == ossFile){ -// throw new JeroBootException("文件不存在.."); -// } -// String fileUrl = ossFile.getUrl(); -// InputStream inputStream = null; -// OutputStream outputStream = null; -// try { -// String fileName = ""; -// if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){ -// //本地下载 -// String filePath = uploadpath + File.separator + fileUrl; -// File file = new File(filePath); -// if(!file.exists()){ -// response.setStatus(404); -// throw new RuntimeException("文件不存在.."); -// } -// // 文件名称 -// fileName = file.getName(); -// inputStream = new BufferedInputStream(new FileInputStream(filePath)); -// }else if(CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){ -// // minio 下载 -// // 通过MinioUtil查询时 只需要桶后面的路径 -// String minioUrl = MinioUtil.getMinioUrl(); -// // Linux/unix 系统下文件路径分隔符为"/" 获取minio与存储桶的路径 -// minioUrl = minioUrl + MinioUtil.getBucketName() + "/"; -// String url = fileUrl.replace(minioUrl, ""); -// // 文件名称 -// fileName = ossFile.getFileName(); -// inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), url); -// } -// -// ossFileService.updateById(ossFile); -// LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); -// if (loginUser.getIsCompanyUser()) { -// Integer integer = ossFileService.searchDownloadTimes(ossFile.getId(), loginUser.getId()); -// if (integer >= 5) { -// throw new JeroBootException("超出下载次数限制"); -// } -// } -// ossFileService.saveDownloadTimes(ossFile.getId(), loginUser.getId()); -// -// response.addHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("UTF-8"),"iso-8859-1")); -// response.setContentType("application/force-download");// 设置强制下载不打开 -// if (type == null) { -// fileName = StringUtils.lowerCase(fileName); -// if (fileName.contains(".jpg") || fileName.contains(".gif") || fileName.contains(".jpeg")) { -// response.setContentType("image/jpeg;image/jpg;image/gif;image/png"); -// } else if (fileName.contains(".png")) { -// response.setContentType("image/png;image/jpg;image/gif;image/jpeg"); -// } -// } -// outputStream = response.getOutputStream(); -// byte[] buf = new byte[1024]; -// int len; -// while ((len = inputStream.read(buf)) > 0) { -// outputStream.write(buf, 0, len); -// } -// response.flushBuffer(); -// //统计下载和上传次数 -// if ("download".equals(type)) { -// Integer downloadNumber = ossFile.getDownloadNumber(); -// if (downloadNumber == null) { -// ossFile.setDownloadNumber(1); -// } else { -// ossFile.setDownloadNumber(downloadNumber + 1); -// } -// ossFileService.updateById(ossFile); -// } else { -// Integer viewNumber = ossFile.getViewNumber(); -// if (viewNumber == null) { -// ossFile.setViewNumber(1); -// } else { -// ossFile.setViewNumber(viewNumber + 1); -// } -// ossFileService.updateAndPush(ossFile); -// } -// } catch (IOException e) { -// log.error("预览文件失败" + e.getMessage()); -// response.setStatus(404); -// e.printStackTrace(); -// } finally { -// if (inputStream != null) { -// try { -// inputStream.close(); -// } catch (IOException e) { -// log.error(e.getMessage(), e); -// } -// } -// if (outputStream != null) { -// try { -// outputStream.close(); -// } catch (IOException e) { -// log.error(e.getMessage(), e); -// } -// } -// } -// + LoginUser sysUser =(LoginUser) SecurityUtils.getSubject().getPrincipal(); + String sysUserId = sysUser.getId(); + PayMeeting byId = payMeetingService.getById(meetingId); + if(ObjectUtils.isEmpty(byId)){ + throw new JeroBootException("会议不存在.."); + } + String meetingMinute = byId.getMeetingMinute(); + String meetingData = byId.getMeetingData(); + List fileList = null; + if(StringUtils.isNotBlank(meetingMinute)) { + fileList.addAll(Arrays.asList(meetingMinute.split(","))); + } + if(StringUtils.isNotBlank(meetingData)) { + fileList.addAll(Arrays.asList(meetingData.split(","))); + } + if(fileList==null||!fileList.contains(id)){ + throw new JeroBootException("会议无此文件.."); + } + BigDecimal meetingCosts = byId.getMeetingCosts(); + //免费会议 + if ("0".equals(meetingCosts.toString())){ + QueryWrapper queryWrapper1 = new QueryWrapper<>(); + queryWrapper1.eq("meeting_id", meetingId); + queryWrapper1.eq("company_contact_id", sysUserId); + PayMeetingSituation one = payMeetingSituationService.getOne(queryWrapper1); + if (ObjectUtils.isEmpty(one)) { + throw new JeroBootException("会议报名并审核通过后才可查看文件"); + } + Integer checkResult = one.getCheckResult(); + if (checkResult != 1) { + throw new JeroBootException("会议报名并审核通过后才可查看文件"); + } + } + // 查询数据表数据是否存在 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(OSSFile::getId,id); + OSSFile ossFile = ossFileService.getOne(queryWrapper); + if( null == ossFile){ + throw new JeroBootException("文件不存在.."); + } + String fileUrl = ossFile.getUrl(); + InputStream inputStream = null; + OutputStream outputStream = null; + try { + String fileName = ""; + if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){ + //本地下载 + String filePath = uploadpath + File.separator + fileUrl; + File file = new File(filePath); + if(!file.exists()){ + response.setStatus(404); + throw new RuntimeException("文件不存在.."); + } + // 文件名称 + fileName = file.getName(); + inputStream = new BufferedInputStream(new FileInputStream(filePath)); + }else if(CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){ + // minio 下载 + // 通过MinioUtil查询时 只需要桶后面的路径 + String minioUrl = MinioUtil.getMinioUrl(); + // Linux/unix 系统下文件路径分隔符为"/" 获取minio与存储桶的路径 + minioUrl = minioUrl + MinioUtil.getBucketName() + "/"; + String url = fileUrl.replace(minioUrl, ""); + // 文件名称 + fileName = ossFile.getFileName(); + inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), url); + } + + ossFileService.updateById(ossFile); + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if (loginUser.getIsCompanyUser()) { + Integer integer = ossFileService.searchDownloadTimes(ossFile.getId(), loginUser.getId()); + if (integer >= 5) { + throw new JeroBootException("超出下载次数限制"); + } + } + ossFileService.saveDownloadTimes(ossFile.getId(), loginUser.getId()); + + response.addHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("UTF-8"),"iso-8859-1")); + response.setContentType("application/force-download");// 设置强制下载不打开 + if (type == null) { + fileName = StringUtils.lowerCase(fileName); + if (fileName.contains(".jpg") || fileName.contains(".gif") || fileName.contains(".jpeg")) { + response.setContentType("image/jpeg;image/jpg;image/gif;image/png"); + } else if (fileName.contains(".png")) { + response.setContentType("image/png;image/jpg;image/gif;image/jpeg"); + } + } + outputStream = response.getOutputStream(); + byte[] buf = new byte[1024]; + int len; + while ((len = inputStream.read(buf)) > 0) { + outputStream.write(buf, 0, len); + } + response.flushBuffer(); + //统计下载和上传次数 + if ("download".equals(type)) { + Integer downloadNumber = ossFile.getDownloadNumber(); + if (downloadNumber == null) { + ossFile.setDownloadNumber(1); + } else { + ossFile.setDownloadNumber(downloadNumber + 1); + } + ossFileService.updateById(ossFile); + } else { + Integer viewNumber = ossFile.getViewNumber(); + if (viewNumber == null) { + ossFile.setViewNumber(1); + } else { + ossFile.setViewNumber(viewNumber + 1); + } + ossFileService.updateAndPush(ossFile); + } + } catch (IOException e) { + log.error("预览文件失败" + e.getMessage()); + response.setStatus(404); + e.printStackTrace(); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + } + } }