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 { @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 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 listTerms(Map terms) { return mapper.listTerms(terms); } /** * 按条件统计 * * @param terms 条件 * @return long */ public long countTerms(Map terms) { return mapper.countTerms(terms); } /** * 按条件分页查询 * * @param page 分页对象 * @param terms 条件 * @return Page */ public Page pageQuery(PageRequest page, Map terms) { long total = mapper.countTerms(terms); List content = mapper.pageTerms(page, terms); return new PageImpl(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 */ 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 meetCloudList = meetCloudService.listByCaseId(caseId, meetType); if (CollectionUtils.isNotEmpty(meetCloudList)) { log.info("save saveVideo meetCloudList {}", JSON.toJSONString(meetCloudList)); MeetCloud meetCloud = meetCloudList.get(0); List 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 meetCloudList = meetCloudService.listByCaseId(caseId, meetType); if (CollectionUtils.isNotEmpty(meetCloudList)) { log.info("save saveVideo meetCloudList {}", JSON.toJSONString(meetCloudList)); MeetCloud meetCloud = meetCloudList.get(0); List 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 */ public List listByCase(String caseId, String meetType) { try { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("case_id", caseId).eq("meet_type", meetType); List meetVideoList = this.list(queryWrapper); if (CollectionUtils.isEmpty(meetVideoList)) { QueryWrapper 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 getDownloadVideo() { return mapper.getDownloadVideo(); } }