package com.casic.service.impl; import com.alibaba.fastjson.JSONObject; import com.casic.config.AEPParamConfig; import com.casic.model.AlarmConfigParam; import com.casic.model.BusConfigParam; import com.casic.model.DataGasConfigParam; import com.ctg.ag.sdk.biz.AepDeviceCommandClient; import com.ctg.ag.sdk.biz.aep_device_command.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.List; import java.util.Map; @Component @Slf4j public class AepCommandSend { @Autowired private AEPParamConfig aepParamConfig; public void sendStatusNb(List<DataGasConfigParam> dataGasConfigList) throws Exception { AepDeviceCommandClient client = AepDeviceCommandClient.newClient() .appKey(aepParamConfig.getAppKey()).appSecret(aepParamConfig.getAppSecret()) .build(); Map<String, Object> dataGasMap = new HashMap<>(); Map<String, Object> queryMap = new HashMap<>(); queryMap.put("query", 1); dataGasMap.put("params", queryMap); dataGasMap.put("serviceIdentifier", "DeviceQuery"); dataGasConfigList.forEach( dataGasConfigParam -> { dataGasConfigParam.setLevel(1); dataGasConfigParam.setContent(dataGasMap); dataGasConfigParam.setOperator("casic"); } ); for (DataGasConfigParam dataGasConfigParam : dataGasConfigList) { CreateCommandRequest request = new CreateCommandRequest(); request.setParamMasterKey(aepParamConfig.getMasterKey()); // single value request.setBody(JSONObject.toJSONString(dataGasConfigParam).getBytes()); //具体格式见前面请求body说明 System.out.println(client.CreateCommand(request)); } client.shutdown(); } public String sendConfig(BusConfigParam busConfigParam) throws Exception { AepDeviceCommandClient client = AepDeviceCommandClient.newClient() .appKey(aepParamConfig.getAppKey()).appSecret(aepParamConfig.getAppSecret()) .build(); Map<String, Object> dataGasMap = new HashMap<>(); dataGasMap.put("serviceIdentifier", "config"); dataGasMap.put("params", busConfigParam.getQueryContent()); busConfigParam.setContent(dataGasMap); busConfigParam.setLevel(1); busConfigParam.setOperator("casic"); CreateCommandRequest request = new CreateCommandRequest(); request.setParamMasterKey(aepParamConfig.getMasterKey()); // single value request.setBody(JSONObject.toJSONString(busConfigParam).getBytes()); //具体格式见前面请求body说明 CreateCommandResponse msgResponse = client.CreateCommand(request); System.out.println(msgResponse); client.shutdown(); log.debug("-----" + msgResponse.getMessage()); if (msgResponse.getStatusCode()==200) { return "未下发"; } else { return "下发异常"; } } public String sendAlarmConfig(AlarmConfigParam alarmConfigParam) throws Exception { AepDeviceCommandClient client = AepDeviceCommandClient.newClient() .appKey(aepParamConfig.getAppKey()).appSecret(aepParamConfig.getAppSecret()) .build(); Map<String, Object> dataGasMap = new HashMap<>(); dataGasMap.put("serviceIdentifier", "alarmconfig"); dataGasMap.put("params", alarmConfigParam.getQueryContent()); alarmConfigParam.setContent(dataGasMap); alarmConfigParam.setLevel(1); alarmConfigParam.setOperator("casic"); CreateCommandRequest request = new CreateCommandRequest(); request.setParamMasterKey(aepParamConfig.getMasterKey()); // single value request.setBody(JSONObject.toJSONString(alarmConfigParam).getBytes()); //具体格式见前面请求body说明 CreateCommandResponse msgResponse = client.CreateCommand(request); System.out.println(msgResponse); client.shutdown(); log.debug("-----" + msgResponse.getMessage()); if (msgResponse.getStatusCode()==200) { return "未下发"; } else { return "下发异常"; } } }