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 list = denseVectorService.getPatentVectorSort(null, "大大的原型"); // EsPatentSearchDTO dto = new EsPatentSearchDTO(); // dto.setKey("手机 OR 产品"); // Records records = denseVectorService.getPatentList(dto); // List 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 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 delimiters = RegexUtil.splitByDelimiters(locNum); delimiters.forEach(System.out::println); } @Test public void test6() throws IOException { byte[] bytes = fileManagerService.downloadSystemFileFromFMS("8e00430876da400aaafdf9c17596d715"); FileUtils.getFileByBytes(bytes, "", ""); List stringList = new ArrayList<>(); List getGuids = new ArrayList<>(); List list = new ArrayList<>(); list.add("8e00430876da400aaafdf9c17596d715"); List 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); } }