From 46872a311da9480d3edb19223aca2e0833fb1e31 Mon Sep 17 00:00:00 2001 From: hcong <1050828145@qq.com> Date: 星期二, 17 十二月 2024 11:41:00 +0800 Subject: [PATCH] 1. 完成数据产品中间结果基本信息和具体信息入库 2. 修改ColInspectionInfo.kt 监管时间格式修改为yyyy-mm-dd 3. 新增数据产品类型枚举类 DataProductType 4. 修改BaseTemplate实现类通过重写genData方法生成Template相关数据 5. TODO 其他未涉及到的产品对象的中间结果对象 --- src/main/kotlin/cn/flightfeather/supervision/common/utils/FileUtil.kt | 39 +++++++++++++++++++++++++++++++++------ 1 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/utils/FileUtil.kt b/src/main/kotlin/cn/flightfeather/supervision/common/utils/FileUtil.kt index f96d545..ba6dae3 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/common/utils/FileUtil.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/common/utils/FileUtil.kt @@ -1,10 +1,9 @@ package cn.flightfeather.supervision.common.utils -import java.awt.Image -import java.awt.image.BufferedImage +import cn.flightfeather.supervision.common.exception.BizException +import org.springframework.web.multipart.MultipartFile import java.io.* import java.util.* -import javax.imageio.ImageIO object FileUtil { @@ -20,13 +19,24 @@ out.close() } + fun delFile(path: String): Boolean { + val file = File(path) + if (!file.exists()) return false + if (file.isDirectory) return false + try { + file.delete() + return true + } catch (e: Exception) { + throw BizException("鏂囦欢鍒犻櫎鍑洪敊", e.cause) + } + } + //鍒犻櫎鏂囦欢澶� fun delFolder(folderPath: String) { try { delAllFile(folderPath) //鍒犻櫎瀹岄噷闈㈡墍鏈夊唴瀹� - var filePath = folderPath - filePath = filePath - val myFilePath = java.io.File(filePath) + val filePath = folderPath + val myFilePath = File(filePath) myFilePath.delete() //鍒犻櫎绌烘枃浠跺す } catch (e: Exception) { e.printStackTrace() @@ -117,6 +127,23 @@ } } + fun saveFiles(files: Array<MultipartFile>, basePath: String, path: String): List<String> { + val pathList = mutableListOf<String>() + files.forEach { file -> + val ext = file.originalFilename?.split(".")?.last() + val fileName = UUID.randomUUID().toString() + "." + ext + pathList.add("$path$fileName") + val absolutePath = "${basePath}/$path/" + try { + //璋冪敤鏂囦欢淇濆瓨鏂规硶 + uploadFile(file.bytes, absolutePath, fileName) + } catch (e: Exception) { + // TODO: handle exception + } + } + return pathList + } + /** * 鎸夌収鍥哄畾瀹藉害鍘嬬缉鍥剧墖鑷砨ase64褰㈠紡 */ -- Gitblit v1.9.3