| | |
| | | package com.sandu.ximon.admin.newnova.led; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereHeartbeatReportInnerFrame; |
| | | import com.sandu.ximon.admin.newnova.conf.ProgramPathConfig; |
| | | import com.sandu.ximon.admin.newnova.param.NewNovaLedParam; |
| | | import com.sandu.ximon.admin.newnova.param.ProgramPrarm; |
| | | import com.sandu.ximon.admin.newnova.program.NewNovaProgramService; |
| | | import com.sandu.ximon.admin.newnova.utils.NovaAPIUtil; |
| | | import com.sandu.ximon.admin.newnova.vo.ProWHVO; |
| | | import com.sandu.ximon.admin.newnova.vo.StatusVO; |
| | | import com.sandu.ximon.admin.newnova.vo.TrasfromStatusVO; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.service.AirDataService; |
| | | import com.sandu.ximon.admin.service.PoleBindingService; |
| | | import com.sandu.ximon.admin.service.PoleService; |
| | | import com.sandu.ximon.dao.bo.NewNovaGroupListBo; |
| | | import com.sandu.ximon.dao.domain.NewNovaLed; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @AllArgsConstructor |
| | | public class NewNovaLedService extends BaseServiceImpl<NewNovaLedMapper, NewNovaLed> { |
| | | |
| | | private final PoleBindingService poleBindingService; |
| | | private ProgramPathConfig filePathConfig; |
| | | |
| | | /** |
| | | * 屏幕注册 |
| | |
| | | * |
| | | * @param baseConditionVO |
| | | * @param keyword |
| | | * @param groupId |
| | | * @param onlineStatus |
| | | * @return |
| | | */ |
| | | public List<NewNovaLed> listLed(BaseConditionVO baseConditionVO, String keyword, boolean onlineStatus) { |
| | | public List<NewNovaLed> listLed(BaseConditionVO baseConditionVO, String keyword, Long groupId, boolean onlineStatus) { |
| | | |
| | | NovaAPIUtil instanceUtil = NovaAPIUtil.getInstanceUtil(); |
| | | //排序 |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | List<NewNovaLed> newNovaListBos = baseMapper.listLed(keyword, SecurityUtils.getClientId()); |
| | | List<NewNovaLed> newNovaListBos = baseMapper.listLed(keyword, groupId, SecurityUtils.getClientId()); |
| | | //获取在线状态 |
| | | instanceUtil.getOnlineStatus(newNovaListBos); |
| | | instanceUtil.getOnlineStatus(newNovaListBos, onlineStatus); |
| | | //获取屏幕开关 |
| | | instanceUtil.getScreenPowerState(newNovaListBos); |
| | | //获取音量 |
| | |
| | | List<NewNovaLed> list = new ArrayList<>(); |
| | | list.add(byId); |
| | | //获取在线状态 |
| | | instanceUtil.getOnlineStatus(list); |
| | | instanceUtil.getOnlineStatus(list, false); |
| | | //获取屏幕开关 |
| | | instanceUtil.getScreenPowerState(list); |
| | | //获取音量 |
| | |
| | | instanceUtil.getInfo(byId); |
| | | return list.get(0); |
| | | } |
| | | |
| | | /** |
| | | * 获取整组的屏幕 |
| | | * |
| | | * @param groupId |
| | | */ |
| | | public List<NewNovaGroupListBo> getListByGroupId(Long groupId) { |
| | | List<NewNovaGroupListBo> listByGroupId = baseMapper.getListByGroupId(groupId, SecurityUtils.getClientId()); |
| | | return listByGroupId; |
| | | } |
| | | |
| | | /** |
| | | * 推送大气 |
| | | * |
| | | * @param id |
| | | * @param duration |
| | | * @param fontSize |
| | | */ |
| | | public Object pushAirData(Long id, Long duration, Long fontSize) throws InterruptedException { |
| | | NovaAPIUtil apiUtil = NovaAPIUtil.getInstanceUtil(); |
| | | NewNovaLed byId = getById(id); |
| | | PoleBinding nova = poleBindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, byId.getSn()).eq(PoleBinding::getDeviceType, 12)); |
| | | if (nova == null) { |
| | | throw new BusinessException("未绑定诺瓦设备"); |
| | | } |
| | | PoleBinding air = poleBindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, nova.getPoleId()).eq(PoleBinding::getDeviceType, 3)); |
| | | if (air == null) { |
| | | throw new BusinessException("未绑定大气设备"); |
| | | } |
| | | |
| | | //获取大气监测数据 |
| | | A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage data = SpringContextHolder.getBean(AirDataService.class).getDataByPoleid(nova.getPoleId()); |
| | | |
| | | //解析大气数据 |
| | | Map pageInfo = parseData(data, duration,fontSize); |
| | | ProgramPrarm page = new ProgramPrarm(); |
| | | page.setPageInfo(pageInfo); |
| | | page.setInsertPlay(true); |
| | | ProWHVO whvo = new ProWHVO("大气监测", 128, 256); |
| | | page.setProgramMsg(whvo); |
| | | StatusVO createPro = apiUtil.createPro(whvo); |
| | | Integer pid = Integer.valueOf(createPro.getStatusData()); |
| | | page.setProgramID(pid); |
| | | |
| | | StatusVO editPro = apiUtil.editProgram(pid, pageInfo); |
| | | if(editPro.getStatusCode()!=0){ |
| | | throw new BusinessException(editPro.getStatusData()); |
| | | } |
| | | StatusVO genVO = apiUtil.genrateProgram(pid); |
| | | if(genVO.getStatusCode()!=0){ |
| | | throw new BusinessException(genVO.getStatusData()); |
| | | } |
| | | page.setProgramID(Integer.valueOf(createPro.getStatusData())); |
| | | page.setStartPlayAfterTransferred(true); |
| | | List<String> sns = new ArrayList<String>(); |
| | | sns.add(byId.getSn()); |
| | | page.setSnList(sns); |
| | | |
| | | List<TrasfromStatusVO> trasfromStatusVOS = apiUtil.trasfromProgram(page); |
| | | |
| | | File file = new File(filePathConfig.getOutPutPath() + "/program" + pid); |
| | | SpringContextHolder.getBean(NewNovaProgramService.class).deleteFile(file); |
| | | |
| | | return trasfromStatusVOS; |
| | | } |
| | | |
| | | /** |
| | | * 处理大气数据 |
| | | * |
| | | * @param data |
| | | * @param duration |
| | | * @param fontSize |
| | | * @return |
| | | */ |
| | | |
| | | private Map parseData(A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage data, Long duration, Long fontSize) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z+8:00'"); |
| | | Date end = new Date(); |
| | | end.setTime(end.getTime()+duration); |
| | | String str = "{\n" + |
| | | " \"name\": \"大气监测\",\n" + |
| | | " \"widgetContainers\": [\n" + |
| | | " {\n" + |
| | | " \"contents\": {\n" + |
| | | " \"widgets\": [\n" + |
| | | " {\n" + |
| | | " \"constraints\": [\n" + |
| | | " {\n" + |
| | | " \"cron\": [\n" + |
| | | " \"\"\n" + |
| | | " ],\n" + |
| | | " \"endTime\": \"" + sdf.format(end) + "\",\n" + |
| | | " \"startTime\": \"" + sdf.format(new Date()) + "\"\n" + |
| | | " }\n" + |
| | | " ],\n" + |
| | | " \"duration\":" + duration + ",\n" + |
| | | " \"metadata\": {\n" + |
| | | " \"content\": {\n" + |
| | | " \"autoPaging\": true,\n" + |
| | | " \"backgroundMusic\": {\n" + |
| | | " \"duration\": 0,\n" + |
| | | " \"isTextSync\": false\n" + |
| | | " },\n" + |
| | | " \"displayStyle\": {\n" + |
| | | " \"scrollAttributes\": {\n" + |
| | | " \"effects\": {\n" + |
| | | " \"animation\": \"MARQUEE_LEFT\",\n" + |
| | | " \"speed\": 3\n" + |
| | | " }\n" + |
| | | " },\n" + |
| | | " \"type\": \"STATIC\"\n" + |
| | | " },\n" + |
| | | " \"paragraphs\": [\n" + |
| | | " {\n" + |
| | | " \"backgroundColor\": \"#00000000\",\n" + |
| | | " \"horizontalAlignment\": \"LEFT\",\n" + |
| | | " \"letterSpacing\": 0,\n" + |
| | | " \"lineSpacing\": 0,\n" + |
| | | " \"lines\": [\n" + |
| | | " {\n" + |
| | | " \"segs\": [\n" + |
| | | " {\n" + |
| | | " \"content\": \"环境监测:\"\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"segs\": [\n" + |
| | | " {\n" + |
| | | " \"content\": \"温度:" + (data == null || data.getTemperature() == null ? " - " : data.getTemperature()) + "°\"" + "\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"segs\": [\n" + |
| | | " {\n" + |
| | | " \"content\": \"湿度:" + (data == null || data.getHumidity() == null ? " - " : data.getHumidity()) + "%\"" + "\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"segs\": [\n" + |
| | | " {\n" + |
| | | " \"content\": \"pm25:" + (data == null || data.getPm25() == null ? " - " : data.getPm25()) + "μg/m³\"" + "\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"segs\": [\n" + |
| | | " {\n" + |
| | | " \"content\": \"pm10:" + (data == null || data.getPm10() == null ? " - " : data.getPm10()) + "μg/m³\"" + "\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"segs\": [\n" + |
| | | " {\n" + |
| | | " \"content\": \"甲醛:" + (data == null || data.getEch2o() == null ? " - " : data.getEch2o()) + "μg/m³\"" + "\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"segs\": [\n" + |
| | | " {\n" + |
| | | " \"content\": \"CO2:" + (data == null || data.getCo2() == null ? " - " : data.getCo2()) + "ppm\"" + "\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " }\n" + |
| | | " ],\n" + |
| | | " \"verticalAlignment\": \"TOP\"\n" + |
| | | " }\n" + |
| | | " ],\n" + |
| | | " \"textAttributes\": [\n" + |
| | | " {\n" + |
| | | " \"backgroundColor\": \"#ff000000\",\n" + |
| | | " \"attributes\": {\n" + |
| | | " \"font\": {\n" + |
| | | " \"family\": [\n" + |
| | | " \"Helvetica\"\n" + |
| | | " ],\n" + |
| | | " \"isUnderline\": false,\n" + |
| | | " \"size\": "+fontSize+",\n" + |
| | | " \"style\": \"NORMAL\"\n" + |
| | | " },\n" + |
| | | " \"letterSpacing\": 0,\n" + |
| | | " \"textColor\": \"#ffff0000\"\n" + |
| | | " }\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " }\n" + |
| | | " },\n" + |
| | | " \"name\": \"环境监测\",\n" + |
| | | " \"type\": \"ARCH_TEXT\"\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " },\n" + |
| | | " \"id\": 1,\n" + |
| | | " \"name\": \"widgetContainers1\"\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " }"; |
| | | |
| | | return JSON.parseObject(str, Map.class); |
| | | } |
| | | |
| | | |
| | | } |