| | |
| | | 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.minio.entity.MinIoConstant; |
| | | import com.sandu.ximon.admin.param.IpVolumeMissionParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.utils.TaskAPIUtils; |
| | | import com.sandu.ximon.admin.vo.TaskMediaFileVO; |
| | | import com.sandu.ximon.admin.vo.TaskTerminalVO; |
| | | import com.sandu.ximon.admin.vo.TaskVO; |
| | | import com.sandu.ximon.dao.bo.IpVolumeMissionBo; |
| | | import com.sandu.ximon.dao.domain.*; |
| | | import com.sandu.ximon.dao.domain.BroadcastV2TaskFile; |
| | | import com.sandu.ximon.dao.domain.BroadcastV2TaskTerminal; |
| | | import com.sandu.ximon.dao.domain.IpVolumeFile; |
| | | import com.sandu.ximon.dao.domain.IpVolumeMission; |
| | | import com.sandu.ximon.dao.enums.OrderByEnums; |
| | | import com.sandu.ximon.dao.mapper.IpVolumeMissionMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | |
| | | import java.math.BigInteger; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | |
| | |
| | | private final BroadcastV2TaskTerminalService broadcastV2TaskTerminalService; |
| | | |
| | | |
| | | /*public boolean add1() { |
| | | return broadcastV2TaskTerminalService.save(); |
| | | }*/ |
| | | public boolean addMission(IpVolumeMissionParam missionparam) { |
| | | |
| | | List<Integer> fileIds = missionparam.getFileIds(); |
| | | List<IpVolumeFile> ipVolumeFiles = ipVolumeFileService.listByIds(fileIds); |
| | | ipVolumeFiles.forEach(file -> { |
| | | if (SecurityUtils.getClientId() != null) { |
| | | //非超管用户 |
| | | if (!SecurityUtils.getUserId().equals(file.getClientId()) && !SecurityUtils.getUserId().equals(file.getUserId())) { |
| | | //用户id和客户id都不匹配 |
| | | throw new BusinessException("文件归属异常,创建任务失败"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | String taskName = missionparam.getMissionName(); |
| | | |
| | |
| | | if (fileEntity == null) { |
| | | throw new BusinessException("fileId为" + fileId + "的文件不存在"); |
| | | } |
| | | // String absolutePath = MinIoConstant.getAbsolutePath( |
| | | // MinIoConstant.BROADCAST_FILE.getBucketName() + fileEntity.getUserId(), |
| | | // fileEntity.getFileName() |
| | | // ); |
| | | |
| | | taskMediaFileVO.setI(i); |
| | | i++; |
| | |
| | | Integer taskId = TaskAPIUtils.addTask(missionparam); |
| | | // Integer taskId = 1111; |
| | | |
| | | boolean flag; |
| | | if (null != taskId && taskId != 0) { |
| | | IpVolumeMission byId = getById(taskId); |
| | | for (BroadcastV2TaskTerminal v2TaskTerminal : taskTerminalEntityList) { |
| | |
| | | broadcastV2TaskTerminalService.deleteByTaskId(taskId); |
| | | broadcastV2TaskTerminalService.saveTaskTerminal(taskTerminalEntityList); |
| | | broadcastV2TaskFileService.saveBatch(taskFileEntityList); |
| | | return true; |
| | | flag = true; |
| | | } else { |
| | | return false; |
| | | flag = false; |
| | | } |
| | | |
| | | /** |
| | | * IP音柱任务添加日志记录开始 |
| | | */ |
| | | String content = "{任务ID:" + taskId |
| | | + ",任务名:" + taskName |
| | | + ",设备ID集合:" + missionparam.getTerminalIds() |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(missionparam.getTerminalIds(), null, "IP音柱任务添加", content); |
| | | /** |
| | | * IP音柱任务添加日志记录结束 |
| | | */ |
| | | |
| | | |
| | | return flag; |
| | | } |
| | | |
| | | public Integer updateMission(Integer taskId, IpVolumeMissionParam missionparam) { |
| | |
| | | taskFileEntity.setFileId(fileId); |
| | | |
| | | IpVolumeFile fileEntity = ipVolumeFileService.getById(fileId); |
| | | 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); |
| | |
| | | |
| | | missionparam.setFiles(taskMediaFileVOS.toArray(new TaskMediaFileVO[taskMediaFileVOS.size()])); |
| | | missionparam.setTerminals(taskTerminalVOList.toArray(new TaskTerminalVO[taskTerminalVOList.size()])); |
| | | System.out.println("---------------------------"); |
| | | |
| | | // 向IP音柱服务器更新任务 |
| | | Integer result = TaskAPIUtils.updateTask(taskId, missionparam); |
| | |
| | | broadcastV2TaskTerminalService.deleteByTaskId(taskId); |
| | | broadcastV2TaskTerminalService.saveBatch(taskTerminalEntityList); |
| | | broadcastV2TaskFileService.saveBatch(taskFileEntityList); |
| | | return 0; |
| | | |
| | | } else { |
| | | return result; |
| | | } |
| | | /** |
| | | * IP音柱任务修改 日志记录开始 |
| | | */ |
| | | String content = "{任务ID:" + taskId |
| | | + ",任务名:" + taskName |
| | | + ",设备ID集合:" + missionparam.getTerminalIds() |
| | | + ",任务编辑结果:" + result |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(missionparam.getTerminalIds(), null, "IP音柱任务修改", content); |
| | | /** |
| | | * IP音柱任务修改 日志记录结束 |
| | | */ |
| | | return result; |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | broadcastV2TaskFileService.deleteByTaskId(taskId); |
| | | broadcastV2TaskTerminalService.deleteByTaskId(taskId); |
| | | // broadcastV2TaskTerminalService.removeById(taskId); |
| | | return 0; |
| | | } else { |
| | | return del; |
| | | } |
| | | |
| | | /** |
| | | * IP音柱任务删除 日志记录开始 |
| | | */ |
| | | String content = "{删除的任务ID:" + taskId |
| | | + ",任务删除结果:" + del |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "IP音柱任务删除", content); |
| | | /** |
| | | * IP音柱任务删除 日志记录结束 |
| | | */ |
| | | |
| | | |
| | | return del; |
| | | } |
| | | |
| | | |
| | | public List<IpVolumeMissionBo> missionList(BaseConditionVO baseConditionVO, String keyword) { |
| | | // PageHelper.startPage(baseConditionVO.getPageNo(),baseConditionVO.getPageSize()); |
| | | boolean r = clientService.findClientId(); //ture代表有上级客户 查询通过userID |
| | | public List<IpVolumeMissionBo> missionList(BaseConditionVO baseConditionVO, String keyword, Integer order, Integer seq) { |
| | | |
| | | |
| | | //排序字段 |
| | | String orderByResult = "task_id"; |
| | | //正序、倒叙 |
| | | String orderBySeq = "ASC"; |
| | | if (order != null) { |
| | | switch (order) { |
| | | case 1: |
| | | orderByResult = OrderByEnums.IP_VOLUME_MISSION_CREATE_TIME.getCode(); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | if (seq != null) { |
| | | switch (seq) { |
| | | case 1: |
| | | orderBySeq = " ASC"; |
| | | break; |
| | | case 2: |
| | | orderBySeq = " DESC"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | //排序方式 |
| | | String orderBy = orderByResult + " " + orderBySeq; |
| | | if (baseConditionVO != null) { |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy); |
| | | } |
| | | |
| | | List<IpVolumeMissionBo> ipVolumeMissionBos = new ArrayList<>(); |
| | | LambdaQueryWrapper<IpVolumeMission> eq = new LambdaQueryWrapper<>(); |
| | | LambdaQueryWrapper<IpVolumeMission> eq = Wrappers.lambdaQuery(IpVolumeMission.class); |
| | | |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | if (r) { |
| | | eq = Wrappers.lambdaQuery(IpVolumeMission.class).eq(IpVolumeMission::getUserId, SecurityUtils.getUserId()); |
| | | } else { |
| | | eq = Wrappers.lambdaQuery(IpVolumeMission.class).eq(IpVolumeMission::getClientId, SecurityUtils.getUserId()); |
| | | |
| | | //不是超管 |
| | | if (SecurityUtils.getClientId() != null) { |
| | | eq = eq.eq(IpVolumeMission::getUserId, SecurityUtils.getUserId()).or(w -> { |
| | | w.eq(IpVolumeMission::getClientId, SecurityUtils.getUserId()); |
| | | }); |
| | | } |
| | | if (!keyword.isEmpty()) { |
| | | if (keyword != null && !keyword.isEmpty()) { |
| | | eq.like(IpVolumeMission::getMissionName, keyword); |
| | | } |
| | | List<IpVolumeMission> list = list(eq); |
| | | |
| | | |
| | | // ipVolumeMissionBos = ipVolumeMissionMapper.listAllByClientId(); |
| | | |
| | | for (IpVolumeMission mission : list) { |
| | | List<String> fileName = broadcastV2TaskFileService.findByTaskid(mission.getTaskId()); |
| | |
| | | BeanUtils.copyProperties(mission, bo); |
| | | bo.setFileNames(fileName); |
| | | ipVolumeMissionBos.add(bo); |
| | | |
| | | } |
| | | |
| | | // for (IpVolumeMissionBo missionBo: ipVolumeMissionBos) { |
| | | // missionBo.setFileNames(broadcastV2TaskFileService.findByTaskid(missionBo.getTaskId())); |
| | | // |
| | | // } |
| | | |
| | | return ipVolumeMissionBos; |
| | | //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 (SecurityUtils.getClientId() != null) { |
| | | if (clientService.findClientId()) { |
| | | if (byId.getUserId() != SecurityUtils.getUserId()) { |
| | | if (!byId.getUserId().equals(SecurityUtils.getUserId())) { |
| | | throw new BusinessException("任务归属错误"); |
| | | } |
| | | |
| | | } else { |
| | | if (byId.getClientId() != SecurityUtils.getUserId()) { |
| | | if (!byId.getClientId().equals(SecurityUtils.getUserId()) && !byId.getUserId().equals(SecurityUtils.getUserId())) { |
| | | throw new BusinessException("任务归属错误"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | task.setWeeks("0" + Integer.toBinaryString(task.getWeek())); |
| | | // byId.setWeeks("0" + Integer.toBinaryString(byId.getWeek())); |
| | | |
| | | byId.setWeeks("0" + Integer.toBinaryString(byId.getWeek())); |
| | | |
| | | // IpVolumeMissionBo bo = new IpVolumeMissionBo(); |
| | | 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()||taskTerminals.isEmpty()){ |
| | | // throw new BusinessException(""); |
| | | // } |
| | | if(!taskFiles.isEmpty()){ |
| | | taskFiles.forEach( |
| | | fileId->{ |
| | | |
| | | if (!taskFiles.isEmpty()) { |
| | | taskFiles.forEach( |
| | | fileId -> { |
| | | // IpVolumeFile volumeFile = ipVolumeFileService.getById(fileId.getFileId()); |
| | | // if(volumeFile==null){ |
| | | // throw new BusinessException("任务文件不存在"); |
| | | // } |
| | | byId.getFileIds().add(fileId.getFileId()); |
| | | } |
| | | ); |
| | | task.getFileIds().add(fileId.getFileId()); |
| | | // byId.getFileIds().add(fileId.getFileId()); |
| | | } |
| | | ); |
| | | |
| | | } |
| | | if(!taskTerminals.isEmpty()){ |
| | | if (!taskTerminals.isEmpty()) { |
| | | taskTerminals.forEach( |
| | | terminalId->{ |
| | | terminalId -> { |
| | | // BroadcastTerminalV2Entity v2Entity = ipVolumeService.getById(terminalId.getTerminalId()); |
| | | // if(v2Entity==null){ |
| | | // throw new BusinessException("该任务暂无设备使用"); |
| | | // } |
| | | byId.getTerminalIds().add(terminalId.getTerminalId()); |
| | | task.getTerminalIds().add(terminalId.getTerminalId()); |
| | | // byId.getTerminalIds().add(terminalId.getTerminalId()); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | return byId; |
| | | |
| | | System.out.println(JSON.toJSONString(task)); |
| | | System.out.println(task); |
| | | return task; |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 推送 |
| | | * |
| | | * @param taskId |
| | | * @return |
| | | */ |
| | | public boolean playTask(Integer taskId) { |
| | | return TaskAPIUtils.playTask(taskId); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 停止 |
| | | * |
| | | * @param taskId |
| | | * @return |
| | | */ |
| | | public boolean stopTask(Integer taskId) { |
| | | return TaskAPIUtils.stopTask(taskId); |
| | | } |
| | | |
| | | /** |
| | | * 暂停 |
| | | * |
| | | * @param taskId |
| | | * @return |
| | | */ |
| | | public boolean pauseTask(Integer taskId) { |
| | | return TaskAPIUtils.pauseTask(taskId); |
| | | } |
| | | |
| | | /** |
| | | * 继续 |
| | | * |
| | | * @param taskId |
| | | * @return |
| | | */ |
| | | public boolean continueTask(Integer taskId) { |
| | | return TaskAPIUtils.continueTask(taskId); |
| | | } |
| | | } |