文件下载加解密
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
package com.jero.modules.docking.download.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.CommonUtils;
|
||||
import com.jero.common.util.MinioUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.docking.utils.IntekeyUtils;
|
||||
import com.jero.modules.laws.home.dto.LawsHomeNormalSearchDTO;
|
||||
import com.jero.modules.laws.home.vo.LawsHomeNormalSearchVO;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author lqt
|
||||
* @version 1.0
|
||||
* @date 2023/11/27 17:41
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/home/search")
|
||||
public class SearchController {
|
||||
|
||||
|
||||
@PostMapping(value = "/download")
|
||||
private void downloadAndView(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("url") String url,
|
||||
@RequestParam("appCode") String appCode,
|
||||
@RequestParam("secretKey") String secretKey,
|
||||
@RequestParam("scope") Integer scope,
|
||||
HttpServletResponse response) {
|
||||
try (InputStream inputStream = IntekeyUtils.DecryptFile(url, appCode, secretKey, scope, file);
|
||||
OutputStream outputStream = response.getOutputStream()
|
||||
) {
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
response.flushBuffer();
|
||||
} catch (Exception e) {
|
||||
response.setStatus(404);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -107,13 +107,13 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new JeroBootException(ResultCommon.ERROR);
|
||||
response.setStatus(404);
|
||||
}
|
||||
|
||||
String contentType = response.getContentType();
|
||||
String fileName = getFileName(response);
|
||||
|
||||
MultipartFile file = getMultipartFile(responseBody, contentType, fileName);
|
||||
MultipartFile file = getMultipartFile(response,responseBody, contentType, fileName);
|
||||
// 访问路径
|
||||
String str = request.getRequestURI();
|
||||
|
||||
@@ -127,12 +127,12 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
|
||||
}else if(b1){
|
||||
// 下载文件 先解密,判断组织域,加密
|
||||
try (InputStream is = IntekeyUtils.DecryptFile(decryptUrl, decryptAppCode, decryptSecretKey, null, file)) {
|
||||
MultipartFile fileDecrypt = getMultipartFile(is, contentType, fileName);
|
||||
MultipartFile fileDecrypt = getMultipartFile(response,is, contentType, fileName);
|
||||
int scope = getScope();
|
||||
// 加密
|
||||
encryptFile(response, fileDecrypt, scope);
|
||||
} catch (Exception e) {
|
||||
throw new JeroBootException(ResultCommon.ERROR);
|
||||
response.setStatus(404);
|
||||
}
|
||||
|
||||
}else{
|
||||
@@ -166,7 +166,7 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
|
||||
try (InputStream is = IntekeyUtils.DecryptFile(decryptUrl, decryptAppCode, decryptSecretKey, scope, file)) {
|
||||
writeResponse(response, is);
|
||||
} catch (Exception e) {
|
||||
throw new JeroBootException(ResultCommon.ERROR);
|
||||
response.setStatus(404);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,18 +174,18 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
|
||||
try (InputStream is = IntekeyUtils.DecryptFile(encryptUrl, encryptAppCode, encryptSecretKey, scope, file)) {
|
||||
writeResponse(response, is);
|
||||
} catch (Exception e) {
|
||||
throw new JeroBootException(ResultCommon.ERROR);
|
||||
response.setStatus(404);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private MultipartFile getMultipartFile(InputStream responseBody,String contentType,String fileName) {
|
||||
MultipartFile file;
|
||||
private MultipartFile getMultipartFile(HttpServletResponse response,InputStream responseBody,String contentType,String fileName) {
|
||||
MultipartFile file = null;
|
||||
try {
|
||||
file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(),fileName,contentType, responseBody);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new JeroBootException(ResultCommon.ERROR);
|
||||
response.setStatus(404);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
-10
@@ -595,12 +595,8 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
|
||||
|
||||
JSONObject sort = new JSONObject();
|
||||
Map<String,Object> issueTimeDesc = new HashMap<>();
|
||||
Map<String,Object> issueTimeAsc = new HashMap<>();
|
||||
Map<String,Object> issueTime = new HashMap<>();
|
||||
issueTimeDesc.put("order","desc");
|
||||
issueTimeAsc.put("order","asc");
|
||||
issueTime.put(RESOURCE_TYPE,issueTimeAsc);
|
||||
issueTime.put(STANDARD_TYPE,issueTimeDesc);
|
||||
issueTime.put(CREATE_TIME,issueTimeDesc);
|
||||
sort.putAll(issueTime);
|
||||
IPage page = getIPage(searchContent, queryMapJsonAll, mapHighlight1,
|
||||
@@ -902,11 +898,6 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
|
||||
obj.setApplicableVehicle(lawsDomesticStandard.getApplicableVehicle());
|
||||
obj.setStandardProperty(lawsDomesticStandard.getStandardProperty());
|
||||
obj.setStandardState(lawsDomesticStandard.getStandardState());
|
||||
if(Objects.equals(lawsDomesticStandard.getStandardClass(),"GB")){
|
||||
obj.setStandardType("2");
|
||||
}else if(Objects.equals(lawsDomesticStandard.getStandardClass(),"GB/T")){
|
||||
obj.setStandardType("1");
|
||||
}
|
||||
List<OSSFile> listFile = getOssFilesLawsDomesticStandard(lawsDomesticStandard);
|
||||
updateES(opType, obj, listFile, lawsDomesticStandard.getId());
|
||||
}catch (Exception e){
|
||||
@@ -1202,7 +1193,6 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
|
||||
map.put(STANDARD_CODE,obj.getStandardCode());
|
||||
map.put(ENTERPRISE_STANDARD_STATE,obj.getEnterpriseStandardState());
|
||||
map.put(GRADE_CLASSIFICATION,obj.getGradeClassification());
|
||||
map.put(STANDARD_TYPE,obj.getStandardType());
|
||||
map.put(CREATE_TIME,new Date());
|
||||
//添加es
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(map));
|
||||
|
||||
@@ -432,7 +432,7 @@ adminRoleCode: admin
|
||||
|
||||
# 文件下载加解密
|
||||
download:
|
||||
enable: true
|
||||
enable: false
|
||||
# 文件下载、预览拦截路径,多个以逗号分隔
|
||||
download_url: /sys/common/download/
|
||||
view_url: /sys/common/view/
|
||||
|
||||
Reference in New Issue
Block a user