2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-04-20 c00a73b74e67dbeb508865c3da4ed8d57c8631db
ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java
@@ -1,5 +1,6 @@
package com.sandu.ximon.admin.service;
import com.sandu.common.execption.BusinessException;
import com.sandu.ximon.admin.config.VnnoxConstant;
import com.sandu.ximon.admin.utils.RedisUtils;
import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
@@ -8,11 +9,13 @@
import com.sandu.ximon.admin.utils.response.VnnoxPlayerResponse;
import com.sandu.ximon.admin.utils.response.VnnoxResult;
import com.sandu.ximon.dao.domain.LedPlayerEntity;
import com.sandu.ximon.dao.domain.LedPlayerInfoEntity;
import com.sandu.ximon.dao.domain.LedV2RegisterResultEntity;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -28,11 +31,11 @@
@AllArgsConstructor
public class VnnoxService {
   // @Autowired
    // @Autowired
    private VnnoxAPIUtil vnnoxAPIUtil;
   // @Autowired
    // @Autowired
    private RedisUtils redisUtils;
   // @Autowired
    // @Autowired
    private LedPlayerEntityService ledPlayerEntityService;
    /**
@@ -42,7 +45,7 @@
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public LedV2RegisterResultEntity validateSN(String sn) {
    public LedV2RegisterResultEntity validateSN(String name, String sn) throws URISyntaxException {
        LedV2RegisterResultEntity ledV2RegisterResultEntity = new LedV2RegisterResultEntity();
        //  判断数据库是否存在,若不存在,判断是否已经注册到Vnnox服务器
@@ -56,16 +59,16 @@
        }
        Integer page = 0;
        Integer limit = 200;
        Integer limit = 100;
        List<VnnoxPlayerResponse> playerList;
        //  获取Vnnox服务器列表
        VnnoxPlayerListResponse response = vnnoxAPIUtil.getPlayerList(limit, page);
        VnnoxPlayerListResponse response = vnnoxAPIUtil.getPlayerList(limit, page, name);
        playerList = response.getRows();
        Integer total = response.getTotal() - limit;
        while (total > 0) {
            page = page + 1;
            total = total - limit;
            response = vnnoxAPIUtil.getPlayerList(limit, page);
            response = vnnoxAPIUtil.getPlayerList(limit, page, name);
            playerList.addAll(response.getRows());
        }
        ledPlayerEntity = new LedPlayerEntity();
@@ -139,6 +142,7 @@
    }
    //截屏
    public Map<String, String> getScreenShotUrl(Integer id) {
        Map<String, String> map = new HashMap();
@@ -180,7 +184,7 @@
        return map;
    }
    //重启
    public VnnoxResult reboot(List<LedPlayerEntity> playerList) {
        return vnnoxAPIUtil.reboot(
                playerList.stream().map(
@@ -189,4 +193,60 @@
        );
    }
    public boolean updateDataName(Long id, String name) {
        LedPlayerEntity byId = ledPlayerEntityService.getById(id);
        if (byId == null) {
            throw new BusinessException("未找到该设备");
        }
        LedPlayerEntity led = new LedPlayerEntity();
        led.setId(id);
        led.setName(name);
        return ledPlayerEntityService.updateById(led);
    }
    /**
     * 获取缓存数据
     *
     * @param list
     * @return
     */
    public List<LedPlayerEntity> setCacheInfo(List<LedPlayerEntity> list) {
        for (LedPlayerEntity playerEntity : list) {
            String playerId = playerEntity.getPlayerId();
            LedPlayerInfoEntity cache = new LedPlayerInfoEntity();
            //  设置屏幕状态
            String result = redisUtils.get(VnnoxConstant.REDIS_SCREEN_STATUS + playerId);
            Integer screenStatus = 1;
            if (null != result) {
                screenStatus = Integer.parseInt(result);
            }
            cache.setScreenStatus(screenStatus);
            //  设置屏幕音量
            result = redisUtils.get(VnnoxConstant.REDIS_VOL + playerId);
            Integer vol = 0;
            if (null != result) {
                vol = Integer.parseInt(result);
            }
            cache.setVol(vol);
            //  设置屏幕亮度
            result = redisUtils.get(VnnoxConstant.REDIS_BRIGHTNESS + playerId);
            Integer brightness = 0;
            if (null != result) {
                brightness = Integer.parseInt(result);
            }
            cache.setBrightness(brightness);
            //  设置缩略图访问路径
            result = redisUtils.get(VnnoxConstant.REDIS_SCREEN_SHOT + playerId);
            System.out.println(playerId + "的路径结果:-----------------------------" + result);
            if (null != result) {
                playerEntity.setScreenShotUrl(result);
            } else {
                playerEntity.setScreenShotUrl("");
            }
            playerEntity.setPlayerInfo(cache);
        }
        return list;
    }
}