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 { private final PatentService patentService; public List getPatentRightByPatentNo(String patentNo) { Patent patent = patentService.getByPatentNo(patentNo); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(PatentRight::getPatentId, patent.getId()); queryWrapper.orderByAsc(PatentRight::getSort); return this.list(queryWrapper); } public List getPatentRightByPatentId(Integer patentId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(PatentRight::getPatentId, patentId); queryWrapper.orderByAsc(PatentRight::getSort); return this.list(queryWrapper); } public List getPatentRightByPatentIds(List patentIds) { if (patentIds == null || patentIds.size() == 0) { return new ArrayList<>(); } LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(PatentRight::getPatentId, patentIds); queryWrapper.orderByAsc(PatentRight::getSort); return this.list(queryWrapper); } public void deleteByPatentId(Integer patentId) { this.remove(Wrappers.lambdaQuery().eq(PatentRight::getPatentId, patentId)); } public void importPatentRight(Integer localPatentId, Integer importPatentId, List importPatentRightList) { this.deleteByPatentId(localPatentId); List 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 splits = splits(params); List authorities = relationshipAuthority(splits); List authorities1 = relationshipAuthority3(authorities); List authorities2 = relationshipAuthority2(authorities1); List 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 splits(PatentRightParams params){ //去掉全要开头的"" String selfContent= params.getContent(); selfContent.replaceAll("''",""); selfContent.replaceAll("\n"," "); // selfContent.replaceAll(" ",""); List list = new ArrayList<>(); //找到1. 2. ...这种格式的正则表达式 String str1="(^\\d*$+)(\\.)"; //找到[001]或者[002]这种格式的 String str2="(\\[)(^[1-9]/d*$+)(\\])"; //【請求項 1】 String str3="(\\【請求項)(^[1-9]/d*$+)(\\】)"; //청구항 1() String str4="청구항(^[1-9]/d*$+)"; Pattern p4 = Pattern.compile(str4); Matcher m4 = p4.matcher(selfContent); if(m4.find()) { String str5="."; Pattern p5 = Pattern.compile(str4); Matcher m5 = p5.matcher(selfContent); List integers1=new ArrayList<>(); while (m5.find()){ integers1.add(m5.start()); } 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 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 authority=new Authority(); authority.setContent(str); list.add(authority); } return list; } Pattern compile = Pattern.compile(str2); Matcher matcher = compile.matcher(selfContent); List start=new ArrayList<>(); List end=new ArrayList<>(); while (matcher.find()){ start.add( matcher.start()); end.add(matcher.end()); } if(start.size()!=0){ for(int i=start.size()-1;i>=0;i--) { if(i==start.size()-1){ String substring = selfContent.substring(end.get(i)); String string=new String(String.valueOf(i)); string=string+"."+substring; Authority authority=new Authority(); list.add(authority); } String substring = selfContent.substring(end.get(i),start.get(i+1)); String string=new String(String.valueOf(i)); string=string+"."+substring; Authority authority=new Authority(); list.add(authority); } return list; } Pattern compile1 = Pattern.compile(str3); Matcher matcher1 = compile1.matcher(selfContent); List start1=new ArrayList<>(); List end1=new ArrayList<>(); while (matcher1.find()){ start1.add( matcher1.start()); end1.add(matcher1.end()); } if(start1.size()!=0){ for(int i=start1.size()-1;i>=0;i--) { if(i==start1.size()-1){ String substring = selfContent.substring(end.get(i)); String string=new String(String.valueOf(i)); string=string+"."+substring; Authority authority=new Authority(); list.add(authority); } String substring = selfContent.substring(end.get(i),start.get(i+1)); String string=new String(String.valueOf(i)); string=string+"."+substring; Authority authority=new Authority(); list.add(authority); } return list; } return list; } /** * 英文下的处理方式(草稿) */ private List relationshipAuthority(List list){ List authorities=list; //英文下的claim 1,claim2 的正则表达式 String str1="(claim)(\\s)(^\\d*$+)"; Pattern p = Pattern.compile(str1); for(int i=0;i sonID = list.get(j - 1).getSonID(); sonID.add(authorities.get(i).getId()); list.get(j - 1).setSonID(sonID); List 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 relationshipAuthority3( List list){ List authorities=list; //英文下的claim 1,claim2 的正则表达式 String str1="(前記第)(^\\d*$+)"; Pattern p = Pattern.compile(str1); for(int i=0;i sonID = list.get(j - 1).getSonID(); sonID.add(authorities.get(i).getId()); list.get(j - 1).setSonID(sonID); List 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 relationshipAuthority2( List 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 sonID = list.get(l).getSonID(); sonID.add(list.get(i).getId()); list.get(l).setSonID(sonID); List 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 sonID = list.get(j).getSonID(); sonID.add(list.get(i).getId()); list.get(j).setSonID(sonID); List fatherID = list.get(i).getFatherID(); fatherID.add(list.get(j).getId()); list.get(i).setFatherID(fatherID); List sonID1 = list.get(k).getSonID(); sonID1.add(list.get(i).getId()); list.get(k).setSonID(sonID1); List 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 sonID = list.get(j).getSonID(); sonID.add(list.get(i).getId()); list.get(j).setSonID(sonID); List 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 relationshipAuthority4(List list){ //韩文情况下的正则表达式 String str1="항(^\\d*$+)(\\s)에있어서"; Pattern p = Pattern.compile(str1); for(int i=0;i sonID = list.get(j - 1).getSonID(); sonID.add(list.get(i).getId()); list.get(j - 1).setSonID(sonID); List 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 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); } this.saveOrUpdateBatch(patentRightList); } } }