| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.config.MinIoConstant; |
| | | import com.sandu.ximon.admin.param.IpVolumeMissionParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.TaskAPIUtils; |
| | |
| | | |
| | | import java.math.BigInteger; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | |
| | |
| | | public class IpVolumeMissionService extends BaseServiceImpl<IpVolumeMissionMapper, IpVolumeMission> { |
| | | private final IpVolumeMissionMapper ipVolumeMissionMapper; |
| | | private final ClientService clientService; |
| | | private final IpVolumeService ipVolumeService; |
| | | private final IpVolumeFileService ipVolumeFileService; |
| | | private final BroadcastV2TaskFileService broadcastV2TaskFileService; |
| | | private final BroadcastV2TaskTerminalService broadcastV2TaskTerminalService; |
| | |
| | | // 封装播放文件列表 |
| | | List<TaskMediaFileVO> taskMediaFileVOS = new ArrayList<>(); |
| | | List<BroadcastV2TaskFile> taskFileEntityList = new ArrayList<>(); |
| | | int i = 1; |
| | | int i = 6666; |
| | | for (Integer fileId : new HashSet<>(missionparam.getFileIds())) { |
| | | TaskMediaFileVO taskMediaFileVO = new TaskMediaFileVO(); |
| | | BroadcastV2TaskFile taskFileEntity = new BroadcastV2TaskFile(); |
| | |
| | | taskFileEntity.setFileId(fileId); |
| | | |
| | | IpVolumeFile fileEntity = ipVolumeFileService.getById(fileId); |
| | | if (fileEntity == null) { |
| | | throw new BusinessException("fileId为" + fileId + "的文件不存在"); |
| | | } |
| | | // String absolutePath = MinIoConstant.getAbsolutePath( |
| | | // MinIoConstant.BROADCAST_FILE.getBucketName() + fileEntity.getUserId(), |
| | | // fileEntity.getFileName() |
| | |
| | | mission.setOffDate(missionparam.getOffDate()); |
| | | mission.setWeek(Integer.parseInt(missionparam.getWeek(), 2));//时间由二进制字符串转换为十进制 |
| | | mission.setMissionVolume(missionparam.getMissionVolume()); |
| | | //mission.setMissionFileUrl(missionparam.getFiles().toString()); |
| | | mission.setNumberInPlay(missionparam.getTerminals().length); |
| | | /*TaskTerminalVO[] terminals = missionparam.getTerminals();*/ |
| | | |
| | | |
| | | System.out.println(save(mission)); |
| | | System.out.println("----------------------------------------------------------"); |
| | |
| | | mission.setMissionVolume(missionparam.getMissionVolume()); |
| | | mission.setMissionFileUrl(missionparam.getFiles().toString()); |
| | | mission.setNumberInPlay(missionparam.getTerminals().length); |
| | | /* System.out.println(updateById(mission)); |
| | | System.out.println("----------------------------------------------------------");*/ |
| | | } |
| | | broadcastV2TaskFileService.deleteByTaskId(taskId); |
| | | broadcastV2TaskTerminalService.deleteByTaskId(taskId); |
| | | // broadcastV2TaskTerminalService.removeById(taskId); |
| | | broadcastV2TaskTerminalService.saveTaskTerminal(taskTerminalEntityList); |
| | | broadcastV2TaskFileService.saveBatch(taskFileEntityList); |
| | | // broadcastV2TaskTerminalService.saveBatch(taskTerminalEntityList); |
| | | // broadcastV2TaskTerminalService.insertTaskTerminal(taskTerminalEntityList); |
| | | |
| | | return true; |
| | | } else { |
| | | return false; |
| | |
| | | taskFileEntity.setFileId(fileId); |
| | | |
| | | IpVolumeFile fileEntity = ipVolumeFileService.getById(fileId); |
| | | String absolutePath = MinIoConstant.getAbsolutePath( |
| | | MinIoConstant.BROADCAST_FILE.getBucketName() + fileEntity.getUserId(), |
| | | fileEntity.getFileName() |
| | | ); |
| | | // String absolutePath = MinIoConstant.getAbsolutePath( |
| | | // MinIoConstant.BROADCAST_FILE.getBucketName() + fileEntity.getUserId(), |
| | | // fileEntity.getFileName() |
| | | // ); |
| | | |
| | | taskMediaFileVO.setI(i); |
| | | i++; |
| | | taskMediaFileVO.setT(0); |
| | | taskMediaFileVO.setN(absolutePath); |
| | | taskMediaFileVO.setN(fileEntity.getFileUrl()); |
| | | taskMediaFileVO.setS(BigInteger.valueOf(fileEntity.getOriginSize())); |
| | | |
| | | taskMediaFileVOS.add(taskMediaFileVO); |
| | |
| | | return -1; |
| | | } |
| | | removeById(taskId); |
| | | broadcastV2TaskFileService.removeById(taskId); |
| | | broadcastV2TaskTerminalService.removeById(taskId); |
| | | broadcastV2TaskFileService.deleteByTaskId(taskId); |
| | | broadcastV2TaskTerminalService.deleteByTaskId(taskId); |
| | | // broadcastV2TaskTerminalService.removeById(taskId); |
| | | return 0; |
| | | } else { |
| | | return del; |
| | |
| | | //return new ArrayList<>(); |
| | | } |
| | | |
| | | public IpVolumeMission getByTaskId(Integer taskId) { |
| | | public TaskVO getByTaskId(Integer taskId) { |
| | | TaskVO task = TaskAPIUtils.getTask(taskId); |
| | | if (task == null) { |
| | | throw new BusinessException("服务器未找到该任务"); |
| | |
| | | if (byId == null) { |
| | | throw new BusinessException("本地未找到该任务"); |
| | | } |
| | | if (SecurityUtils.getClientId() != null) { |
| | | if (clientService.findClientId()) { |
| | | if (byId.getUserId() != SecurityUtils.getUserId()) { |
| | | throw new BusinessException("任务归属错误"); |
| | | } |
| | | |
| | | byId.setWeeks("0" + Integer.toBinaryString(byId.getWeek())); |
| | | } else { |
| | | if (byId.getClientId() != SecurityUtils.getUserId()) { |
| | | throw new BusinessException("任务归属错误"); |
| | | } |
| | | } |
| | | |
| | | return byId; |
| | | |
| | | } |
| | | task.setWeeks("0" + Integer.toBinaryString(byId.getWeek())); |
| | | // byId.setWeeks("0" + Integer.toBinaryString(byId.getWeek())); |
| | | |
| | | List<BroadcastV2TaskFile> taskFiles = broadcastV2TaskFileService.list(Wrappers.lambdaQuery(BroadcastV2TaskFile.class) |
| | | .eq(BroadcastV2TaskFile::getTaskId, taskId)); |
| | | List<BroadcastV2TaskTerminal> taskTerminals = broadcastV2TaskTerminalService.list(Wrappers.lambdaQuery(BroadcastV2TaskTerminal.class) |
| | | .eq(BroadcastV2TaskTerminal::getTaskId, taskId)); |
| | | |
| | | if (!taskFiles.isEmpty()) { |
| | | taskFiles.forEach( |
| | | fileId -> { |
| | | // IpVolumeFile volumeFile = ipVolumeFileService.getById(fileId.getFileId()); |
| | | // if(volumeFile==null){ |
| | | // throw new BusinessException("任务文件不存在"); |
| | | // } |
| | | task.getFileIds().add(fileId.getFileId()); |
| | | // byId.getFileIds().add(fileId.getFileId()); |
| | | } |
| | | ); |
| | | |
| | | } |
| | | if (!taskTerminals.isEmpty()) { |
| | | taskTerminals.forEach( |
| | | terminalId -> { |
| | | // BroadcastTerminalV2Entity v2Entity = ipVolumeService.getById(terminalId.getTerminalId()); |
| | | // if(v2Entity==null){ |
| | | // throw new BusinessException("该任务暂无设备使用"); |
| | | // } |
| | | task.getTerminalIds().add(terminalId.getTerminalId()); |
| | | // byId.getTerminalIds().add(terminalId.getTerminalId()); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | // Map map=new HashMap(); |
| | | // map.put("本地",byId); |
| | | // map.put("服务器",task); |
| | | |
| | | System.out.println(JSON.toJSONString(task)); |
| | | System.out.println(task); |
| | | return task; |
| | | |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public boolean stopTask(Integer taskId) { |
| | | return TaskAPIUtils.stopTask(taskId); |
| | | } |
| | | } |