Browse Source

临时提交

airhead 8 years ago
parent
commit
e5d89a75ef

+ 0 - 2
hos-broker/src/main/java/com/yihu/hos/broker/HosBrokerApplication.java

@ -1,7 +1,6 @@
package com.yihu.hos.broker;
import com.yihu.hos.broker.services.camel.CamelStartBoot;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
@ -34,7 +33,6 @@ public class HosBrokerApplication extends SpringBootServletInitializer implement
    @Override
    public void run(String... strings) throws Exception {
        GridFSUtil.gridFsOperations = operations;
        executorService.execute(() -> {
            camelStartBoot.start();
        });

+ 4 - 1
hos-broker/src/main/resources/jndi.properties

@ -1 +1,4 @@
topic.logTopic=business.log.queue
connectionFactoryNames = queueConnectionFactory
# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.my-logback-queue = business.log.queue

+ 0 - 47
hos-broker/src/main/resources/log4j.properties

@ -1,47 +0,0 @@
## ------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements.  See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You 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.
## ------------------------------------------------------------------------
#
# The logging properties used for testing.
#
log4j.rootLogger=INFO, jms
# uncomment the following to enable camel debugging
#log4j.logger.org.apache.camel.component.http4=DEBUG
# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=com.yihu.hos.broker.common.log.PatternLayout
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
log4j.appender.jms=com.yihu.hos.broker.common.log.JMSAppender
log4j.appender.jms.InitialContextFactoryName=org.apache.activemq.jndi.ActiveMQInitialContextFactory
log4j.appender.jms.ProviderURL=tcp://172.19.103.67:61616
log4j.appender.jms.TopicBindingName=logTopic
log4j.appender.jms.TopicConnectionFactoryBindingName=ConnectionFactory
log4j.appender.jms.userName=admin
log4j.appender.jms.password=admin
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.layout=com.yihu.hos.broker.common.log.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%m%n
#log4j.appender.file.file=D:/log/camel-http4-test.log

+ 57 - 0
hos-dfs/src/main/java/com/yihu/com/hos/configuration/MongoConfig.java

@ -0,0 +1,57 @@
package com.yihu.com.hos.configuration;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static java.util.Collections.singletonList;
/**
 * @created Airhead 2016/7/27.
 */
@Configuration
public class MongoConfig {
    @Value("${spring.data.mongodb.host}")
    private String host;
    @Value("${spring.data.mongodb.port}")
    private int port;
    @Value("${spring.data.mongodb.username}")
    private String username;
    @Value("${spring.data.mongodb.password}")
    private String password;
    @Value("${spring.data.mongodb.authenticationDatabase}")
    private String authenticationDatabase;
    @Bean
    public MongoClient mongoClient() throws Exception {
        return new MongoClient(singletonList(new ServerAddress(host, port)),
                singletonList(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray())));
    }
    @Bean
    public Mongo mongo() throws Exception {
        return new MongoClient(singletonList(new ServerAddress(host, port)),
                singletonList(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray())));
    }
    public String getHost() {
        return host;
    }
    public int getPort() {
        return port;
    }
    public String getUsername() {
        return username;
    }
    public String getPassword() {
        return password;
    }
}

+ 24 - 0
hos-dfs/src/main/java/com/yihu/com/hos/configuration/ZbusConfiguration.java

@ -0,0 +1,24 @@
package com.yihu.com.hos.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
 * Created by l4qiang on 2017-04-10.
 */
@Configuration
public class ZbusConfiguration {
    @Value("${hos.zbus.port}")
    private Integer zbusPort;
    @Value("${hos.zbus.store}")
    private String zbusStore;
    public Integer getZbusPort() {
        return zbusPort;
    }
    public String getZbusStore() {
        return zbusStore;
    }
}

+ 73 - 0
hos-dfs/src/main/java/com/yihu/com/hos/controller/DFSController.java

@ -0,0 +1,73 @@
package com.yihu.com.hos.controller;
import com.yihu.com.hos.service.DFSService;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
/**
 * Created by l4qiang on 2017-04-10.
 */
public class DFSController {
    @Autowired
    private DFSService dfsService;
    /**
     *  //TODO 后 独立到对应的rest接口中
     * 上传文件
     * @param response
     * @param fileName
     * @return
     */
    @RequestMapping(value = "/upload/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Object upload(
            HttpServletResponse response, @PathVariable("fileName")  String fileName,
            @ApiParam(name = "pack", value = "文件", allowMultiple = true)
            @RequestPart() MultipartFile pack
    ) {
        try {
            return dfsService.uploadFile(pack.getInputStream(), fileName);
        } catch (Exception e) {
            return Result.error("上传文件出错!");
        }
    }
    /**
     *  //TODO 后 独立到对应的rest接口中
     * 文件下载
     * @return
     */
    @RequestMapping(value = "/down/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public Object down(HttpServletResponse response, @PathVariable("fileName")  String fileName) {
        try {
            OutputStream os = response.getOutputStream();
            return dfsService.dowFile(os, fileName);
        } catch (Exception e) {
            return Result.error("下载文件出错!");
        }
    }
    /**
     *  //TODO 后 独立到对应的rest接口中
     * 删除文件
     * @return
     */
    @RequestMapping(value = "/delFile/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Object delFile(HttpServletResponse response, @PathVariable("fileName")  String fileName) {
        try {
            return dfsService.delFile(fileName);
        } catch (Exception e) {
            return Result.error("下载文件失败!");
        }
    }
}

+ 68 - 0
hos-dfs/src/main/java/com/yihu/com/hos/service/DFSService.java

@ -0,0 +1,68 @@
package com.yihu.com.hos.service;
import com.yihu.com.hos.configuration.MongoConfig;
import com.yihu.hos.core.encrypt.DES;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.io.OutputStream;
/**
 * Created by l4qiang on 2017-04-10.
 */
@Service
public class DFSService {
    @Autowired
    private GridFsOperations operations;
    @Autowired
    private MongoConfig mongoConfig;
    public Result dowFile(OutputStream os, String fileName) {
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            boolean succ = GridFSUtil.readFile(mongoConfig.mongoClient().getDatabase("dfs"), os, fileName);
            if (succ) {
                return Result.success("读取文件成功");
            } else {
                return Result.success("读取文件失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("读取文件异常");
        }
    }
    public Result uploadFile(InputStream inputStream, String fileName) {
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            String saveFileName = GridFSUtil.uploadFile(inputStream, fileName, null);
            if (saveFileName != null) {
                return Result.success("上传文件成功");
            } else {
                return Result.error("上传文件失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("上传文件异常");
        }
    }
    public Result delFile(String fileName) {
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            boolean succ = GridFSUtil.deleteFile(fileName);
            if (succ) {
                return Result.success("删除文件成功");
            } else {
                return Result.success("删除文件失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除文件异常");
        }
    }
}

+ 1 - 1
hos-web-framework/src/main/java/com/yihu/hos/web/framework/util/GridFSUtil.java

@ -1,4 +1,4 @@
package com.yihu.hos.web.framework.util;
package com.yihu.com.hos.service;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.gridfs.GridFSBucket;

+ 0 - 1
hos-rest/src/main/java/com/yihu/hos/rest/services/crawler/CollectHelper.java

@ -12,7 +12,6 @@ import com.yihu.ehr.dbhelper.mongodb.MongodbHelper;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.file.FileUtil;
import com.yihu.hos.rest.models.crawler.patient.Patient;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.bson.Document;
import java.io.IOException;

+ 0 - 1
hos-rest/src/main/java/com/yihu/hos/rest/services/crawler/CrawlerService.java

@ -31,7 +31,6 @@ import com.yihu.hos.rest.services.standard.adapter.AdapterSchemeVersionService;
import com.yihu.hos.web.framework.constant.SqlConstants;
import com.yihu.hos.web.framework.model.ActionResult;
import com.yihu.hos.web.framework.model.DetailModelResult;
import com.yihu.hos.web.framework.util.GridFSUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;

+ 0 - 1
hos-rest/src/main/java/com/yihu/hos/rest/services/crawler/DatacollectService.java

@ -21,7 +21,6 @@ import com.yihu.hos.rest.services.standard.StdService;
import com.yihu.hos.web.framework.constant.DateConvert;
import com.yihu.hos.web.framework.constant.SqlConstants;
import com.yihu.hos.web.framework.model.ActionResult;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.bson.types.ObjectId;
import org.dom4j.Document;
import org.dom4j.Element;

+ 385 - 0
hos-rest/src/main/java/com/yihu/hos/rest/services/crawler/GridFSUtil.java

@ -0,0 +1,385 @@
package com.yihu.hos.rest.services.crawler;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.gridfs.GridFSBucket;
import com.mongodb.client.gridfs.GridFSBuckets;
import com.mongodb.client.gridfs.model.GridFSUploadOptions;
import com.mongodb.gridfs.GridFSDBFile;
import com.yihu.hos.core.file.FileUtil;
import eu.medsea.mimeutil.MimeUtil;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.gridfs.GridFsCriteria;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.stereotype.Component;
import java.io.*;
import java.sql.Blob;
import java.util.*;
/**
 * MongoDB GridFS 操作类
 *
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/7/21.
 */
@Component
public class GridFSUtil {
    public static final int defaultChunkSize = 1024 * 1024 * 4;
    public static GridFsOperations gridFsOperations;
    public static ObjectId uploadFile( Blob blob, String fileType, Map<String, Object> params) {
//        String fileName = UUID.randomUUID().toString() + "." + fileType;
        //自定义字段
        Document metaDocument = new Document();
        if (params != null && params.size() > 0) {
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                String key = entry.getKey();
                metaDocument.append(key, entry.getValue());
            }
        }
        // Create some custom options
        GridFSUploadOptions gridFSUploadOptions = new GridFSUploadOptions()
                .chunkSizeBytes(defaultChunkSize).metadata(metaDocument);
        try {
            com.mongodb.gridfs.GridFSFile gridFSFile = gridFsOperations.store(blob.getBinaryStream(), gridFSUploadOptions);
            if (gridFSFile != null) {
                return (ObjectId) gridFSFile.getId();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 上传文件至Mongodb by GridFS
     *
     * @param filePath        上传的文件路径
     * @param saveFileName   保存到mongo的文件名
     * @param params          自定义保存字段
     */
    public static String uploadFile(String filePath,String saveFileName, Map<String, Object> params) {
        //自定义字段
        Document metaDocument = new Document();
        if (params != null && params.size() > 0) {
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                String key = entry.getKey();
                metaDocument.append(key, entry.getValue());
            }
        }
        // Create some custom options
        FileInputStream fileInputStream = null;
        try {
            File readFile = new File(filePath);
            fileInputStream = new FileInputStream(readFile);
            gridFsOperations.delete(Query.query(GridFsCriteria.where("filename").is(saveFileName)));//删除原来的文件,保证唯一
            com.mongodb.gridfs.GridFSFile gridFSFile = gridFsOperations.store(fileInputStream,saveFileName,"",metaDocument);
            if (gridFSFile != null) {
                return saveFileName;
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    /**
     * 从 mongodb GridFS 下载文件
     *
     * @param dbName   数据库名
     * @param savePath 文件保存路径
     * @param objectId GridFS文件保存ObjectId
     * @return
     */
    public static String downFile(String dbName, String savePath, ObjectId objectId) {
        FileOutputStream fileOutputStream = null;
        try {
            GridFSDBFile gridFSDBFile = gridFsOperations.findOne(Query.query(GridFsCriteria.where("_id").is(objectId)));
            fileOutputStream = new FileOutputStream(savePath);
            gridFSDBFile.writeTo(fileOutputStream);
            return savePath;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    /**
     * 批量下载文件保存(根据 fs.files集合)
     *
     * @param dbName   数据库名
     * @param savePath 文件保存的路径
     * @param fsFiles  fs.files
     * @return 以“,”分割的文件名
     */
    public static Map<String, StringBuffer> downFileList(String dbName, String savePath, List<GridFSDBFile> fsFiles) {
        StringBuffer stringBuffer = new StringBuffer();
        Map<String, String> fileNames = new HashMap<>();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        if (fsFiles != null && fsFiles.size() > 0) {
            for (GridFSDBFile fsFile : fsFiles) {
                Object objectId = fsFile.getId();
                String fileType = fsFile.getFilename().substring(fsFile.getFilename().lastIndexOf("."));
                String newName = UUID.randomUUID().toString() + "." + fileType;
                GridFSDBFile gridFSDBFile = gridFsOperations.findOne(Query.query(GridFsCriteria.where("_id").is(objectId)));
                try {
                    gridFSDBFile.writeTo(out);
                    boolean success = FileUtil.writeFile(savePath + "/" + newName, out.toByteArray(), "utf-8");
                    if (!success) {
                        break;
                    }
                    String type = getMimeType(out.toByteArray());
                    fileNames.put(newName, type);
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                } finally {
                    if (out != null) {
                        try {
                            out.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            return groupDataMap(fileNames);
        } else {
            return null;
        }
    }
    /**
     * 删除 mongodb-GridFS文件
     *
     * @param dbName
     * @param objectId
     */
    public static void deleteFile(String dbName, ObjectId objectId) {
        gridFsOperations.delete(Query.query(GridFsCriteria.where("_id").is(objectId)));
    }
    /**
     * 查询fs.files 数据 in GridFS
     *
     * @param filters 查询条件
     * @return files集合
     */
    public static List<GridFSDBFile> findFiles( Map<String, Object> filters) {
        Query query = new Query();
        if (filters != null) {
            filters.forEach((key, value) -> query.addCriteria(GridFsCriteria.where(key).is(value)));
        }
        return gridFsOperations.find(query);
    }
    /**
     * 根据ObjectID集合查询GridFS 文件列表
     *
     * @param dbName 数据库名
     * @param ids    objectId集合
     * @return
     */
    public static List<GridFSDBFile> findFsFiles(String dbName, List<ObjectId> ids) {
        List<GridFSDBFile> list = new ArrayList<>();
        ids.forEach(objectId -> {
            GridFSDBFile gridFSDBFile = gridFsOperations.findOne(Query.query(GridFsCriteria.where("_id").is(objectId)));
            list.add(gridFSDBFile);
        });
        return list;
    }
    /*************************************** MineType 工具类 *********************************/
    /**
     * 获取文件Mine-Type
     *
     * @param file
     * @return
     */
    public static String getMimeType(File file) {
        MimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
        Collection<?> collection = MimeUtil.getMimeTypes(file);
        return collection.toString();
    }
    public static String getMimeType(byte[] bytes) {
        MimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
        Collection<?> collection = MimeUtil.getMimeTypes(bytes);
        return collection.toString();
    }
    /**
     * 非结构化档案--文件类型map生成
     *
     * @param map
     * @return
     */
    public static Map<String, StringBuffer> groupDataMap(Map<String, String> map) {
        Map<String, StringBuffer> result = new HashMap<String, StringBuffer>();
        Iterator<String> rs = map.keySet().iterator();
        while (rs.hasNext()) {
            String key = rs.next();
            String value = map.get(key);
            if (result.containsKey(value)) {
                result.get(value).append(",").append(key);
            } else {
                result.put(value, new StringBuffer(key));
            }
        }
        return result;
    }
    /**
     *  上传文件至Mongodb by GridFS
     * @param saveFileName  保存到mongo的文件名
     * @param inputStream   文件流
     * @param params         metaData数据
     * @return
     */
    public static String uploadFile( InputStream inputStream,String saveFileName,Map<String ,Object> params) {
        //metaData参数
        Document metaDocument = new Document();
        if (params != null && params.size() > 0) {
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                String key = entry.getKey();
                metaDocument.append(key, entry.getValue());
            }
        }
        try {
            gridFsOperations.delete(Query.query(GridFsCriteria.where("filename").is(saveFileName)));//删除原来的文件,保证唯一
            com.mongodb.gridfs.GridFSFile gridFSFile = gridFsOperations.store(inputStream, saveFileName, "", metaDocument);
            if (gridFSFile != null) {
                return saveFileName;
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    /**
     * 据文件名返回文件,只返回第一个
     *
     * @param fileName
     * @return
     */
    public static boolean readFile(MongoDatabase db, OutputStream os, String fileName) {
        try {
            GridFSBucket gridFS = GridFSBuckets.create(db);
            gridFS.downloadToStreamByName(fileName, os);
            os.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 读取文件内容
     *
     * @param fileName 文件名
     * @return
     */
    public static String readFileContent( String fileName) {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            GridFSDBFile gridFSDBFile = gridFsOperations.findOne(Query.query(GridFsCriteria.where("filename").is(fileName)));
            gridFSDBFile.writeTo(byteArrayOutputStream);
            return byteArrayOutputStream.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 从 mongodb GridFS 下载文件
     *
     * @param savePath 文件保存路径
     * @param fileName GridFS文件名
     * @return
     */
    public static String downFile( String savePath, String fileName) {
        FileOutputStream fileOutputStream = null;
        try {
            File file = new File(savePath);
            fileOutputStream = new FileOutputStream(file);
            List<GridFSDBFile> gridFSDBFiles = gridFsOperations.find(Query.query(GridFsCriteria.where("filename").is(fileName)));
            if (gridFSDBFiles==null || gridFSDBFiles.isEmpty()){
                return null;
            }else {
                GridFSDBFile gridFSDBFile = gridFSDBFiles.get(0);
                gridFSDBFile.writeTo(fileOutputStream);
                return savePath;
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    public static boolean deleteFile(String fileName){
        try {
            gridFsOperations.delete(Query.query(GridFsCriteria.where("filename").is(fileName)));//删除原来的文件,保证唯一
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}

+ 22 - 0
pom.xml

@ -51,6 +51,11 @@
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.hos</groupId>
            <artifactId>hos-core</artifactId>
            <version>${hos-version}</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.hos</groupId>
            <artifactId>hos-web-framework</artifactId>
@ -153,5 +158,22 @@
            <scope>test</scope>
        </dependency>
        <!-- test end -->
        <!-- swagger start -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>classmate</artifactId>
                    <groupId>com.fasterxml</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>
        <!-- swagger end -->
    </dependencies>
</project>

+ 0 - 1
src/main/java/com/yihu/hos/ESBApplication.java

@ -2,7 +2,6 @@ package com.yihu.hos;
import com.yihu.hos.config.BeanConfig;
import com.yihu.hos.interceptor.WebMvcInterceptor;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;

+ 1 - 1
src/main/java/com/yihu/hos/filter/SessionOutTimeFilter.java

@ -43,7 +43,7 @@ public class SessionOutTimeFilter extends OncePerRequestFilter {
        }
        String requestUri = httpServletRequest.getRequestURI();
        //¹ýÂËoauth2 ÇëÇó
        //
        if (requestUri!=null && !requestUri.contains("/oauth2")) {
            if (httpServletRequest.getSession(false) == null
                    || httpServletRequest.getSession().getAttribute("userInfo") == null) {

+ 0 - 1
src/main/java/com/yihu/hos/system/service/AppManager.java

@ -14,7 +14,6 @@ import com.yihu.hos.system.model.SystemApp;
import com.yihu.hos.system.model.SystemServiceEndpoint;
import com.yihu.hos.web.framework.constant.EndPointConstant;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

+ 0 - 1
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -18,7 +18,6 @@ import com.yihu.hos.web.framework.model.ActionResult;
import com.yihu.hos.web.framework.model.DictItem;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.bo.ServiceFlow;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

+ 0 - 55
src/main/java/com/yihu/hos/tenant/controller/TenantController.java

@ -199,59 +199,4 @@ public class TenantController extends BaseController{
            return Result.error("新建数据库失败!");
        }
    }
    /**
     *  //TODO 后 独立到对应的rest接口中
     * 上传文件
     * @param response
     * @param fileName
     * @return
     */
    @RequestMapping(value = "/upload/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Object upload(
            HttpServletResponse response, @PathVariable("fileName")  String fileName,
                         @ApiParam(name = "pack", value = "文件", allowMultiple = true)
                         @RequestPart() MultipartFile pack
                         ) {
        try {
            return tenantService.uploadFile(pack.getInputStream(), fileName);
        } catch (Exception e) {
            return Result.error("上传文件出错!");
        }
    }
    /**
     *  //TODO 后 独立到对应的rest接口中
     * 文件下载
     * @return
     */
    @RequestMapping(value = "/down/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public Object down(HttpServletResponse response, @PathVariable("fileName")  String fileName) {
        try {
            OutputStream os = response.getOutputStream();
            return tenantService.dowFile(os, fileName);
        } catch (Exception e) {
            return Result.error("下载文件出错!");
        }
    }
    /**
     *  //TODO 后 独立到对应的rest接口中
     * 删除文件
     * @return
     */
    @RequestMapping(value = "/delFile/{fileName}", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public Object delFile(HttpServletResponse response, @PathVariable("fileName")  String fileName) {
        try {
            return tenantService.delFile(fileName);
        } catch (Exception e) {
            return Result.error("下载文件失败!");
        }
    }
}

+ 0 - 46
src/main/java/com/yihu/hos/tenant/service/TenantService.java

@ -9,7 +9,6 @@ import com.yihu.hos.tenant.model.TenantModel;
import com.yihu.hos.web.framework.constant.MycatConstant;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.bo.ServiceMycat;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -134,51 +133,6 @@ public class TenantService {
        return Result.success("删除成功");
    }
    public Result dowFile(OutputStream os, String fileName) {
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            boolean succ = GridFSUtil.readFile(mongoConfig.mongoClient().getDatabase(dbName), os, fileName);
            if (succ) {
                return Result.success("读取文件成功");
            } else {
                return Result.success("读取文件失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("读取文件异常");
        }
    }
    public Result uploadFile(InputStream inputStream, String fileName) {
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            String saveFileName = GridFSUtil.uploadFile(inputStream, fileName, null);
            if (saveFileName != null) {
                return Result.success("上传文件成功");
            } else {
                return Result.error("上传文件失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("上传文件异常");
        }
    }
    public Result delFile(String fileName) {
        try {
            fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
            boolean succ = GridFSUtil.deleteFile(fileName);
            if (succ) {
                return Result.success("删除文件成功");
            } else {
                return Result.success("删除文件失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除文件异常");
        }
    }
    @Transactional
    public Result createDB(String dbName) throws Exception {
        tenantDao.createDB(dbName);

+ 0 - 1
src/test/java/com/yihu/hos/HosAdminApplicationTests.java

@ -1,7 +1,6 @@
package com.yihu.hos;
import com.yihu.hos.core.file.FileUtil;
import com.yihu.hos.web.framework.util.GridFSUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;