EventServiceTests.java 18 KB

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