Browse Source

test

dev-lhz
liuhuazhong 1 year ago
parent
commit
a00c04d757
1 changed files with 52 additions and 0 deletions
  1. +52
    -0
      ruoyi-modules/management-platform/src/test/java/com/ruoyi/platform/utils/ExcelReaderTest.java

+ 52
- 0
ruoyi-modules/management-platform/src/test/java/com/ruoyi/platform/utils/ExcelReaderTest.java View File

@@ -0,0 +1,52 @@
package com.ruoyi.platform.utils;

import com.ruoyi.platform.domain.kg.*;
import com.ruoyi.platform.repository.MatKGRepository;
import com.ruoyi.platform.service.impl.MatKGServiceImpl;
import com.ruoyi.platform.vo.MatKGVo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ExcelReaderTest {
@Autowired
private MatKGServiceImpl service;

@Autowired
private MatKGRepository repository;
@Test
void read() {
String excelFilePath = "C:\\haha\\matKG\\ENTDOI.csv";

ExecutorService executorService = Executors.newFixedThreadPool(10);
// 创建ExcelReader实例
ExcelReader<MatKGVo> excelReader = new ExcelReader<>(excelFilePath, MatKGVo.class, data -> {
// Optional<MaterialEntity> existingEntity = service.findById(data.getEntity());
// executorService.execute(() -> {
MaterialEntity entity = new MaterialEntity();
entity.setId(data.getUnnamed());
entity.setEntity(data.getEntity());
entity.setPreferredEntity(new PreferredEntity(data.getPreferred_Entity()));
entity.setDoi(new DOI(data.getDOI(),data.getYear()));
entity.setNerTag(new NERTag(data.getNER_Tag()));
entity.setPartOfText(new PartOfText(data.getPart_of_text()));
service.save(entity);
// });
// System.out.println(data);
});

// 读取Excel文件
excelReader.read();
}

@Test
public void xx(){
Optional<MaterialEntity> byId = repository.findById("27358");
System.out.println(byId.get());
}
}

Loading…
Cancel
Save