EventServiceTests.java 16 KB

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