|
@@ -16,9 +16,7 @@ import cn.cslg.pas.service.permissions.PermissionService;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
-import co.elastic.clients.elasticsearch.core.DeleteResponse;
|
|
|
|
-import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
|
|
-import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
|
|
|
+import co.elastic.clients.elasticsearch.core.*;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.json.JsonData;
|
|
import co.elastic.clients.json.JsonData;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -64,15 +62,10 @@ public class EsScratchWordsService {
|
|
}
|
|
}
|
|
Marking marking = new Marking();
|
|
Marking marking = new Marking();
|
|
BeanUtils.copyProperties(scratchWords, marking);
|
|
BeanUtils.copyProperties(scratchWords, marking);
|
|
- Patent patent = new Patent();
|
|
|
|
- patent.setMarkings(marking);
|
|
|
|
- PatentJoin patentJoin = new PatentJoin();
|
|
|
|
- patentJoin.setParent(patentId);
|
|
|
|
- patentJoin.setName("marking");
|
|
|
|
- patent.setPatentJoin(patentJoin);
|
|
|
|
|
|
+
|
|
String id = null;
|
|
String id = null;
|
|
try {
|
|
try {
|
|
- id = esService.addChildPatent(patent, patentId);
|
|
|
|
|
|
+ id = this.saveToEs(marking);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new XiaoShiException("保存失败");
|
|
throw new XiaoShiException("保存失败");
|
|
}
|
|
}
|
|
@@ -81,26 +74,24 @@ public class EsScratchWordsService {
|
|
|
|
|
|
public String updateScratchWords(String id, Marking marking) {
|
|
public String updateScratchWords(String id, Marking marking) {
|
|
//根据id查询
|
|
//根据id查询
|
|
- Patent patent = null;
|
|
|
|
|
|
+ Marking markingLast = null;
|
|
try {
|
|
try {
|
|
- patent = this.getById(id);
|
|
|
|
|
|
+ markingLast = this.getById(id);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new XiaoShiException("错误");
|
|
throw new XiaoShiException("错误");
|
|
}
|
|
}
|
|
- if (patent == null) {
|
|
|
|
|
|
+ if (markingLast == null) {
|
|
throw new XiaoShiException("划词信息不存在");
|
|
throw new XiaoShiException("划词信息不存在");
|
|
}
|
|
}
|
|
- Marking marking1 = patent.getMarkings();
|
|
|
|
- BeanUtils.copyProperties(marking, marking1);
|
|
|
|
- patent.setMarkings(marking1);
|
|
|
|
- esService.updatePatent(patent, id);
|
|
|
|
|
|
+ BeanUtils.copyProperties(marking, markingLast);
|
|
|
|
+ this.updateToEs(marking, id);
|
|
return id;
|
|
return id;
|
|
}
|
|
}
|
|
|
|
|
|
public Records queryScratchWord(QueryScratchWordsDTO queryScratchWordsDTO) {
|
|
public Records queryScratchWord(QueryScratchWordsDTO queryScratchWordsDTO) {
|
|
Long current = queryScratchWordsDTO.getCurrent();
|
|
Long current = queryScratchWordsDTO.getCurrent();
|
|
Long size = queryScratchWordsDTO.getSize();
|
|
Long size = queryScratchWordsDTO.getSize();
|
|
- Records records =new Records();
|
|
|
|
|
|
+ Records records = new Records();
|
|
List<ScratchWordsVO> scratchWordsVOS = new ArrayList<>();
|
|
List<ScratchWordsVO> scratchWordsVOS = new ArrayList<>();
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
String createId = personnelVO.getId();
|
|
String createId = personnelVO.getId();
|
|
@@ -109,33 +100,34 @@ public class EsScratchWordsService {
|
|
String patentNo = queryScratchWordsDTO.getPatentNo();
|
|
String patentNo = queryScratchWordsDTO.getPatentNo();
|
|
String content = queryScratchWordsDTO.getMarkSelectText();
|
|
String content = queryScratchWordsDTO.getMarkSelectText();
|
|
Date marketTime = queryScratchWordsDTO.getMarkTime();
|
|
Date marketTime = queryScratchWordsDTO.getMarkTime();
|
|
- Integer projectId = 1;
|
|
|
|
|
|
+ Integer projectId = queryScratchWordsDTO.getProjectId();
|
|
//公开
|
|
//公开
|
|
- Query q1 = QueryBuilders.term(t -> t.field("markings.is_public").value(true));
|
|
|
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("is_public").value(true));
|
|
//不公开
|
|
//不公开
|
|
- Query q2 = QueryBuilders.term(t -> t.field("markings.is_public").value(false));
|
|
|
|
|
|
+ Query q2 = QueryBuilders.term(t -> t.field("is_public").value(false));
|
|
//创建人id
|
|
//创建人id
|
|
- Query q3 = QueryBuilders.term(t -> t.field("markings.mark_user_id").value(createId));
|
|
|
|
|
|
+ Query q3 = QueryBuilders.term(t -> t.field("mark_user_id").value(createId));
|
|
//租户id
|
|
//租户id
|
|
- Query q4 = QueryBuilders.term(t -> t.field("markings.public_tenant_id").value(tenantId));
|
|
|
|
|
|
+ Query q4 = QueryBuilders.term(t -> t.field("public_tenant_id").value(tenantId));
|
|
//公开范围为全部
|
|
//公开范围为全部
|
|
- Query q5 = QueryBuilders.term(t -> t.field("markings.public_scope").value(0));
|
|
|
|
|
|
+ Query q5 = QueryBuilders.term(t -> t.field("public_scope").value(0));
|
|
//公开范围为所在地
|
|
//公开范围为所在地
|
|
- Query q6 = QueryBuilders.term(t -> t.field("markings.public_scope").value(1));
|
|
|
|
|
|
+ Query q6 = QueryBuilders.term(t -> t.field("public_scope").value(1));
|
|
//数据库id
|
|
//数据库id
|
|
Query q7 = QueryBuilders.term(t -> t.field("public_project_id").value(projectId));
|
|
Query q7 = QueryBuilders.term(t -> t.field("public_project_id").value(projectId));
|
|
|
|
|
|
|
|
|
|
//公开并且全部范围
|
|
//公开并且全部范围
|
|
- Query bool1 = QueryBuilders.bool(i -> i.must(q1, q6, q4));
|
|
|
|
|
|
+ Query bool1 = QueryBuilders.bool(i -> i.must(q1, q5, q4));
|
|
// 公开并且所在地
|
|
// 公开并且所在地
|
|
- Query bool2 = QueryBuilders.bool(i -> i.must(q1, q6, q7));
|
|
|
|
- //不公开
|
|
|
|
- Query bool3 = QueryBuilders.bool(i -> i.must(q2, q3, q7));
|
|
|
|
|
|
+ Query bool2 = QueryBuilders.bool(i -> i.must(q1, q6, q7, q4));
|
|
|
|
+ //不公开并且全部范围
|
|
|
|
+ Query bool3 = QueryBuilders.bool(i -> i.must(q2, q5, q3));
|
|
|
|
+ //不公开并且所在地
|
|
|
|
+ Query bool4 = QueryBuilders.bool(i -> i.must(q2, q6, q3, q7));
|
|
|
|
+ Query riBool = QueryBuilders.bool(i -> i.should(bool1, bool2, bool3, bool4));
|
|
List<Query> queries = new ArrayList<>();
|
|
List<Query> queries = new ArrayList<>();
|
|
- queries.add(bool1);
|
|
|
|
- queries.add(bool2);
|
|
|
|
- queries.add(bool3);
|
|
|
|
|
|
+ queries.add(riBool);
|
|
if (patentNo != null) {
|
|
if (patentNo != null) {
|
|
Query query = this.getPatentNoQuery(patentNo);
|
|
Query query = this.getPatentNoQuery(patentNo);
|
|
queries.add(query);
|
|
queries.add(query);
|
|
@@ -154,53 +146,52 @@ public class EsScratchWordsService {
|
|
}
|
|
}
|
|
Query searchBool = QueryBuilders.bool(i -> i.must(queries));
|
|
Query searchBool = QueryBuilders.bool(i -> i.must(queries));
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
- builder.index("patent");
|
|
|
|
- if (current!=null&&size!=null&¤t > 0 && size > 0) {
|
|
|
|
|
|
+ builder.index("patent_marking");
|
|
|
|
+ if (current != null && size != null && current > 0 && size > 0) {
|
|
builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
|
|
builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
|
|
}
|
|
}
|
|
builder.query(searchBool);
|
|
builder.query(searchBool);
|
|
|
|
|
|
- long total=0;
|
|
|
|
|
|
+ long total = 0;
|
|
try {
|
|
try {
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
- List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
|
|
+ SearchResponse<Marking> response = client.search(builder.build(), Marking.class);
|
|
|
|
+ List<Hit<Marking>> hits = response.hits().hits();
|
|
total = response.hits().total().value();
|
|
total = response.hits().total().value();
|
|
- for (Hit<Patent> hit : hits) {
|
|
|
|
- Patent patent = hit.source();
|
|
|
|
|
|
+ for (Hit<Marking> hit : hits) {
|
|
|
|
+ Marking marking = hit.source();
|
|
ScratchWordsVO scratchWordsVO = new ScratchWordsVO();
|
|
ScratchWordsVO scratchWordsVO = new ScratchWordsVO();
|
|
- BeanUtils.copyProperties(patent.getMarkings(), scratchWordsVO);
|
|
|
|
|
|
+ BeanUtils.copyProperties(marking, scratchWordsVO);
|
|
scratchWordsVO.setId(hit.id());
|
|
scratchWordsVO.setId(hit.id());
|
|
scratchWordsVOS.add(scratchWordsVO);
|
|
scratchWordsVOS.add(scratchWordsVO);
|
|
- scratchWordsVO.setPatentId(patent.getPatentJoin().getParent());
|
|
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
|
|
}
|
|
}
|
|
records.setTotal(total);
|
|
records.setTotal(total);
|
|
- records.setTotal(total);
|
|
|
|
|
|
+ records.setData(scratchWordsVOS);
|
|
return records;
|
|
return records;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询栏位历史
|
|
//查询栏位历史
|
|
- public Patent getById(String wordsId) throws Exception {
|
|
|
|
- Patent patent = null;
|
|
|
|
|
|
+ public Marking getById(String wordsId) throws Exception {
|
|
|
|
+ Marking marking = null;
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
- builder.index("patent");
|
|
|
|
|
|
+ builder.index("patent_marking");
|
|
Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(wordsId)));
|
|
Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(wordsId)));
|
|
builder.query(q);
|
|
builder.query(q);
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
|
|
+ SearchResponse<Marking> response = client.search(builder.build(), Marking.class);
|
|
long total = response.hits().total().value();
|
|
long total = response.hits().total().value();
|
|
if (total > 0) {
|
|
if (total > 0) {
|
|
- patent = response.hits().hits().get(0).source();
|
|
|
|
|
|
+ marking = response.hits().hits().get(0).source();
|
|
}
|
|
}
|
|
- return patent;
|
|
|
|
|
|
+ return marking;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeById(String id) throws IOException {
|
|
public void removeById(String id) throws IOException {
|
|
DeleteResponse deleteResponse = client.delete(deleteRequest ->
|
|
DeleteResponse deleteResponse = client.delete(deleteRequest ->
|
|
- deleteRequest.index("patent").id(id)
|
|
|
|
|
|
+ deleteRequest.index("patent_marking").id(id)
|
|
);
|
|
);
|
|
|
|
|
|
}
|
|
}
|
|
@@ -208,16 +199,8 @@ public class EsScratchWordsService {
|
|
|
|
|
|
//获得专利号检索式
|
|
//获得专利号检索式
|
|
public Query getPatentNoQuery(String patentNo) {
|
|
public Query getPatentNoQuery(String patentNo) {
|
|
- Query parentQ1 = QueryBuilders.term(t -> t.field("app_no.keyword").value(patentNo));
|
|
|
|
-
|
|
|
|
- //公开号
|
|
|
|
- Query parentQ2 = QueryBuilders.term(t -> t.field("public_no.keyword").value(patentNo));
|
|
|
|
-
|
|
|
|
- //授权号
|
|
|
|
- Query parentQ3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(patentNo));
|
|
|
|
- Query parentQ = QueryBuilders.bool(i -> i.should(parentQ1, parentQ2, parentQ3));
|
|
|
|
- Query qPatent = QueryBuilders.hasParent(t -> t.parentType("patent").query(parentQ));
|
|
|
|
- return qPatent;
|
|
|
|
|
|
+ Query query = QueryBuilders.term(t -> t.field("patent_no").value(patentNo));
|
|
|
|
+ return query;
|
|
}
|
|
}
|
|
|
|
|
|
//获得创建时间检索式
|
|
//获得创建时间检索式
|
|
@@ -241,13 +224,38 @@ public class EsScratchWordsService {
|
|
ids.add("0");
|
|
ids.add("0");
|
|
}
|
|
}
|
|
String strs = JsonData.of(ids).toString();
|
|
String strs = JsonData.of(ids).toString();
|
|
- Query query = QueryBuilders.term(t -> t.field("mark_time").value(strs));
|
|
|
|
|
|
+ Query query = QueryBuilders.term(t -> t.field("mark_user_id").value(strs));
|
|
return query;
|
|
return query;
|
|
}
|
|
}
|
|
|
|
|
|
//获得内容检索式
|
|
//获得内容检索式
|
|
public Query getContentQuery(String content) {
|
|
public Query getContentQuery(String content) {
|
|
- Query query = QueryBuilders.match(t -> t.field("mark_selectText").query(content));
|
|
|
|
|
|
+ Query query = QueryBuilders.match(t -> t.field("mark_select_text").query(content));
|
|
return query;
|
|
return query;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //保存
|
|
|
|
+ public String saveToEs(Marking marking) throws Exception {
|
|
|
|
+ IndexResponse indexResponse = client.index(i -> i
|
|
|
|
+ .index("patent_marking")
|
|
|
|
+ .document(marking)
|
|
|
|
+ );
|
|
|
|
+ return indexResponse.id();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Integer updateToEs(Marking marking, String id) {
|
|
|
|
+ UpdateRequest<Marking, Marking> req;
|
|
|
|
+ req = UpdateRequest.of(
|
|
|
|
+ b -> b.index("patent_marking").id(id)
|
|
|
|
+ .doc(marking)
|
|
|
|
+ );
|
|
|
|
+ try {
|
|
|
|
+ client.update(req, Marking.class);
|
|
|
|
+ return 1;
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|