|
@@ -0,0 +1,260 @@
|
|
|
+package cn.cslg.pas.service.upLoadPatent;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.model.outApi.PatentStarListDto;
|
|
|
+import cn.cslg.pas.common.model.vo.UploadParamsVO;
|
|
|
+import cn.cslg.pas.common.model.vo.outApi.StarPatentVO;
|
|
|
+import cn.cslg.pas.domain.*;
|
|
|
+import cn.cslg.pas.domain.asso.AssoOsTaskQrtzTask;
|
|
|
+import cn.cslg.pas.service.asso.AssoOsTaskQrtzTaskService;
|
|
|
+import cn.cslg.pas.service.outApi.PatentStarApiService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 专利之星类型任务解析获取专利类
|
|
|
+ *
|
|
|
+ * @Author chenyu
|
|
|
+ * @Date 2023/6/25
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class ExcutePatentDataStar implements IExcutePatentData {
|
|
|
+ private final AssoOsTaskQrtzTaskService assoOsTaskQrtzTaskService;
|
|
|
+ private final PatentStarApiService patentStarApiService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析获取专利数据
|
|
|
+ *
|
|
|
+ * @param task 任务
|
|
|
+ * @throws IOException 抛出IO异常
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void startExcute(Task task) throws IOException {
|
|
|
+ //从任务关联网站导入任务表中取出当前任务
|
|
|
+ List<AssoOsTaskQrtzTask> assoOsTaskQrtzTasks = assoOsTaskQrtzTaskService.list(new LambdaQueryWrapper<AssoOsTaskQrtzTask>().eq(AssoOsTaskQrtzTask::getTaskId, task.getId()));
|
|
|
+ AssoOsTaskQrtzTask assoOsTaskQrtzTask = assoOsTaskQrtzTasks.get(0);
|
|
|
+
|
|
|
+ //从任务数据中获取下载字段、检索式
|
|
|
+ String cellsStr = assoOsTaskQrtzTask.getConfigCells();
|
|
|
+ List<String> cells = Arrays.asList(cellsStr.split(","));
|
|
|
+ String conditions = assoOsTaskQrtzTask.getConditions();
|
|
|
+
|
|
|
+ //定义每次检索的专利数量(每次检索50件)
|
|
|
+ int size = 50;
|
|
|
+
|
|
|
+ //获得专利总数量
|
|
|
+ Integer count = task.getTotal();
|
|
|
+
|
|
|
+ ArrayList<UploadParamsVO> uploadParamsVOs = new ArrayList<>();
|
|
|
+ //1.根据专利总数量count遍历检索专利
|
|
|
+ for (int i = 1; i <= count; i += size) {
|
|
|
+ PatentStarListDto patentStarListDto = new PatentStarListDto()
|
|
|
+ .setCurrentQuery(conditions)
|
|
|
+ .setOrderBy("AD")
|
|
|
+ .setOrderByType("DESC")
|
|
|
+ .setPageNum(1)
|
|
|
+ .setRowCount(size)
|
|
|
+ .setDBType("cN");
|
|
|
+ //调用一般接口
|
|
|
+ Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
|
|
|
+ if (resultMap == null || (Integer) resultMap.get("total") == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //调用一般接口返回专利相关数据
|
|
|
+ List<StarPatentVO> patents = (List<StarPatentVO>) resultMap.get("records");
|
|
|
+
|
|
|
+ //遍历50个专利
|
|
|
+ for (StarPatentVO starPatent : patents) {
|
|
|
+ UploadParamsVO uploadParamsVO = new UploadParamsVO();
|
|
|
+ Patent patent = new Patent();
|
|
|
+ //装载专利著录
|
|
|
+ if (cells.contains("1")) {
|
|
|
+ setPatentZhuLu(starPatent, uploadParamsVO, patent);
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载权要
|
|
|
+ if (cells.contains("2")) {
|
|
|
+ setPatentClaim(starPatent, uploadParamsVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载说明书文本
|
|
|
+ if (cells.contains("3")) {
|
|
|
+ setPatentInstructionText(starPatent, uploadParamsVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ uploadParamsVOs.add(uploadParamsVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("专利总数量:" + uploadParamsVOs.size());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载著录方法
|
|
|
+ *
|
|
|
+ * @param uploadParamsVO 专利实体类对象
|
|
|
+ * @param patent 专利基础数据实体类对象
|
|
|
+ * @param starPatent 专利之星著录对象
|
|
|
+ */
|
|
|
+ private void setPatentZhuLu(StarPatentVO starPatent, UploadParamsVO uploadParamsVO, Patent patent) {
|
|
|
+ //装载专利号
|
|
|
+ patent.setPatentNo(starPatent.getPatentNo());
|
|
|
+ //装载申请号
|
|
|
+ patent.setApplicationNo(starPatent.getApplicationNo());
|
|
|
+ //装载申请日
|
|
|
+ if (starPatent.getApplicationDate() != null && !starPatent.getApplicationDate().equals("")) {
|
|
|
+ patent.setApplicationDate(Integer.parseInt(starPatent.getApplicationDate()));
|
|
|
+ }
|
|
|
+ //装载公开号
|
|
|
+ patent.setPublicNo(starPatent.getPublicNo());
|
|
|
+
|
|
|
+ //装载公开日
|
|
|
+ if (starPatent.getPublicDate() != null && !starPatent.getPublicDate().equals(""))
|
|
|
+ patent.setPublicDate(Integer.parseInt(starPatent.getPublicDate()));
|
|
|
+ //装载申请人
|
|
|
+ if (starPatent.getAbstractStr() != null && !starPatent.getAbstractStr().equals("")) {
|
|
|
+ uploadParamsVO.setPatentApplicantOriginalName(Arrays.asList(starPatent.getApplicantStr().split(";")));
|
|
|
+ }
|
|
|
+ //装载摘要
|
|
|
+ patent.setAbstractStr(starPatent.getAbstractStr());
|
|
|
+ //装载标题
|
|
|
+ patent.setName(starPatent.getName());
|
|
|
+ //装载IPC分类号
|
|
|
+ if (starPatent.getIpcListStr() != null && !starPatent.getIpcListStr().equals("")) {
|
|
|
+ String[] ipcArr = starPatent.getIpcListStr().split(";");
|
|
|
+ //装载IPC分类号
|
|
|
+ uploadParamsVO.setMainIpc(ipcArr[0]);
|
|
|
+ uploadParamsVO.setIpcList(Arrays.asList(ipcArr));
|
|
|
+ }
|
|
|
+ //以上 ↑装载的是调用"一般接口"返回的专利相关数据
|
|
|
+
|
|
|
+ //以下 ↓装载的是调用"中国专利著录接口"返回的专利相关数据
|
|
|
+ String appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
|
|
|
+ //调用中国专利著录接口返回的专利相关数据最外层是一个集合"[]",但是集合中只有一个对象"{}",以下方式处理
|
|
|
+ String chinaPatentZhuLuStr = patentStarApiService.getCnBibApi(appNo);
|
|
|
+ //chinaPatentZhuLuStr = chinaPatentZhuLuStr.substring(chinaPatentZhuLuStr.indexOf("["), chinaPatentZhuLuStr.lastIndexOf("[")).trim();
|
|
|
+ //ChinaPatentZhuLu chinaPatentZhuLu = JSONObject.parseObject(chinaPatentZhuLuStr, ChinaPatentZhuLu.class);
|
|
|
+ //以上暂无需处理 ↑ 以下 ↓有现成的json数组字符串转为集合方法
|
|
|
+ List<ChinaPatentZhuLu> chinaPatentZhuLus = JSON.parseArray(chinaPatentZhuLuStr, ChinaPatentZhuLu.class);
|
|
|
+ ChinaPatentZhuLu chinaPatentZhuLu = chinaPatentZhuLus.get(0);
|
|
|
+
|
|
|
+ //装载申请人地址
|
|
|
+ ArrayList<String> patentApplicantOriginalAddresss = new ArrayList<>();
|
|
|
+ patentApplicantOriginalAddresss.add(chinaPatentZhuLu.getDZ().substring(chinaPatentZhuLu.getDZ().indexOf(" ") + 1));
|
|
|
+ uploadParamsVO.setPatentApplicantOriginalAddress(patentApplicantOriginalAddresss);
|
|
|
+
|
|
|
+ //装载代理人
|
|
|
+ List<String> patentAgents = Arrays.asList(chinaPatentZhuLu.getAT().split(";"));
|
|
|
+ ArrayList<PatentAgent> patentAgentList = new ArrayList<>();
|
|
|
+ for (String n : patentAgents) {
|
|
|
+ PatentAgent patentAgent = new PatentAgent();
|
|
|
+ patentAgent.setName(n);
|
|
|
+ patentAgentList.add(patentAgent);
|
|
|
+ }
|
|
|
+ uploadParamsVO.setPatentAgentList(patentAgentList);
|
|
|
+
|
|
|
+ //装载代理机构地址
|
|
|
+ if (chinaPatentZhuLu.getAGN() != null && !chinaPatentZhuLu.getAGN().equals("")) {
|
|
|
+ String agencyAddress = chinaPatentZhuLu.getAGN().substring(0, chinaPatentZhuLu.getAGN().lastIndexOf(" "));
|
|
|
+ patent.setAgencyId(agencyAddress);
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载发明人
|
|
|
+ List<String> patentInventorNames = Arrays.asList(chinaPatentZhuLu.getIV().split(";"));
|
|
|
+ ArrayList<PatentInventor> patentInventors = new ArrayList<>();
|
|
|
+ for (String patentInventorName : patentInventorNames) {
|
|
|
+ PatentInventor patentInventor = new PatentInventor();
|
|
|
+ patentInventor.setName(patentInventorName);
|
|
|
+ patentInventors.add(patentInventor);
|
|
|
+ }
|
|
|
+ uploadParamsVO.setPatentInventorList(patentInventors);
|
|
|
+
|
|
|
+ //装载同族号
|
|
|
+// patentCell.setFamilyId(patent.getFamilyId());
|
|
|
+// //装载优先权号、优先权国家、优先权日
|
|
|
+// ArrayList<Priority> priorities = new ArrayList<>();
|
|
|
+// List<Priorityy> priorties = patent.getPriorties();
|
|
|
+// for (Priorityy priorty : priorties) {
|
|
|
+// for (PriorityNumber number : priorty.getNumbers()) {
|
|
|
+// if (number.getType().equals("epodoc")) {
|
|
|
+// Priority priority = new Priority()
|
|
|
+// .setPriorityNo(number.getNumber().substring(2))
|
|
|
+// .setPriorityCountry(number.getNumber().substring(0, 2))
|
|
|
+// .setPriorityDate(priorty.getDate());
|
|
|
+// priorities.add(priority);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// patentCell.setPriorities(priorities);
|
|
|
+ uploadParamsVO.setPatent(patent);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载权要方法
|
|
|
+ *
|
|
|
+ * @param uploadParamsVO 专利实体类对象
|
|
|
+ */
|
|
|
+ private void setPatentClaim(StarPatentVO starPatent, UploadParamsVO uploadParamsVO) throws IOException {
|
|
|
+ String appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
|
|
|
+ //根据申请号调用"获得中国专利全文文本"接口,获得包含各种xml标签的专利全文内容的长字符串 cnFullXmlStr
|
|
|
+ String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(appNo);
|
|
|
+
|
|
|
+ //使用正则表达式,拼接出权要原文
|
|
|
+ String regex = "(?<=<claim-text>)[\\w\\W]+?(?=</claim-text>)";
|
|
|
+ Pattern compile = Pattern.compile(regex);
|
|
|
+ Matcher matcher = compile.matcher(cnFullXmlStr);
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ while (matcher.find()) {
|
|
|
+ builder.append(matcher.group()).append("\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载权利要求原文
|
|
|
+ PatentRight patentRight = new PatentRight();
|
|
|
+ patentRight.setContent(builder + "");
|
|
|
+ uploadParamsVO.setPatentRight(patentRight);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载说明书文本
|
|
|
+ *
|
|
|
+ * @param uploadParamsVO 专利实体类对象
|
|
|
+ */
|
|
|
+ private void setPatentInstructionText(StarPatentVO starPatent, UploadParamsVO uploadParamsVO) throws IOException {
|
|
|
+ String appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
|
|
|
+ //根据申请号调用"获得中国专利全文文本"接口,获得包含各种xml标签的专利全文内容的长字符串 cnFullXmlStr
|
|
|
+ String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(appNo);
|
|
|
+
|
|
|
+ //使用正则表达式,拼接出说明书文本全文
|
|
|
+ String regex = "(?<=<claim-text>)[\\w\\W]+?(?=</claim-text>)";
|
|
|
+ Pattern compile = Pattern.compile(regex);
|
|
|
+ Matcher matcher = compile.matcher(cnFullXmlStr);
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ while (matcher.find()) {
|
|
|
+ builder.append(matcher.group()).append("\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载说明书文本全文
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|