2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-26 d8bd5680f12b212d740ba7b8f5d641e3a327faca
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.sandu.ximon.admin.service;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.config.RealtimeServerBean;
import com.sandu.ximon.admin.config.XiXunConfig;
import com.sandu.ximon.admin.entity.*;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.JsonUtil;
import com.sandu.ximon.admin.utils.LightemitUtils;
import com.sandu.ximon.admin.utils.LogUtils;
import com.sandu.ximon.dao.domain.LEDProgram;
import com.sandu.ximon.dao.domain.LedSFile;
import com.sandu.ximon.dao.domain.PoleLightemitEntity;
import com.sandu.ximon.dao.domain.PoleXixunPlayerEntity;
import com.sandu.ximon.dao.mapper.PoleXixunPlayerEntityMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
 
/**
 * 熙讯节目
 */
@Service
@AllArgsConstructor
public class XiXunPlayerService extends BaseServiceImpl<PoleXixunPlayerEntityMapper, PoleXixunPlayerEntity> {
 
    private final PoleXixunPlayerEntityMapper poleXixunPlayerEntityMapper;
    private final XiXunConfig config;
    private final LightemitUtils lightemitUtils;
    private final RealtimeServerBean realtimeServerBean;
    private final PoleLightemitService poleLightemitService;
    private final ClientService clientService;
    private final LedSFileService xiXunFileService;
 
    //熙讯节目列表
    public LambdaQueryWrapper<PoleXixunPlayerEntity> XixunPlayerList(String keyword) {
        if (SecurityUtils.getClientId() == null) {
            if (keyword != null && keyword.isEmpty()) {
                return Wrappers.lambdaQuery(PoleXixunPlayerEntity.class);
            } else {
                return Wrappers.lambdaQuery(PoleXixunPlayerEntity.class).like(PoleXixunPlayerEntity::getProgramName, keyword);
            }
 
        } else {
            if (keyword != null && keyword.isEmpty()) {
                return Wrappers.lambdaQuery(PoleXixunPlayerEntity.class).eq(PoleXixunPlayerEntity::getCreateUserId, SecurityUtils.getUserId())
                        .or(w -> {
                            w.eq(PoleXixunPlayerEntity::getClientId, SecurityUtils.getClientId());
                        });
            } else {
                return Wrappers.lambdaQuery(PoleXixunPlayerEntity.class).eq(PoleXixunPlayerEntity::getCreateUserId, SecurityUtils.getUserId())
                        .or(w -> {
                            w.eq(PoleXixunPlayerEntity::getClientId, SecurityUtils.getClientId());
                        }).like(PoleXixunPlayerEntity::getProgramName, keyword);
            }
        }
    }
 
    public boolean insert(ProgramPro programPro) {
        String json = JsonUtil.jsonObj2Sting(programPro);
        PoleXixunPlayerEntity poleXixunPlayer = new PoleXixunPlayerEntity();
        poleXixunPlayer.setProgramCode(programPro.get_id());
        poleXixunPlayer.setProgramName(programPro.getName());
        poleXixunPlayer.setHeight(programPro.getHeight());
        poleXixunPlayer.setWidth(programPro.getWidth());
        poleXixunPlayer.setTotalSize((float) programPro.getTotalSize() / 1000000 + "MB");
//        poleXixunPlayer.setTotalSize( Long.parseLong(programPro.getTotalSize()) / 1000000 + "MB");
//        programPro.setProgramId(poleXixunPlayer.getProgramId());
//        System.out.println(poleXixunPlayer.getProgramId());
        poleXixunPlayer.setRequestBody(json);
        poleXixunPlayer.setScreenShot(programPro.getScreenShot());
        //  poleXixunPlayer.setCreatTime(sdf.format(date));
        poleXixunPlayer.setCreateUserId(SecurityUtils.getUserId());
        if (SecurityUtils.getClientId() != null) {
            poleXixunPlayer.setCreateUserId(SecurityUtils.getUserId());
            if (clientService.findClientId()) {
                poleXixunPlayer.setClientId(clientService.getClientId());
            }
        }
        return this.save(poleXixunPlayer);
    }
 
    public boolean deleteProgram(Long pid) {
        PoleXixunPlayerEntity byId = getById(pid);
        if (byId == null) {
            throw new BusinessException("未找到该节目");
        }
        return removeById(pid);
    }
 
    public Object getByPid(Long pid) {
        PoleXixunPlayerEntity byId = getById(pid);
        List<Long> fileIds = new ArrayList<>();
        List<LedSFile> file = new ArrayList<>();
        if (byId == null) {
            throw new BusinessException("未找到该节目");
        }
        String json = byId.getRequestBody();
        ProgramPro programPro = new ProgramPro();
        try {
            programPro = JsonUtil.convertJsonStringToObject(json, ProgramPro.class);
            programPro.setProgramId(pid);
            programPro.setScreenShot(byId.getScreenShot());
            programPro.getLayers().forEach(
                    layerPro -> {
                        layerPro.getSources().forEach(
                                sourcePro -> {
                                    long fileId = Long.parseLong(sourcePro.getId());
                                    file.add(xiXunFileService.getById(fileId));
                                }
                        );
                    }
            );
            programPro.setFileList(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return programPro;
    }
 
 
 
//    public Object getProgram(String json) {
////        PoleXixunPlayerEntity byId = getById(pid);
//        List<Long> fileIds = new ArrayList<>();
//        List<LedSFile> file = new ArrayList<>();
//        if (json == null) {
//            throw new BusinessException("未找到该节目");
//        }
//        ProgramPro programPro = new ProgramPro();
//        try {
//            programPro = JsonUtil.convertJsonStringToObject(json, ProgramPro.class);
//            programPro.setProgramId(pid);
//            programPro.setScreenShot(byId.getScreenShot());
//            programPro.getLayers().forEach(
//                    layerPro -> {
//                        layerPro.getSources().forEach(
//                                sourcePro -> {
//                                    long fileId = Long.parseLong(sourcePro.getId());
//                                    file.add(xiXunFileService.getById(fileId));
//                                }
//                        );
//                    }
//            );
//            programPro.setFileList(file);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return programPro;
//    }
 
 
    /**
     * 推送节目
     *
     * @param programId
     * @param lightemitIds
     */
    public void videoXixunPlayer(long programId, List<Long> lightemitIds) {
 
        ProgramPro pro = new ProgramPro();
        ItemPro items = new ItemPro();
        TaskPro taskPro = new TaskPro();
        CommandPro command = new CommandPro();
        XixunPlayerPro xixun = new XixunPlayerPro();
        PoleXixunPlayerEntity poleXixunPlayerEntity = new PoleXixunPlayerEntity();
        items.set_id(UUID.randomUUID().toString());
        QueryWrapper<PoleXixunPlayerEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("program_id", programId);
        poleXixunPlayerEntity = this.getOne(queryWrapper);
        String json = poleXixunPlayerEntity.getRequestBody();
 
//        System.out.println( JSON.parseArray(json, ProgramPro.class));
 
        try {
            pro = JsonUtil.convertJsonStringToObject(json, ProgramPro.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        items.set_program(pro);
        items.setRepeatTimes(1);
        items.setSchedulePros(null);//定时段,不做定时可为null
        taskPro.set_id(UUID.randomUUID().toString());
        taskPro.setName(poleXixunPlayerEntity.getProgramName());
        List<ItemPro> list2 = new ArrayList<>();
        list2.add(items);
        taskPro.setItems(list2);
        command.setId(UUID.randomUUID().toString());
        //这里是下方的post回调地址,需要修改IP地址
        command.setNotificationURL("http://" + config.getIp() + ":" + config.getPort() + "/machine-fast/serv/download/getJSON");
        //资源下载链接的请求头
        command.setPreDownloadURL("http://" + config.getIp() + ":" + config.getPort() + "/machine-fast/serv/download/downliadFileById/");
        command.setTask(taskPro);
        xixun.set_id(UUID.randomUUID().toString());
        xixun.setCommand(command);
        xixun.setType("commandXixunPlayer");    //命令固定类型,不可更改
 
 
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
//        String jsondata = JSON.toJSONString(xixun);
        String jsondata = gson.toJson(xixun);
 
        Collection<PoleLightemitEntity> poleLightemitEntities = poleLightemitService.listByIds(lightemitIds);
 
        if (poleLightemitEntities != null) {
            for (PoleLightemitEntity entity : poleLightemitEntities) {
                lightemitUtils.clear(entity.getLightemitControlCode());
                poleLightemitService.updateRequestBody(entity.getLightemitControlCode(), jsondata);
                String post = lightemitUtils.post(realtimeServerBean.getCommand() + entity.getLightemitControlCode(), jsondata);
                LogUtils.error("结果:" + post);
            }
        }
    }
 
 
    /**
     * 推送大气数据到熙讯LED
     */
 
 
 
}