feiyu02
2025-09-30 a3cc1d220f8a1de11874bebceba0130d32157ff1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cn.flightfeather.supervision.lightshare.service.impl
 
import cn.flightfeather.supervision.domain.ds1.entity.Version
import cn.flightfeather.supervision.domain.ds1.mapper.VersionMapper
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.common.utils.FileUtil
import cn.flightfeather.supervision.lightshare.service.VersionService
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
import tk.mybatis.mapper.entity.Example
 
@Service
class VersionServiceImpl(
    val versionMapper: VersionMapper, @Value("\${filePath}") var filePath: String,
    @Value("\${imgPath}") var imgPath: String,
): VersionService {
 
    override fun save(version: Version): Int = versionMapper.insert(version)
 
    override fun update(version: Version): Int = versionMapper.updateByPrimaryKey(version)
 
    override fun delete(id: String): Int =versionMapper.deleteByPrimaryKey(id)
 
    override fun getLatestVersion(): Version? {
        val example = Example(Version::class.java)
        example.orderBy("versionCode").desc()
        val versionlist = versionMapper.selectByExample(example)
        if (versionlist != null && versionlist.size > 0) {
            return versionlist[0]
        }
        return Version()
    }
 
    override fun upLoadCrashInfo(userId: String, files: Array<MultipartFile>): Boolean {
        if (files.isNotEmpty()) {
            val file = files[0]
            val fileName = files[0].originalFilename
            val basePath = filePath
            val path = "/crash/"
            try {
                //调用文件保存方法
                FileUtil.uploadFile(file.bytes, basePath + path, fileName!!)
                return true
            } catch (e: Exception) {
                e.printStackTrace()
                return false
            }
        } else {
            return false
        }
    }
}