|
@@ -27,6 +27,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -39,7 +40,7 @@ public class DrugTest10 {
|
|
|
@Autowired
|
|
|
EntityService entityService;
|
|
|
private static int maxCount= -1;
|
|
|
- private static String drugExcelPath = "C:\\Users\\dell\\Desktop\\图谱\\药品说明书.xlsx";
|
|
|
+ private static String drugExcelPath = "C:\\Users\\17664\\Desktop\\药品说明书.xlsx";
|
|
|
static HSSFWorkbook workbook;
|
|
|
static String startLabel = "药品";
|
|
|
@Test
|
|
@@ -71,9 +72,6 @@ public class DrugTest10 {
|
|
|
if(StringUtils.isEmpty(name)){
|
|
|
continue;
|
|
|
}
|
|
|
- if("商品名称".equals(property)){
|
|
|
- property = "商品名";
|
|
|
- }
|
|
|
BaseEntity endEntity = createNoExists(startLabel+property, name);
|
|
|
Long endId = endEntity.getId();
|
|
|
RelationshipVO relationshipVO = new RelationshipVO();
|
|
@@ -94,6 +92,109 @@ public class DrugTest10 {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 剂型、规格
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void writeNeo4jFromExcel() throws Exception {
|
|
|
+ IOUtils.setByteArrayMaxOverride(369167224);
|
|
|
+ workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
|
|
|
+ InputStream drugFis = new FileInputStream(drugExcelPath);
|
|
|
+ Workbook drugWorkbook = new XSSFWorkbook(drugFis);
|
|
|
+ Sheet drugSheet = drugWorkbook.getSheetAt(0);
|
|
|
+ List<String> propertys = Arrays.asList("剂型", "规格");
|
|
|
+ for(String property:propertys) {
|
|
|
+ List<Knowlege> knowleges = saveExecl(drugSheet, property);
|
|
|
+
|
|
|
+ for (Knowlege temp : knowleges) {
|
|
|
+ String value = temp.getValue();
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(value);
|
|
|
+ BaseEntity startEntity = createNoExists(startLabel, temp.getEntity());
|
|
|
+ long startId = startEntity.getId();
|
|
|
+ List<RelationshipVO> relationshipList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ String name = jsonArray.getString(i);
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BaseEntity endEntity = createNoExists(startLabel + property, name);
|
|
|
+ Long endId = endEntity.getId();
|
|
|
+ RelationshipVO relationshipVO = new RelationshipVO();
|
|
|
+ relationshipVO.setStartId(startId);
|
|
|
+ relationshipVO.setEndId(endId);
|
|
|
+ relationshipVO.setStartLabel(startLabel);
|
|
|
+ relationshipVO.setEndLabel(startLabel + property);
|
|
|
+ relationshipVO.setRelationshipType(startLabel + "相关" + property);
|
|
|
+ relationshipList.add(relationshipVO);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(relationshipList)) {
|
|
|
+ System.out.println(relationshipService.createRelationship(relationshipList));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Knowlege> saveExecl(Sheet drugSheet,String property){
|
|
|
+ HSSFSheet sheet = workbook.createSheet(property);
|
|
|
+ int curCount = 0;
|
|
|
+ List<Knowlege> result = new ArrayList<>();
|
|
|
+ for (int rowNum = 1; rowNum <= drugSheet.getLastRowNum(); rowNum++) {
|
|
|
+ try {
|
|
|
+ Row row = drugSheet.getRow(rowNum);
|
|
|
+ String value;
|
|
|
+ if("剂型".equals(property)) {
|
|
|
+ value = row.getCell(3).getStringCellValue();
|
|
|
+ }else if("规格".equals(property)){
|
|
|
+ value = row.getCell(4).getStringCellValue();
|
|
|
+ }else {
|
|
|
+ System.out.println(property+"不对!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ HSSFRow writeRow = sheet.createRow(curCount);
|
|
|
+ String name = row.getCell(2).getStringCellValue();
|
|
|
+ String zhaiyao = row.getCell(7).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(value) || value.length()>30 || StringUtils.isEmpty(name) || name.length()>50 || StringUtils.isEmpty(zhaiyao)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ for (String item : value.split(";")) {
|
|
|
+ jsonArray.add(item);
|
|
|
+ }
|
|
|
+ value = jsonArray.toJSONString();
|
|
|
+ writeRow.createCell(0).setCellValue(name);
|
|
|
+ writeRow.createCell(1).setCellValue(value);
|
|
|
+
|
|
|
+ Knowlege knowlege = new Knowlege();
|
|
|
+ knowlege.setEntity(name);
|
|
|
+ knowlege.setProperty(property);
|
|
|
+
|
|
|
+ knowlege.setValue(value);
|
|
|
+
|
|
|
+ result.add(knowlege);
|
|
|
+ curCount++;
|
|
|
+ if (maxCount > 0) {
|
|
|
+ if (curCount >= maxCount) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ save(property);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
private BaseEntity createNoExists(String labelName, String name) {
|
|
|
BaseEntity nodeByName = entityService.findNodeByName(labelName, name);
|
|
|
if(Objects.nonNull(nodeByName)){//节点不存在
|
|
@@ -113,6 +214,7 @@ public class DrugTest10 {
|
|
|
Workbook drugWorkbook = new XSSFWorkbook(drugFis);
|
|
|
Sheet drugSheet = drugWorkbook.getSheetAt(2);
|
|
|
String[] split = propertys.split(",");
|
|
|
+
|
|
|
for(String property:split) {
|
|
|
HSSFSheet sheet = workbook.createSheet(property);
|
|
|
saveExecl(property, drugSheet, accessToken, sheet);
|
|
@@ -211,7 +313,7 @@ public class DrugTest10 {
|
|
|
|
|
|
private static synchronized void save(String fileName) {
|
|
|
try {
|
|
|
- fileName="D:\\测试文件夹\\"+fileName+System.currentTimeMillis()+".xlsx";
|
|
|
+ fileName="C:\\Users\\17664\\Desktop\\"+fileName+System.currentTimeMillis()+".xlsx";
|
|
|
//文档输出
|
|
|
FileOutputStream out = new FileOutputStream(new File(fileName));
|
|
|
workbook.write(out);
|