Commit f06e2b0e3d5c0f53dd5c6223a8ea9c210adc21cb
1 parent
7539135b
Exists in
master
涂鸦接口对接完成
Showing
4 changed files
with
179 additions
and
2 deletions
Show diff stats
springboot/src/main/java/com/sincre/springboot/ApiModel/TuYaAirCondition.java
0 → 100644
| @@ -0,0 +1,100 @@ | @@ -0,0 +1,100 @@ | ||
| 1 | +package com.sincre.springboot.ApiModel; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import io.swagger.annotations.ApiModel; | ||
| 5 | +import io.swagger.annotations.ApiModelProperty; | ||
| 6 | + | ||
| 7 | +@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| 8 | +@ApiModel | ||
| 9 | +public class TuYaAirCondition { | ||
| 10 | + | ||
| 11 | + @ApiModelProperty(name = "remote_index",value="遥控器索引",required = true) | ||
| 12 | + private String remote_index; | ||
| 13 | + @ApiModelProperty(name = "remote_id",value="遥控器标识",required = true) | ||
| 14 | + private String remote_id; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 开关(1:开,0:关) | ||
| 18 | + */ | ||
| 19 | + @ApiModelProperty(name = "power",value="开关(1:开,0:关)",required = true) | ||
| 20 | + private String power; | ||
| 21 | + /** | ||
| 22 | + * 模式(0:制冷,1:制热,2:自动,3:送风,4:除湿) | ||
| 23 | + */ | ||
| 24 | + @ApiModelProperty(name = "power",value="开关(1:开,0:关)") | ||
| 25 | + private String mode; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 温度(16-30) | ||
| 29 | + */ | ||
| 30 | + @ApiModelProperty(name = "temp",value="温度(16-30)") | ||
| 31 | + private String temp; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 风速(0:自动,1:低,2:中,3:高) | ||
| 35 | + */ | ||
| 36 | + @ApiModelProperty(name = "wind",value = "风速(0:自动,1:低,2:中,3:高)") | ||
| 37 | + private String wind; | ||
| 38 | + | ||
| 39 | + public String getRemote_index() { | ||
| 40 | + return remote_index; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setRemote_index(String remote_index) { | ||
| 44 | + this.remote_index = remote_index; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getRemote_id() { | ||
| 48 | + return remote_id; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setRemote_id(String remote_id) { | ||
| 52 | + this.remote_id = remote_id; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getPower() { | ||
| 56 | + return power; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setPower(String power) { | ||
| 60 | + this.power = power; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getMode() { | ||
| 64 | + return mode; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setMode(String mode) { | ||
| 68 | + this.mode = mode; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public String getTemp() { | ||
| 72 | + return temp; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setTemp(String temp) { | ||
| 76 | + this.temp = temp; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public String getWind() { | ||
| 80 | + return wind; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void setWind(String wind) { | ||
| 84 | + this.wind = wind; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public String getSwing() { | ||
| 88 | + return swing; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public void setSwing(String swing) { | ||
| 92 | + this.swing = swing; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 风向(暂时不支持) | ||
| 97 | + */ | ||
| 98 | + @ApiModelProperty(name = "swing",value = "风向(暂时不支持)") | ||
| 99 | + private String swing; | ||
| 100 | +} |
springboot/src/main/java/com/sincre/springboot/ApiModel/TuYaInfrared.java
| 1 | package com.sincre.springboot.ApiModel; | 1 | package com.sincre.springboot.ApiModel; |
| 2 | 2 | ||
| 3 | import com.fasterxml.jackson.annotation.JsonInclude; | 3 | import com.fasterxml.jackson.annotation.JsonInclude; |
| 4 | +import io.swagger.annotations.ApiModel; | ||
| 5 | +import io.swagger.annotations.ApiModelProperty; | ||
| 4 | 6 | ||
| 5 | /** | 7 | /** |
| 6 | * 红外所需要的类 | 8 | * 红外所需要的类 |
| 7 | */ | 9 | */ |
| 8 | 10 | ||
| 9 | @JsonInclude(JsonInclude.Include.NON_EMPTY) | 11 | @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| 12 | +@ApiModel | ||
| 10 | public class TuYaInfrared { | 13 | public class TuYaInfrared { |
| 11 | 14 | ||
| 15 | + /** | ||
| 16 | + * 类型ID | ||
| 17 | + */ | ||
| 18 | + @ApiModelProperty(name = "category_id",value = "类型ID") | ||
| 12 | private String category_id; | 19 | private String category_id; |
| 13 | 20 | ||
| 14 | public String getCategory_id() { | 21 | public String getCategory_id() { |
| @@ -27,6 +34,7 @@ public class TuYaInfrared { | @@ -27,6 +34,7 @@ public class TuYaInfrared { | ||
| 27 | this.category_name = category_name; | 34 | this.category_name = category_name; |
| 28 | } | 35 | } |
| 29 | 36 | ||
| 37 | + | ||
| 30 | public String getBrand_id() { | 38 | public String getBrand_id() { |
| 31 | return brand_id; | 39 | return brand_id; |
| 32 | } | 40 | } |
| @@ -51,14 +59,34 @@ public class TuYaInfrared { | @@ -51,14 +59,34 @@ public class TuYaInfrared { | ||
| 51 | this.remote_index = remote_index; | 59 | this.remote_index = remote_index; |
| 52 | } | 60 | } |
| 53 | 61 | ||
| 54 | - | 62 | + /** |
| 63 | + * 类型名称 | ||
| 64 | + */ | ||
| 65 | + @ApiModelProperty(name = "category_name",value = "类型名称") | ||
| 55 | private String category_name; | 66 | private String category_name; |
| 56 | 67 | ||
| 68 | + /** | ||
| 69 | + * 商品标识 | ||
| 70 | + * @return | ||
| 71 | + */ | ||
| 72 | + @ApiModelProperty(name = "brand_id",value = "商标标识") | ||
| 57 | private String brand_id; | 73 | private String brand_id; |
| 58 | 74 | ||
| 75 | + /** | ||
| 76 | + * 商品名称 | ||
| 77 | + */ | ||
| 78 | + @ApiModelProperty(name="brand_name",value = "商品名称") | ||
| 59 | private String brand_name; | 79 | private String brand_name; |
| 60 | 80 | ||
| 81 | + /** | ||
| 82 | + * 遥控索引 | ||
| 83 | + */ | ||
| 84 | + @ApiModelProperty(name="remote_index",value = "遥控索引") | ||
| 61 | private String remote_index; | 85 | private String remote_index; |
| 86 | + /** | ||
| 87 | + * 遥控标识 | ||
| 88 | + */ | ||
| 89 | + @ApiModelProperty(name = "remote_id",value = "遥控标识") | ||
| 62 | private String remote_id; | 90 | private String remote_id; |
| 63 | 91 | ||
| 64 | public String getRemote_id() { | 92 | public String getRemote_id() { |
| @@ -77,5 +105,9 @@ public class TuYaInfrared { | @@ -77,5 +105,9 @@ public class TuYaInfrared { | ||
| 77 | this.remote_name = remote_name; | 105 | this.remote_name = remote_name; |
| 78 | } | 106 | } |
| 79 | 107 | ||
| 108 | + /** | ||
| 109 | + * 遥控名称 | ||
| 110 | + */ | ||
| 111 | + @ApiModelProperty(name = "remote_name",value = "遥控名称") | ||
| 80 | private String remote_name; | 112 | private String remote_name; |
| 81 | } | 113 | } |
springboot/src/main/java/com/sincre/springboot/common/ServerResponse.java
| @@ -2,6 +2,8 @@ package com.sincre.springboot.common; | @@ -2,6 +2,8 @@ package com.sincre.springboot.common; | ||
| 2 | 2 | ||
| 3 | import com.fasterxml.jackson.annotation.JsonIgnore; | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 4 | import com.fasterxml.jackson.annotation.JsonInclude; | 4 | import com.fasterxml.jackson.annotation.JsonInclude; |
| 5 | +import io.swagger.annotations.ApiModel; | ||
| 6 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | 7 | ||
| 6 | 8 | ||
| 7 | import java.io.Serializable; | 9 | import java.io.Serializable; |
| @@ -10,24 +12,28 @@ import java.io.Serializable; | @@ -10,24 +12,28 @@ import java.io.Serializable; | ||
| 10 | * Created by Ziv | 12 | * Created by Ziv |
| 11 | */ | 13 | */ |
| 12 | @JsonInclude(JsonInclude.Include.NON_EMPTY) | 14 | @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| 13 | - | 15 | +@ApiModel |
| 14 | public class ServerResponse<T> implements Serializable { | 16 | public class ServerResponse<T> implements Serializable { |
| 15 | 17 | ||
| 16 | /** | 18 | /** |
| 17 | * 分页时用到的总数量 | 19 | * 分页时用到的总数量 |
| 18 | */ | 20 | */ |
| 21 | + @ApiModelProperty(name="total",value = "分页时用到的总数量,当返回的是集合对象的时候,才有该值,否者该值不存在") | ||
| 19 | private String total; | 22 | private String total; |
| 20 | /** | 23 | /** |
| 21 | * 操作状态码 | 24 | * 操作状态码 |
| 22 | */ | 25 | */ |
| 26 | + @ApiModelProperty(name="code",value = "操作状态码") | ||
| 23 | private int code; | 27 | private int code; |
| 24 | /** | 28 | /** |
| 25 | * 状态信息 | 29 | * 状态信息 |
| 26 | */ | 30 | */ |
| 31 | + @ApiModelProperty(name="msg",value = "状态信息") | ||
| 27 | private String msg; | 32 | private String msg; |
| 28 | /** | 33 | /** |
| 29 | * 返回的数据包 | 34 | * 返回的数据包 |
| 30 | */ | 35 | */ |
| 36 | + @ApiModelProperty(name="data",value = "返回的数据包") | ||
| 31 | private T data; | 37 | private T data; |
| 32 | 38 | ||
| 33 | private ServerResponse(int code) { | 39 | private ServerResponse(int code) { |
springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java
| @@ -440,6 +440,45 @@ public class TuYaYunController { | @@ -440,6 +440,45 @@ public class TuYaYunController { | ||
| 440 | TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | 440 | TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); |
| 441 | return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | 441 | return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); |
| 442 | } | 442 | } |
| 443 | + | ||
| 444 | + @ApiOperation("同步空调当前状态") | ||
| 445 | + @ApiImplicitParams({ | ||
| 446 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path"), | ||
| 447 | + @ApiImplicitParam(name="remote_id",value = "设备ID",required = true,paramType = "path") | ||
| 448 | + }) | ||
| 449 | + @GetMapping("{infrared_id}/getHWAirStatus/{remote_id}") | ||
| 450 | + public ServerResponse getHWAirStatus(@PathVariable String infrared_id,@PathVariable String remote_id){ | ||
| 451 | + | ||
| 452 | + String apiUrl = String.format("/v1.0/infrareds/%s/remotes/%s/ac/status",infrared_id,remote_id); | ||
| 453 | + Map<String,String> map = headContent(); | ||
| 454 | + String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | ||
| 455 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | ||
| 456 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 457 | + } | ||
| 458 | + | ||
| 459 | + @ApiOperation("下发空调红外码") | ||
| 460 | + @ApiImplicitParam(name="infrared_id",value = "设备ID",required = true,paramType = "path") | ||
| 461 | + @PostMapping("{infrared_id}/addAirCode") | ||
| 462 | + public ServerResponse addAirCode(@RequestBody TuYaAirCondition tuYaAirCondition,@PathVariable String infrared_id){ | ||
| 463 | + | ||
| 464 | + if(StringUtils.isBlank(infrared_id)||tuYaAirCondition==null){ | ||
| 465 | + return ServerResponse.createByErrorCodeMessage(400,"参数错误"); | ||
| 466 | + } | ||
| 467 | + else{ | ||
| 468 | + if(StringUtils.isBlank(tuYaAirCondition.getRemote_id())||StringUtils.isBlank(tuYaAirCondition.getRemote_index())){ | ||
| 469 | + return ServerResponse.createByErrorCodeMessage(400,"参数错误"); | ||
| 470 | + } | ||
| 471 | + } | ||
| 472 | + String apiUrl = String.format("/v1.0/infrareds/%s/ac/send-keys",infrared_id); | ||
| 473 | + Map<String,String> map = headContent(); | ||
| 474 | + | ||
| 475 | + String json = JSON.toJSONString(tuYaAirCondition); | ||
| 476 | + String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,map,json); | ||
| 477 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | ||
| 478 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 479 | + } | ||
| 480 | + | ||
| 481 | + | ||
| 443 | /** | 482 | /** |
| 444 | * 请求头的参数 | 483 | * 请求头的参数 |
| 445 | * @return | 484 | * @return |