1.国网工具类提交
This commit is contained in:
@@ -69,6 +69,11 @@
|
||||
<groupId>com.nimbusds</groupId>
|
||||
<artifactId>nimbus-jose-jwt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csb.sdk</groupId>
|
||||
<artifactId>http-client</artifactId>
|
||||
<version>1.1.5.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.njcn.web.enums;
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 上送枚举
|
||||
* @Author: wr
|
||||
* @Date: 2023/12/7 10:53
|
||||
*/
|
||||
public enum GWSendEnum {
|
||||
|
||||
|
||||
//接收电能质量基准水平评估数据接口
|
||||
EVALUATION("pqEvaluationCreate", "/WMCenter/powerQuality/evaluation/create"),
|
||||
//接收电能质量典型源荷指标统计数据接口
|
||||
TYPICAL_SOURCE("pqTypicalSourceCreate", "/WMCenter/powerQuality/typicalSource/create"),
|
||||
//接收电能质量风电场台账数据接口
|
||||
WIND_CREATE("pqArchivalInformationWindCreate", "/WMCenter/powerQuality/archivalInformation/windCreate"),
|
||||
//接收电能质量光伏电站台账数据接口
|
||||
PHOTOVOLTAIC_CREATE("pqArchivalInformationPhotovoltaicCreate", "/WMCenter/powerQuality/archivalInformation/photovoltaicCreate"),
|
||||
//接收电能质量重要、敏感用户台账数据接口
|
||||
SENSITIVE_USER_CREATE("pqArchivalInformationSensitiveUserCreate", "/WMCenter/powerQuality/archivalInformation/sensitiveUserCreate"),
|
||||
//接收电能质量牵引站台账数据接口
|
||||
TRACTION_STATION("pqTractionStationCreate", "/WMCenter/powerQuality/tractionStation/create"),
|
||||
//接收电能质量监测点台账数据接口
|
||||
MONITOR("pqMonitorCreate", "/WMCenter/powerQuality/monitor/create"),
|
||||
//接收电能质量监测点限值台账数据接口
|
||||
LIMIT_CREATE("pqMonitorLimitCreate", "/WMCenter/powerQuality/monitor/limitCreate"),
|
||||
//接收电能质量主配网监测点统计数据接口
|
||||
STATISTICAL_CREATE("pqMonitorStatisticalCreate", "/WMCenter/powerQuality/monitor/statisticalCreate"),
|
||||
//接收电能质量换流站指标汇总统计数据接口
|
||||
INDEX_CREATE("pqConverterMonitorIndexCreate", "/WMCenter/powerQuality/converterMonitor/indexCreate"),
|
||||
//接收电能质量换流站指标统计明细数据接口
|
||||
DETAIL_CREATE("pqConverterMonitorDetailCreate", "/WMCenter/powerQuality/converterMonitor/detailCreate"),
|
||||
//接收电能质量变电站监测统计数据接口
|
||||
SUBSTATION_MONITOR("pqSubstationMonitorCreate", "/WMCenter/powerQuality/substationMonitor/create"),
|
||||
//2.4.1.21接收其他干扰用户台账数据接口
|
||||
OTHER_USER_CREATE("pqArchivalInformationOtherUserCreate", "/WMCenter/powerQuality/archivalInformation/otherUserCreate"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
private final String serviceName;
|
||||
|
||||
private final String url;
|
||||
|
||||
GWSendEnum(String serviceName, String url) {
|
||||
this.serviceName = serviceName;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return "http://dwzyywzt-pms3-proxy.com/CSB" + url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.web.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2023/7/28 9:47
|
||||
*/
|
||||
@Data
|
||||
public class SendParam {
|
||||
|
||||
@ApiModelProperty(value = "省id")
|
||||
private String provinceId="13B9B47F1E483324E05338297A0A0595";
|
||||
|
||||
@ApiModelProperty(value = "密钥")
|
||||
private String secretKey="lW2xr6zKjbaqVDOSgQpcGrM6Rg0=";
|
||||
|
||||
@ApiModelProperty(value = "统计日期")
|
||||
private String statisticalDate;
|
||||
|
||||
@ApiModelProperty(value = "上报参数")
|
||||
private List stats;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.njcn.web.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.csb.sdk.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.web.pojo.param.SendParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2023/12/6 13:59
|
||||
*/
|
||||
@Slf4j
|
||||
public class GwSendUtil {
|
||||
|
||||
private static final String GWURL = "dwzyywzt-pms3-proxy.com";
|
||||
private static final String CODE = "13B9B47F1E483324E05338297A0A0595";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param param 上报入参数据
|
||||
* @param url 上报地址 例如(http://dwzyywzt-pms3-proxy.com/CSB/WMCenter/powerQuality/plan/create)
|
||||
* @param serviceName 例如(pqPlanCreate)
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> send(SendParam param, String url, String serviceName) {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
try {
|
||||
ContentBody cb;
|
||||
if (ObjectUtil.isNull(param)) {
|
||||
cb = new ContentBody("");
|
||||
} else {
|
||||
String s = JSONObject.toJSONStringWithDateFormat(param, JSON.DEFFAULT_DATE_FORMAT);
|
||||
log.info(Thread.currentThread().getName() + "1.信息:" + s);
|
||||
cb = new ContentBody(s);
|
||||
}
|
||||
//ContentBody传递,要求使用post方式进行调用
|
||||
//如果需要传递请求参数 可以拼接到请求URL中,或者设置paramsMap参数由SDK内部进行拼接
|
||||
HttpParameters.Builder builder = HttpParameters.newBuilder();
|
||||
|
||||
builder.requestURL(url) // 设置请求的URL,可以拼接URL请求参数
|
||||
.api("zongbuSync") // 设置服务名
|
||||
.version("1.0.0") // 设置版本号
|
||||
.method("post") // 设置调用方式, 必须为 post
|
||||
.contentType("application/json; charset=UTF-8") //设置请求content-type
|
||||
.accessKey("7d4cb2c0afb5468ca56e0654b1a442ef").secretKey("lW2xr6zKjbaqVDOSgQpcGrM6Rg0=");// 设置accessKey 和 设置secretKey
|
||||
|
||||
|
||||
builder.contentBody(cb);
|
||||
String token = LoginToken();
|
||||
builder.putHeaderParamsMap("x-token", token);
|
||||
builder.putHeaderParamsMap("serviceName", serviceName);
|
||||
//进行调用,返回结果
|
||||
try {
|
||||
HttpReturn ret = HttpCaller.invokeReturn(builder.build());
|
||||
String responseStr = ret.getResponseStr();//获取响应的文本串
|
||||
map.put("succeed", responseStr);
|
||||
} catch (HttpCallerException e) {
|
||||
// error process
|
||||
log.info(Thread.currentThread().getName() + "错误信息:" + e);
|
||||
map.put("error", e.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
map.put("error", "当前时间段国网上送请求过多,请稍后再试");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
* @return
|
||||
*/
|
||||
public static String LoginToken() {
|
||||
String token;
|
||||
String clientId = "942a9278671711eda2e10ae0b5517f6c";
|
||||
String clientSecret = "3Psd2VEhsA3dVsSPHW0ll5r/03kAqlA2P4w2IiWPA8UWSadcX0we2wffjyTUYGsK";
|
||||
|
||||
String userUrl = "http://" + GWURL + "/psr-auth/oauth/accessToken?grant_type={grant_type}&client_id={client_id}&client_secret={client_secret}";
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("grant_type", "credentials");
|
||||
map.put("client_id", clientId);
|
||||
map.put("client_secret", clientSecret);
|
||||
ResponseEntity<Map> userEntity = RestTemplateUtil.get(userUrl, Map.class, map);
|
||||
|
||||
if (userEntity.getStatusCodeValue() == 200) {
|
||||
log.info(Thread.currentThread().getName() + "数据:" + userEntity.getBody() + "结束----!");
|
||||
//获取返回体
|
||||
Map body = userEntity.getBody();
|
||||
token = body.get("access_token").toString();
|
||||
} else {
|
||||
throw new BusinessException("获取数据token出现未知异常!请检查ip端口是否正确!");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user