package cn.cslg.pas.service; import cn.cslg.pas.common.core.IgnoreDTDEntityResolver; import cn.cslg.pas.common.dto.PatentStarListDTO; import cn.cslg.pas.common.model.cronModel.Records; import cn.cslg.pas.common.utils.FormatUtil; import cn.cslg.pas.common.utils.RedisUtil; import cn.cslg.pas.common.utils.StringUtils; import cn.cslg.pas.common.vo.PatentWithIdVO; import cn.cslg.pas.domain.es.Patent; import cn.cslg.pas.service.business.es.EsService; import cn.cslg.pas.service.common.PatentStarApiService; import cn.cslg.pas.service.importPatent.SchedulingTaskService; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.XPath; import org.dom4j.io.SAXReader; import org.junit.jupiter.api.Test; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.io.Reader; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * @author chenyu * @date 2023/9/6 */ @SpringBootTest public class PatentStarServiceTests { @Autowired private EsService esService; @Autowired private RedisUtil redisUtil; @Autowired private SchedulingTaskService importTaskAdd; @Autowired private PatentStarApiService patentStarApiService; @Test void addPatent() throws Exception { PatentStarListDTO patentStarListDTO = new PatentStarListDTO(); patentStarListDTO.setCurrentQuery(" TI=计算机"); patentStarListDTO.setDBType("CN"); patentStarListDTO.setOrderBy("AD"); patentStarListDTO.setPageNum(1); patentStarListDTO.setRowCount(10); patentStarListDTO.setOrderByType("DESC"); Records records = patentStarApiService.patentStarSearchLocal(patentStarListDTO); System.out.println(records); } @Test void getPatentByPatentNo() throws Exception { //根据专利号获得id PatentWithIdVO patentWithIdVO = esService.getIdByPatentNo("CN201114765Y"); Patent patent = new Patent(); patent.setAgency("张三"); Patent orgPatent = patentWithIdVO.getPatent(); BeanUtils.copyProperties(patent, orgPatent, FormatUtil.getNullPropertyNames(patent)); esService.updateDocument(orgPatent, patentWithIdVO.getId()); } @Test void updatePatent() throws Exception { String a = patentStarApiService.getCnFullXmlApi("CN2006200179281"); SAXReader reader = new SAXReader(); reader.setEntityResolver(new IgnoreDTDEntityResolver()); Reader stringReader = new StringReader(a); Document document = reader.read(stringReader); XPath xpath = document.createXPath("//claim-text"); List element = (List) xpath.selectNodes(document); if (element.size() == 0) { xpath = document.createXPath("//business:ClaimText"); element = (List) xpath.selectNodes(document); } List reStrs = new ArrayList<>(); element.forEach(item -> { String claim = item.getText(); claim = claim.replaceAll("\r\n|\r|\n| ", ""); claim = claim.replaceAll(" ", ""); reStrs.add(claim); }); String reStr = ""; if (reStrs.size() != 0) { reStr = StringUtils.join(reStrs, "\r\n"); } Element root = document.getRootElement(); //获取根元素的名称 String rootName = root.getName(); System.out.println(rootName); } @Test void updatePatent1() throws Exception { String a = patentStarApiService.getCnFullXmlApi("201210398357"); SAXReader reader = new SAXReader(); reader.setEntityResolver(new IgnoreDTDEntityResolver()); Reader stringReader = new StringReader(a); Document document = reader.read(stringReader); XPath xpath = document.createXPath("//description//p"); List elements = (List) xpath.selectNodes(document); if (elements.size() == 0) { xpath = document.createXPath("//business:Description//base:Paragraphs"); elements = (List) xpath.selectNodes(document); } List reStrs = new ArrayList<>(); Integer count = 1; for (Element item : elements) { String claim = item.getText().replaceAll("
", ""); if (!claim.trim().equals("技术领域") && !claim.trim().equals("发明内容") && !claim.trim().equals("附图说明") && !claim.trim().equals("具体实施方式") && !claim.trim().equals("背景技术")) { String formattedNum = String.format("%04d", count); claim = "[" + formattedNum + "]" + claim; count++; } reStrs.add(claim); } String reStr = ""; if (reStrs.size() != 0) { reStr = StringUtils.join(reStrs, "\r\n"); } System.out.println(reStr); Element root = document.getRootElement(); //获取根元素的名称 String rootName = root.getName(); System.out.println(rootName); } @Test void addImportTask() throws Exception { List patentList = esService.searchChild("1", 1, 10); System.out.println(patentList); Thread.sleep(1000000); } @Test void getLegalEvent() throws Exception { String a = patentStarApiService.getCnLegalApi("201210398357"); System.out.println(a); Thread.sleep(1000000); } @Test void getFamilyPatent() throws Exception { String a = patentStarApiService.getFamilyByPubNoApi("CN116825114A"); System.out.println(a); Thread.sleep(1000000); } }