|
@@ -6,14 +6,12 @@ import cn.cslg.pas.common.model.dto.GetDescriptionInfoParamsDTO;
|
|
|
import cn.cslg.pas.common.model.dto.GetFuTuParamsDTO;
|
|
|
import cn.cslg.pas.common.model.dto.GetSearchBiblioParamsDTO;
|
|
|
import cn.cslg.pas.common.model.outApi.PatentStarListDto;
|
|
|
-import cn.cslg.pas.common.model.vo.outApi.StarPatentVO;
|
|
|
import cn.cslg.pas.common.utils.FormatUtil;
|
|
|
import cn.cslg.pas.common.utils.JsonUtils;
|
|
|
import cn.cslg.pas.common.utils.SecurityUtils.SecurityUtils;
|
|
|
import cn.cslg.pas.domain.PubNo;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.JsonObject;
|
|
@@ -49,55 +47,51 @@ public class PatentStarApiService {
|
|
|
@Value("${PASUrl}")
|
|
|
private String PASUrl;
|
|
|
|
|
|
- public static String formatQuery(String query) {
|
|
|
- query = query
|
|
|
- .replace(" AND ", "*")
|
|
|
- .replace(" OR ", "+")
|
|
|
- .replace(" NOT ", "-");
|
|
|
- StringBuilder sb = new StringBuilder(query);
|
|
|
- String regex = "(?<=[\\(\\)\\+\\-=\\*])[\\w\\W]+?(?=[\\(\\+\\-=\\)\\*])";
|
|
|
+ public static String formatQuery(String query){
|
|
|
+ String str = "((abc=13+ac=232)+ad=33+(ad=2))";
|
|
|
+ StringBuilder sb =new StringBuilder(str);
|
|
|
+ String regex = "(?<=[\\(\\)\\+\\-=])[\\w\\W]+?(?=[\\(\\+\\-=\\)])";
|
|
|
Pattern pattern = Pattern.compile(regex);
|
|
|
- Matcher matcher = pattern.matcher(query);
|
|
|
- Map<Integer, Integer> map = new LinkedHashMap<>();
|
|
|
+ Matcher matcher = pattern.matcher(str);
|
|
|
+ Map<Integer,Integer> map =new LinkedHashMap<>();
|
|
|
while (matcher.find()) {
|
|
|
- String a = matcher.group();
|
|
|
+ String a= matcher.group();
|
|
|
String regex2 = "[^\\(^\\)^\\+^-^=^*]";
|
|
|
Pattern pattern2 = Pattern.compile(regex2);
|
|
|
Matcher matcher2 = pattern2.matcher(a);
|
|
|
- Integer start = matcher.start();
|
|
|
- if (matcher2.find()) {
|
|
|
- start += matcher2.start();
|
|
|
+ System.out.println(matcher.start() + "->" + matcher.end()+matcher.group());
|
|
|
+ Integer start =matcher.start();
|
|
|
+ if(matcher2.find()){
|
|
|
+ start +=matcher2.start();
|
|
|
}
|
|
|
- map.put(start, matcher.end());
|
|
|
+ map.put(start,matcher.end());
|
|
|
}
|
|
|
- if (map.size() == 0) {
|
|
|
- return "";
|
|
|
- }
|
|
|
- List<Integer> list = new ArrayList<Integer>(map.keySet());
|
|
|
- for (int i = 0; i < list.size(); i += 2) {
|
|
|
- int start1 = list.get(i);
|
|
|
- int end1 = map.get(list.get(i));
|
|
|
- int len1 = end1 - start1;
|
|
|
- int start2 = list.get(i + 1);
|
|
|
- int end2 = map.get(list.get(i + 1));
|
|
|
- int len2 = end2 - start2;
|
|
|
- int diff = len2 - len1;
|
|
|
- if (diff > 0) {
|
|
|
- sb.replace(start1, end1, query.substring(start2, end2));
|
|
|
- sb.replace(start2 + diff, end2 + diff, query.substring(start1, end1));
|
|
|
- } else {
|
|
|
- sb.replace(start2, end2, query.substring(start1, end1));
|
|
|
- sb.replace(start1, end1, query.substring(start2, end2));
|
|
|
- }
|
|
|
- }
|
|
|
- String reStr = sb.toString();
|
|
|
- reStr ="FXX"+reStr.replace("=", "/");
|
|
|
- return reStr;
|
|
|
+ List <Integer> list = new ArrayList<Integer>(map.keySet());
|
|
|
+for(int i=0;i<list.size();i+=2){
|
|
|
+ int start1 = list.get(i);
|
|
|
+ int end1 = map.get(list.get(i));
|
|
|
+ int len1 =end1-start1;
|
|
|
+ int start2 = list.get(i+1);
|
|
|
+ int end2 = map.get(list.get(i+1));
|
|
|
+ int len2 =end2-start2;
|
|
|
+ int diff =len2 -len1;
|
|
|
+ if(diff>0){
|
|
|
+ sb.replace(start1,end1,str.substring(start2,end2));
|
|
|
+ sb.replace(start2+diff,end2+diff,str.substring(start1,end1));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sb.replace(start2,end2,str.substring(start1,end1));
|
|
|
+ sb.replace(start1,end1,str.substring(start2,end2));
|
|
|
+ }
|
|
|
+ System.out.println(sb);
|
|
|
+}
|
|
|
+String aa =sb.toString();
|
|
|
+aa.replace("\\","=");
|
|
|
+ System.out.println(aa);
|
|
|
+return "";
|
|
|
}
|
|
|
-
|
|
|
public Map<String,Object> patentStarSearchApi(PatentStarListDto patentStarListDto) throws IOException {
|
|
|
String formQuery=patentStarListDto.getCurrentQuery();
|
|
|
- patentStarListDto.setCurrentQuery(PatentStarApiService.formatQuery(formQuery));
|
|
|
String json = JSONObject.toJSONString(patentStarListDto);
|
|
|
String url = "http://s.patentstar.com.cn/SearchAPI/PatentSearch/ResultGet";
|
|
|
Long currentTimeMillis = System.currentTimeMillis() / 1000;
|
|
@@ -121,13 +115,13 @@ public class PatentStarApiService {
|
|
|
if (response.isSuccessful()) {
|
|
|
JSONObject jsonObject =JSONObject.parseObject(Objects.requireNonNull(response.body()).string());
|
|
|
JSONObject Data= (JSONObject)jsonObject.get("Data");
|
|
|
- List<StarPatentVO> starPatentVOS = JSONArray.parseArray(Data.get("List").toString(),StarPatentVO.class);
|
|
|
// 打印服务端返回结果
|
|
|
// return Objects.requireNonNull(response.body()).string();
|
|
|
+
|
|
|
Map<String,Object> reMap =new HashMap<>();
|
|
|
reMap.put("size",patentStarListDto.getRowCount());
|
|
|
reMap.put("current",patentStarListDto.getPageNum());
|
|
|
- reMap.put("records",starPatentVOS);
|
|
|
+ reMap.put("records",Data.get("List"));
|
|
|
reMap.put("total",Data.get("HitCount"));
|
|
|
return reMap;
|
|
|
}
|
|
@@ -509,7 +503,7 @@ public class PatentStarApiService {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- String str ="(AB=电子 OR TI=电子)";
|
|
|
+ String str ="D=ABC";
|
|
|
String aa= PatentStarApiService.formatQuery(str);
|
|
|
System.out.println(aa);
|
|
|
}
|