123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- package cn.cslg.pas.service;
- import cn.cslg.pas.common.model.params.PatentRightParams;
- import cn.cslg.pas.common.utils.PatentUtils;
- import cn.cslg.pas.common.utils.Response;
- import cn.cslg.pas.common.utils.StringUtils;
- import cn.cslg.pas.domain.Authority;
- import cn.cslg.pas.domain.Patent;
- import cn.cslg.pas.domain.PatentRight;
- import cn.cslg.pas.mapper.PatentRightMapper;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import lombok.RequiredArgsConstructor;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- /**
- * @author Administrator
- * @description 针对表【os_patent_right(专利权利要求)】的数据库操作Service
- * @createDate 2022-04-16 10:09:24
- */
- @Service
- @RequiredArgsConstructor(onConstructor_ = {@Lazy})
- public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRight> {
- private final PatentService patentService;
- public List<PatentRight> getPatentRightByPatentNo(String patentNo) {
- Patent patent = patentService.getByPatentNo(patentNo);
- LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(PatentRight::getPatentId, patent.getId());
- queryWrapper.orderByAsc(PatentRight::getSort);
- return this.list(queryWrapper);
- }
- public List<PatentRight> getPatentRightByPatentId(Integer patentId) {
- LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(PatentRight::getPatentId, patentId);
- queryWrapper.orderByAsc(PatentRight::getSort);
- return this.list(queryWrapper);
- }
- public List<PatentRight> getPatentRightByPatentIds(List<Integer> patentIds) {
- if (patentIds == null || patentIds.size() == 0) {
- return new ArrayList<>();
- }
- LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(PatentRight::getPatentId, patentIds);
- queryWrapper.orderByAsc(PatentRight::getSort);
- return this.list(queryWrapper);
- }
- public void deleteByPatentId(Integer patentId) {
- this.remove(Wrappers.<PatentRight>lambdaQuery().eq(PatentRight::getPatentId, patentId));
- }
- public void importPatentRight(Integer localPatentId, Integer importPatentId, List<PatentRight> importPatentRightList) {
- this.deleteByPatentId(localPatentId);
- List<PatentRight> patentRightList = importPatentRightList.stream().filter(item -> item.getPatentId().equals(importPatentId)).collect(Collectors.toList());
- for (PatentRight patentRight : patentRightList) {
- patentRight.setId(null);
- patentRight.setPatentId(localPatentId);
- }
- this.saveOrUpdateBatch(patentRightList);
- }
- public void importAuthority(PatentRightParams params) {
- List<Authority> splits = splits(params);
- List<Authority> authorities = relationshipAuthority(splits);
- List<Authority> authorities1 = relationshipAuthority3(authorities);
- List<Authority> authorities2 = relationshipAuthority2(authorities1);
- List<Authority> authorities3 = relationshipAuthority4(authorities2);
- for (Authority a : authorities3) {
- Authority authority = new Authority();
- authority.setContent(a.getContent());
- String join = StringUtils.join(a.getFatherID(), ",");
- authority.setFID(join);
- String join1 = StringUtils.join(a.getSonID(), ",");
- authority.setSID(join1);
- authority.setPatentID(params.getPatentId());
- authority.setType(a.getType());
- authority.insert();
- }
- }
- public List<Authority> splits(PatentRightParams params) {
- //去掉全要开头的""
- List<Authority> list = new ArrayList<>();
- String selfContent = params.getContent();
- if (selfContent == null) {
- selfContent = "";
- }
- //청구항 2. 삭제(是否删除代办)
- // selfContent.replaceAll("청구항(\\s)(^\\d*$+)(\\s)삭제","");
- selfContent.replaceAll("''", "");
- selfContent.replaceAll("(^\\d*$+)-(^\\d*$+)(\\.)(\\s)(canceled)", "");
- // selfContent.replaceAll("(^\\d*$+)(.)(\\s)(canceled)","");
- selfContent.replaceAll("\n", " ");
- //找到1. 2. ...这种格式的正则表达式
- String str1 = "(^\\d*$+)(\\.)";
- //找到[001]或者[002]这种格式的
- String str2 = "(\\[)(^[1-9]/d*$+)(\\])";
- //【請求項 1】
- String str3 = "(\\【請求項)(^[1-9]/d*$+)(\\】)";
- //청구항 1()
- String str4 = "청구항(\\s)(^[1-9]/d*$+)(\\.)";
- Pattern p4 = Pattern.compile(str4);
- Matcher m4 = p4.matcher(selfContent);
- List<Integer> integers1 = new ArrayList<>();
- while (m4.find()) {
- integers1.add(m4.start());
- }
- if (integers1.size() != 0) {
- for (int i = integers1.size() - 1; i >= 0; i--) {
- String str = selfContent.substring(integers1.get(i));
- Authority authority = new Authority();
- authority.setContent(str);
- list.add(authority);
- }
- Authority authority = new Authority();
- authority.setContent(selfContent);
- list.add(authority);
- return list;
- }
- Pattern p = Pattern.compile(str1);
- Matcher m = p.matcher(selfContent);
- //判断找到的数量
- List<Integer> integers = new ArrayList<>();
- while (m.find()) {
- integers.add(m.start());
- }
- if (integers.size() != 0) {
- for (int i = integers.size() - 1; i > 0; i--) {
- String str = selfContent.substring(integers.get(i));
- Authority authority1 = new Authority();
- authority1.setContent(str);
- list.add(authority1);
- }
- Authority authority1 = new Authority();
- authority1.setContentOut(selfContent);
- list.add(authority1);
- return list;
- }
- Pattern compile = Pattern.compile(str2);
- Matcher matcher = compile.matcher(selfContent);
- List<Integer> start = new ArrayList<>();
- while (matcher.find()) {
- start.add(matcher.start());
- }
- if (start.size() != 0) {
- for (int i = start.size() - 1; i > 0; i--) {
- String str = selfContent.substring(integers.get(i));
- Authority authority2 = new Authority();
- authority2.setContent(str);
- list.add(authority2);
- }
- Authority authority2 = new Authority();
- authority2.setContent(selfContent);
- list.add(authority2);
- return list;
- }
- Pattern compile1 = Pattern.compile(str3);
- Matcher matcher1 = compile1.matcher(selfContent);
- List<Integer> start1 = new ArrayList<>();
- while (matcher1.find()) {
- start1.add(matcher1.start());
- }
- if (start1.size() != 0) {
- for (int i = start1.size() - 1; i >= 0; i--) {
- String str = selfContent.substring(integers.get(i));
- Authority authority3 = new Authority();
- authority3.setContent(str);
- list.add(authority3);
- }
- Authority authority3 = new Authority();
- authority3.setContent(selfContent);
- list.add(authority3);
- }
- return list;
- }
- /**
- * 英文下的处理方式(草稿)
- */
- private List<Authority> relationshipAuthority(List<Authority> list) {
- List<Authority> authorities = list;
- //英文下的claim 1,claim2 的正则表达式
- String str1 = "(claim)(\\s)(^\\d*$+)";
- Pattern p = Pattern.compile(str1);
- for (int i = 0; i < list.size(); i++) {
- //去掉空格
- authorities.get(i).getContent().replaceAll(" ", "");
- Matcher m = p.matcher(authorities.get(i).getContent());
- if (!m.find()) {
- list.get(i).setFID(null);
- list.get(i).setType(0);
- return list;
- } else {
- //找到了
- String group = m.group(0);
- //把claim去掉只剩下面的数字
- String substring = group.substring(5);
- int j = Integer.parseInt(substring);
- List<Integer> sonID = list.get(j - 1).getSonID();
- sonID.add(authorities.get(i).getId());
- list.get(j - 1).setSonID(sonID);
- List<Integer> fatherID = list.get(i).getFatherID();
- fatherID.add(list.get(j - 1).getId());
- list.get(i).setFatherID(fatherID);
- //设置为
- list.get(i).setType(1);
- }
- }
- return list;
- }
- /**
- * 小日子的语言下的处理模式
- */
- private List<Authority> relationshipAuthority3(List<Authority> list) {
- List<Authority> authorities = list;
- //英文下的claim 1,claim2 的正则表达式
- String str1 = "(前記第)(^\\d*$+)";
- Pattern p = Pattern.compile(str1);
- for (int i = 0; i < list.size(); i++) {
- Matcher m = p.matcher(authorities.get(i).getContent());
- if (!m.find()) {
- list.get(i).setFID(null);
- list.get(i).setType(0);
- return list;
- } else {
- //找到了
- String group = m.group(0);
- //把claim去掉只剩下面的数字
- String substring = group.substring(3);
- int j = Integer.parseInt(substring);
- List<Integer> sonID = list.get(j - 1).getSonID();
- sonID.add(authorities.get(i).getId());
- list.get(j - 1).setSonID(sonID);
- List<Integer> fatherID = list.get(i).getFatherID();
- fatherID.add(list.get(j - 1).getId());
- list.get(i).setFatherID(fatherID);
- //设置为
- list.get(i).setType(1);
- }
- }
- return list;
- }
- /**
- * 中文下的处理方式
- */
- public List<Authority> relationshipAuthority2(List<Authority> list) {
- //中文下权利要求1,权利要求2,权利要求3
- String str1 = "(权利要求)(^\\d*$+)";
- //中文下权利要求1至
- String str2 = "(权利要求)(^\\d*$+)(至)(^\\d*$+)";
- //中文下权利要求 或
- String str3 = "(权利要求)(^\\d*$+)(或)(^\\d*$+)";
- Pattern p = Pattern.compile(str1);
- Pattern p1 = Pattern.compile(str2);
- Pattern p2 = Pattern.compile(str3);
- for (int i = 0; i < list.size(); i++) {
- Matcher matcher = p.matcher(list.get(i).getContent());
- if (matcher.find()) {
- list.get(i).setType(1);
- //找到满足第一情况
- Matcher matcher1 = p1.matcher(list.get(i).getContent());
- if (matcher1.find()) {
- //找到满足第一和第二种情况按第二种情况处理
- String group = matcher1.group(0);
- String str5 = "^\\d*$+";
- Pattern p3 = Pattern.compile(str5);
- Matcher matcher2 = p3.matcher(group);
- if (matcher2.find()) {
- String group1 = matcher2.group(0);
- String group2 = matcher2.group(1);
- Integer j = Integer.parseInt(group1);
- Integer k = Integer.parseInt(group2);
- for (int l = j - 1; l < k; l++) {
- List<Integer> sonID = list.get(l).getSonID();
- sonID.add(list.get(i).getId());
- list.get(l).setSonID(sonID);
- List<Integer> fatherID = list.get(i).getFatherID();
- fatherID.add(list.get(l).getId());
- list.get(i).setFatherID(fatherID);
- }
- }
- } else {
- Matcher matcher2 = p2.matcher(list.get(i).getContent());
- if (matcher2.find()) {
- //找到满足第三和第一情况按第三中情况处理
- String group = matcher1.group(0);
- String str6 = "^\\d*$+";
- Pattern p3 = Pattern.compile(str6);
- Matcher matcher3 = p3.matcher(group);
- if (matcher3.find()) {
- String group1 = matcher2.group(0);
- String group2 = matcher2.group(1);
- Integer j = Integer.parseInt(group1);
- Integer k = Integer.parseInt(group2);
- List<Integer> sonID = list.get(j).getSonID();
- sonID.add(list.get(i).getId());
- list.get(j).setSonID(sonID);
- List<Integer> fatherID = list.get(i).getFatherID();
- fatherID.add(list.get(j).getId());
- list.get(i).setFatherID(fatherID);
- List<Integer> sonID1 = list.get(k).getSonID();
- sonID1.add(list.get(i).getId());
- list.get(k).setSonID(sonID1);
- List<Integer> fatherID1 = list.get(i).getFatherID();
- fatherID1.add(list.get(k).getId());
- list.get(i).setFatherID(fatherID1);
- }
- } else {
- //只满足第一中情况
- String group = matcher.group(0);
- String str7 = "^\\d*$+";
- Pattern p3 = Pattern.compile(str7);
- Matcher matcher3 = p3.matcher(group);
- if (matcher3.find()) {
- String group1 = matcher2.group(0);
- Integer j = Integer.parseInt(group1);
- List<Integer> sonID = list.get(j).getSonID();
- sonID.add(list.get(i).getId());
- list.get(j).setSonID(sonID);
- List<Integer> fatherID = list.get(i).getFatherID();
- fatherID.add(list.get(j).getId());
- list.get(i).setFatherID(fatherID);
- }
- }
- }
- } else {
- list.get(i).setType(0);
- list.get(i).setFID(null);
- }
- }
- return list;
- }
- /**
- * 韩文下的处理
- */
- public List<Authority> relationshipAuthority4(List<Authority> list) {
- //韩文情况下的正则表达式
- String str1 = "제(\\s)(^\\d*$+)항"; //"제 1항에" ;
- String str3 = "제(\\s)(^\\d*$+)항(\\s)또는(\\s)제(^\\d*$+)항";//제 1항 또는 제 2항에 있어서 这种情况下的正则表达式
- Pattern p = Pattern.compile(str1);
- for (int i = 0; i < list.size(); i++) {
- // list.get(i).getContent().replaceAll(" ", "");
- Matcher m = p.matcher(list.get(i).getContent());
- if (!m.find()) {
- list.get(i).setFID(null);
- list.get(i).setType(0);
- } else {
- //找到了
- Pattern compile = Pattern.compile(str3);
- Matcher matcher1 = compile.matcher(list.get(i).getContent());
- if (matcher1.find()) {
- String group = m.group(0);
- String str2 = "(^\\d*$+)";
- Pattern p1 = Pattern.compile(str1);
- Matcher matcher = p1.matcher(group);
- String group1 = matcher.group(0);
- String group2 = matcher.group(1);
- Integer j = Integer.parseInt(group1);
- Integer k = Integer.parseInt(group2);
- List<Integer> sonID = list.get(j).getSonID();
- sonID.add(list.get(i).getId());
- list.get(j).setSonID(sonID);
- List<Integer> fatherID = list.get(i).getFatherID();
- fatherID.add(list.get(j).getId());
- list.get(i).setFatherID(fatherID);
- List<Integer> sonID1 = list.get(k).getSonID();
- sonID1.add(list.get(i).getId());
- list.get(k).setSonID(sonID1);
- List<Integer> fatherID1 = list.get(i).getFatherID();
- fatherID1.add(list.get(k).getId());
- list.get(i).setFatherID(fatherID1);
- } else {
- String group = m.group(0);
- String str2 = "(^\\d*$+)";
- Pattern p1 = Pattern.compile(str1);
- Matcher matcher = p1.matcher(group);
- String substring = matcher.group(0);
- int j = Integer.parseInt(substring);
- List<Integer> sonID = list.get(j - 1).getSonID();
- sonID.add(list.get(i).getId());
- list.get(j - 1).setSonID(sonID);
- List<Integer> fatherID = list.get(i).getFatherID();
- fatherID.add(list.get(j - 1).getId());
- list.get(i).setFatherID(fatherID);
- //设置为
- list.get(i).setType(1);
- }
- }
- }
- return list;
- }
- public void updatePatentRight(PatentRightParams params) {
- // List<PatentRight> patentRightList = new ArrayList<>();
- // 获取国家 公开号前两位
- // String country = PatentUtils.getPatentCountry(params.getPatentNo());
- // String code;
- //权利要求原文
- String content = params.getContent();
- //权利要求译文
- String contentOut = params.getContentOut();
- //独立权利要求
- String selfContent = params.getSelfContent();
- if (StringUtils.isNotEmpty(content)) {
- this.deleteByPatentId(params.getPatentId());
- // String[] contentArray = null;
- // String[] contentOutArray = null;
- // String[] selfContentArray = null;
- // switch (country) {
- // case "JP":
- // case "CN":
- // code = "。";
- // if (StringUtils.isNotEmpty(contentOut)) {
- // contentOut = contentOut.replaceAll("\n", "");
- // contentOutArray = StringUtils.split(contentOut, code);
- // }
- // if (StringUtils.isNotEmpty(selfContent)) {
- // selfContent = selfContent.replaceAll("\n", "");
- // selfContentArray = StringUtils.split(selfContent, code);
- // }
- // content = content.replaceAll("\n", "");
- // contentArray = StringUtils.split(content, code);
- // break;
- // default:
- // code = "\n";
- // if (StringUtils.isNotEmpty(contentOut)) {
- // contentOutArray = StringUtils.split(contentOut, code);
- // }
- // if (StringUtils.isNotEmpty(selfContent)) {
- // selfContentArray = StringUtils.split(selfContent, code);
- // }
- // contentArray = StringUtils.split(content, code);
- // }
- // for (int i = 0; i < contentArray.length; i++) {
- // if (StringUtils.isEmpty(contentArray[i])) {
- // continue;
- // }
- // PatentRight patentRight = new PatentRight();
- // patentRight.setPatentId(params.getPatentId());
- // patentRight.setContent(contentArray[i]);
- // patentRight.setType(0);
- // patentRight.setSort(i);
- // if (contentOutArray != null && i < contentOutArray.length) {
- // patentRight.setContentOut(contentOutArray[i]);
- // }
- // if (selfContentArray != null) {
- // String temp = Arrays.stream(selfContentArray).filter(item -> item.equals(patentRight.getContent())).findFirst().orElse(null);
- // if (temp != null) {
- // patentRight.setType(1);
- // }
- // }
- // patentRightList.add(patentRight);
- ArrayList<PatentRight> patentRights = new ArrayList<>();
- //先去掉所有换行符,使原文连起来
- if (content.contains("\r\n")) {
- content = content.replaceAll("\r\n", "");
- } else {
- content = content.replaceAll("\n", "");
- }
- if (contentOut == null) {
- contentOut = "";
- }
- if (contentOut.contains("\r\n")) {
- contentOut = contentOut.replaceAll("\r\n", "");
- } else {
- contentOut = contentOut.replaceAll("\n", "");
- }
- //根据专利所属国家,定义序号规则
- String regex;
- if (content.contains("1.")) {
- regex = "[0-9]+[.]";
- } else if (content.contains("1、")) {
- regex = "[0-9]+[、]";
- } else if (content.contains("[001]")) {
- regex = "\\[[0-9]+]";
- } else {
- regex = "";
- }
- Pattern compile = Pattern.compile(regex);
- Matcher matcher = compile.matcher(content);
- Matcher matcherOut = compile.matcher(contentOut);
- while (matcher.find()) {
- if (!matcher.group().equals("1.") && !matcher.group().equals("1、") && !matcher.group().equals("[001]")) {
- content = content.replaceFirst(matcher.group(), "\n" + matcher.group());
- }
- }
- String[] strs = content.split("\n");
- while (matcherOut.find()) {
- if (!matcherOut.group().equals("1.") && !matcherOut.group().equals("1、") && !matcherOut.group().equals("[001]")) {
- contentOut = contentOut.replaceFirst(matcherOut.group(), "\n" + matcherOut.group());
- }
- }
- String[] strsOut = contentOut.split("\n");
- //定义父权要排序号
- String regex1 = "权利要求[0-9]+";
- String regex2 = "权利要求[0-9]+[至或~-]+[0-9]+";
- for (int i = 0; i < strs.length; i++) {
- if (strs[i].contains("权利要求")) {
- Pattern compile1 = Pattern.compile(regex1);
- Matcher matcher1 = compile1.matcher(strs[i]);
- Pattern compile2 = Pattern.compile(regex2);
- Matcher matcher2 = compile2.matcher(strs[i]);
- if (matcher2.find()) {
- String parentNum = matcher2.group().substring(matcher2.group().indexOf("求") + 1);
- String[] parentNums;
- if (parentNum.contains("~")) {
- parentNums = parentNum.split("~");
- } else if (parentNum.contains("-")) {
- parentNums = parentNum.split("-");
- } else if (parentNum.contains("至")) {
- parentNums = parentNum.split("至");
- } else if (parentNum.contains("或")) {
- parentNums = parentNum.split("或");
- } else {
- parentNums = new String[0];
- }
- StringBuilder builder = new StringBuilder();
- for (int j = Integer.parseInt(parentNums[0]) - 1; j < Integer.parseInt(parentNums[parentNums.length - 1]); j++) {
- if ((builder + "").equals("")) {
- builder.append(j);
- } else {
- builder.append(",").append(j);
- }
- }
- PatentRight patentRight = new PatentRight()
- .setPatentId(params.getPatentId())
- .setType(1)
- .setContent(strs[i])
- .setSort(i)
- .setParentSort(builder + "");
- if (strsOut.length - 1 >= i) {
- patentRight.setContentOut(strsOut[i]);
- }
- patentRights.add(patentRight);
- } else if (matcher1.find()) {
- String parentNum = matcher1.group().substring(matcher1.group().indexOf("求") + 1);
- PatentRight patentRight = new PatentRight()
- .setPatentId(params.getPatentId())
- .setType(1)
- .setContent(strs[i])
- .setSort(i)
- .setParentSort((Integer.parseInt(parentNum) - 1) + "");
- if (strsOut.length - 1 >= i) {
- patentRight.setContentOut(strsOut[i]);
- }
- patentRights.add(patentRight);
- }
- } else {
- PatentRight patentRight = new PatentRight()
- .setPatentId(params.getPatentId())
- .setType(0)
- .setContent(strs[i])
- .setSort(i)
- .setParentSort("-1");
- if (strsOut.length - 1 >= i) {
- patentRight.setContentOut(strsOut[i]);
- }
- patentRights.add(patentRight);
- }
- }
- this.saveOrUpdateBatch(patentRights);
- }
- }
- }
|