update 海南省平台

This commit is contained in:
Lemon
2025-05-14 13:48:49 +08:00
parent deabdd30a1
commit ebdfbc51fd

View File

@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
@@ -20,6 +21,8 @@ import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.pile.thirdparty.ZDLEquipmentInfo;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
@@ -32,10 +35,8 @@ import com.jsowell.pile.vo.web.EchoBillingTemplateVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO;
import com.jsowell.thirdparty.lianlian.domain.*;
import com.jsowell.thirdparty.lianlian.vo.EquipmentAuthVO;
import com.jsowell.thirdparty.lianlian.vo.QueryChargingStatusVO;
import com.jsowell.thirdparty.lianlian.vo.QueryStartChargeVO;
import com.jsowell.thirdparty.lianlian.vo.QueryStopChargeVO;
import com.jsowell.thirdparty.lianlian.vo.*;
import com.jsowell.thirdparty.platform.domain.SupStationInfo;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.domain.HNStationInfo;
@@ -56,6 +57,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -76,6 +78,9 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private RedisCache redisCache;
@Autowired
private PileBasicInfoService pileBasicInfoService;
@@ -113,6 +118,68 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
System.out.println("当前类名:" + this.getClass().getSimpleName());
}
/**
* 请求令牌 query_token
* @param dto
* @return
*/
@Override
public Map<String, String> queryToken(CommonParamsDTO dto) {
AccessTokenVO vo = new AccessTokenVO();
// 0:成功1:失败
int succStat = 0;
// 0:无1:无此对接平台2:密钥错误; 399:自定义
int failReason = 0;
String operatorId = dto.getOperatorID();
// token缓存key值
String redisKey = operatorId + "_token:";
// 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
if (thirdPartySecretInfoVO == null) {
failReason = 1;
succStat = 1;
} else {
String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret();
String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
// 解密data 获取参数中的OperatorSecret
String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv);
String inputOperatorSecret = null;
if (StringUtils.isNotBlank(decrypt)) {
inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret");
}
// 对比密钥
if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) {
failReason = 1;
succStat = 1;
} else {
// 先查缓存中是否有已生成的token
String token = redisCache.getCacheObject(redisKey);
int expiredTime = (int) redisCache.getExpire(redisKey);
if (StringUtils.isBlank(token)){
// 生成token
token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis);
expiredTime = (int) (JWTUtils.ttlMillis / 1000);
}
vo.setAccessToken(token);
vo.setTokenAvailableTime(expiredTime);
// 设置缓存
redisCache.setCacheObject(redisKey, token, expiredTime, TimeUnit.SECONDS);
}
}
// 组装返回参数
vo.setOperatorID(operatorId);
vo.setFailReason(failReason);
vo.setSuccStat(succStat);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret()
, thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret());
return resultMap;
}
public String pushStationInfoV2(PushStationInfoDTO dto) {
return zdlService.pushStationInfoV2(dto);
}
@@ -123,22 +190,12 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
// 查询出要查询的充电站id并set进 dto 的stationIds
if (StringUtils.isNotBlank(dto.getThirdPlatformType())) {
List<ThirdPartyStationRelation> xdtList = thirdPartyStationRelationService.selectThirdPartyStationRelationList(dto.getThirdPlatformType());
if (CollectionUtils.isNotEmpty(xdtList)) {
List<String> stationList = xdtList.stream()
.map(x -> String.valueOf(x.getStationId()))
.collect(Collectors.toList());
dto.setStationIds(stationList);
}
}
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
dto.setThirdPlatformType(thirdPlatformType);
PageUtils.startPage(pageNo, pageSize);
List<ThirdPartyStationInfoVO> stationInfos = pileStationInfoService.getStationInfosByThirdParty(dto);
List<ThirdPartyStationInfoVO> stationInfos = pileStationInfoService.selectStationInfosByThirdParty(dto);
if (CollectionUtils.isEmpty(stationInfos)) {
// 未查到数据
return null;
@@ -146,36 +203,33 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
List<HNStationInfo> resultList = new ArrayList<>();
HNStationInfo stationInfo = null;
List<SupStationInfo> resultList = new ArrayList<>();
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
stationInfo = new HNStationInfo();
String stationId = String.valueOf(pileStationInfo.getId());
stationInfo.setStationId(stationId);
stationInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); // 组织机构代码
String organizationCode = pileStationInfo.getOrganizationCode();
if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) {
String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1);
stationInfo.setEquipmentOwnerId(equipmentOwnerId);
} else {
stationInfo.setEquipmentOwnerId(Constants.OPERATORID_JIANG_SU);
}
stationInfo.setStationName(pileStationInfo.getStationName());
stationInfo.setCountryCode(pileStationInfo.getCountryCode());
SupStationInfo stationInfo = SupStationInfo.builder()
.stationID(stationId)
.operatorID(Constants.OPERATORID_JIANG_SU)
.equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(pileStationInfo.getOrganizationCode()))
.stationName(pileStationInfo.getStationName())
.countryCode(pileStationInfo.getCountryCode())
.address(pileStationInfo.getAddress())
.serviceTel(pileStationInfo.getStationTel())
.stationType(Integer.parseInt(pileStationInfo.getStationType()))
.stationStatus(Integer.parseInt(pileStationInfo.getStationStatus()))
.parkNums(Integer.parseInt(pileStationInfo.getParkNums()))
.stationLng(new BigDecimal(pileStationInfo.getStationLng()))
.stationLat(new BigDecimal(pileStationInfo.getStationLat()))
.construction(Integer.parseInt(pileStationInfo.getConstruction()))
.build();
String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213
// 根据逗号分组
String[] split = StringUtils.split(areaCode, ",");
// 只取最后一部分 330213
String subAreaCode = split[split.length - 1];
stationInfo.setAreaCode(subAreaCode);
stationInfo.setAddress(pileStationInfo.getAddress());
stationInfo.setServiceTel(pileStationInfo.getStationTel());
stationInfo.setStationType(Integer.parseInt(pileStationInfo.getStationType()));
stationInfo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus()));
stationInfo.setParkNums(Integer.parseInt(pileStationInfo.getParkNums()));
stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng()));
stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat()));
stationInfo.setConstruction(Integer.parseInt(pileStationInfo.getConstruction()));
// 停车费率描述
if (StringUtils.isNotBlank(pileStationInfo.getParkFeeDescribe())) {
stationInfo.setParkFee(pileStationInfo.getParkFeeDescribe());
@@ -187,7 +241,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
stationInfo.setPictures(Lists.newArrayList());
}
List<ZDLEquipmentInfo> pileList = pileBasicInfoService.getPileListForZDL(stationId);
List<EquipmentInfo> pileList = pileBasicInfoService.getPileListForLianLian(stationId);
if (CollectionUtils.isNotEmpty(pileList)) {
stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表
}
@@ -211,6 +265,11 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
return resultMap;
}
/**
* 获取充电费用
* @param stationId
* @return
*/
private Map<String, String> getPriceDescription(String stationId) {
Map<String, String> resultMap = Maps.newHashMap();
StringBuilder electricityFee = new StringBuilder("电费:");
@@ -275,19 +334,14 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
String thirdPartyType = dto.getThirdPartyType();
String pileConnectorCode = dto.getPileConnectorCode();
String status = dto.getStatus();
// 通过第三方类型查询相关配置信息
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
relation.setThirdPartyType(thirdPartyType);
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
if (relationInfo == null) {
return null;
}
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getOurOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue();
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
@@ -373,7 +427,6 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
String dataSecret = secretInfoVO.getTheirDataSecret();
String dataSecretIv = secretInfoVO.getTheirDataSecretIv();
String urlAddress = secretInfoVO.getTheirUrlPrefix();
String thirdPartyType = secretInfoVO.getPlatformType();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_CHARGE_ORDER_INFO.getValue();
JSONObject json = new JSONObject();
@@ -670,21 +723,14 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
if (orderInfo == null) {
return null;
}
// 通过第三方平台类型查询相关配置信息
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
relation.setThirdPartyType(orderInfo.getThirdPartyType());
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
// ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId()));
if (relationInfo == null) {
return null;
}
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
String thirdPartyType = relationInfo.getThirdPartyType();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getOurOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 推送启动充电结果(调用接口 notification_start_charge_result)
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_START_CHARGE_RESULT.getValue();
@@ -847,27 +893,20 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
public String notificationEquipChargeStatus(String orderCode) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
// 通过第三方平台类型查询相关配置信息
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
relation.setThirdPartyType(orderInfo.getThirdPartyType());
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
// ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId()));
if (relationInfo == null) {
return null;
}
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
String thirdPartyType = relationInfo.getThirdPartyType();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getOurOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 调用 查询充电状态方法
QueryEquipChargeStatusDTO dto = new QueryEquipChargeStatusDTO();
dto.setStartChargeSeq(orderCode);
// 根据type获取operatorId
String operatorIdByType = ThirdPartyOperatorIdEnum.getOperatorIdByType(thirdPartyType);
String operatorIdByType = ThirdPartyOperatorIdEnum.getOperatorIdByType(thirdPartySecretInfoVO.getTheirOperatorId());
dto.setOperatorID(operatorIdByType);
Map<String, String> map = queryEquipChargeStatus(dto);
if (map == null) {
@@ -875,7 +914,6 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
}
String data = map.get("Data");
// 解密data (此处解密需用 thirdparty_platform_config 的密钥配置)
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);