rev:es日志查询

This commit is contained in:
zhangzhiqiang
2023-06-02 11:26:57 +08:00
parent 9c590599d6
commit e75fb3216c
5 changed files with 74 additions and 8 deletions

View File

@@ -15,6 +15,9 @@ import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.nl.modules.system.domain.LogRepositoryDTO;
import org.nl.modules.system.enums.LevelEnum;
import org.nl.modules.system.repository.EsLogRepository;
@@ -53,8 +56,13 @@ public class EsLogServiceImpl implements EsLogService {
PageResult page = new PageResult();
if (logQuery != null){
BoolQueryBuilder query = QueryBuilders.boolQuery(); //requestMethod
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
queryBuilder.withSort(SortBuilders.fieldSort("@timestamp").unmappedType("date").order(SortOrder.DESC));
extractedParam(logQuery, query);
Iterable<LogRepositoryDTO> all = esLogRepository.search(query, PageRequest.of(logQuery.getPage()-1,logQuery.getSize(), Sort.by("@timestamp").descending()));
queryBuilder.withQuery(query);
queryBuilder.withPageable(PageRequest.of(logQuery.getPage()-1,logQuery.getSize()));
NativeSearchQuery build = queryBuilder.build();
Iterable<LogRepositoryDTO> all = esLogRepository.search(build);
page.addAll(((AggregatedPageImpl) all).getContent());
page.setTotal((int) ((AggregatedPageImpl) all).getTotalElements());
page.setPage(logQuery.getPage());

View File

@@ -29,12 +29,11 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Map;
/**
@@ -56,4 +55,63 @@ public class HandSetController {
public ResponseEntity<Object> setPrint(@RequestBody Map<String, String> whereJson) {
return new ResponseEntity<>(handSetService.setPrint(whereJson), HttpStatus.OK);
}
@RequestMapping("/{name}")
public void setPrint(HttpServletResponse response, @PathVariable String name) throws Exception {
downloadFile(response,"D:\\app\\file\\apl\\app-release.apk",name);
}
/**
* 附件下载
* @param response
* @param fileName
* @param path
* @return
* @throws Exception
*/
public void downloadFile(HttpServletResponse response, String path, String fileName) throws Exception {
if (fileName != null) {
//设置文件路径
File file = new File(path);
if (file.exists()) {
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
try {
response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("utf-8"),"ISO-8859-1")+".apk");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] buffer = new byte[1024];
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
OutputStream os = response.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
}

View File

@@ -841,7 +841,7 @@ public class HandPFOutIvtServiceImpl implements HandPFOutIvtService {
RLock lock = redisLock.getLock("QST_IVT_RAWASSISTISTOR02");
try {
// 尝试加锁最多等待1000ms上锁以后5s自动解锁
boolean isLock = lock.tryLock(5000, 5000, TimeUnit.MILLISECONDS);
boolean isLock = lock.tryLock(1000, 5000, TimeUnit.MILLISECONDS);
if (isLock) {
//获取锁成功,执行对应的业务逻辑

View File

@@ -523,7 +523,7 @@ public class EmptyVehicleServiceImpl implements EmptyVehicleService {
JSONObject obj = jo.getJSONObject("obj");
String vehicle_code = (String) jsonObject.get("vehicle_code");
JSONArray has = line_wql.query("storagevehicle_code = '" + vehicle_code + "' and workorder_id = " + obj.getString("workorder_id") + "'").getResultJSONArray(0);
JSONArray has = line_wql.query("storagevehicle_code = '" + vehicle_code + "' and workorder_id = '" + obj.getString("workorder_id") + "'").getResultJSONArray(0);
JSONObject vehicle = vehicle_wql.query("storagevehicle_code = '" + vehicle_code + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(vehicle)){

View File

@@ -726,7 +726,7 @@ public abstract class AbstractInManage {
try {
// 尝试加锁最多等待1000ms上锁以后5s自动解锁
boolean isLock = lock.tryLock(5000, 5000, TimeUnit.MILLISECONDS);
boolean isLock = lock.tryLock(1000, 5000, TimeUnit.MILLISECONDS);
if (isLock) {//获取锁成功,执行对应的业务逻辑
//调用分配货位sql
JSONObject struct_jo = WQL.getWO("QST_IVT_RAWASSISTISTOR02").addParamMap(struct_map).process().uniqueResult(0);