Commit 66f5f6fe authored by tianyiming's avatar tianyiming

更新索引--涉及任务下发、定时器修改、任务执行

parent d7eb215f
...@@ -24,7 +24,7 @@ public class ESPlanTaskListDto { ...@@ -24,7 +24,7 @@ public class ESPlanTaskListDto {
private String planTaskId; private String planTaskId;
@Field(type = FieldType.Text) @Field(type = FieldType.Text)
private String OrgCode; private String orgCode;
@Field(type = FieldType.Text) @Field(type = FieldType.Text)
private String planId; private String planId;
......
...@@ -270,4 +270,6 @@ public interface PlanTaskMapper extends BaseMapper { ...@@ -270,4 +270,6 @@ public interface PlanTaskMapper extends BaseMapper {
int deleteDate(String table); int deleteDate(String table);
Long selectRoutId(String id); Long selectRoutId(String id);
List<String> selectPlanTaskIdLists(long planId, int status, int status1);
} }
package com.yeejoin.amos.patrol.config;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
@Configuration
public class ElasticSearchClientConfig {
@Value("${spring.elasticsearch.rest.uris}")
private String uris;
@Value("${elasticsearch.username}")
private String username;
@Value("${elasticsearch.password}")
private String password;
@Bean(destroyMethod = "close")
public RestHighLevelClient restHighLevelClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password));
try {
HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new);
RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
});
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
builder.setRequestConfigCallback(requestConfigBuilder -> {
// 连接超时(默认为1秒)
return requestConfigBuilder.setConnectTimeout(5000 * 1000)
// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
.setSocketTimeout(6000 * 1000);
});
return new RestHighLevelClient(builder);
} catch (Exception e) {
throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e);
}
}
}
...@@ -218,6 +218,9 @@ public class JobService implements IJobService { ...@@ -218,6 +218,9 @@ public class JobService implements IJobService {
planTaskMapper.updatePlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue()); planTaskMapper.updatePlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
updateEsPlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue()); updateEsPlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
} }
} else {
planTaskMapper.updatePlanTaskList(ids, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
updateEsPlanTaskList(ids, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
} }
} }
planTaskAddJob(planTask); planTaskAddJob(planTask);
...@@ -243,6 +246,9 @@ public class JobService implements IJobService { ...@@ -243,6 +246,9 @@ public class JobService implements IJobService {
planTaskMapper.updatePlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue()); planTaskMapper.updatePlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
updateEsPlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue()); updateEsPlanTaskList(newList, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
} }
} else {
planTaskMapper.updatePlanTaskList(ids, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
updateEsPlanTaskList(ids, PlanTaskFinishStatusEnum.UNDERWAY.getValue());
} }
} }
} }
...@@ -296,10 +302,24 @@ public class JobService implements IJobService { ...@@ -296,10 +302,24 @@ public class JobService implements IJobService {
} }
private void updatePlanTaskAndDetailStatus(PlanTask planTask) { private void updatePlanTaskAndDetailStatus(PlanTask planTask) {
List<String> esIds = planTaskMapper.selectPlanTaskIdList(planTask.getPlanId(), PlanTaskFinishStatusEnum.UNDERWAY.getValue()); List<String> esIds = planTaskMapper.selectPlanTaskIdLists(planTask.getPlanId(), PlanTaskFinishStatusEnum.UNDERWAY.getValue(),PlanTaskFinishStatusEnum.NOTSTARTED.getValue());
if(esIds.size() > 0) { if(esIds.size() > 0) {
planTaskMapper.updatePlanTaskList(esIds, PlanTaskFinishStatusEnum.OVERTIME.getValue()); if (!ObjectUtils.isEmpty(esIds)) {
updateEsPlanTaskList(esIds, PlanTaskFinishStatusEnum.OVERTIME.getValue()); if (esIds.size() > 10000) {
int index = 10000;
for (int i = 0; i < esIds.size(); i += 10000) {
if (i + 10000 > esIds.size()) {
index = esIds.size() - i;
}
List<String> newList = esIds.subList(i, i + index);
planTaskMapper.updatePlanTaskList(newList, PlanTaskFinishStatusEnum.OVERTIME.getValue());
updateEsPlanTaskList(newList, PlanTaskFinishStatusEnum.OVERTIME.getValue());
}
} else {
planTaskMapper.updatePlanTaskList(esIds, PlanTaskFinishStatusEnum.OVERTIME.getValue());
updateEsPlanTaskList(esIds, PlanTaskFinishStatusEnum.OVERTIME.getValue());
}
}
} }
List<Long> ids = new ArrayList<>(); List<Long> ids = new ArrayList<>();
ids.add(planTask.getId()); ids.add(planTask.getId());
......
...@@ -1735,4 +1735,14 @@ ...@@ -1735,4 +1735,14 @@
<select id="selectRoutId" resultType="java.lang.Long"> <select id="selectRoutId" resultType="java.lang.Long">
select route_id from p_plan_task where id = #{id} select route_id from p_plan_task where id = #{id}
</select> </select>
<select id="selectPlanTaskIdLists" resultType="java.lang.String">
SELECT
id
FROM
"p_plan_task"
WHERE
plan_id = #{planId}
AND (finish_status = #{status} or finish_status = #{status1} )
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment