diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java index 8194e96fb..0a990f4b7 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java @@ -190,6 +190,11 @@ public class CacheConstants { */ public static final String CHARGING_HANDSHAKE_DATA_BY_TRANSACTION_CODE = "charging_handshake_data_by_transaction_code:"; + /** + * 第三方平台Token缓存 + */ + public static final String THIRD_PARTY_TOKEN_BY_OPERATOR_ID = "third_party_token_by_operator_id:"; + /** * 充电桩状态前缀 */ diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java index b48e43f18..afc905b3d 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java @@ -4,10 +4,13 @@ import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson2.JSON; import com.google.common.collect.Maps; +import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.bean.BeanUtils; import com.jsowell.pile.dto.*; import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO; import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO; @@ -22,12 +25,14 @@ import com.jsowell.thirdparty.platform.util.Encodes; import com.jsowell.thirdparty.platform.util.GBSignUtils; import org.bouncycastle.crypto.CryptoException; import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.spec.InvalidKeySpecException; import java.util.*; +import java.util.concurrent.TimeUnit; /** * 第三方平台对接需要的api集合 @@ -440,6 +445,15 @@ public interface ThirdPartyPlatformService extends InitializingBean { default String getToken(String urlAddress, String operatorId, String operatorSecret, String dataSecretIv, String signSecret, String dataSecret) { String token = ""; + // 先查询缓存有没有token + String tokenKey = CacheConstants.THIRD_PARTY_TOKEN_BY_OPERATOR_ID + operatorId; + RedisCache redisCache = BeanUtils.getBean(RedisCache.class); + String cacheToken = redisCache.getCacheObject(tokenKey); + if (StringUtils.isNotBlank(cacheToken)) { + token = cacheToken; + return token; + } + try { // 请求地址 String requestUrl = urlAddress + "query_token"; @@ -477,8 +491,11 @@ public interface ThirdPartyPlatformService extends InitializingBean { byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) result.getData()), dataSecret.getBytes(), dataSecretIv.getBytes()); String dataStr = new String(plainText, StandardCharsets.UTF_8); - Map resultMap = (Map) JSON.parse(dataStr); - token = resultMap.get("AccessToken"); + Map resultMap = (Map) JSON.parse(dataStr); + token = String.valueOf(resultMap.get("AccessToken")); + int tokenAvailableTime = Integer.parseInt(String.valueOf(resultMap.get("TokenAvailableTime"))); + // 将token存入缓存 + redisCache.setCacheObject(tokenKey, token, tokenAvailableTime, TimeUnit.SECONDS); // logger.info("token: {}", token); } // logger.info("获取令牌 result:{}, token: {}", result, token); diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java index f38bea542..3198e4b99 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java @@ -500,9 +500,10 @@ public class GuangXiPlatformServiceImpl implements ThirdPartyPlatformService { if (orderDetail == null) { return null; } - + // 拼装订单编号 + String startChargeSeq = Constants.OPERATORID_JIANG_SU + orderCode + DateUtils.dateTimeNow(DateUtils.YYMMDD); ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder() - .startChargeSeq(orderCode) + .startChargeSeq(startChargeSeq) // .startChargeType() .connectorId(orderBasicInfo.getPileConnectorCode()) .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) @@ -553,8 +554,10 @@ public class GuangXiPlatformServiceImpl implements ThirdPartyPlatformService { PageInfo pageInfo = new PageInfo<>(orderVOS); for (OrderVO orderVO : pageInfo.getList()) { + // 拼装订单编号 + String startChargeSeq = Constants.OPERATORID_JIANG_SU + orderVO.getOrderCode() + DateUtils.dateTimeNow(DateUtils.YYMMDD); ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder() - .startChargeSeq(orderVO.getOrderCode()) + .startChargeSeq(startChargeSeq) // .startChargeType() .connectorId(orderVO.getPileConnectorCode()) .startTime(orderVO.getStartTime()) @@ -645,17 +648,25 @@ public class GuangXiPlatformServiceImpl implements ThirdPartyPlatformService { String soc = realTimeMonitorData.getSOC() == null ? Constants.ZERO : info.getSOC(); String dateTime = DateUtils.getDateTime(); + // 拼装订单编号 + String startChargeSeq = Constants.OPERATORID_JIANG_SU + orderInfo.getOrderCode() + DateUtils.dateTimeNow(DateUtils.YYMMDD); SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo.builder() - .startChargeSeq(orderInfo.getOrderCode()) + .startChargeSeq(startChargeSeq) .startChargeSeqStat(Integer.parseInt(orderStatus)) + // .startChargeSeqStat(2) .connectorID(orderInfo.getPileConnectorCode()) .connectorStatus(Integer.parseInt(realTimeMonitorData.getConnectorStatus())) // 3-充电中 + // .connectorStatus(3) // 3-充电中 .currentA(current.setScale(1, RoundingMode.HALF_UP)) + // .currentA(new BigDecimal("20.3")) .voltageA(voltage.setScale(1, RoundingMode.HALF_UP)) + // .voltageA(new BigDecimal("260.7")) .soc(new BigDecimal(soc)) + // .soc(new BigDecimal("79")) .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) .endTime(dateTime) .totalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())) + // .totalPower(new BigDecimal("5292.21")) .build();