| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | import com.sandu.ximon.admin.config.VnnoxConstant; |
| | | import com.sandu.ximon.admin.dto.PlanDto; |
| | | import com.sandu.ximon.admin.dto.SchedulesDTO; |
| | | import com.sandu.ximon.admin.dto.nova.PlayerProgram; |
| | | import com.sandu.ximon.admin.dto.nova.ProgramSchedule; |
| | | import com.sandu.ximon.admin.entity.Plans; |
| | | import com.sandu.ximon.admin.dto.nova.*; |
| | | import com.sandu.ximon.admin.param.PlayPlanParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.LogUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.utils.VnnoxAPIUtil; |
| | | import com.sandu.ximon.admin.utils.VnnoxProgramAPIUtil; |
| | |
| | | import com.sandu.ximon.admin.vo.NovaOpenVO; |
| | | import com.sandu.ximon.admin.vo.NovaPushResultVO; |
| | | import com.sandu.ximon.admin.vo.PlansVO; |
| | | import com.sandu.ximon.dao.domain.LEDProgram; |
| | | import com.sandu.ximon.dao.domain.LedPlayerEntity; |
| | | import com.sandu.ximon.dao.domain.PlayPlanNv; |
| | | import com.sandu.ximon.dao.domain.PushToLed; |
| | | import com.sandu.ximon.dao.domain.*; |
| | | import com.sandu.ximon.dao.mapper.PlayPlanNvMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 播放计划 |
| | |
| | | private VnnoxAPIUtil vnnoxAPIUtil; |
| | | private final LEDProgramService ledProgramService; |
| | | private final ClientService clientService; |
| | | private final LEDProgramFileService fileService; |
| | | |
| | | public boolean addPlan(PlayPlanParam playPlanParam) { |
| | | |
| | |
| | | + playPlan.getName() |
| | | + ", 播放计划计划内容:" |
| | | + JSON.toJSONString(playPlan) |
| | | + ", 定时任务内容:" + playPlan.getSchedule() |
| | | + ", 定时任务内容:" + playPlan.getSchedules() |
| | | + "}," + " 推送结果:" + save |
| | | + " }"; |
| | | if (playPlanParam.getId() == null) { |
| | |
| | | return removeByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * 推送定时节目 |
| | | * |
| | | * @param planId |
| | | * @param nova |
| | | * @return |
| | | */ |
| | | public Map<String, Object> pushToLed(Long planId, List<NovaPushResultVO> nova) { |
| | | if (nova == null) { |
| | | throw new BusinessException("请选择正确的LED屏"); |
| | | } |
| | | PushToLed pushToLed = playPlanMapper.pushToLed(planId); |
| | | if (pushToLed.getPages() == null) { |
| | | throw new BusinessException("节目内容丢失"); |
| | | } |
| | | PlayPlanNv byId = getById(planId); |
| | | if (pushToLed == null) { |
| | | throw new BusinessException("未找到该播放计划"); |
| | |
| | | nova.forEach(n -> { |
| | | playerIds.add(n.getPlayerId()); |
| | | }); |
| | | |
| | | PlayerProgram program = new PlayerProgram(); |
| | | program.setPlayerIds(playerIds); |
| | | |
| | | //获取节目实体 |
| | | program.setPages(JSON.parseObject(pushToLed.getPages(), List.class)); |
| | | |
| | | |
| | | //获取节目定时实体 |
| | | program.setSchedule((JSON.parseObject(pushToLed.getSchedule(), Map.class))); |
| | | Map map = JSON.parseObject(pushToLed.getSchedule(), Map.class); |
| | | map.get("plans"); |
| | | List<Plans> plans = JSON.parseArray(map.get("plans").toString(), Plans.class); |
| | | plans.forEach(p -> { |
| | | //删除后两位字符串 |
| | | p.setStartTime(p.getStartTime().substring(0, p.getStartTime().length() - 3)); |
| | | p.setEndTime(p.getEndTime().substring(0, p.getEndTime().length() - 3)); |
| | | }); |
| | | System.out.println(plans + "plans11111"); |
| | | map.put("plans", plans); |
| | | program.setSchedule(map); |
| | | |
| | | program.setNoticeUrl(VnnoxConstant.NOTIFY_URL); |
| | | VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program); |
| | | vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(pushToLed.getVolume()).intValue()); |
| | | |
| | | List<String> success = new ArrayList<>(); |
| | | List<String> fail = new ArrayList<>(); |
| | | if (vnnoxResultResponse.getData() != null) { |
| | | success = vnnoxResultResponse.getData().getSuccess(); |
| | | fail = vnnoxResultResponse.getData().getFail(); |
| | | } |
| | | |
| | | //拼接成功失败的结果 |
| | | Map<String, Object> result = new HashMap<>(); |
| | | List<NovaPushResultVO> successList = new ArrayList<>(); |
| | | List<NovaPushResultVO> faileList = new ArrayList<>(); |
| | | List<String> finalSuccess = success; |
| | | List<String> finalFail = fail; |
| | | nova.forEach(n -> { |
| | | if (finalSuccess.contains(n.getPlayerId())) { |
| | | successList.add(n); |
| | | } else if (finalFail.contains(n.getPlayerId())) { |
| | | faileList.add(n); |
| | | |
| | | |
| | | List<List<String>> split = CollectionUtil.split(playerIds, 100); |
| | | for (List<String> playIds : split) { |
| | | PlayerProgram program = new PlayerProgram(); |
| | | program.setPlayerIds(playIds); |
| | | |
| | | //获取节目实体 |
| | | |
| | | List<PlayerPage> programDtos = JSON.parseArray(pushToLed.getPages(), PlayerPage.class); |
| | | programDtos.forEach( |
| | | programDto -> { |
| | | programDto.getWidgets().forEach( |
| | | widget -> { |
| | | if (PlayerWidgetType.PICTURE.equals(widget.getType()) || PlayerWidgetType.VIDEO.equals(widget.getType())) { |
| | | String url = widget.getUrl(); |
| | | LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url)); |
| | | if (one == null) { |
| | | throw new BusinessException("节目文件已失效"); |
| | | } |
| | | widget.setMd5(one.getMd5()); |
| | | widget.setSize(Long.parseLong(one.getSize())); |
| | | } |
| | | } |
| | | ); |
| | | } |
| | | ); |
| | | |
| | | program.setPages(programDtos); |
| | | |
| | | //获取节目定时实体 |
| | | PlayerSchedule playerSchedule = JSON.parseObject(pushToLed.getSchedule(), PlayerSchedule.class); |
| | | //删除时间的后三位 |
| | | List<PlayerSchedulePlans> plans = playerSchedule.getPlans(); |
| | | plans.forEach( |
| | | plan -> { |
| | | plan.setStartTime(plan.getStartTime().substring(0, plan.getStartTime().length() - 3)); |
| | | plan.setEndTime(plan.getEndTime().substring(0, plan.getEndTime().length() - 3)); |
| | | } |
| | | ); |
| | | program.setSchedule(playerSchedule); |
| | | |
| | | |
| | | program.setNoticeUrl(VnnoxConstant.NOTIFY_URL); |
| | | LogUtils.error("节目内容+++++++++++" + JSON.toJSONString(program)); |
| | | VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program); |
| | | vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(pushToLed.getVolume()).intValue()); |
| | | |
| | | |
| | | if (vnnoxResultResponse.getData() != null) { |
| | | success = vnnoxResultResponse.getData().getSuccess(); |
| | | fail = vnnoxResultResponse.getData().getFail(); |
| | | } |
| | | }); |
| | | |
| | | List<String> finalSuccess = success; |
| | | List<String> finalFail = fail; |
| | | nova.forEach(n -> { |
| | | if (finalSuccess.contains(n.getPlayerId())) { |
| | | successList.add(n); |
| | | } else if (finalFail.contains(n.getPlayerId())) { |
| | | faileList.add(n); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | result.put("success", successList); |
| | | result.put("fail", faileList); |
| | |
| | | + ", 节目名称:" + byId.getName() |
| | | + "}," + " 推送结果:" + result |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦推送定时任务", content); |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦推送播放计划", content); |
| | | /** |
| | | * 诺瓦推送节目日志记录结束 |
| | | */ |
| | |
| | | throw new BusinessException("未找到节目"); |
| | | } |
| | | List<SchedulesDTO> schedulesDTOS = JSON.parseArray(one.getSchedules(), SchedulesDTO.class); |
| | | ProgramSchedule programSchedule = new ProgramSchedule(); |
| | | programSchedule.setSchedules(schedulesDTOS); |
| | | List<String> playerIds = new ArrayList<>(); |
| | | nova.forEach( |
| | | n -> { |
| | | playerIds.add(n.getPlayerId()); |
| | | } |
| | | ); |
| | | //设置 |
| | | programSchedule.setPlayerIds(playerIds); |
| | | VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.timeProgram(programSchedule); |
| | | |
| | | List<String> success = new ArrayList<>(); |
| | | List<String> fail = new ArrayList<>(); |
| | | if (vnnoxResultResponse.getData() != null) { |
| | | success = vnnoxResultResponse.getData().getSuccess(); |
| | | fail = vnnoxResultResponse.getData().getFail(); |
| | | } |
| | | |
| | | //拼接成功失败的结果 |
| | | Map<String, Object> result = new HashMap<>(); |
| | | List<NovaPushResultVO> successList = new ArrayList<>(); |
| | | List<NovaPushResultVO> faileList = new ArrayList<>(); |
| | | List<String> finalSuccess = success; |
| | | List<String> finalFail = fail; |
| | | nova.forEach( |
| | | n -> { |
| | | if (finalSuccess.contains(n.getPlayerId())) { |
| | | successList.add(n); |
| | | } else if (finalFail.contains(n.getPlayerId())) { |
| | | faileList.add(n); |
| | | } |
| | | } |
| | | |
| | | ); |
| | | List<List<String>> split = CollectionUtil.split(nova.stream().map(NovaPushResultVO::getPlayerId).collect(Collectors.toList()), 100); |
| | | for (List<String> playerIds : split) { |
| | | //设置 |
| | | ProgramSchedule programSchedule = new ProgramSchedule(); |
| | | programSchedule.setSchedules(schedulesDTOS); |
| | | programSchedule.setPlayerIds(playerIds); |
| | | VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.timeProgram(programSchedule); |
| | | |
| | | |
| | | if (vnnoxResultResponse.getData() != null) { |
| | | success = vnnoxResultResponse.getData().getSuccess(); |
| | | fail = vnnoxResultResponse.getData().getFail(); |
| | | } |
| | | List<String> finalSuccess = success; |
| | | List<String> finalFail = fail; |
| | | |
| | | nova.forEach( |
| | | n -> { |
| | | if (finalSuccess.contains(n.getPlayerId())) { |
| | | successList.add(n); |
| | | } else if (finalFail.contains(n.getPlayerId())) { |
| | | faileList.add(n); |
| | | } |
| | | } |
| | | |
| | | ); |
| | | } |
| | | |
| | | result.put("success", successList); |
| | | result.put("fail", faileList); |
| | |
| | | + ", 节目名称:" + one.getName() |
| | | + "}," + " 推送结果:" + result |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦推送定时任务", content); |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦推送定时开关屏", content); |
| | | /** |
| | | * 诺瓦推送定时日志记录结束 |
| | | */ |
| | |
| | | plan.put("schedules", schedules); |
| | | return plan; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 推送实时节目 |
| | | * |
| | | * @param pid |
| | | * @param nova |
| | | * @return |
| | | */ |
| | | public Map<String, Object> pushProgram(Long pid, List<NovaPushResultVO> nova) { |
| | | LEDProgram ledProgram = ledProgramService.getById(pid); |
| | | if (ledProgram == null) { |
| | | throw new BusinessException("未找到节目"); |
| | | } |
| | | if (ledProgram.getPages() == null) { |
| | | throw new BusinessException("节目内容丢失"); |
| | | } |
| | | if (SecurityUtils.getClientId() != null |
| | | && !Objects.equals(ledProgram.getClientId(), SecurityUtils.getUserId()) |
| | | && !Objects.equals(ledProgram.getUserId(), SecurityUtils.getUserId())) { |
| | | throw new BusinessException("请不要操作其他人的节目"); |
| | | } |
| | | String pages = ledProgram.getPages(); |
| | | |
| | | |
| | | List<String> success = new ArrayList<>(); |
| | | List<String> fail = new ArrayList<>(); |
| | | //拼接成功失败的结果 |
| | | Map<String, Object> result = new HashMap<>(); |
| | | List<NovaPushResultVO> successList = new ArrayList<>(); |
| | | List<NovaPushResultVO> faileList = new ArrayList<>(); |
| | | |
| | | |
| | | List<List<String>> split = CollectionUtil.split(nova.stream().map(NovaPushResultVO::getPlayerId).collect(Collectors.toList()), 100); |
| | | |
| | | for (List<String> playerIds : split) { |
| | | PlayerProgram program = new PlayerProgram(); |
| | | List<PlayerPage> programDtos = JSON.parseArray(pages, PlayerPage.class); |
| | | programDtos.forEach( |
| | | programDto -> { |
| | | programDto.getWidgets().forEach( |
| | | widget -> { |
| | | if (PlayerWidgetType.PICTURE.equals(widget.getType()) || PlayerWidgetType.VIDEO.equals(widget.getType())) { |
| | | String url = widget.getUrl(); |
| | | LEDProgramFile one = fileService.getOne(Wrappers.lambdaQuery(LEDProgramFile.class).eq(LEDProgramFile::getFileUrl, url)); |
| | | if (one == null) { |
| | | throw new BusinessException("节目文件已失效"); |
| | | } |
| | | widget.setMd5(one.getMd5()); |
| | | widget.setSize(Long.parseLong(one.getSize())); |
| | | } |
| | | } |
| | | ); |
| | | } |
| | | ); |
| | | program.setPlayerIds(playerIds); |
| | | //获取节目实体 |
| | | program.setPages(programDtos); |
| | | |
| | | program.setNoticeUrl(VnnoxConstant.NOTIFY_URL); |
| | | VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.pushProgram(program); |
| | | |
| | | if (vnnoxResultResponse == null || vnnoxResultResponse.getData() == null) { |
| | | throw new BusinessException("推送失败"); |
| | | } |
| | | |
| | | |
| | | if (vnnoxResultResponse.getData() != null) { |
| | | success = vnnoxResultResponse.getData().getSuccess(); |
| | | fail = vnnoxResultResponse.getData().getFail(); |
| | | } |
| | | |
| | | List<String> finalSuccess = success; |
| | | List<String> finalFail = fail; |
| | | nova.forEach(n -> { |
| | | if (finalSuccess.contains(n.getPlayerId())) { |
| | | successList.add(n); |
| | | } else if (finalFail.contains(n.getPlayerId())) { |
| | | faileList.add(n); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | result.put("success", successList); |
| | | result.put("fail", faileList); |
| | | |
| | | /** |
| | | * 诺瓦推送节目日志记录开始 |
| | | */ |
| | | List<LedPlayerEntity> list = SpringContextHolder.getBean(LedPlayerEntityService.class) |
| | | .list(Wrappers.lambdaQuery(LedPlayerEntity.class).in(LedPlayerEntity::getId, nova.stream().map(NovaPushResultVO::getPlayerId).toArray())); |
| | | List<String> listCode = new ArrayList<>(); |
| | | for (LedPlayerEntity temp : list) { |
| | | listCode.add(temp.getSn()); |
| | | } |
| | | |
| | | String content = "{节目ID:" + pid |
| | | + ", 节目名称:" + ledProgram.getName() |
| | | + "}," + " 推送结果:" + result |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦推送节目", content); |
| | | /** |
| | | * 诺瓦推送节目日志记录结束 |
| | | */ |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | } |