更正 获取的当前用户ui设置接口实现逻辑
This commit is contained in:
+20
@@ -1,12 +1,18 @@
|
|||||||
package com.gzzn.omms.adminapi.controller.history;
|
package com.gzzn.omms.adminapi.controller.history;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.gzzn.omms.adminapi.dto.ResponseDto;
|
import com.gzzn.omms.adminapi.dto.ResponseDto;
|
||||||
@@ -14,6 +20,7 @@ import com.gzzn.omms.adminapi.dto.history.HistoryFilghtConditionDto;
|
|||||||
import com.gzzn.omms.adminapi.elasticsearch.ElasticsearchUtil;
|
import com.gzzn.omms.adminapi.elasticsearch.ElasticsearchUtil;
|
||||||
import com.gzzn.omms.adminapi.elasticsearch.EsPage;
|
import com.gzzn.omms.adminapi.elasticsearch.EsPage;
|
||||||
import com.gzzn.omms.adminapi.utils.DateUtils;
|
import com.gzzn.omms.adminapi.utils.DateUtils;
|
||||||
|
import com.gzzn.omms.adminapi.utils.GzznFileUtils;
|
||||||
/**
|
/**
|
||||||
* 历史航班数据 controller
|
* 历史航班数据 controller
|
||||||
* @author fhc
|
* @author fhc
|
||||||
@@ -57,4 +64,17 @@ public class HistoryFlightDataController {
|
|||||||
EsPage page = ElasticsearchUtil.searchDataPage(INDEX_NAME, OPLOG_ES_TYPE, pageIndex, pageSize, boolQuery, null, null, null);
|
EsPage page = ElasticsearchUtil.searchDataPage(INDEX_NAME, OPLOG_ES_TYPE, pageIndex, pageSize, boolQuery, null, null, null);
|
||||||
return ResponseDto.success(page);
|
return ResponseDto.success(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="/findTest/{log_type}",method = RequestMethod.GET)
|
||||||
|
public ResponseDto<EsPage> findTest(@PathVariable String log_type){
|
||||||
|
//获取查询条件script
|
||||||
|
String script = GzznFileUtils.getFileContent("/es/findTest.query");
|
||||||
|
//封装参数 分页等参数全都放入此处
|
||||||
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
params.put("log_type", log_type);
|
||||||
|
params.put("from", 1);
|
||||||
|
params.put("size", 10);
|
||||||
|
//执行查询
|
||||||
|
return ResponseDto.success(ElasticsearchUtil.searchDataPageByScript(INDEX_NAME, params, script,1,10));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,15 +82,15 @@ public class UISettingsController {
|
|||||||
List<Uisettings> uisettingsList = new ArrayList<Uisettings>();
|
List<Uisettings> uisettingsList = new ArrayList<Uisettings>();
|
||||||
if(!StringUtils.isEmpty(envCode) && !StringUtils.isEmpty(groupCode)){
|
if(!StringUtils.isEmpty(envCode) && !StringUtils.isEmpty(groupCode)){
|
||||||
//包括envCode、groupCode条件
|
//包括envCode、groupCode条件
|
||||||
uisettingsList = uisettingsDao.findByEnvCodeAndGroupCode(envCode,groupCode);
|
uisettingsList = uisettingsDao.findByEnvCodeAndGroupCodeAndUserid(envCode,groupCode,userService.getCurrentUserId());
|
||||||
}else{
|
}else{
|
||||||
if (!StringUtils.isEmpty(envCode) && StringUtils.isEmpty(groupCode)) {
|
if (!StringUtils.isEmpty(envCode) && StringUtils.isEmpty(groupCode)) {
|
||||||
//envCode条件
|
//envCode条件
|
||||||
uisettingsList = uisettingsDao.findByEnvCode(envCode);
|
uisettingsList = uisettingsDao.findByEnvCodeAndUserid(envCode,userService.getCurrentUserId());
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(envCode) && !StringUtils.isEmpty(groupCode)) {
|
if (StringUtils.isEmpty(envCode) && !StringUtils.isEmpty(groupCode)) {
|
||||||
//groupCode条件
|
//groupCode条件
|
||||||
uisettingsList = uisettingsDao.findByGroupCode(groupCode);
|
uisettingsList = uisettingsDao.findByGroupCodeAndUserid(groupCode,userService.getCurrentUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ public interface UisettingsDao extends CrudRepository<Uisettings,String>{
|
|||||||
//根据条件goupCode查询
|
//根据条件goupCode查询
|
||||||
List<Uisettings> findByGroupCode(String goupCode);
|
List<Uisettings> findByGroupCode(String goupCode);
|
||||||
|
|
||||||
|
//根据条件envCode、goupCode、userid查询
|
||||||
|
List<Uisettings> findByEnvCodeAndGroupCodeAndUserid(String envCode,String goupCode,String userid);
|
||||||
|
|
||||||
|
//根据条件envCode、userid查询
|
||||||
|
List<Uisettings> findByEnvCodeAndUserid(String envCode,String userid);
|
||||||
|
|
||||||
|
//根据条件goupCode、userid查询
|
||||||
|
List<Uisettings> findByGroupCodeAndUserid(String goupCode,String userid);
|
||||||
|
|
||||||
//保存
|
//保存
|
||||||
Uisettings save(Uisettings uisettings);
|
Uisettings save(Uisettings uisettings);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import org.elasticsearch.action.update.UpdateRequest;
|
|||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import org.elasticsearch.common.text.Text;
|
import org.elasticsearch.common.text.Text;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
|
import org.elasticsearch.script.ScriptType;
|
||||||
|
import org.elasticsearch.script.mustache.SearchTemplateRequestBuilder;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
@@ -365,4 +367,25 @@ public class ElasticsearchUtil {
|
|||||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EsPage searchDataPageByScript(String index,Map<String, Object> params, String script,int startPage,int pageSize) {
|
||||||
|
|
||||||
|
SearchResponse searchResponse = new SearchTemplateRequestBuilder(client)
|
||||||
|
.setScript(script)
|
||||||
|
.setScriptType(ScriptType.INLINE)
|
||||||
|
.setScriptParams(params)
|
||||||
|
.setRequest(client.prepareSearch(index).request())
|
||||||
|
.get()
|
||||||
|
.getResponse();
|
||||||
|
|
||||||
|
if (searchResponse.status().getStatus() == 200) {
|
||||||
|
|
||||||
|
long totalHits = searchResponse.getHits().totalHits;
|
||||||
|
// 解析对象
|
||||||
|
List<Map<String, Object>> sourceList = setSearchResponse(searchResponse, null);
|
||||||
|
|
||||||
|
return new EsPage(startPage, pageSize, (int) totalHits, sourceList);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.gzzn.omms.adminapi.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
/**
|
||||||
|
* @author fhc
|
||||||
|
* @Description: 文件工具类
|
||||||
|
* @date 2018年12月4日
|
||||||
|
*/
|
||||||
|
public class GzznFileUtils{
|
||||||
|
/**
|
||||||
|
* 读取文件的内容
|
||||||
|
* @param filePath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getFileContent(String filePath){
|
||||||
|
String content = null;
|
||||||
|
InputStream in = null;
|
||||||
|
InputStreamReader reader = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
try {
|
||||||
|
Resource resource = new ClassPathResource(filePath);
|
||||||
|
in = resource.getInputStream();
|
||||||
|
reader = new InputStreamReader(in);
|
||||||
|
br = new BufferedReader(reader);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String line = null;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
// 添加字符串
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
content = sb.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
try {
|
||||||
|
if(null!=br){
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
if(null!=reader){
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
if(null!=in){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"from" : "{{from}}",
|
||||||
|
"size" : "{{size}}",
|
||||||
|
"query": {
|
||||||
|
"match": {
|
||||||
|
"log_type": "{{log_type}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user