2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-02 ab060213fe5b62ba8bf9b87c8a93ba7e9fea05db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.sandu.ximon.admin.service;
 
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.ximon.admin.config.VnnoxConstant;
import com.sandu.ximon.admin.param.PlayPlanParam;
import com.sandu.ximon.admin.security.SecurityUtils;
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.dao.domain.*;
import com.sandu.ximon.dao.enums.AdministratorEnums;
import com.sandu.ximon.dao.mapper.PlayPlanNvMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * 播放计划
 */
@Service
@AllArgsConstructor
public class PlayPlanNvService extends BaseServiceImpl<PlayPlanNvMapper, PlayPlanNv> {
 
    private final PlayPlanNvMapper playPlanMapper;
    private final VnnoxProgramAPIUtil vnnoxProgramAPIUtil;
    private final LedPlayerEntityService ledPlayerEntityService;
    private VnnoxAPIUtil vnnoxAPIUtil;
    private final LEDProgramService ledProgramService;
 
    public boolean addPlan(PlayPlanParam playPlanParam) {
 
        PlayPlanNv playPlan = new PlayPlanNv();
        if (AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())) {
            playPlan.setUserId(SecurityUtils.getUserId());
        }
        playPlan.setName(playPlanParam.getName());
        playPlan.setLedProgramName(playPlanParam.getLedProgramName());
        LEDProgram byId = ledProgramService.getById(playPlanParam.getLedProgramId());
        if (byId == null) {
            throw new BusinessException("ledProgramId有误,未找到该节目");
        }
        playPlan.setLedProgramId(playPlanParam.getLedProgramId());
        playPlan.setVolume(playPlanParam.getVolume());
        playPlan.setApplySeries(playPlanParam.getApplySeries());
        playPlan.setStartDate(playPlanParam.getStartDate());
        playPlan.setEndDate(playPlanParam.getEndDate());
        playPlan.setWeekDays(playPlanParam.getWeekDays());
        playPlan.setSchedule(JSON.toJSONString(playPlanParam.getSchedule()));
        playPlan.setStartTime(playPlanParam.getStartTime());
        playPlan.setEndTime(playPlanParam.getEndTime());
        //  BeanUtils.copyProperties(playPlanParam, playPlan);
 
 
        return save(playPlan);
 
    }
 
    public boolean updatePlan(Long id, PlayPlanParam playPlanParam) {
        PlayPlanNv byId = getById(id);
        if (byId == null) {
            throw new BusinessException("操作对象不存在");
        }
        PlayPlanNv playPlan = new PlayPlanNv();
        playPlan.setId(id);
        playPlan.setName(playPlanParam.getName());
        playPlan.setLedProgramName(playPlanParam.getLedProgramName());
        playPlan.setLedProgramId(playPlanParam.getLedProgramId());
        playPlan.setVolume(playPlanParam.getVolume());
        playPlan.setApplySeries(playPlanParam.getApplySeries());
        playPlan.setStartDate(playPlanParam.getStartDate());
        playPlan.setEndDate(playPlanParam.getEndDate());
        playPlan.setWeekDays(playPlanParam.getWeekDays());
        playPlan.setSchedule(JSON.toJSONString(playPlanParam.getSchedule()));
        playPlan.setStartTime(playPlanParam.getStartTime());
        playPlan.setEndTime(playPlanParam.getEndTime());
 
        return updateById(playPlan);
 
    }
 
    public boolean deletePlan(List<Long> ids) {
        for (Long id : ids) {
            PlayPlanNv byId = getById(id);
            if (byId == null) {
                throw new BusinessException("部分操作对象不存在");
            }
        }
        return removeByIds(ids);
    }
 
    public Map<String, Object> pushToLed(Long planId, List<String> playerIds) {
//    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<>();
        // playerIds.add("872bb51ae0f06e70c21e913cf3dc9e4d");
        //List<Map<String,Object>> pages = JSON.parseObject(pushToLed.getPages(), List.class);
        PlayerProgram program = new PlayerProgram();
        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));
        program.setNoticeUrl(VnnoxConstant.NOTIFY_URL);
        VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(program);
        VnnoxResult vnnoxResult = vnnoxAPIUtil.volChange(playerIds, Integer.valueOf(one.getVolume()).intValue());
 
        // VnnoxResultResponse vnnoxResultResponse = vnnoxProgramAPIUtil.normalProgram(push);
        List<String> success = new ArrayList<>();
        List<String> fail = new ArrayList<>();
        if (vnnoxResultResponse.getData() != null) {
            success = vnnoxResultResponse.getData().getSuccess();
            fail = vnnoxResultResponse.getData().getFail();
        }
 
 
        // fail.addAll(vnnoxResult.getFail());
        Map<String, Object> result = new HashMap<>();
        List<LedPlayerEntity> successList = new ArrayList<>();
        List<LedPlayerEntity> faileList = new ArrayList<>();
        for (String playerId : success) {
            successList.add(ledPlayerEntityService.getByPlayerId(playerId));
        }
        for (String playerId : fail) {
            faileList.add(ledPlayerEntityService.getByPlayerId(playerId));
        }
 
 
        result.put("success", successList);
        result.put("fail", faileList);
 
        return result;
        // return program;
 
    }
 
    public Object getByPlanId(Long planId) {
        PlayPlanNv byId = getById(planId);
        if (byId == null) {
            throw new BusinessException("找不到该计划");
        }
        LEDProgram byId1 = ledProgramService.getById(byId.getLedProgramId());
        if (byId1 == null) {
            throw new BusinessException("找不到该节目");
        }
        Map schedule = JSON.parseObject(byId.getSchedule(), Map.class);
        List pages = JSON.parseObject(byId1.getPages(), List.class);
        Map plan = new HashMap();
        plan.put("planId", byId.getId());
        plan.put("planName", byId.getName());
        plan.put("programId", byId1.getId());
        plan.put("programName", byId1.getName());
        plan.put("planVolume", byId.getVolume());
        plan.put("preview", byId1.getPreview());
        plan.put("pages", pages);
        plan.put("schedule", schedule);
        return plan;
    }
}