PatentRightService.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.model.params.PatentRightParams;
  3. import cn.cslg.pas.common.utils.PatentUtils;
  4. import cn.cslg.pas.common.utils.Response;
  5. import cn.cslg.pas.common.utils.StringUtils;
  6. import cn.cslg.pas.domain.Authority;
  7. import cn.cslg.pas.domain.Patent;
  8. import cn.cslg.pas.domain.PatentRight;
  9. import cn.cslg.pas.mapper.PatentRightMapper;
  10. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import lombok.RequiredArgsConstructor;
  14. import org.springframework.context.annotation.Lazy;
  15. import org.springframework.stereotype.Service;
  16. import java.util.ArrayList;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. import java.util.regex.Matcher;
  20. import java.util.regex.Pattern;
  21. import java.util.stream.Collectors;
  22. /**
  23. * @author Administrator
  24. * @description 针对表【os_patent_right(专利权利要求)】的数据库操作Service
  25. * @createDate 2022-04-16 10:09:24
  26. */
  27. @Service
  28. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  29. public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRight> {
  30. private final PatentService patentService;
  31. public List<PatentRight> getPatentRightByPatentNo(String patentNo)
  32. {
  33. Patent patent = patentService.getByPatentNo(patentNo);
  34. LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
  35. queryWrapper.eq(PatentRight::getPatentId, patent.getId());
  36. queryWrapper.orderByAsc(PatentRight::getSort);
  37. return this.list(queryWrapper);
  38. }
  39. public List<PatentRight> getPatentRightByPatentId(Integer patentId) {
  40. LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
  41. queryWrapper.eq(PatentRight::getPatentId, patentId);
  42. queryWrapper.orderByAsc(PatentRight::getSort);
  43. return this.list(queryWrapper);
  44. }
  45. public List<PatentRight> getPatentRightByPatentIds(List<Integer> patentIds) {
  46. if (patentIds == null || patentIds.size() == 0) {
  47. return new ArrayList<>();
  48. }
  49. LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
  50. queryWrapper.in(PatentRight::getPatentId, patentIds);
  51. queryWrapper.orderByAsc(PatentRight::getSort);
  52. return this.list(queryWrapper);
  53. }
  54. public void deleteByPatentId(Integer patentId) {
  55. this.remove(Wrappers.<PatentRight>lambdaQuery().eq(PatentRight::getPatentId, patentId));
  56. }
  57. public void importPatentRight(Integer localPatentId, Integer importPatentId, List<PatentRight> importPatentRightList) {
  58. this.deleteByPatentId(localPatentId);
  59. List<PatentRight> patentRightList = importPatentRightList.stream().filter(item -> item.getPatentId().equals(importPatentId)).collect(Collectors.toList());
  60. for (PatentRight patentRight : patentRightList) {
  61. patentRight.setId(null);
  62. patentRight.setPatentId(localPatentId);
  63. }
  64. this.saveOrUpdateBatch(patentRightList);
  65. }
  66. public void importAuthority(PatentRightParams params){
  67. List<Authority> splits = splits(params);
  68. List<Authority> authorities = relationshipAuthority(splits);
  69. List<Authority> authorities1 = relationshipAuthority3(authorities);
  70. List<Authority> authorities2 = relationshipAuthority2(authorities1);
  71. List<Authority> authorities3 = relationshipAuthority4(authorities2);
  72. for(Authority a:authorities3){
  73. Authority authority = new Authority();
  74. authority.setContent(a.getContent());
  75. String join = StringUtils.join(a.getFatherID(), ",");
  76. authority.setFID(join);
  77. String join1 = StringUtils.join(a.getSonID(), ",");
  78. authority.setSID(join1);
  79. authority.setPatentID(params.getPatentId());
  80. authority.setType(a.getType());
  81. authority.insert();
  82. }
  83. }
  84. public List<Authority> splits(PatentRightParams params){
  85. //去掉全要开头的""
  86. String selfContent= params.getContent();
  87. selfContent.replaceAll("''","");
  88. selfContent.replaceAll("\n"," ");
  89. // selfContent.replaceAll(" ","");
  90. List<Authority> list = new ArrayList<>();
  91. //找到1. 2. ...这种格式的正则表达式
  92. String str1="(^\\d*$+)(\\.)";
  93. //找到[001]或者[002]这种格式的
  94. String str2="(\\[)(^[1-9]/d*$+)(\\])";
  95. //【請求項 1】
  96. String str3="(\\【請求項)(^[1-9]/d*$+)(\\】)";
  97. //청구항 1()
  98. String str4="청구항(^[1-9]/d*$+)";
  99. Pattern p4 = Pattern.compile(str4);
  100. Matcher m4 = p4.matcher(selfContent);
  101. if(m4.find()) {
  102. String str5=".";
  103. Pattern p5 = Pattern.compile(str4);
  104. Matcher m5 = p5.matcher(selfContent);
  105. List<Integer> integers1=new ArrayList<>();
  106. while (m5.find()){
  107. integers1.add(m5.start());
  108. }
  109. for(int i=integers1.size()-1;i>=0;i--){
  110. String str=selfContent.substring(integers1.get(i));
  111. Authority authority=new Authority();
  112. authority.setContent(str);
  113. list.add(authority);
  114. }
  115. Authority authority=new Authority();
  116. authority.setContent(selfContent);
  117. list.add(authority);
  118. return list;
  119. }
  120. Pattern p = Pattern.compile(str1);
  121. Matcher m = p.matcher(selfContent);
  122. //判断找到的数量
  123. List<Integer> integers=new ArrayList<>();
  124. while (m.find()){
  125. integers.add(m.start());
  126. }
  127. if(integers.size()!=0){
  128. for(int i=integers.size()-1;i>=0;i--){
  129. String str=selfContent.substring(integers.get(i));
  130. Authority authority=new Authority();
  131. authority.setContent(str);
  132. list.add(authority);
  133. }
  134. return list;
  135. }
  136. Pattern compile = Pattern.compile(str2);
  137. Matcher matcher = compile.matcher(selfContent);
  138. List<Integer> start=new ArrayList<>();
  139. List<Integer> end=new ArrayList<>();
  140. while (matcher.find()){
  141. start.add( matcher.start());
  142. end.add(matcher.end());
  143. }
  144. if(start.size()!=0){
  145. for(int i=start.size()-1;i>=0;i--) {
  146. if(i==start.size()-1){
  147. String substring = selfContent.substring(end.get(i));
  148. String string=new String(String.valueOf(i));
  149. string=string+"."+substring;
  150. Authority authority=new Authority();
  151. list.add(authority);
  152. }
  153. String substring = selfContent.substring(end.get(i),start.get(i+1));
  154. String string=new String(String.valueOf(i));
  155. string=string+"."+substring;
  156. Authority authority=new Authority();
  157. list.add(authority);
  158. }
  159. return list;
  160. }
  161. Pattern compile1 = Pattern.compile(str3);
  162. Matcher matcher1 = compile1.matcher(selfContent);
  163. List<Integer> start1=new ArrayList<>();
  164. List<Integer> end1=new ArrayList<>();
  165. while (matcher1.find()){
  166. start1.add( matcher1.start());
  167. end1.add(matcher1.end());
  168. }
  169. if(start1.size()!=0){
  170. for(int i=start1.size()-1;i>=0;i--) {
  171. if(i==start1.size()-1){
  172. String substring = selfContent.substring(end.get(i));
  173. String string=new String(String.valueOf(i));
  174. string=string+"."+substring;
  175. Authority authority=new Authority();
  176. list.add(authority);
  177. }
  178. String substring = selfContent.substring(end.get(i),start.get(i+1));
  179. String string=new String(String.valueOf(i));
  180. string=string+"."+substring;
  181. Authority authority=new Authority();
  182. list.add(authority);
  183. }
  184. return list;
  185. }
  186. return list;
  187. }
  188. /**
  189. * 英文下的处理方式(草稿)
  190. */
  191. private List<Authority> relationshipAuthority(List<Authority> list){
  192. List<Authority> authorities=list;
  193. //英文下的claim 1,claim2 的正则表达式
  194. String str1="(claim)(\\s)(^\\d*$+)";
  195. Pattern p = Pattern.compile(str1);
  196. for(int i=0;i<list.size();i++){
  197. //去掉空格
  198. authorities.get(i).getContent().replaceAll(" ","");
  199. Matcher m = p.matcher(authorities.get(i).getContent());
  200. if(!m.find()){
  201. list.get(i).setFID(null);
  202. list.get(i).setType(0);
  203. return list;
  204. }
  205. else {
  206. //找到了
  207. String group = m.group(0);
  208. //把claim去掉只剩下面的数字
  209. String substring = group.substring(5);
  210. int j = Integer.parseInt(substring);
  211. List<Integer> sonID = list.get(j - 1).getSonID();
  212. sonID.add(authorities.get(i).getId());
  213. list.get(j - 1).setSonID(sonID);
  214. List<Integer> fatherID = list.get(i).getFatherID();
  215. fatherID.add( list.get(j - 1).getId());
  216. list.get(i).setFatherID(fatherID);
  217. //设置为
  218. list.get(i).setType(1);
  219. }
  220. }
  221. return list;
  222. }
  223. /**
  224. * 小日子的语言下的处理模式
  225. */
  226. private List<Authority> relationshipAuthority3( List<Authority> list){
  227. List<Authority> authorities=list;
  228. //英文下的claim 1,claim2 的正则表达式
  229. String str1="(前記第)(^\\d*$+)";
  230. Pattern p = Pattern.compile(str1);
  231. for(int i=0;i<list.size();i++){
  232. Matcher m = p.matcher(authorities.get(i).getContent());
  233. if(!m.find()){
  234. list.get(i).setFID(null);
  235. list.get(i).setType(0);
  236. return list;
  237. }
  238. else {
  239. //找到了
  240. String group = m.group(0);
  241. //把claim去掉只剩下面的数字
  242. String substring = group.substring(3);
  243. int j = Integer.parseInt(substring);
  244. List<Integer> sonID = list.get(j - 1).getSonID();
  245. sonID.add(authorities.get(i).getId());
  246. list.get(j - 1).setSonID(sonID);
  247. List<Integer> fatherID = list.get(i).getFatherID();
  248. fatherID.add( list.get(j - 1).getId());
  249. list.get(i).setFatherID(fatherID);
  250. //设置为
  251. list.get(i).setType(1);
  252. }
  253. }
  254. return list;
  255. }
  256. /**
  257. * 中文下的处理方式
  258. */
  259. public List<Authority> relationshipAuthority2( List<Authority> list){
  260. //中文下权利要求1,权利要求2,权利要求3
  261. String str1="(权利要求)(^\\d*$+)";
  262. //中文下权利要求1至
  263. String str2="(权利要求)(^\\d*$+)(至)(^\\d*$+)";
  264. //中文下权利要求 或
  265. String str3="(权利要求)(^\\d*$+)(或)(^\\d*$+)";
  266. Pattern p = Pattern.compile(str1);
  267. Pattern p1 = Pattern.compile(str2);
  268. Pattern p2 = Pattern.compile(str3);
  269. for(int i=0;i<list.size();i++){
  270. Matcher matcher = p.matcher(list.get(i).getContent());
  271. if(matcher.find()){
  272. list.get(i).setType(1);
  273. //找到满足第一情况
  274. Matcher matcher1 = p1.matcher(list.get(i).getContent());
  275. if(matcher1.find()){
  276. //找到满足第一和第二种情况按第二种情况处理
  277. String group = matcher1.group(0);
  278. String str5="^\\d*$+";
  279. Pattern p3 = Pattern.compile(str5);
  280. Matcher matcher2 = p3.matcher(group);
  281. if(matcher2.find()){
  282. String group1 = matcher2.group(0);
  283. String group2 = matcher2.group(1);
  284. Integer j=Integer.parseInt(group1);
  285. Integer k=Integer.parseInt(group2);
  286. for(int l=j-1;l<k;l++){
  287. List<Integer> sonID = list.get(l).getSonID();
  288. sonID.add(list.get(i).getId());
  289. list.get(l).setSonID(sonID);
  290. List<Integer> fatherID = list.get(i).getFatherID();
  291. fatherID.add(list.get(l).getId());
  292. list.get(i).setFatherID(fatherID);
  293. }
  294. }
  295. }else {
  296. Matcher matcher2 = p2.matcher(list.get(i).getContent());
  297. if(matcher2.find()){
  298. //找到满足第三和第一情况按第三中情况处理
  299. String group = matcher1.group(0);
  300. String str6="^\\d*$+";
  301. Pattern p3 = Pattern.compile(str6);
  302. Matcher matcher3 = p3.matcher(group);
  303. if(matcher3.find()) {
  304. String group1 = matcher2.group(0);
  305. String group2 = matcher2.group(1);
  306. Integer j = Integer.parseInt(group1);
  307. Integer k = Integer.parseInt(group2);
  308. List<Integer> sonID = list.get(j).getSonID();
  309. sonID.add(list.get(i).getId());
  310. list.get(j).setSonID(sonID);
  311. List<Integer> fatherID = list.get(i).getFatherID();
  312. fatherID.add(list.get(j).getId());
  313. list.get(i).setFatherID(fatherID);
  314. List<Integer> sonID1 = list.get(k).getSonID();
  315. sonID1.add(list.get(i).getId());
  316. list.get(k).setSonID(sonID1);
  317. List<Integer> fatherID1 = list.get(i).getFatherID();
  318. fatherID1.add(list.get(k).getId());
  319. list.get(i).setFatherID(fatherID1);
  320. }
  321. }else {
  322. //只满足第一中情况
  323. String group = matcher.group(0);
  324. String str7="^\\d*$+";
  325. Pattern p3 = Pattern.compile(str7);
  326. Matcher matcher3 = p3.matcher(group);
  327. if(matcher3.find()){
  328. String group1 = matcher2.group(0);
  329. Integer j = Integer.parseInt(group1);
  330. List<Integer> sonID = list.get(j).getSonID();
  331. sonID.add(list.get(i).getId());
  332. list.get(j).setSonID(sonID);
  333. List<Integer> fatherID = list.get(i).getFatherID();
  334. fatherID.add(list.get(j).getId());
  335. list.get(i).setFatherID(fatherID);
  336. }
  337. }
  338. }
  339. }else {
  340. list.get(i).setType(0);
  341. list.get(i).setFID(null);
  342. }
  343. }
  344. return list;
  345. }
  346. /**
  347. *
  348. * 韩文下的处理
  349. */
  350. public List<Authority> relationshipAuthority4(List<Authority> list){
  351. //韩文情况下的正则表达式
  352. String str1="항(^\\d*$+)(\\s)에있어서";
  353. Pattern p = Pattern.compile(str1);
  354. for(int i=0;i<list.size();i++){
  355. //去掉空格
  356. list.get(i).getContent().replaceAll(" ","");
  357. Matcher m = p.matcher(list.get(i).getContent());
  358. if(!m.find()){
  359. list.get(i).setFID(null);
  360. list.get(i).setType(0);
  361. return list;
  362. }
  363. else {
  364. //找到了
  365. String group = m.group(0);
  366. String str2="(^\\d*$+)";
  367. Pattern p1 = Pattern.compile(str1);
  368. Matcher matcher = p1.matcher(group);
  369. String substring= matcher.group(0);
  370. int j = Integer.parseInt(substring);
  371. List<Integer> sonID = list.get(j - 1).getSonID();
  372. sonID.add(list.get(i).getId());
  373. list.get(j - 1).setSonID(sonID);
  374. List<Integer> fatherID = list.get(i).getFatherID();
  375. fatherID.add( list.get(j - 1).getId());
  376. list.get(i).setFatherID(fatherID);
  377. //设置为
  378. list.get(i).setType(1);
  379. }
  380. }
  381. return list;
  382. }
  383. public void updatePatentRight(PatentRightParams params) {
  384. List<PatentRight> patentRightList = new ArrayList<>();
  385. //获取国家 公开号前两位
  386. String country = PatentUtils.getPatentCountry(params.getPatentNo());
  387. String code;
  388. //权利要求
  389. String content = params.getContent();
  390. //权利要求(译)
  391. String contentOut = params.getContentOut();
  392. //独立权利要求
  393. String selfContent = params.getSelfContent();
  394. if (StringUtils.isNotEmpty(content)) {
  395. this.deleteByPatentId(params.getPatentId());
  396. String[] contentArray = null;
  397. String[] contentOutArray = null;
  398. String[] selfContentArray = null;
  399. switch (country) {
  400. case "JP":
  401. case "CN":
  402. code = "。";
  403. if (StringUtils.isNotEmpty(contentOut)) {
  404. contentOut = contentOut.replaceAll("\n", "");
  405. contentOutArray = StringUtils.split(contentOut, code);
  406. }
  407. if (StringUtils.isNotEmpty(selfContent)) {
  408. selfContent = selfContent.replaceAll("\n", "");
  409. selfContentArray = StringUtils.split(selfContent, code);
  410. }
  411. content = content.replaceAll("\n", "");
  412. contentArray = StringUtils.split(content, code);
  413. break;
  414. default:
  415. code = "\n";
  416. if (StringUtils.isNotEmpty(contentOut)) {
  417. contentOutArray = StringUtils.split(contentOut, code);
  418. }
  419. if (StringUtils.isNotEmpty(selfContent)) {
  420. selfContentArray = StringUtils.split(selfContent, code);
  421. }
  422. contentArray = StringUtils.split(content, code);
  423. }
  424. for (int i = 0; i < contentArray.length; i++) {
  425. if (StringUtils.isEmpty(contentArray[i])) {
  426. continue;
  427. }
  428. PatentRight patentRight = new PatentRight();
  429. patentRight.setPatentId(params.getPatentId());
  430. patentRight.setContent(contentArray[i]);
  431. patentRight.setType(0);
  432. patentRight.setSort(i);
  433. if (contentOutArray != null && i < contentOutArray.length) {
  434. patentRight.setContentOut(contentOutArray[i]);
  435. }
  436. if (selfContentArray != null) {
  437. String temp = Arrays.stream(selfContentArray).filter(item -> item.equals(patentRight.getContent())).findFirst().orElse(null);
  438. if (temp != null) {
  439. patentRight.setType(1);
  440. }
  441. }
  442. patentRightList.add(patentRight);
  443. }
  444. this.saveOrUpdateBatch(patentRightList);
  445. }
  446. }
  447. }