feiyu02
2025-09-30 6904763f0e74d9a9fa4dbc39f635d2aee39416c6
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.MeetingInfo
import cn.flightfeather.supervision.domain.entity.Participant
import cn.flightfeather.supervision.domain.entity.Signature
import cn.flightfeather.supervision.domain.entity.VMRoom
import cn.flightfeather.supervision.domain.enumeration.MeetingFileType
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
import cn.flightfeather.supervision.lightshare.repository.*
import cn.flightfeather.supervision.lightshare.service.MeetingInfoService
import cn.flightfeather.supervision.lightshare.service.NotificationService
import cn.flightfeather.supervision.lightshare.service.UserinfoService
import cn.flightfeather.supervision.websocket.MediaType
import cn.flightfeather.supervision.websocket.MeetingMsgVo
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.flightfeather.taizhang.model.bean.ChangedMeetingInfoVo
import cn.flightfeather.supervision.lightshare.vo.MaterialSignStatusVo
import cn.flightfeather.supervision.lightshare.vo.MeetingMaterialVo
import cn.flightfeather.supervision.lightshare.vo.MeetingUserOnlineStatusVo
import cn.flightfeather.supervision.lightshare.vo.UserStatusVo
import cn.flightfeather.supervision.websocket.Processor
import cn.flightfeather.supervision.domain.enumeration.ParticipantType
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
import java.util.*
import javax.servlet.http.HttpServletResponse
 
@Service
class MeetingInfoServiceImpl(
        val meetingRepository: MeetingRepository,
        val meetingVMRoomRepository: MeetingVMRoomRepository,
        val meetingMaterialRepository: MeetingMaterialRepository,
        val meetingParticipantRepository: MeetingParticipantRepository,
        val notificationService: NotificationService,
        val userInfoService: UserinfoService,
        val signatureRepository: MeetingSignatureRepository,
        val processor: Processor
): MeetingInfoService {
 
    override fun getMeetingInfo(userId: String, status: Int, page: Int, perPage: Int, response: HttpServletResponse): List<MeetingInfo> {
        val resultList = when (status) {
            1 -> meetingRepository.getAllMeeting(userId, page, perPage, response)
            2 -> meetingRepository.getMeetingUserJoined(userId, status, page, perPage, response)
            3 -> meetingRepository.getMyMeetingUnReleased(userId, status, page, perPage, response)
            4 -> meetingRepository.getMyMeetingReleased(userId, status, page, perPage, response)
            5 -> meetingRepository.getHistoryMeeting(userId, status, page, perPage, response)
            else -> emptyList()
        }
        return resultList.sortedByDescending {
            it.miBegindate
        }
    }
 
    override fun getMeetingInfoById(userId: String, meetingId: String): MeetingInfo {
        val result = meetingRepository.getMeeting(meetingId)
        return result ?: MeetingInfo()
    }
 
    override fun addMeetingInfo(userId: String, meetingInfo: MeetingInfo): ChangedMeetingInfoVo {
        //生成会议主键
        meetingInfo.miGuid = UUIDGenerator.generate16ShortUUID()
        val result = meetingRepository.addMeetingInfo(meetingInfo)
        //同时生成一个默认的会议室
        val vmRoom = meetingVMRoomRepository.createVMRoom(userId, meetingInfo)
 
        return ChangedMeetingInfoVo(meetingInfo.miGuid, meetingInfo.miTitle, vmRoom.vmrGuid, vmRoom.vmrRoomcode)
    }
 
    override fun updateMeetingInfo(userId: String, meetingInfo: MeetingInfo): Int {
        val roomList = getMeetingRoom(userId, meetingInfo.miGuid)
        processor.refreshMeetingInfo(meetingInfo, roomList)
        return meetingRepository.updateMeetingInfo(userId, meetingInfo)
    }
 
    override fun deleteMeetingInfo(userId: String, meetingId: String): Int {
        //删除数据
//        val result1 = meetingRepository.deleteMeetingInfo(meetingId)
//        val result2 = meetingParticipantRepository.deleteAllByMeetingId(meetingId)
//        val result3 = meetingMaterialRepository.deleteAllByMeetingId(meetingId)
 
        //修改字段,更新为删除的会议
        return meetingRepository.updateMeetingStatusDeleted(meetingId)
    }
 
    override fun getMeetingRegisterStatus(userId: String, meetingId: String, roomId: String?): Int {
        val participant = meetingParticipantRepository.getParticipant(meetingId, roomId, userId)
        //用户是参会人员,判断是否需要签到
        if (participant != null) {
            //查询签到记录
            var signature = signatureRepository.getSignatureByUser(meetingId, roomId, userId)
            //签到记录不存在(签到记录应该在添加参会人员后就同步生成,此处做冗余判断)
            if (signature == null) {
                val room = meetingVMRoomRepository.getRoom(roomId ?: "")
                val user = userInfoService.findOne(userId)
                signature = Signature().apply {
                    msMguid = meetingId
                    mcVmroomguid = roomId
                    mcVmroomcode = room?.vmrRoomcode
                    msPtunitid = user.dGuid
                    msPtunit = user.departmentname
                    msParticipantid = userId
                    msParticipant = user.acountname
                    msIsnotice = true
                    msIstriprmd = true
                    msIsshortrmd = true
                    //将签到状态设置为未签到
                    msIssignin = false
                    msCreatedate = Date()
                    msUpdatedate = Date()
                }
                signatureRepository.addSignature(signature)
                return 0
            } else {
                if (signature.msIssignin == true) {
                    return 1
                } else {
                    return 0
                }
            }
        }
        //用户不是参会人员,无需签到
        else {
            return 2
        }
    }
 
    override fun getMeetingRegisterRecord(userId: String, meetingId: String, roomId: String?): List<Signature> {
        return signatureRepository.getSignatureRecord(meetingId, roomId)
    }
 
    override fun meetingRegister(userId: String, meetingId: String, roomId: String?): Boolean {
        var signature = signatureRepository.getSignatureByUser(meetingId, roomId, userId)
        //只有第一次签到时才需要更新会议信息表中的签到人数
        if (signature == null || signature.msIssignin == false) {
            val meeting = meetingRepository.getMeeting(meetingId)
            meeting?.miRegisternum = if (meeting?.miRegisternum == null) {
                1
            } else {
                meeting.miRegisternum + 1
            }
            meeting?.let { updateMeetingInfo(userId, it) }
        }
        if (signature == null) {
            val room = meetingVMRoomRepository.getRoom(roomId ?: "")
            val user =userInfoService.findOne(userId)
            signature = Signature().apply {
                msMguid =meetingId
                mcVmroomguid = roomId
                mcVmroomcode = room?.vmrRoomcode
                msPtunitid=user.dGuid
                msPtunit = user.departmentname
                msParticipantid = userId
                msParticipant = user.acountname
                msIsnotice = true
                msIstriprmd = true
                msIsshortrmd = true
                msIssignin = true
                msSignindate = Date()
                msIssignout = false
                msCreatedate = Date()
                msUpdatedate = Date()
            }
            return signatureRepository.addSignature(signature) == 1
        } else {
            signature.apply {
                msIssignin = true
                msSignindate = Date()
                msUpdatedate = Date()
            }
            val result = signatureRepository.updateSignature(signature) == 1
 
            return result
        }
    }
 
    override fun getMeetingRoom(userId: String, meetingId: String): List<VMRoom> {
        return meetingVMRoomRepository.getRoomsByMeetingId(meetingId)
    }
 
    override fun saveMeetingRecords(meetingId: String, roomId: String, msgVoList: List<MeetingMsgVo>): Int {
        return meetingRepository.saveMeetingRecords(meetingId, roomId, msgVoList)
    }
 
    override fun getMeetingRecords(userId: String, meetingId: String, roomId: String, page: Int, perPage: Int, response: HttpServletResponse): List<MeetingMsgVo> {
        return meetingRepository.getMeetingRecords(userId, meetingId, roomId, page, perPage, response)
    }
 
    /**************************************************************************************/
    override fun addParticipant(userId: String, participantList: List<Participant>): Int {
        var result = 0
        participantList.forEach {
            it.mpCreatedate= Date()
            it.mpUpdatedate = Date()
            result += meetingParticipantRepository.addParticipant(it)
 
            //同时生成每个参会人员的签到表
            val signature = Signature().apply {
                msMguid = it.mpMguid
                mcVmroomguid = it.mcVmroomguid
                mcVmroomcode = it.mcVmroomcode
                msPtunitid=it.mpPtunitid
                msPtunit = it.mpPtunit
                msParticipantid = it.mpParticipantid
                msParticipant = it.mpParticipant
                msIsnotice = false
                msIstriprmd = false
                msIsshortrmd = false
                msIssignin = false
                msCreatedate = Date()
                msUpdatedate = Date()
            }
            signatureRepository.addSignature(signature)
 
            //同时更新会议信息中的主持人、嘉宾和参会人数的记录
            if(result > 0) {
                val meeting = meetingRepository.getMeeting(it.mpMguid ?: "")
                if (it.mpPersontype == ParticipantType.Chair.value.toByte()) {
                    meeting?.miChairsid = if (meeting?.miChairsid.isNullOrEmpty()) {
                        it.mpParticipantid
                    } else {
                        meeting?.miChairsid + ";" + it.mpParticipantid
                    }
                    meeting?.miChairs = if (meeting?.miChairs.isNullOrEmpty()) {
                        it.mpParticipant
                    } else {
                        meeting?.miChairs + ";" + it.mpParticipant
                    }
                } else if (it.mpPersontype == ParticipantType.Guest.value.toByte()) {
                    meeting?.miIsguests = true
                    meeting?.miGuests = if (meeting?.miGuests.isNullOrEmpty()) {
                        it.mpParticipant
                    } else {
                        meeting?.miGuests + ";" + it.mpParticipant
                    }
                }
                //会议参会人数
                meeting?.miExtension1 = if (meeting?.miExtension1.isNullOrEmpty()) {
                    "1"
                } else {
                    "${(meeting?.miExtension1?.toInt() ?: 0) + 1}"
                }
                meeting?.let { updateMeetingInfo(userId, it) }
            }
 
            //同时刷新会议室的缓存人员信息
            processor.refreshUserInfo(it.mpMguid, it.mcVmroomguid, it, false)
        }
        return result
    }
 
    override fun deleteParticipant(userId: String, meetingId: String, participantList: List<Participant>): Int {
        var result = 0
        participantList.forEach {
            if (meetingId == it.mpMguid) {
                result += meetingParticipantRepository.deleteParticipant(it)
 
                //删除会议的参会人员时,同时删除对应的签到记录表
                signatureRepository.deleteSignatureByUser(meetingId, it.mcVmroomguid, it.mpParticipantid)
 
                //同时更新会议信息中的主持人、嘉宾和参会人数的记录
                val meeting = meetingRepository.getMeeting(it.mpMguid ?: "")
                if (it.mpPersontype == ParticipantType.Chair.value.toByte()) {
                    if (!meeting?.miChairsid.isNullOrEmpty()) {
                        val tempChairs = StringBuilder()
                        meeting!!.miChairsid.split(";").toMutableList().apply {
                            remove(it.mpParticipantid)
                        }.forEach {
                            tempChairs.append(";").append(it)
                        }
                        if (tempChairs.isNotEmpty()) {
                            tempChairs.deleteCharAt(0)
                        }
                        meeting.miChairsid = tempChairs.toString()
                    }
                    if (!meeting?.miChairs.isNullOrEmpty()) {
                        val tempChairs = StringBuilder()
                        meeting!!.miChairs.split(";").toMutableList().apply {
                            remove(it.mpParticipant)
                        }.forEach {
                            tempChairs.append(";").append(it)
                        }
                        if (tempChairs.isNotEmpty()) {
                            tempChairs.deleteCharAt(0)
                        }
                        meeting.miChairs = tempChairs.toString()
                    }
                }else if (it.mpPersontype == ParticipantType.Guest.value.toByte()) {
                    if (!meeting?.miGuests.isNullOrEmpty()) {
                        val tempGuests = java.lang.StringBuilder()
                        meeting!!.miGuests.split(";").toMutableList().apply {
                            remove(it.mpParticipant)
                        }.forEach {
                            tempGuests.append(";").append(it)
                        }
                        if (tempGuests.isNotEmpty()) {
                            tempGuests.deleteCharAt(0)
                            meeting.miIsguests = true
                        } else {
                            meeting.miIsguests = false
                        }
                        meeting.miGuests = tempGuests.toString()
                    }
                }
                //会议参会人数
                if (!meeting?.miExtension1.isNullOrEmpty()) {
                    meeting?.miExtension1 = "${(meeting?.miExtension1?.toInt() ?: 1) - 1}"
                }
 
                meeting?.let { updateMeetingInfo(userId, it) }
 
                //同时刷新会议室的缓存人员信息
                processor.refreshUserInfo(it.mpMguid, it.mcVmroomguid, it, true)
            }
        }
        return result
    }
 
    override fun getParticipant(userId: String, meetingId: String, roomId: String?, participantType: Int): List<Participant> {
        return meetingParticipantRepository.getParticipantByType(meetingId, roomId, participantType)
    }
 
    override fun getOnlineUsers(userId: String, meetingId: String, roomId: String): List<MeetingUserOnlineStatusVo> {
        val userStatusMap = processor.getOnlineUsers(meetingId, roomId)
        val participantList = meetingParticipantRepository.selectAsUserInfo(meetingId, roomId)
        participantList.forEach {
            it.online = if (userStatusMap.contains(it.userId)) userStatusMap[it.userId]?.online ?: false else false
            it.mute = userStatusMap[it.userId]?.mute ?: true
        }
 
        return participantList
    }
 
    override fun setMuteStatus(userId: String, meetingId: String, roomId: String, userStatusList: List<UserStatusVo>): Boolean {
        processor.setUserMute(meetingId, roomId, userStatusList)
        val attachmentId = "$meetingId-$roomId"
        processor.broadMuteStatus(meetingId, attachmentId, userStatusList,userId)
 
        return true
    }
 
    override fun uploadFile(userId: String, meetingId: String, roomId: String, msgVo: String, files: Array<MultipartFile>, documentType: Int): List<MeetingMsgVo> {
        val mapper = ObjectMapper()
 
        val meetingMsgVo = mapper.readValue<MeetingMsgVo>(msgVo, object : TypeReference<MeetingMsgVo>() {})
 
        val result = meetingMaterialRepository.saveMaterials(userId, meetingId, roomId, meetingMsgVo, files, documentType)
 
        return listOf(result)
    }
 
    override fun getMeetingMaterials(userId: String, meetingId: String, mediaType: Int, page: Int, perPage: Int, response: HttpServletResponse): List<MeetingMaterialVo> {
        val tempList = meetingMaterialRepository.getMeetingMaterials(userId, meetingId, mediaType, page, perPage, response)
        return mutableListOf<MeetingMaterialVo>().apply {
            tempList.forEach {
                add(MeetingMaterialVo().apply {
                    id = it.mmId
                    documentType = it.mmDocumenttype.toInt()
                    this.meetingId = it.mmMguid
                    resourceFileType = it.mmResourcefiletype.toInt()
                    resourceOutUrl = it.mmResourceouturl
                    resourceUrl = it.mmResourceurl
                    updateDate = it.mmUpdatedate
                    signed = meetingMaterialRepository.getMaterialSignState(userId, meetingId, it.mmId)
                })
            }
        }
    }
 
    override fun updateSignState(userId: String, signStateList: List<MeetingMaterialVo>): Boolean {
        return meetingMaterialRepository.updateSignState(userId, signStateList)
    }
 
    override fun getMaterialCount(userId: String, meetingId: String, mediaType: Int, meetingFileType: Int): Int =
            meetingMaterialRepository.getMaterialCount(meetingId, mediaType, meetingFileType)
 
    override fun deleteFiles(userId: String, meetingId: String, fileList: List<MeetingMaterialVo>): List<MeetingMaterialVo> =
            meetingMaterialRepository.deleteFiles(meetingId, fileList)
 
    override fun getAllMaterialSignStatus(userId: String, meetingId: String): List<MaterialSignStatusVo> {
        val participants = meetingParticipantRepository.getParticipantByType(meetingId, null, ParticipantType.Conferee.value)
        val totalMaterialCount = meetingMaterialRepository.getMaterialCount(meetingId, MediaType.File.value, MeetingFileType.Preach.value)
        val resultList = mutableListOf<MaterialSignStatusVo>()
        participants.forEach {
            val userInfo = userInfoService.findOne(it.mpParticipantid)
            val signedCount = meetingMaterialRepository.getMaterialSignCount(it.mpParticipantid, meetingId)
            if (signedCount == totalMaterialCount) {
                return@forEach
            } else {
                resultList.add(MaterialSignStatusVo().apply {
                    this.userId = it.mpParticipantid
                    headIconUrl = userInfo.headIconUrl
                    acountname = userInfo.realname
                    this.meetingId = meetingId
                    this.signedCount = signedCount
                    this.totalMaterialCount = totalMaterialCount
                    this.totalUserCount = participants.size
                })
            }
        }
 
        if (resultList.isEmpty()) {
            resultList.add(MaterialSignStatusVo().apply {
                this.userId = "all_signed"
                this.meetingId = meetingId
                this.totalMaterialCount = totalMaterialCount
                this.totalUserCount = participants.size
            })
        }
 
        return resultList
    }
 
    override fun pushMeetingInfo(userId: String, meetingId: String, roomId: String?, title: String, body: String): Boolean {
        val meetingVo = meetingRepository.getMeeting(meetingId)
        val room = if (roomId!=null) meetingVMRoomRepository.getRoom(roomId) else null
        meetingVo?.let {
            notificationService.pushMeetingReleaseNotification(it, room, userId, title, body)
            return true
        }
        return false
    }
}