|
@@ -3,26 +3,14 @@ package com.caimei.www.service.page.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
|
-import com.aliyun.oss.model.GetObjectRequest;
|
|
|
-import com.aliyun.oss.model.OSSObject;
|
|
|
-import com.caimei.www.mapper.DocumentAuthDao;
|
|
|
import com.caimei.www.pojo.JsonModel;
|
|
|
-import com.caimei.www.pojo.document.CookieBuilder;
|
|
|
-import com.caimei.www.pojo.document.OssArchive;
|
|
|
import com.caimei.www.pojo.document.OssArchivePdf;
|
|
|
-import com.caimei.www.pojo.document.OssAuthorization;
|
|
|
import com.caimei.www.service.page.DocumentAuthService;
|
|
|
import com.caimei.www.service.redis.RedisService;
|
|
|
-import com.caimei.www.utils.ImageUtil;
|
|
|
import com.caimei.www.utils.RandomCodeGenerator;
|
|
|
import com.caimei.www.utils.VerifyCodeUtils;
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
-import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.http.*;
|
|
|
-import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
-import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
@@ -31,16 +19,12 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
+
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -52,8 +36,6 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class DocumentAuthServiceImpl implements DocumentAuthService {
|
|
|
- @Resource
|
|
|
- private DocumentAuthDao documentAuthDao;
|
|
|
|
|
|
@Resource
|
|
|
private RedisService redisService;
|
|
@@ -79,14 +61,7 @@ public class DocumentAuthServiceImpl implements DocumentAuthService {
|
|
|
@Value("${caimei.coreServer}")
|
|
|
private String coreServer;
|
|
|
|
|
|
- @Override
|
|
|
- public Boolean getAuthorizationCookie(String authorizationMobile) {
|
|
|
- if (!StringUtils.isEmpty(authorizationMobile)) {
|
|
|
- OssAuthorization ossAuthorization = documentAuthDao.findOssAuthorizationByMobile(authorizationMobile);
|
|
|
- return ossAuthorization != null;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Mono<JsonModel> getImgVerifyCode() {
|
|
@@ -144,72 +119,6 @@ public class DocumentAuthServiceImpl implements DocumentAuthService {
|
|
|
return Mono.just(JsonModel.error("验证码不正确"));
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ResponseEntity<JsonModel> mobileCodeLogin(OssAuthorization authorization) {
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- if (StringUtils.isEmpty(authorization.getMobile()) || StringUtils.isEmpty(authorization.getCode())) {
|
|
|
- return new ResponseEntity<>(JsonModel.error("参数异常"), headers, HttpStatus.OK);
|
|
|
- }
|
|
|
- String mobileCode = (String) redisService.get(authorization.getMobile() + ":mobileCode");
|
|
|
- if (!StringUtils.isEmpty(mobileCode) && authorization.getCode().equals(mobileCode)) {
|
|
|
- OssAuthorization ossAuthorization = documentAuthDao.findOssAuthorizationByMobile(authorization.getMobile());
|
|
|
- if (ossAuthorization != null) {
|
|
|
- String cookie = new CookieBuilder().setKey("authorizationMobile")
|
|
|
- .setValue(authorization.getMobile())
|
|
|
- .setMaxAge(60 * 60 * 24 * 30 * 1000L)
|
|
|
- .setPath("/")
|
|
|
- .build();
|
|
|
- headers.add("Set-Cookie", cookie);
|
|
|
- return new ResponseEntity<>(JsonModel.success(), headers, HttpStatus.OK);
|
|
|
- } else {
|
|
|
- return new ResponseEntity<>(JsonModel.error(-2, "登录失败,您可能没有查看资料的权限"), headers, HttpStatus.OK);
|
|
|
- }
|
|
|
- } else {
|
|
|
- return new ResponseEntity<>(JsonModel.error("短信验证码不正确"), headers, HttpStatus.OK);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Mono<JsonModel> dataList(String name, Integer pageNum, Integer pageSize) {
|
|
|
- pageNum = pageNum == null ? 1 : pageNum;
|
|
|
- pageSize = pageSize == null ? 20 : pageSize;
|
|
|
- PageHelper.startPage(pageNum, pageSize);
|
|
|
- List<OssArchive> ossArchiveList = documentAuthDao.findOssArchive(name);
|
|
|
- PageInfo<OssArchive> pageInfo = null;
|
|
|
- if (ossArchiveList != null && ossArchiveList.size() > 0) {
|
|
|
- for (OssArchive ossArchive : ossArchiveList) {
|
|
|
- if (!StringUtils.isEmpty(ossArchive.getMainImage())) {
|
|
|
- ossArchive.setMainImage(ImageUtil.getImageURL("product", ossArchive.getMainImage(), 0, domain));
|
|
|
- }
|
|
|
- List<OssArchivePdf> pdfList = documentAuthDao.findOssArchivePdf(ossArchive.getId());
|
|
|
- if (pdfList != null && pdfList.size() > 0) {
|
|
|
- pdfList.forEach(this::setOssArchivePdfUrl);
|
|
|
- ossArchive.setIsShowDowns(false);
|
|
|
- } else {
|
|
|
- ossArchive.setIsShowDowns(true);
|
|
|
- }
|
|
|
- ossArchive.setPdfList(pdfList);
|
|
|
- }
|
|
|
- pageInfo = new PageInfo<>(ossArchiveList);
|
|
|
- }
|
|
|
- return Mono.just(JsonModel.success(pageInfo));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Mono<JsonModel> dataDetails(Integer pdfId) {
|
|
|
- Map<String, Object> map = new HashMap<>(2);
|
|
|
- OssArchivePdf ossArchivePdf = documentAuthDao.findOssArchivePdfById(pdfId);
|
|
|
- setOssArchivePdfUrl(ossArchivePdf);
|
|
|
- OssArchive ossArchive = documentAuthDao.getOssArchive(ossArchivePdf.getArchiveId());
|
|
|
- if (!StringUtils.isEmpty(ossArchive.getMainImage())) {
|
|
|
- ossArchive.setMainImage(ImageUtil.getImageURL("product", ossArchive.getMainImage(), 0, domain));
|
|
|
- }
|
|
|
- map.put("ossArchivePdf", ossArchivePdf);
|
|
|
- map.put("ossArchive", ossArchive);
|
|
|
-
|
|
|
- return Mono.just(JsonModel.success(map));
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 设置预览链接
|
|
@@ -238,96 +147,22 @@ public class DocumentAuthServiceImpl implements DocumentAuthService {
|
|
|
ossClient.shutdown();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Mono<JsonModel> moreData(Integer archiveId) {
|
|
|
- OssArchive ossArchive = documentAuthDao.getOssArchive(archiveId);
|
|
|
- if (ossArchive != null) {
|
|
|
- if (!StringUtils.isEmpty(ossArchive.getMainImage())) {
|
|
|
- ossArchive.setMainImage(ImageUtil.getImageURL("product", ossArchive.getMainImage(), 0, domain));
|
|
|
- }
|
|
|
- List<OssArchivePdf> pdfList = documentAuthDao.findOssArchivePdf(ossArchive.getId());
|
|
|
- if (pdfList != null && pdfList.size() > 0) {
|
|
|
- pdfList.forEach(this::setOssArchivePdfUrl);
|
|
|
- }
|
|
|
- ossArchive.setPdfList(pdfList);
|
|
|
- }
|
|
|
- return Mono.just(JsonModel.success(ossArchive));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Mono<Void> downFile(Integer pdfId, ServerHttpRequest request, ServerHttpResponse response) {
|
|
|
- try {
|
|
|
- OssArchivePdf ossArchivePdf = documentAuthDao.findOssArchivePdfById(pdfId);
|
|
|
- // 创建OSSClient实例。
|
|
|
- OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
- File file = new File("src/main/resources/static/file");
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdir();
|
|
|
- }
|
|
|
- // 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
|
|
|
- ossClient.getObject(new GetObjectRequest(bucketName, ossArchivePdf.getOssName()), new File("src/main/resources/static/file/" + ossArchivePdf.getName()));
|
|
|
- // 关闭OSSClient。
|
|
|
- ossClient.shutdown();
|
|
|
- File pdfFile = new File("src/main/resources/static/file/" + ossArchivePdf.getName());
|
|
|
- //输出文件名乱码问题处理
|
|
|
- response.getHeaders().set(HttpHeaders.CONTENT_DISPOSITION,
|
|
|
- "attachment; filename=" + new String(pdfFile.getName().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
|
|
- ZeroCopyHttpOutputMessage zeroCopyResponse = (ZeroCopyHttpOutputMessage) response;
|
|
|
- response.getHeaders().setContentType(MediaType.APPLICATION_PDF);
|
|
|
- return zeroCopyResponse.writeWith(pdfFile, 0, pdfFile.length());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return Mono.error(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deleteFile() {
|
|
|
- File file = new File("src/main/resources/static/file");
|
|
|
- //取得这个目录下的所有子文件对象
|
|
|
- File[] files = file.listFiles();
|
|
|
- //遍历该目录下的文件对象
|
|
|
- if (files != null && files.length > 0) {
|
|
|
- for (File f : files) {
|
|
|
- //打印文件名
|
|
|
- String name = file.getName();
|
|
|
- log.info("定时删除服务器临时文件,文件名>>>>>" + name);
|
|
|
- //判断子目录是否存在子目录,如果是文件则删除
|
|
|
- f.delete();
|
|
|
- }
|
|
|
- }
|
|
|
- //删除空文件夹
|
|
|
- file.delete();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Mono<JsonModel> downFileAll(Integer pdfId) {
|
|
|
- Map<String, Object> map = new HashMap<>(2);
|
|
|
- StringBuilder date = new StringBuilder();
|
|
|
- try {
|
|
|
- OssArchivePdf ossArchivePdf = documentAuthDao.findOssArchivePdfById(pdfId);
|
|
|
- map.put("name", ossArchivePdf.getName());
|
|
|
- // 创建OSSClient实例。
|
|
|
- OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
- // ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
|
|
|
- OSSObject ossObject = ossClient.getObject(bucketName, ossArchivePdf.getOssName());
|
|
|
- // 读取文件内容。
|
|
|
- BufferedReader reader = new BufferedReader(new InputStreamReader(ossObject.getObjectContent()));
|
|
|
- while (true) {
|
|
|
- String line = reader.readLine();
|
|
|
- if (line == null) {
|
|
|
- break;
|
|
|
- }
|
|
|
- date.append(line);
|
|
|
- }
|
|
|
- // 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
|
|
- reader.close();
|
|
|
- // 关闭OSSClient。
|
|
|
- ossClient.shutdown();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- map.put("date", date);
|
|
|
- return Mono.just(JsonModel.success(JsonModel.success(map)));
|
|
|
- }
|
|
|
+// @Override
|
|
|
+// public void deleteFile() {
|
|
|
+// File file = new File("src/main/resources/static/file");
|
|
|
+// //取得这个目录下的所有子文件对象
|
|
|
+// File[] files = file.listFiles();
|
|
|
+// //遍历该目录下的文件对象
|
|
|
+// if (files != null && files.length > 0) {
|
|
|
+// for (File f : files) {
|
|
|
+// //打印文件名
|
|
|
+// String name = file.getName();
|
|
|
+// log.info("定时删除服务器临时文件,文件名>>>>>" + name);
|
|
|
+// //判断子目录是否存在子目录,如果是文件则删除
|
|
|
+// f.delete();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //删除空文件夹
|
|
|
+// file.delete();
|
|
|
+// }
|
|
|
}
|