|
@@ -24,6 +24,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
@@ -65,24 +66,24 @@ public class EsPatentService {
|
|
|
.eq(AssoPersonProduct::getPersonUuid, uuid));
|
|
|
Integer personProductId = assoPersonProduct.getId();
|
|
|
//判断该专利是否已经被收藏
|
|
|
- boolean b = this.selectPatentByProductId(personProductId);
|
|
|
- if (!b) {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ List<String> patentNoList = this.selectPatentByProductId(personProductId);
|
|
|
+ patentNos.removeAll(patentNoList);
|
|
|
//根据专利号获取专利id
|
|
|
List<String> list = new ArrayList<>();
|
|
|
- for (String patentNo : patentNos) {
|
|
|
- String patentId = this.selectPatentByPatentNo(patentNo);
|
|
|
- Patent patent = new Patent();
|
|
|
- patent.setProductId(personProductId);
|
|
|
- PatentJoin patentJoin = new PatentJoin();
|
|
|
- patentJoin.setParent(patentId);
|
|
|
- patentJoin.setName("product");
|
|
|
- patent.setPatentJoin(patentJoin);
|
|
|
- try {
|
|
|
- String id = esService.addChildPatent(patent, patentId);
|
|
|
- list.add(id);
|
|
|
- } catch (Exception e) {
|
|
|
+ if (!CollectionUtils.isEmpty(patentNos)) {
|
|
|
+ for (String patentNo : patentNos) {
|
|
|
+ String patentId = this.selectPatentByPatentNo(patentNo);
|
|
|
+ Patent patent = new Patent();
|
|
|
+ patent.setProductId(personProductId);
|
|
|
+ PatentJoin patentJoin = new PatentJoin();
|
|
|
+ patentJoin.setParent(patentId);
|
|
|
+ patentJoin.setName("product");
|
|
|
+ patent.setPatentJoin(patentJoin);
|
|
|
+ try {
|
|
|
+ String id = esService.addChildPatent(patent, patentId);
|
|
|
+ list.add(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (ToolUtil.equals(list.size(), patentNos.size())) {
|
|
@@ -119,8 +120,8 @@ public class EsPatentService {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public boolean selectPatentByProductId(Integer personProductId) throws IOException {
|
|
|
- boolean flag = false;
|
|
|
+ public List<String> selectPatentByProductId(Integer personProductId) throws IOException {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
|
builder.index("wxpatent");
|
|
@@ -129,12 +130,11 @@ public class EsPatentService {
|
|
|
builder.query(query);
|
|
|
builder.size(10);
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
- long count = response.hits().total().value();
|
|
|
- if (count > 0) {
|
|
|
- flag = true;
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+ Patent patent = hit.source();
|
|
|
+ list.add(patent.getPatentNo());
|
|
|
}
|
|
|
-// List<Hit<Patent>> hits = response.hits().hits();
|
|
|
-// int size = hits.size();
|
|
|
- return flag;
|
|
|
+ return list;
|
|
|
}
|
|
|
}
|