| | |
| | | } |
| | | public static void main(String[] args) { |
| | | QueryDataRequest param = new QueryDataRequest(); |
| | | param.setStart_time("2026-05-19 10:00::00"); |
| | | param.setEnd_time("2026-05-19 12:24:25"); |
| | | param.setStart_time("2026-05-25 10:00::00"); |
| | | param.setEnd_time("2026-05-25 14:24:25"); |
| | | param.setLimit(1); |
| | | param.setFunctionids("253"); |
| | | param.setOffset(0); |
| | |
| | | try { |
| | | String request_content = JSON.toJSONString(param); |
| | | String r = requestAsync(url, request_content); |
| | | TypeReference typeReference = |
| | | new TypeReference< ElectronicBaseResponse<List<MeterDealResponse>> >(){}; |
| | | ElectronicBaseResponse result = JSONObject.parseObject(r, typeReference.getType()); |
| | | return result; |
| | | return parseAsyncMeterResponse(r); |
| | | }catch (Exception e){ |
| | | log.error("电表==============开户",e); |
| | | } |
| | |
| | | try { |
| | | String request_content = JSON.toJSONString(param); |
| | | String r = requestAsync(url, request_content); |
| | | TypeReference typeReference = |
| | | new TypeReference< ElectronicBaseResponse<List<MeterDealResponse>> >(){}; |
| | | ElectronicBaseResponse result = JSONObject.parseObject(r, typeReference.getType()); |
| | | return result; |
| | | return parseAsyncMeterResponse(r); |
| | | }catch (Exception e){ |
| | | log.error("电表==============开户",e); |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 电表开户_电表充值 |
| | | * 电表_电表充值 |
| | | */ |
| | | public static ElectronicBaseResponse recharger(List<OpenAccountRequest> param) { |
| | | if(param ==null || param.size()==0){ |
| | |
| | | try { |
| | | String request_content = JSON.toJSONString(param); |
| | | String r = requestAsync(url, request_content); |
| | | TypeReference typeReference = |
| | | new TypeReference< ElectronicBaseResponse<List<MeterDealResponse>> >(){}; |
| | | ElectronicBaseResponse result = JSONObject.parseObject(r, typeReference.getType()); |
| | | return result; |
| | | return parseAsyncMeterResponse(r); |
| | | }catch (Exception e){ |
| | | log.error("电表==============开户",e); |
| | | log.error("电表==============充值",e); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | if(param ==null || param.size()==0){ |
| | | return null; |
| | | } |
| | | String url = ElectronicConstant.api2_url+"/Api_v2/ele_security/ele_control"; |
| | | String url = ElectronicConstant.api2_url+"/Api_v2/ele_control"; |
| | | |
| | | try { |
| | | String request_content = JSON.toJSONString(param); |
| | | String r = requestAsync(url, request_content); |
| | | TypeReference typeReference = |
| | | new TypeReference< ElectronicBaseResponse<List<MeterDealResponse>> >(){}; |
| | | ElectronicBaseResponse result = JSONObject.parseObject(r, typeReference.getType()); |
| | | return result; |
| | | return parseAsyncMeterResponse(r); |
| | | }catch (Exception e){ |
| | | log.error("电表==============拉合闸",e); |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 电表_拉合闸 |
| | | * 查询异步操作任务状态(/Api_v2/request/status)。 |
| | | * request_content 为 JSON 数组,可合并传入多个 opr_id 一次查询。 |
| | | * 调用成功后建议 30s 首次查询,后续间隔递增(1h、2h、4h…),禁止频繁调用。 |
| | | * 响应 SUCCESS、FAIL、TIMEOUT、CANCELED、RESPONSE_FAIL 后无需再查询。 |
| | | */ |
| | | public static ElectronicBaseResponse requestStatus(List<RequestStatusRequest> param) { |
| | | if (param == null || param.isEmpty()) { |
| | | return null; |
| | | } |
| | | String url = ElectronicConstant.api2_url + "/Api_v2/request/status"; |
| | | try { |
| | | String request_content = JSON.toJSONString(param); |
| | | String r = request(url, request_content); |
| | | return parseAsyncMeterResponse(r); |
| | | } catch (Exception e) { |
| | | log.error("电表==============查询异步任务状态", e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 按 opr_id 列表合并查询异步任务状态。 |
| | | */ |
| | | public static ElectronicBaseResponse requestStatusByOprIds(List<String> oprIds) { |
| | | if (oprIds == null || oprIds.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<RequestStatusRequest> param = new ArrayList<>(); |
| | | for (String oprId : oprIds) { |
| | | if (StringUtils.isNotBlank(oprId)) { |
| | | RequestStatusRequest req = new RequestStatusRequest(); |
| | | req.setOpr_id(oprId.trim()); |
| | | param.add(req); |
| | | } |
| | | } |
| | | return param.isEmpty() ? null : requestStatus(param); |
| | | } |
| | | |
| | | /** |
| | | * 查询单个异步操作任务状态。 |
| | | */ |
| | | public static ElectronicBaseResponse requestStatus(String oprId) { |
| | | if (StringUtils.isBlank(oprId)) { |
| | | return null; |
| | | } |
| | | RequestStatusRequest req = new RequestStatusRequest(); |
| | | req.setOpr_id(oprId.trim()); |
| | | return requestStatus(Collections.singletonList(req)); |
| | | } |
| | | |
| | | /** |
| | | * 异步任务是否已到达终态,平台后续不再处理,无需再轮询。 |
| | | */ |
| | | public static boolean isAsyncStatusFinal(String status) { |
| | | if (StringUtils.isBlank(status)) { |
| | | return false; |
| | | } |
| | | String s = status.trim().toUpperCase(Locale.ROOT); |
| | | return "SUCCESS".equals(s) || "FAIL".equals(s) || "TIMEOUT".equals(s) |
| | | || "CANCELED".equals(s) || "RESPONSE_FAIL".equals(s); |
| | | } |
| | | |
| | | /** |
| | | * 电表_立即抄表 |
| | | */ |
| | | public static ElectronicBaseResponse eleRead(List<EleReadRequest> param) { |
| | | if(param ==null || param.size()==0){ |
| | |
| | | try { |
| | | String request_content = JSON.toJSONString(param); |
| | | String r = requestAsync(url, request_content); |
| | | TypeReference typeReference = |
| | | new TypeReference< ElectronicBaseResponse<List<MeterDealResponse>> >(){}; |
| | | ElectronicBaseResponse result = JSONObject.parseObject(r, typeReference.getType()); |
| | | return result; |
| | | return parseAsyncMeterResponse(r); |
| | | }catch (Exception e){ |
| | | log.error("电表==============拉合闸",e); |
| | | log.error("电表==============立即抄表",e); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 查询历史数据接口 |
| | | */ |
| | | public static ElectronicDataResponse queryDataRequest() { |
| | | return queryDataRequest(null); |
| | | } |
| | | |
| | | /** |
| | | * 查询历史数据接口 |
| | | */ |
| | |
| | | } |
| | | |
| | | // 打印响应内容 |
| | | /** |
| | | * 解析 Api_v2 异步电表操作响应。 |
| | | * 平台 response_content 可能是 JSON 数组,也可能是字符串形式的 JSON 数组。 |
| | | */ |
| | | public static ElectronicBaseResponse parseAsyncMeterResponse(String r) { |
| | | if (StringUtils.isBlank(r)) { |
| | | return null; |
| | | } |
| | | try { |
| | | JSONObject jsonObject = JSON.parseObject(r); |
| | | if (jsonObject == null) { |
| | | return null; |
| | | } |
| | | ElectronicBaseResponse<List<MeterDealResponse>> result = new ElectronicBaseResponse<>(); |
| | | result.setStatus(jsonObject.getString("status")); |
| | | result.setTimestamp(jsonObject.getString("timestamp")); |
| | | result.setError_msg(jsonObject.getString("error_msg")); |
| | | result.setSign(jsonObject.getString("sign")); |
| | | result.setResponse_content(parseResponseContentList(jsonObject.get("response_content"), MeterDealResponse.class)); |
| | | return result; |
| | | } catch (Exception e) { |
| | | log.error("parse async meter response failed, raw={}", r, e); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private static <T> List<T> parseResponseContentList(Object content, Class<T> clazz) { |
| | | if (content == null) { |
| | | return null; |
| | | } |
| | | if (content instanceof JSONArray) { |
| | | return ((JSONArray) content).toJavaList(clazz); |
| | | } |
| | | if (content instanceof JSONObject) { |
| | | T one = ((JSONObject) content).toJavaObject(clazz); |
| | | return one != null ? Collections.singletonList(one) : null; |
| | | } |
| | | String text = String.valueOf(content); |
| | | if (StringUtils.isBlank(text) || "null".equalsIgnoreCase(text.trim())) { |
| | | return null; |
| | | } |
| | | text = text.trim(); |
| | | if (text.startsWith("[")) { |
| | | return JSON.parseArray(text, clazz); |
| | | } |
| | | if (text.startsWith("{")) { |
| | | T one = JSON.parseObject(text, clazz); |
| | | return one != null ? Collections.singletonList(one) : null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void printResponse(String response) { |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | |