RestartMachineAdapt.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.job.adapt.hcIot;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.java110.core.client.RestTemplate;
  19. import com.java110.job.adapt.DatabusAdaptImpl;
  20. import com.java110.vo.ResultVo;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.http.HttpEntity;
  23. import org.springframework.http.HttpMethod;
  24. import org.springframework.http.HttpStatus;
  25. import org.springframework.http.ResponseEntity;
  26. import org.springframework.stereotype.Component;
  27. import org.springframework.util.MultiValueMap;
  28. /**
  29. * 开门适配器
  30. * 接口协议地址: https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
  31. *
  32. * @desc add by 吴学文 15:29
  33. */
  34. @Component(value = "restartMachineAdapt")
  35. public class RestartMachineAdapt extends DatabusAdaptImpl {
  36. @Autowired
  37. RestTemplate outRestTemplate;
  38. @Override
  39. public ResultVo restartMachine(JSONObject paramIn) {
  40. JSONObject postParameters = new JSONObject();
  41. postParameters.put("machineCode", paramIn.getString("machineCode"));
  42. HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, getHeaders(outRestTemplate));
  43. ResponseEntity<String> responseEntity = outRestTemplate.exchange(IotConstant.getUrl(IotConstant.RESTART_MACHINE), HttpMethod.POST, httpEntity, String.class);
  44. if (responseEntity.getStatusCode() != HttpStatus.OK) {
  45. return new ResultVo(ResultVo.CODE_ERROR, responseEntity.getBody());
  46. }
  47. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  48. return new ResultVo(paramOut.getInteger("code"), paramOut.getString("msg"));
  49. }
  50. }