| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.ximon.admin.config.RealtimeServerBean; |
| | | import com.sandu.ximon.admin.config.XiXunConfig; |
| | | import com.sandu.ximon.admin.entity.*; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereHeartbeatReportInnerFrame; |
| | | 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.admin.utils.request.SubTitleSet; |
| | | import com.sandu.ximon.dao.domain.LedSFile; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | 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.apache.commons.lang.StringUtils; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | |
| | | 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); |
| | |
| | | poleXixunPlayer.setScreenShot(programPro.getScreenShot()); |
| | | // poleXixunPlayer.setCreatTime(sdf.format(date)); |
| | | poleXixunPlayer.setCreateUserId(SecurityUtils.getUserId()); |
| | | if(!clientService.findClientId()){ |
| | | poleXixunPlayer.setClientId(clientService.getClientId()); |
| | | if (SecurityUtils.getClientId() != null) { |
| | | poleXixunPlayer.setCreateUserId(SecurityUtils.getUserId()); |
| | | if (clientService.findClientId()) { |
| | | poleXixunPlayer.setClientId(clientService.getClientId()); |
| | | } |
| | | } |
| | | |
| | | |
| | | return this.save(poleXixunPlayer); |
| | | } |
| | | |
| | |
| | | |
| | | public Object getByPid(Long pid) { |
| | | PoleXixunPlayerEntity byId = getById(pid); |
| | | List<Long> fileIds=new ArrayList<>(); |
| | | List<LedSFile> file=new ArrayList<>(); |
| | | List<Long> fileIds = new ArrayList<>(); |
| | | List<LedSFile> file = new ArrayList<>(); |
| | | if (byId == null) { |
| | | throw new BusinessException("未找到该节目"); |
| | | } |
| | |
| | | programPro.getLayers().forEach( |
| | | layerPro -> { |
| | | layerPro.getSources().forEach( |
| | | sourcePro -> { |
| | | long fileId = Long.parseLong(sourcePro.getId()); |
| | | file.add(xiXunFileService.getById(fileId)); |
| | | } |
| | | sourcePro -> { |
| | | long fileId = Long.parseLong(sourcePro.getId()); |
| | | file.add(xiXunFileService.getById(fileId)); |
| | | } |
| | | ); |
| | | } |
| | | ); |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return programPro; |
| | | 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 |
| | | */ |
| | |
| | | |
| | | Collection<PoleLightemitEntity> poleLightemitEntities = poleLightemitService.listByIds(lightemitIds); |
| | | |
| | | if(poleLightemitEntities != null){ |
| | | for (PoleLightemitEntity entity: poleLightemitEntities) { |
| | | 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); |
| | | LogUtils.error("结果:" + post); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 推送大气数据到熙讯LED |
| | | */ |
| | | @Async("taskExecutor") |
| | | public Boolean pushWeather(String lightemitControlCode, A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage sensorEntity, Pole streetlightEntity) { |
| | | if (StringUtils.isBlank(lightemitControlCode)) { |
| | | return Boolean.valueOf(false); |
| | | } |
| | | Integer screenHeight = Integer.parseInt(lightemitUtils.getScreenHeight(lightemitControlCode)); |
| | | String size = String.valueOf(screenHeight / 18); |
| | | //字幕主体拼接 |
| | | String body = |
| | | "<head><style type=\"text/css\">body{background-color:#000;}</style></head>" + |
| | | "<p style=\"font-size:" + size + "px;line-height:17px;color:#fff\">" + |
| | | (streetlightEntity == null || streetlightEntity.getCity() == null ? "" : streetlightEntity.getCity().replace("市", "")) + "<br/>" + |
| | | "温度:" + (sensorEntity == null || sensorEntity.getTemperature() == null ? " -" : sensorEntity.getTemperature()) + "℃<br/>" + |
| | | "湿度:" + (sensorEntity == null || sensorEntity.getHumidity() == null ? "-" : sensorEntity.getHumidity()) + "%RH<br/>" + |
| | | "亮度:" + (sensorEntity == null || sensorEntity.getLightIntensity() == null ? "-" : sensorEntity.getLightIntensity()) + "lux<br/>" + |
| | | "风速:" + (sensorEntity == null || sensorEntity.getWindSpeed() == null ? "-" : sensorEntity.getWindSpeed()) + "m/s<br/>" + |
| | | "CO2:" + (sensorEntity == null || sensorEntity.getCo2() == null ? "-" : sensorEntity.getCo2()) + "ppm<br/>" + |
| | | "甲醛:" + (sensorEntity == null || sensorEntity.getEch2o() == null ? "-" : sensorEntity.getEch2o()) + "mg/m³<br/>" + |
| | | "TVOC:" + (sensorEntity == null || sensorEntity.getTvoc() == null ? "-" : sensorEntity.getTvoc()) + "mg/m³<br/>" + |
| | | "PM25:" + (sensorEntity == null || sensorEntity.getPm25() == null ? "-" : sensorEntity.getPm25()) + "mg/m³<br/>" + |
| | | "PM10:" + (sensorEntity == null || sensorEntity.getPm10() == null ? "-" : sensorEntity.getPm10()) + "mg/m³<br/>"; |
| | | |
| | | //组装请求参数 |
| | | SubTitleSet subTitleSet = new SubTitleSet(); |
| | | subTitleSet.html = body; |
| | | subTitleSet.num = 1; |
| | | |
| | | //清屏操作 |
| | | lightemitUtils.clear(lightemitControlCode); |
| | | //清除播放列表 |
| | | lightemitUtils.clearVideoPlay(lightemitControlCode); |
| | | //清除节目列表 |
| | | lightemitUtils.clearPlayerTask(lightemitControlCode); |
| | | try { |
| | | lightemitUtils.subTitleSet(subTitleSet, lightemitControlCode, false); |
| | | return true; |
| | | } catch (Exception e) { |
| | | return false; |
| | | } finally { |
| | | //一分钟后清除屏幕 |
| | | new Timer().schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | lightemitUtils.clear(lightemitControlCode); |
| | | //清除播放列表 |
| | | lightemitUtils.clearVideoPlay(lightemitControlCode); |
| | | //清除节目列表 |
| | | lightemitUtils.clearPlayerTask(lightemitControlCode); |
| | | //推送最后命令 |
| | | lightemitUtils.sendLastCommand(lightemitControlCode); |
| | | } |
| | | }, 60 * 1000); |
| | | } |
| | | } |
| | | |
| | | } |