|
@@ -0,0 +1,90 @@
|
|
|
+package com.gxzc.zen.api.sys.service.impl
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper
|
|
|
+import com.baomidou.mybatisplus.service.impl.ServiceImpl
|
|
|
+import com.gxzc.zen.api.sys.mapper.SysUploadInfoMapper
|
|
|
+import com.gxzc.zen.api.sys.model.SysUploadInfo
|
|
|
+import com.gxzc.zen.api.sys.service.ISysUploadInfoService
|
|
|
+import com.gxzc.zen.common.dto.ZenFileMetadata
|
|
|
+import org.apache.commons.io.FilenameUtils
|
|
|
+import org.springframework.stereotype.Service
|
|
|
+import java.io.File
|
|
|
+import java.util.*
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 上传文件信息表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author NorthLan
|
|
|
+ * @since 2018-06-01
|
|
|
+ */
|
|
|
+@Service
|
|
|
+class SysUploadInfoServiceImpl : ServiceImpl<SysUploadInfoMapper, SysUploadInfo>(), ISysUploadInfoService {
|
|
|
+ override fun addUploadFileInfo(fileMetadata: ZenFileMetadata, file: File) {
|
|
|
+ val entity = SysUploadInfo().apply {
|
|
|
+ // filename
|
|
|
+ this.filename = if (fileMetadata.rename.isNullOrEmpty()) {
|
|
|
+ fileMetadata.filename
|
|
|
+ } else {
|
|
|
+ "${FilenameUtils.removeExtension(fileMetadata.rename)}.${FilenameUtils.getExtension(fileMetadata.filename)}"
|
|
|
+ }
|
|
|
+ this.realFilename = file.name
|
|
|
+ this.originFilename = fileMetadata.filename
|
|
|
+ // infomation
|
|
|
+ this.relativePath = if (fileMetadata.repath.isNullOrEmpty()) fileMetadata.relativePath?.replace(this.originFilename!!, "") else fileMetadata.repath
|
|
|
+ this.batchId = fileMetadata.batchId
|
|
|
+ this.lastModified = Date(file.lastModified())
|
|
|
+ this.md5 = fileMetadata.md5
|
|
|
+ this.extension = FilenameUtils.getExtension(file.name)
|
|
|
+ this.filesize = fileMetadata.totalSize
|
|
|
+ }
|
|
|
+ baseMapper.insert(entity)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun getUploadInfosByBatchId(batchId: String): MutableList<SysUploadInfo> {
|
|
|
+ val condition = SysUploadInfo().apply { this.batchId = batchId }
|
|
|
+ val ret = baseMapper.selectWOLogic(EntityWrapper(condition))
|
|
|
+ ret.forEach {
|
|
|
+ generateURL(it)
|
|
|
+ }
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun generateURL(it: SysUploadInfo?) {
|
|
|
+ if (it != null) {
|
|
|
+ it.url = "/${it.realFilename}"
|
|
|
+// if (it.relativePath.isNullOrEmpty()) {
|
|
|
+// it.url = FilenameUtils.normalize("/${it.filename}")
|
|
|
+// } else {
|
|
|
+// it.url = FilenameUtils.normalize("/${it.relativePath}/${it.filename}")
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun getUploadInfoById(id: Long): SysUploadInfo? {
|
|
|
+ val condition = SysUploadInfo().apply { this.id = id }
|
|
|
+ return baseMapper.selectOne(condition).apply {
|
|
|
+ generateURL(this)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun getUploadInfoListByIdList(ids: Collection<Long>): MutableList<SysUploadInfo> {
|
|
|
+ val ret = baseMapper.selectWOLogic(EntityWrapper<SysUploadInfo>().`in`("id", ids))
|
|
|
+ ret.forEach {
|
|
|
+ generateURL(it)
|
|
|
+ }
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun modifyFileInfo(entity: SysUploadInfo): SysUploadInfo {
|
|
|
+ this.updateById(entity)
|
|
|
+ return getUploadInfoById(entity.id!!)!!
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun modifyBatchFileInfo(entityList: MutableList<SysUploadInfo>): MutableList<SysUploadInfo> {
|
|
|
+ this.updateBatchById(entityList)
|
|
|
+ return getUploadInfoListByIdList(entityList.map { it.id!! }.toList())
|
|
|
+ }
|
|
|
+
|
|
|
+}
|