Browse Source

数据资源目录以及兼容web登录

vincent 3 years ago
parent
commit
96955f8a56

+ 10 - 0
Dockerfile

@@ -0,0 +1,10 @@
+# jdk的版本
+FROM openjdk:8u181-jdk-alpine
+# 作者
+MAINTAINER zhangheng
+ARG workdir=/app
+VOLUME ${workdir}
+WORKDIR ${workdir}
+ADD server/target/maxkey-gateway-3.1.1.jar app.jar
+EXPOSE 9000
+ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]

+ 211 - 0
config/application-ext.yml

@@ -0,0 +1,211 @@
+#  <<
+#  Davinci
+#  ==
+#  Copyright (C) 2016 - 2019 EDP
+#  ==
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#        http://www.apache.org/licenses/LICENSE-2.0
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#  >>
+
+
+server:
+  protocol: http
+  address: 127.0.0.1
+  port: ${SERVER_PORT:8081}
+
+  servlet:
+    context-path: /
+
+  # Used for mail and download services, can be empty, careful configuration
+  # By default, 'server.address' and 'server.port' is used as the string value.
+  # access:
+  #  address:
+  #  port:
+
+
+## jwt is one of the important configuration of the application
+## jwt config cannot be null or empty
+jwtToken:
+  secret: secret
+  timeout: 1800000
+  algorithm: HS512
+
+
+## your datasource config
+source:
+  initial-size: 1
+  min-idle: 1
+  max-wait: 30000
+  max-active: 10
+  break-after-acquire-failure: false
+  connection-error-retry-attempts: 1
+  time-between-eviction-runs-millis: 2000
+  min-evictable-idle-time-millis: 600000
+  max-evictable-idle-time-millis: 900000
+  time-between-connect-error-millis: 60000
+  test-while-idle: true
+  test-on-borrow: false
+  test-on-return: false
+  validation-query: select 1
+  validation-query-timeout: 10
+  keep-alive: false
+  filters: stat
+
+  enable-query-log: false
+  result-limit: 1000000
+
+
+spring:
+  mvc:
+    async:
+      request-timeout: 30s
+  rest:
+    proxy-host:
+    proxy-port:
+    proxy-ignore:
+
+
+  ## davinci datasource config
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    url: jdbc:mysql://${DATABASE_HOST:61.132.52.38}:${DATABASE_PORT:20002}/${DATABASE_NAME:davinci0.3}?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
+    username: ${DATABASE_USER:root}
+    password: ${DATABASE_PWD:root}
+    driver-class-name: com.mysql.jdbc.Driver
+    initial-size: 1
+    min-idle: 1
+    max-wait: 30000
+    max-active: 10
+    break-after-acquire-failure: false
+    connection-error-retry-attempts: 1
+    time-between-eviction-runs-millis: 2000
+    min-evictable-idle-time-millis: 600000
+    max-evictable-idle-time-millis: 900000
+    time-between-connect-error-millis: 60000
+    test-while-idle: true
+    test-on-borrow: false
+    test-on-return: false
+    validation-query: select 1
+    validation-query-timeout: 10
+    keep-alive: false
+    filters: stat
+
+  ## redis config
+  ## please choose either of the two ways
+  redis:
+    isEnable: true
+
+  ## standalone config
+    host: 127.0.0.1
+    port: 6379
+
+  ## cluster config
+  #  cluster:
+  #       nodes:
+
+    password:
+    database: 0
+    timeout: 1000
+    jedis:
+      pool:
+        max-active: 8
+        max-wait: 1000
+        max-idle: 200
+        min-idle: 0
+
+  ## mail is one of the important configuration of the application
+  ## mail config cannot be null or empty
+  ## some mailboxes need to be set separately password for the SMTP service)
+  mail:
+    host: smtp.qq.com
+    port: 465
+    username: 372237882@qq.com
+    fromAddress: 372237882@qq.com
+    password: pdjjxdplzwwzbhic
+    nickname: vincent
+
+    properties:
+      smtp:
+        starttls:
+          enable: true
+          required: true
+        auth: true
+      mail:
+        smtp:
+          ssl:
+            enable: false
+
+  ldap:
+    urls:
+    username:
+    password:
+    base:
+    domainName:    # domainName 指 企业邮箱后缀,如企业邮箱为:xxx@example.com,这里值为 '@example.com'
+
+  security:
+    oauth2:
+      enable: false
+#      client:
+#        registration:
+#          cas:
+#            provider: cas
+#            client-id: "xxxxx"
+#            client-name: "Sign in with XXX"
+#            client-secret: "xxxxx"
+#            authorization-grant-type: authorization_code
+#            client-authentication-method: post
+#            redirect-uri-template: "{baseUrl}/login/oauth2/code/{registrationId}"
+#            scope: userinfo
+#        provider:
+#          cas:
+#            authorization-uri: https://cas.xxxxx.cn/cas/oauth2.0/authorize
+#            token-uri: https://cas.xxxxx.cn/cas/oauth2.0/accessToken
+#            user-info-uri: https://cas.xxxxx.cn/cas/oauth2.0/profile
+#            user-name-attribute: id
+#            userMapping:
+#              email: "attributes.Email"
+#              name: "attributes.CnName1"
+#              avatar: "attributes.Avatar"
+
+screenshot:
+  default_browser: CHROME
+  timeout_second: 600
+  chromedriver_path: $your_chromedriver_path$
+  remote_webdriver_url: $your_remote_webdriver_url$
+
+data-auth-center:
+  channels:
+    - name:
+      base-url:
+      auth-code:
+
+statistic:
+  enable: false
+
+  # You can use external elasticsearch storage [127.0.0.1:9300]
+  elastic_urls:
+  elastic_user:
+  elastic_index_prefix:
+
+  # You can also use external mysql storage
+  mysql_url:
+  mysql_username:
+  mysql_password:
+
+  # You can also use external kafka
+  kafka.bootstrap.servers:
+  kafka.topic:
+  java.security.krb5.conf:
+  java.security.keytab:
+  java.security.principal:
+
+encryption:
+  maxEncryptSize: 1024
+  type: Off # Off is to turn off encryption, to enable encryption, please select AES or RSA

+ 1 - 1
server/pom.xml

@@ -5,7 +5,7 @@
     <modelVersion>4.0.0</modelVersion>
 
     <groupId>edp.davinci</groupId>
-    <artifactId>davinci-server_0.3.1</artifactId>
+    <artifactId>davinci-server</artifactId>
     <packaging>jar</packaging>
 
     <parent>

+ 7 - 3
server/src/main/java/edp/core/utils/TokenUtils.java

@@ -22,6 +22,7 @@ package edp.core.utils;
 import com.alibaba.druid.util.StringUtils;
 import edp.core.consts.Consts;
 import edp.core.model.TokenDetail;
+import edp.davinci.core.common.Constants;
 import io.jsonwebtoken.Claims;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.SignatureAlgorithm;
@@ -103,9 +104,12 @@ public class TokenUtils
      */
     public String refreshToken(String token)
     {
-//        Claims claims = getClaims(token);
-//        claims.put(Consts.TOKEN_CREATE_TIME, System.currentTimeMillis());
-//        return generate(claims);
+        if (token.startsWith(Constants.TOKEN_PREFIX))
+        {
+            Claims claims = getClaims(token);
+            claims.put(Consts.TOKEN_CREATE_TIME, System.currentTimeMillis());
+            return generate(claims);
+        }
         return token;
 
     }

+ 62 - 0
server/src/main/java/edp/davinci/controller/CatalogueController.java

@@ -0,0 +1,62 @@
+package edp.davinci.controller;
+
+import edp.core.annotation.CurrentUser;
+import edp.davinci.common.controller.BaseController;
+import edp.davinci.core.common.Constants;
+import edp.davinci.core.common.ResultMap;
+import edp.davinci.dto.viewDto.ViewBaseInfo;
+import edp.davinci.model.Catalogue;
+import edp.davinci.model.User;
+import edp.davinci.service.CatalogueService;
+import edp.davinci.service.ViewService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import springfox.documentation.annotations.ApiIgnore;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+@Api(value = "/catalogue", tags = "check", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+@ApiResponses(@ApiResponse(code = 404, message = "catalogue not found"))
+@Slf4j
+@RestController
+@RequestMapping(value = Constants.BASE_API_PATH + "/catalogue", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+public class CatalogueController extends BaseController
+{
+    @Autowired
+    private CatalogueService catalogueService;
+
+    /**
+     * 获取 数据资源目录
+     *
+     * @param projectId
+     * @param user
+     * @param request
+     * @return
+     */
+    @ApiOperation(value = "get catalogue")
+    @GetMapping(value = "/getCatalogues")
+    public ResponseEntity getCatalogues(@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<Catalogue> views = catalogueService.getCatalogues(projectId, user);
+        return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(views));
+    }
+
+}

+ 22 - 1
server/src/main/java/edp/davinci/core/inteceptor/AuthenticationInterceptor.java

@@ -86,6 +86,19 @@ public class AuthenticationInterceptor implements HandlerInterceptor
         }
         // 网关转发后请求头中获取token和userinfo
         String token = request.getHeader("Authorization");
+        // 分享
+        AuthShare authShareMethod = method.getAnnotation(AuthShare.class);
+        if (null != authShareMethod)
+        {
+            if (!StringUtils.isEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
+            {
+                String username = tokenUtils.getUsername(token);
+                User user = userService.getByUsername(username);
+                request.setAttribute(Constants.CURRENT_USER, user);
+            }
+            return true;
+        }
+
         String userinfo = request.getHeader("userinfo");
         String ticket = request.getParameter("ticket");
 
@@ -99,10 +112,18 @@ public class AuthenticationInterceptor implements HandlerInterceptor
 
         // token 不为空
         if(StringUtils.isNotEmpty(token)){
+            // 兼容之前登录
+            String username = tokenUtils.getUsername(token);
+            User userInfo = userService.getByUsername(username);
+            if(StringUtils.isNotEmpty(username)){
+                request.setAttribute(Constants.CURRENT_USER, userInfo);
+                return true;
+            }
+            // 统一认证
             JSONObject acessToken = (JSONObject) redisUtils.get(token);
             if(StringUtils.isEmpty(acessToken.toString())){
                 response.setStatus(HttpCodeEnum.UNAUTHORIZED.getCode());
-                response.getWriter().print(ErrorMsg.ERR_LOAD_DATA_TOKEN);
+                response.getWriter().print(ErrorMsg.ERR_INVALID_TOKEN);
                 return false;
             }
             JSONObject userinfoObject = (JSONObject) JSONObject.toJSON(acessToken);

+ 110 - 0
server/src/main/java/edp/davinci/dao/CatalogueMapper.java

@@ -0,0 +1,110 @@
+/*
+ * <<
+ *  Davinci
+ *  ==
+ *  Copyright (C) 2016 - 2019 EDP
+ *  ==
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *  >>
+ *
+ */
+
+package edp.davinci.dao;
+
+import edp.davinci.dto.viewDto.*;
+import edp.davinci.model.Catalogue;
+import edp.davinci.model.View;
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Set;
+
+@Component
+public interface CatalogueMapper
+{
+
+    int insert(Catalogue catalogue);
+
+    @Select({"select id from `catalogue` where project_id = #{projectId} and `name` = #{name}"})
+    Long getByNameWithProjectId(@Param("name") String name, @Param("projectId") Long projectId);
+
+//    ViewWithProjectAndSource getViewWithProjectAndSourceById(@Param("id") Long id);
+
+//    ViewWithProjectAndSource getViewWithProjectAndSourceByWidgetId(@Param("widgetId") Long widgetId);
+
+    @Delete({"delete from `catalogue` where id = #{id}"})
+    int deleteById(Long id);
+
+    @Select({"select * from `catalogue` where id = #{id}"})
+    Catalogue getById(Long id);
+
+//    @Select({"select id, name, model, variable from `view` where id = #{id}"})
+//    SimpleView getSimpleViewById(Long id);
+
+    @Update({
+            "update `catalogue`",
+            "set `name` = #{name,jdbcType=VARCHAR},",
+            "`description` = #{description,jdbcType=VARCHAR},",
+            "`project_id` = #{projectId,jdbcType=BIGINT},",
+            "`origin_dept` = #{originDept,jdbcType=VARCHAR},",
+            "`origin_system` = #{originSystem,jdbcType=VARCHAR},",
+            "`industry` = #{industry,jdbcType=VARCHAR},",
+            "`ext_config` = #{extConfig,jdbcType=LONGVARCHAR},",
+            "`update_by` = #{updateBy,jdbcType=BIGINT},",
+            "`update_time` = #{updateTime,jdbcType=TIMESTAMP}",
+            "where id = #{id,jdbcType=BIGINT}"
+    })
+    int update(Catalogue catalogue);
+
+    @Select({"select * from `catalogue` where project_id = #{projectId}"})
+    List<Catalogue> getByProjectId(@Param("projectId") Long projectId);
+
+//    @Select({
+//            "select v.*,",
+//            "s.id as 'source.id', s.`name` as 'source.name' from `view` v ",
+//            "left join source s on s.id = v.source_id ",
+//            "where v.id = #{id}"
+//    })
+//    ViewWithSourceBaseInfo getViewWithSourceBaseInfo(@Param("id") Long id);
+
+//    @Select({
+//            "select v.id, v.`name`, v.`description`, s.name as 'sourceName'",
+//            "from `view` v ",
+//            "left join source s on s.id = v.source_id ",
+//            "where v.project_id = #{projectId}"
+//    })
+//    List<ViewBaseInfo> getViewBaseInfoByProject(@Param("projectId") Long projectId);
+
+    int insertBatch(@Param("list") List<Catalogue> catalogueList);
+
+    @Delete({"delete from `catalogue` where project_id = #{projectId}"})
+    int deleteByProject(@Param("projectId") Long projectId);
+
+//    @Select({
+//            "SELECT ",
+//            "	v.*,",
+//            "	s.`id` 'source.id',",
+//            "	s.`name` 'source.name',",
+//            "	s.`description` 'source.description',",
+//            "	s.`config` 'source.config',",
+//            "	s.`project_id` 'source.projectId',",
+//            "	s.`type` 'source.type'",
+//            "FROM `view` v",
+//            "	LEFT JOIN project p on p.id = v.project_id",
+//            "	LEFT JOIN source s on s.id = v.source_id",
+//            "WHERE v.id = #{id}"
+//    })
+//    ViewWithSource getViewWithSource(Long id);
+}

+ 40 - 0
server/src/main/java/edp/davinci/model/Catalogue.java

@@ -0,0 +1,40 @@
+package edp.davinci.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import edp.core.model.RecordInfo;
+import lombok.Data;
+
+/**
+ *  数据资源目录
+ */
+@Data
+public class Catalogue extends RecordInfo<Catalogue>
+{
+    private Long id;
+
+    // 父ID
+    private Long parentId;
+
+    private Long projectId;
+
+    // 资源名称
+    private String name;
+
+    // 资源描述
+    private String description;
+
+    // 来源部门
+    private String originDept;
+
+    // 来源系统
+    private String originSystem;
+
+    // 行业分类
+    private String industry;
+
+    // 扩展信息
+    @JSONField(serialize = false)
+    private String extConfig;
+
+
+}

+ 3 - 0
server/src/main/java/edp/davinci/model/View.java

@@ -39,6 +39,9 @@ public class View extends RecordInfo<View> {
 
     private Long sourceId;
 
+    // 父ID
+    private Long parentId;
+
     private String sql;
 
     private String model;

+ 20 - 0
server/src/main/java/edp/davinci/service/CatalogueService.java

@@ -0,0 +1,20 @@
+package edp.davinci.service;
+
+import edp.core.exception.NotFoundException;
+import edp.core.exception.ServerException;
+import edp.core.exception.UnAuthorizedException;
+import edp.davinci.model.Catalogue;
+import edp.davinci.model.User;
+
+import java.util.List;
+
+public interface CatalogueService
+{
+    List<Catalogue> getCatalogues(Long projectId, User user) throws NotFoundException, UnAuthorizedException, ServerException;
+
+    Catalogue createCatalogue(Catalogue catalogue, User user) throws NotFoundException, UnAuthorizedException, ServerException;
+
+    boolean updateCatalogue(Catalogue catalogue, User user) throws NotFoundException, UnAuthorizedException, ServerException;
+
+    boolean deleteCatalogue(Long id, User user) throws NotFoundException, UnAuthorizedException, ServerException;
+}

+ 47 - 0
server/src/main/java/edp/davinci/service/impl/CatalogueServiceImpl.java

@@ -0,0 +1,47 @@
+package edp.davinci.service.impl;
+
+import edp.core.exception.NotFoundException;
+import edp.core.exception.ServerException;
+import edp.core.exception.UnAuthorizedException;
+import edp.davinci.dao.CatalogueMapper;
+import edp.davinci.dao.DictTypeMapper;
+import edp.davinci.model.Catalogue;
+import edp.davinci.model.User;
+import edp.davinci.service.CatalogueService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Slf4j
+@Service("catalogueService")
+public class CatalogueServiceImpl implements CatalogueService
+{
+    @Autowired
+    private CatalogueMapper catalogueMapper;
+
+    @Override
+    public List<Catalogue> getCatalogues(Long projectId, User user) throws NotFoundException, UnAuthorizedException, ServerException
+    {
+        return catalogueMapper.getByProjectId(projectId);
+    }
+
+    @Override
+    public Catalogue createCatalogue(Catalogue catalogue, User user) throws NotFoundException, UnAuthorizedException, ServerException
+    {
+        return null;
+    }
+
+    @Override
+    public boolean updateCatalogue(Catalogue catalogue, User user) throws NotFoundException, UnAuthorizedException, ServerException
+    {
+        return false;
+    }
+
+    @Override
+    public boolean deleteCatalogue(Long id, User user) throws NotFoundException, UnAuthorizedException, ServerException
+    {
+        return false;
+    }
+}

+ 91 - 0
server/src/main/resources/mybatis/mapper/CatalogueMapper.xml

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  ~ <<
+  ~  Davinci
+  ~  ==
+  ~  Copyright (C) 2016 - 2019 EDP
+  ~  ==
+  ~  Licensed under the Apache License, Version 2.0 (the "License");
+  ~  you may not use this file except in compliance with the License.
+  ~  You may obtain a copy of the License at
+  ~        http://www.apache.org/licenses/LICENSE-2.0
+  ~   Unless required by applicable law or agreed to in writing, software
+  ~   distributed under the License is distributed on an "AS IS" BASIS,
+  ~   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~   See the License for the specific language governing permissions and
+  ~   limitations under the License.
+  ~  >>
+  ~
+  -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="edp.davinci.dao.CatalogueMapper">
+    <insert id="insert" parameterType="edp.davinci.model.Catalogue">
+        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
+            SELECT LAST_INSERT_ID() AS id
+        </selectKey>
+        insert into `catalogue`
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            `name`,
+            `project_id`,
+            <if test="description != null">
+                description,
+            </if>
+            <if test="originDept != null">
+                `origin_dept`,
+            </if>
+            <if test="originSystem != null">
+                `origin_system`,
+            </if>
+            <if test="industry != null">
+                `industry`,
+            </if>
+            <if test="extConfig != null">
+                `ext_config`,
+            </if>
+            `create_by`,
+            `create_time`
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            #{name,jdbcType=VARCHAR},
+            #{projectId,jdbcType=BIGINT},
+            <if test="description != null">
+                #{description,jdbcType=VARCHAR},
+            </if>
+            <if test="originDept != null">
+                #{originDept,jdbcType=VARCHAR},
+            </if>
+            <if test="originSystem != null">
+                #{originSystem,jdbcType=VARCHAR},
+            </if>
+            <if test="industry != null">
+                #{industry,jdbcType=VARCHAR},
+            </if>
+            <if test="extConfig != null">
+                #{extConfig,jdbcType=LONGVARCHAR},
+            </if>
+            #{createBy,jdbcType=BIGINT},
+            #{createTime,jdbcType=TIMESTAMP}
+        </trim>
+    </insert>
+
+
+    <insert id="insertBatch" useGeneratedKeys="true" keyProperty="id">
+        insert into `view`
+        (`id`,`name`,description, origin_dept, `project_id`, `origin_system`, `industry`,`ext_config`)
+        VALUES
+        <foreach collection="list" item="record" index="index" separator=",">
+            (
+            #{record.id,jdbcType=BIGINT},
+            #{record.name,jdbcType=VARCHAR},
+            #{record.description,jdbcType=VARCHAR},
+            #{record.originDept,jdbcType=VARCHAR},
+            #{record.projectId,jdbcType=BIGINT},
+            #{record.originSystem,jdbcType=VARCHAR},
+            #{record.industry,jdbcType=VARCHAR},
+            #{record.extConfig,jdbcType=VARCHAR}
+            )
+        </foreach>
+    </insert>
+
+</mapper>