2021与蓝度共同重构项目,服务端
liuhaonan
2022-10-25 d495f9b8cdc83663e4189bc3cc72ac9543ff5555
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
@@ -435,91 +435,90 @@
                && !Objects.equals(ledProgram.getUserId(), SecurityUtils.getUserId())) {
            throw new BusinessException("请不要操作其他人的节目");
        }
        return null;
//        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;
        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;
    }