Commit e8dd7310 authored by suhuiguang's avatar suhuiguang

1.立即刷新

parent c53d8586
...@@ -24,8 +24,12 @@ public class ESPlanTaskListDto { ...@@ -24,8 +24,12 @@ public class ESPlanTaskListDto {
@Id @Id
private String id;
@Field(type = FieldType.Text)
private String planTaskId; private String planTaskId;
@Field(type = FieldType.Text) @Field(type = FieldType.Text)
private String orgCode; private String orgCode;
......
...@@ -35,12 +35,23 @@ public class PlanTaskDetail extends BasicEntity { ...@@ -35,12 +35,23 @@ public class PlanTaskDetail extends BasicEntity {
@Column(name="executor_id") @Column(name="executor_id")
private String executorId; private String executorId;
@Transient
public String getName() {
return name;
}
@Transient
public String getPointNo() {
return pointNo;
}
/** /**
* 点名称 * 点名称
*/ */
@Column(name="name") @Column(name="name")
private String name; private String name;
/** /**
* 点编号 * 点编号
*/ */
......
...@@ -61,6 +61,8 @@ import org.elasticsearch.action.bulk.BulkRequest; ...@@ -61,6 +61,8 @@ import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
...@@ -1028,6 +1030,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -1028,6 +1030,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
ESPlanTaskListDto esPlanTaskListDto = JSONObject.parseObject(toJSONString(planTask), ESPlanTaskListDto esPlanTaskListDto = JSONObject.parseObject(toJSONString(planTask),
ESPlanTaskListDto.class); ESPlanTaskListDto.class);
esPlanTaskListDto.setPlanTaskId(String.valueOf(planTask.getId())); esPlanTaskListDto.setPlanTaskId(String.valueOf(planTask.getId()));
esPlanTaskListDto.setId(String.valueOf(planTask.getId()));
esPlanTaskListDto.setPlanId(String.valueOf(plan.getId())); esPlanTaskListDto.setPlanId(String.valueOf(plan.getId()));
esPlanTaskListDto.setTaskName(plan.getName()); esPlanTaskListDto.setTaskName(plan.getName());
esPlanTaskListDto.setType(planType); esPlanTaskListDto.setType(planType);
...@@ -1811,7 +1814,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -1811,7 +1814,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
private void saveMustData(List<ESTaskDetailDto> esTaskDetailDtos, List<ESPlanTaskListDto> esPlanTaskListDtos, List<PlanTask> planTasks) { private void saveMustData(List<ESTaskDetailDto> esTaskDetailDtos, List<ESPlanTaskListDto> esPlanTaskListDtos, List<PlanTask> planTasks) {
// 保存es数据 // 保存es数据
CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> saveTasks(esTaskDetailDtos), asyncServiceExecutor); CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> savePlanTaskDetails(esTaskDetailDtos), asyncServiceExecutor);
CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> savePlanTasks(esPlanTaskListDtos), asyncServiceExecutor); CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> savePlanTasks(esPlanTaskListDtos), asyncServiceExecutor);
// 更新统计数据表 // 更新统计数据表
CompletableFuture<Void> future3 = CompletableFuture.runAsync(() -> updateStaticTable(planTasks), asyncServiceExecutor); CompletableFuture<Void> future3 = CompletableFuture.runAsync(() -> updateStaticTable(planTasks), asyncServiceExecutor);
...@@ -1819,11 +1822,11 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -1819,11 +1822,11 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
allOfFuture.join(); allOfFuture.join();
} }
private void saveTasks(List<ESTaskDetailDto> esTaskDetailDtos) { private void savePlanTaskDetails(List<ESTaskDetailDto> esTaskDetailDtos) {
try { try {
List<EsEntity<ESTaskDetailDto>> batchList = esTaskDetailDtos.stream() List<EsEntity<ESTaskDetailDto>> batchList = esTaskDetailDtos.stream()
.map(item -> new EsEntity<>(item.getId().toString(), item)).collect(Collectors.toList()); .map(item -> new EsEntity<>(item.getId().toString(), item)).collect(Collectors.toList());
this.insertBatch("web_app_task_detail", batchList); this.updateBatch("web_app_task_detail", batchList);
// esTaskDetail.saveAll(esTaskDetailDtos); // esTaskDetail.saveAll(esTaskDetailDtos);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
...@@ -1848,12 +1851,32 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -1848,12 +1851,32 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
} }
} }
/**
* Description: 批量修改数据
*
* @param index index
* @param list 更新列表
* @author LiuLin
*/
public <T> void updateBatch(String index, List<EsEntity<T>> list) {
BulkRequest request = new BulkRequest();
list.forEach(item -> request.add(new UpdateRequest(index, item.getId())
.doc(JSON.toJSONString(item.getData()), XContentType.JSON)));
try {
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
restHighLevelClient.bulk(request, RequestOptions.DEFAULT);
list.forEach(s -> log.info("===========索引:【{}】,主键:【{}】修改成功", index, s.getId()));
} catch (Exception e) {
log.error("索引:[{}]", index, e);
}
}
private void savePlanTasks(List<ESPlanTaskListDto> esPlanTaskListDtos) { private void savePlanTasks(List<ESPlanTaskListDto> esPlanTaskListDtos) {
try { try {
// esPlanTaskList.saveAll(esPlanTaskListDtos); // esPlanTaskList.saveAll(esPlanTaskListDtos);
List<EsEntity<ESPlanTaskListDto>> batchList = esPlanTaskListDtos.stream() List<EsEntity<ESPlanTaskListDto>> batchList = esPlanTaskListDtos.stream()
.map(item -> new EsEntity<>(item.getPlanTaskId(), item)).collect(Collectors.toList()); .map(item -> new EsEntity<>(item.getPlanTaskId(), item)).collect(Collectors.toList());
this.insertBatch("web_app_plan_task_list", batchList); this.updateBatch("web_app_plan_task_list", batchList);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
......
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