2021与蓝度共同重构项目,服务端
fix
zhanzhiqin
2022-03-11 67b483b124d74ba1ef5701b508d4e808e26b0d2e
ximon-admin/src/main/java/com/sandu/ximon/admin/service/VnnoxService.java
@@ -1,7 +1,9 @@
package com.sandu.ximon.admin.service;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.log.Log;
import com.sandu.ximon.admin.config.VnnoxConstant;
import com.sandu.ximon.admin.utils.LogUtils;
import com.sandu.ximon.admin.utils.RedisUtils;
import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
import com.sandu.ximon.admin.utils.request.VnnoxScreenStatusType;
@@ -9,6 +11,7 @@
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;
@@ -30,11 +33,11 @@
@AllArgsConstructor
public class VnnoxService {
   // @Autowired
    // @Autowired
    private VnnoxAPIUtil vnnoxAPIUtil;
   // @Autowired
    // @Autowired
    private RedisUtils redisUtils;
   // @Autowired
    // @Autowired
    private LedPlayerEntityService ledPlayerEntityService;
    /**
@@ -44,7 +47,7 @@
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public LedV2RegisterResultEntity validateSN(String name,String sn) throws URISyntaxException {
    public LedV2RegisterResultEntity validateSN(String name, String sn) throws URISyntaxException {
        LedV2RegisterResultEntity ledV2RegisterResultEntity = new LedV2RegisterResultEntity();
        //  判断数据库是否存在,若不存在,判断是否已经注册到Vnnox服务器
@@ -61,13 +64,13 @@
        Integer limit = 100;
        List<VnnoxPlayerResponse> playerList;
        //  获取Vnnox服务器列表
        VnnoxPlayerListResponse response = vnnoxAPIUtil.getPlayerList(limit, page,name);
        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,name);
            response = vnnoxAPIUtil.getPlayerList(limit, page, name);
            playerList.addAll(response.getRows());
        }
        ledPlayerEntity = new LedPlayerEntity();
@@ -141,6 +144,7 @@
    }
    //截屏
    public Map<String, String> getScreenShotUrl(Integer id) {
        Map<String, String> map = new HashMap();
@@ -182,7 +186,7 @@
        return map;
    }
    //重启
    public VnnoxResult reboot(List<LedPlayerEntity> playerList) {
        return vnnoxAPIUtil.reboot(
                playerList.stream().map(
@@ -191,16 +195,61 @@
        );
    }
    public boolean updateDataName(Long  id, String name){
    public boolean updateDataName(Long id, String name) {
        LedPlayerEntity byId = ledPlayerEntityService.getById(id);
        if(byId==null){
        if (byId == null) {
            throw new BusinessException("未找到该设备");
        }
        LedPlayerEntity led=new LedPlayerEntity();
        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;
    }
}