Commit bd5a4be2381142a7cb6e96aa05522e1c4d2d0c96
Exists in
master
Merge branch 'master' of http://git.shunzhi.net/taohd/javassm
# Conflicts: # springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java
Showing
4 changed files
with
254 additions
and
112 deletions
Show diff stats
springboot/src/main/java/com/sincre/springboot/ApiModel/TuYaResResult.java
| @@ -5,11 +5,11 @@ import com.fasterxml.jackson.annotation.JsonInclude; | @@ -5,11 +5,11 @@ import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 5 | @JsonInclude(JsonInclude.Include.NON_EMPTY) | 5 | @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| 6 | public class TuYaResResult<T> { | 6 | public class TuYaResResult<T> { |
| 7 | 7 | ||
| 8 | - public String getSuccess() { | 8 | + public Boolean getSuccess() { |
| 9 | return success; | 9 | return success; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | - public void setSuccess(String success) { | 12 | + public void setSuccess(Boolean success) { |
| 13 | this.success = success; | 13 | this.success = success; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| @@ -45,7 +45,7 @@ public class TuYaResResult<T> { | @@ -45,7 +45,7 @@ public class TuYaResResult<T> { | ||
| 45 | this.t = t; | 45 | this.t = t; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | - private String success; | 48 | + private Boolean success; |
| 49 | private String code; | 49 | private String code; |
| 50 | private String msg; | 50 | private String msg; |
| 51 | private Long t; | 51 | private Long t; |
springboot/src/main/java/com/sincre/springboot/controller/TuYaYunController.java
| 1 | package com.sincre.springboot.controller; | 1 | package com.sincre.springboot.controller; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 3 | import com.fasterxml.jackson.core.type.TypeReference; | 4 | import com.fasterxml.jackson.core.type.TypeReference; |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | 5 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | -import com.sincre.springboot.ApiModel.DeviceToken; | ||
| 6 | -import com.sincre.springboot.ApiModel.TuYaDevicesList; | ||
| 7 | -import com.sincre.springboot.ApiModel.TuYaResResult; | ||
| 8 | -import com.sincre.springboot.ApiModel.UserInfo; | 6 | +import com.sincre.springboot.ApiModel.*; |
| 9 | import com.sincre.springboot.ApiPlatform.TuYaCloudService; | 7 | import com.sincre.springboot.ApiPlatform.TuYaCloudService; |
| 8 | +import com.sincre.springboot.common.ServerResponse; | ||
| 10 | import com.sincre.springboot.utils.ApiHelper; | 9 | import com.sincre.springboot.utils.ApiHelper; |
| 11 | import com.sincre.springboot.utils.CacheHelper; | 10 | import com.sincre.springboot.utils.CacheHelper; |
| 12 | import com.sincre.springboot.utils.ResultUtils; | 11 | import com.sincre.springboot.utils.ResultUtils; |
| 13 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
| 13 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 14 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 15 | +import io.swagger.annotations.ApiOperation; | ||
| 14 | import org.springframework.web.bind.annotation.*; | 16 | import org.springframework.web.bind.annotation.*; |
| 15 | 17 | ||
| 16 | import java.util.HashMap; | 18 | import java.util.HashMap; |
| @@ -22,7 +24,7 @@ import java.util.Map; | @@ -22,7 +24,7 @@ import java.util.Map; | ||
| 22 | public class TuYaYunController { | 24 | public class TuYaYunController { |
| 23 | 25 | ||
| 24 | @GetMapping("GetDevicesInfo") | 26 | @GetMapping("GetDevicesInfo") |
| 25 | - public TuYaResResult getTuYaDevicesInfo(){ | 27 | + public ServerResponse getTuYaDevicesInfo(){ |
| 26 | 28 | ||
| 27 | String apiUrl = "/v1.0/devices?device_ids="; | 29 | String apiUrl = "/v1.0/devices?device_ids="; |
| 28 | Long t = System.currentTimeMillis(); | 30 | Long t = System.currentTimeMillis(); |
| @@ -36,16 +38,18 @@ public class TuYaYunController { | @@ -36,16 +38,18 @@ public class TuYaYunController { | ||
| 36 | map.put("t",t.toString()); | 38 | map.put("t",t.toString()); |
| 37 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | 39 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); |
| 38 | 40 | ||
| 39 | - TuYaResResult<TuYaDevicesList> resResult = null; | ||
| 40 | - try{ | ||
| 41 | - ObjectMapper objectMapper = new ObjectMapper(); | ||
| 42 | - TypeReference<TuYaResResult<TuYaDevicesList>> reference = new TypeReference<TuYaResResult<TuYaDevicesList>>(){}; | ||
| 43 | - resResult = objectMapper.readValue(result,reference); | ||
| 44 | - } catch(Exception ex){ | ||
| 45 | - System.out.println(ex.getMessage()); | ||
| 46 | - } | 41 | +// TuYaResResult<TuYaDevicesList> resResult = null; |
| 42 | +// try{ | ||
| 43 | +// ObjectMapper objectMapper = new ObjectMapper(); | ||
| 44 | +// TypeReference<TuYaResResult<TuYaDevicesList>> reference = new TypeReference<TuYaResResult<TuYaDevicesList>>(){}; | ||
| 45 | +// resResult = objectMapper.readValue(result,reference); | ||
| 46 | +// } catch(Exception ex){ | ||
| 47 | +// System.out.println(ex.getMessage()); | ||
| 48 | +// } | ||
| 47 | System.out.println(result); | 49 | System.out.println(result); |
| 48 | - return resResult; | 50 | + |
| 51 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | ||
| 52 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 49 | } | 53 | } |
| 50 | 54 | ||
| 51 | 55 | ||
| @@ -56,8 +60,13 @@ public class TuYaYunController { | @@ -56,8 +60,13 @@ public class TuYaYunController { | ||
| 56 | * @param pageSize 大小 | 60 | * @param pageSize 大小 |
| 57 | * @return | 61 | * @return |
| 58 | */ | 62 | */ |
| 63 | + @ApiOperation(value = "获取用户信息列表") | ||
| 64 | + @ApiImplicitParams({ | ||
| 65 | + @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true), | ||
| 66 | + @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50") | ||
| 67 | + }) | ||
| 59 | @GetMapping("{AppId}/GetTuYaAPPUser") | 68 | @GetMapping("{AppId}/GetTuYaAPPUser") |
| 60 | - public String getTuYaAPPUser(@PathVariable("AppId") String AppId, @RequestParam int pageIndex, @RequestParam int pageSize){ | 69 | + public ServerResponse getTuYaAPPUser(@PathVariable("AppId") String AppId, @RequestParam int pageIndex, @RequestParam(defaultValue = "10") int pageSize){ |
| 61 | 70 | ||
| 62 | String apiUrl = String.format("/v1.0/apps/%s/users?page_no=%d&page_size=%d",AppId,pageIndex,pageSize);//iotshunzhi | 71 | String apiUrl = String.format("/v1.0/apps/%s/users?page_no=%d&page_size=%d",AppId,pageIndex,pageSize);//iotshunzhi |
| 63 | Long t = System.currentTimeMillis(); | 72 | Long t = System.currentTimeMillis(); |
| @@ -73,12 +82,13 @@ public class TuYaYunController { | @@ -73,12 +82,13 @@ public class TuYaYunController { | ||
| 73 | 82 | ||
| 74 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,headMap); | 83 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,headMap); |
| 75 | 84 | ||
| 76 | - return result; | 85 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); |
| 86 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 77 | } | 87 | } |
| 78 | 88 | ||
| 79 | 89 | ||
| 80 | @PostMapping("{AppId}/AddTuYaAPPUser") | 90 | @PostMapping("{AppId}/AddTuYaAPPUser") |
| 81 | - public String addTuYaAPPUser(@PathVariable("AppId") String AppId,@RequestBody UserInfo userInfo){ | 91 | + public ServerResponse addTuYaAPPUser(@PathVariable("AppId") String AppId, @RequestBody UserInfo userInfo){ |
| 82 | 92 | ||
| 83 | String apiUrl = String.format("/v1.0/apps/%s/user",AppId);//应用标识iotshunzhi | 93 | String apiUrl = String.format("/v1.0/apps/%s/user",AppId);//应用标识iotshunzhi |
| 84 | Long t = System.currentTimeMillis(); | 94 | Long t = System.currentTimeMillis(); |
| @@ -93,7 +103,6 @@ public class TuYaYunController { | @@ -93,7 +103,6 @@ public class TuYaYunController { | ||
| 93 | headMap.put("t",t.toString()); | 103 | headMap.put("t",t.toString()); |
| 94 | 104 | ||
| 95 | ObjectMapper objectMapper = new ObjectMapper(); | 105 | ObjectMapper objectMapper = new ObjectMapper(); |
| 96 | - | ||
| 97 | String jsonResult = ""; | 106 | String jsonResult = ""; |
| 98 | try { | 107 | try { |
| 99 | jsonResult = objectMapper.writeValueAsString(userInfo); | 108 | jsonResult = objectMapper.writeValueAsString(userInfo); |
| @@ -103,9 +112,8 @@ public class TuYaYunController { | @@ -103,9 +112,8 @@ public class TuYaYunController { | ||
| 103 | 112 | ||
| 104 | String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,headMap,jsonResult); | 113 | String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,headMap,jsonResult); |
| 105 | 114 | ||
| 106 | - TuYaResResult<UserInfo> resResult = null; | ||
| 107 | - | ||
| 108 | - return result; | 115 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); |
| 116 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 109 | } | 117 | } |
| 110 | 118 | ||
| 111 | /** | 119 | /** |
| @@ -114,7 +122,7 @@ public class TuYaYunController { | @@ -114,7 +122,7 @@ public class TuYaYunController { | ||
| 114 | * @return | 122 | * @return |
| 115 | */ | 123 | */ |
| 116 | @GetMapping("{uid}/GetDevicesByUid") | 124 | @GetMapping("{uid}/GetDevicesByUid") |
| 117 | - public String getDevicesByUid(@PathVariable("uid") String uid){ | 125 | + public ServerResponse getDevicesByUid(@PathVariable("uid") String uid){ |
| 118 | 126 | ||
| 119 | String apiUrl = String.format("/v1.0/users/%s/devices",uid); | 127 | String apiUrl = String.format("/v1.0/users/%s/devices",uid); |
| 120 | Long t = System.currentTimeMillis(); | 128 | Long t = System.currentTimeMillis(); |
| @@ -130,14 +138,16 @@ public class TuYaYunController { | @@ -130,14 +138,16 @@ public class TuYaYunController { | ||
| 130 | 138 | ||
| 131 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | 139 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); |
| 132 | 140 | ||
| 133 | - return result; | 141 | + System.out.println(result); |
| 142 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); | ||
| 143 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 134 | } | 144 | } |
| 135 | /** | 145 | /** |
| 136 | * 生成配网的Token | 146 | * 生成配网的Token |
| 137 | * @return | 147 | * @return |
| 138 | */ | 148 | */ |
| 139 | @GetMapping("AddDevicesToken") | 149 | @GetMapping("AddDevicesToken") |
| 140 | - public String addDevicesToken(@RequestParam String UId){ | 150 | + public ServerResponse addDevicesToken(@RequestParam String UId){ |
| 141 | 151 | ||
| 142 | String apiUrl = String.format("/v1.0/devices/token"); | 152 | String apiUrl = String.format("/v1.0/devices/token"); |
| 143 | Long t = System.currentTimeMillis(); | 153 | Long t = System.currentTimeMillis(); |
| @@ -164,11 +174,12 @@ public class TuYaYunController { | @@ -164,11 +174,12 @@ public class TuYaYunController { | ||
| 164 | } | 174 | } |
| 165 | String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,map,jsonResult); | 175 | String result = ApiHelper.doPost(TuYaCloudService.TuYaOpenUrl + apiUrl,map,jsonResult); |
| 166 | 176 | ||
| 167 | - return result; | 177 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); |
| 178 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 168 | } | 179 | } |
| 169 | 180 | ||
| 170 | @GetMapping("{token}/GetDevicesByToken") | 181 | @GetMapping("{token}/GetDevicesByToken") |
| 171 | - public String getDevicesByToken(@PathVariable("token") String token){ | 182 | + public ServerResponse getDevicesByToken(@PathVariable("token") String token){ |
| 172 | 183 | ||
| 173 | String apiUrl = String.format("/v1.0/devices/tokens/%s",token); | 184 | String apiUrl = String.format("/v1.0/devices/tokens/%s",token); |
| 174 | Long t = System.currentTimeMillis(); | 185 | Long t = System.currentTimeMillis(); |
| @@ -184,6 +195,7 @@ public class TuYaYunController { | @@ -184,6 +195,7 @@ public class TuYaYunController { | ||
| 184 | 195 | ||
| 185 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); | 196 | String result = ApiHelper.doGet(TuYaCloudService.TuYaOpenUrl + apiUrl,map); |
| 186 | 197 | ||
| 187 | - return result; | 198 | + TuYaResResult tuYaResResult = JSON.parseObject(result,TuYaResResult.class); |
| 199 | + return ResultUtils.getInstance().returnResultTuYa(tuYaResResult); | ||
| 188 | } | 200 | } |
| 189 | } | 201 | } |
springboot/src/main/java/com/sincre/springboot/controller/YinShiController.java
| @@ -3,6 +3,7 @@ package com.sincre.springboot.controller; | @@ -3,6 +3,7 @@ package com.sincre.springboot.controller; | ||
| 3 | 3 | ||
| 4 | import com.alibaba.fastjson.JSON; | 4 | import com.alibaba.fastjson.JSON; |
| 5 | import com.sincre.springboot.ApiModel.YinShiResResult; | 5 | import com.sincre.springboot.ApiModel.YinShiResResult; |
| 6 | +import com.sincre.springboot.ApiPlatform.YinShiServiceConfig; | ||
| 6 | import com.sincre.springboot.common.MD5; | 7 | import com.sincre.springboot.common.MD5; |
| 7 | import com.sincre.springboot.common.ResponseCode; | 8 | import com.sincre.springboot.common.ResponseCode; |
| 8 | import com.sincre.springboot.common.ServerResponse; | 9 | import com.sincre.springboot.common.ServerResponse; |
| @@ -10,19 +11,17 @@ import com.sincre.springboot.utils.ApiHelper; | @@ -10,19 +11,17 @@ import com.sincre.springboot.utils.ApiHelper; | ||
| 10 | import com.sincre.springboot.utils.CacheHelper; | 11 | import com.sincre.springboot.utils.CacheHelper; |
| 11 | import com.sincre.springboot.utils.ResultUtils; | 12 | import com.sincre.springboot.utils.ResultUtils; |
| 12 | import io.swagger.annotations.Api; | 13 | import io.swagger.annotations.Api; |
| 14 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 15 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 13 | import io.swagger.annotations.ApiOperation; | 16 | import io.swagger.annotations.ApiOperation; |
| 14 | -import org.json.JSONObject; | ||
| 15 | import org.springframework.web.bind.annotation.GetMapping; | 17 | import org.springframework.web.bind.annotation.GetMapping; |
| 16 | import org.springframework.web.bind.annotation.RequestMapping; | 18 | import org.springframework.web.bind.annotation.RequestMapping; |
| 17 | import org.springframework.web.bind.annotation.RequestParam; | 19 | import org.springframework.web.bind.annotation.RequestParam; |
| 18 | import org.springframework.web.bind.annotation.RestController; | 20 | import org.springframework.web.bind.annotation.RestController; |
| 19 | 21 | ||
| 20 | -import java.util.Date; | ||
| 21 | import java.util.HashMap; | 22 | import java.util.HashMap; |
| 22 | import java.util.Map; | 23 | import java.util.Map; |
| 23 | 24 | ||
| 24 | -import com.sincre.springboot.ApiPlatform.YinShiServiceConfig; | ||
| 25 | - | ||
| 26 | @RestController | 25 | @RestController |
| 27 | @RequestMapping("/YinShi") | 26 | @RequestMapping("/YinShi") |
| 28 | @Api(value = "YinShiController", tags = "萤石对接接口") | 27 | @Api(value = "YinShiController", tags = "萤石对接接口") |
| @@ -39,7 +38,7 @@ public class YinShiController { | @@ -39,7 +38,7 @@ public class YinShiController { | ||
| 39 | 38 | ||
| 40 | @ApiOperation(value = "增加子账号") | 39 | @ApiOperation(value = "增加子账号") |
| 41 | @GetMapping("/addChildAccount") | 40 | @GetMapping("/addChildAccount") |
| 42 | - public String addChildAccount(@RequestParam String accountName, @RequestParam String password) { | 41 | + public ServerResponse addChildAccount(@RequestParam String accountName, @RequestParam String password) { |
| 43 | 42 | ||
| 44 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; | 43 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/create"; |
| 45 | Map<String, Object> map = new HashMap<>(); | 44 | Map<String, Object> map = new HashMap<>(); |
| @@ -54,28 +53,38 @@ public class YinShiController { | @@ -54,28 +53,38 @@ public class YinShiController { | ||
| 54 | map.put("accountName", accountName); | 53 | map.put("accountName", accountName); |
| 55 | map.put("password", password); | 54 | map.put("password", password); |
| 56 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | 55 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); |
| 57 | - return result;//ResultUtils.getInstance().resturnResultYingshi(result); | 56 | + |
| 57 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 58 | + | ||
| 59 | + System.out.println(result); | ||
| 60 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 58 | } | 61 | } |
| 59 | 62 | ||
| 60 | @ApiOperation(value = "获取单个子账户信息") | 63 | @ApiOperation(value = "获取单个子账户信息") |
| 64 | + @ApiImplicitParam(name="accountId",value = "子账号标识",required = true,dataType = "String") | ||
| 61 | @GetMapping("getChildAccount") | 65 | @GetMapping("getChildAccount") |
| 62 | - public String getChildAccount(@RequestParam String accountId, @RequestParam String accountName) { | 66 | + public ServerResponse getChildAccount(@RequestParam String accountId) { |
| 63 | 67 | ||
| 64 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; | 68 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/get"; |
| 65 | Map<String, Object> map = new HashMap<>(); | 69 | Map<String, Object> map = new HashMap<>(); |
| 66 | 70 | ||
| 67 | map.put("accessToken", YinShiServiceConfig.AccessToken); | 71 | map.put("accessToken", YinShiServiceConfig.AccessToken); |
| 68 | map.put("accountId", accountId); | 72 | map.put("accountId", accountId); |
| 69 | - map.put("accountName", accountName); | ||
| 70 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | 73 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); |
| 74 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 71 | 75 | ||
| 72 | - return result; | 76 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); |
| 73 | } | 77 | } |
| 74 | 78 | ||
| 75 | @ApiOperation(value = "获取子账号信息列表") | 79 | @ApiOperation(value = "获取子账号信息列表") |
| 80 | + @ApiImplicitParams({ | ||
| 81 | + @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true), | ||
| 82 | + @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50") | ||
| 83 | + }) | ||
| 76 | @GetMapping("getChildAccountList") | 84 | @GetMapping("getChildAccountList") |
| 77 | - public ServerResponse getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) { | 85 | + public ServerResponse getChildAccountList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) { |
| 78 | 86 | ||
| 87 | + pageIndex = pageIndex - 1; | ||
| 79 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list"; | 88 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/list"; |
| 80 | Map<String, Object> map = new HashMap<>(); | 89 | Map<String, Object> map = new HashMap<>(); |
| 81 | 90 | ||
| @@ -84,15 +93,14 @@ public class YinShiController { | @@ -84,15 +93,14 @@ public class YinShiController { | ||
| 84 | map.put("pageSize", pageSize); | 93 | map.put("pageSize", pageSize); |
| 85 | String result = ApiHelper.doPost(url, new HashMap<String,String>(), map); | 94 | String result = ApiHelper.doPost(url, new HashMap<String,String>(), map); |
| 86 | 95 | ||
| 87 | - System.out.println(result); | ||
| 88 | YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | 96 | YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); |
| 89 | 97 | ||
| 90 | - return ResultUtils.getInstance().resturnResultYingshi(yinShiResResult); | 98 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); |
| 91 | } | 99 | } |
| 92 | 100 | ||
| 93 | @ApiOperation(value = "修改当前子账户密码") | 101 | @ApiOperation(value = "修改当前子账户密码") |
| 94 | @GetMapping("updateChildPassword") | 102 | @GetMapping("updateChildPassword") |
| 95 | - public String updateChildPassword(@RequestParam("accountId") String accountId, @RequestParam("newPassword") String newPassword, @RequestParam("oldPassword") String oldPassword) { | 103 | + public ServerResponse updateChildPassword(@RequestParam("accountId") String accountId, @RequestParam("newPassword") String newPassword, @RequestParam("oldPassword") String oldPassword) { |
| 96 | 104 | ||
| 97 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword"; | 105 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/updatePassword"; |
| 98 | Map<String, Object> map = new HashMap<>(); | 106 | Map<String, Object> map = new HashMap<>(); |
| @@ -110,13 +118,14 @@ public class YinShiController { | @@ -110,13 +118,14 @@ public class YinShiController { | ||
| 110 | map.put("oldPassword", oldPassword); | 118 | map.put("oldPassword", oldPassword); |
| 111 | map.put("newPassword", newPassword); | 119 | map.put("newPassword", newPassword); |
| 112 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | 120 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); |
| 121 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 113 | 122 | ||
| 114 | - return result; | 123 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); |
| 115 | } | 124 | } |
| 116 | 125 | ||
| 117 | @ApiOperation(value = "删除指定子账户") | 126 | @ApiOperation(value = "删除指定子账户") |
| 118 | @GetMapping("deleteChildAccount") | 127 | @GetMapping("deleteChildAccount") |
| 119 | - public String deleteChildAccount(@RequestParam String accountId) { | 128 | + public ServerResponse deleteChildAccount(@RequestParam String accountId) { |
| 120 | 129 | ||
| 121 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; | 130 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/account/delete"; |
| 122 | Map<String, Object> map = new HashMap<>(); | 131 | Map<String, Object> map = new HashMap<>(); |
| @@ -124,14 +133,15 @@ public class YinShiController { | @@ -124,14 +133,15 @@ public class YinShiController { | ||
| 124 | map.put("accessToken", YinShiServiceConfig.AccessToken); | 133 | map.put("accessToken", YinShiServiceConfig.AccessToken); |
| 125 | map.put("accountId", accountId); | 134 | map.put("accountId", accountId); |
| 126 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | 135 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); |
| 136 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 127 | 137 | ||
| 128 | - return result; | 138 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); |
| 129 | } | 139 | } |
| 130 | 140 | ||
| 131 | 141 | ||
| 132 | @ApiOperation(value = "设置子账户的授权策略") | 142 | @ApiOperation(value = "设置子账户的授权策略") |
| 133 | @GetMapping("policySet") | 143 | @GetMapping("policySet") |
| 134 | - public String policySet(@RequestParam String accountId, @RequestParam String policy) { | 144 | + public ServerResponse policySet(@RequestParam String accountId, @RequestParam String policy) { |
| 135 | 145 | ||
| 136 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/policy/set"; | 146 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/policy/set"; |
| 137 | Map<String, Object> map = new HashMap<>(); | 147 | Map<String, Object> map = new HashMap<>(); |
| @@ -141,12 +151,14 @@ public class YinShiController { | @@ -141,12 +151,14 @@ public class YinShiController { | ||
| 141 | map.put("policy", policy); | 151 | map.put("policy", policy); |
| 142 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | 152 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); |
| 143 | 153 | ||
| 144 | - return result; | 154 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); |
| 155 | + | ||
| 156 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 145 | } | 157 | } |
| 146 | 158 | ||
| 147 | @ApiOperation(value = "增加子账户授权策略中的授权语句") | 159 | @ApiOperation(value = "增加子账户授权策略中的授权语句") |
| 148 | @GetMapping("policyAdd") | 160 | @GetMapping("policyAdd") |
| 149 | - public String policyAdd(@RequestParam String accountId, @RequestParam String statement) { | 161 | + public ServerResponse policyAdd(@RequestParam String accountId, @RequestParam String statement) { |
| 150 | 162 | ||
| 151 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/add"; | 163 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/add"; |
| 152 | Map<String, Object> map = new HashMap<>(); | 164 | Map<String, Object> map = new HashMap<>(); |
| @@ -156,12 +168,14 @@ public class YinShiController { | @@ -156,12 +168,14 @@ public class YinShiController { | ||
| 156 | map.put("statement", statement); | 168 | map.put("statement", statement); |
| 157 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | 169 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); |
| 158 | 170 | ||
| 159 | - return result; | 171 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); |
| 172 | + | ||
| 173 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 160 | } | 174 | } |
| 161 | 175 | ||
| 162 | @ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句") | 176 | @ApiOperation(value = "删除子账户授权策略中指定设备的所有授权语句") |
| 163 | @GetMapping("policyDelete") | 177 | @GetMapping("policyDelete") |
| 164 | - public String policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) { | 178 | + public ServerResponse policyDelete(@RequestParam String accountId, @RequestParam String deviceSerial) { |
| 165 | 179 | ||
| 166 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete"; | 180 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/statement/delete"; |
| 167 | Map<String, Object> map = new HashMap<>(); | 181 | Map<String, Object> map = new HashMap<>(); |
| @@ -171,20 +185,148 @@ public class YinShiController { | @@ -171,20 +185,148 @@ public class YinShiController { | ||
| 171 | map.put("deviceSerial", deviceSerial); | 185 | map.put("deviceSerial", deviceSerial); |
| 172 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | 186 | String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); |
| 173 | 187 | ||
| 174 | - return result; | 188 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); |
| 189 | + | ||
| 190 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 175 | } | 191 | } |
| 176 | 192 | ||
| 177 | @ApiOperation(value = "获取B模式子账户accessToken") | 193 | @ApiOperation(value = "获取B模式子账户accessToken") |
| 178 | @GetMapping("getChildAccountToken") | 194 | @GetMapping("getChildAccountToken") |
| 179 | - public String getChildAccountToken(@RequestParam String accountId) { | 195 | + public ServerResponse getChildAccountToken(@RequestParam String accountId) { |
| 180 | 196 | ||
| 181 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; | 197 | String url = YinShiServiceConfig.HostUrl + "lapp/ram/token/get"; |
| 182 | - Map<String, Object> map1 = new HashMap<>(); | 198 | + Map<String, Object> map = new HashMap<>(); |
| 199 | + | ||
| 200 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 201 | + map.put("accountId", accountId); | ||
| 202 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | ||
| 203 | + | ||
| 204 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 205 | + | ||
| 206 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + | ||
| 210 | + | ||
| 211 | + @ApiOperation(value = "添加设备到账号下") | ||
| 212 | + @ApiImplicitParams({ | ||
| 213 | + @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true), | ||
| 214 | + @ApiImplicitParam(name="validateCode",value = "备验证码,设备机身上的六位大写字母,如OLZKQU",required = true) | ||
| 215 | + }) | ||
| 216 | + @GetMapping("addAccountDevice") | ||
| 217 | + public ServerResponse addAccountDevice(@RequestParam String deviceSerial,@RequestParam String validateCode) { | ||
| 218 | + | ||
| 219 | + String url = YinShiServiceConfig.HostUrl + "lapp/device/add"; | ||
| 220 | + Map<String, Object> map = new HashMap<>(); | ||
| 221 | + | ||
| 222 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 223 | + map.put("deviceSerial", deviceSerial); | ||
| 224 | + map.put("validateCode", validateCode); | ||
| 225 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | ||
| 226 | + | ||
| 227 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 228 | + | ||
| 229 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + @ApiOperation(value = "修改设备的名称") | ||
| 233 | + @ApiImplicitParams({ | ||
| 234 | + @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true), | ||
| 235 | + @ApiImplicitParam(name="deviceName",value = "设备名称,长度不大于50字节,不能包含特殊字符",required = true) | ||
| 236 | + }) | ||
| 237 | + @GetMapping("updateDeviceName") | ||
| 238 | + public ServerResponse updateDeviceName(@RequestParam String deviceName,@RequestParam String deviceSerial) { | ||
| 239 | + | ||
| 240 | + String url = YinShiServiceConfig.HostUrl + "lapp/device/name/update"; | ||
| 241 | + Map<String, Object> map = new HashMap<>(); | ||
| 242 | + | ||
| 243 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 244 | + map.put("deviceSerial", deviceSerial); | ||
| 245 | + map.put("deviceName", deviceName); | ||
| 246 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | ||
| 247 | + | ||
| 248 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 249 | + | ||
| 250 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + @ApiOperation(value = "删除设备") | ||
| 254 | + @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true) | ||
| 255 | + @GetMapping("deleteDevice") | ||
| 256 | + public ServerResponse deleteDevice(@RequestParam String deviceSerial) { | ||
| 257 | + | ||
| 258 | + String url = YinShiServiceConfig.HostUrl + "lapp/device/delete"; | ||
| 259 | + Map<String, Object> map = new HashMap<>(); | ||
| 260 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 261 | + map.put("deviceSerial", deviceSerial); | ||
| 262 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | ||
| 263 | + | ||
| 264 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 265 | + | ||
| 266 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + @ApiOperation(value = "设备抓拍图片") | ||
| 270 | + @ApiImplicitParams({ | ||
| 271 | + @ApiImplicitParam(name="channelNo",value = "通道号,IPC设备填写1",required = true), | ||
| 272 | + @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true) | ||
| 273 | + }) | ||
| 274 | + @GetMapping("deviceCapture") | ||
| 275 | + public ServerResponse deviceCapture(@RequestParam Integer channelNo,@RequestParam String deviceSerial) { | ||
| 276 | + | ||
| 277 | + String url = YinShiServiceConfig.HostUrl + "lapp/device/capture"; | ||
| 278 | + Map<String, Object> map = new HashMap<>(); | ||
| 279 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 280 | + map.put("deviceSerial", deviceSerial); | ||
| 281 | + map.put("channelNo",channelNo); | ||
| 282 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | ||
| 283 | + | ||
| 284 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 285 | + | ||
| 286 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 287 | + } | ||
| 288 | + | ||
| 183 | 289 | ||
| 184 | - map1.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 185 | - map1.put("accountId", accountId); | ||
| 186 | - String result = ApiHelper.doPost(url, new HashMap<String, String>(), map1); | ||
| 187 | 290 | ||
| 188 | - return result; | 291 | + |
| 292 | + | ||
| 293 | + | ||
| 294 | + | ||
| 295 | + @ApiOperation(value = "获取设备列表") | ||
| 296 | + @ApiImplicitParams({ | ||
| 297 | + @ApiImplicitParam(name="pageIndex", value = "分页起始页,从1开始",required = true), | ||
| 298 | + @ApiImplicitParam(name="pageSize", value = "分页大小,默认为10,最大为50") | ||
| 299 | + }) | ||
| 300 | + @GetMapping("getDeviceList") | ||
| 301 | + public ServerResponse getDeviceList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) { | ||
| 302 | + | ||
| 303 | + pageIndex = pageIndex - 1; | ||
| 304 | + String url = YinShiServiceConfig.HostUrl + "lapp/device/list"; | ||
| 305 | + Map<String, Object> map = new HashMap<>(); | ||
| 306 | + | ||
| 307 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 308 | + map.put("pageStart", pageIndex); | ||
| 309 | + map.put("pageSize", pageSize); | ||
| 310 | + String result = ApiHelper.doPost(url, new HashMap<String,String>(), map); | ||
| 311 | + | ||
| 312 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 313 | + | ||
| 314 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 315 | + } | ||
| 316 | + | ||
| 317 | + @ApiOperation(value = "获取单个设备信息") | ||
| 318 | + @ApiImplicitParam(name="deviceSerial",value = "设备序列号",required = true) | ||
| 319 | + @GetMapping("getDeviceInfo") | ||
| 320 | + public ServerResponse getDeviceInfo(@RequestParam String deviceSerial) { | ||
| 321 | + | ||
| 322 | + String url = YinShiServiceConfig.HostUrl + "lapp/device/info"; | ||
| 323 | + Map<String, Object> map = new HashMap<>(); | ||
| 324 | + map.put("accessToken", YinShiServiceConfig.AccessToken); | ||
| 325 | + map.put("deviceSerial", deviceSerial); | ||
| 326 | + String result = ApiHelper.doPost(url, new HashMap<String, String>(), map); | ||
| 327 | + | ||
| 328 | + YinShiResResult yinShiResResult = JSON.parseObject(result,YinShiResResult.class); | ||
| 329 | + | ||
| 330 | + return ResultUtils.getInstance().returnResultYingshi(yinShiResResult); | ||
| 189 | } | 331 | } |
| 190 | } | 332 | } |
springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java
| 1 | package com.sincre.springboot.utils; | 1 | package com.sincre.springboot.utils; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import com.sincre.springboot.ApiModel.TuYaResResult; | ||
| 4 | import com.sincre.springboot.ApiModel.YinShiResResult; | 5 | import com.sincre.springboot.ApiModel.YinShiResResult; |
| 5 | import com.sincre.springboot.common.ResponseCode; | 6 | import com.sincre.springboot.common.ResponseCode; |
| 6 | import com.sincre.springboot.common.ServerResponse; | 7 | import com.sincre.springboot.common.ServerResponse; |
| 7 | -import com.sincre.springboot.model.ResultModelObj; | ||
| 8 | -import org.json.JSONObject; | ||
| 9 | 8 | ||
| 10 | /** | 9 | /** |
| 11 | * 结果返回工具类 | 10 | * 结果返回工具类 |
| @@ -30,70 +29,59 @@ public class ResultUtils { | @@ -30,70 +29,59 @@ public class ResultUtils { | ||
| 30 | 29 | ||
| 31 | 30 | ||
| 32 | /** | 31 | /** |
| 33 | - * 萤石统一结果回调 | 32 | + * 涂鸦云返回结果 |
| 34 | * | 33 | * |
| 35 | - * @param yinShiResResult 萤石接口返回对象的字符串 | ||
| 36 | - * @return 返回的data可以是对象或者集合,都以字符串形式返回 | 34 | + * @param yinShiResResult |
| 35 | + * @return | ||
| 37 | */ | 36 | */ |
| 38 | - public ServerResponse resturnResultYingshi(YinShiResResult yinShiResResult) { | ||
| 39 | -// JSONObject jsonObject = new JSONObject(result); | ||
| 40 | -// ResultModelObj resultModelObj = new ResultModelObj(); | ||
| 41 | -// long code = jsonObject.optLong("code"); | ||
| 42 | -// if (code==10002){//accesstoken过期 | ||
| 43 | -// new YinShiController().GetYinShiToken(); | ||
| 44 | -// try { | ||
| 45 | -// Thread.sleep(1000); | ||
| 46 | -// } catch (InterruptedException e) { | ||
| 47 | -// e.printStackTrace(); | ||
| 48 | -// } | ||
| 49 | -// } | ||
| 50 | -// resultModelObj.setCode(code); | ||
| 51 | -// resultModelObj.setData(jsonObject.optString("data")); | ||
| 52 | -// resultModelObj.setMsg(jsonObject.optString("msg")); | ||
| 53 | -// resultModelObj.setTotal(jsonObject.optInt("page")); | ||
| 54 | -// return resultModelObj.toString(); | ||
| 55 | - | ||
| 56 | - int code = yinShiResResult.getCode(); | ||
| 57 | - System.out.println(yinShiResResult.getPage().getTotal()); | ||
| 58 | - if (code == 200) { | ||
| 59 | - return ServerResponse.createBySuccess(yinShiResResult.getPage().getTotal().toString(), ResponseCode.SUCCESS.getDesc(), yinShiResResult.getData()); | ||
| 60 | - } else { | ||
| 61 | - if (code == 10002) {//accessToken过期或异常 | ||
| 62 | - CacheHelper.GetYinShiToken(); | ||
| 63 | - try { | ||
| 64 | - Thread.sleep(1000); | ||
| 65 | - } catch (InterruptedException e) { | ||
| 66 | - e.printStackTrace(); | 37 | + public ServerResponse returnResultYingshi(YinShiResResult yinShiResResult) { |
| 38 | + | ||
| 39 | + try { | ||
| 40 | + int code = yinShiResResult.getCode(); | ||
| 41 | + | ||
| 42 | + if (code == 200) { | ||
| 43 | + String total = null; | ||
| 44 | + if (yinShiResResult.getPage() != null) { | ||
| 45 | + total = yinShiResResult.getPage().getTotal().toString(); | ||
| 67 | } | 46 | } |
| 47 | + return ServerResponse.createBySuccess(total, ResponseCode.SUCCESS.getDesc(), yinShiResResult.getData()); | ||
| 48 | + } else { | ||
| 49 | + if (code == 10002) {//accessToken过期或异常 | ||
| 50 | + CacheHelper.GetYinShiToken(); | ||
| 51 | + try { | ||
| 52 | + Thread.sleep(1000); | ||
| 53 | + } catch (InterruptedException e) { | ||
| 54 | + e.printStackTrace(); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + return ServerResponse.createByErrorCodeMessage(code, yinShiResResult.getMsg()); | ||
| 68 | } | 58 | } |
| 69 | - return ServerResponse.createByErrorMessage(yinShiResResult.getMsg()); | ||
| 70 | } | 59 | } |
| 71 | - } | ||
| 72 | - | ||
| 73 | - private void getYinShiToken() { | ||
| 74 | - | 60 | + catch (Exception ex){ |
| 61 | + return ServerResponse.createByErrorMessage("服务器内部处理出错!"); | ||
| 62 | + } | ||
| 75 | } | 63 | } |
| 76 | 64 | ||
| 77 | /** | 65 | /** |
| 78 | * 涂鸦云返回结果 | 66 | * 涂鸦云返回结果 |
| 79 | - * | ||
| 80 | - * @param result | 67 | + * @param |
| 81 | * @return | 68 | * @return |
| 82 | */ | 69 | */ |
| 83 | - public String resturnResultTuya(String result) { | ||
| 84 | - JSONObject jsonObject = new JSONObject(result); | ||
| 85 | - boolean success = jsonObject.optBoolean("success"); | ||
| 86 | - ResultModelObj resultModelObj = new ResultModelObj(); | ||
| 87 | - if (success) {//成功 | ||
| 88 | - resultModelObj.setCode(200); | ||
| 89 | - resultModelObj.setData(jsonObject.optString("result")); | ||
| 90 | - resultModelObj.setMsg(jsonObject.optString("msg")); | ||
| 91 | - } else {//失败 | ||
| 92 | - resultModelObj.setCode(jsonObject.optLong("code")); | ||
| 93 | - resultModelObj.setData("{}"); | ||
| 94 | - resultModelObj.setMsg(jsonObject.optString("msg")); | 70 | + public ServerResponse returnResultTuYa(TuYaResResult tuYaResResult) { |
| 71 | + try { | ||
| 72 | + boolean success = tuYaResResult.getSuccess(); | ||
| 73 | + | ||
| 74 | + if (success) { | ||
| 75 | + | ||
| 76 | + return ServerResponse.createBySuccess(ResponseCode.SUCCESS.getDesc(), tuYaResResult.getResult()); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + int code = Integer.valueOf(tuYaResResult.getCode()); | ||
| 80 | + return ServerResponse.createByErrorCodeMessage(code, tuYaResResult.getMsg()); | ||
| 81 | + } | ||
| 82 | + catch (Exception ex){ | ||
| 83 | + return ServerResponse.createByErrorMessage("服务器内部处理出错!"); | ||
| 95 | } | 84 | } |
| 96 | - return resultModelObj.toString(); | ||
| 97 | } | 85 | } |
| 98 | 86 | ||
| 99 | } | 87 | } |