一般检索修改

This commit is contained in:
梁琦涛
2023-11-16 17:43:15 +08:00
parent 0e721c3865
commit fe55c82048
4 changed files with 63 additions and 43 deletions
@@ -1,89 +0,0 @@
package com.jero.modules.laws.common.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
import org.springframework.util.DigestUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
/**
* intekey解密文件相关
*/
public class IntekeyUtils {
private static final Logger logger = LoggerFactory.getLogger(IntekeyUtils.class);
/**
* 解密文件,返回InputStream,供excel使用
*
*
* @param url
* @param multipartFile
* @return
*/
//todo 这个方法需要写在laws-modules-docking 里面 可以新建一个文件夹是encrypt
public static InputStream DecryptFile(String url, String appCode, String secretKey, String scope, MultipartFile multipartFile) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
logger.info("解密时间:" + format.format(new Date()));
//设置校验
Long time = System.currentTimeMillis();
String sign = DigestUtils.md5DigestAsHex((secretKey + time).getBytes());
url = url + "?appCode=" + appCode + "&time=" + time + "&sign=" + sign + "&scope=" + scope;
File file = transferToFile(multipartFile);
RestTemplate restTemplate = new RestTemplate();
//设置请求头
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("multipart/form-data");
headers.setContentType(type);
//设置请求体,注意是LinkedMultiValueMap
FileSystemResource fileSystemResource = new FileSystemResource(file);
MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
form.add("file", fileSystemResource);
form.add("filename", multipartFile.getOriginalFilename());
//用HttpEntity封装整个请求报文
HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(form, headers);
System.out.println(url);
ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, files, byte[].class);
System.out.println(entity.getStatusCode().value() + ","+ entity.getStatusCode().getReasonPhrase() + "," + Objects.requireNonNull(entity.getBody()).length);
byte[] body = entity.getBody();
InputStream sbs = new ByteArrayInputStream(body);
return sbs;
}
private static File transferToFile(MultipartFile multipartFile) {
// 选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 。
File file = null;
try {
String originalFilename = multipartFile.getOriginalFilename();
int index = originalFilename.lastIndexOf(".");
//String[] filename = originalFilename.split("\\.");
file = File.createTempFile(originalFilename.substring(0, index), originalFilename.substring(index + 1));
file.delete();
multipartFile.transferTo(file);
file.deleteOnExit();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
public static void main(String args[]) {
String originalFilename = "C:\\Users\\LQT\\Desktop\\参考代码 - 副本.txt";
int index = originalFilename.lastIndexOf(".");
//String[] filename = originalFilename.split("\\.");
System.out.println(originalFilename.substring(0, index) + "||||||||||||" + originalFilename.substring(index + 1));
}
}
@@ -3,7 +3,6 @@ package com.jero.modules.laws.home.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.laws.common.util.IntekeyUtils;
import com.jero.modules.laws.home.dto.LawsHomeNormalSearchDTO;
import com.jero.modules.laws.home.service.ILawsHomeSearchService;
import com.jero.modules.laws.home.vo.LawsHomeNormalSearchStatisticsVO;
@@ -11,13 +10,12 @@ import com.jero.modules.laws.home.vo.LawsHomeNormalSearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
/**
* @author lqt
@@ -41,7 +39,6 @@ public class LawsHomeSearchController {
public Result<IPage<LawsHomeNormalSearchVO>> getNormalSearchTitlePage(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
// todo 待开发
return Result.OK(lawsHomeSearchService.getNormalSearchTitlePage(lawsHomeNormalSearchDTO,pageNo,pageSize));
}
@@ -49,7 +46,6 @@ public class LawsHomeSearchController {
@ApiOperation(value="首页-一般检索(标题)(数据统计)", notes="首页-一般检索(标题)(数据统计)")
@GetMapping(value = "/getNormalSearchTitleCount")
public Result<LawsHomeNormalSearchStatisticsVO> getNormalSearchTitleCount(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO) {
// todo 待开发
return Result.OK(lawsHomeSearchService.getNormalSearchTitleCount(lawsHomeNormalSearchDTO));
}
@@ -80,27 +76,4 @@ public class LawsHomeSearchController {
// todo 待开发
return Result.OK(lawsHomeSearchService.getAdvancedSearchPage(homeNormalSearchDTO,pageNo,pageSize));
}
/**
* 下载附件
*
*/
@PostMapping(value = "/download")
public void view(MultipartFile file,String url, String appCode, String secretKey, String 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){
log.error(e.getMessage());
response.setStatus(404);
e.printStackTrace();
}
}
}
@@ -332,7 +332,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getStandardCode().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getStandardCode(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -348,7 +348,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getEnterpriseStandardState().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getEnterpriseStandardState(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -364,7 +364,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getGradeClassification().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getGradeClassification(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -383,7 +383,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getStandardClass().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getStandardClass(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -399,7 +399,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getApplicableVehicle().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->!StringUtils.isBlank(o.getApplicableVehicle()) && Arrays.asList(o.getApplicableVehicle().split(",")).contains(dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -415,7 +415,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getStandardState().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getStandardState(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -434,7 +434,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getStandardClass().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getStandardClass(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -450,7 +450,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getDynamicType().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->!StringUtils.isBlank(o.getDynamicType()) && Arrays.asList(o.getDynamicType().split(",")).contains(dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -466,7 +466,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getApplicableVehicle().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->!StringUtils.isBlank(o.getApplicableVehicle()) && Arrays.asList(o.getApplicableVehicle().split(",")).contains(dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -482,7 +482,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getStandardProperty().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getStandardProperty(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);
@@ -498,7 +498,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(CollectionUtils.isEmpty(list)){
objVO.setStatisticsCount("0");
}else{
long l = list.stream().filter(o->Arrays.asList(o.getStandardState().split(",")).contains(dict.getValue())).count();
long l = list.stream().filter(o->Objects.equals(o.getStandardState(),dict.getValue())).count();
objVO.setStatisticsCount(String.valueOf(l));
}
listDict.add(objVO);