2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-24 0f1938fcb0acc34e2bf808048fa15435142cb5a6
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PlayPlanNvService.java
@@ -5,6 +5,8 @@
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
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.param.PlayPlanParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
@@ -12,14 +14,20 @@
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.dao.domain.*;
import com.sandu.ximon.dao.enums.AdministratorEnums;
import com.sandu.ximon.admin.vo.NovaOpenVO;
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.mapper.PlayPlanNvMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 播放计划
@@ -38,9 +46,9 @@
    public boolean addPlan(PlayPlanParam playPlanParam) {
        PlayPlanNv playPlan = new PlayPlanNv();
        if (SecurityUtils.getClientId()!=null){
        if (SecurityUtils.getClientId() != null) {
            playPlan.setUserId(SecurityUtils.getUserId());
            if(clientService.findClientId()){
            if (clientService.findClientId()) {
                playPlan.setClientId(clientService.getClientId());
            }
        }
@@ -56,7 +64,35 @@
        playPlan.setStartDate(playPlanParam.getStartDate());
        playPlan.setEndDate(playPlanParam.getEndDate());
        playPlan.setWeekDays(playPlanParam.getWeekDays());
        playPlan.setSchedule(JSON.toJSONString(playPlanParam.getSchedule()));
        Map schedule = playPlanParam.getSchedule();
        String s = JSON.toJSONString(schedule.get("plans"));
        List<PlanDto> plans = JSON.parseArray(s, PlanDto.class);
        System.out.println(plans.toString()+"plans");
//        List<PlanDto> plans = (List<PlanDto>) schedule.get("plans");
        plans.forEach(plan -> {
                    System.out.println(plan+"plan");
                }
        );
        List<SchedulesDTO> schedulesDTOS = new ArrayList<>();
        for (int i = 0; i < plans.size(); i++) {
            SchedulesDTO schedulesDTO = new SchedulesDTO();
            schedulesDTO.setStartDate(playPlanParam.getStartDate());
            schedulesDTO.setEndDate(playPlanParam.getEndDate());
            if (i % 2 == 1) {
                schedulesDTO.setExecTime(plans.get(i).getStartTime());
            } else {
                schedulesDTO.setWeekDays(plans.get(i).getWeekDays());
                schedulesDTO.setExecTime(plans.get(i).getEndTime());
            }
            schedulesDTOS.add(schedulesDTO);
        }
        playPlan.setSchedule(JSON.toJSONString(schedulesDTOS));
        playPlan.setStartTime(playPlanParam.getStartTime());
        playPlan.setEndTime(playPlanParam.getEndTime());
        //  BeanUtils.copyProperties(playPlanParam, playPlan);
@@ -113,11 +149,21 @@
        program.setPlayerIds(playerIds);
        System.out.println(pushToLed.getPages());
        System.out.println(JSON.parseArray(pushToLed.getPages(), Map.class));
        program.setPages(JSON.parseObject(pushToLed.getPages(), List.class));
        program.setSchedule(JSON.parseObject(pushToLed.getSchedule(), Map.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.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
        VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program);
        VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.timeProgram(program);
        VnnoxResult vnnoxResult = vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(one.getVolume()).intValue());
        // VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(push);
@@ -127,7 +173,6 @@
            success = vnnoxResultResponse.getData().getSuccess();
            fail = vnnoxResultResponse.getData().getFail();
        }
        // fail.addAll(vnnoxResult.getFail());
        Map<String, Object> result = new HashMap<>();
@@ -143,12 +188,41 @@
        result.put("success", successList);
        result.put("fail", faileList);
        result.put("program", program);
        return result;
        // return program;
    }
    /**
     * 解析定时
     *
     * @param
     * @return
     */
    public List<Map<String, Object>> parseSchedule(Map map) {
        map.get("startDate");
        map.get("endDate");
        List<PlansVO> plans = (List<PlansVO>) map.get("plans");
        plans.forEach(
                plan -> {
                    NovaOpenVO Open = new NovaOpenVO();
                    Open.setStartDate(map.get("startDate").toString());
                    Open.setEndDate(map.get("endDate").toString());
                    Open.setExecTime(plan.getStartTime());
                }
        );
        NovaOpenVO Open1 = new NovaOpenVO();
        Open1.setStartDate(map.get("startDate").toString());
        Open1.setEndDate(map.get("endDate").toString());
        return null;
    }
    public Object getByPlanId(Long planId) {
        PlayPlanNv byId = getById(planId);
        if (byId == null) {