PatentRightService.java 21 KB

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