package cn.flightfeather.supervision.domain.repository
|
|
import cn.flightfeather.supervision.domain.entity.LedgerMediaFile
|
import cn.flightfeather.supervision.domain.mapper.LedgerMediaFileMapper
|
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
|
import cn.flightfeather.supervision.infrastructure.utils.FileUtil
|
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
|
import cn.flightfeather.supervision.lightshare.vo.LedgerVo
|
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.stereotype.Repository
|
import java.io.FileNotFoundException
|
import java.util.*
|
|
@Repository
|
class LedgerMediaFileRep(private val ledgerMediaFileMapper: LedgerMediaFileMapper) {
|
|
@Value("\${imgPath}")
|
lateinit var imgPath: String
|
|
/**
|
* 查询
|
* @param lrGuid 台账记录id
|
*/
|
fun select(lrGuid: String): LedgerMediaFile? {
|
return ledgerMediaFileMapper.selectOne(LedgerMediaFile().apply { this.lrGuid = lrGuid })
|
}
|
|
fun saveFile(userId: String, ledgerVo: LedgerVo, files: List<Pair<ByteArray, String>>): String {
|
var picPath = ""
|
val time = DateUtil.DateToString(ledgerVo.updateDate, DateUtil.DateStyle.YYYY_MM)
|
|
files.forEachIndexed { index, file ->
|
val fileName = "${ledgerVo.ledgerSubTypeId}-${index + 1}.${file.second}"
|
val basePath = imgPath
|
val path = "$time/$userId/${ledgerVo.ledgerName}/"
|
picPath += if (picPath.isEmpty()) {
|
"$path$fileName"
|
} else {
|
";$path$fileName"
|
}
|
try {
|
//调用文件保存方法
|
FileUtil.uploadFile(file.first, basePath + path, fileName!!)
|
} catch (e: FileNotFoundException) {
|
e.printStackTrace()
|
}
|
}
|
return picPath
|
}
|
|
fun insert(ledgerVo: LedgerVo, picPath: String) {
|
val ledgerMedia = LedgerMediaFile().apply {
|
mfGuid = UUIDGenerator.generate16ShortUUID()
|
lrGuid = ledgerVo.id
|
mfFiletype = ledgerVo.fileType
|
mfPath1 = picPath
|
mfDescription1 = ledgerVo.remark1
|
mfSavetime = Date()
|
mfIsdelete = false
|
}
|
//插入新的多媒体文件记录数据
|
ledgerMediaFileMapper.insert(ledgerMedia)
|
}
|
|
fun update(ledgerMedia: LedgerMediaFile?) {
|
//更新的多媒体文件记录数据
|
ledgerMediaFileMapper.updateByPrimaryKey(ledgerMedia)
|
}
|
}
|