|
@@ -14,14 +14,19 @@ import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.service.business.TreeNodeService;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.NestedAggregation;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
|
import co.elastic.clients.elasticsearch.core.IndexResponse;
|
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
+import co.elastic.clients.json.JsonData;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.Value;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -197,6 +202,7 @@ public class EsCustomFieldService {
|
|
|
esCustomFieldHistory.setFieldType(fieldType);
|
|
|
esCustomFieldHistory.setCreateTime(createDate);
|
|
|
esCustomFieldHistory.setFieldValue(addValues);
|
|
|
+ esCustomFieldHistory.setSavedValue(esCustomField.getFieldValue());
|
|
|
esCustomFieldHistory.setHistoryType(optionType);
|
|
|
esCustomFieldHistory.setTaskId(taskId);
|
|
|
esCustomFieldHistory.setPersonId("1");
|
|
@@ -385,18 +391,80 @@ public class EsCustomFieldService {
|
|
|
/**
|
|
|
* 回退
|
|
|
*/
|
|
|
- public void BackTo(String historyId) throws Exception {
|
|
|
- //根据历史id获得历史
|
|
|
+ public void backTo(String historyId) throws Exception {
|
|
|
+ Hit<ESCustomFieldHistory> hit = this.getEsCustomFieldHistoryById(historyId);
|
|
|
+ ESCustomFieldHistory esCustomFieldHistory = hit.source();
|
|
|
+ List<String> values = esCustomFieldHistory.getSavedValue();
|
|
|
+ String customFieldId = esCustomFieldHistory.getCustomFieldId();
|
|
|
+ //根据id查询customField
|
|
|
+ Patent patent = new Patent();
|
|
|
+ String id = "";
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
builder.index("patent");
|
|
|
- Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(historyId)));
|
|
|
+ Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(customFieldId)));
|
|
|
builder.query(q);
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
long total = response.hits().total().value();
|
|
|
- System.out.println(total);
|
|
|
- //根据历史的创建时间,查询出所有创建时间大于当前创建时间的历史
|
|
|
+ if (total > 0) {
|
|
|
+ patent = response.hits().hits().get(0).source();
|
|
|
+ id = response.hits().hits().get(0).id();
|
|
|
+ }
|
|
|
+ if (values == null || values.size() <= 0) {
|
|
|
+ patent.getESCustomField().setFieldValue(null);
|
|
|
+ patent.getESCustomField().setStatsValue(null);
|
|
|
+ } else {
|
|
|
+ List<Integer> fieldIds = FormatUtil.StringTOIntegerList(values);
|
|
|
+ //根据树节点id查询树节点
|
|
|
+ LambdaQueryWrapper<TreeNode> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(TreeNode::getId, fieldIds);
|
|
|
+ List<TreeNode> treeNodes = treeNodeService.list(queryWrapper);
|
|
|
+ //遍历节点
|
|
|
+ List<String> reStateValues = new ArrayList<>(values);
|
|
|
+ treeNodes.forEach(item -> {
|
|
|
+ String path = item.getPath();
|
|
|
+ if (path != null && path.trim() != "") {
|
|
|
+ List<String> a = Arrays.asList(path.split("/"));
|
|
|
+ reStateValues.addAll(a);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<String> disReStateValues = new ArrayList<>(new HashSet<>(reStateValues));
|
|
|
+ patent.getESCustomField().setStatsValue(disReStateValues);
|
|
|
+ patent.getESCustomField().setFieldValue(values);
|
|
|
+ }
|
|
|
+ //更新自定义栏位
|
|
|
+ esService.updatePatent(patent, id);
|
|
|
+ //新增历史
|
|
|
+ ESCustomFieldHistory newEsCustomFieldHistory = new ESCustomFieldHistory();
|
|
|
+ newEsCustomFieldHistory.setField(patent.getESCustomField().getField());
|
|
|
+ newEsCustomFieldHistory.setFieldType(patent.getESCustomField().getFieldType());
|
|
|
+ newEsCustomFieldHistory.setCreateTime(new Date());
|
|
|
+ newEsCustomFieldHistory.setFieldValue(patent.getESCustomField().getFieldValue());
|
|
|
+ newEsCustomFieldHistory.setHistoryType(3);
|
|
|
+ newEsCustomFieldHistory.setTaskId(patent.getESCustomField().getTaskId());
|
|
|
+ newEsCustomFieldHistory.setPersonId("1");
|
|
|
+ newEsCustomFieldHistory.setProjectId(patent.getESCustomField().getProjectId());
|
|
|
+ newEsCustomFieldHistory.setCustomFieldId(id);
|
|
|
+ this.addCustomFieldHistory(esCustomFieldHistory);
|
|
|
+
|
|
|
|
|
|
- //遍历历史,根据操作类型,反推
|
|
|
- //根据反推内容保存并保存历史为回退;
|
|
|
}
|
|
|
+
|
|
|
+ //查询栏位历史
|
|
|
+ public Hit<ESCustomFieldHistory> getEsCustomFieldHistoryById(String historyId) throws Exception {
|
|
|
+ Hit<ESCustomFieldHistory> esCustomFieldHistoryHit = null;
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ builder.index("custom_field_history");
|
|
|
+ Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(historyId)));
|
|
|
+ builder.query(q);
|
|
|
+ SearchResponse<ESCustomFieldHistory> response = client.search(builder.build(), ESCustomFieldHistory.class);
|
|
|
+ long total = response.hits().total().value();
|
|
|
+ if (total > 0) {
|
|
|
+ esCustomFieldHistoryHit = response.hits().hits().get(0);
|
|
|
+
|
|
|
+ }
|
|
|
+ return esCustomFieldHistoryHit;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|