| | |
| | | package com.sandu.ximon.admin.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.ximon.admin.config.BroadcastAPI; |
| | | import com.sandu.ximon.admin.dto.TerminalDto; |
| | | import com.sandu.ximon.admin.utils.request.CommonRequestParams; |
| | | import com.sandu.ximon.admin.utils.response.CommonResponseVO; |
| | | import com.sandu.ximon.admin.utils.response.DataResponseVO; |
| | | import com.sandu.ximon.admin.vo.ListDataResponseVO; |
| | | import com.sandu.ximon.admin.vo.TerminalVO; |
| | | import org.springframework.beans.BeanUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class TerminalAPIUtils { |
| | |
| | | * @param terminalId |
| | | * @return |
| | | */ |
| | | public static TerminalVO getTerminalInfo(Integer terminalId) { |
| | | DataResponseVO responseVO = JSON.parseObject( |
| | | BroadcastPostUtils.Post( |
| | | new CommonRequestParams().put("id", terminalId).getParams(), |
| | | BroadcastAPI.GET_TERMINAL.getUrl(), |
| | | CharUtils.GBK), |
| | | DataResponseVO.class |
| | | ); |
| | | public static TerminalDto getTerminalInfo(Integer terminalId) { |
| | | DataResponseVO responseVO = JSON.parseObject(BroadcastPostUtils.Post(new CommonRequestParams().put("id", terminalId).getParams(), BroadcastAPI.GET_TERMINAL.getUrl(), CharUtils.GBK), DataResponseVO.class); |
| | | |
| | | return responseVO.convert(TerminalVO.class); |
| | | TerminalVO bean = responseVO.convert(TerminalVO.class); |
| | | |
| | | TerminalDto terminalDto = new TerminalDto(); |
| | | BeanUtils.copyProperties(bean, terminalDto); |
| | | //根据API上的更新字段做赋值修改 |
| | | terminalDto.setVolumn(bean.getVolume()); |
| | | terminalDto.setDefaultVolumn(bean.getFirstVol()); |
| | | terminalDto.setDefaultPower(bean.getFirstPower()); |
| | | |
| | | return terminalDto; |
| | | } |
| | | |
| | | /** |
| | | * 获取终端服务器对象列表 |
| | | */ |
| | | public static List<TerminalVO> getTerminalList() { |
| | | ListDataResponseVO responseVO = JSON.parseObject( |
| | | BroadcastPostUtils.Post( |
| | | new CommonRequestParams().getParams(), |
| | | BroadcastAPI.GET_TERMINAL_LIST.getUrl(), |
| | | CharUtils.GBK), |
| | | ListDataResponseVO.class |
| | | ); |
| | | return responseVO.covertTerminalList(); |
| | | public static List<TerminalDto> getTerminalList() { |
| | | ListDataResponseVO responseVO = JSON.parseObject(BroadcastPostUtils.Post(new CommonRequestParams().getParams(), BroadcastAPI.GET_TERMINAL_LIST.getUrl(), CharUtils.GBK), ListDataResponseVO.class); |
| | | |
| | | List<TerminalDto> list = new ArrayList<>(); |
| | | if (responseVO.covertTerminalList() != null) { |
| | | for (TerminalVO bean : responseVO.covertTerminalList()) { |
| | | TerminalDto terminalDto = new TerminalDto(); |
| | | BeanUtils.copyProperties(bean, terminalDto); |
| | | //根据API上的更新字段做赋值修改 |
| | | terminalDto.setVolumn(bean.getVolume()); |
| | | terminalDto.setDefaultVolumn(bean.getFirstVol()); |
| | | terminalDto.setDefaultPower(bean.getFirstPower()); |
| | | list.add(terminalDto); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public static boolean updateTerminal(Integer terminalId, TerminalVO terminalVO, Long userId) { |
| | | CommonResponseVO responseVO = JSON.parseObject( |
| | | BroadcastPostUtils.Post( |
| | | new CommonRequestParams() |
| | | .put("id", terminalId) |
| | | .put("data", JSON.toJSONString(terminalVO)) |
| | | .getParams(), |
| | | BroadcastAPI.UPDATE_TERMINAL.getUrl(), |
| | | CharUtils.GBK), |
| | | CommonResponseVO.class |
| | | ); |
| | | CommonResponseVO responseVO = JSON.parseObject(BroadcastPostUtils.Post(new CommonRequestParams().put("id", terminalId).put("data", JSON.toJSONString(terminalVO)).getParams(), BroadcastAPI.UPDATE_TERMINAL.getUrl(), CharUtils.GBK), CommonResponseVO.class); |
| | | if (responseVO.isOK()) { |
| | | // log("修改播放终端(id:"+terminalId+", name:"+terminalVO.getName()+")",userId,null); |
| | | return true; |
| | |
| | | * @return |
| | | */ |
| | | public static boolean delTerminal(Integer terminalId, Long userId) { |
| | | CommonResponseVO responseVO = JSON.parseObject( |
| | | BroadcastPostUtils.Post( |
| | | new CommonRequestParams() |
| | | .put("id", terminalId) |
| | | .getParams(), |
| | | BroadcastAPI.DEL_TERMINAL.getUrl(), |
| | | CharUtils.GBK), |
| | | CommonResponseVO.class |
| | | ); |
| | | CommonResponseVO responseVO = JSON.parseObject(BroadcastPostUtils.Post(new CommonRequestParams().put("id", terminalId).getParams(), BroadcastAPI.DEL_TERMINAL.getUrl(), CharUtils.GBK), CommonResponseVO.class); |
| | | if (responseVO.isOK()) { |
| | | // log("删除播放终端(id:"+terminalId+")",userId,null); |
| | | return true; |
| | |
| | | * @param terminalId |
| | | * @param defaultVolumn |
| | | */ |
| | | public static boolean changeVol(Integer terminalId, Integer defaultVolumn, Long userId) { |
| | | TerminalVO terminalInfo = getTerminalInfo(terminalId); |
| | | public static boolean changeVol(Integer terminalId, Integer defaultVolumn) { |
| | | TerminalDto terminalInfo = getTerminalInfo(terminalId); |
| | | if (terminalInfo == null) { |
| | | throw new BusinessException("IP音柱硬件设备不存在"); |
| | | } |
| | | terminalInfo.setDefaultVolumn(defaultVolumn); |
| | | terminalInfo.setVolumn(defaultVolumn); |
| | | CommonResponseVO responseVO = JSON.parseObject( |
| | | BroadcastPostUtils.Post( |
| | | new CommonRequestParams() |
| | | .put("id", terminalId) |
| | | .put("data", terminalInfo) |
| | | .getParams(), |
| | | BroadcastAPI.UPDATE_TERMINAL.getUrl(), |
| | | CharUtils.GBK), |
| | | CommonResponseVO.class |
| | | ); |
| | | terminalInfo.setVolume(defaultVolumn); |
| | | |
| | | CommonResponseVO responseVO = JSON.parseObject(BroadcastPostUtils.Post(new CommonRequestParams().put("id", terminalId).put("data", terminalInfo).getParams(), BroadcastAPI.UPDATE_TERMINAL.getUrl(), CharUtils.GBK), CommonResponseVO.class); |
| | | System.out.println(responseVO + " response"); |
| | | if (responseVO.isOK()) { |
| | | // log("修改播放终端音量(id:"+terminalId+")",userId,null); |
| | | return true; |
| | | } |
| | | // logError("修改播放终端音量失败!(id:"+terminalId+")",userId,null); |
| | | return false; |
| | | } |
| | | |