PatentRightService.java 19 KB

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