update 江苏省平台接口

This commit is contained in:
Lemon
2023-10-20 17:20:31 +08:00
parent be44562253
commit 4c6277b36c
6 changed files with 65 additions and 49 deletions

View File

@@ -44,6 +44,8 @@ import com.jsowell.thirdparty.lianlian.util.HttpRequestUtil;
import com.jsowell.thirdparty.lianlian.vo.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -62,6 +64,8 @@ public class LianLianServiceImpl implements LianLianService {
// private static final String DATA_SECRET = "R1Hdq80mSWswwCzt"; // 消息密钥 R1Hdq80mSWswwCzt 1234567890abcdef
// private static final String DATA_SECRETIV = "LVpz3qHD8sM2PYjl"; // 消息密钥初始化向量 LVpz3qHD8sM2PYjl 1234567890abcdef
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private IPileMerchantInfoService pileMerchantInfoService;
@@ -779,6 +783,7 @@ public class LianLianServiceImpl implements LianLianService {
String response = HttpUtil.post(requestUrl, tokenRequest);
LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class);
logger.info("获取令牌 result:{}", result);
if (result.getRet() == 0) {
// 解密data
@@ -787,6 +792,7 @@ public class LianLianServiceImpl implements LianLianService {
String dataStr = new String(plainText, "UTF-8");
Map<String, String> resultMap = (Map<String, String>) JSON.parse(dataStr);
token = resultMap.get("AccessToken");
logger.info("token: {}", token);
}
} catch (Exception e) {
return token;

View File

@@ -157,11 +157,11 @@ public class HttpRequestUtil {
}
/**
* 南瑞平台发送请求
* 江苏平台发送请求
*
* TODO和联联平台一样的方法若测试通过则统一更换成上面的方法
*
* @param token 南瑞平台令牌
* @param token 江苏平台令牌
* @param data 要传输的JsonString格式数据
* @param url 请求地址
* @param dataSecret 消息密钥
@@ -172,7 +172,7 @@ public class HttpRequestUtil {
*/
public static String nrSendPost(String token, String data, String url, String dataSecret,
String dataSecretIV, String operatorId, String sigSecret){
log.info("南瑞平台发送请求 data:{}", data);
log.info("江苏平台发送请求 data:{}", data);
//加密
byte[] encryptText = Cryptos.aesEncrypt(data.getBytes(),
dataSecret.getBytes(), dataSecretIV.getBytes());
@@ -188,23 +188,25 @@ public class HttpRequestUtil {
params.put("Sig", sign);
String postData = JSON.toJSONString(params);
log.info("南瑞平台发送请求 最终提交数据:{}", postData);
log.info("江苏平台发送请求 最终提交数据:{}", postData);
// System.out.println("最终提交数据:" + postData);
String hutoolRequest = HttpRequest.post(url).header("Authorization", "Bearer " + token).body(postData).execute().body();
log.info("南瑞平台发送请求 接收到返回数据:{}", hutoolRequest);
log.info("江苏平台发送请求 接收到返回数据:{}", hutoolRequest);
// System.out.println("接收到返回数据:" + hutoolRequest);
if (StringUtils.isBlank(hutoolRequest)) {
return "SUCCESS";
}
Map<String, Object> map = (Map<String, Object>) JSON.parse(hutoolRequest);
log.info("南瑞平台发送请求 返回数据map:{}", JSON.toJSONString(map));
log.info("江苏平台发送请求 返回数据map:{}", JSON.toJSONString(map));
int ret = (int) map.get("Ret");
String resultMsg = (String) map.get("Msg");
if (ret != 0) {
// 表示请求有异常
log.error("南瑞平台发送请求 error:{}, 源数据:{}", resultMsg, data);
log.error("江苏平台发送请求 error:{}, 源数据:{}", resultMsg, data);
return resultMsg;
}
String rData = (String) map.get("Data");
@@ -218,7 +220,7 @@ public class HttpRequestUtil {
e.printStackTrace();
}
log.info("南瑞平台发送请求 解密数据:{}", plainData);
log.info("江苏平台发送请求 解密数据:{}", plainData);
// System.out.println("解密数据:" + plainData);
return resultMsg;
}

View File

@@ -151,11 +151,11 @@ public class NRServiceImpl implements NRService {
// 拼装南瑞平台所需参数
NRStationInfo nrStationInfo = NRStationInfo.builder()
.stationId("NR" + stationInfoVO.getId())
.operatorID("014406554")
.equipmentOwnerID("014406554")
.operatorID(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerID(Constants.OPERATORID_JIANG_SU)
.stationName(stationInfoVO.getStationName())
.countryCode(stationInfoVO.getCountryCode())
.areaCode(stationInfoVO.getAreaCode())
// .areaCode()
.address(stationInfoVO.getAddress())
.serviceTel(stationInfoVO.getStationTel())
.stationStatus(stationInfoVO.getStationStatus())
@@ -166,7 +166,6 @@ public class NRServiceImpl implements NRService {
.openAllDay(Integer.parseInt(stationInfoVO.getOpenAllDay()))
.busineHours(stationInfoVO.getBusinessHours())
.minElectricityPrice(stationInfoVO.getElectricityPrice().add(stationInfoVO.getServicePrice()))
.loungeFlag(0)
.isAloneApply(0)
.printerFlag(0)
@@ -185,6 +184,12 @@ public class NRServiceImpl implements NRService {
.parkFeeType(1)
.build();
// 站点地址
String areaCode = stationInfoVO.getAreaCode();
// 截取最后一组数据,例如将 320000,320500,320583 截取为 320583
String[] split = StringUtils.split(areaCode, ",");
String s = split[split.length - 1];
nrStationInfo.setAreaCode(s);
// 站点图片
if (CollectionUtils.isNotEmpty(stationInfoVO.getPictureList())) {
nrStationInfo.setPictures(stationInfoVO.getPictureList());
@@ -203,15 +208,15 @@ public class NRServiceImpl implements NRService {
// 推送到平台
String url = urlAddress + "notification_stationInfo";
String jsonStr = JSONObject.toJSONString(nrStationInfo);
JSONObject data = new JSONObject();
data.put("StationInfo", jsonStr);
data.put("StationInfo", nrStationInfo);
String jsonString = JSONObject.toJSONString(data);
String jsonString = data.toString();
System.out.println("jsonString : " + jsonString);
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
System.out.println(token);
String result = HttpRequestUtil.nrSendPost(token, jsonString, url, dataSecret
, dataSecretIv, operatorId, signSecret);
@@ -244,9 +249,9 @@ public class NRServiceImpl implements NRService {
for (PileStationInfo pileStationInfo : pageInfo.getList()) {
// 拼装参数
NRStationInfo nrStationInfo = NRStationInfo.builder()
.stationId(String.valueOf(pileStationInfo.getId()))
.operatorID(Constants.OPERATORID_LIANLIAN)
.equipmentOwnerID(Constants.OPERATORID_LIANLIAN)
.stationId("NR" + pileStationInfo.getId())
.operatorID(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerID(Constants.OPERATORID_JIANG_SU)
.stationName(pileStationInfo.getStationName())
.countryCode(pileStationInfo.getCountryCode())
.areaCode(pileStationInfo.getAreaCode())
@@ -352,7 +357,7 @@ public class NRServiceImpl implements NRService {
.connectorId(dto.getPileConnectorCode())
.alertTime(DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS))
.alertCode(120) // 120-预留
.describe(faultReason)
.describe("急停按钮动作故障")
.status(status)
.build();
@@ -361,9 +366,8 @@ public class NRServiceImpl implements NRService {
// 发送请求
String url = urlAddress + "notification_alarmInfo";
String jsonStr = JSONObject.toJSONString(nrAlarmInfos);
JSONObject data = new JSONObject();
data.put("AlarmInfos", jsonStr);
data.put("AlarmInfos", nrAlarmInfos);
String jsonString = JSONObject.toJSONString(data);
System.out.println("jsonString : " + jsonString);
@@ -418,8 +422,8 @@ public class NRServiceImpl implements NRService {
NRConnectorStatusInfo nrConnectorStatusInfo = NRConnectorStatusInfo.builder()
.connectorID(pileConnectorCode)
.status(Integer.parseInt(connectorStatus))
.currentA(Integer.parseInt(realTimeMonitorData.getOutputCurrent()))
.voltageA(Integer.parseInt(realTimeMonitorData.getOutputVoltage()))
.currentA(new BigDecimal(realTimeMonitorData.getOutputCurrent()).intValue())
.voltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage()).intValue())
.soc(BigDecimal.ZERO)
.beginTime(DateUtils.formatDateTime(orderBasicInfo.getChargeStartTime()))
.currentKwh(new BigDecimal(realTimeMonitorData.getChargingDegree()).setScale(3, BigDecimal.ROUND_HALF_UP))