package com.casic.service; import com.alibaba.fastjson.JSONObject; import com.casic.config.AEPParamConfig; import com.casic.config.DeviceGroup; import com.casic.config.PressDeviceConfig; import com.casic.model.BusConfigParam; import com.ctg.ag.sdk.biz.AepDeviceCommandClient; import com.ctg.ag.sdk.biz.aep_device_command.CreateCommandRequest; import com.ctg.ag.sdk.biz.aep_device_command.CreateCommandResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component @Slf4j public class PressCommandSend { @Autowired private AEPParamConfig aepParamConfig; @Autowired private PressDeviceConfig pressDeviceConfig; public String sendConfig(BusConfigParam busConfigParam) { AepDeviceCommandClient client = AepDeviceCommandClient.newClient() .appKey(pressDeviceConfig.getAepKey()).appSecret(pressDeviceConfig.getAepSecret()) .build(); try { busConfigParam.setTtl(pressDeviceConfig.getTtl()); CreateCommandRequest request = new CreateCommandRequest(); request.setParamMasterKey(pressDeviceConfig.getMasterKey()); // single value request.setBody(JSONObject.toJSONString(busConfigParam).getBytes()); CreateCommandResponse msgResponse = client.CreateCommand(request); log.error("-----" + msgResponse.getMessage()); return msgResponse.getStatusCode() == 200 ? "下发成功" : "下发异常"; } catch (Exception ex) { log.error("设备命令下发配置异常,下发配置内容{},aepKey{},aepScret{},异常信息{}", JSONObject.toJSONString(busConfigParam), pressDeviceConfig.getAepKey(), pressDeviceConfig.getAepSecret()); return "下发异常"; } finally { client.shutdown(); } } }