From 85ef942e7195abeb71466b7159c3ee30161e1e54 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 07 四月 2026 08:51:01 +0800
Subject: [PATCH] 2026.4.7
---
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/MediafileServiceImpl.kt | 131 +++++++++++++++++++++++++++++++++++++++----
1 files changed, 119 insertions(+), 12 deletions(-)
diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/MediafileServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/MediafileServiceImpl.kt
index 4081cf9..b06ee08 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/MediafileServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/MediafileServiceImpl.kt
@@ -1,16 +1,20 @@
package cn.flightfeather.supervision.lightshare.service.impl
+import cn.flightfeather.supervision.business.autooutput.datasource.AopDbMapper
import cn.flightfeather.supervision.common.exception.BizException
+import cn.flightfeather.supervision.common.utils.*
import cn.flightfeather.supervision.domain.ds1.entity.Mediafile
import cn.flightfeather.supervision.domain.ds1.mapper.MediafileMapper
-import cn.flightfeather.supervision.common.utils.Constant
-import cn.flightfeather.supervision.common.utils.FileUtil
import cn.flightfeather.supervision.domain.ds1.entity.Inspection
+import cn.flightfeather.supervision.domain.ds1.entity.Subtask
import cn.flightfeather.supervision.domain.ds1.repository.InspectionRep
import cn.flightfeather.supervision.domain.ds1.repository.MediaFileRep
import cn.flightfeather.supervision.domain.ds1.repository.SceneRep
import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep
+import cn.flightfeather.supervision.lightshare.service.DomainitemService
import cn.flightfeather.supervision.lightshare.service.MediafileService
+import cn.flightfeather.supervision.lightshare.vo.AreaVo
+import cn.flightfeather.supervision.lightshare.vo.ExcelConfigVo
import cn.flightfeather.supervision.lightshare.vo.MediaFileVo
import com.fasterxml.jackson.core.type.TypeReference
import org.springframework.beans.BeanUtils
@@ -20,7 +24,15 @@
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
+import tk.mybatis.mapper.entity.Example
import java.io.File
+import java.io.FileInputStream
+import java.io.FileOutputStream
+import java.nio.charset.StandardCharsets
+import java.time.LocalDateTime
+import java.time.ZoneId
+import java.util.*
+import javax.servlet.http.HttpServletResponse
@Service
@@ -30,6 +42,8 @@
private val inspectionRep: InspectionRep,
private val subTaskRep: SubTaskRep,
private val sceneRep: SceneRep,
+ private val domainItemService: DomainitemService,
+ private val dbMapper: AopDbMapper,
@Value("\${filePath}") var filePath: String,
@Value("\${imgPath}") var imgPath: String,
) : MediafileService {
@@ -63,8 +77,8 @@
throw BizException("宸℃煡璁板綍id鍜屽贰鏌ヤ换鍔d鑷冲皯濉啓鍏朵腑涓�涓�")
}
sceneId ?: throw BizException("璁板綍瀵瑰簲鐨勫満鏅笉瀛樺湪")
- val sceneInfo = sceneRep.findScene(sceneId = sceneId)
- val mediaFileTypeList = Constant.MediaFileType.getList(sceneInfo?.typeid).map { it.value }
+ val sceneInfo = sceneRep.findScene(sceneId = sceneId) ?: throw BizException("鍦烘櫙涓嶅瓨鍦紝鑾峰彇鍦烘櫙鍥剧墖澶辫触")
+ val mediaFileTypeList = domainItemService.getMediaFileType(sceneInfo.typeid?.toInt()).entries.map { it.key?.toInt() }
return mediaFileRep.findList(inspectionGuid, mediaFileTypeList)
}
@@ -96,7 +110,9 @@
mapper.readValue<List<MediaFileVo>>(mediafileVoList, object : TypeReference<List<MediaFileVo>>() {})
if (mediaFileVos.isNotEmpty()) {
- mediaFileVos.forEach {
+ mediaFileVos.forEachIndexed { i, it ->
+ if (i >= files.size) return@forEachIndexed
+
val mediafile = Mediafile()
BeanUtils.copyProperties(it, mediafile)
@@ -106,17 +122,15 @@
if (reme == null) {
mediafileMapper.insert(mediafile)
}
- }
- //鏍规嵁鎵╁睍瀛楁1鑾峰彇淇濆瓨璺緞
- val path = mediaFileVos[0].extension1
- for (image in files) {
- val fileName = image.originalFilename
-
+ //鏍规嵁鎵╁睍瀛楁1鑾峰彇淇濆瓨璺緞
+ val path = it.extension1
+ val fileName = it.guid + ".jpg"
+ val image = files[i]
val filePath = "${imgPath}/$path/"
try {
//璋冪敤鏂囦欢淇濆瓨鏂规硶
- FileUtil.uploadFile(image.bytes, filePath, fileName!!)
+ FileUtil.uploadFile(image.bytes, filePath, fileName)
} catch (e: Exception) {
// TODO: handle exception
}
@@ -196,4 +210,97 @@
}
return res
}
+
+ override fun downloadPic(config: ExcelConfigVo, response: HttpServletResponse): HttpServletResponse {
+ val subSum = dbMapper.subtaskMapper.getSummaryByArea(AreaVo().apply {
+ provincecode = config.provinceCode
+ citycode = config.cityCode
+ districtcode = config.districtCode
+ starttime = LocalDateTime.ofInstant(config.startTime?.toInstant(), ZoneId.systemDefault())
+ endtime = LocalDateTime.ofInstant(config.endTime?.toInstant(), ZoneId.systemDefault())
+ scensetypeid = config.sceneType.toString()
+ })
+ if (subSum.isEmpty()) return response
+
+ val mediaList = mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
+ createCriteria().andIn("iguid", subSum.map { it.insGuid })
+ .apply {
+ if (!config.fileType.isNullOrEmpty()) {
+ andIn("businesstypeid", config.fileType)
+ }
+ }
+ })
+
+ //寤虹珛绗竴灞傜洰褰曪紝鍖呭惈鎵�鏈夌殑浠诲姟
+ val time = DateUtil.DateToString(Date(), "yyyy-MM-dd_HH-mm-ss")
+ val basePath = imgPath + File.separator + "temp" + File.separator + time
+ FileUtil.mkDirs(basePath)
+
+ //寰幆寤虹珛绗簩灞傜洰褰曪紝鎸夌収鏃ユ湡鍒嗙被
+ subSum.groupBy { it.stPlanTime }.forEach { (date, sList) ->
+ //寤虹珛涓�涓棩鏈熸枃浠跺す
+ val datePath = "${basePath}${File.separator}${DateUtil.DateToString(date, DateUtil.DateStyle.YYYY_MM_DD)}"
+ FileUtil.mkDirs(datePath)
+
+ //寰幆寤虹珛绗笁灞傜洰褰曪紝鎸夌収宸℃煡浠诲姟鍒嗙被
+ sList.forEach {s ->
+ //寤虹珛涓�涓瓙浠诲姟鏂囦欢澶�
+ val subTaskFilePath = "${datePath}${File.separator}${StringUtil.numberFormat(s.sceneIndex, 3)} ${s.sceneName}"
+ FileUtil.mkDirs(subTaskFilePath)
+
+ //寰幆寤虹珛绗洓灞傜洰褰曪紝鎸夌収鍥剧墖绫诲瀷鍒嗙被
+ mediaList.filter { m-> m.iguid == s.insGuid }.groupBy { m-> m.businesstype }.forEach { (type, mList) ->
+ val mediaTypeFilePath = "${subTaskFilePath}${File.separator}${type}"
+ FileUtil.mkDirs(mediaTypeFilePath)
+
+ // 鍐欏叆鍥剧墖
+ mList.forEachIndexed { i, m->
+ val fromPicName = m.guid + ".jpg"
+ val picPath =
+ imgPath + File.separator + m.extension1 + fromPicName
+ val fromFile = File(picPath)
+ val picName = if (m.description != null) {
+ m.description!!.replace("/", "-")
+ .replace("\\", "-")
+ .replace("\n", "")
+ .replace(".", "(${i + 1}).")
+ } else {
+ fromPicName
+ }
+// val picName = fromPicName
+ val toFile = File(mediaTypeFilePath + File.separator + picName)
+ if (fromFile.exists()) {
+ FileUtil.copy(fromFile, toFile)
+ }
+ }
+ }
+ }
+ }
+
+ response.apply {
+ setHeader("Content-Disposition", "attachment;filename=$time.zip")
+ contentType = "application/octet-stream"
+ characterEncoding = StandardCharsets.UTF_8.name()
+ }
+
+ val zipFile = File("$basePath.zip")
+ val fos1 = FileOutputStream(zipFile)
+ ZipUtils.toZip(basePath, fos1, true)
+
+ val out = response.outputStream
+ val fis = FileInputStream(zipFile)
+
+ val buf = ByteArray(2 * 1024)
+ var len = fis.read(buf)
+ while (len != -1) {
+ out.write(buf, 0, len)
+ len = fis.read(buf)
+ }
+ out.flush()
+ out.close()
+ fis.close()
+ fos1.close()
+
+ return response
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3