Browse Source

source添加pid

vincent 3 years ago
parent
commit
9c7798b33d

+ 1 - 0
bin/davinci.sql

@@ -474,6 +474,7 @@ CREATE TABLE `source`
     `id`             bigint(20)   NOT NULL AUTO_INCREMENT,
     `name`           varchar(255) NOT NULL,
     `description`    varchar(255) DEFAULT NULL,
+    `pId`    varchar(255) DEFAULT NULL,
     `config`         text         NOT NULL,
     `type`           varchar(10)  NOT NULL,
     `project_id`     bigint(20)   NOT NULL,

+ 7 - 2
server/pom.xml

@@ -27,7 +27,7 @@
     <repositories>
         <repository>
             <id>elasticsearch-releases</id>
-            <url>https://artifacts.elastic.co/maven</url>
+            <url>https://artifacts.elastic.com/maven</url>
             <releases>
                 <enabled>true</enabled>
             </releases>
@@ -54,7 +54,12 @@
         <dependency>
             <groupId>com.alibaba.boot</groupId>
             <artifactId>nacos-config-spring-boot-starter</artifactId>
-            <version>0.2.1</version>
+            <version>0.2.10</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.boot</groupId>
+            <artifactId>nacos-discovery-spring-boot-starter</artifactId>
+            <version>0.2.10</version>
         </dependency>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>

+ 27 - 2
server/src/main/java/edp/DavinciServerApplication.java

@@ -19,21 +19,46 @@
 
 package edp;
 
-import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
+import com.alibaba.nacos.api.annotation.NacosInjected;
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.api.naming.NamingService;
+import com.alibaba.nacos.client.naming.utils.CollectionUtils;
+import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
+import javax.annotation.PostConstruct;
+
 @SpringBootApplication(exclude = {
         org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.class,
         org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
 })
 @EnableScheduling
-@NacosPropertySource(dataId = "example", autoRefreshed = true)
 public class DavinciServerApplication {
 
+    @NacosInjected
+    private NamingService namingService;
+
+    @Value("${server.port}")
+    private int serverPort;
+
+    @Value("${nacos.discovery.server-addr}")
+    private String serverAddr;
+
+    @Value("${spring.application.name}")
+    private String applicationName;
+    //curl -X PUT 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=xxx&ip=127.0.0.1&port=8080'
+    @PostConstruct
+    public void registerInstance() throws NacosException
+    {
+        if(CollectionUtils.isEmpty(namingService.getAllInstances(applicationName))){
+            namingService.registerInstance(applicationName,serverAddr,serverPort);
+        }
+    }
+
     public static void main(String[] args) {
         System.setProperty("mail.mime.splitlongparameters", "false");
         SpringApplication.run(DavinciServerApplication.class, args);

+ 22 - 0
server/src/main/java/edp/davinci/controller/SourceController.java

@@ -78,6 +78,28 @@ public class SourceController extends BaseController {
         return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(sources));
     }
 
+    /**
+     * 获取source树形列表
+     *
+     * @param projectId
+     * @param user
+     * @param request
+     * @return
+     */
+    @ApiOperation(value = "get tree sources")
+    @GetMapping
+    public ResponseEntity getTreeSources(@RequestParam Long projectId,
+                                     @ApiIgnore @CurrentUser User user,
+                                     HttpServletRequest request) {
+        if (invalidId(projectId)) {
+            ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid project id");
+            return ResponseEntity.status(resultMap.getCode()).body(resultMap);
+        }
+        List<Source> sources = sourceService.getSources(projectId, user);
+
+        return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(sources));
+    }
+
 
     /**
      * 获取source 信息

+ 2 - 0
server/src/main/java/edp/davinci/dto/sourceDto/SourceCreate.java

@@ -32,6 +32,8 @@ public class SourceCreate {
     @NotBlank(message = "Source name cannot be empty")
     private String name;
 
+    private Long pId;
+
     private String description;
 
     @NotBlank(message = "Source type cannot be empty")

+ 2 - 0
server/src/main/java/edp/davinci/dto/sourceDto/SourceInfo.java

@@ -35,6 +35,8 @@ public class SourceInfo {
     @NotBlank(message = "Source name cannot be empty")
     private String name;
 
+    private Long pId;  // 父id
+
     private String description;
 
     @NotBlank(message = "Source type cannot be empty")

+ 2 - 0
server/src/main/java/edp/davinci/model/Source.java

@@ -42,6 +42,8 @@ public class Source extends RecordInfo<Source> {
 
     private Long id;
 
+    private Long pId;  // 父id
+
     private String name;
 
     private String description;

+ 12 - 0
server/src/main/resources/bootstrap.properties

@@ -0,0 +1,12 @@
+#nacos config
+spring.cloud.nacos.config.server-addr           =${NACOS_CONFIG_SERVER_ADDR:127.0.0.1:8848}
+# Nacos Console add configuration:
+# Data ID:maxkey.properties
+# Group:DEFAULT_GROUP
+# configuration:useLocalCache=true
+spring.application.name                         =taihu-analysis
+# Suffix for the configuration. Supports properties,yaml,yml,default is properties
+spring.cloud.nacos.config.file-extension        =properties
+#spring.cloud.nacos.config.file-extension=yaml
+#nacos enabled
+spring.cloud.nacos.config.enabled               =${NACOS_CONFIG_ENABLED:true}