|
|
|
@@ -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()); |
|
|
|
} |
|
|
|
} |