广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
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
package cn.huge.module.meet.service;
 
import cn.huge.base.common.constant.FileConsts;
import cn.huge.base.common.exception.ServiceException;
import cn.huge.base.common.utils.DateUtils;
import cn.huge.base.common.utils.IdUtils;
import cn.huge.base.common.utils.SpringContextUtil;
import cn.huge.base.common.utils.ThreadPoolUtils;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.constant.BaseConsts;
import cn.huge.module.mediate.constant.MeetBaseConstsEnum;
import cn.huge.module.meet.dao.mapper.MeetVideoMapper;
import cn.huge.module.meet.domain.po.MeetCloud;
import cn.huge.module.meet.domain.po.MeetVideo;
import cn.huge.module.xylink.constant.XylinkConsts;
import cn.huge.module.xylink.domain.dto.XylinkVedioDTO;
import cn.huge.module.xylink.domain.po.XylinkVideo;
import cn.huge.module.xylink.service.XylinkVideoService;
import cn.huge.module.xylink.utils.XylinkUtils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.sf.json.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @author liyj
 * @version 1.0.0
 * @title: 云会议录制视频表业务逻辑处理
 * @Description JPA的单表数据查询以由BaseService完成
 * @company hugeinfo
 * @Time 2022-05-09 16:18:58
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class MeetVideoService extends ServiceImpl<MeetVideoMapper, MeetVideo> {
 
    @Autowired
    private MeetVideoMapper mapper;
 
    @Autowired
    private MeetCloudService meetCloudService;
    @Autowired
    private XylinkVideoService xylinkVideoService;
 
    @Autowired
    private UtilsClientImpl utilsClient;
 
    /**
     * 更新对象
     *
     * @param entity 对象
     */
    public void updateMeetVideo(MeetVideo entity) {
        try {
            mapper.updateMeetVideo(entity);
        } catch (Exception e) {
            log.error("service方法[MeetVideoService.updateMeetVideo]调用异常:" + e, e);
            throw new ServiceException("MeetVideoService.updateMeetVideo", e);
        }
    }
 
    /**
     * 条件更新对象
     *
     * @param entity 对象
     * @param terms  条件
     */
    public void updateMeetVideoTerms(MeetVideo entity, Map<String, Object> terms) {
        try {
            mapper.updateMeetVideoTerms(entity, terms);
        } catch (Exception e) {
            log.error("service方法[MeetVideoService.updateMeetVideoTerms]调用异常:" + e, e);
            throw new ServiceException("MeetVideoService.updateMeetVideoTerms", e);
        }
    }
 
    /**
     * 根据编号物理删除
     *
     * @param id 查询条件集合
     */
    public void deleteMeetVideo(String id) {
        try {
            mapper.deleteMeetVideo(id);
        } catch (Exception e) {
            log.error("service方法[MeetVideoService.deleteMeetVideo]调用异常:" + e, e);
            throw new ServiceException("MeetVideoService.deleteMeetVideo", e);
        }
    }
 
    /**
     * 按条件查询
     *
     * @param terms 条件
     * @return List
     */
    public List<MeetVideo> listTerms(Map<String, Object> terms) {
        return mapper.listTerms(terms);
    }
 
    /**
     * 按条件统计
     *
     * @param terms 条件
     * @return long
     */
    public long countTerms(Map<String, Object> terms) {
        return mapper.countTerms(terms);
    }
 
    /**
     * 按条件分页查询
     *
     * @param page  分页对象
     * @param terms 条件
     * @return Page
     */
    public Page<MeetVideo> pageQuery(PageRequest page, Map<String, Object> terms) {
        long total = mapper.countTerms(terms);
        List<MeetVideo> content = mapper.pageTerms(page, terms);
        return new PageImpl<MeetVideo>(content, page, total);
    }
 
    /**
     * 新增或更新对象
     *
     * @param meetVideo 实体对象
     */
    public void saveMeetVideo(MeetVideo meetVideo) {
        try {
            Date nowDate = DateUtils.getNowDate();
            // 判断是否新增
            if (IdUtils.checkNewId(meetVideo.getId())) {
                meetVideo.setId(utilsClient.getNewTimeId());
                meetVideo.setCreateTime(nowDate);
            }
            meetVideo.setUpdateTime(nowDate);
            this.saveOrUpdate(meetVideo);
        } catch (Exception e) {
            log.error("service方法[MeetVideoService.saveMeetVideo]调用异常:" + e, e);
            throw new ServiceException("MeetVideoService.saveMeetVideo", e);
        }
    }
 
    /**
     * 保存云会议录制视频
     *
     * @param caseId   纠纷编号
     * @param meetType 会议类型
     * @return List<MeetVideo>
     */
    public void saveCloudVideo(String caseId, String meetType, boolean rightNow) {
        try {
            // 异步转存小鱼云会议录制视频到多元化平台
            if(rightNow){
                ThreadPoolUtils.executor(new AsynReSaveCloudVideo(caseId, meetType));
            }else {
                ThreadPoolUtils.executor(new AsynSaveCloudVideo(caseId, meetType));
            }
 
        } catch (Exception e) {
            log.error("service方法[MeetVideoService.saveCloudVideo]调用异常:" + e, e);
            throw new ServiceException("MeetVideoService.saveCloudVideo", e);
        }
    }
 
    /**
     * 保存云会议录制视频-异步实现
     */
    public class AsynSaveCloudVideo implements Runnable {
        private String caseId;
        private String meetType;
 
        public AsynSaveCloudVideo(String caseId, String meetType) {
            this.caseId = caseId;
            this.meetType = meetType;
        }
 
 
        @Override
        public void run() {
            try {
                log.info("开始保存视频...先等待5分钟...");
                Thread.sleep(60 * 5000);
                Date nowDate = DateUtils.getNowDate();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                // 保存云会议录制视频
                List<MeetCloud> meetCloudList = meetCloudService.listByCaseId(caseId, meetType);
                if (CollectionUtils.isNotEmpty(meetCloudList)) {
                    log.info("save saveVideo meetCloudList {}", JSON.toJSONString(meetCloudList));
                    MeetCloud meetCloud = meetCloudList.get(0);
                    List<XylinkVedioDTO> xylinkVedioDTOList = XylinkUtils.getMeetingVideos(meetCloud.getRoomNo());
                    log.info("save saveVideo xylinkVedioDTOList {}", JSON.toJSONString(xylinkVedioDTOList));
                    if (CollectionUtils.isNotEmpty(xylinkVedioDTOList)) {
                        for (XylinkVedioDTO xylinkVedioDTO : xylinkVedioDTOList) {
                            MeetVideo meetVideo = new MeetVideo();
                            meetVideo.setId(xylinkVedioDTO.getVodId());
                            meetVideo.setCaseId(caseId);
                            meetVideo.setMeetId(meetCloud.getMeetId());
                            meetVideo.setMeetType(meetCloud.getMeetType());
                            meetVideo.setMeetTypeName(meetCloud.getMeetTypeName());
                            meetVideo.setColudId(meetCloud.getId());
                            meetVideo.setRoomNo(xylinkVedioDTO.getMeetingRoomNumber());
                            meetVideo.setVodId(xylinkVedioDTO.getVodId());
                            meetVideo.setVideoName(meetCloud.getRoomName() + MeetBaseConstsEnum.getDes(meetType) + "录制视频_" + sdf.format(xylinkVedioDTO.getStartTime()));
                            meetVideo.setDisplayName(xylinkVedioDTO.getDisplayName());
                            meetVideo.setStartTime(xylinkVedioDTO.getStartTime());
                            meetVideo.setEndTime(xylinkVedioDTO.getEndTime());
                            meetVideo.setFileSize(xylinkVedioDTO.getFileSize());
                            meetVideo.setNemoNo(xylinkVedioDTO.getNemoNumber());
                            if (XylinkUtils.VOD_METADATA_TYPE_4.equals(xylinkVedioDTO.getVodMetadataType())) {
                                meetVideo.setRecordStatus(MeetBaseConstsEnum.RECORD_STATUS_1.getIndex());
                                meetVideo.setRecordStatusName(MeetBaseConstsEnum.RECORD_STATUS_1.getDes());
                            } else {
                                meetVideo.setRecordStatus(MeetBaseConstsEnum.RECORD_STATUS_2.getIndex());
                                meetVideo.setRecordStatusName(MeetBaseConstsEnum.RECORD_STATUS_2.getDes());
                            }
                            log.info("save saveVideo xylinkVedioDTO {}", xylinkVedioDTO.getDownloadUrl());
                            meetVideo.setDownUrl(xylinkVedioDTO.getDownloadUrl());
                            meetVideo.setCustId(meetCloud.getCustId());
                            meetVideo.setCreateTime(nowDate);
                            meetVideo.setUpdateTime(nowDate);
                            // 小鱼云会议录制视频转存到多元化平台
                            String playUrl = xylinkVideoService.saveVideoToDyh(meetVideo.getVodId(), meetVideo.getVideoName() + FileConsts._mp4);
                            if (StringUtils.isNotEmpty(playUrl)) {
                                // 转存成功
                                meetVideo.setPlayUrl(playUrl);
                                meetVideo.setIsDownload(1);
                            } else {
                                // 转存失败,保存小鱼云会议录制视频记录
                                XylinkVideo xylinkVideo = new XylinkVideo();
                                String vodId = xylinkVedioDTO.getVodId();
                                xylinkVideo.setId(vodId);
                                xylinkVideo.setVodId(vodId);
                                xylinkVideo.setDisplayName(xylinkVedioDTO.getDisplayName());
                                xylinkVideo.setStartTime(xylinkVedioDTO.getStartTime());
                                xylinkVideo.setEndTime(xylinkVedioDTO.getEndTime());
                                xylinkVideo.setFileSize(xylinkVedioDTO.getFileSize());
                                xylinkVideo.setMeetingRoomNumber(xylinkVedioDTO.getMeetingRoomNumber());
                                xylinkVideo.setNemoNumber(xylinkVedioDTO.getNemoNumber());
                                xylinkVideo.setVodMetadataType(xylinkVedioDTO.getVodMetadataType());
                                xylinkVideo.setTranscriptionId(xylinkVedioDTO.getTranscriptionId());
                                xylinkVideo.setTranscriptionTxtFileUrl(xylinkVedioDTO.getTranscriptionTxtFileUrl());
                                xylinkVideo.setPlayUrl(XylinkUtils.getDownloadUrl(vodId));
                                xylinkVideo.setDownloadUrl(XylinkUtils.getDownloadUrl(vodId));
                                xylinkVideo.setStorage(XylinkConsts.STORAGE_1);
                                xylinkVideo.setCreateTime(nowDate);
                                xylinkVideo.setUpdateTime(nowDate);
                                xylinkVideoService.saveOrUpdate(xylinkVideo);
                                // 设置小鱼访问路径
                                meetVideo.setPlayUrl(xylinkVedioDTO.getPlayUrl());
                                meetVideo.setIsDownload(0);
                            }
                            mapper.insert(meetVideo);
                        }
                    }
                }
                log.info("结束保存视频...");
            } catch (Exception e) {
                log.error("service方法[MeetVideoService.AsynSaveCloudVideo]调用异常:" + e, e);
                throw new ServiceException("MeetVideoService.AsynSaveCloudVideo", e);
            }
        }
    }
 
    public class AsynReSaveCloudVideo implements Runnable {
        private String caseId;
        private String meetType;
 
 
        public AsynReSaveCloudVideo(String caseId, String meetType) {
            this.caseId = caseId;
            this.meetType = meetType;
 
        }
 
 
        @Override
        public void run() {
            try {
                Date nowDate = DateUtils.getNowDate();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                // 保存云会议录制视频
                List<MeetCloud> meetCloudList = meetCloudService.listByCaseId(caseId, meetType);
                if (CollectionUtils.isNotEmpty(meetCloudList)) {
                    log.info("save saveVideo meetCloudList {}", JSON.toJSONString(meetCloudList));
                    MeetCloud meetCloud = meetCloudList.get(0);
                    List<XylinkVedioDTO> xylinkVedioDTOList = XylinkUtils.getMeetingVideos(meetCloud.getRoomNo());
                    log.info("save saveVideo xylinkVedioDTOList {}", JSON.toJSONString(xylinkVedioDTOList));
                    if (CollectionUtils.isNotEmpty(xylinkVedioDTOList)) {
                        for (XylinkVedioDTO xylinkVedioDTO : xylinkVedioDTOList) {
                            MeetVideo meetVideo = mapper.selectById(xylinkVedioDTO.getVodId());
                            if (meetVideo != null) {
                                String playUrl = xylinkVideoService.saveVideoToDyh(meetVideo.getVodId(), meetVideo.getVideoName() + FileConsts._mp4);
                                if (StringUtils.isNotEmpty(playUrl)) {
                                    // 转存成功
                                    meetVideo.setPlayUrl(playUrl);
                                    meetVideo.setUpdateTime(new Date());
                                    meetVideo.setIsDownload(1);
                                    mapper.updateMeetVideo(meetVideo);
                                }
                            }
 
                        }
                    }
                }
                log.info("结束保存视频...");
            } catch (Exception e) {
                log.error("service方法[MeetVideoService.AsynSaveCloudVideo]调用异常:" + e, e);
                throw new ServiceException("MeetVideoService.AsynSaveCloudVideo", e);
            }
        }
    }
 
    /**
     * 查询云会议录制视频
     *
     * @param caseId   纠纷编号
     * @param meetType 会议类型
     * @return List<MeetVideo>
     */
    public List<MeetVideo> listByCase(String caseId, String meetType) {
        try {
            QueryWrapper<MeetVideo> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("case_id", caseId).eq("meet_type", meetType);
            List<MeetVideo> meetVideoList = this.list(queryWrapper);
            if (CollectionUtils.isEmpty(meetVideoList)) {
                QueryWrapper<MeetVideo> meetVideoQueryWrapper = new QueryWrapper<>();
                meetVideoQueryWrapper.eq("case_id", caseId).eq("meet_type", meetType);
                meetVideoList = mapper.selectList(meetVideoQueryWrapper);
            }
            return meetVideoList;
        } catch (Exception e) {
            log.error("service方法[MeetVideoService.listByCase]调用异常:" + e, e);
            throw new ServiceException("MeetVideoService.listByCase", e);
        }
    }
 
    public List<MeetVideo> getDownloadVideo() {
        return mapper.getDownloadVideo();
    }
 
}