Commit 94a59521 authored by zhengfunan's avatar zhengfunan

stater版首次提交

parents
Pipeline #384 failed with stages
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="67e936c8-2d55-4655-871e-e6e153e4d8e1" name="更改" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/auto/Neo4jAutoConfiguration.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/config/Neo4jProperties.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/neo4j/Neo4jServer.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/service/TDGraphService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/tasks/SynchronizeMetadata.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/util/GraphUtil.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/META-INF/spring.factories" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="MavenImportPreferences">
<option name="importingSettings">
<MavenImportingSettings>
<option name="workspaceImportEnabled" value="true" />
</MavenImportingSettings>
</option>
</component>
<component name="ProjectId" id="2UeUXtwjbhwh54lBi8nJQtzpQb7" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "false",
"last_opened_file_path": "D:/ideawork/stater-tdtopo",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"spring.configuration.checksum": "35834eaec7657be6760ebdbe364857eb",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\ideawork\stater-tddopo\src\main\java\com\tongda\tddopo" />
<recent name="D:\ideawork\stater-tddopo\src\main\resources" />
<recent name="D:\ideawork\stater-tddopo\src\main\java\com\tongda" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="com.tongda.tddopo" />
</key>
</component>
<component name="RunManager">
<configuration name="Test" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.tongda.tddopo.test.Test" />
<module name="stater-tdtopo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.tongda.tddopo.test.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="应用程序.Test" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="默认任务">
<changelist id="67e936c8-2d55-4655-871e-e6e153e4d8e1" name="更改" comment="" />
<created>1693299583537</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1693299583537</updated>
<workItem from="1693299584659" duration="7284000" />
<workItem from="1693363826067" duration="10263000" />
<workItem from="1693386223381" duration="1313000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tongda</groupId>
<artifactId>stater-tdtopo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<!-- <version>5.9.0</version>-->
<version>3.5.30</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.32</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.tongda.tddopo.auto;
import com.tongda.tddopo.config.Neo4jProperties;
import com.tongda.tddopo.neo4j.Neo4jServer;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
@Configuration
@EnableConfigurationProperties(Neo4jProperties.class)
public class Neo4jAutoConfiguration {
@Resource
private Neo4jProperties properties; // 使用配置
@Bean
@ConditionalOnMissingBean
public GraphDatabaseService init() {
//初始化neo4j
GraphDatabaseService graphDatabaseService=new Neo4jServer().init(properties.getPath(),properties.getBolt());
System.out.println("neo4j-server启动成功");
return graphDatabaseService;
}
}
package com.tongda.tddopo.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "neo4j")
@Data
public class Neo4jProperties {
private String path="data/";
private String bolt="true";
}
package com.tongda.tddopo.neo4j;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.graphdb.schema.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import javax.annotation.PostConstruct;
import java.io.File;
@Configuration
public class Neo4jServer {
public static GraphDatabaseService graphDatabaseService;
// public static DatabaseManagementService managementService;
// @Autowired
// private Environment environment;
// @PostConstruct
public GraphDatabaseService init(String file,String bolt){
// GraphDatabaseSettings.BoltConnector boltConnector = GraphDatabaseSettings.boltConnector( "0" );
graphDatabaseService = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(new File(file))
.setConfig( GraphDatabaseSettings.pagecache_memory, "8192M" )
.setConfig( GraphDatabaseSettings.string_block_size, "600" )
.setConfig( GraphDatabaseSettings.array_block_size, "3000" )
// .setConfig( boltConnector.type, "BOLT" )
// .setConfig( boltConnector.enabled, "true" )
// .setConfig( boltConnector.address, "localhost:7687")
.newGraphDatabase();
IndexDefinition indexDefinition;
try ( Transaction tx = graphDatabaseService.beginTx() )
{
// Schema schema = graphDatabaseService.schema();
// indexDefinition = schema.indexFor( Label.label( "MDE" ))
// .on( "id" )
// .create();
// indexDefinition = schema.indexFor( Label.label( "AST" ))
// .on( "id" )
// .create();
tx.success();
}
return graphDatabaseService;
}
// private static void registerShutdownHook( final GraphDatabaseService graphDb )
// {
// // Registers a shutdown hook for the Neo4j instance so that it
// // shuts down nicely when the VM exits (even if you "Ctrl-C" the
// // running application).
// Runtime.getRuntime().addShutdownHook( new Thread()
// {
// @Override
// public void run()
// {
// graphDb.shutdown();
// }
// } );
// }
// @PostConstruct
// public void init(){
//
// Path of = Path.of(environment.getProperty("spring.neo4j.path"));
// managementService = new DatabaseManagementServiceBuilder(of)
// .setConfig( BoltConnector.enabled, true)
//// .setConfig( HttpConnector.enabled, true )
//// .setConfig( HttpConnector.listen_address, new SocketAddress(Integer.parseInt(environment.getProperty("spring.neo4j.port"))) )
// .setConfig( BoltConnector.listen_address, new SocketAddress(Integer.parseInt(environment.getProperty("spring.neo4j.port"))))
//// .setConfig( GraphDatabaseSettings.auth_enabled,true)
//// .setConfig( GraphDatabaseSettings.data_directory,of)
// .setConfig( GraphDatabaseSettings.initial_default_database,environment.getProperty("spring.data.neo4j.database"))
// .setConfig(GraphDatabaseSettings.transaction_timeout, Duration.ofSeconds(60))
// .build();
// graphDatabaseService = managementService.database(environment.getProperty("spring.data.neo4j.database"));
// }
}
This diff is collapsed.
package com.tongda.tddopo.tasks;
import com.alibaba.fastjson.JSONObject;
import com.tongda.tddopo.service.TDGraphService;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@Component
@PropertySource(value = "classpath:application.properties")
public class SynchronizeMetadata {
// @Value("${db.login.user}")
// private String user;
// @Value("${db.login.password}")
// private String password;
// @Value("${db.login.loginId}")
// private String loginId;
// @Value("${db.login.loginPort}")
// private int loginPort;
// @Value("${db.pimserver.serverId}")
// private String serverId;
// @Value("${db.pimserver.serverPort}")
// private int serverPort;
// @Value("${db.pimserver.dbName}")
// private String dbName;
//
// private static Long lastTime;
//
// @Scheduled(cron="${cron.msg}")
// public void updateMetadata() {
// //初始化登录信息
// RemoteSaAuthHandler rsh = initConfig();
// lastTime=0L;
// //初次更新时初值
// if(lastTime==null){
// lastTime=System.currentTimeMillis();
// }
// //获取更新列表
// String url="http://"+ rsh.serverIP +":"+ rsh.serverPort+"/pims/index/swap?dbName="+rsh.dbName+"&timestamp="+lastTime;
// //保存更新时间
// lastTime=System.currentTimeMillis();
// String response= PimHttpUtil.sendGet(rsh.saToken,url);
// String data=responseData(response);
// metadataListHandle(data,rsh);
// }
//
// @Scheduled(cron="${cron.msg.date}")
// public void updateMetadataDate() {
// //初始化登录信息
// RemoteSaAuthHandler rsh = initConfig();
//// System.out.println("登录数据"+rsh);
// long time=System.currentTimeMillis()-1000*60*60*24;
// String url="http://"+ rsh.serverIP +":"+ rsh.serverPort+"/pims/index/swap?dbName="+rsh.dbName+"&timestamp="+time;
//
// String response= PimHttpUtil.sendGet(rsh.saToken,url);
//// System.out.println(response);
// JSONObject jsonObject=JSONObject.parseObject(response);
// String data=jsonObject.getString("data");
// metadataListHandle(data,rsh);
// }
//每天删除独立的节点
// @Scheduled(cron="${cron.msg.date}")
// public void deleteLoneNode() {
// TDGraphService tdGraphService=new TDGraphService();
// tdGraphService.deleteLoneNode();
// }
// //更新数据方法 createStamp
// public void selectById(Element e,RemoteSaAuthHandler rsh){
//
//
// String id=e.attributeValue("id");
// String func=e.attributeValue("func");
// long totalMilliSeconds1 = System.currentTimeMillis();
// String url1="http://"+ rsh.serverIP +":"+ rsh.serverPort+"/pims/index/graph?dbName="+rsh.dbName+"&id="+id+"&func="+func;
// String response= PimHttpUtil.sendGet(rsh.saToken,url1);
// long totalMilliSeconds2 = System.currentTimeMillis();
// System.out.println("拉取数据时间:"+(totalMilliSeconds2-totalMilliSeconds1));
// JSONObject jsonObject=JSONObject.parseObject(response);
// String xml=jsonObject.getString("data");
// System.out.println("返回id:"+id);
// TDGraphApi tdGraphApi=new TDGraphApi();
// tdGraphApi.addData(xml);
// long totalMilliSeconds3 = System.currentTimeMillis();
// System.out.println("添加数据时间:"+(totalMilliSeconds3-totalMilliSeconds2));
//
// }
//
// //处理更新id集合
// public void metadataListHandle(String data,RemoteSaAuthHandler rsh) {
//
// SAXReader saxReader = new SAXReader();
// try {
// System.out.println(data);
// Document document = saxReader.read(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
// Element root = document.getRootElement();
// //处理节点
// List<Element> elements=root.elements("GraphicUpdate");
// int i=0;
// for (Element e:elements) {
// i++;
// if (e.attributeValue("type").equals("Delete")){
// deleteById(e);
// }else if (checkTimeById(e)){
// selectById(e,rsh);
// }
// System.out.println("数量:"+i);
// }
// } catch (DocumentException e) {
// throw new RuntimeException(e);
// }
// }
//
// //检查id在neo4j里的时间,判断是否需要更新
// public boolean checkTimeById(Element e){
// long stamp=Long.parseLong(e.attributeValue("stamp"));
// String id=e.attributeValue("id");
// String type=e.attributeValue("id").split("-")[0];
// TDGraphApi tdGraphApi=new TDGraphApi();
// JSONObject json=new JSONObject();
//
// List<String> list=new ArrayList<>();
// list.add(type);
// json.put("tag",list);
// List<String> listid=new ArrayList<>();
// listid.add(id);
// json.put("idList",listid);
// String s=tdGraphApi.searchMetadata(json.toString());
// System.out.println("返回结果"+s);
// List<JSONObject> relist=JSONObject.parseArray(s,JSONObject.class);
//
// if (relist.size()>0){
// String time= (String) relist.get(0).get("updateStamp");
// long timeL=Long.parseLong(time);
// timeL=0;
//// System.out.println(time);
//// LocalDateTime date = LocalDateTime.parse(time, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
//// timeNeo4j=date.toInstant(ZoneOffset.of("+8")).toEpochMilli();
// if(timeL>=stamp){
// System.out.println("无需更新");
// return false;
// }
//
// }
//// System.out.println(timeNeo4j+"/"+stamp);
//
// return true;
// }
//
// /**
// * 删除向下关联1范围内的所有节点及关系,
// * match (n)-->(m) where n.id='ResourceTemplate-1133463217943609344' DETACH DELETE n,m
// * @param e
// */
// public void deleteById(Element e){
// String id=e.attributeValue("id");
// TDGraphApi tdGraphApi=new TDGraphApi();
// tdGraphApi.removeGraph(id);
// }
//
// public RemoteSaAuthHandler initConfig(){
//
//// RemoteSaAuthHandler rsh = new RemoteSaAuthHandler("graphsdk","q1w2e3r4","121.199.160.117",9000);
//// rsh.setAppInstance("150.158.75.213",8080,"TXPIMDB");
// RemoteSaAuthHandler rsh = new RemoteSaAuthHandler(user,password,loginId,loginPort);
// String token=rsh.loginGetSaToken();
// if (token==null||token.equals("")){
// rsh.loginGetSaToken();
// }
// //登录获取token
// rsh.setAppInstance(serverId,serverPort,dbName);
// System.out.println("登录数据"+rsh);
// return rsh;
// }
//
// /**
// * 处理返回数据
// * @param response
// * @return
// */
// public String responseData(String response){
// System.out.println("response"+response);
// JSONObject jsonObject=JSONObject.parseObject(response);
// String data="";
// if (jsonObject.get("code").toString().equals("200")){
// data=jsonObject.getString("data");
// }else {
// System.out.println("错误信息:"+jsonObject.getString("data"));
// }
// return data;
// }
}
package com.tongda.tddopo.util;
import com.alibaba.fastjson.JSONObject;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Result;
import java.util.*;
public class GraphUtil {
/**
* neo4j返回结果 节点处理工具node
* return m,n
* @param result
* @return
*/
public static HashMap<String, JSONObject> nodesUtil(Result result){
HashMap<String,JSONObject> hashMapNode=new HashMap<>();
while (result.hasNext()) {
Map<String,Object> row = result.next();
for (Map.Entry<String,Object> column : row.entrySet()) {
Node node=(Node)column.getValue();
Iterator<Label> iterator=node.getLabels().iterator();
ArrayList<String> arrayList=new ArrayList<>();
while (iterator.hasNext()){
arrayList.add(iterator.next().toString());
}
JSONObject jsonObject=new JSONObject(node.getAllProperties());
jsonObject.put("tags",arrayList);
hashMapNode.put(column.getValue().toString(),jsonObject);
}
}
return hashMapNode;
}
/**
* neo4j返回结果 关系处理工具link
* 适用此方法需要查询时设置关系的步长,默认可以为1,如[r*1],保证返回值中是一个list
* return r
* @param result
* @return
*/
public static ArrayList<JSONObject> linksUtil(Result result){
ArrayList<JSONObject> relationList=new ArrayList<>();
while (result.hasNext()) {
Map<String,Object> row = result.next();
for (Map.Entry<String,Object> column : row.entrySet()) {
ArrayList<Relationship> arrayList=(ArrayList<Relationship>)column.getValue();
for (Relationship relationship :arrayList){
JSONObject jsonObject1=new JSONObject();
jsonObject1.put("source",relationship.getStartNode().getAllProperties().get("id"));
jsonObject1.put("target",relationship.getEndNode().getAllProperties().get("id"));
jsonObject1.put("type",relationship.getType().toString());
relationList.add(jsonObject1);
}
}
}
return relationList;
}
/**
* 步长为一的返回关系结果处理 r为1时
* @param result
* @return
*/
public static JSONObject LinksAndNodesUtil(Result result){
// System.out.println(result.resultAsString());
ArrayList<JSONObject> relationList=new ArrayList<>();
HashMap<String,JSONObject> hashMapNode=new HashMap<>();
while (result.hasNext()) {
Map<String,Object> row = result.next();
// System.out.println(row.toString());
for (Map.Entry<String,Object> column : row.entrySet()) {
// System.out.println(column.toString());
if (column.getKey().equals("r")){
// System.out.println(column.getValue());
List<Relationship> relationships=(List<Relationship>)column.getValue();
Relationship relationship=relationships.get(0);
JSONObject jsonObject1=new JSONObject();
jsonObject1.put("source",relationship.getStartNode().getProperty("id").toString());
jsonObject1.put("target",relationship.getEndNode().getProperty("id").toString());
jsonObject1.put("type",relationship.getType().toString());
relationList.add(jsonObject1);
}else {
Node node=(Node)column.getValue();
Iterator<Label> iterator=node.getLabels().iterator();
ArrayList<String> arrayList=new ArrayList<>();
while (iterator.hasNext()){
arrayList.add(iterator.next().toString());
}
JSONObject jsonObject=new JSONObject(node.getAllProperties());
jsonObject.put("tags",arrayList);
hashMapNode.put(column.getValue().toString(),jsonObject);
}
}
}
ArrayList<JSONObject> nodeList = new ArrayList();
Iterator iterator = hashMapNode.keySet().iterator();
String s;
while(iterator.hasNext()) {
s = (String)iterator.next();
JSONObject jsonObject = hashMapNode.get(s);
nodeList.add(jsonObject);
}
JSONObject returnJson = new JSONObject();
returnJson.put("nodes", nodeList);
returnJson.put("links", relationList);
return returnJson;
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tongda.tddopo.auto.Neo4jAutoConfiguration
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment