|
@@ -24,9 +24,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 调用外部接口的Service类 PCS:权限系统
|
|
@@ -46,7 +47,51 @@ public class PatentStarApiService {
|
|
|
@Value("${PASUrl}")
|
|
|
private String PASUrl;
|
|
|
|
|
|
- public String patentStarSearchApi(PatentStarListDto patentStarListDto) throws IOException {
|
|
|
+ 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(str);
|
|
|
+ Map<Integer,Integer> map =new LinkedHashMap<>();
|
|
|
+ while (matcher.find()) {
|
|
|
+ String a= matcher.group();
|
|
|
+ String regex2 = "[^\\(^\\)^\\+^-^=^*]";
|
|
|
+ Pattern pattern2 = Pattern.compile(regex2);
|
|
|
+ Matcher matcher2 = pattern2.matcher(a);
|
|
|
+ System.out.println(matcher.start() + "->" + matcher.end()+matcher.group());
|
|
|
+ Integer start =matcher.start();
|
|
|
+ if(matcher2.find()){
|
|
|
+ start +=matcher2.start();
|
|
|
+ }
|
|
|
+ map.put(start,matcher.end());
|
|
|
+ }
|
|
|
+ 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();
|
|
|
String json = JSONObject.toJSONString(patentStarListDto);
|
|
|
String url = "http://s.patentstar.com.cn/SearchAPI/PatentSearch/ResultGet";
|
|
|
Long currentTimeMillis = System.currentTimeMillis() / 1000;
|
|
@@ -68,15 +113,22 @@ public class PatentStarApiService {
|
|
|
Response response = okHttpClient.newCall(request).execute();
|
|
|
// 判断请求是否成功
|
|
|
if (response.isSuccessful()) {
|
|
|
-// JSONObject jsonObject =JSONObject.parseObject(Objects.requireNonNull(response.body()).string());
|
|
|
-// JSONObject jsonObject1= (JSONObject)jsonObject.get("Data");
|
|
|
+ JSONObject jsonObject =JSONObject.parseObject(Objects.requireNonNull(response.body()).string());
|
|
|
+ JSONObject Data= (JSONObject)jsonObject.get("Data");
|
|
|
// 打印服务端返回结果
|
|
|
- return Objects.requireNonNull(response.body()).string();
|
|
|
+ // 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",Data.get("List"));
|
|
|
+ reMap.put("total",Data.get("HitCount"));
|
|
|
+ return reMap;
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return "{}";
|
|
|
+ return null;
|
|
|
}
|
|
|
/**
|
|
|
* @param appNo
|
|
@@ -449,4 +501,10 @@ public class PatentStarApiService {
|
|
|
}
|
|
|
return "{}";
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String str ="D=ABC";
|
|
|
+ String aa= PatentStarApiService.formatQuery(str);
|
|
|
+ System.out.println(aa);
|
|
|
+ }
|
|
|
}
|