|
|
@@ -44,12 +44,12 @@ public class WaterElectricComponent {
|
|
|
* 获取token
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getToken() {
|
|
|
+ public String queryToken() {
|
|
|
String token = stringRedisTemplate.opsForValue().get(RedisKey.WATER_AND_ELECTRIC_SERVICE_TOKEN);
|
|
|
if (StringUtils.hasText(token)) {
|
|
|
return token;
|
|
|
} else {
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
map.put("operatorSecret", waterElectricConfig.getOperatorSecret());
|
|
|
try {
|
|
|
JsonNode jsonNode = queryData("queryToken", map, null);
|
|
|
@@ -59,19 +59,67 @@ public class WaterElectricComponent {
|
|
|
|
|
|
return accessToken;
|
|
|
} catch (Exception e) {
|
|
|
- throw new RRException(BizCodeEnume.THIRD_PARTY_SERVICE_CALL_FAILED, "请求水电接口token异常");
|
|
|
+ throw new RRException(BizCodeEnume.THIRD_PARTY_SERVICE_CALL_FAILED, "请求水电接口-获取token异常");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取电表实时数据
|
|
|
+ * @param pointId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JsonNode queryPowerRealTimeData(String pointId) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("pointId", pointId);
|
|
|
+ try {
|
|
|
+ return queryData("queryPowerRealTimeData", map, queryToken());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RRException(BizCodeEnume.THIRD_PARTY_SERVICE_CALL_FAILED, "请求水电接口-获取电表实时数据异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取电表实时数据
|
|
|
+ * @param pointId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JsonNode queryLastHistoryCumulantInfo(String pointId) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("pointId", pointId);
|
|
|
+ map.put("pointType", "2");
|
|
|
+ try {
|
|
|
+ return queryData("queryLastHistoryCumulantInfo", map, queryToken());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RRException(BizCodeEnume.THIRD_PARTY_SERVICE_CALL_FAILED, "请求水电接口-获取电表实时数据异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程控制水电表
|
|
|
+ * @param pointId
|
|
|
+ * @param operType 1开、2关
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JsonNode remoteDisconnect(String pointId, String operType) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("pointId", pointId);
|
|
|
+ map.put("operType", operType);
|
|
|
+ try {
|
|
|
+ return queryData("remoteDisconnect", map, queryToken());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RRException(BizCodeEnume.THIRD_PARTY_SERVICE_CALL_FAILED, "请求水电接口-远程控制水电表异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 请求数据
|
|
|
*
|
|
|
- * @param path 请求接口url
|
|
|
+ * @param uri 请求接口url
|
|
|
* @param paramMap 请求参数
|
|
|
* @param token 请求token 获取token时该字段可以为空
|
|
|
*/
|
|
|
- private JsonNode queryData(String path, Map<String, String> paramMap, String token) throws Exception {
|
|
|
+ private JsonNode queryData(String uri, Map<String, String> paramMap, String token) throws Exception {
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
// 加密data部分
|
|
|
@@ -95,7 +143,7 @@ public class WaterElectricComponent {
|
|
|
headers.add("token", token);
|
|
|
}
|
|
|
HttpEntity<MultiValueMap<String, String>> formEntity = new HttpEntity<>(requestMap, headers);
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.postForEntity(waterElectricConfig.getServiceHost() + path, formEntity, String.class);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(waterElectricConfig.getServiceHost() + uri, formEntity, String.class);
|
|
|
String body = responseEntity.getBody();
|
|
|
|
|
|
JsonNode jsonNode = mapper.readTree(body);
|