2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-05-16 32889c5139b77575fa2cd6d4d1f5aea578ece160
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
@@ -1,18 +1,23 @@
package com.sandu.ximon.admin.service;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
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.param.PlayPlanParam;
import com.sandu.ximon.admin.security.SecurityUtils;
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.utils.request.PlayerProgram;
import com.sandu.ximon.admin.utils.response.VnnoxResult;
import com.sandu.ximon.admin.utils.response.VnnoxResultResponse;
import com.sandu.ximon.admin.vo.NovaOpenVO;
import com.sandu.ximon.admin.vo.NovaPushResultVO;
@@ -71,21 +76,14 @@
        String s = JSON.toJSONString(schedule.get("plans"));
        List<PlanDto> plans = JSON.parseArray(s, PlanDto.class);
        System.out.println(plans.toString()+"plans");
        System.out.println(plans.toString() + "plans");
//        List<PlanDto> plans = (List<PlanDto>) schedule.get("plans");
        List<SchedulesDTO> schedulesDTOS = new ArrayList<>();
        for (int i = 0; i < plans.size(); i++) {
            SchedulesDTO openDto = new SchedulesDTO();
//            if (i % 2 == 0) {
//                schedulesDTO.setExecTime(plans.get(i).getStartTime());
//                schedulesDTO.setStatus("OPEN");
//            } else {
//                schedulesDTO.setWeekDays(plans.get(i).getWeekDays());
//                schedulesDTO.setExecTime(plans.get(i).getEndTime());
//                schedulesDTO.setStatus("CLOSE");
//            }
            SchedulesDTO closeDto = new SchedulesDTO();
@@ -93,6 +91,19 @@
            openDto.setEndDate(schedule.get("endDate").toString());
            openDto.setExecTime(plans.get(i).getStartTime());
            openDto.setStatus("OPEN");
            /**
             * 判断时间的先后
             */
            String startTime = openDto.getStartDate() + " " + plans.get(i).getStartTime();
            String endTime = openDto.getEndDate() + " " + plans.get(i).getEndTime();
            //转换成时间戳
            long startTimeStamp = DateUtil.parse(startTime, DatePattern.NORM_DATETIME_PATTERN).getTime();
            long endTimeStamp = DateUtil.parse(endTime, DatePattern.NORM_DATETIME_PATTERN).getTime();
            if (startTimeStamp > endTimeStamp) {
                throw new BusinessException("开始时间不能大于结束时间");
            }
            closeDto.setStartDate(schedule.get("startDate").toString());
            closeDto.setEndDate(schedule.get("endDate").toString());
@@ -104,7 +115,8 @@
            schedulesDTOS.add(openDto);
        }
        playPlan.setSchedule(JSON.toJSONString(schedulesDTOS));
        playPlan.setSchedule(JSON.toJSONString(playPlanParam.getSchedule()));
        playPlan.setSchedules(JSON.toJSONString(schedulesDTOS));
        playPlan.setStartTime(playPlanParam.getStartTime());
        playPlan.setEndTime(playPlanParam.getEndTime());
        //  BeanUtils.copyProperties(playPlanParam, playPlan);
@@ -119,7 +131,7 @@
        if (byId == null) {
            throw new BusinessException("操作对象不存在");
        }
        if(removeById(id)){
        if (removeById(id)) {
            return addPlan(playPlanParam);
        }
@@ -138,41 +150,40 @@
    }
    public Map<String, Object> pushToLed(Long planId, List<NovaPushResultVO> nova) {
//    public PlayerProgram pushToLed(Long planId){
        PushToLed pushToLed = playPlanMapper.pushToLed(planId);
        PlayPlanNv one = getOne(Wrappers.lambdaQuery(PlayPlanNv.class).eq(PlayPlanNv::getId, planId));
        if (pushToLed == null) {
            throw new BusinessException("未找到该播放计划");
        }
        List<String> playerIds=new ArrayList<>();
        nova.forEach(
                n->{
                    playerIds.add(n.getPlayerId());
                }
        );
        List<String> playerIds = new ArrayList<>();
        nova.forEach(n -> {
            playerIds.add(n.getPlayerId());
        });
        PlayerProgram program = new PlayerProgram();
        program.setPlayerIds(playerIds);
        System.out.println(pushToLed.getPages());
        //获取节目实体
        program.setPages(JSON.parseObject(pushToLed.getPages(), List.class));
//
//        test test = JSON.parseObject(pushToLed.getSchedule(), test.class);
//
//        SchedulesDTO schedulesDTO = new SchedulesDTO();
//        schedulesDTO.setExecTime(A.get);
        program.setSchedules((JSON.parseArray(pushToLed.getSchedule(), SchedulesDTO.class)));
        // Map map = JSON.parseObject(pushToLed.getSchedule(), Map.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.timeProgram(program);
        VnnoxResult vnnoxResult = vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(one.getVolume()).intValue());
        VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program);
        vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(pushToLed.getVolume()).intValue());
        // VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(push);
        List<String> success = new ArrayList<>();
        List<String> fail = new ArrayList<>();
        if (vnnoxResultResponse.getData() != null) {
@@ -180,17 +191,63 @@
            fail = vnnoxResultResponse.getData().getFail();
        }
        // fail.addAll(vnnoxResult.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);
            }
        });
        result.put("success", successList);
        result.put("fail", faileList);
        return result;
    }
    //推送定时到LED
    public Map<String, Object> pushSchedule(Long planId, List<NovaPushResultVO> nova) {
        PlayPlanNv one = getOne(Wrappers.lambdaQuery(PlayPlanNv.class).eq(PlayPlanNv::getId, planId));
        if (one == null) {
            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())){
                n -> {
                    if (finalSuccess.contains(n.getPlayerId())) {
                        successList.add(n);
                    }else if(finalFail.contains(n.getPlayerId())){
                    } else if (finalFail.contains(n.getPlayerId())) {
                        faileList.add(n);
                    }
                }
@@ -200,9 +257,25 @@
        result.put("success", successList);
        result.put("fail", faileList);
        return result;
        // return program;
        /**
         * 诺瓦推送定时日志记录开始
         */
        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:" + one.getId()
                + ", 节目名称:" + one.getName()
                + "}," + " 推送结果:" + result
                + " }";
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦推送定时任务", content);
        /**
         * 诺瓦推送定时日志记录结束
         */
        return result;
    }
    /**
@@ -233,6 +306,12 @@
        return null;
    }
    /**
     * 获取播放计划
     *
     * @param planId
     * @return
     */
    public Object getByPlanId(Long planId) {
        PlayPlanNv byId = getById(planId);
        if (byId == null) {
@@ -242,7 +321,8 @@
        if (byId1 == null) {
            throw new BusinessException("找不到该节目");
        }
        List schedule = JSON.parseObject(byId.getSchedule(), List.class);
        List schedule = JSON.parseObject(byId.getSchedules(), List.class);
        Map schedules = JSON.parseObject(byId.getSchedule(), Map.class);
        List pages = JSON.parseObject(byId1.getPages(), List.class);
        Map plan = new HashMap();
        plan.put("planId", byId.getId());
@@ -253,6 +333,7 @@
        plan.put("preview", byId1.getPreview());
        plan.put("pages", pages);
        plan.put("schedule", schedule);
        plan.put("schedules", schedules);
        return plan;
    }
}