|
@@ -10,16 +10,19 @@ import cn.cslg.pas.common.model.cronModel.Records;
|
|
|
import cn.cslg.pas.common.model.importTaskModel.PatentApplicant;
|
|
|
import cn.cslg.pas.common.utils.*;
|
|
|
import cn.cslg.pas.common.vo.ContentVO;
|
|
|
+import cn.cslg.pas.common.vo.NoCacheVO;
|
|
|
import cn.cslg.pas.common.vo.QueryExternalFamilyVO;
|
|
|
import cn.cslg.pas.common.vo.StarPatentVO;
|
|
|
import cn.cslg.pas.common.vo.business.PatentNoVO;
|
|
|
import cn.cslg.pas.domain.WebLoginConfig;
|
|
|
import cn.cslg.pas.domain.business.RetrieveRecord;
|
|
|
import cn.cslg.pas.domain.es.*;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.service.WebLoginConfigService;
|
|
|
|
|
|
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -64,10 +67,7 @@ import java.util.stream.Collectors;
|
|
|
@RequiredArgsConstructor
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-
|
|
|
public class PatentStarApiService {
|
|
|
- private ApplicationContext applicationContext;
|
|
|
- private PatentStarApiService patentStarApiService;
|
|
|
@Autowired
|
|
|
private RetrieveRecordService retrieveRecordService;
|
|
|
@Autowired
|
|
@@ -78,22 +78,42 @@ public class PatentStarApiService {
|
|
|
private WebLoginConfigService webLoginConfigService;
|
|
|
@Autowired
|
|
|
private FormatQueryService formatQueryService;
|
|
|
+ @Autowired
|
|
|
+ private NOSCacheService cacheService;
|
|
|
|
|
|
public Records patentStarSearchLocal(PatentStarListDTO patentStarListDTO) throws IOException {
|
|
|
RetrieveRecord retrieveRecord = new RetrieveRecord();
|
|
|
retrieveRecord.setConditions(patentStarListDTO.getCurrentQuery());
|
|
|
-
|
|
|
+ retrieveRecord.setSearchType(0);
|
|
|
if (patentStarListDTO.getRetrieveRecordId() != null) {
|
|
|
retrieveRecord = retrieveRecordService.getById(patentStarListDTO.getRetrieveRecordId());
|
|
|
patentStarListDTO.setCurrentQuery(retrieveRecord.getConditions());
|
|
|
patentStarListDTO.setDBType(retrieveRecord.getDbType());
|
|
|
}
|
|
|
- long start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ String redisKey = patentStarListDTO.getRedisKey();
|
|
|
+ List<String> nos = new ArrayList<>();
|
|
|
+ Long total = 0L;
|
|
|
+ if (StringUtils.isNotEmpty(patentStarListDTO.getNumberQuery())) {
|
|
|
+ NoCacheVO cacheVO = cacheService.savaByList(patentStarListDTO);
|
|
|
+ retrieveRecord.setConditions(patentStarListDTO.getNumberQuery());
|
|
|
+ retrieveRecord.setSearchType(1);
|
|
|
+ redisKey = cacheVO.getKey();
|
|
|
+ total = cacheVO.getTotal();
|
|
|
+ nos.addAll(cacheVO.getList());
|
|
|
+ }
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(patentStarListDTO.getNumberQuery())) && StringUtils.isNotEmpty(redisKey)) {
|
|
|
+ NoCacheVO cacheVO = cacheService.getByList(patentStarListDTO);
|
|
|
+ retrieveRecord.setConditions(patentStarListDTO.getNumberQuery());
|
|
|
+ retrieveRecord.setSearchType(1);
|
|
|
+ nos.addAll(cacheVO.getList());
|
|
|
+ total = cacheVO.getTotal();
|
|
|
+ redisKey = cacheVO.getKey();
|
|
|
+ }
|
|
|
+
|
|
|
Map<String, Object> map = this.patentStarSearchApi(patentStarListDTO);
|
|
|
-long end =System.currentTimeMillis();
|
|
|
-System.out.println("search time:"+(end-start));
|
|
|
if (map == null) {
|
|
|
- ThrowException.throwXiaoShiException("检索失败,请检查检索式");
|
|
|
+ throw new XiaoShiException("检索失败,请检查检索式");
|
|
|
}
|
|
|
|
|
|
//记录检索历史
|
|
@@ -117,12 +137,23 @@ System.out.println("search time:"+(end-start));
|
|
|
records.setRetrieveRecordId(retrieveRecord.getId());
|
|
|
records.setCurrent(Long.parseLong(map.get("current").toString()));
|
|
|
records.setSize(Long.parseLong(map.get("size").toString()));
|
|
|
- records.setData(this.loadPatent(starPatentVOS));
|
|
|
- records.setTotal(Long.parseLong(map.get("total").toString()));
|
|
|
+ List<PatentColumnDTO> columnDTOS = this.loadPatent(starPatentVOS);
|
|
|
+ records.setData(this.loadPatentList(columnDTOS, nos, patentStarListDTO.getDBType()));
|
|
|
+ if (total != 0) {
|
|
|
+ records.setTotal(total);
|
|
|
+ } else {
|
|
|
+ records.setTotal(Long.parseLong(map.get("total").toString()));
|
|
|
+ }
|
|
|
+ records.setRedisKey(redisKey);
|
|
|
return records;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 格式化条件后并请求外部接口
|
|
|
+ * @param PatentStarListDTO
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
public Map<String, Object> patentStarSearchApi(PatentStarListDTO PatentStarListDTO) throws IOException {
|
|
|
try {
|
|
|
if (PatentStarListDTO.getFormed() == null || PatentStarListDTO.getFormed() == false) {
|
|
@@ -168,12 +199,7 @@ System.out.println("search time:"+(end-start));
|
|
|
Request request = new Request.Builder().url(url).post(requestBody).build();
|
|
|
// 发送请求获取响应
|
|
|
try {
|
|
|
- long start = System.currentTimeMillis();
|
|
|
-
|
|
|
Response response = okHttpClient.newCall(request).execute();
|
|
|
-
|
|
|
- long end =System.currentTimeMillis();
|
|
|
- System.out.println("search11time:"+(end-start));
|
|
|
// 判断请求是否成功
|
|
|
if (response.isSuccessful()) {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(Objects.requireNonNull(response.body()).string());
|
|
@@ -190,26 +216,70 @@ System.out.println("search time:"+(end-start));
|
|
|
return reMap;
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return null;
|
|
|
+// e.printStackTrace();
|
|
|
+// return null;
|
|
|
+ throw new XiaoShiException("外部接口检索超时");
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public String getFormatCondition(String condition) {
|
|
|
- String s = condition.substring(condition.indexOf("=") + 1);
|
|
|
- String s1 = s.replaceAll("[()]", "");
|
|
|
- String[] valueStrs = s1.split("[,,]|(\\r\\n)+|\\r+|\\n+");
|
|
|
- StringBuilder stringBuilder = new StringBuilder();
|
|
|
- for (int i = 0; i < valueStrs.length; i++) {
|
|
|
- final String value = valueStrs[i];
|
|
|
- if (i != valueStrs.length - 1) {
|
|
|
- stringBuilder.append(value).append(",");
|
|
|
- } else {
|
|
|
- stringBuilder.append(value);
|
|
|
+ //封装patent column数据返回
|
|
|
+ private List<PatentColumnDTO> loadPatentList(List<PatentColumnDTO> columnDTOS, List<String> list, String dbType) {
|
|
|
+ if (CollectionUtils.isEmpty(list) || CollectionUtils.isEmpty(columnDTOS)) {
|
|
|
+ return list.isEmpty() ? columnDTOS : createNewDTOs(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PatentColumnDTO> result = new ArrayList<>(columnDTOS.size());
|
|
|
+ Set<String> searchedNumbers = new HashSet<>(); // 用于跟踪已搜索的专利号
|
|
|
+
|
|
|
+ for (String patentNo : list) {
|
|
|
+ boolean found = false;
|
|
|
+ String formattedNo = dbType.equals("CN") ? PatentNoUtil.formatApNo(patentNo) : patentNo;
|
|
|
+
|
|
|
+ for (PatentColumnDTO columnDTO : columnDTOS) {
|
|
|
+ if (containsNumber(columnDTO, formattedNo)) {
|
|
|
+ PatentColumnDTO dto = new PatentColumnDTO();
|
|
|
+ BeanUtils.copyProperties(columnDTO,dto);
|
|
|
+ dto.setSearchNo(patentNo);
|
|
|
+ result.add(dto);
|
|
|
+ searchedNumbers.add(patentNo); // 标记为已搜索
|
|
|
+ found = true;
|
|
|
+ break; // 找到匹配项后跳出内层循环
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!found) {
|
|
|
+ // 如果没有在columnDTOS中找到匹配项,则创建一个新的DTO
|
|
|
+ PatentColumnDTO newDTO = new PatentColumnDTO();
|
|
|
+ newDTO.setPatentNo(patentNo);
|
|
|
+ newDTO.setSearchNo(patentNo);
|
|
|
+ newDTO.setIfSearch(false);
|
|
|
+ result.add(newDTO);
|
|
|
}
|
|
|
}
|
|
|
- return stringBuilder.toString();
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean containsNumber(PatentColumnDTO dto, String number) {
|
|
|
+ String appNo = StringUtils.isNotEmpty(dto.getAppNo()) ? dto.getAppNo() : "";
|
|
|
+ String publicNo = StringUtils.isNotEmpty(dto.getPublicNo()) ? dto.getPublicNo() : "";
|
|
|
+ String grantNo = StringUtils.isNotEmpty(dto.getGrantNo()) ? dto.getGrantNo() : "";
|
|
|
+ String rowAppNo = StringUtils.isNotEmpty(dto.getRowApplicationNo()) ? dto.getRowApplicationNo() : "";
|
|
|
+ return appNo.contains(number) || publicNo.contains(number)
|
|
|
+ || grantNo.contains(number) || rowAppNo.contains(number);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<PatentColumnDTO> createNewDTOs(List<String> list) {
|
|
|
+ List<PatentColumnDTO> newDTOs = new ArrayList<>();
|
|
|
+ for (String s : list) {
|
|
|
+ PatentColumnDTO dto = new PatentColumnDTO();
|
|
|
+ dto.setPatentNo(s);
|
|
|
+ dto.setSearchNo(s);
|
|
|
+ dto.setIfSearch(false);
|
|
|
+ newDTOs.add(dto);
|
|
|
+ }
|
|
|
+ return newDTOs;
|
|
|
}
|
|
|
|
|
|
public List<PatentStarListDTO> getSplitedConditions(PatentStarListDTO patentStarListDTO, int patentNum) throws IOException {
|
|
@@ -393,8 +463,7 @@ System.out.println("search time:"+(end-start));
|
|
|
if (response.isSuccessful()) {
|
|
|
// 打印服务端返回结果
|
|
|
return Objects.requireNonNull(response.body()).string();
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
response.close();
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
@@ -480,8 +549,7 @@ System.out.println("search time:"+(end-start));
|
|
|
if (response.isSuccessful()) {
|
|
|
// 打印服务端返回结果
|
|
|
return Objects.requireNonNull(response.body()).string();
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
response.close();
|
|
|
}
|
|
|
|
|
@@ -631,8 +699,7 @@ System.out.println("search time:"+(end-start));
|
|
|
if (response.isSuccessful()) {
|
|
|
// 打印服务端返回结果
|
|
|
return Objects.requireNonNull(response.body()).string();
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
response.close();
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
@@ -925,10 +992,6 @@ System.out.println("search time:"+(end-start));
|
|
|
}
|
|
|
// patentColumnDTO.setAppCountry(item.getBureau());
|
|
|
//装载申请人地址
|
|
|
- PersonAddress appAddress = new PersonAddress();
|
|
|
- appAddress.setAddress(item.getApplicationAddress());
|
|
|
- appAddress.setProvince(item.getProvinceStr());
|
|
|
- patentColumnDTO.setApplicantAddr(appAddress);
|
|
|
patentColumnDTO.setAppAddress(item.getApplicationAddress());
|
|
|
// patentColumnDTO.setApplicantCountry(item.getProvinceStr());
|
|
|
String provinceStr = item.getProvinceStr();
|
|
@@ -1199,21 +1262,20 @@ System.out.println("search time:"+(end-start));
|
|
|
dto.setType(0);
|
|
|
list.add(dto);
|
|
|
}
|
|
|
- }
|
|
|
- else { //若只有一个
|
|
|
+ } else { //若只有一个
|
|
|
pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"));
|
|
|
if (pdfUrl1.contains("0A_CN_0.pdf")) {
|
|
|
|
|
|
- InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
|
|
|
- dto.setPdfGuid(pdfUrl1);
|
|
|
- dto.setType(0);
|
|
|
- list.add(dto);
|
|
|
+ InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
|
|
|
+ dto.setPdfGuid(pdfUrl1);
|
|
|
+ dto.setType(0);
|
|
|
+ list.add(dto);
|
|
|
|
|
|
} else {
|
|
|
- InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
|
|
|
- dto.setPdfGuid(pdfUrl1);
|
|
|
- dto.setType(1);
|
|
|
- list.add(dto);
|
|
|
+ InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
|
|
|
+ dto.setPdfGuid(pdfUrl1);
|
|
|
+ dto.setType(1);
|
|
|
+ list.add(dto);
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -1221,11 +1283,11 @@ System.out.println("search time:"+(end-start));
|
|
|
} else {
|
|
|
String usedPatentNo;
|
|
|
if (publicNo != null && !publicNo.equals("")) {
|
|
|
- usedPatentNo =publicNo;
|
|
|
+ usedPatentNo = publicNo;
|
|
|
} else {
|
|
|
usedPatentNo = grantNo;
|
|
|
}
|
|
|
- if(usedPatentNo!=null){
|
|
|
+ if (usedPatentNo != null) {
|
|
|
pdfUrl = this.getEnPdfApi(usedPatentNo);
|
|
|
if (!pdfUrl.equals("")) {
|
|
|
InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
|