feiyu02
2022-10-21 f22c4b9230808fed4fec80c435eccb4c833349a0
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
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.Version
import cn.flightfeather.supervision.domain.mapper.VersionMapper
import cn.flightfeather.supervision.infrastructure.utils.FileUtil
import cn.flightfeather.supervision.lightshare.service.VersionService
import cn.flightfeather.supervision.lightshare.vo.VersionVo
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
import tk.mybatis.mapper.entity.Example
 
@Service
class VersionServiceImpl(val versionMapper: VersionMapper): 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.createCriteria().andEqualTo("enable", true)
        example.orderBy("versionCode").desc()
        val versionlist = versionMapper.selectByExample(example)
        if (versionlist != null && versionlist.size > 0) {
            return versionlist[0]
        }
        return null
    }
 
    override fun upLoadCrashInfo(userId: String, files: Array<MultipartFile>): Boolean {
        if (files.isNotEmpty()) {
            val file = files[0]
            val fileName = files[0].originalFilename
            val basePath = "D:/02product/05ledger/files/"
            val path = "crash/"
            try {
                //调用文件保存方法
                FileUtil.uploadFile(file.bytes, basePath + path, fileName!!)
                return true
            } catch (e: Exception) {
                e.printStackTrace()
                return false
            }
        } else {
            return false
        }
    }
}