2 Commits 51eca04bdf ... 4edd51ba62

Author SHA1 Message Date
  zhangtong 4edd51ba62 fss 3 years ago
  fengyanjie 981966c481 修复onlyCount返回总数量bug 3 years ago
35 changed files with 2014 additions and 202 deletions
  1. 46 0
      dmp-fss-ioc/doc/config.sql
  2. 72 0
      dmp-fss-ioc/pom.xml
  3. 15 0
      dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/IOCApp.java
  4. 14 0
      dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/config/IOCConfig.java
  5. 32 0
      dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/config/properties/IOCProperties.java
  6. 169 0
      dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/service/IOCFileService.java
  7. 161 0
      dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/tool/HttpTools.java
  8. 19 0
      dmp-fss-ioc/src/main/resources/application.yml
  9. 60 0
      dmp-fss-ioc/src/main/resources/bootstrap.yml
  10. 114 0
      dmp-fss/pom.xml
  11. 45 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/FSSApp.java
  12. 23 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/config/AuthorizationConfig.java
  13. 41 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/config/DMPConfig.java
  14. 87 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/controller/FileController.java
  15. 39 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/controller/TestController.java
  16. 56 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/controller/TokenController.java
  17. 66 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/interceptor/AuthorizationInterceptor.java
  18. 72 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/BaseFileService.java
  19. 13 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/FileService.java
  20. 8 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/TokenService.java
  21. 87 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/impl/TokenServiceImpl.java
  22. 127 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/common/tool/AESTools.java
  23. 39 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/controller/FileAuthorizationController.java
  24. 39 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/controller/FileResourceController.java
  25. 42 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/entity/FileAuthorization.java
  26. 57 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/entity/FileResource.java
  27. 14 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/model/FileAuthorizationModel.java
  28. 18 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/model/FileResourceModel.java
  29. 9 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/repository/FileAuthorizationRepository.java
  30. 9 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/repository/FileResourceRepository.java
  31. 77 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/service/FileAuthorizationService.java
  32. 82 0
      dmp-fss/src/main/java/com/persagy/dmp/fss/file/service/FileResourceService.java
  33. 54 0
      dmp-fss/src/main/resources/bootstrap.yml
  34. 206 202
      dmp-rwd/src/main/java/com/persagy/dmp/rwd/service/RelationInstanceService.java
  35. 2 0
      pom.xml

+ 46 - 0
dmp-fss-ioc/doc/config.sql

@@ -0,0 +1,46 @@
+# rwd config
+delete from `integrated_config` where application = 'dmp-fss';
+INSERT INTO `integrated_config`
+(`APPLICATION`,`PPROFILE`,`LABLE`,`BELONGTO`,`ISUPDATE`,`PKEY`,`PVALUE`,`DESCRIPTION`)
+VALUES
+('dmp-fss','default','master','DMP',1,'spring.jackson.time-zone', 'Asia/Shanghai', 'json时间解析时区'),
+('dmp-fss','default','master','DMP',1,'spring.jpa.show-sql', 'false', '不打印sql'),
+('dmp-fss','default','master','DMP',1,'spring.jpa.hibernate.ddl-auto', 'none', '不自动更新表结构'),
+('dmp-fss','default','master','DMP',1,'management.endpoints.web.exposure.include', '*', '暴露所有端点'),
+('dmp-fss','default','master','DMP',1,'management.endpoint.health.show-details', 'ALWAYS', '详细的应用健康信息'),
+('dmp-fss','default','master','DMP',1,'eureka.client.fetch-registry','true','检索服务'),
+('dmp-fss','default','master','DMP',1,'eureka.client.register-with-eureka','true','注册服务'),
+('dmp-fss','default','master','DMP',1,'eureka.instance.lease-renewal-interval-in-seconds','10','心跳发发送频率'),
+('dmp-fss','default','master','DMP',1,'eureka.instance.lease-expiration-duration-in-seconds','30','过期剔除时间'),
+('dmp-fss','default','master','DMP',1,'eureka.instance.hostname','${spring.application.name}','应用实例主机名'),
+('dmp-fss','default','master','DMP',1,'eureka.instance.prefer-ip-address','true','显示IP'),
+('dmp-fss','default','master','DMP',1,'eureka.instance.instance-id','${spring.cloud.client.ip-address}:${server.port}','eureka中状态显示名称'),
+
+('dmp-fss','default','master','DMP',1,'spring.datasource.type', 'com.alibaba.druid.pool.DruidDataSource', '连接池'),
+('dmp-fss','default','master','DMP',1,'spring.datasource.driverClassName', 'com.mysql.cj.jdbc.Driver', '数据库驱动'),
+('dmp-fss','default','master','DMP',1,'spring.datasource.url', 'jdbc:mysql://${persagy.mysql.host}:${persagy.mysql.port}/${persagy.mysql.database}?useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai', null),
+('dmp-fss','default','master','DMP',1,'spring.datasource.username', '${persagy.mysql.username}', '用户'),
+('dmp-fss','default','master','DMP',1,'spring.datasource.password', '${persagy.mysql.password}', '密码'),
+('dmp-fss','default','master','DMP',1,'spring.datasource.max-active', '${persagy.mysql.maxActive}', '连接池中最大的活跃连接数'),
+('dmp-fss','default','master','DMP',1,'spring.datasource.max-idle', '20', '连接池最大的空闲连接数量'),
+('dmp-fss','default','master','DMP',1,'spring.datasource.min-idle', '10', '连接池最小的空闲连接数量'),
+
+('dmp-fss','dev','master','DMP',1,'server.port', '8080', '服务端口号'),
+
+('dmp-fss','dev','master','DMP',1,'eureka.client.service-url.defaultZone','http://frame:123456@localhost:9931/eureka/','注册中心地址'),
+('dmp-fss','dev','master','DMP',1,'eureka.instance.ip-address','localhost','人工设置IP'),
+
+('dmp-fss','dev','master','DMP',1,'persagy.mysql.host', 'localhost', null),
+('dmp-fss','dev','master','DMP',1,'persagy.mysql.port', '3306', null),
+('dmp-fss','dev','master','DMP',1,'persagy.mysql.database', 'dmp_fss', null),
+('dmp-fss','dev','master','DMP',1,'persagy.mysql.username', 'pbsage', null),
+('dmp-fss','dev','master','DMP',1,'persagy.mysql.password', '123456', null),
+('dmp-fss','dev','master','DMP',1,'persagy.mysql.initialSize', '10', null),
+('dmp-fss','dev','master','DMP',1,'persagy.mysql.maxActive', '100', null),
+
+('dmp-fss','dev','master','DMP',1,'persagy.fss.ioc.access-key', 'dzQ0L4VF', 'ioc访问key'),
+('dmp-fss','dev','master','DMP',1,'persagy.fss.ioc.secret-key', '820B522EE587883A9F4EDDA6F250D74D', 'ioc密码key'),
+('dmp-fss','dev','master','DMP',1,'persagy.fss.ioc.bucket-name', 'labsl-core-public-bucket', 'ioc存储名'),
+('dmp-fss','dev','master','DMP',1,'persagy.fss.ioc.system-url', 'https://cos-sk-st1.uat.cmft.com:9002', 'ioc地址'),
+('dmp-fss','dev','master','DMP',1,'persagy.fss.ioc.user-id', 'cmsk', '访问用户名')
+

+ 72 - 0
dmp-fss-ioc/pom.xml

@@ -0,0 +1,72 @@
+<?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">
+    <parent>
+        <groupId>com.persagy</groupId>
+        <artifactId>dmp</artifactId>
+        <version>4.0.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>dmp-fss-ioc</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>com.persagy</groupId>
+            <artifactId>dmp-fss</artifactId>
+            <version>4.0.0</version>
+        </dependency>
+
+        <!-- httpclient -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient-cache</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient-win</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpmime</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <finalName>dmp-fss-ioc</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <fork>true</fork>
+                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 15 - 0
dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/IOCApp.java

@@ -0,0 +1,15 @@
+package com.persagy.dmp.fss;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@EnableTransactionManagement
+@SpringBootApplication
+@EnableDiscoveryClient
+public class IOCApp {
+    public static void main(String[] args) {
+        SpringApplication.run(IOCApp.class, args);
+    }
+}

+ 14 - 0
dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/config/IOCConfig.java

@@ -0,0 +1,14 @@
+package com.persagy.dmp.fss.ioc.config;
+
+import com.persagy.dmp.fss.ioc.config.properties.IOCProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class IOCConfig {
+
+    @Bean
+    public IOCProperties getIOCProperties(){
+        return new IOCProperties();
+    }
+}

+ 32 - 0
dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/config/properties/IOCProperties.java

@@ -0,0 +1,32 @@
+package com.persagy.dmp.fss.ioc.config.properties;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@Getter
+@Setter
+@ConfigurationProperties(prefix="persagy.fss.ioc")
+public class IOCProperties {
+
+    private String accessKey;
+
+    private String secretKey;
+
+    private String bucketName;
+
+    private String systemUrl;
+
+    private String userId;
+
+    private String tokenUrl;
+
+    private String uploadUrl;
+
+    private String downloadUrl;
+
+    private String removeUrl;
+
+    private String deleteTokenUrl;
+
+}

+ 169 - 0
dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/service/IOCFileService.java

@@ -0,0 +1,169 @@
+package com.persagy.dmp.fss.ioc.service;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.fss.common.service.BaseFileService;
+import com.persagy.dmp.fss.common.service.FileService;
+import com.persagy.dmp.fss.file.entity.FileResource;
+import com.persagy.dmp.fss.ioc.config.properties.IOCProperties;
+import com.persagy.dmp.fss.ioc.tool.HttpTools;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@Service
+public class IOCFileService extends BaseFileService implements FileService {
+
+    @Autowired
+    private IOCProperties iocProperties;
+
+    /**
+     * 存储 显示调用父类使事务生效
+     * @param fileName
+     * @param appId
+     * @param userId
+     * @param groupCode
+     * @param projectId
+     * @param file
+     * @return
+     * @throws Exception
+     */
+    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=Exception.class)
+    @Override
+    public String upload(String fileName, String appId, String userId, String groupCode, String projectId, MultipartFile file) throws Exception {
+        return super.upload(fileName, appId, userId, groupCode, projectId, file);
+    }
+
+    /**
+     * 存储实现
+     * @param fileName
+     * @param appId
+     * @param groupCode
+     * @param projectId
+     * @param file
+     * @return
+     * @throws Exception
+     */
+    @Override
+    protected ObjectNode store(String fileName, String appId, String groupCode, String projectId, MultipartFile file) throws Exception {
+        // 获取Token
+        Map<String,String> map = new LinkedHashMap<>();
+        map.put("accessKey", iocProperties.getAccessKey());
+        map.put("secretKey", iocProperties.getSecretKey());
+        map.put("bucketName", iocProperties.getBucketName());
+        map.put("systemUrl", iocProperties.getSystemUrl());
+        String json = objectMapper.writeValueAsString(map);
+
+        String tokenUrl = iocProperties.getSystemUrl() + iocProperties.getTokenUrl();
+        String result = HttpTools.postJson(tokenUrl,json);
+
+        Map resultMap = objectMapper.readValue(result, Map.class);
+        String code = (String) resultMap.get("code");
+        if(!"Y".equals(code)){
+            throw new Exception(result);
+        }
+
+        // 上传文件
+        String authorization = (String) resultMap.get("body");
+        String uploadUrl = iocProperties.getSystemUrl() + iocProperties.getUploadUrl();
+        String upload = HttpTools.uploadFile(file.getBytes(), fileName, iocProperties.getUserId(), authorization, uploadUrl);
+        resultMap = objectMapper.readValue(upload, Map.class);
+        code = (String) resultMap.get("code");
+        if(!"Y".equals(code)){
+            throw new Exception(upload);
+        }
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        objectNode.putPOJO("ioc", resultMap);
+
+        return objectNode;
+    }
+
+    /**
+     * 将存储转换为二进制数组
+     * @param fileResource
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public byte[] download(FileResource fileResource) throws Exception {
+        ObjectNode extension = fileResource.getExtension();
+        JsonNode body = extension.get("ioc").get("body");
+        String bucketName = body.get("bucketName").asText();
+        String resourceId = body.get("resourceId").asText();
+        String resourceName = body.get("resourceName").asText();
+
+        StringBuffer downloadUrl = new StringBuffer(iocProperties.getSystemUrl());
+        downloadUrl.append(iocProperties.getDownloadUrl());
+        downloadUrl.append("/");
+        downloadUrl.append(bucketName);
+        downloadUrl.append("/");
+        downloadUrl.append(resourceId);
+        downloadUrl.append("/");
+        downloadUrl.append(resourceName);
+
+        byte[] file = HttpTools.downloadFile(downloadUrl.toString());
+        return file;
+    }
+
+    /**
+     * 删除存储 显示调用父类使事务生效
+     * @param resourceId
+     * @throws Exception
+     */
+    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=Exception.class)
+    @Override
+    public void delete(String resourceId) throws Exception {
+        super.delete(resourceId);
+    }
+
+    /**
+     * 清除实现
+     * @param fileResource
+     * @throws Exception
+     */
+    @Override
+    protected void clear(FileResource fileResource) throws Exception {
+        Map<String,String> map = new LinkedHashMap<>();
+        map.put("accessKey", iocProperties.getAccessKey());
+        map.put("secretKey", iocProperties.getSecretKey());
+        map.put("bucketName", iocProperties.getBucketName());
+
+        String json = objectMapper.writeValueAsString(map);
+
+        String tokenUrl = iocProperties.getSystemUrl() + iocProperties.getDeleteTokenUrl();
+        String result = HttpTools.postJson(tokenUrl,json);
+
+        Map resultMap = objectMapper.readValue(result, Map.class);
+        String code = (String) resultMap.get("code");
+        if(!"Y".equals(code)){
+            throw new Exception(result);
+        }
+
+        // 上传文件
+        String authorization = (String) resultMap.get("body");
+        JsonNode body = fileResource.getExtension().get(this.getType()).get("body");
+        String resourceId = body.get("resourceId").asText();
+
+        String deleteUrl = iocProperties.getSystemUrl() + iocProperties.getRemoveUrl() + "/" + resourceId;
+        String delete = HttpTools.delete(deleteUrl, authorization);
+        resultMap = objectMapper.readValue(delete, Map.class);
+        code = (String) resultMap.get("code");
+        if(!"Y".equals(code)){
+            throw new Exception(delete);
+        }
+    }
+
+    /**
+     * 文件存储类型
+     * @return
+     */
+    @Override
+    protected String getType() {
+        return "ioc";
+    }
+}

+ 161 - 0
dmp-fss-ioc/src/main/java/com/persagy/dmp/fss/ioc/tool/HttpTools.java

@@ -0,0 +1,161 @@
+package com.persagy.dmp.fss.ioc.tool;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.StringBody;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+public class HttpTools {
+
+    public static String postJson(String url,String json) throws Exception{
+        String result = null;
+
+        CloseableHttpResponse response = null;
+        HttpEntity entity = null;
+        try {
+            CloseableHttpClient httpClient = HttpClients.createDefault();
+
+            HttpPost httpPost = new HttpPost(url);
+            httpPost.addHeader("Content-type","application/json; charset=utf-8");
+            httpPost.setHeader("Accept", "application/json");
+            httpPost.setEntity(new StringEntity(json, Charset.forName("UTF-8")));
+
+            response = httpClient.execute(httpPost);
+
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode != 200 && statusCode != 201) {
+                httpPost.abort();
+                throw new RuntimeException("HttpClient,error status code :" + statusCode);
+            }
+
+            entity = response.getEntity();
+
+
+            if (entity != null){
+                result = EntityUtils.toString(entity, "utf-8");
+            }
+        } finally {
+            if(entity!=null){
+                EntityUtils.consume(entity);
+            }
+            if(response!=null){
+                response.close();
+            }
+        }
+
+
+        return result;
+    }
+
+    public static String uploadFile(byte[] body, String filename, String userId, String authorization, String url) throws Exception {
+        String result = null;
+
+        CloseableHttpResponse response = null;
+        HttpEntity entity = null;
+        try {
+            CloseableHttpClient httpClient = HttpClients.createDefault();
+            MultipartEntityBuilder meb = MultipartEntityBuilder.create();
+            meb.addBinaryBody("file", body, ContentType.DEFAULT_BINARY, filename);
+            meb.addPart("userId",new StringBody(userId,ContentType.create("text/plain", Charset.forName("UTF-8"))));
+            HttpEntity reqEntity = meb.build();
+            HttpPost httpPost = new HttpPost(url);
+            httpPost.setEntity(reqEntity);
+            httpPost.addHeader("Authorization", authorization);
+            response = httpClient.execute(httpPost);
+            entity = response.getEntity();
+
+            if (entity != null){
+                result = EntityUtils.toString(entity, "utf-8");
+            }
+        } finally {
+            if(entity!=null){
+                EntityUtils.consume(entity);
+            }
+            if(response!=null){
+                response.close();
+            }
+        }
+
+
+        return result;
+    }
+
+    public static byte[] downloadFile(String url) throws Exception {
+        byte[] content = null;
+        CloseableHttpResponse response = null;
+        HttpEntity entity = null;
+        try {
+            CloseableHttpClient client = HttpClients.createDefault();
+            HttpGet httpget = new HttpGet(url);
+            response = client.execute(httpget);
+            entity = response.getEntity();
+            InputStream inputStream = entity.getContent();
+            content = readInputStream(inputStream);
+        } finally {
+            if(entity!=null){
+                EntityUtils.consume(entity);
+            }
+            if(response!=null){
+                response.close();
+            }
+        }
+        return content;
+    }
+
+    public static byte[] readInputStream(InputStream inputStream) throws Exception {
+        ByteArrayOutputStream bos = null;
+        try {
+            byte[] buffer = new byte[1024];
+            int len = 0;
+            bos = new ByteArrayOutputStream();
+            while((len = inputStream.read(buffer)) != -1) {
+                bos.write(buffer, 0, len);
+            }
+        } finally {
+            if(bos!=null){
+                bos.flush();
+                bos.close();
+            }
+        }
+        return bos.toByteArray();
+    }
+
+    public static String delete(String url, String authorization) throws Exception {
+        String result = null;
+
+        CloseableHttpResponse response = null;
+        HttpEntity entity = null;
+        try {
+            CloseableHttpClient httpClient = HttpClients.createDefault();
+            HttpPost httpPost = new HttpPost(url);
+            httpPost.addHeader("Authorization", authorization);
+            response = httpClient.execute(httpPost);
+            entity = response.getEntity();
+
+            if (entity != null){
+                result = EntityUtils.toString(entity, "utf-8");
+            }
+        } finally {
+            if(entity!=null){
+                EntityUtils.consume(entity);
+            }
+            if(response!=null){
+                response.close();
+            }
+        }
+
+
+        return result;
+    }
+}

+ 19 - 0
dmp-fss-ioc/src/main/resources/application.yml

@@ -0,0 +1,19 @@
+# 应用默认上下文地址
+server:
+  servlet:
+    context-path: /file-service
+
+# 应用默认名称
+spring:
+  application:
+    name: dmp-fss
+
+# fss-ioc 默认配置
+persagy:
+  fss:
+    ioc:
+      token-url: /cos-upload/v2/uploadToken #获取token地址
+      upload-url: /cos-upload/v2/uploadFile #上传文件地址
+      download-url: /cos-download/v2/downloadFile #下载文件地址
+      remove-url: /cos-upload/v2/drbri #删除文件地址
+      delete-token-url: /cos-upload/v2/deleteToken #获取删除token地址

+ 60 - 0
dmp-fss-ioc/src/main/resources/bootstrap.yml

@@ -0,0 +1,60 @@
+spring:
+  cloud:
+    config:
+      profile: dev
+      label: master
+      uri: http://localhost:5001
+
+#server:
+#  port: 6001
+
+#  jackson:
+#    time-zone: Asia/Shanghai
+#
+#  jpa:
+#    show-sql: false
+#    hibernate:
+#      ddl-auto: none
+#
+#  datasource:
+#    type: com.alibaba.druid.pool.DruidDataSource
+#    driver-class-name: com.mysql.cj.jdbc.Driver
+#    url: jdbc:mysql://${persagy.mysql.host}:${persagy.mysql.port}/${persagy.mysql.database}?useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
+#    username: ${persagy.mysql.username}
+#    password: ${persagy.mysql.password}
+#    max-active: ${persagy.mysql.maxActive}
+#    max-idle: 20
+#    min-idle: 10
+
+#eureka:
+#  client:
+#    register-with-eureka: true #注册服务
+#    fetch-registry: true #检索服务
+#    service-url:
+#      defaultZone: http://localhost:7000/eureka #连接eureka服务
+#  instance:
+#    prefer-ip-address: true #显示IP
+#    ip-address: 192.168.0.63 #人工设置IP
+#    instance-id: ${spring.application.name} #eureka中状态显示名称
+
+#persagy:
+#  mysql:
+#    host: localhost
+#    port: 3306
+#    database: test
+#    username: pbsage
+#    password: 123456
+#    initialSize: 10
+#    maxActive: 100
+#  fss:
+#    ioc:
+#      access-key: dzQ0L4VF # ioc访问key
+#      secret-key: 820B522EE587883A9F4EDDA6F250D74D #ioc密码key
+#      bucket-name: labsl-core-public-bucket #ioc存储名
+#      system-url: https://cos-sk-st1.uat.cmft.com:9002 #ioc地址
+#      user-id: cmsk #访问用户名
+#      token-url: /cos-upload/v2/uploadToken #获取token地址
+#      upload-url: /cos-upload/v2/uploadFile #上传文件地址
+#      download-url: /cos-download/v2/downloadFile #下载文件地址
+#      remove-url: /cos-upload/v2/drbri #删除文件地址
+#      delete-token-url: /cos-upload/v2/deleteToken #获取删除token地址

+ 114 - 0
dmp-fss/pom.xml

@@ -0,0 +1,114 @@
+<?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">
+    <parent>
+        <groupId>com.persagy</groupId>
+        <artifactId>dmp</artifactId>
+        <version>4.0.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>dmp-fss</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <!-- 注册中心 -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+        </dependency>
+
+        <!-- 配置中心 -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-config</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <dependency>
+            <groupId>com.persagy</groupId>
+            <artifactId>dmp-common</artifactId>
+            <version>4.0.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>1.1.21</version>
+        </dependency>
+        <dependency>
+            <groupId>com.querydsl</groupId>
+            <artifactId>querydsl-apt</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.querydsl</groupId>
+            <artifactId>querydsl-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.vladmihalcea</groupId>
+            <artifactId>hibernate-types-52</artifactId>
+            <version>2.9.13</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <finalName>dmp-fss</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <fork>true</fork>
+                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>com.mysema.maven</groupId>
+                <artifactId>apt-maven-plugin</artifactId>
+                <version>1.1.3</version>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>process</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>target/generated-sources</outputDirectory>
+                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 45 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/FSSApp.java

@@ -0,0 +1,45 @@
+package com.persagy.dmp.fss;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+@SpringBootApplication
+@EnableDiscoveryClient
+public class FSSApp {
+
+    public static void main(String[] args) {
+        SpringApplication.run(FSSApp.class, args);
+    }
+
+    public static String getExceptionStackTrace(Exception e) {
+        String result;
+        StringWriter sw = null;
+        PrintWriter pw = null;
+        try {
+            sw = new StringWriter();
+            pw = new PrintWriter(sw);
+            e.printStackTrace(pw);
+            pw.flush();
+            sw.flush();
+            result = sw.toString();
+        } catch (Exception ex) {
+            result = "bad getErrorInfoFromException";
+        } finally {
+            if (pw != null) {
+                pw.close();
+            }
+            if (sw != null) {
+                try {
+                    sw.close();
+                } catch (Exception ei) {
+                    // TODO Auto-generated catch block
+                }
+            }
+        }
+        return result;
+    }
+}

+ 23 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/config/AuthorizationConfig.java

@@ -0,0 +1,23 @@
+package com.persagy.dmp.fss.common.config;
+
+import com.persagy.dmp.fss.common.interceptor.AuthorizationInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class AuthorizationConfig implements WebMvcConfigurer {
+
+    @Bean
+    public AuthorizationInterceptor authorizationInterceptor(){
+        return new AuthorizationInterceptor();
+    }
+
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        InterceptorRegistration registration = registry.addInterceptor(new AuthorizationInterceptor());
+        registration.addPathPatterns("/file/**");
+    }
+}

+ 41 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/config/DMPConfig.java

@@ -0,0 +1,41 @@
+package com.persagy.dmp.fss.common.config;
+
+import com.persagy.common.criteria.CriteriaUtils;
+import com.persagy.common.criteria.JpaUtils;
+import com.persagy.dmp.common.SpringUtils;
+import com.persagy.dmp.common.http.HttpUtils;
+import com.querydsl.jpa.impl.JPAQueryFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.persistence.EntityManager;
+
+@Configuration
+public class DMPConfig {
+
+    @Bean
+    public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
+        return new JPAQueryFactory(entityManager);
+    }
+
+    @Bean
+    public CriteriaUtils criteriaUtils(@Autowired JPAQueryFactory jpaQueryFactory) {
+        return new CriteriaUtils(jpaQueryFactory);
+    }
+
+    @Bean
+    public JpaUtils jpaUtils(@Autowired EntityManager entityManager) {
+        return new JpaUtils(entityManager);
+    }
+
+    @Bean
+    public HttpUtils httpUtils() {
+        return new HttpUtils();
+    }
+
+    @Bean
+    public SpringUtils springUtils() {
+        return new SpringUtils();
+    }
+}

+ 87 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/controller/FileController.java

@@ -0,0 +1,87 @@
+package com.persagy.dmp.fss.common.controller;
+
+import com.persagy.common.web.BaseResponse;
+import com.persagy.common.web.MapResponse;
+import com.persagy.dmp.common.SpringUtils;
+import com.persagy.dmp.fss.FSSApp;
+import com.persagy.dmp.fss.common.service.FileService;
+import com.persagy.dmp.fss.common.service.TokenService;
+import com.persagy.dmp.fss.file.entity.FileResource;
+import com.persagy.dmp.fss.file.service.FileResourceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.net.URLEncoder;
+
+@RestController
+@RequestMapping("/file")
+public class FileController {
+
+    @Autowired
+    private TokenService tokenService;
+
+    @RequestMapping(value = "/upload", consumes = {"multipart/form-data"})
+    public MapResponse upload(@RequestParam(value = "fileName") String fileName,
+                              @RequestParam(value = "appId") String appId,
+                              @RequestParam(value = "userId") String userId,
+                              @RequestParam(value = "groupCode") String groupCode,
+                              @RequestParam(value = "projectId", required = false, defaultValue = "unique") String projectId,
+                              @RequestParam(value = "file") MultipartFile file
+                              ) throws Exception {
+
+        MapResponse mapResponse = new MapResponse();
+        FileService fileService = null;
+        try {
+            fileService = SpringUtils.getBean(FileService.class);
+            String id = fileService.upload(fileName, appId, userId, groupCode, projectId, file);
+            mapResponse.add("id", id);
+        } catch (Exception e) {
+            e.printStackTrace();
+            mapResponse.setResult(BaseResponse.FAIL);
+            mapResponse.setMessage(e.getMessage());
+            mapResponse.add("error", FSSApp.getExceptionStackTrace(e));
+        }
+
+        return mapResponse;
+    }
+
+    @RequestMapping(value = "/download")
+    public ResponseEntity<byte[]> download(@RequestParam(value = "appId") String appId, @RequestParam(value = "resourceId") String resourceId) throws Exception {
+
+        FileService fileService = SpringUtils.getBean(FileService.class);
+        FileResourceService fileResourceService = SpringUtils.getBean(FileResourceService.class);
+        FileResource fileResource = fileResourceService.getFileResource(resourceId);
+        byte[] body = fileService.download(fileResource);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+        headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileResource.getFileName(), "UTF-8"));
+
+        ResponseEntity<byte[]> responseEntity = new ResponseEntity<byte[]>(body, headers, HttpStatus.CREATED);
+        return responseEntity;
+    }
+
+    @RequestMapping(value = "/delete")
+    public MapResponse delete(@RequestParam(value = "appId") String appId, @RequestParam(value = "resourceId") String resouceId) throws Exception {
+        MapResponse mapResponse = new MapResponse();
+        FileService fileService = null;
+        try {
+            fileService = SpringUtils.getBean(FileService.class);
+            fileService.delete(resouceId);
+        } catch (Exception e) {
+            e.printStackTrace();
+            mapResponse.setResult(BaseResponse.FAIL);
+            mapResponse.setMessage(e.getMessage());
+            mapResponse.add("error", FSSApp.getExceptionStackTrace(e));
+        }
+
+        return mapResponse;
+    }
+}

+ 39 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/controller/TestController.java

@@ -0,0 +1,39 @@
+package com.persagy.dmp.fss.common.controller;
+
+import com.persagy.common.criteria.CriteriaUtils;
+import com.persagy.common.criteria.JpaUtils;
+import com.persagy.dmp.common.SpringUtils;
+import com.persagy.dmp.common.http.HttpUtils;
+import com.querydsl.jpa.impl.JPAQueryFactory;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/test")
+@ToString
+@Getter
+@Setter
+public class TestController {
+
+    @Autowired
+    private JPAQueryFactory jpaQueryFactory;
+    @Autowired
+    private CriteriaUtils criteriaUtils;
+    @Autowired
+    private JpaUtils jpaUtils;
+    @Autowired
+    private HttpUtils httpUtils;
+    @Autowired
+    private SpringUtils springUtils;
+
+    @RequestMapping("/config")
+    public String config() {
+        String result = this.toString();
+        return result;
+    }
+
+}

+ 56 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/controller/TokenController.java

@@ -0,0 +1,56 @@
+package com.persagy.dmp.fss.common.controller;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.common.web.BaseResponse;
+import com.persagy.common.web.MapResponse;
+import com.persagy.dmp.fss.FSSApp;
+import com.persagy.dmp.fss.common.service.TokenService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/token")
+public class TokenController {
+
+    @Autowired
+    private TokenService tokenService;
+
+    @RequestMapping(value = "/get", consumes = {"application/json"})
+    public MapResponse getToken(@RequestBody ObjectNode json) throws Exception {
+        String accessKey = json.get("accessKey").asText();
+        String secretKey = json.get("secretKey").asText();
+        String token = null;
+        MapResponse mapResponse = new MapResponse();
+        try {
+            token = tokenService.generateToken(accessKey, secretKey);
+            mapResponse.add("token", token);
+        } catch (Exception e) {
+            e.printStackTrace();
+            mapResponse.setResult(BaseResponse.FAIL);
+            mapResponse.setMessage(e.getMessage());
+            mapResponse.add("error", FSSApp.getExceptionStackTrace(e));
+        }
+
+        return mapResponse;
+    }
+
+    @RequestMapping(value = "/check", consumes = {"application/json"})
+    public MapResponse checkToken(@RequestBody ObjectNode json) throws Exception {
+        String appId = json.get("appId").asText();
+        String token = json.get("token").asText();
+        Boolean check = null;
+        MapResponse mapResponse = new MapResponse();
+        try {
+            tokenService.checkToken(appId, token);
+        } catch (Exception e) {
+            e.printStackTrace();
+            mapResponse.setResult(BaseResponse.FAIL);
+            mapResponse.setMessage(e.getMessage());
+            mapResponse.add("error", FSSApp.getExceptionStackTrace(e));
+        }
+
+        return mapResponse;
+    }
+}

+ 66 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/interceptor/AuthorizationInterceptor.java

@@ -0,0 +1,66 @@
+package com.persagy.dmp.fss.common.interceptor;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.common.web.BaseResponse;
+import com.persagy.common.web.MapResponse;
+import com.persagy.dmp.common.SpringUtils;
+import com.persagy.dmp.fss.FSSApp;
+import com.persagy.dmp.fss.common.service.TokenService;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+public class AuthorizationInterceptor implements HandlerInterceptor {
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("application/json; charset=utf-8");
+        String token = request.getHeader("token");
+        String appId = request.getParameter("appId");
+        try {
+            if(StringUtils.isBlank(token)){
+                token = request.getParameter("auth");
+                if(StringUtils.isBlank(token)){
+                    throw new Exception("参数错误!1");
+                }
+
+            }
+            if(StringUtils.isBlank(appId)){
+                throw new Exception("参数错误!2");
+            }
+            TokenService tokenService = SpringUtils.getBean(TokenService.class);
+            tokenService.checkToken(appId, token);
+        } catch (Exception e) {
+            e.printStackTrace();
+            MapResponse mapResponse = new MapResponse();
+            mapResponse.setResult(BaseResponse.FAIL);
+            mapResponse.setMessage(e.getMessage());
+            mapResponse.add("error", FSSApp.getExceptionStackTrace(e));
+            ObjectMapper objectMapper = SpringUtils.getBean(ObjectMapper.class);
+            returnJson(response, objectMapper.writeValueAsString(mapResponse));
+            return false;
+        }
+        return true;
+    }
+
+    private void returnJson(HttpServletResponse response, String json) throws Exception{
+        PrintWriter writer = null;
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("text/html; charset=utf-8");
+        try {
+            writer = response.getWriter();
+            writer.print(json);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (writer != null)
+                writer.close();
+        }
+    }
+
+}

+ 72 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/BaseFileService.java

@@ -0,0 +1,72 @@
+package com.persagy.dmp.fss.common.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.fss.file.entity.FileResource;
+import com.persagy.dmp.fss.file.repository.FileResourceRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Optional;
+import java.util.UUID;
+
+public abstract class BaseFileService implements FileService {
+
+    @Autowired
+    private FileResourceRepository fileResourceRepository;
+    @Autowired
+    protected ObjectMapper objectMapper;
+
+    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+    @Override
+    public String upload(String fileName, String appId, String userId, String groupCode, String projectId, MultipartFile file) throws Exception {
+        ObjectNode extension = store(fileName, appId, groupCode, projectId, file);
+        String resourceId = record(fileName, appId, userId,groupCode, projectId, extension);
+        return resourceId;
+    }
+
+    private String record(String fileName,String appId, String userId, String groupCode, String projectId, ObjectNode extension) throws Exception {
+        FileResource entity = new FileResource();
+        entity.setId(UUID.randomUUID().toString());
+        entity.setAppId(appId);
+        entity.setGroupCode(groupCode);
+        entity.setProjectId(projectId);
+        entity.setFileName(fileName);
+        if(extension==null){
+            extension = objectMapper.createObjectNode();
+        }
+        LocalDateTime localDateTime = LocalDateTime.now();
+        String format = localDateTime.format(formatter);
+        extension.putPOJO("date", format);
+        extension.putPOJO("type", this.getType());
+        entity.setExtension(extension);
+        fileResourceRepository.save(entity);
+        return entity.getId();
+    }
+
+    protected abstract ObjectNode store(String fileName, String appId, String groupCode, String projectId, MultipartFile file) throws Exception;
+
+    @Override
+    public void delete(String resourceId) throws Exception {
+        FileResource fileResource = deleteRecord(resourceId);
+        if(fileResource!=null) {
+            clear(fileResource);
+        }
+    }
+
+    private FileResource deleteRecord(String resourceId) throws Exception {
+        Optional<FileResource> of = fileResourceRepository.findById(resourceId);
+        if(!of.isPresent()){
+            return null;
+        }
+        fileResourceRepository.deleteById(resourceId);
+        return of.get();
+    }
+
+    protected abstract void clear(FileResource fileResource) throws Exception;
+
+    protected abstract String getType();
+}

+ 13 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/FileService.java

@@ -0,0 +1,13 @@
+package com.persagy.dmp.fss.common.service;
+
+import com.persagy.dmp.fss.file.entity.FileResource;
+import org.springframework.web.multipart.MultipartFile;
+
+public interface FileService {
+
+    public abstract String upload(String fileName, String appId, String userId, String groupCode, String projectId, MultipartFile file) throws Exception;
+
+    public abstract byte[] download(FileResource fileResource) throws Exception;
+
+    public abstract void delete(String resourceId) throws Exception;
+}

+ 8 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/TokenService.java

@@ -0,0 +1,8 @@
+package com.persagy.dmp.fss.common.service;
+
+public interface TokenService {
+
+    public abstract String generateToken(String accessKey, String secretKey) throws Exception;
+
+    public abstract void checkToken(String appId, String token) throws Exception;
+}

+ 87 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/impl/TokenServiceImpl.java

@@ -0,0 +1,87 @@
+package com.persagy.dmp.fss.common.service.impl;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.dmp.fss.common.service.TokenService;
+import com.persagy.dmp.fss.common.tool.AESTools;
+import com.persagy.dmp.fss.file.entity.FileAuthorization;
+import com.persagy.dmp.fss.file.entity.QFileAuthorization;
+import com.persagy.dmp.fss.file.repository.FileAuthorizationRepository;
+import com.querydsl.jpa.impl.JPAQuery;
+import com.querydsl.jpa.impl.JPAQueryFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+@Service
+public class TokenServiceImpl implements TokenService {
+
+    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+    @Autowired
+    private  ObjectMapper objectMapper;
+
+    @Autowired
+    private FileAuthorizationRepository fileAuthorizationRepository;
+
+    @Autowired
+    private JPAQueryFactory queryFactory;
+
+    @Override
+    public String generateToken(String accessKey, String secretKey) throws Exception {
+        QFileAuthorization q = QFileAuthorization.fileAuthorization;
+        JPAQuery<FileAuthorization> query = queryFactory.selectFrom(q).where(q.accessKey.eq(accessKey).and(q.secretKey.eq(secretKey)));
+        List<FileAuthorization> list = query.fetch();
+        if(list.size()==0){
+            throw new Exception("访问验证失败!0");
+        }
+
+        LocalDateTime localDateTime = LocalDateTime.now().plusMinutes(1);
+        String format = localDateTime.format(formatter);
+
+        Map tokenMap = new LinkedHashMap<>();
+        tokenMap.put("expireTime", format);
+        tokenMap.put("accessKey", accessKey);
+        tokenMap.put("secretKey", secretKey);
+
+        String plainText = objectMapper.writeValueAsString(tokenMap);
+        String token = AESTools.encrypt(plainText);
+        return token;
+    }
+
+    @Override
+    public void checkToken(String appId, String token) throws Exception {
+        String plainText = null;
+        try {
+            plainText = AESTools.decrypt(token);
+        } catch (Exception e) {
+            throw new Exception("访问验证失败!0", e);
+        }
+        Map tokenMap = objectMapper.readValue(plainText, Map.class);
+        String accessKey = (String) tokenMap.get("accessKey");
+        String secretKey = (String) tokenMap.get("secretKey");
+        String expireTime = (String) tokenMap.get("expireTime");
+
+        Optional<FileAuthorization> of = fileAuthorizationRepository.findById(appId);
+        if(!of.isPresent()){
+            throw new Exception("访问验证失败!1");
+        }
+
+        FileAuthorization fileAuthorization = of.get();
+        if(!fileAuthorization.getAccessKey().equals(accessKey) || !fileAuthorization.getSecretKey().equals(secretKey)){
+            throw new Exception("访问验证失败!2");
+        }
+
+        LocalDateTime localDateTime = LocalDateTime.parse(expireTime, formatter);
+        if(localDateTime.compareTo(LocalDateTime.now()) < 0 ){
+            throw new Exception("访问验证失败!3");
+        }
+
+    }
+
+}

+ 127 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/common/tool/AESTools.java

@@ -0,0 +1,127 @@
+package com.persagy.dmp.fss.common.tool;
+
+import org.apache.tomcat.util.codec.binary.Base64;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.SecureRandom;
+
+public class AESTools {
+
+    // AES secretKey length (must be 16 bytes)
+    public static final String secretKey = "=persagy-dmp-fss";
+
+    // 字符串编码
+    private static final String KEY_CHARSET = "UTF-8";
+
+    // 算法方式
+    private static final String KEY_ALGORITHM = "AES";
+
+    // 算法/模式/填充
+    private static final String CIPHER_ALGORITHM_CBC = "AES/CBC/PKCS5Padding";
+
+    // 私钥大小128/192/256(bits)位 即:16/24/32bytes,暂时使用128,如果扩大需要更换java/jre里面的jar包
+    private static final Integer PRIVATE_KEY_SIZE_BIT = 128;
+
+    private static final Integer PRIVATE_KEY_SIZE_BYTE = 16;
+
+    public static String encrypt(String plainText) {
+        return encrypt(secretKey, plainText);
+    }
+
+    public static String encrypt(String secretKey, String plainText) {
+        if (secretKey.length() != PRIVATE_KEY_SIZE_BYTE) {
+            throw new RuntimeException("AESUtil:Invalid AES secretKey length (must be 16 bytes)");
+        }
+
+        // 密文字符串
+        String cipherText = "";
+        try {
+            // 加密模式初始化参数
+            Cipher cipher = initParam(secretKey, Cipher.ENCRYPT_MODE);
+            // 获取加密内容的字节数组
+            byte[] bytePlainText = plainText.getBytes(KEY_CHARSET);
+            // 执行加密
+            byte[] byteCipherText = cipher.doFinal(bytePlainText);
+            cipherText = Base64.encodeBase64String(byteCipherText);
+        } catch (Exception e) {
+            throw new RuntimeException("AESUtil:encrypt fail!", e);
+        }
+        return cipherText;
+    }
+
+    public static String decrypt( String cipherText) {
+        return decrypt(secretKey, cipherText);
+    }
+
+    public static String decrypt(String secretKey, String cipherText) {
+
+        if (secretKey.length() != PRIVATE_KEY_SIZE_BYTE) {
+            throw new RuntimeException("AESUtil:Invalid AES secretKey length (must be 16 bytes)");
+        }
+
+        // 明文字符串
+        String plainText = "";
+        try {
+            Cipher cipher = initParam(secretKey, Cipher.DECRYPT_MODE);
+            // 将加密并编码后的内容解码成字节数组
+            byte[] byteCipherText = Base64.decodeBase64(cipherText);
+            // 解密
+            byte[] bytePlainText = cipher.doFinal(byteCipherText);
+            plainText = new String(bytePlainText, KEY_CHARSET);
+        } catch (Exception e) {
+            throw new RuntimeException("AESUtil:decrypt fail!", e);
+        }
+        return plainText;
+    }
+
+    public static Cipher initParam(String secretKey, int mode) {
+        try {
+            // 防止Linux下生成随机key
+            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
+            secureRandom.setSeed(secretKey.getBytes());
+            // 获取key生成器
+            KeyGenerator keygen = KeyGenerator.getInstance(KEY_ALGORITHM);
+            keygen.init(PRIVATE_KEY_SIZE_BIT, secureRandom);
+
+            // 获得原始对称密钥的字节数组
+            byte[] raw = secretKey.getBytes();
+
+            // 根据字节数组生成AES内部密钥
+            SecretKeySpec key = new SecretKeySpec(raw, KEY_ALGORITHM);
+            // 根据指定算法"AES/CBC/PKCS5Padding"实例化密码器
+            Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM_CBC);
+            IvParameterSpec iv = new IvParameterSpec(secretKey.getBytes());
+
+            // 初始化AES密码器
+            cipher.init(mode, key, iv);
+
+            return cipher;
+        } catch (Exception e) {
+            throw new RuntimeException("AESUtil:initParam fail!", e);
+        }
+    }
+
+    public static void main(String[] args) {
+
+        long s = System.currentTimeMillis();
+
+        String text = "AES加密测试";
+        String encryptMsg = encrypt(secretKey,  text);
+        System.out.println("密文为:" + encryptMsg);
+
+        long e = System.currentTimeMillis();
+
+        System.out.println(e-s);
+
+        String decryptMsg = decrypt(secretKey,  encryptMsg);
+        System.out.println("明文为:" + decryptMsg);
+
+        long d = System.currentTimeMillis();
+
+        System.out.println(d-e);
+    }
+
+}

+ 39 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/controller/FileAuthorizationController.java

@@ -0,0 +1,39 @@
+package com.persagy.dmp.fss.file.controller;
+
+import com.persagy.common.criteria.JacksonCriteria;
+import com.persagy.common.web.MapResponse;
+import com.persagy.common.web.PagedResponse;
+import com.persagy.dmp.fss.file.model.FileAuthorizationModel;
+import com.persagy.dmp.fss.file.service.FileAuthorizationService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+@RestController
+@RequestMapping("/file/authorization")
+public class FileAuthorizationController {
+	@Autowired
+	private FileAuthorizationService service;
+	
+	@PostMapping("/query")
+	public PagedResponse<FileAuthorizationModel> query(@RequestBody JacksonCriteria criteria) {
+		return service.query(criteria);
+	}
+	
+	@PostMapping("/create")
+	public MapResponse create(@RequestBody FileAuthorizationModel param){
+		return service.create(param);
+	}
+	
+	@PostMapping("/update")
+	public MapResponse update(@RequestBody FileAuthorizationModel param){
+		return service.update(param);
+	}
+	
+	@PostMapping("/delete")
+	public MapResponse delete(@RequestBody FileAuthorizationModel param){
+		return service.delete(param);
+	}
+	
+}

+ 39 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/controller/FileResourceController.java

@@ -0,0 +1,39 @@
+package com.persagy.dmp.fss.file.controller;
+
+import com.persagy.common.criteria.JacksonCriteria;
+import com.persagy.common.web.MapResponse;
+import com.persagy.common.web.PagedResponse;
+import com.persagy.dmp.fss.file.model.FileResourceModel;
+import com.persagy.dmp.fss.file.service.FileResourceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+@RestController
+@RequestMapping("/file/resource")
+public class FileResourceController {
+	@Autowired
+	private FileResourceService service;
+	
+	@PostMapping("/query")
+	public PagedResponse<FileResourceModel> query(@RequestBody JacksonCriteria criteria) {
+		return service.query(criteria);
+	}
+	
+	@PostMapping("/create")
+	public MapResponse create(@RequestBody FileResourceModel param){
+		return service.create(param);
+	}
+	
+	@PostMapping("/update")
+	public MapResponse update(@RequestBody FileResourceModel param){
+		return service.update(param);
+	}
+	
+	@PostMapping("/delete")
+	public MapResponse delete(@RequestBody FileResourceModel param){
+		return service.delete(param);
+	}
+	
+}

+ 42 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/entity/FileAuthorization.java

@@ -0,0 +1,42 @@
+package com.persagy.dmp.fss.file.entity;
+
+import com.persagy.dmp.fss.file.model.FileAuthorizationModel;
+import lombok.Getter;
+import lombok.Setter;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Setter
+@Getter
+@Entity
+@Table(name = "file_authorization")
+public class FileAuthorization {
+
+	@Id
+	@GeneratedValue(generator = "assignedId")
+	@GenericGenerator(name = "assignedId", strategy = "assigned")
+	private String appId;
+	private String accessKey;
+	private String secretKey;
+
+	public static FileAuthorization fromModel(FileAuthorizationModel model) {
+		FileAuthorization entity = new FileAuthorization();
+		entity.setAppId(model.getAppId());
+		entity.setAccessKey(model.getAccessKey());
+		entity.setSecretKey(model.getSecretKey());
+		return entity;
+	}
+
+	public FileAuthorizationModel toModel() {
+		FileAuthorizationModel model = new FileAuthorizationModel();
+		model.setAppId(this.appId);
+		model.setAccessKey(this.getAccessKey());
+		model.setSecretKey(this.getSecretKey());
+		return model;
+	}
+
+}

+ 57 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/entity/FileResource.java

@@ -0,0 +1,57 @@
+package com.persagy.dmp.fss.file.entity;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.fss.file.model.FileResourceModel;
+import com.vladmihalcea.hibernate.type.json.JsonStringType;
+import lombok.Getter;
+import lombok.Setter;
+import org.hibernate.annotations.GenericGenerator;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Setter
+@Getter
+@Entity
+@Table(name = "file_resource")
+@TypeDef(name = "json", typeClass = JsonStringType.class)
+public class FileResource {
+
+	@Id
+	@GeneratedValue(generator = "assignedId")
+	@GenericGenerator(name = "assignedId", strategy = "assigned")
+	private String id;
+	private String fileName;
+	private String appId;
+	private String groupCode;
+	private String projectId;
+	@Type(type = "json")
+	private ObjectNode extension;
+
+	public static FileResource fromModel(FileResourceModel model) {
+		FileResource entity = new FileResource();
+		entity.setId(model.getId());
+		entity.setFileName(model.getFileName());
+		entity.setAppId(model.getAppId());
+		entity.setGroupCode(model.getGroupCode());
+		entity.setProjectId(model.getProjectId());
+		entity.setExtension(model.getExtension());
+		return entity;
+	}
+
+	public FileResourceModel toModel() {
+		FileResourceModel model = new FileResourceModel();
+		model.setId(this.id);
+		model.setFileName(this.getFileName());
+		model.setAppId(this.getAppId());
+		model.setGroupCode(this.getGroupCode());
+		model.setProjectId(this.getProjectId());
+		model.setExtension(this.getExtension());
+		return model;
+	}
+
+}

+ 14 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/model/FileAuthorizationModel.java

@@ -0,0 +1,14 @@
+package com.persagy.dmp.fss.file.model;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Setter
+@Getter
+public class FileAuthorizationModel {
+
+	private String appId;
+	private String accessKey;
+	private String secretKey;
+
+}

+ 18 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/model/FileResourceModel.java

@@ -0,0 +1,18 @@
+package com.persagy.dmp.fss.file.model;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import lombok.Getter;
+import lombok.Setter;
+
+@Setter
+@Getter
+public class FileResourceModel {
+
+	private String id;
+	private String fileName;
+	private String appId;
+	private String groupCode;
+	private String projectId;
+	private ObjectNode extension;
+
+}

+ 9 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/repository/FileAuthorizationRepository.java

@@ -0,0 +1,9 @@
+package com.persagy.dmp.fss.file.repository;
+
+import com.persagy.dmp.fss.file.entity.FileAuthorization;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.querydsl.QuerydslPredicateExecutor;
+
+public interface FileAuthorizationRepository extends JpaRepository<FileAuthorization, String>, QuerydslPredicateExecutor<FileAuthorization>{
+}
+

+ 9 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/repository/FileResourceRepository.java

@@ -0,0 +1,9 @@
+package com.persagy.dmp.fss.file.repository;
+
+import com.persagy.dmp.fss.file.entity.FileResource;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.querydsl.QuerydslPredicateExecutor;
+
+public interface FileResourceRepository extends JpaRepository<FileResource, String>, QuerydslPredicateExecutor<FileResource>{
+}
+

+ 77 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/service/FileAuthorizationService.java

@@ -0,0 +1,77 @@
+package com.persagy.dmp.fss.file.service;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.common.criteria.CriteriaUtils;
+import com.persagy.common.criteria.JacksonCriteria;
+import com.persagy.common.web.MapResponse;
+import com.persagy.common.web.PagedResponse;
+import com.persagy.dmp.fss.file.entity.FileAuthorization;
+import com.persagy.dmp.fss.file.entity.QFileAuthorization;
+import com.persagy.dmp.fss.file.model.FileAuthorizationModel;
+import com.persagy.dmp.fss.file.repository.FileAuthorizationRepository;
+import com.querydsl.core.types.dsl.BooleanExpression;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.transaction.Transactional;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class FileAuthorizationService {
+
+	@Autowired
+	private FileAuthorizationRepository fileAuthorizationRepository;
+
+	@Autowired
+	private CriteriaUtils criteriaUtils;
+
+	private List<BooleanExpression> parse(ObjectNode criteria) {
+		// TODO
+		return null;
+	}
+
+	public PagedResponse<FileAuthorizationModel> query(JacksonCriteria criteria) {
+		PagedResponse<FileAuthorization> resp = criteriaUtils.query(QFileAuthorization.fileAuthorization, this::parse, criteria);
+		PagedResponse<FileAuthorizationModel> result = new PagedResponse<>();
+		result.setCount(resp.getCount());
+		List<FileAuthorization> dataList = resp.getData();
+		if (dataList != null && dataList.size() > 0) {
+			List<FileAuthorizationModel> collect = dataList.stream().map(entity -> {
+				FileAuthorizationModel model = entity.toModel();
+				return model;
+			}).collect(Collectors.toList());
+			result.setData(collect);
+		}
+		return result;
+	}
+
+	@Transactional
+	public MapResponse create(FileAuthorizationModel param) {
+		MapResponse response = new MapResponse();
+		// TODO
+		FileAuthorization entity = FileAuthorization.fromModel(param);
+		fileAuthorizationRepository.save(entity);
+		response.add("appId", entity.getAppId());
+		return response;
+	}
+
+	@Transactional
+	public MapResponse update(FileAuthorizationModel param) {
+		MapResponse response = new MapResponse();
+		// TODO
+		FileAuthorization entity = FileAuthorization.fromModel(param);
+		fileAuthorizationRepository.save(entity);
+		response.add("appId", entity.getAppId());
+		return response;
+	}
+
+	@Transactional
+	public MapResponse delete(FileAuthorizationModel param) {
+		MapResponse response = new MapResponse();
+		// TODO
+		fileAuthorizationRepository.deleteById(param.getAppId());
+		return response;
+	}
+}
+

+ 82 - 0
dmp-fss/src/main/java/com/persagy/dmp/fss/file/service/FileResourceService.java

@@ -0,0 +1,82 @@
+package com.persagy.dmp.fss.file.service;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.common.criteria.CriteriaUtils;
+import com.persagy.common.criteria.JacksonCriteria;
+import com.persagy.common.web.MapResponse;
+import com.persagy.common.web.PagedResponse;
+import com.persagy.dmp.fss.file.entity.FileResource;
+import com.persagy.dmp.fss.file.entity.QFileResource;
+import com.persagy.dmp.fss.file.model.FileResourceModel;
+import com.persagy.dmp.fss.file.repository.FileResourceRepository;
+import com.querydsl.core.types.dsl.BooleanExpression;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.transaction.Transactional;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class FileResourceService {
+
+	@Autowired
+	private FileResourceRepository fileResourceRepository;
+
+	@Autowired
+	private CriteriaUtils criteriaUtils;
+
+	private List<BooleanExpression> parse(ObjectNode criteria) {
+		// TODO
+		return null;
+	}
+
+	public PagedResponse<FileResourceModel> query(JacksonCriteria criteria) {
+		PagedResponse<FileResource> resp = criteriaUtils.query(QFileResource.fileResource, this::parse, criteria);
+		PagedResponse<FileResourceModel> result = new PagedResponse<>();
+		result.setCount(resp.getCount());
+		List<FileResource> dataList = resp.getData();
+		if (dataList != null && dataList.size() > 0) {
+			List<FileResourceModel> collect = dataList.stream().map(entity -> {
+				FileResourceModel model = entity.toModel();
+				return model;
+			}).collect(Collectors.toList());
+			result.setData(collect);
+		}
+		return result;
+	}
+
+	@Transactional
+	public MapResponse create(FileResourceModel param) {
+		MapResponse response = new MapResponse();
+		// TODO
+		FileResource entity = FileResource.fromModel(param);
+		fileResourceRepository.save(entity);
+		response.add("id", entity.getId());
+		return response;
+	}
+
+	@Transactional
+	public MapResponse update(FileResourceModel param) {
+		MapResponse response = new MapResponse();
+		// TODO
+		FileResource entity = FileResource.fromModel(param);
+		fileResourceRepository.save(entity);
+		response.add("id", entity.getId());
+		return response;
+	}
+
+	@Transactional
+	public MapResponse delete(FileResourceModel param) {
+		MapResponse response = new MapResponse();
+		// TODO
+		fileResourceRepository.deleteById(param.getId());
+		return response;
+	}
+
+	@Transactional
+	public FileResource getFileResource(String resourceId) {
+		return fileResourceRepository.getOne(resourceId);
+	}
+}
+

+ 54 - 0
dmp-fss/src/main/resources/bootstrap.yml

@@ -0,0 +1,54 @@
+server:
+  port: 6001
+  servlet:
+    context-path: /file-service
+
+spring:
+  application:
+    name: dmp-fss
+
+  cloud:
+    config:
+      profile: dev
+      label: dev
+      uri: http://localhost:5001
+
+  jackson:
+    time-zone: Asia/Shanghai
+    date-format: yyyy-MM-dd HH:mm:ss
+
+  jpa:
+    show-sql: false
+    hibernate:
+      ddl-auto: none
+
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://${persagy.mysql.host}:${persagy.mysql.port}/${persagy.mysql.database}?useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
+    username: ${persagy.mysql.username}
+    password: ${persagy.mysql.password}
+    max-active: ${persagy.mysql.maxActive}
+    max-idle: 20
+    min-idle: 10
+
+eureka:
+  client:
+    register-with-eureka: true #注册服务
+    fetch-registry: true #检索服务
+    service-url:
+      defaultZone: http://localhost:7000/eureka #连接eureka服务
+  instance:
+    prefer-ip-address: true #显示IP
+    ip-address: 192.168.0.63 #人工设置IP
+    instance-id: ${spring.application.name} #eureka中状态显示名称
+
+persagy:
+  mysql:
+    host: localhost
+    port: 3306
+    database: test
+    username: pbsage
+    password: 123456
+    initialSize: 10
+    maxActive: 100

+ 206 - 202
dmp-rwd/src/main/java/com/persagy/dmp/rwd/service/RelationInstanceService.java

@@ -27,208 +27,212 @@ import java.util.stream.Collectors;
 @Service
 public class RelationInstanceService extends BaseService {
 
-	@Autowired
-	private ObjectInstanceQueryService objectInstanceQueryService;
-
-	@Autowired
-	private CriteriaUtils criteriaUtils;
-
-	private List<BooleanExpression> parse(ObjectNode criteria) {
-		// TODO
-		return null;
-	}
-
-	public PagedResponse<RelationInstanceModel> query(JacksonCriteria criteria) {
-		PagedResponse<RelationInstanceModel> result = new PagedResponse<>();
-		super.checkParam(result, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
-		if (!result.success()) {
-			return result;
-		}
-		criteria.add(RwdConstants.OBJECT_GROUPCODE, DmpParameterStorage.getGroupCode());
-		criteria.add(RwdConstants.OBJECT_PROJECTID, DmpParameterStorage.getProjectId());
-		PagedResponse<RelationInstance> resp = criteriaUtils.query(QRelationInstance.relationInstance, this::parse, criteria);
-		result.setCount(resp.getCount());
-		List<RelationInstance> dataList = resp.getData();
-		if (dataList != null && dataList.size() > 0) {
-			List<RelationInstanceModel> collect = dataList.stream().map(entity -> {
-				RelationInstanceModel model = entity.toModel();
-				return model;
-			}).collect(Collectors.toList());
-			result.setData(collect);
-		}
-		return result;
-	}
-
-	@Transactional
-	public MapResponse create(List<RelationInstanceModel> paramList) {
-		MapResponse response = new MapResponse();
-		super.checkParam(response, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
-		if (!response.success()) {
-			return response;
-		}
-		// TODO
-		if (paramList == null || paramList.size() == 0) {
-			return response;
-		}
-
-		String projectId = DmpParameterStorage.getProjectId();
-		String groupCode = DmpParameterStorage.getGroupCode();
-		if (projectId == null) {
-			response.setFail("[projectId] is required");
-			return response;
-		}
-
-		List<RelationInstance> list = new ArrayList<>(paramList.size());
-		for (RelationInstanceModel param : paramList) {
-			RelationInstance entity = RelationInstance.fromModel(param);
-			entity.setGroupCode(DmpParameterStorage.getGroupCode());
-			entity.setProjectId(projectId);
-			if (entity.getId() == null) {
-				entity.setId(UUID.randomUUID().toString().replace("-", ""));
-			}
-			if (param.getGraphCode() == null && param.getGraphId() == null) {
-				response.setFail("[graphId | graphCode] is required");
-				return response;
-			}
-
-			QGraphInstance qt = QGraphInstance.graphInstance;
-			// 优先级: graphId > graphCode
-			if (param.getGraphId() != null) {
-				GraphInstance gi = graphInstanceRepository.getOne(entity.getGraphId());
-				entity.setGraphCode(gi.getGraphCode());
-			} else if (param.getGraphCode() != null) {
-				Sort orders = Sort.by(new Sort.Order(Sort.Direction.ASC, "id"));
-				Iterable<GraphInstance> all = graphInstanceRepository.findAll(qt.groupCode.eq(groupCode).and(qt.projectId.eq(projectId).and(qt.graphCode.eq(entity.getGraphCode()))), orders);
-				GraphInstance next = all.iterator().next();
-				entity.setGraphId(next.getId());
-			}
-			entity.setStatus(1);
-			if (entity.getCreateApp() == null) {
-				entity.setCreateApp(DmpParameterStorage.getAppId());
-			}
-			// 判断是否已存在
-			QRelationInstance rt = QRelationInstance.relationInstance;
-			BooleanExpression exp = rt.groupCode.eq(entity.getGroupCode())
-					.and(rt.projectId.eq(entity.getProjectId()))
-					.and(rt.graphId.eq(entity.getGraphId()))
-					.and(rt.relCode.eq(entity.getRelCode()))
-					.and(rt.objFrom.eq(entity.getObjFrom()))
-					.and(rt.objTo.eq(entity.getObjTo()));
-			if (entity.getRelValue() != null) {
-				exp = exp.and(rt.relValue.eq(entity.getRelValue()));
-			} else {
-				exp = exp.and(rt.relValue.isNull());
-			}
-
-			long count = relationInstanceRepository.count(exp);
-			if (count == 0) {
-				// 数据不存在, 新增, 已存在时忽略
-				list.add(entity);
-			}
-		}
-		if (list.size() > 0) {
-			relationInstanceRepository.saveAll(list);
-			String now = DateUtils.format(new Date());
-			for (RelationInstance relation : list) {
-				DmpMessage message = new DmpMessage(RwdConstants.MESSAGE_INSTANCE_RELATION_CREATE, null);
-				message.setGroupCode(DmpParameterStorage.getGroupCode());
-				message.setProjectId(DmpParameterStorage.getProjectId());
-				message.setAppId(DmpParameterStorage.getAppId());
-				message.setUserId(DmpParameterStorage.getUserId());
-				message.setSendTime(now);
-				message.add("graphId", relation.getGraphId());
-				message.add("graphCode", relation.getGraphCode());
-				message.add("relCode", relation.getRelCode());
-				message.add("relValue", relation.getRelValue());
-				message.add("objFrom", relation.getObjFrom());
-				message.add("objTo", relation.getObjTo());
-				response.add(message);
-			}
-		}
-		return response;
-	}
-
-	@Transactional
-	public MapResponse delete(JacksonCriteria criteria) {
-		MapResponse response = new MapResponse();
-		super.checkParam(response, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
-		if (!response.success()) {
-			return response;
-		}
-		criteria.add(RwdConstants.OBJECT_GROUPCODE, DmpParameterStorage.getGroupCode());
-		criteria.add(RwdConstants.OBJECT_PROJECTID, DmpParameterStorage.getProjectId());
-		criteria.setWithoutCount(true);
-		QRelationInstance qt = QRelationInstance.relationInstance;
-		PagedResponse<RelationInstance> resp = criteriaUtils.query(qt, this::parse, criteria);
-		List<RelationInstance> data = resp.getData();
-		if (data != null && data.size() > 0) {
-			int cnt = 0;
-			for (RelationInstance datum : data) {
-				long execute = jpaQueryFactory.delete(qt).where(qt.groupCode.eq(DmpParameterStorage.getGroupCode()), qt.projectId.eq(DmpParameterStorage.getProjectId()), qt.id.eq(datum.getId())).execute();
-				cnt += execute;
-			}
-			response.add("deleteCount", cnt);
-
-			String now = DateUtils.format(new Date());
-			for (RelationInstance relation : data) {
-				DmpMessage message = new DmpMessage(RwdConstants.MESSAGE_INSTANCE_RELATION_DELETE, null);
-				message.setGroupCode(DmpParameterStorage.getGroupCode());
-				message.setProjectId(DmpParameterStorage.getProjectId());
-				message.setAppId(DmpParameterStorage.getAppId());
-				message.setUserId(DmpParameterStorage.getUserId());
-				message.setSendTime(now);
-				message.add("graphId", relation.getGraphId());
-				message.add("graphCode", relation.getGraphCode());
-				message.add("relCode", relation.getRelCode());
-				message.add("objFrom", relation.getObjFrom());
-				message.add("objTo", relation.getObjTo());
-				response.add(message);
-			}
-		} else {
-			response.add("deleteCount", 0);
-		}
-		return response;
-	}
-
-	public PagedResponse<ObjectNode> queryObject(JacksonCriteria criteria) {
-		PagedResponse response = new PagedResponse();
-		super.checkParam(response, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
-		if (!response.success()) {
-			return response;
-		}
-		PagedResponse<RelationInstanceModel> queryResp = query(criteria);
-		response.setCount(queryResp.getCount());
-		List<RelationInstanceModel> data = queryResp.getData();
-		if (data == null || data.size() == 0) {
-			return response;
-		}
-
-		List<String> objectIds = null;
-		if (criteria.getCriteria().has(RwdConstants.RELATION_OBJ_FROM)) {
-			objectIds = data.stream().map(RelationInstanceModel::getObjTo).collect(Collectors.toList());
-		} else {
-			objectIds = data.stream().map(RelationInstanceModel::getObjFrom).collect(Collectors.toList());
-		}
-		if (objectIds == null || objectIds.size() == 0) {
-			return response;
-		}
-
-		JacksonCriteria objectCriteria = JacksonCriteria.newInstance();
-		JsonNode objectNode = criteria.getCriteria().get("objectCriteria");
-		if (objectNode != null && objectNode.isObject()) {
-			objectCriteria.getCriteria().setAll((ObjectNode) objectNode);
-		}
-		objectCriteria.add("id", objectIds);
-
-		Set<String> withColumns = criteria.getWithColumns();
-		if (withColumns != null && withColumns.size() > 0) {
-			objectCriteria.setWithColumns(withColumns);
-		}
-		PagedResponse<ObjectNode> query = objectInstanceQueryService.query(objectCriteria);
-		response.setData(query.getData());
-		response.setCount(query.getCount());
-		return response;
-	}
+    @Autowired
+    private ObjectInstanceQueryService objectInstanceQueryService;
+
+    @Autowired
+    private CriteriaUtils criteriaUtils;
+
+    private List<BooleanExpression> parse(ObjectNode criteria) {
+        // TODO
+        return null;
+    }
+
+    public PagedResponse<RelationInstanceModel> query(JacksonCriteria criteria) {
+        PagedResponse<RelationInstanceModel> result = new PagedResponse<>();
+        super.checkParam(result, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
+        if (!result.success()) {
+            return result;
+        }
+        criteria.add(RwdConstants.OBJECT_GROUPCODE, DmpParameterStorage.getGroupCode());
+        criteria.add(RwdConstants.OBJECT_PROJECTID, DmpParameterStorage.getProjectId());
+        PagedResponse<RelationInstance> resp = criteriaUtils.query(QRelationInstance.relationInstance, this::parse, criteria);
+        result.setCount(resp.getCount());
+        List<RelationInstance> dataList = resp.getData();
+        if (dataList != null && dataList.size() > 0) {
+            List<RelationInstanceModel> collect = dataList.stream().map(entity -> {
+                RelationInstanceModel model = entity.toModel();
+                return model;
+            }).collect(Collectors.toList());
+            result.setData(collect);
+        }
+        return result;
+    }
+
+    @Transactional
+    public MapResponse create(List<RelationInstanceModel> paramList) {
+        MapResponse response = new MapResponse();
+        super.checkParam(response, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
+        if (!response.success()) {
+            return response;
+        }
+        // TODO
+        if (paramList == null || paramList.size() == 0) {
+            return response;
+        }
+
+        String projectId = DmpParameterStorage.getProjectId();
+        String groupCode = DmpParameterStorage.getGroupCode();
+        if (projectId == null) {
+            response.setFail("[projectId] is required");
+            return response;
+        }
+
+        List<RelationInstance> list = new ArrayList<>(paramList.size());
+        for (RelationInstanceModel param : paramList) {
+            RelationInstance entity = RelationInstance.fromModel(param);
+            entity.setGroupCode(DmpParameterStorage.getGroupCode());
+            entity.setProjectId(projectId);
+            if (entity.getId() == null) {
+                entity.setId(UUID.randomUUID().toString().replace("-", ""));
+            }
+            if (param.getGraphCode() == null && param.getGraphId() == null) {
+                response.setFail("[graphId | graphCode] is required");
+                return response;
+            }
+
+            QGraphInstance qt = QGraphInstance.graphInstance;
+            // 优先级: graphId > graphCode
+            if (param.getGraphId() != null) {
+                GraphInstance gi = graphInstanceRepository.getOne(entity.getGraphId());
+                entity.setGraphCode(gi.getGraphCode());
+            } else if (param.getGraphCode() != null) {
+                Sort orders = Sort.by(new Sort.Order(Sort.Direction.ASC, "id"));
+                Iterable<GraphInstance> all = graphInstanceRepository.findAll(qt.groupCode.eq(groupCode).and(qt.projectId.eq(projectId).and(qt.graphCode.eq(entity.getGraphCode()))), orders);
+                GraphInstance next = all.iterator().next();
+                entity.setGraphId(next.getId());
+            }
+            entity.setStatus(1);
+            if (entity.getCreateApp() == null) {
+                entity.setCreateApp(DmpParameterStorage.getAppId());
+            }
+            // 判断是否已存在
+            QRelationInstance rt = QRelationInstance.relationInstance;
+            BooleanExpression exp = rt.groupCode.eq(entity.getGroupCode())
+                    .and(rt.projectId.eq(entity.getProjectId()))
+                    .and(rt.graphId.eq(entity.getGraphId()))
+                    .and(rt.relCode.eq(entity.getRelCode()))
+                    .and(rt.objFrom.eq(entity.getObjFrom()))
+                    .and(rt.objTo.eq(entity.getObjTo()));
+            if (entity.getRelValue() != null) {
+                exp = exp.and(rt.relValue.eq(entity.getRelValue()));
+            } else {
+                exp = exp.and(rt.relValue.isNull());
+            }
+
+            long count = relationInstanceRepository.count(exp);
+            if (count == 0) {
+                // 数据不存在, 新增, 已存在时忽略
+                list.add(entity);
+            }
+        }
+        if (list.size() > 0) {
+            relationInstanceRepository.saveAll(list);
+            String now = DateUtils.format(new Date());
+            for (RelationInstance relation : list) {
+                DmpMessage message = new DmpMessage(RwdConstants.MESSAGE_INSTANCE_RELATION_CREATE, null);
+                message.setGroupCode(DmpParameterStorage.getGroupCode());
+                message.setProjectId(DmpParameterStorage.getProjectId());
+                message.setAppId(DmpParameterStorage.getAppId());
+                message.setUserId(DmpParameterStorage.getUserId());
+                message.setSendTime(now);
+                message.add("graphId", relation.getGraphId());
+                message.add("graphCode", relation.getGraphCode());
+                message.add("relCode", relation.getRelCode());
+                message.add("relValue", relation.getRelValue());
+                message.add("objFrom", relation.getObjFrom());
+                message.add("objTo", relation.getObjTo());
+                response.add(message);
+            }
+        }
+        return response;
+    }
+
+    @Transactional
+    public MapResponse delete(JacksonCriteria criteria) {
+        MapResponse response = new MapResponse();
+        super.checkParam(response, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
+        if (!response.success()) {
+            return response;
+        }
+        criteria.add(RwdConstants.OBJECT_GROUPCODE, DmpParameterStorage.getGroupCode());
+        criteria.add(RwdConstants.OBJECT_PROJECTID, DmpParameterStorage.getProjectId());
+        criteria.setWithoutCount(true);
+        QRelationInstance qt = QRelationInstance.relationInstance;
+        PagedResponse<RelationInstance> resp = criteriaUtils.query(qt, this::parse, criteria);
+        List<RelationInstance> data = resp.getData();
+        if (data != null && data.size() > 0) {
+            int cnt = 0;
+            for (RelationInstance datum : data) {
+                long execute = jpaQueryFactory.delete(qt).where(qt.groupCode.eq(DmpParameterStorage.getGroupCode()), qt.projectId.eq(DmpParameterStorage.getProjectId()), qt.id.eq(datum.getId())).execute();
+                cnt += execute;
+            }
+            response.add("deleteCount", cnt);
+
+            String now = DateUtils.format(new Date());
+            for (RelationInstance relation : data) {
+                DmpMessage message = new DmpMessage(RwdConstants.MESSAGE_INSTANCE_RELATION_DELETE, null);
+                message.setGroupCode(DmpParameterStorage.getGroupCode());
+                message.setProjectId(DmpParameterStorage.getProjectId());
+                message.setAppId(DmpParameterStorage.getAppId());
+                message.setUserId(DmpParameterStorage.getUserId());
+                message.setSendTime(now);
+                message.add("graphId", relation.getGraphId());
+                message.add("graphCode", relation.getGraphCode());
+                message.add("relCode", relation.getRelCode());
+                message.add("objFrom", relation.getObjFrom());
+                message.add("objTo", relation.getObjTo());
+                response.add(message);
+            }
+        } else {
+            response.add("deleteCount", 0);
+        }
+        return response;
+    }
+
+    public PagedResponse<ObjectNode> queryObject(JacksonCriteria criteria) {
+        PagedResponse response = new PagedResponse();
+        response.setCount(0L);
+        super.checkParam(response, RwdConstants.QUERY_GROUPCODE, RwdConstants.QUERY_PROJECTID);
+        if (!response.success()) {
+            return response;
+        }
+
+        JacksonCriteria objectCriteria = JacksonCriteria.newInstance();
+        JsonNode objectNode = criteria.getCriteria().get("objectCriteria");
+        if (objectNode != null && objectNode.isObject()) {
+            objectCriteria.getCriteria().setAll((ObjectNode) objectNode);
+        }
+
+        PagedResponse<RelationInstanceModel> queryResp = query(criteria);
+        List<RelationInstanceModel> data = queryResp.getData();
+        if (data == null || data.size() == 0) {
+            if (objectNode == null || !objectNode.isObject()) {
+                response.setCount(queryResp.getCount());
+                return response;
+            }
+        }
+
+        List<String> objectIds = null;
+        if (criteria.getCriteria().has(RwdConstants.RELATION_OBJ_FROM)) {
+            objectIds = data.stream().map(RelationInstanceModel::getObjTo).collect(Collectors.toList());
+        } else {
+            objectIds = data.stream().map(RelationInstanceModel::getObjFrom).collect(Collectors.toList());
+        }
+        if (objectIds == null || objectIds.size() == 0) {
+            return response;
+        }
+        objectCriteria.add("id", objectIds);
+
+        Set<String> withColumns = criteria.getWithColumns();
+        if (withColumns != null && withColumns.size() > 0) {
+            objectCriteria.setWithColumns(withColumns);
+        }
+        PagedResponse<ObjectNode> query = objectInstanceQueryService.query(objectCriteria);
+        response.setData(query.getData());
+        response.setCount(query.getCount());
+        return response;
+    }
 
 }
 

+ 2 - 0
pom.xml

@@ -20,6 +20,8 @@
         <module>dmp-alarm</module>
         <module>dmp-admin</module>
         <module>dmp-rwd-edit</module>
+        <module>dmp-fss</module>
+        <module>dmp-fss-ioc</module>
     </modules>
 
     <packaging>pom</packaging>