feiyu02
2022-07-28 237d7c42498806a3ca205f63d151671a45304854
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package cn.flightfeather.supervision.lightshare.repository.impl
 
import cn.flightfeather.supervision.domain.entity.MaterialSignState
import cn.flightfeather.supervision.domain.entity.MeetingMaterial
import cn.flightfeather.supervision.domain.enumeration.MeetingFileType
import cn.flightfeather.supervision.domain.mapper.MaterialSignStateMapper
import cn.flightfeather.supervision.domain.mapper.MeetingMaterialMapper
import cn.flightfeather.supervision.infrastructure.utils.FileUtil
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
import cn.flightfeather.supervision.lightshare.repository.MeetingMaterialRepository
import cn.flightfeather.supervision.websocket.MediaType
import cn.flightfeather.supervision.websocket.MeetingMsgVo
import cn.flightfeather.supervision.lightshare.vo.MeetingMaterialVo
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Repository
import org.springframework.web.multipart.MultipartFile
import tk.mybatis.mapper.entity.Example
import java.util.*
import javax.servlet.http.HttpServletResponse
 
/**
 * @author riku
 * Date: 2019/12/19
 */
@Repository
class MeetingMaterialRepositoryImpl(val meetingMaterialMapper: MeetingMaterialMapper,
                                    val materialSignStateMapper: MaterialSignStateMapper): MeetingMaterialRepository {
 
    override fun deleteAllByMeetingId(meetingId: String): Int {
        return meetingMaterialMapper.deleteByExample(Example(MeetingMaterial::class.java).apply {
            createCriteria().andEqualTo("mmMguid", meetingId)
        })
    }
 
    override fun saveMaterials(userId: String, meetingId: String, roomId: String, msgVo: MeetingMsgVo, files: Array<MultipartFile>, documentType: Int): MeetingMsgVo {
        var url = ""
        var thumbnailPath = ""
 
        val basePath = "D:/02product/05ledger/files/"
        val path = "$meetingId-$roomId/${msgVo.mediaType ?: 0}/"
        val fileName = FileUtil.getFileName(msgVo.materialUrl)
        url = path + fileName
        val thumbnailName = FileUtil.getFileName(msgVo.thumbnailPath)
        thumbnailPath = path + thumbnailName
 
        files.forEach {file ->
            FileUtil.uploadFile(file.bytes, basePath + path, file.originalFilename?:"${Date().time}_no_name+file")
        }
        meetingMaterialMapper.insert(MeetingMaterial().apply {
            mmId = UUIDGenerator.generate16ShortUUID()
            mcId = 0
            mmDocumenttype = documentType.toByte()
            mmMguid = meetingId
            mmResourcefiletype = msgVo.mediaType?.toByte()
            mmResourceurl = url
            mmExtension2 = thumbnailPath
            mmUpdatedate = Date()
        })
        msgVo.materialUrl = url
        msgVo.thumbnailPath = thumbnailPath
        return msgVo
    }
 
    override fun getMeetingMaterials(userId: String, meetingId: String, mediaType: Int, page: Int, perPage: Int, response: HttpServletResponse):List<MeetingMaterial> {
        val example = Example(MeetingMaterial::class.java).apply {
            createCriteria().andEqualTo("mmMguid", meetingId)
                    .apply {
                        if (mediaType != MediaType.NoType.value) {
                            andEqualTo("mmResourcefiletype", mediaType.toByte())
                        }
                    }
            and(
                    createCriteria().orIsNull("mmExtension1")
                            .orNotEqualTo("mmExtension1", "deleted")
            )
        }
        val counts = meetingMaterialMapper.selectCountByExample(example)
        val totalPage = Math.ceil(counts.toDouble() / perPage.toDouble()).toInt()
        response.setIntHeader("totalPage", totalPage)
        response.setIntHeader("currentPage", page)
 
        val offset = perPage.times(page - 1)
        PageHelper.offsetPage<MeetingMaterial>(offset, perPage)
 
        return meetingMaterialMapper.selectByExample(example)
    }
 
    override fun getMaterialSignState(userId: String, meetingId: String, materialId: String): Boolean {
        val resultList = materialSignStateMapper.selectByExample(Example(MaterialSignState::class.java).apply {
            createCriteria().andEqualTo("msUserid", userId)
                    .andEqualTo("mcId", meetingId)
                    .andEqualTo("mmId", materialId)
        })
        return if (resultList.isEmpty()) {
            false
        } else {
            resultList[0].mmSignstate ?: false
        }
    }
 
    override fun updateSignState(userId: String, signStateList: List<MeetingMaterialVo>): Boolean {
        var result = 0
        signStateList.forEach {
            result += materialSignStateMapper.insert(MaterialSignState().apply {
                msUserid = userId
                mmId = it.id
                mcId = it.meetingId
                mmSignstate = true
            })
        }
        return result == signStateList.size
    }
 
    override fun getMaterialCount(meetingId: String, mediaType: Int, meetingFileType: Int): Int {
        return meetingMaterialMapper.selectCountByExample(Example(MeetingMaterial::class.java).apply {
            createCriteria().andEqualTo("mmMguid", meetingId)
                    .apply {
                        if (meetingFileType != 0) {
                            andEqualTo("mmDocumenttype", meetingFileType.toByte())
                        }
                        if (mediaType != MediaType.NoType.value) {
                            andEqualTo("mmResourcefiletype", mediaType.toByte())
                        }
                    }
            and(
                    createCriteria().orIsNull("mmExtension1")
                            .orNotEqualTo("mmExtension1", "deleted")
            )
        })
    }
 
    override fun deleteFiles(meetingId: String, fileList: List<MeetingMaterialVo>): List<MeetingMaterialVo> {
        var result = 0
        fileList.forEach {
            val newEntity = MeetingMaterial().apply {
                mmId = it.id
                mmUpdatedate = Date()
                mmExtension1 = "deleted"
            }
            result += meetingMaterialMapper.updateByPrimaryKeySelective(newEntity)
        }
        return if (result == fileList.size) {
            fileList
        } else {
            emptyList()
        }
    }
 
    override fun getMaterialSignCount(userId: String, meetingId: String): Int {
        return materialSignStateMapper.selectCountByExample(Example(MaterialSignState::class.java).apply {
            createCriteria().andEqualTo("msUserid", userId)
                    .andEqualTo("mcId", meetingId)
                    .andEqualTo("mmSignstate", true)
        })
    }
}