|
@@ -1,6 +1,7 @@
|
|
|
package cn.cslg.pas.service.business.es;
|
|
|
|
|
|
import cn.cslg.pas.common.core.base.IfConstant;
|
|
|
+import cn.cslg.pas.common.dto.GetUnselectedDTO;
|
|
|
import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
|
import cn.cslg.pas.common.dto.PatentDTO;
|
|
|
//import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
|
|
@@ -61,6 +62,9 @@ public class EsService {
|
|
|
private PatentStarApiService patentStarApiService;
|
|
|
@Autowired
|
|
|
private EsPatentService esPatentService;
|
|
|
+ @Lazy
|
|
|
+ @Autowired
|
|
|
+ private EsCountService esCountService;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -158,7 +162,7 @@ public class EsService {
|
|
|
}
|
|
|
List<EsCustomFieldValueDTO> customFields = queryRequest.getCustomFields();
|
|
|
if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
- searchCondition = this.parseCustomField(customFields);
|
|
|
+ searchCondition = this.parseCustomField(customFields,projectId,taskId);
|
|
|
}
|
|
|
if (taskId != null) {
|
|
|
if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
@@ -388,7 +392,7 @@ public class EsService {
|
|
|
* @param customFields
|
|
|
* @return
|
|
|
*/
|
|
|
- public String parseCustomField(List<EsCustomFieldValueDTO> customFields) {
|
|
|
+ public String parseCustomField(List<EsCustomFieldValueDTO> customFields, Integer projectId, Integer taskId) throws Exception {
|
|
|
int m = 1;
|
|
|
int n = 0;
|
|
|
StringBuilder builder = new StringBuilder();
|
|
@@ -398,10 +402,10 @@ public class EsService {
|
|
|
EsCustomFieldValueDTO customField = customFields.get(i);
|
|
|
if (i != n) {
|
|
|
builder.append(" ").append("and").append(" ").append("(");
|
|
|
- this.appendStr(customField, builder, m, customField.getIfHaveChild());
|
|
|
+ this.appendStr(customField, builder, m, customField.getIfHaveChild(), projectId, taskId);
|
|
|
} else {
|
|
|
builder.append("(");
|
|
|
- this.appendStr(customField, builder, m, customField.getIfHaveChild());
|
|
|
+ this.appendStr(customField, builder, m, customField.getIfHaveChild(), projectId, taskId);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -409,10 +413,10 @@ public class EsService {
|
|
|
EsCustomFieldValueDTO customField = customFields.get(i);
|
|
|
if (i != n) {
|
|
|
builder.append(" ").append("and").append(" ");
|
|
|
- this.appendStr(customField, builder, m, customField.getIfHaveChild());
|
|
|
+ this.appendStr(customField, builder, m, customField.getIfHaveChild(), projectId, taskId);
|
|
|
} else {
|
|
|
builder.append("(");
|
|
|
- this.appendStr(customField, builder, m, customField.getIfHaveChild());
|
|
|
+ this.appendStr(customField, builder, m, customField.getIfHaveChild(), projectId, taskId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -422,9 +426,14 @@ public class EsService {
|
|
|
return builder.toString();
|
|
|
}
|
|
|
|
|
|
- public void appendStr(EsCustomFieldValueDTO customField, StringBuilder builder, int m, boolean ifHaveChild) {
|
|
|
+ public void appendStr(EsCustomFieldValueDTO customField, StringBuilder builder, int m, boolean ifHaveChild,
|
|
|
+ Integer projectId, Integer taskId) throws Exception {
|
|
|
builder.append("field").append("=").append(customField.getFieldId());
|
|
|
List<String> values = customField.getFieldValue();
|
|
|
+ if (values.contains("未选择")) {
|
|
|
+ values.removeIf(value -> value.equals("未选择"));
|
|
|
+ values.add("未选择");
|
|
|
+ }
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
|
builder.append(" ").append("and").append(" ");
|
|
|
if (ifHaveChild) {
|
|
@@ -440,12 +449,29 @@ public class EsService {
|
|
|
if (j != values.size() - m) {
|
|
|
builder.append(s).append(" ").append("or").append(" ");
|
|
|
} else {
|
|
|
- builder.append(s).append(")").append(")");
|
|
|
+ if (s.equals("未选择")) {
|
|
|
+ GetUnselectedDTO unselectedDTO = esCountService.getUnselectedCustomNum(projectId, taskId);
|
|
|
+ List<String> childIds = unselectedDTO.getBeinglessChildIds();
|
|
|
+ List<String> nos = this.getPatentNos(childIds);
|
|
|
+ String noCondition = this.appendPatentNo(nos);
|
|
|
+ builder.append(s).append(")").append(" ").append("or")
|
|
|
+ .append(" ").append("(").append(noCondition).append(")").append(")");
|
|
|
+ } else {
|
|
|
+ builder.append(s).append(")").append(")");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
for (String value : values) {
|
|
|
- builder.append(value).append(")");
|
|
|
+ if (value.equals("未选择")) {
|
|
|
+ GetUnselectedDTO unselectedDTO = esCountService.getUnselectedCustomNum(projectId, taskId);
|
|
|
+ List<String> childIds = unselectedDTO.getBeinglessChildIds();
|
|
|
+ List<String> nos = this.getPatentNos(childIds);
|
|
|
+ String noCondition = this.appendPatentNo(nos);
|
|
|
+ builder.append(value).append(" ").append("or").append(" ").append(noCondition).append(")");
|
|
|
+ } else {
|
|
|
+ builder.append(value).append(")");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -1337,6 +1363,43 @@ public class EsService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ public List<String> getPatentNos(List<String> ids) throws IOException {
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ Query q = QueryBuilders.ids(i -> i.values(ids));
|
|
|
+ builder.size(9999);
|
|
|
+ builder.query(q);
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+ Patent patent = hit.source();
|
|
|
+ list.add(patent.getPatentNo());
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String appendPatentNo(List<String> nos) {
|
|
|
+ String str = "NO = ";
|
|
|
+ if (nos.size() > 1) {
|
|
|
+ str = str + "(";
|
|
|
+ for (int i = 0; i < nos.size(); i++) {
|
|
|
+ String s = nos.get(i);
|
|
|
+ if (i != nos.size() - 1) {
|
|
|
+ str = str + s + " " + "OR" + " ";
|
|
|
+ } else {
|
|
|
+ str = str + s + ")";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (String no : nos) {
|
|
|
+ str = str + no;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|