|
|
@ -153,7 +153,7 @@ public class AppServiceImpl implements AppService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Res<?> getMyTasks(Integer page, Integer size,Boolean isData) { |
|
|
|
|
|
|
|
|
public Res<?> getMyTasks(Integer page, Integer size,Boolean isData,Integer appId) { |
|
|
|
|
|
|
|
|
if (page == null || page < 1) { |
|
|
if (page == null || page < 1) { |
|
|
page = 1; |
|
|
page = 1; |
|
|
@ -173,6 +173,7 @@ public class AppServiceImpl implements AppService { |
|
|
|
|
|
|
|
|
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>(); |
|
|
wrapper.eq(Task::getDel, 0) |
|
|
wrapper.eq(Task::getDel, 0) |
|
|
|
|
|
.eq(Task::getAppId,appId) |
|
|
.eq(userId != null, Task::getUserId, userId) |
|
|
.eq(userId != null, Task::getUserId, userId) |
|
|
.orderByDesc(Task::getCreateTime); |
|
|
.orderByDesc(Task::getCreateTime); |
|
|
|
|
|
|
|
|
@ -182,106 +183,8 @@ public class AppServiceImpl implements AppService { |
|
|
List<Task> tasks = result.getRecords(); |
|
|
List<Task> tasks = result.getRecords(); |
|
|
for (Task task : tasks) { |
|
|
for (Task task : tasks) { |
|
|
String taskId = task.getId(); |
|
|
String taskId = task.getId(); |
|
|
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
|
|
|
|
|
credentialsProvider.setCredentials( |
|
|
|
|
|
AuthScope.ANY, |
|
|
|
|
|
new UsernamePasswordCredentials(esUser, esPassword) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
CloseableHttpClient httpClient = null; |
|
|
|
|
|
try { |
|
|
|
|
|
if (esUser != null && !esUser.trim().equals("")) { |
|
|
|
|
|
httpClient = HttpClients.custom() |
|
|
|
|
|
.setDefaultCredentialsProvider(credentialsProvider) |
|
|
|
|
|
.build(); |
|
|
|
|
|
} else { |
|
|
|
|
|
httpClient = HttpClients.custom().build(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ================== 构建查询 DSL ================== |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> query = new HashMap<String, Object>(); |
|
|
|
|
|
// must 条件 |
|
|
|
|
|
List<Map<String, Object>> mustList = new ArrayList<Map<String, Object>>(); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> termDel = new HashMap<String, Object>(); |
|
|
|
|
|
termDel.put("del", 0); |
|
|
|
|
|
Map<String, Object> termDelWrap = new HashMap<String, Object>(); |
|
|
|
|
|
termDelWrap.put("term", termDel); |
|
|
|
|
|
mustList.add(termDelWrap); |
|
|
|
|
|
//任务id查询条件 |
|
|
|
|
|
Map<String, Object> termTaskId = new HashMap<String, Object>(); |
|
|
|
|
|
termTaskId.put("taskId", taskId); |
|
|
|
|
|
Map<String, Object> termTaskIdWrap = new HashMap<String, Object>(); |
|
|
|
|
|
termTaskIdWrap.put("term", termTaskId); |
|
|
|
|
|
mustList.add(termTaskIdWrap); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> bool = new HashMap<String, Object>(); |
|
|
|
|
|
bool.put("must", mustList); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> queryBody = new HashMap<String, Object>(); |
|
|
|
|
|
queryBody.put("bool", bool); |
|
|
|
|
|
|
|
|
|
|
|
query.put("query", queryBody); |
|
|
|
|
|
|
|
|
|
|
|
// sort |
|
|
|
|
|
List<Map<String, Object>> sortList = new ArrayList<Map<String, Object>>(); |
|
|
|
|
|
Map<String, Object> order = new HashMap<String, Object>(); |
|
|
|
|
|
order.put("order", "desc"); |
|
|
|
|
|
Map<String, Object> sortField = new HashMap<String, Object>(); |
|
|
|
|
|
sortField.put("createTime", order); |
|
|
|
|
|
sortList.add(sortField); |
|
|
|
|
|
query.put("sort", sortList); |
|
|
|
|
|
log.info("任务数据查询条件:{}",JSONObject.toJSONString(query)); |
|
|
|
|
|
|
|
|
|
|
|
// ================== 发起 HTTP 请求 ================== |
|
|
|
|
|
StringBuffer host = new StringBuffer(); |
|
|
|
|
|
host.append(esUrl) |
|
|
|
|
|
.append("/") |
|
|
|
|
|
.append(indexName) |
|
|
|
|
|
.append("/_search"); |
|
|
|
|
|
|
|
|
|
|
|
HttpPost httpPost = new HttpPost(host.toString()); |
|
|
|
|
|
httpPost.setHeader("Content-Type", "application/json"); |
|
|
|
|
|
|
|
|
|
|
|
StringEntity entity = new StringEntity( |
|
|
|
|
|
JSONObject.toJSONString(query), |
|
|
|
|
|
ContentType.APPLICATION_JSON |
|
|
|
|
|
); |
|
|
|
|
|
httpPost.setEntity(entity); |
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = httpClient.execute(httpPost); |
|
|
|
|
|
int statusCode = response.getStatusLine().getStatusCode(); |
|
|
|
|
|
String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
if (statusCode != 200) { |
|
|
|
|
|
log.error("ES 查询失败 status={}, body={}", statusCode, responseBody); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ================== 解析返回 ================== |
|
|
|
|
|
JSONObject json = JSONObject.parseObject(responseBody); |
|
|
|
|
|
JSONObject hits = json.getJSONObject("hits"); |
|
|
|
|
|
|
|
|
|
|
|
List<AppResultDoc> list = new ArrayList<AppResultDoc>(); |
|
|
|
|
|
JSONArray hitList = hits.getJSONArray("hits"); |
|
|
|
|
|
for (int i = 0; i < hitList.size(); i++) { |
|
|
|
|
|
JSONObject source = hitList.getJSONObject(i).getJSONObject("_source"); |
|
|
|
|
|
AppResultDoc item = source.toJavaObject(AppResultDoc.class); |
|
|
|
|
|
list.add(item); |
|
|
|
|
|
} |
|
|
|
|
|
task.setData(list); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("查询用户任务失败 userId={}", userId, e); |
|
|
|
|
|
continue; |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (httpClient != null) { |
|
|
|
|
|
try { |
|
|
|
|
|
httpClient.close(); |
|
|
|
|
|
} catch (Exception ignored) {} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
List<AppResultDoc> list = getAppData(taskId); |
|
|
|
|
|
task.setData(list); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
log.info("任务查询成功"); |
|
|
log.info("任务查询成功"); |
|
|
@ -292,6 +195,114 @@ public class AppServiceImpl implements AppService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 根据任务id查询是数据 |
|
|
|
|
|
* @param taskId |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<AppResultDoc> getAppData(String taskId) { |
|
|
|
|
|
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
|
|
|
|
|
credentialsProvider.setCredentials( |
|
|
|
|
|
AuthScope.ANY, |
|
|
|
|
|
new UsernamePasswordCredentials(esUser, esPassword) |
|
|
|
|
|
); |
|
|
|
|
|
List<AppResultDoc> list = new ArrayList<AppResultDoc>(); |
|
|
|
|
|
CloseableHttpClient httpClient = null; |
|
|
|
|
|
try { |
|
|
|
|
|
if (esUser != null && !esUser.trim().equals("")) { |
|
|
|
|
|
httpClient = HttpClients.custom() |
|
|
|
|
|
.setDefaultCredentialsProvider(credentialsProvider) |
|
|
|
|
|
.build(); |
|
|
|
|
|
} else { |
|
|
|
|
|
httpClient = HttpClients.custom().build(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ================== 构建查询 DSL ================== |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> query = new HashMap<String, Object>(); |
|
|
|
|
|
// must 条件 |
|
|
|
|
|
List<Map<String, Object>> mustList = new ArrayList<Map<String, Object>>(); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> termDel = new HashMap<String, Object>(); |
|
|
|
|
|
termDel.put("del", 0); |
|
|
|
|
|
Map<String, Object> termDelWrap = new HashMap<String, Object>(); |
|
|
|
|
|
termDelWrap.put("term", termDel); |
|
|
|
|
|
mustList.add(termDelWrap); |
|
|
|
|
|
//任务id查询条件 |
|
|
|
|
|
Map<String, Object> termTaskId = new HashMap<String, Object>(); |
|
|
|
|
|
termTaskId.put("taskId", taskId); |
|
|
|
|
|
Map<String, Object> termTaskIdWrap = new HashMap<String, Object>(); |
|
|
|
|
|
termTaskIdWrap.put("term", termTaskId); |
|
|
|
|
|
mustList.add(termTaskIdWrap); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> bool = new HashMap<String, Object>(); |
|
|
|
|
|
bool.put("must", mustList); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> queryBody = new HashMap<String, Object>(); |
|
|
|
|
|
queryBody.put("bool", bool); |
|
|
|
|
|
|
|
|
|
|
|
query.put("query", queryBody); |
|
|
|
|
|
|
|
|
|
|
|
// sort |
|
|
|
|
|
List<Map<String, Object>> sortList = new ArrayList<Map<String, Object>>(); |
|
|
|
|
|
Map<String, Object> order = new HashMap<String, Object>(); |
|
|
|
|
|
order.put("order", "desc"); |
|
|
|
|
|
Map<String, Object> sortField = new HashMap<String, Object>(); |
|
|
|
|
|
sortField.put("createTime", order); |
|
|
|
|
|
sortList.add(sortField); |
|
|
|
|
|
query.put("sort", sortList); |
|
|
|
|
|
log.info("任务数据查询条件:{}",JSONObject.toJSONString(query)); |
|
|
|
|
|
|
|
|
|
|
|
// ================== 发起 HTTP 请求 ================== |
|
|
|
|
|
StringBuffer host = new StringBuffer(); |
|
|
|
|
|
host.append(esUrl) |
|
|
|
|
|
.append("/") |
|
|
|
|
|
.append(indexName) |
|
|
|
|
|
.append("/_search"); |
|
|
|
|
|
|
|
|
|
|
|
HttpPost httpPost = new HttpPost(host.toString()); |
|
|
|
|
|
httpPost.setHeader("Content-Type", "application/json"); |
|
|
|
|
|
|
|
|
|
|
|
StringEntity entity = new StringEntity( |
|
|
|
|
|
JSONObject.toJSONString(query), |
|
|
|
|
|
ContentType.APPLICATION_JSON |
|
|
|
|
|
); |
|
|
|
|
|
httpPost.setEntity(entity); |
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = httpClient.execute(httpPost); |
|
|
|
|
|
int statusCode = response.getStatusLine().getStatusCode(); |
|
|
|
|
|
String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
if (statusCode != 200) { |
|
|
|
|
|
log.error("ES 查询失败 taskId={},status={}, body={}", taskId,statusCode, responseBody); |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ================== 解析返回 ================== |
|
|
|
|
|
JSONObject json = JSONObject.parseObject(responseBody); |
|
|
|
|
|
JSONObject hits = json.getJSONObject("hits"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray hitList = hits.getJSONArray("hits"); |
|
|
|
|
|
for (int i = 0; i < hitList.size(); i++) { |
|
|
|
|
|
JSONObject source = hitList.getJSONObject(i).getJSONObject("_source"); |
|
|
|
|
|
AppResultDoc item = source.toJavaObject(AppResultDoc.class); |
|
|
|
|
|
list.add(item); |
|
|
|
|
|
} |
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("查询任务数据失败 taskId={}", taskId, e); |
|
|
|
|
|
return list; |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (httpClient != null) { |
|
|
|
|
|
try { |
|
|
|
|
|
httpClient.close(); |
|
|
|
|
|
} catch (Exception ignored) {} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
@Override |
|
|
@Override |
|
|
public Res<?> dataSave(AppResultDoc appData) { |
|
|
public Res<?> dataSave(AppResultDoc appData) { |
|
|
String docId = UUID.randomUUID().toString().replace("-", Constants.EMPTY); |
|
|
String docId = UUID.randomUUID().toString().replace("-", Constants.EMPTY); |
|
|
@ -302,6 +313,7 @@ public class AppServiceImpl implements AppService { |
|
|
log.error("启动应用记录写入异常, appData={}", appData); |
|
|
log.error("启动应用记录写入异常, appData={}", appData); |
|
|
Task task = new Task(); |
|
|
Task task = new Task(); |
|
|
task.setId(appData.getTaskId()); |
|
|
task.setId(appData.getTaskId()); |
|
|
|
|
|
task.setAppId(appData.getAppId()); |
|
|
task.setStatus(appData.getStatus()); |
|
|
task.setStatus(appData.getStatus()); |
|
|
task.setFinishTime(LocalDateTime.now()); |
|
|
task.setFinishTime(LocalDateTime.now()); |
|
|
task.setStatus(2); |
|
|
task.setStatus(2); |
|
|
@ -312,6 +324,7 @@ public class AppServiceImpl implements AppService { |
|
|
log.info("任务状态更新"); |
|
|
log.info("任务状态更新"); |
|
|
Task task = new Task(); |
|
|
Task task = new Task(); |
|
|
task.setId(appData.getTaskId()); |
|
|
task.setId(appData.getTaskId()); |
|
|
|
|
|
task.setAppId(appData.getAppId()); |
|
|
task.setStatus(appData.getStatus()); |
|
|
task.setStatus(appData.getStatus()); |
|
|
task.setFinishTime(LocalDateTime.now()); |
|
|
task.setFinishTime(LocalDateTime.now()); |
|
|
task.setStatus(appData.getStatus()); |
|
|
task.setStatus(appData.getStatus()); |
|
|
@ -384,5 +397,11 @@ public class AppServiceImpl implements AppService { |
|
|
} catch (Exception ignored){} |
|
|
} catch (Exception ignored){} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
@Override |
|
|
|
|
|
public Res<?> getAppResById(String id) { |
|
|
|
|
|
// TODO Auto-generated method stub |
|
|
|
|
|
List<AppResultDoc> list = getAppData(id); |
|
|
|
|
|
return Res.ok(list); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |