XiaoshiWeixinbackApplicationTests.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package com.example.xiaoshiweixinback;
  2. import cn.hutool.core.util.IdUtil;
  3. import com.example.xiaoshiweixinback.business.common.base.SystemFile;
  4. import com.example.xiaoshiweixinback.business.utils.FileUtils;
  5. import com.example.xiaoshiweixinback.business.utils.RegexUtil;
  6. import com.example.xiaoshiweixinback.domain.Product;
  7. import com.example.xiaoshiweixinback.mapper.ProductMapper;
  8. import com.example.xiaoshiweixinback.service.ProductCategoryService;
  9. import com.example.xiaoshiweixinback.service.common.FileManagerService;
  10. import com.example.xiaoshiweixinback.service.common.GetVectorService;
  11. import com.example.xiaoshiweixinback.service.importPatent.EsDenseVectorService;
  12. import org.apache.commons.compress.utils.IOUtils;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.junit.jupiter.api.Test;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.boot.test.context.SpringBootTest;
  17. import org.springframework.context.annotation.Lazy;
  18. import org.springframework.util.CollectionUtils;
  19. import java.io.*;
  20. import java.text.SimpleDateFormat;
  21. import java.time.LocalDateTime;
  22. import java.time.ZoneId;
  23. import java.time.ZonedDateTime;
  24. import java.time.format.DateTimeFormatter;
  25. import java.time.temporal.ChronoUnit;
  26. import java.util.*;
  27. import java.util.concurrent.TimeUnit;
  28. import java.util.regex.Matcher;
  29. import java.util.regex.Pattern;
  30. @SpringBootTest
  31. class XiaoshiWeixinbackApplicationTests {
  32. @Autowired
  33. @Lazy
  34. private EsDenseVectorService denseVectorService;
  35. @Autowired
  36. private ProductCategoryService productCategoryService;
  37. @Autowired
  38. private FileManagerService fileManagerService;
  39. @Autowired
  40. private GetVectorService getVectorService;
  41. @Autowired
  42. private ProductMapper productMapper;
  43. @Test
  44. void contextLoads() {
  45. }
  46. @Test
  47. public void test() throws Exception {
  48. // List<EsPictureVectorVo> list = denseVectorService.getPatentVectorSort(null, "大大的原型");
  49. // EsPatentSearchDTO dto = new EsPatentSearchDTO();
  50. // dto.setKey("手机 OR 产品");
  51. // Records records = denseVectorService.getPatentList(dto);
  52. // List<EsPictureVectorVo> list = JSON.parseArray(records.getData().toString(), EsPictureVectorVo.class);
  53. // System.out.println(list);
  54. // String s = "a , b , c , d";
  55. // boolean regExpReplace = RegexUtil.isRegExpReplace(s);
  56. // System.out.println(regExpReplace);
  57. // String all = s.replaceAll("[,。、;,./;]", " OR ");
  58. // System.out.println(all);
  59. // String s = "a OR b OR c OR d";
  60. // boolean regExpReplace = RegexUtil.isRegExpReplace(s);
  61. // System.out.println(regExpReplace);
  62. // String sa = s.replaceAll("[,。、;,./;\\s]", " OR ");
  63. // System.out.println(sa);
  64. // StpUtil.login("2");
  65. // Object id = StpUtil.getLoginId();
  66. // String tokenValue = StpUtil.getTokenValue();
  67. // String value = StpUtil.getTokenValueByLoginId(2);
  68. // System.out.println(tokenValue);
  69. // System.out.println(value);
  70. SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
  71. SimpleDateFormat format1 = new SimpleDateFormat("yyyy");
  72. Date now = new Date();
  73. String nowFormat = format.format(now);
  74. System.out.println(nowFormat);
  75. Calendar calendar = Calendar.getInstance();
  76. calendar.setTime(now);
  77. calendar.add(Calendar.YEAR, -3);
  78. Date beforeDate = calendar.getTime();
  79. String threeYearsAgo = format1.format(beforeDate) + "0101";
  80. System.out.println(threeYearsAgo);
  81. }
  82. @Test
  83. public void test1() {
  84. // 获取当前时间
  85. LocalDateTime now = LocalDateTime.now();
  86. System.out.println(now);
  87. // 计算当天零点的时间
  88. LocalDateTime midnight = now.plusDays(1).truncatedTo(ChronoUnit.DAYS);
  89. // 转换为ZonedDateTime以获取时区信息
  90. ZonedDateTime zonedDateTime = midnight.atZone(ZoneId.systemDefault());
  91. // 转换为Unix时间戳(秒)
  92. long midnightTimestamp = TimeUnit.MILLISECONDS.toSeconds(zonedDateTime.toInstant().toEpochMilli());
  93. System.out.println(midnightTimestamp);
  94. // 获取当前时间的Unix时间戳(秒)
  95. long currentTimestamp = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
  96. System.out.println(currentTimestamp);
  97. // 计算剩余秒数直到当天零点
  98. long ttlSeconds = midnightTimestamp - currentTimestamp;
  99. System.out.println(ttlSeconds);
  100. // 如果已经过了零点,则设置过期时间为0或者重新计算逻辑
  101. if (ttlSeconds <= 0) {
  102. ttlSeconds = 0; // 或者你可以设置为其他逻辑,比如下一个天的零点
  103. }
  104. }
  105. @Test
  106. public void test2() {
  107. // String companyName = "CN";
  108. String keyword = "CN ZN KM,IU";
  109. String searchCondition = "";
  110. // String cName = companyName.replaceAll("[,。、;,./;]+|\\s+", "OR");
  111. // if (cName.contains("OR")) {
  112. // String[] split = cName.split("OR");
  113. // String ccName = "";
  114. // for (int i = 0; i < split.length; i++) {
  115. // String s = split[i];
  116. // if (split.length -1 != i) {
  117. // ccName = ccName + "\"" + s + "\"" + " OR ";
  118. // } else {
  119. // ccName = ccName + "\"" + s + "\"";
  120. // }
  121. // }
  122. // companyName = ccName;
  123. // } else {
  124. // companyName = "\"" + companyName + "\"";
  125. // }
  126. String key = denseVectorService.appendStr(keyword);
  127. if (StringUtils.isEmpty(searchCondition)) {
  128. searchCondition = "PE = " + "(" + key + ")";
  129. } else {
  130. searchCondition = searchCondition + " AND " + "PE = " + "(" + key + ")";
  131. }
  132. System.out.println(searchCondition);
  133. }
  134. @Test
  135. public void test4() {
  136. String input = "field1,field2,field3;‘field4,with,commas’, field5 with quotes,“field6,another field”, ac";
  137. List<String> result = RegexUtil.splitByDelimiters(input);
  138. // String append = denseVectorService.appendStr(input);
  139. System.out.println(result);
  140. for (String s : result) {
  141. System.out.println(s);
  142. }
  143. }
  144. @Test
  145. public void test5() {
  146. Product product = productMapper.selectById(35);
  147. String locNum = product.getLocNum();
  148. List<String> delimiters = RegexUtil.splitByDelimiters(locNum);
  149. delimiters.forEach(System.out::println);
  150. }
  151. @Test
  152. public void test6() throws IOException {
  153. byte[] bytes = fileManagerService.downloadSystemFileFromFMS("8e00430876da400aaafdf9c17596d715");
  154. FileUtils.getFileByBytes(bytes, "", "");
  155. List<String> stringList = new ArrayList<>();
  156. List<String> getGuids = new ArrayList<>();
  157. List<String> list = new ArrayList<>();
  158. list.add("8e00430876da400aaafdf9c17596d715");
  159. List<SystemFile> systemFileByGuids = fileManagerService.getSystemFileByGuids(getGuids);
  160. if (!CollectionUtils.isEmpty(systemFileByGuids)) {
  161. SystemFile systemFile = systemFileByGuids.get(0);
  162. String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
  163. String prefix = IdUtil.simpleUUID();
  164. File file = FileUtils.getFileByBytes(bytes, prefix, suffix);
  165. stringList = getVectorService.getVectorByFile(file);
  166. }
  167. System.out.println(stringList);
  168. }
  169. }