123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package com.example.xiaoshiweixinback;
- import cn.hutool.core.util.IdUtil;
- import com.example.xiaoshiweixinback.business.common.base.SystemFile;
- import com.example.xiaoshiweixinback.business.utils.FileUtils;
- import com.example.xiaoshiweixinback.business.utils.RegexUtil;
- import com.example.xiaoshiweixinback.domain.Product;
- import com.example.xiaoshiweixinback.mapper.ProductMapper;
- import com.example.xiaoshiweixinback.service.ProductCategoryService;
- import com.example.xiaoshiweixinback.service.common.FileManagerService;
- import com.example.xiaoshiweixinback.service.common.GetVectorService;
- import com.example.xiaoshiweixinback.service.importPatent.EsDenseVectorService;
- import org.apache.commons.compress.utils.IOUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.junit.jupiter.api.Test;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.util.CollectionUtils;
- import java.io.*;
- import java.text.SimpleDateFormat;
- import java.time.LocalDateTime;
- import java.time.ZoneId;
- import java.time.ZonedDateTime;
- import java.time.format.DateTimeFormatter;
- import java.time.temporal.ChronoUnit;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- @SpringBootTest
- class XiaoshiWeixinbackApplicationTests {
- @Autowired
- @Lazy
- private EsDenseVectorService denseVectorService;
- @Autowired
- private ProductCategoryService productCategoryService;
- @Autowired
- private FileManagerService fileManagerService;
- @Autowired
- private GetVectorService getVectorService;
- @Autowired
- private ProductMapper productMapper;
- @Test
- void contextLoads() {
- }
- @Test
- public void test() throws Exception {
- // List<EsPictureVectorVo> list = denseVectorService.getPatentVectorSort(null, "大大的原型");
- // EsPatentSearchDTO dto = new EsPatentSearchDTO();
- // dto.setKey("手机 OR 产品");
- // Records records = denseVectorService.getPatentList(dto);
- // List<EsPictureVectorVo> list = JSON.parseArray(records.getData().toString(), EsPictureVectorVo.class);
- // System.out.println(list);
- // String s = "a , b , c , d";
- // boolean regExpReplace = RegexUtil.isRegExpReplace(s);
- // System.out.println(regExpReplace);
- // String all = s.replaceAll("[,。、;,./;]", " OR ");
- // System.out.println(all);
- // String s = "a OR b OR c OR d";
- // boolean regExpReplace = RegexUtil.isRegExpReplace(s);
- // System.out.println(regExpReplace);
- // String sa = s.replaceAll("[,。、;,./;\\s]", " OR ");
- // System.out.println(sa);
- // StpUtil.login("2");
- // Object id = StpUtil.getLoginId();
- // String tokenValue = StpUtil.getTokenValue();
- // String value = StpUtil.getTokenValueByLoginId(2);
- // System.out.println(tokenValue);
- // System.out.println(value);
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
- SimpleDateFormat format1 = new SimpleDateFormat("yyyy");
- Date now = new Date();
- String nowFormat = format.format(now);
- System.out.println(nowFormat);
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(now);
- calendar.add(Calendar.YEAR, -3);
- Date beforeDate = calendar.getTime();
- String threeYearsAgo = format1.format(beforeDate) + "0101";
- System.out.println(threeYearsAgo);
- }
- @Test
- public void test1() {
- // 获取当前时间
- LocalDateTime now = LocalDateTime.now();
- System.out.println(now);
- // 计算当天零点的时间
- LocalDateTime midnight = now.plusDays(1).truncatedTo(ChronoUnit.DAYS);
- // 转换为ZonedDateTime以获取时区信息
- ZonedDateTime zonedDateTime = midnight.atZone(ZoneId.systemDefault());
- // 转换为Unix时间戳(秒)
- long midnightTimestamp = TimeUnit.MILLISECONDS.toSeconds(zonedDateTime.toInstant().toEpochMilli());
- System.out.println(midnightTimestamp);
- // 获取当前时间的Unix时间戳(秒)
- long currentTimestamp = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
- System.out.println(currentTimestamp);
- // 计算剩余秒数直到当天零点
- long ttlSeconds = midnightTimestamp - currentTimestamp;
- System.out.println(ttlSeconds);
- // 如果已经过了零点,则设置过期时间为0或者重新计算逻辑
- if (ttlSeconds <= 0) {
- ttlSeconds = 0; // 或者你可以设置为其他逻辑,比如下一个天的零点
- }
- }
- @Test
- public void test2() {
- // String companyName = "CN";
- String keyword = "CN ZN KM,IU";
- String searchCondition = "";
- // String cName = companyName.replaceAll("[,。、;,./;]+|\\s+", "OR");
- // if (cName.contains("OR")) {
- // String[] split = cName.split("OR");
- // String ccName = "";
- // for (int i = 0; i < split.length; i++) {
- // String s = split[i];
- // if (split.length -1 != i) {
- // ccName = ccName + "\"" + s + "\"" + " OR ";
- // } else {
- // ccName = ccName + "\"" + s + "\"";
- // }
- // }
- // companyName = ccName;
- // } else {
- // companyName = "\"" + companyName + "\"";
- // }
- String key = denseVectorService.appendStr(keyword);
- if (StringUtils.isEmpty(searchCondition)) {
- searchCondition = "PE = " + "(" + key + ")";
- } else {
- searchCondition = searchCondition + " AND " + "PE = " + "(" + key + ")";
- }
- System.out.println(searchCondition);
- }
- @Test
- public void test4() {
- String input = "field1,field2,field3;‘field4,with,commas’, field5 with quotes,“field6,another field”, ac";
- List<String> result = RegexUtil.splitByDelimiters(input);
- // String append = denseVectorService.appendStr(input);
- System.out.println(result);
- for (String s : result) {
- System.out.println(s);
- }
- }
- @Test
- public void test5() {
- Product product = productMapper.selectById(35);
- String locNum = product.getLocNum();
- List<String> delimiters = RegexUtil.splitByDelimiters(locNum);
- delimiters.forEach(System.out::println);
- }
- @Test
- public void test6() throws IOException {
- byte[] bytes = fileManagerService.downloadSystemFileFromFMS("8e00430876da400aaafdf9c17596d715");
- FileUtils.getFileByBytes(bytes, "", "");
- List<String> stringList = new ArrayList<>();
- List<String> getGuids = new ArrayList<>();
- List<String> list = new ArrayList<>();
- list.add("8e00430876da400aaafdf9c17596d715");
- List<SystemFile> systemFileByGuids = fileManagerService.getSystemFileByGuids(getGuids);
- if (!CollectionUtils.isEmpty(systemFileByGuids)) {
- SystemFile systemFile = systemFileByGuids.get(0);
- String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
- String prefix = IdUtil.simpleUUID();
- File file = FileUtils.getFileByBytes(bytes, prefix, suffix);
- stringList = getVectorService.getVectorByFile(file);
- }
- System.out.println(stringList);
- }
- }
|