EventServiceTests.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.dto.*;
  3. import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
  4. import cn.cslg.pas.common.dto.business.ReportTempleDTO;
  5. import cn.cslg.pas.common.dto.business.SelectClaimDTO;
  6. import cn.cslg.pas.common.dto.es.EsCustomFieldDTO;
  7. import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
  8. import cn.cslg.pas.common.model.cronModel.Records;
  9. import cn.cslg.pas.common.model.request.*;
  10. import cn.cslg.pas.common.utils.Response;
  11. import cn.cslg.pas.common.vo.business.EsCountVO;
  12. import cn.cslg.pas.common.vo.business.PatentKinVO;
  13. import cn.cslg.pas.common.vo.business.PatentNoVO;
  14. import cn.cslg.pas.common.vo.business.TempleByReportTypeVO;
  15. import cn.cslg.pas.controller.EventController;
  16. import cn.cslg.pas.controller.PatentController;
  17. import cn.cslg.pas.domain.es.FamilyPatent;
  18. import cn.cslg.pas.domain.es.Patent;
  19. import cn.cslg.pas.domain.es.PatentFamilyMessage;
  20. import cn.cslg.pas.service.business.MergePersonService;
  21. import cn.cslg.pas.service.business.ProductMarketDataService;
  22. import cn.cslg.pas.service.business.ReportTempleService;
  23. import cn.cslg.pas.service.business.es.EsCountService;
  24. import cn.cslg.pas.service.business.es.EsCustomFieldService;
  25. import cn.cslg.pas.service.business.es.EsService;
  26. import cn.cslg.pas.service.business.es.EsPatentService;
  27. import com.alibaba.fastjson.JSONObject;
  28. import org.apache.http.entity.ContentType;
  29. import org.junit.jupiter.api.Test;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.boot.test.context.SpringBootTest;
  32. import org.springframework.mock.web.MockMultipartFile;
  33. import org.springframework.transaction.annotation.Propagation;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import org.springframework.web.multipart.MultipartFile;
  36. import java.io.File;
  37. import java.io.FileInputStream;
  38. import java.io.IOException;
  39. import java.util.*;
  40. import java.util.stream.Collectors;
  41. /**
  42. * @author chenyu
  43. * @date 2023/9/6
  44. */
  45. @SpringBootTest
  46. public class EventServiceTests {
  47. @Autowired
  48. private EventController eventController;
  49. @Autowired
  50. PatentController patentController;
  51. @Autowired
  52. private EsService esService;
  53. @Autowired
  54. private EsCountService esCountService;
  55. @Autowired
  56. private ReportTempleService templeService;
  57. @Autowired
  58. private EsPatentService patentService;
  59. @Autowired
  60. private EsCustomFieldService esCustomFieldService;
  61. @Autowired
  62. private MergePersonService mergePersonService;
  63. @Autowired
  64. private ProductMarketDataService productMarketDataService;
  65. @Test
  66. void test() throws Exception {
  67. StringRequest queryRequest = new StringRequest();
  68. queryRequest.setSearchQuery("id=52");
  69. List<OrderDTO> dtos = new ArrayList<>();
  70. OrderDTO orderDTO1 = new OrderDTO();
  71. orderDTO1.setOrderBy("name");
  72. orderDTO1.setOrderType(0);
  73. OrderDTO orderDTO2 = new OrderDTO();
  74. orderDTO2.setOrderBy("createName");
  75. orderDTO2.setOrderType(1);
  76. dtos.add(orderDTO1);
  77. dtos.add(orderDTO2);
  78. queryRequest.setOrderDTOList(dtos);
  79. queryRequest.setCurrent(Long.parseLong("1"));
  80. queryRequest.setSize(Long.parseLong("10"));
  81. Response response = eventController.queryEvent(queryRequest);
  82. System.out.println(response);
  83. }
  84. @Test
  85. void add() throws Exception {
  86. JSONObject jsonObj = new JSONObject();
  87. jsonObj.put("name", "事件4");
  88. jsonObj.put("description", "描述1");
  89. jsonObj.put("clientId", 1);
  90. jsonObj.put("scenarioId", 2);
  91. jsonObj.put("eventDate", "");
  92. String json_to_string = JSONObject.toJSONString(jsonObj);
  93. List<MultipartFile> list = new ArrayList<>();
  94. File file = new File("C:\\Users\\admin\\Desktop\\test.txt");
  95. MultipartFile mulFile = new MockMultipartFile(
  96. "th.jpg", //文件名
  97. "th.jpg", //originalName 相当于上传文件在客户机上的文件名
  98. ContentType.APPLICATION_OCTET_STREAM.toString(), //文件类型
  99. new FileInputStream(file) //文件流
  100. );
  101. list.add(mulFile);
  102. eventController.addEvent(json_to_string, list);
  103. }
  104. @Test
  105. void groupEvent() throws Exception {
  106. StringGroupRequest queryRequest = new StringGroupRequest();
  107. queryRequest.setSearchQuery("name~事件 and createName=朱");
  108. List<OrderDTO> dtos = new ArrayList<>();
  109. OrderDTO orderDTO1 = new OrderDTO();
  110. orderDTO1.setOrderBy("name");
  111. orderDTO1.setOrderType(0);
  112. OrderDTO orderDTO2 = new OrderDTO();
  113. orderDTO2.setOrderBy("createName");
  114. orderDTO2.setOrderType(1);
  115. dtos.add(orderDTO1);
  116. dtos.add(orderDTO2);
  117. queryRequest.setOrderDTOList(dtos);
  118. queryRequest.setCurrent(Long.parseLong("1"));
  119. queryRequest.setSize(Long.parseLong("10"));
  120. queryRequest.setGroupBy("name");
  121. eventController.groupEvent(queryRequest);
  122. }
  123. @Test
  124. void test1() throws Exception {
  125. StringGroupRequest groupRequest = new StringGroupRequest();
  126. groupRequest.setGroupBy("groupMonthTime");
  127. Records records = (Records) productMarketDataService.getGroup(groupRequest, "productMarketData");
  128. System.out.println(records);
  129. }
  130. @Test
  131. void test11() throws Exception {
  132. // List<Patent> list = esService.Search("publicDate=2009-03", 0, 50,null);
  133. // MapRequest mapRequest = new MapRequest();
  134. // Map<String, Object> map = new HashMap<>();
  135. // map.put("titleTextContent", "电子");
  136. // map.put("patentNo", "CN201199922Y");
  137. // mapRequest.setSearchQuery(map);
  138. // mapRequest.setCurrent(0L);
  139. // mapRequest.setSize(50L);
  140. // mapRequest.setProjectId(1);
  141. StringRequest stringRequest = new StringRequest();
  142. // stringRequest.setSearchQuery("appCity=济南");
  143. // stringRequest.setSearchQuery("mipcLevel1=H");
  144. // stringRequest.setSearchQuery("agent=李桂存");
  145. // stringRequest.setSearchQuery("IN=郝旭东");
  146. // stringRequest.setSearchQuery("simpleStatus=3");
  147. // stringRequest.setSearchQuery("publicFullText=本申请涉及直流输电技术领域");
  148. // stringRequest.setSearchQuery("AB=本申请提供一种储能系统机电暂态建模方法、装置、设备及可读存储介质");
  149. // stringRequest.setSearchQuery("TI=储能系统机电暂态建模方法、装置、设备及可读存储介质");
  150. // stringRequest.setSearchQuery("PN=CN114513005B");
  151. // stringRequest.setSearchQuery("AN=CN201810025278.2");
  152. // stringRequest.setSearchQuery("patentNo=CN");
  153. stringRequest.setSearchQuery("PD<=200903");
  154. // stringRequest.setSearchQuery("patentNo=CN201199922Y and (simpleFamilyNum>1 or simpleFamilyNum=0)");
  155. stringRequest.setCurrent(1L);
  156. stringRequest.setSize(5L);
  157. // stringRequest.setProjectId(1);
  158. //
  159. PatentDTO patentDTO = esService.esSearch(stringRequest);
  160. System.out.println(patentDTO);
  161. }
  162. @Test
  163. void test12() throws IOException {
  164. Boolean bool = esService.searchPatent("YiQCGowBmB3pRkTj4NNG", 5);
  165. System.out.println(bool);
  166. }
  167. @Test
  168. void getpagetexst() throws IOException {
  169. //1.添加一批数据(10)
  170. //2.调用查询取第一页(5笔一页)
  171. //3.判断5笔数据是正确的;
  172. //4.删除测试数据
  173. List<Integer> list = Arrays.asList(1, 2, 3, 4);
  174. List<Integer> list1 = Arrays.asList(4, 5);
  175. // list1.removeAll(list);
  176. System.out.println(list1);
  177. }
  178. @Test
  179. void add1() throws Exception {
  180. List<FamilyPatent> list = new ArrayList<>();
  181. FamilyPatent patent = new FamilyPatent();
  182. patent.setAppNo("CN147258369");
  183. patent.setGrantNo("CN258369147");
  184. patent.setPublicNo("CN369258147");
  185. FamilyPatent patent1 = new FamilyPatent();
  186. patent1.setAppNo("US147258369");
  187. patent1.setGrantNo("US258369147");
  188. patent1.setPublicNo("US369258147");
  189. list.add(patent);
  190. list.add(patent1);
  191. PatentFamilyMessage patentFamilyMessage = new PatentFamilyMessage();
  192. patentFamilyMessage.setPatent(list);
  193. patentFamilyMessage.setFamilyType("test");
  194. String id = esService.addPatentFamily(patentFamilyMessage);
  195. System.out.println(id);
  196. }
  197. @Test
  198. void test3() throws IOException {
  199. List<String> stringList = Arrays.asList("US369258147", "US258369147", "14528");
  200. EsPatentFamilyDTO test = esService.addEsPatentFamily(stringList, "test");
  201. System.out.println(test);
  202. }
  203. @Test
  204. void test4() throws IOException {
  205. List<String> stringList = Arrays.asList("US369258147", "US258369147", "14528");
  206. EsPatentFamilyDTO test = esService.addEsPatentFamily(stringList, "test");
  207. System.out.println(test);
  208. }
  209. @Test
  210. void test5() throws IOException {
  211. SelectClaimDTO dto = esService.selectClaim("CN102324864A");
  212. System.out.println(dto);
  213. }
  214. @Test
  215. void test8() throws Exception {
  216. List<EsCountVO> countVOS = new ArrayList<>();
  217. EsCountVO vo1 = new EsCountVO();
  218. vo1.setField("childRaw");
  219. // vo.setField("CO");
  220. // vo.setField("PT");
  221. // vo1.setValueOne("国家电网公司");
  222. // vo.setValueOne("2022");
  223. // vo.setValueTwo("2024");
  224. // vo.setField("AD");
  225. EsCountVO vo2 = new EsCountVO();
  226. vo2.setField("AD");
  227. vo2.setValueOne("2022");
  228. vo2.setValueTwo("2023");
  229. countVOS.add(vo1);
  230. // countVOS.add(vo2);
  231. // EsCountDTO esCountDTO = esCountService.esCountSearch(countVOS);
  232. // System.out.println(esCountDTO);
  233. }
  234. @Test
  235. void test9() throws IOException {
  236. PatentNoVO vo = new PatentNoVO();
  237. vo.setPatentNo("CN201910069334.7");
  238. PatentColumnDTO columnDTO = patentService.selectPatentDetail(vo);
  239. System.out.println(columnDTO);
  240. // String s = "asfassafsafe";
  241. // Map<Character, Long> map = s.chars().mapToObj(c->(char)c).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  242. // System.out.println(map);
  243. //
  244. // List<String> stringList = Arrays.asList("apple", "apple", "balana", "origin", "apple", "balana");
  245. // Map<String, Long> collect = stringList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  246. // System.out.println("----" + collect);
  247. }
  248. @Test
  249. void test10() throws IOException {
  250. PatentKinVO vo = new PatentKinVO();
  251. vo.setPatentNo("CN201910069334.7");
  252. vo.setPageNum(1);
  253. vo.setPageSize(10);
  254. vo.setType("inpadoc");
  255. List<PatentKinDTO> kinDTOS = patentService.selectKinByPatentNo(vo);
  256. System.out.println(kinDTOS);
  257. }
  258. @Test
  259. void test14() {
  260. TempleByReportTypeVO vo = new TempleByReportTypeVO();
  261. vo.setReportType(1);
  262. List<ReportTempleDTO> reportTempleDTOS = templeService.queryTempleByType(vo);
  263. System.out.println(reportTempleDTOS);
  264. }
  265. @Test
  266. void test15() throws Exception {
  267. EsCustomFieldDTO dto = new EsCustomFieldDTO();
  268. dto.setProjectId(83);
  269. dto.setFieldType(5);
  270. dto.setFieldId("303");
  271. dto.setFieldValue(Arrays.asList("多选1", "多选2"));
  272. dto.setOptionType(1);
  273. dto.setPatentNo("CN201910069334.7");
  274. esCustomFieldService.addCustomField(dto);
  275. }
  276. @Test
  277. void test16() {
  278. List<EsCustomFieldValueDTO> customFields = new ArrayList<>();
  279. EsCustomFieldValueDTO dto1 = new EsCustomFieldValueDTO();
  280. dto1.setFieldId("1");
  281. dto1.setFieldValue(Arrays.asList("a"));
  282. EsCustomFieldValueDTO dto2 = new EsCustomFieldValueDTO();
  283. dto2.setFieldId("2");
  284. dto2.setFieldValue(Arrays.asList("a"));
  285. customFields.add(dto1);
  286. customFields.add(dto2);
  287. String s = esService.parseCustomField(customFields);
  288. System.out.println("结果为:" + s);
  289. System.out.println("-----------------------------");
  290. List<EsCustomFieldValueDTO> fields = new ArrayList<>();
  291. }
  292. @Test
  293. void test17() throws IOException {
  294. List<String> list = new ArrayList<>();
  295. list.add("CN201910069334.7");
  296. list.add("CN201110286649.0");
  297. list.add("CN200820185104.4");
  298. SelectClaimDTO dto = esService.selectPatentNo(list);
  299. System.out.println(dto);
  300. }
  301. @Test
  302. void test18() {
  303. List<String> list = Arrays.asList("AD");
  304. if (list.contains("AD")) {
  305. String str = "AD=2008~201009";
  306. String s = this.get(str);
  307. if (s.contains("~")) {
  308. int i = s.indexOf("~");
  309. // s.substring()
  310. String s1 = this.get(s);
  311. System.out.println("-------------");
  312. System.out.println("s1是:" + s1);
  313. }
  314. } else {
  315. System.out.println("DDDDDDDDDDDDDDDDDD");
  316. }
  317. }
  318. public String get(String str) {
  319. int i = str.indexOf("AD");
  320. String s = str.substring(str.indexOf("AD")).toUpperCase(Locale.ROOT);
  321. int length = s.length();//------
  322. String key = s.substring(0, s.indexOf("="));
  323. int i2 = s.indexOf("=");
  324. String s1 = s.substring(s.indexOf("=") + 1, s.indexOf("~"));
  325. String s2 = "";
  326. if (s.contains("AND")) {
  327. s2 = s.substring(s.indexOf("~") + 1, s.indexOf("AND"));
  328. } else {
  329. s2 = s.substring(s.indexOf("~") + 1).trim();
  330. }
  331. int index = str.indexOf(key);
  332. int index1 = str.indexOf(s2) + s2.length();
  333. int i1 = index + key.length() + 1 + s1.length() + 1 + s2.length();
  334. String substring = str.substring(index, i1);
  335. String concat = key.concat(">=").concat(s1).concat(" and ").concat(key).concat("<=").concat(s2);
  336. System.out.println(concat);
  337. String replace = str.replace(substring, concat);
  338. System.out.println(replace);
  339. return replace;
  340. }
  341. @Test
  342. public void aaaaa() throws Exception {
  343. List<String> list = Arrays.asList("gh,ji");
  344. String str = "[";
  345. if (list.size() >= 1) {
  346. for (int i = 0; i < list.size(); i++) {
  347. String s = list.get(i);
  348. if (i == list.size() - 1) {
  349. str = str + "\"" +s + "\"" ;
  350. } else {
  351. str = str + "\"" +s + "\"" + "," ;
  352. }
  353. }
  354. } else {
  355. }
  356. str = str + "]";
  357. System.out.println(str + "------------");
  358. String projectId = "ctx._source.custom_field.project_id = " + 1 + ";" + "\n";
  359. String field = "ctx._source.custom_field.field=" + 1 + ";" + "\n";
  360. String fieldType = "ctx._source.custom_field.field_type = " + 1 + ";" + "\n";
  361. String personId = "ctx._source.custom_field.person_id = " + 1 + ";" + "\n";
  362. String createTime = "ctx._source.custom_field.create_time = " + new Date().getTime() + ";" + "\n";
  363. String fieldValue = "ctx._source.custom_field.field_value = " + str + ";" + "\n";
  364. String statsValue = "ctx._source.custom_field.stats_value = " + list;
  365. String source = "\"" + projectId + field + fieldType + personId + createTime + fieldValue + statsValue + "\"";
  366. // String source = "\"\"ctx._source.custom_field.project_id = " + 1 + ";" + "\n" +
  367. // "ctx._source.custom_field.field=" + 2 + ";" + "\n" + "\"\"";
  368. System.out.println(source);
  369. Patent patent = new Patent();
  370. String id = "hy7ayIwB68vilgBjUWBz";
  371. String name = "士大夫";
  372. Integer type = 0;
  373. esService.delMergePerson(patent, id, type, name);
  374. }
  375. @Test
  376. public void test100() {
  377. List<GetAllPersonDTO> DTOS = new ArrayList<>();
  378. List<GetAllPersonDTO> applicantDTOS = new ArrayList<>();
  379. GetAllPersonDTO dto = new GetAllPersonDTO();
  380. dto.setName("A");
  381. dto.setType(0);
  382. dto.setCountry("CN");
  383. dto.setAddress("efe");
  384. applicantDTOS.add(dto);
  385. GetAllPersonDTO dto1 = new GetAllPersonDTO();
  386. dto1.setName("B");
  387. dto1.setType(0);
  388. dto1.setCountry("CN");
  389. dto1.setAddress("weew");
  390. applicantDTOS.add(dto1);
  391. GetAllPersonDTO dto2 = new GetAllPersonDTO();
  392. dto2.setName("C");
  393. dto2.setType(0);
  394. dto2.setCountry("CN");
  395. dto2.setAddress("fdsyt");
  396. applicantDTOS.add(dto2);
  397. List<GetAllPersonDTO> rightDTOS = new ArrayList<>();
  398. GetAllPersonDTO dto4 = new GetAllPersonDTO();
  399. dto4.setName("A");
  400. dto4.setType(0);
  401. dto4.setCountry("CN");
  402. dto4.setAddress("efed");
  403. rightDTOS.add(dto4);
  404. GetAllPersonDTO dto5 = new GetAllPersonDTO();
  405. dto5.setName("D");
  406. dto5.setType(0);
  407. dto5.setCountry("CN");
  408. dto5.setAddress("ete");
  409. rightDTOS.add(dto5);
  410. GetAllPersonDTO dto6 = new GetAllPersonDTO();
  411. dto6.setName("E");
  412. dto6.setType(0);
  413. rightDTOS.add(dto6);
  414. applicantDTOS.removeAll(rightDTOS);
  415. System.out.println(applicantDTOS + "-----------------");
  416. for (GetAllPersonDTO applicantDTO : applicantDTOS) {
  417. rightDTOS.removeIf(rightDTO -> applicantDTO.getName().equals(rightDTO.getName()));
  418. }
  419. System.out.println(applicantDTOS);
  420. System.out.println(rightDTOS);
  421. DTOS.addAll(applicantDTOS);
  422. DTOS.addAll(rightDTOS);
  423. System.out.println("DTOS:" + DTOS);
  424. }
  425. @Test
  426. public void test101() {
  427. // Date date = new Date();
  428. // Calendar calendar = Calendar.getInstance();
  429. // calendar.setTime(date);
  430. // calendar.add(Calendar.DAY_OF_MONTH, 1);
  431. // Date date1 = calendar.getTime();
  432. // System.out.println(date1);
  433. //
  434. // List<Integer> list = Arrays.asList(1, 2, 3);
  435. // String result = String.join(",", String.join(",", list.stream().map(Object::toString).collect(Collectors.toList())));
  436. // System.out.println(result); // 输出: 1,2,3
  437. String s = "((type='1') AND (type_id='7') ) AND (parent_id='0') ";
  438. if (s.contains("type='1") || s.contains("type='2'")) {
  439. System.out.println("Sdggdsgred");
  440. } else {
  441. System.out.println("end");
  442. }
  443. }
  444. }