Browse Source

删除没有使用的依赖

tuonina 6 years ago
parent
commit
28d7d76029

+ 8 - 34
build.gradle

@@ -8,28 +8,14 @@ buildscript {
         commons_io_version = '2.5'
         commons_lang3_version = '3.5'
         commons_codec_version = '1.10'
-        commons_fileupload_version = '1.3.2'
         slf4j_api_version = '1.7.25'
-        ehcache_version = '3.4.0'
-        ehcache_core_version = '2.6.11'
         mysql_connector_version = '5.1.45'
-        alidruid_version = '1.1.6'
         mybatis_plus_version = '2.2.0'
         mybatis_plus_boot_version = '1.0.5'
-        activiti_starter_version = '6.0.0'
-//        rocketmq_starter_version = '1.1.0-RELEASE'
-        rocketmq_starter_version = '0.1.0'
-        xxljob_version = '1.9.0'
         swagger_version = '2.7.0'
-        fastjson_version = '1.2.44'
-        pinyin4j_version = '2.5.1'
-//        kisso_version = '3.6.13'
         caffeine_version = '2.6.1'
         shiro_version = '1.4.0'
-        dubbo_starter_version = '0.1.0'
-        dubbo_version = "2.6.1"
-        jsqlparser_version = '1.2'
-        fastdfs_client_version = '1.26.2'
+        pinyin4j_version = '2.5.1'
     }
     repositories {
         mavenCentral()
@@ -81,6 +67,9 @@ subprojects {
         }
     }
 
+    configurations{
+        all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
+    }
 
     dependencies {
         // Kotlin
@@ -94,9 +83,8 @@ subprojects {
         compile('org.springframework.cloud:spring-cloud-starter-openfeign')
         compile("org.springframework.session:spring-session-data-redis")
 //
-        compile('org.springframework.boot:spring-boot-starter-web'){
-            exclude module:'spring-boot-starter-tomcat'
-        }
+
+        compile('org.springframework.boot:spring-boot-starter-web')
         compile('org.springframework.boot:spring-boot-starter-jdbc')
         compile('org.springframework.boot:spring-boot-starter-actuator')
 
@@ -120,11 +108,12 @@ subprojects {
             exclude group:"org.apache.shiro"
         }
 
+        compile("com.belerweb:pinyin4j:$pinyin4j_version")
+
         // commons
         compile("commons-io:commons-io:$commons_io_version")
         compile("org.apache.commons:commons-lang3:$commons_lang3_version")
         compile("commons-codec:commons-codec:$commons_codec_version")
-        compile("commons-fileupload:commons-fileupload:$commons_fileupload_version")
         compile("javax.servlet:javax.servlet-api:3.1.0")
         compile("javax.servlet:servlet-api:2.5")
 
@@ -133,25 +122,10 @@ subprojects {
         // db
         compile("mysql:mysql-connector-java:$mysql_connector_version")
         compile("com.baomidou:mybatis-plus-boot-starter:$mybatisPlusVersion")
-        // job
-        compile("com.xuxueli:xxl-job-core:$xxljob_version")
-
         // swagger
         compile("io.springfox:springfox-swagger2:$swagger_version")
         compile("io.springfox:springfox-swagger-ui:$swagger_version")
 
-        // utils
-        compile("org.projectlombok:lombok:1.18.2")
-        compile("com.alibaba:fastjson:$fastjson_version")
-        compile("com.belerweb:pinyin4j:$pinyin4j_version")
-
-
-        compile("org.apache.velocity:velocity-engine-core:2.0")
-        // sql parser
-        compile("com.github.jsqlparser:jsqlparser:$jsqlparser_version")
-        // fastdfs
-        compile("com.github.tobato:fastdfs-client:$fastdfs_client_version")
-
         ext.jarTree = fileTree(dir: 'libs', include: '**/*.jar')
         compile jarTree
     }

+ 1 - 0
zen-core/src/main/kotlin/com/gxzc/zen/common/base/BaseModel.kt

@@ -1,5 +1,6 @@
 package com.gxzc.zen.common.base
 
+import cn.gygxzc.tina.orm.base.BaseModel
 import com.baomidou.mybatisplus.annotation.*
 import com.fasterxml.jackson.annotation.JsonInclude
 import io.swagger.annotations.ApiModelProperty

+ 0 - 17
zen-core/src/main/kotlin/com/gxzc/zen/common/properties/FSProperties.kt

@@ -1,17 +0,0 @@
-package com.gxzc.zen.common.properties
-
-import org.springframework.boot.context.properties.ConfigurationProperties
-import org.springframework.stereotype.Component
-
-/**
- * FileSystem配置
- * @author NorthLan
- * @date 2018/9/5
- * @url https://noahlan.com
- */
-@Component
-@ConfigurationProperties(prefix = "fs")
-open class FSProperties {
-    var maxFileSize: Long = 4294967296L // 4 * 1024 * 1024 * 1024
-    var chunkSize: Long = 1048576L // 1 * 1024 * 1024
-}

+ 0 - 17
zen-core/src/main/kotlin/com/gxzc/zen/common/properties/FdfsProperties.kt

@@ -1,17 +0,0 @@
-package com.gxzc.zen.common.properties
-
-import org.springframework.boot.context.properties.ConfigurationProperties
-import org.springframework.stereotype.Component
-
-/**
- * FastDFS配置
- * @author NorthLan
- * @date 2018/9/5
- * @url https://noahlan.com
- */
-@Component
-@ConfigurationProperties(prefix = "fdfs")
-open class FdfsProperties {
-    var enable: Boolean = true
-    var tmpPath: String = "/tmp/zen"
-}

+ 0 - 16
zen-core/src/main/kotlin/com/gxzc/zen/common/properties/PlatformProperties.kt

@@ -1,16 +0,0 @@
-package com.gxzc.zen.common.properties
-
-import org.springframework.boot.context.properties.ConfigurationProperties
-import org.springframework.stereotype.Component
-
-/**
- * 平台配置类
- * @author NorthLan
- * @date 2018/2/6
- * @url https://noahlan.com
- */
-@Component
-@ConfigurationProperties(prefix = "platform")
-class PlatformProperties {
-    var id: Int? = null
-}

+ 0 - 17
zen-core/src/main/kotlin/com/gxzc/zen/common/properties/UploadProperties.kt

@@ -1,17 +0,0 @@
-package com.gxzc.zen.common.properties
-
-import org.springframework.boot.context.properties.ConfigurationProperties
-import org.springframework.stereotype.Component
-
-/**
- * 上传文件 配置
- * @author NorthLan
- * @date 2018/5/19
- * @url https://noahlan.com
- */
-@Component
-@ConfigurationProperties(prefix = "upload")
-open class UploadProperties {
-    var tmpPath: String = "/tmp/zen"
-    var dataPath: String = "/data/zen"
-}

+ 0 - 149
zen-core/src/main/kotlin/com/gxzc/zen/common/util/FileUtil.kt

@@ -1,149 +0,0 @@
-package com.gxzc.zen.common.util
-
-import com.gxzc.zen.common.properties.FSProperties
-import com.gxzc.zen.common.util.io.BufferedRandomAccessFile
-import java.io.File
-import java.io.FileInputStream
-import java.io.IOException
-import java.io.InputStream
-import java.nio.ByteBuffer
-
-/**
- * 文件工具类
- * @author NorthLan
- * @date 2018/5/24
- * @url https://noahlan.com
- */
-object FileUtil {
-
-    private val fsProperties: FSProperties by lazy { SpringContextHolder.getBean(FSProperties::class.java)!! }
-
-    /**
-     * 获取 文件首+尾chunk
-     * 拼接起来的md5
-     */
-    fun md5HeadTail(path: String, chunkSize: Int? = fsProperties.chunkSize.toInt()): String {
-        val file = File(path)
-        return transientMd5HeadTail(file, chunkSize)
-    }
-
-    /**
-     * 获取 文件首+尾chunk
-     * 拼接起来的md5
-     */
-    fun md5HeadTail(file: File, chunkSize: Int? = fsProperties.chunkSize.toInt()): String {
-        return transientMd5HeadTail(file, chunkSize)
-    }
-
-    private fun transientMd5HeadTail(file: File, size: Int?): String {
-        var chunkSize = size
-        if (chunkSize == null) {
-            chunkSize = fsProperties.chunkSize.toInt()
-        }
-        val fc = FileInputStream(file).channel
-        val fileSize = fc.size()
-
-        val buffer = ByteBuffer.allocate(chunkSize)
-        //        val lastModified = file.lastModified() / 1000 * 1000 // 由于jdk8的bug导致在linux上读取修改时间丢失精度
-        val chunks = Math.ceil(1.0 * fileSize / chunkSize).toInt() // 分块总数
-
-        var currentPos = 0 * chunkSize * 1L
-
-        var retBuffer: ByteBuffer? = null
-
-        var readLength = try {
-            fc.read(buffer, currentPos)
-        } catch (e: IOException) {
-            -1
-        }
-        if (readLength != -1) {
-            val byte = ByteArray(readLength)
-            buffer.flip()
-            buffer.get(byte)
-            buffer.clear()
-            // 第一块读完
-            currentPos = (chunks - 1) * chunkSize * 1L
-            if (currentPos > 0) {
-                readLength = try {
-                    fc.read(buffer, currentPos)
-                } catch (e: IOException) {
-                    -1
-                }
-                if (readLength != -1) {
-                    val byte2 = ByteArray(readLength)
-                    buffer.flip()
-                    buffer.get(byte2)
-                    buffer.clear()
-                    // 第二块读完
-                    retBuffer = ByteBuffer.allocate(byte.size + byte2.size + 8) // 8 为long占用字节数
-                    retBuffer.put(byte)
-                    retBuffer.put(byte2)
-                }
-            } else {
-                retBuffer = ByteBuffer.allocate(byte.size + 8) // 8 为long占用字节数
-                retBuffer.put(byte)
-            }
-        }
-
-        fc.close() // 关闭文件流
-
-        return if (retBuffer != null) {
-            //            val timeByteArray = ByteBuffer.allocate(8).putLong(lastModified).array()
-            //            timeByteArray.reverse()
-            //
-            //            retBuffer.put(timeByteArray)
-            MD5Util.encodeMd5(retBuffer.array())
-        } else {
-            ""
-        }
-    }
-
-    /**
-     * 将文件写入指定路径
-     * 优化过的RandomAccessFile
-     */
-    fun writeFile(ins: InputStream, outputPath: String): File {
-        val brafWriteFile = BufferedRandomAccessFile(outputPath, "rw", 10)
-
-        ins.use {
-            brafWriteFile.use {
-                val buf = ByteArray(4096)
-                var readcount = ins.read(buf)
-                while (readcount != -1) {
-                    brafWriteFile.write(buf, 0, readcount)
-                    readcount = ins.read(buf)
-                }
-            }
-        }
-        return File(brafWriteFile.filename)
-    }
-
-    /**
-     * 将文件写入指定路径
-     * 优化过的RandomAccessFile
-     */
-    fun writeFile(path: String, outputPath: String): File {
-        return writeFile(File(path), outputPath)
-    }
-
-    /**
-     * 将文件写入指定路径
-     * 优化过的RandomAccessFile
-     */
-    fun writeFile(file: File, outputPath: String): File {
-        val brafReadFile = BufferedRandomAccessFile(file)
-        val brafWriteFile = BufferedRandomAccessFile(outputPath, "rw", 10)
-
-        brafReadFile.use {
-            brafWriteFile.use {
-                val buf = ByteArray(4096)
-                var readcount = brafReadFile.read(buf)
-                while (readcount != -1) {
-                    brafWriteFile.write(buf, 0, readcount)
-                    readcount = brafReadFile.read(buf)
-                }
-            }
-        }
-        return File(brafWriteFile.filename)
-    }
-}

+ 0 - 44
zen-core/src/main/kotlin/com/gxzc/zen/common/util/PlatformUtil.kt

@@ -1,44 +0,0 @@
-package com.gxzc.zen.common.util
-
-import com.gxzc.zen.common.contants.PLATFORM
-import com.gxzc.zen.common.properties.PlatformProperties
-import org.slf4j.LoggerFactory
-
-/**
- * 平台工具类
- * @author NorthLan
- * @date 2018/2/6
- * @url https://noahlan.com
- */
-object PlatformUtil {
-    private val logger = LoggerFactory.getLogger(PlatformUtil::class.java)
-
-    var properties: PlatformProperties? = null
-        get() {
-            if (field == null) {
-                field = SpringContextHolder.getBean(PlatformProperties::class.java)
-            }
-            return field
-        }
-
-    fun getPlatformId(): Int {
-        return try {
-            properties!!.id!!
-        } catch (e: Throwable) {
-            logger.warn("error get platform properties, cause", e)
-            0
-        }
-    }
-
-    fun getPlatform(id: Int): PLATFORM {
-        return PLATFORM.intValueOf(id)
-    }
-
-    fun getPlatform(): PLATFORM {
-        return getPlatform(getPlatformId())
-    }
-
-    fun getPlatform(properties: PlatformProperties): PLATFORM {
-        return getPlatform(properties.id!!)
-    }
-}

+ 0 - 9
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/FdfsFile.kt

@@ -1,9 +0,0 @@
-package com.gxzc.zen.common.util.upload
-
-/**
- *
- * @author NorthLan
- * @date 2018/8/30
- * @url https://noahlan.com
- */
-open class FdfsFile(val group: String, val path: String)

+ 0 - 309
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/FdfsUploadUtil.kt

@@ -1,309 +0,0 @@
-package com.gxzc.zen.common.util.upload
-
-import com.github.tobato.fastdfs.domain.StorePath
-import com.github.tobato.fastdfs.exception.FdfsServerException
-import com.github.tobato.fastdfs.service.AppendFileStorageClient
-import com.github.tobato.fastdfs.service.FastFileStorageClient
-import com.gxzc.zen.common.exception.ZenException
-import com.gxzc.zen.common.exception.ZenExceptionEnum
-import com.gxzc.zen.common.properties.FSProperties
-import com.gxzc.zen.common.properties.FdfsProperties
-import com.gxzc.zen.common.util.KeyLock
-import com.gxzc.zen.common.util.SpringContextHolder
-import com.gxzc.zen.common.util.upload.constants.CheckStatus
-import com.gxzc.zen.common.util.upload.constants.UploadStatus
-import com.gxzc.zen.common.util.upload.result.CheckResult
-import com.gxzc.zen.common.util.upload.result.UploadResult
-import org.apache.commons.io.FilenameUtils
-import org.slf4j.LoggerFactory
-import org.springframework.web.multipart.MultipartFile
-import java.io.BufferedInputStream
-import java.io.File
-import java.nio.file.Files
-import java.nio.file.Paths
-
-/**
- * FastDFS 上传工具类 <br>
- * 前端上传文件到 分布式文件服务器
- * @author NorthLan
- * @date 2018/8/29
- * @url https://noahlan.com
- */
-object FdfsUploadUtil {
-    private val logger = LoggerFactory.getLogger(FdfsUploadUtil::class.java)
-
-    private val fdfsProperties: FdfsProperties by lazy { SpringContextHolder.getBean(FdfsProperties::class.java)!! }
-    private val fsProperties: FSProperties by lazy { SpringContextHolder.getBean(FSProperties::class.java)!! }
-
-    private val appendFileStorageClient: AppendFileStorageClient by lazy { SpringContextHolder.getBean(AppendFileStorageClient::class.java)!! }
-    private val fastFileStorageClient: FastFileStorageClient by lazy { SpringContextHolder.getBean(FastFileStorageClient::class.java)!! }
-
-    /*-------------------------------------------
-    |           Multipart File 文件上传           |
-    ============================================*/
-
-    // 针对文件md5加锁,保证上传合并文件时线程安全
-    private val checkMergeLock: KeyLock<Int> = KeyLock()
-    private val mergeLock: KeyLock<Int> = KeyLock()
-    private val uploadLock: KeyLock<Int> = KeyLock()
-    //    private val mergeLock = ReentrantLock(true)
-    /**
-     * 检查文件是否存在,实现文件秒传
-     * 通过MD5查询数据库是否有记录
-     *     有记录: 查询真实文件是否存在
-     *         真实文件存在: 秒传
-     *         真实文件不存在: 数据库记录清理
-     *     无记录: 文件不存在,查询分片存在情况
-     * 状态:
-     * 1. 有数据库记录,有文件
-     * 2. 有数据库记录,无文件
-     * 3. 无数据库记录,文件分片不完整
-     * 4. 无数据库记录,文件分片完整
-     */
-    fun check(fdfsFile: FdfsFile?, fileMetadata: ZenFileMetadata): CheckResult {
-        val ret = CheckResult()
-        if (validateRequest(fileMetadata, null)) {
-            // fdfsFile != null 表示数据库中有记录,再次检查文件在FastDFS中是否存在
-            if (fdfsFile != null) {
-                // 数据库有记录
-                val fileInfo = try {
-                    fastFileStorageClient.queryFileInfo(fdfsFile.group, fdfsFile.path)
-                } catch (e: FdfsServerException) {
-                    null
-                }
-                if (fileInfo != null) {
-                    // 文件存在
-                    ret.checkStatus = CheckStatus.FDFS_DB_FILE
-                    ret.uploadedChunks = mutableListOf()
-                    for (i in 1..fileMetadata.totalChunks!!) {
-                        ret.uploadedChunks!!.add(i)
-                    }
-                } else {
-                    // 真实文件不存在
-                    ret.checkStatus = CheckStatus.FDFS_DB_NO_FILE
-                }
-            } else {
-                // 数据库无记录
-                ret.checkStatus = CheckStatus.FDFS_NO_DB_FRAG_CHUNK
-                // 检查分片存在情况
-                for (i in 1..fileMetadata.totalChunks!!) {
-                    if (chunkExists(i, fileMetadata.md5!!)) {
-                        if (ret.uploadedChunks == null) {
-                            ret.uploadedChunks = mutableListOf()
-                        }
-                        ret.uploadedChunks!!.add(i)
-                    }
-                }
-                if (ret.uploadedChunks != null && ret.uploadedChunks!!.size == fileMetadata.totalChunks) {
-                    ret.checkStatus = CheckStatus.FDFS_NO_DB_FULL_CHUNK
-
-                    val hashedMd5 = fileMetadata.md5!!.hashCode()
-                    val tmpPath = fdfsProperties.tmpPath
-
-                    checkMergeLock.lock(hashedMd5)
-                    try {
-                        // 将分片依次上传到 fastdfs 中(同步操作)
-                        //  logger.warn("checking: 上传所有分片啊!!!")
-                        val storePath = appendFileChunks(tmpPath, fileMetadata)
-                        ret.fdfsFile = FdfsFile(storePath.group, storePath.path)
-                    } finally {
-                        checkMergeLock.unlock(hashedMd5)
-                    }
-                }
-            }
-        } else {
-            throw ZenException(ZenExceptionEnum.FILE_METADATA_VALIDATE_ERROR)
-        }
-        return ret
-    }
-
-    /**
-     * 正常上传<br>
-     * 文件夹结构/文件名
-     */
-    fun upload(fileMetadata: ZenFileMetadata, file: MultipartFile): UploadResult {
-        val tmpPath = fdfsProperties.tmpPath
-        val chunkSize = fsProperties.chunkSize
-        var storePath: StorePath? = null
-        if (validateRequest(fileMetadata, file)) {
-            val filename = fileMetadata.filename!!
-            val fileExtName = FilenameUtils.getExtension(filename)
-            val hashedMd5 = fileMetadata.md5!!.hashCode()
-
-            // 如果分片小于chunkSize && totalChunk = 1 表示文件只有一个分片
-            if (fileMetadata.totalChunks == 1 && fileMetadata.chunkSize!! <= chunkSize) {
-                // 这里也需要加锁,避免并发上传失败
-                uploadLock.lock(hashedMd5)
-                try {
-                    file.inputStream.use {
-                        storePath = appendFileStorageClient.uploadAppenderFile(null, it, file.size, fileExtName)
-                    }
-                } finally {
-                    uploadLock.unlock(hashedMd5)
-                }
-            } else {
-                // 保存分片到本地磁盘临时路径
-                val chunkFilename = getChunkFilename(tmpPath, fileMetadata.chunkNumber, fileMetadata.md5)
-                val directory = Paths.get(tmpPath)
-                if (Files.notExists(directory)) {
-                    Files.createDirectories(directory)
-                }
-                file.transferTo(File(chunkFilename))
-
-                mergeLock.lock(hashedMd5)
-                try {
-                    if (checkChunks(tmpPath, fileMetadata)) {
-                        // 将分片依次上传到 fastdfs 中(同步操作)
-                        // logger.warn("上传所有分片啊!!! ${fileMetadata.chunkNumber} ${fileMetadata.totalChunks}")
-                        storePath = appendFileChunks(tmpPath, fileMetadata)
-                    }
-                } finally {
-                    mergeLock.unlock(hashedMd5)
-                }
-
-            }
-        } else {
-            throw ZenException(ZenExceptionEnum.FILE_METADATA_VALIDATE_ERROR)
-        }
-        var status: String = UploadStatus.UPLOADING
-        if (storePath != null) {
-            status = UploadStatus.UPLOADED
-        }
-        return UploadResult().apply {
-            this.status = status
-            this.storePath = storePath
-        }
-    }
-
-    /**
-     * 将单个文件所有分片上传到FastDFS中
-     */
-    private fun appendFileChunks(sourceRootPath: String, fileMetadata: ZenFileMetadata): StorePath {
-        val filename = fileMetadata.filename!!
-        val fileExtName = FilenameUtils.getExtension(filename)
-        val totalChunks = fileMetadata.totalChunks!!
-        val md5 = fileMetadata.md5!!
-        //        val hashedMd5 = md5.hashCode()
-        //        val chunkSize = fdfsProperties!!.chunkSize!!
-        var storePath: StorePath? = null
-        for (i in 1..totalChunks) {
-            val sourceFile = File(getChunkFilename(sourceRootPath, i, md5))
-            val inputStream = BufferedInputStream(sourceFile.inputStream())
-            try {
-                if (i == 1) {
-                    // first chunk
-                    try {
-                        storePath = appendFileStorageClient.uploadAppenderFile(null, inputStream, sourceFile.length(), fileExtName)
-                    } catch (e: FdfsServerException) {
-                        if (e.errorCode != 16 && e.errorCode != 2) {
-                            throw ZenException(403, e.message!!)
-                        } else {
-                            throw e // 2:找不到节点或文件 16:服务器忙 可进行重试 ,其它情况均视为失败
-                        }
-                    } finally {
-                        if (storePath == null) {
-                            throw ZenException(ZenExceptionEnum.FILE_FRAG_UPLOAD_FAILURE)
-                        }
-                    }
-                } else {
-                    if (storePath == null) {
-                        throw ZenException(ZenExceptionEnum.FILE_FRAG_UPLOAD_FAILURE)
-                    } else {
-                        appendFileStorageClient.appendFile(storePath.group, storePath.path, inputStream, sourceFile.length())
-                        // appendFileStorageClient.modifyFile(storePath.group, storePath.path, inputStream, sourceFile.length(), i * chunkSize)
-                    }
-                }
-            } finally {
-                inputStream.close()
-                // 删除分片
-                sourceFile.delete()
-            }
-        }
-        return storePath!!
-    }
-
-    /**
-     * 检查分片是否存在 (tmp目录)
-     */
-    private fun chunkExists(chunkNumber: Int?, md5: String): Boolean {
-        val tmpPath = fdfsProperties.tmpPath
-        return Files.exists(Paths.get(getChunkFilename(tmpPath, chunkNumber, md5)))
-    }
-
-    /**
-     * 检查分块是否上传完毕
-     */
-    private fun checkChunks(tmpPath: String, fileMetadata: ZenFileMetadata): Boolean {
-        val totalChunks = fileMetadata.totalChunks!!
-        val md5 = fileMetadata.md5!!
-        for (i in 1..totalChunks) {
-            if (Files.notExists(Paths.get(getChunkFilename(tmpPath, i, md5)))) {
-                return false
-            }
-        }
-        // 不能这样判断,因为chunk是无序的
-        //        return fileMetadata.chunkNumber == fileMetadata.totalChunks
-        return true
-    }
-
-    /**
-     * 生成 分片文件名
-     */
-    private fun getChunkFilename(path: String, chunkNumber: Int?, identifier: String?): String {
-        return "$path/upload-$identifier.$chunkNumber"
-    }
-
-    /**
-     * validate request multipart chunks
-     */
-    private fun validateRequest(fileMetadata: ZenFileMetadata, file: MultipartFile?): Boolean {
-        val md5 = fileMetadata.md5
-        val chunkNumber = fileMetadata.chunkNumber
-        val chunkSize = fileMetadata.chunkSize
-        val totalSize = fileMetadata.totalSize
-        val filename = fileMetadata.filename
-
-        if (chunkNumber == null || chunkNumber <= 0 ||
-                chunkSize == null || chunkSize <= 0 ||
-                totalSize == null || totalSize <= 0 ||
-                md5 == null || md5.isEmpty() ||
-                filename == null || filename.isEmpty()) {
-            return false
-        }
-
-        val numberOfChunks = Math.max(Math.floor(totalSize / (chunkSize * 1.0)), 1.0).toInt()
-        if (chunkNumber > numberOfChunks) {
-            return false
-        }
-
-        // is the file too large?
-        fsProperties.let {
-            val maxFileSize = it.maxFileSize
-            if (maxFileSize > 0) {
-                if (totalSize > maxFileSize) {
-                    logger.error("filesize limit: [${maxFileSize / 1024 / 1024} MB], now [${totalSize / 1024 / 1024} MB]")
-                    return false
-                }
-            }
-        }
-
-        if (file != null) {
-            // The chunk in the POST request isn't the correct size
-            if (chunkNumber < numberOfChunks && file.size != chunkSize) {
-                logger.error("The chunk in the POST request isn't the correct size")
-                return false
-            }
-            // The chunks in the POST is the last one, and the fil is not the correct size
-            if (numberOfChunks > 1 && chunkNumber == numberOfChunks && file.size != (totalSize % chunkSize) + chunkSize) {
-                logger.error("The chunks in the POST is the last one, and the fil is not the correct size")
-                return false
-            }
-            // The file is only a single chunk, and the data size does not fit
-            if (numberOfChunks == 1 && file.size != totalSize) {
-                logger.error("The file is only a single chunk, and the data size does not fit")
-                return false
-            }
-        }
-        return true
-    }
-}

+ 0 - 316
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/UploadUtil.kt

@@ -1,316 +0,0 @@
-package com.gxzc.zen.common.util.upload
-
-import com.gxzc.zen.common.exception.ZenException
-import com.gxzc.zen.common.exception.ZenExceptionEnum
-import com.gxzc.zen.common.properties.FSProperties
-import com.gxzc.zen.common.properties.UploadProperties
-import com.gxzc.zen.common.util.FileUtil
-import com.gxzc.zen.common.util.KeyLock
-import com.gxzc.zen.common.util.SpringContextHolder
-import com.gxzc.zen.common.util.upload.constants.CheckStatus
-import com.gxzc.zen.common.util.upload.constants.UploadStatus
-import com.gxzc.zen.common.util.upload.result.CheckResult
-import com.gxzc.zen.common.util.upload.result.UploadResult
-import org.apache.commons.io.FilenameUtils
-import org.slf4j.LoggerFactory
-import org.springframework.web.multipart.MultipartFile
-import java.io.*
-import java.nio.file.Files
-import java.nio.file.Paths
-
-/**
- * 上传 工具类
- * @author NorthLan
- * @date 2018/5/19
- * @url https://noahlan.com
- */
-object UploadUtil {
-    private val logger = LoggerFactory.getLogger(UploadUtil::class.java)
-
-    private val uploadProperties: UploadProperties by lazy { SpringContextHolder.getBean(UploadProperties::class.java)!! }
-    private val fsProperties: FSProperties by lazy { SpringContextHolder.getBean(FSProperties::class.java)!! }
-
-    private val checkMergeLock = KeyLock<Int>()
-    private val mergeLock = KeyLock<Int>()
-    private val uploadLock = KeyLock<Int>()
-
-    private val FILE_SEPARATOR = System.getProperty("file.separator") // 适配操作系统的文件路径
-
-    /**
-     * 正常上传<br>
-     * 文件夹结构/文件名
-     */
-    fun upload(fileMetadata: ZenFileMetadata, file: MultipartFile): UploadResult {
-        val tmpPath = uploadProperties.tmpPath
-        val dataPath = uploadProperties.dataPath
-        val chunkSize = fsProperties.chunkSize
-        var retFile: File? = null
-        if (validateRequest(fileMetadata, file)) {
-            val filename = fileMetadata.filename!!
-            val md5 = fileMetadata.md5!!
-            val hashedMd5 = md5.hashCode()
-            // 文件分片 如果分片小于chunkSize && totalChunk = 1,直接转存
-            if (fileMetadata.totalChunks == 1 && fileMetadata.chunkSize!! <= chunkSize) {
-
-                uploadLock.lock(hashedMd5)
-                try {
-                    // 目标文件流 通过文件名来拼接
-                    val outputFullFilename = getFullDestFilename(dataPath, filename, md5)
-                    val outputPath = Paths.get(FilenameUtils.getFullPath(outputFullFilename))
-                    // 不存在则创建文件夹
-                    if (Files.notExists(outputPath)) {
-                        Files.createDirectories(outputPath)
-                    }
-                    retFile = File(outputFullFilename)
-                    file.transferTo(retFile)
-                    retFile.setLastModified(fileMetadata.lastModified!!)
-                } finally {
-                    uploadLock.unlock(hashedMd5)
-                }
-            } else {
-                val chunkFilename = getChunkFilename(tmpPath, fileMetadata.chunkNumber, fileMetadata.md5)
-                val directory = Paths.get(tmpPath)
-                if (Files.notExists(directory)) {
-                    Files.createDirectories(directory)
-                }
-                file.transferTo(File(chunkFilename))
-
-                mergeLock.lock(hashedMd5)
-                try {
-                    // 检查分块完整性
-                    if (checkChunks(tmpPath, fileMetadata)) {
-                        // 合并
-                        retFile = try {
-                            mergeChunks(tmpPath, dataPath, fileMetadata)
-                        } catch (e: Throwable) {
-                            logger.error("merge file chunks exception, cause ", e)
-                            null
-                        }
-                    }
-                } finally {
-                    mergeLock.unlock(hashedMd5)
-                }
-            }
-        } else {
-            throw ZenException(ZenExceptionEnum.FILE_METADATA_VALIDATE_ERROR)
-        }
-        var status: String = UploadStatus.UPLOADING
-        if (retFile != null) {
-            status = UploadStatus.UPLOADED
-        }
-        return UploadResult().apply {
-            this.status = status
-            this.file = retFile
-        }
-    }
-
-    /**
-     * 检测文件是否存在 实现文件秒传
-     * 真实文件已存在,秒传
-     * 真实文件不存在,检查分片上传情况
-     */
-    fun checkUpload(fileMetadata: ZenFileMetadata): CheckResult {
-        val tmpPath = uploadProperties.tmpPath
-        val dataPath = uploadProperties.dataPath
-        val ret = CheckResult()
-        if (validateRequest(fileMetadata, null)) {
-            if (fileExists(fileMetadata)) {
-                ret.uploadedChunks = mutableListOf()
-                for (i in 1..fileMetadata.totalChunks!!) {
-                    ret.uploadedChunks!!.add(i)
-                }
-                ret.file = File(getFullDestFilename(dataPath, fileMetadata.filename!!, fileMetadata.md5!!))
-                ret.checkStatus = CheckStatus.FILE_EXISTS
-            } else {
-                // 检查分片存在情况
-                ret.checkStatus = CheckStatus.NO_FILE_FRAG_CHUNK
-                for (i in 1..fileMetadata.totalChunks!!) {
-                    if (chunkExists(i, fileMetadata.md5!!)) {
-                        if (ret.uploadedChunks == null) {
-                            ret.uploadedChunks = mutableListOf()
-                        }
-                        ret.uploadedChunks!!.add(i)
-                    }
-                }
-                if (ret.uploadedChunks != null && ret.uploadedChunks!!.size == fileMetadata.totalChunks) {
-                    // 合并
-                    ret.checkStatus = CheckStatus.NO_FILE_FULL_CHUNK
-                    val hashedMd5 = fileMetadata.md5!!.hashCode()
-                    checkMergeLock.lock(hashedMd5)
-                    try {
-                        ret.file = try {
-                            mergeChunks(tmpPath, dataPath, fileMetadata)
-                        } catch (e: Throwable) {
-                            logger.error("merge file chunks exception, cause ", e)
-                            null
-                        }
-                    } finally {
-                        checkMergeLock.unlock(hashedMd5)
-                    }
-                }
-            }
-        } else {
-            throw ZenException(ZenExceptionEnum.FILE_METADATA_VALIDATE_ERROR)
-        }
-        return ret
-    }
-
-    /**
-     * 检查文件是否存在 (真实文件)
-     */
-    private fun fileExists(fileMetadata: ZenFileMetadata): Boolean {
-        val dataPath = uploadProperties.dataPath
-        // 获取filename 真实文件
-        val filename = fileMetadata.filename!!
-        val md5 = fileMetadata.md5!!
-        val realFilename = getFullDestFilename(dataPath, filename, md5)
-        return Files.exists(Paths.get(realFilename)) && FileUtil.md5HeadTail(realFilename, fsProperties.chunkSize.toInt()) == md5 // # 防篡改
-    }
-
-    /**
-     * 检查分片是否存在 (tmp目录)
-     */
-    private fun chunkExists(chunkNumber: Int?, md5: String): Boolean {
-        val tmpPath = uploadProperties.tmpPath
-        return Files.exists(Paths.get(getChunkFilename(tmpPath, chunkNumber, md5)))
-    }
-
-    /**
-     * 检查分块是否上传完毕
-     */
-    private fun checkChunks(tmpPath: String, fileMetadata: ZenFileMetadata): Boolean {
-        val totalChunks = fileMetadata.totalChunks!!
-        val md5 = fileMetadata.md5!!
-        for (i in 1..totalChunks) {
-            if (Files.notExists(Paths.get(getChunkFilename(tmpPath, i, md5)))) {
-                return false
-            }
-        }
-        return true
-    }
-
-    /**
-     * 合并所有分块
-     * 支持 文件夹合并
-     */
-    private fun mergeChunks(sourceRootPath: String, destRootPath: String, fileMetadata: ZenFileMetadata): File? {
-        // 源文件的文件夹信息 然后组合拼接
-        val filename = fileMetadata.filename!!
-        val totalChunks = fileMetadata.totalChunks!!
-        val md5 = fileMetadata.md5!!
-
-        // 目标文件流 通过文件名来拼接
-        val outputFullFilename = getFullDestFilename(destRootPath, filename, md5)
-        val outputPath = Paths.get(FilenameUtils.getFullPath(outputFullFilename))
-        // 不存在则创建文件夹
-        if (Files.notExists(outputPath)) {
-            Files.createDirectories(outputPath)
-        }
-        val outputFile = File(outputFullFilename)
-        val destOutputStream = BufferedOutputStream(FileOutputStream(outputFile))
-
-        val buffer = ByteArray(4096)
-        var readBytesLength: Int
-        for (i: Int in 1..totalChunks) {
-            val sourceFile = File(getChunkFilename(sourceRootPath, i, md5))
-            val sourceInputStream = BufferedInputStream(FileInputStream(sourceFile))
-
-            readBytesLength = sourceInputStream.read(buffer)
-            while (readBytesLength != -1) {
-                destOutputStream.write(buffer, 0, readBytesLength)
-                readBytesLength = sourceInputStream.read(buffer)
-            }
-            sourceInputStream.close()
-            // 删除分片
-            sourceFile.delete()
-        }
-        //
-        destOutputStream.flush()
-        destOutputStream.close()
-
-        // 修改文件 修改时间
-        outputFile.setLastModified(fileMetadata.lastModified!!)
-
-        return outputFile
-    }
-
-    /**
-     * 生成 分片文件名
-     */
-    private fun getChunkFilename(path: String, chunkNumber: Int?, identifier: String?): String {
-        return "$path/upload-$identifier.$chunkNumber"
-    }
-
-    /**
-     * 生成 输出文件名
-     */
-    private fun getDestFileName(filename: String, md5: String): String {
-        val ext = FilenameUtils.getExtension(filename)
-        return if (!ext.isNullOrEmpty()) {
-            "$md5.$ext"
-        } else {
-            md5
-        }
-    }
-
-    /**
-     * 获取输出完整文件名
-     */
-    private fun getFullDestFilename(dataPath: String, filename: String, md5: String): String {
-        return FilenameUtils.normalize("$dataPath$FILE_SEPARATOR${getDestFileName(filename, md5)}")
-    }
-
-    /**
-     * validate request multipart chunks
-     */
-    private fun validateRequest(fileMetadata: ZenFileMetadata, file: MultipartFile?): Boolean {
-        val md5 = fileMetadata.md5
-        val chunkNumber = fileMetadata.chunkNumber
-        val chunkSize = fileMetadata.chunkSize
-        val totalSize = fileMetadata.totalSize
-        val filename = fileMetadata.filename
-
-        if (chunkNumber == null || chunkNumber <= 0 ||
-                chunkSize == null || chunkSize <= 0 ||
-                totalSize == null || totalSize <= 0 ||
-                md5 == null || md5.isEmpty() ||
-                filename == null || filename.isEmpty()) {
-            return false
-        }
-
-        val numberOfChunks = Math.max(Math.floor(totalSize / (chunkSize * 1.0)), 1.0).toInt()
-        if (chunkNumber > numberOfChunks) {
-            return false
-        }
-
-        // is the file too large?
-        fsProperties.let {
-            val maxFileSize = it.maxFileSize
-            if (maxFileSize > 0) {
-                if (totalSize > maxFileSize) {
-                    logger.error("filesize limit: [${maxFileSize / 1024 / 1024} MB], now [${totalSize / 1024 / 1024} MB]")
-                    return false
-                }
-            }
-        }
-
-        if (file != null) {
-            // The chunk in the POST request isn't the correct size
-            if (chunkNumber < numberOfChunks && file.size != chunkSize) {
-                logger.error("The chunk in the POST request isn't the correct size")
-                return false
-            }
-            // The chunks in the POST is the last one, and the fil is not the correct size
-            if (numberOfChunks > 1 && chunkNumber == numberOfChunks && file.size != (totalSize % chunkSize) + chunkSize) {
-                logger.error("The chunks in the POST is the last one, and the fil is not the correct size")
-                return false
-            }
-            // The file is only a single chunk, and the data size does not fit
-            if (numberOfChunks == 1 && file.size != totalSize) {
-                logger.error("The file is only a single chunk, and the data size does not fit")
-                return false
-            }
-        }
-        return true
-    }
-}

+ 0 - 34
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/ZenFileMetadata.kt

@@ -1,34 +0,0 @@
-package com.gxzc.zen.common.util.upload
-
-import java.io.Serializable
-
-/**
- * 文件DTO
- * @author NorthLan
- * @date 2018/5/18
- * @url https://noahlan.com
- */
-open class ZenFileMetadata : Serializable {
-    companion object {
-        private const val serialVersionUID = 1000000000000000015L
-    }
-
-    var chunkNumber: Int? = null
-    var chunkSize: Long? = null
-    //    var currentChunkSize: Long? = null
-    var totalSize: Long? = null
-    //    var identifier: String? = null
-    var filename: String? = null
-    var relativePath: String? = null
-    var totalChunks: Int? = null
-    var lastModified: Long? = null
-    var md5: String? = null
-
-    // 重构文件夹结构或重命名特性
-    var repath: String? = null
-    var rename: String? = null
-
-    // 批次
-    var batchId: String? = null
-    var totalNumber: Int? = null
-}

+ 0 - 20
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/constants/CheckStatus.kt

@@ -1,20 +0,0 @@
-package com.gxzc.zen.common.util.upload.constants
-
-/**
- * 检查状态
- * @author NorthLan
- * @date 2018/8/30
- * @url https://noahlan.com
- */
-object CheckStatus {
-    // FDFS_CHECK_STATUS
-    const val FDFS_DB_FILE = "FDFS_DB_FILE" // 有数据库记录,有文件
-    const val FDFS_DB_NO_FILE = "FDFS_DB_NO_FILE" // 有数据库记录,无文件
-    const val FDFS_NO_DB_FRAG_CHUNK = "FDFS_NO_DB_FRAG_CHUNK" // 无数据库记录,分片不完整
-    const val FDFS_NO_DB_FULL_CHUNK = "FDFS_NO_DB_FULL_CHUNK" // 无数据库记录,分片完整
-
-    // CHECK_STATUS
-    const val FILE_EXISTS = "FILE_EXISTS" // 真实文件存在
-    const val NO_FILE_FRAG_CHUNK = "NO_FILE_FRAG_CHUNK" // 文件不存在,分片不完整
-    const val NO_FILE_FULL_CHUNK = "NO_FILE_FULL_CHUNK" // 文件不存在,分片完整
-}

+ 0 - 14
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/constants/UploadStatus.kt

@@ -1,14 +0,0 @@
-package com.gxzc.zen.common.util.upload.constants
-
-/**
- * 上传状态
- * @author NorthLan
- * @date 2018/8/30
- * @url https://noahlan.com
- */
-object UploadStatus {
-//    const val CHECKING = "checking" // 检查中
-    const val UPLOADED = "uploaded" // 单文件上传完毕
-//    const val BATCH_UPLOADED = "batchUploaded" // 批量文件上传完毕
-    const val UPLOADING = "uploading" // 上传中
-}

+ 0 - 28
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/result/CheckResult.kt

@@ -1,28 +0,0 @@
-package com.gxzc.zen.common.util.upload.result
-
-import com.fasterxml.jackson.annotation.JsonIgnore
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.gxzc.zen.common.util.upload.FdfsFile
-import java.io.File
-
-/**
- * 检查结果
- * @author NorthLan
- * @date 2018/8/30
- * @url https://noahlan.com
- */
-@JsonInclude(JsonInclude.Include.NON_NULL)
-open class CheckResult {
-    var uploadedChunks: MutableList<Int>? = null // 已上传分片数
-
-//    @JsonIgnore
-    var checkStatus: String? = null
-
-    @JsonIgnore
-    var fdfsFile: FdfsFile? = null
-
-    @JsonIgnore
-    var file: File? = null
-
-    var info: Any? = null // 回传信息
-}

+ 0 - 26
zen-core/src/main/kotlin/com/gxzc/zen/common/util/upload/result/UploadResult.kt

@@ -1,26 +0,0 @@
-package com.gxzc.zen.common.util.upload.result
-
-import com.fasterxml.jackson.annotation.JsonIgnore
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.github.tobato.fastdfs.domain.StorePath
-import com.gxzc.zen.common.util.upload.constants.UploadStatus
-import java.io.File
-
-/**
- * 上传结果
- * @author NorthLan
- * @date 2018/5/25
- * @url https://noahlan.com
- */
-@JsonInclude(JsonInclude.Include.NON_NULL)
-open class UploadResult {
-    var status: String? = null // 上传状态码
-
-    @JsonIgnore
-    var file: File? = null // 服务端文件实例
-
-    @JsonIgnore
-    var storePath: StorePath? = null
-
-    var info: Any? = null // 信息
-}