update 深圳平台设备状态变化推送接口

This commit is contained in:
Lemon
2025-05-19 08:59:52 +08:00
parent 2dd90e0938
commit b9debe8258
3 changed files with 352 additions and 68 deletions

View File

@@ -408,6 +408,79 @@ public class StationInfo extends BaseStationInfo {
@JSONField(name = "ParkingLockFlag")
private Integer parkingLockFlag;
/**
* 投入运营日期
*/
@JSONField(name = "OfficialRunTime")
private String officialRunTime;
/**
* 站点类别
* 1充电站
* 2换电站
* 3充换电一体站
*/
@JSONField(name = "StationClassification")
private Integer stationClassification;
/**
* 站点类别子分类
* 1集中式专营充电业务的场站
* 2分散式充电和停车功能复合的场站
*/
@JSONField(name = "SubStationClassification")
private Integer subStationClassification;
/**
* 充电接口标准支持
* 0:国标
* 1:欧标
*/
@JSONField(name = "SupportStandard")
private String supportStandard;
/**
* 土地所有权
* 1: 国有临时用地
* 2: 国有建设用地
* 3: 集体土地
*/
@JSONField(name = "OwnershipOfLand")
private Integer ownershipOfLand;
/**
* 城市用地分类
* 1: 居住用地
* 2: 商业服务用地
* 3: 公共管理与服务设施用地
* 4: 工业用地
* 5: 物流仓储用地
* 6: 交通设施用地
* 7: 绿地与广场用地
* 8:公用设施用地
* 255: 其它用地
*/
@JSONField(name = "LandProperty")
private Integer landProperty;
/**
* 服务车辆类型
* 1公交车
* 2出租车
* 3物流车
* 4通勤车
* 5大巴车
* 6私家车
* 7环卫车
* 8泥头、重卡车
* 9公务车
* 10网约车
* 11港口码头作业车
* 255其它
*/
@JSONField(name = "ServiceCarTypes")
private String serviceCarTypes;
/**
* 充电计费信息
*/

View File

@@ -7,12 +7,14 @@ import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
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.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.pile.domain.AreaCodeInfo;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.ThirdPartyStationRelation;
import com.jsowell.pile.dto.PushRealTimeInfoDTO;
@@ -24,6 +26,7 @@ import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
import com.jsowell.pile.vo.web.OrderListVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
import com.jsowell.pile.vo.web.PileStationVO;
@@ -34,12 +37,15 @@ import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
import com.jsowell.thirdparty.platform.common.StationInfo;
import com.jsowell.thirdparty.platform.domain.BMSInfo;
import com.jsowell.thirdparty.platform.domain.StationChargeStatsInfo;
import com.jsowell.thirdparty.platform.domain.SupStationInfo;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.HttpRequestUtil;
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.yi.business.geo.GeoCodeInfo;
import com.yi.business.geo.TermRelationTreeCoordinate;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,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;
/**
@@ -75,11 +82,17 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
private IAreaCodeInfoService areaCodeInfoService;
@Autowired
private PileBasicInfoService pileBasicInfoService;
@Autowired
private PileBillingTemplateService pileBillingTemplateService;
@Autowired
private RedisCache redisCache;
Logger logger = LoggerFactory.getLogger(this.getClass());
// 平台类型
@@ -106,24 +119,69 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
StationInfo stationInfo = StationInfo.builder()
.stationID(stationVO.getId())
.operatorID(Constants.OPERATORID_JIANG_SU)
// .equipmentOwnerID()
.equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(stationVO.getOrganizationCode()))
.stationName(stationVO.getStationName())
.countryCode(stationVO.getCountryCode())
.areaCode(stationVO.getAreaCode())
.address(stationVO.getAddress())
.stationTel(stationVO.getStationTel())
.serviceTel(stationVO.getStationTel())
.buildDate(stationVO.getCreateTime())
.officialRunTime(stationVO.getCreateTime())
.stationType(Integer.parseInt(stationVO.getStationType()))
.stationClassification(1) // 1-充电站
.subStationClassification(2)
.supportStandard("0")
.stationStatus(stationVO.getStationStatus())
.parkNums(0) // 默认 0未知
.stationLng(new BigDecimal(stationVO.getStationLng()))
.stationLat(new BigDecimal(stationVO.getStationLat()))
// .ownershipOfLand()
// .landProperty()
.construction(Integer.parseInt(stationVO.getConstruction()))
.supportOrder(0)
.busineHours("00:0024:00")
.build();
String stationTel = stationVO.getStationTel();
if (StringUtils.isNotBlank(stationTel)) {
stationInfo.setStationTel(stationTel);
stationInfo.setServiceTel(stationTel);
// electricityFee、serviceFee
StringBuilder electricityFee = new StringBuilder();
StringBuilder serviceFee = new StringBuilder();
// 查询计费模板
List<BillingPriceVO> priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(stationVO.getId()));
for (BillingPriceVO billingPriceVO : priceList) {
electricityFee.append(billingPriceVO.getStartTime())
.append("").append(billingPriceVO.getEndTime())
.append(",").append(billingPriceVO.getElectricityPrice())
.append(";");
serviceFee.append(billingPriceVO.getStartTime())
.append("").append(billingPriceVO.getEndTime())
.append(",").append(billingPriceVO.getServicePrice())
.append(";");
}
// // 去除最后一位的分号
// electricityFee.deleteCharAt(electricityFee.length() - 1);
// serviceFee.deleteCharAt(serviceFee.length() - 1);
stationInfo.setElectricityFee(electricityFee.toString());
stationInfo.setServiceFee(serviceFee.toString());
// streetCode
GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(stationVO.getAddress());
if (geoCode == null) {
// String areaCodeCountryside = geoCode.getCounty_code();
stationInfo.setStreetCode("123456789101");
} else {
AreaCodeInfo areaCodeInfo = new AreaCodeInfo();
if (StringUtils.isNotBlank(geoCode.getTownName())) {
String townName = geoCode.getTownName();
areaCodeInfo.setName(townName);
} else {
String countyName = geoCode.getCountyName();
areaCodeInfo.setName(countyName);
}
List<AreaCodeInfo> areaCodeInfoList = areaCodeInfoService.selectAreaCodeInfoList(areaCodeInfo);
stationInfo.setStreetCode(String.valueOf(areaCodeInfoList.get(0).getAreaCode()));
}
if (StringUtils.isNotBlank(stationVO.getPictures())) {
stationInfo.setPictures(Lists.newArrayList(stationVO.getPictures().split(",")));
}
@@ -156,41 +214,56 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@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();
// 通过operatorId 查出 相关配置信息
ThirdPartySecretInfoVO secretInfoVO = getShenZhenSecretInfo();
String operatorSecret = secretInfoVO.getOurOperatorSecret();
String dataSecret = secretInfoVO.getOurDataSecret();
String dataSecretIv = secretInfoVO.getOurDataSecretIv();
String signSecret = secretInfoVO.getOurSigSecret();
// 解密data 获取参数中的OperatorSecret
try {
// token缓存key值
String redisKey = operatorId + "_token:";
// 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getShenZhenSecretInfo();
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(operatorSecret, inputOperatorSecret)) {
throw new RuntimeException("密钥不一致");
// 对比密钥
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);
}
} catch (RuntimeException e) {
throw new BusinessException("2", "密钥错误");
}
// 生成token
String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis);
// 组装返回参数
AccessTokenVO vo = new AccessTokenVO();
vo.setAccessToken(token);
vo.setOperatorID(operatorId);
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
vo.setFailReason(0);
vo.setSuccStat(0);
vo.setFailReason(failReason);
vo.setSuccStat(succStat);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, secretInfoVO);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret()
, thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret());
return resultMap;
}
@@ -203,53 +276,86 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
@Override
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
List<StationInfo> resultList = new ArrayList<>();
// 查询出要查询的充电站id并set进 dto 的stationIds
if (StringUtils.isNotBlank(dto.getThirdPlatformType())) {
List<ThirdPartyStationRelation> relationList = thirdPartyStationRelationService.selectThirdPartyStationRelationList(dto.getThirdPlatformType());
if (CollectionUtils.isNotEmpty(relationList)) {
List<String> stationList = relationList.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;
}
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
StationInfo stationInfo = null;
for (ThirdPartyStationInfoVO stationVO : pageInfo.getList()) {
Long stationId = stationVO.getId();
stationInfo = StationInfo.builder()
.stationID(String.valueOf(stationVO.getId()))
StationInfo stationInfo = StationInfo.builder()
.stationID(String.valueOf(stationId))
.operatorID(Constants.OPERATORID_JIANG_SU)
// .equipmentOwnerID()
.equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(stationVO.getOrganizationCode()))
.stationName(stationVO.getStationName())
.countryCode(stationVO.getCountryCode())
.areaCode(stationVO.getAreaCode())
.address(stationVO.getAddress())
.stationTel(stationVO.getStationTel())
.serviceTel(stationVO.getStationTel())
.buildDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, stationVO.getCreateTime()))
.officialRunTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, stationVO.getCreateTime()))
.stationType(Integer.parseInt(stationVO.getStationType()))
.stationClassification(1) // 1-充电站
.subStationClassification(2)
.supportStandard("0")
.stationStatus(Integer.parseInt(stationVO.getStationStatus()))
.parkNums(0) // 默认 0未知
.stationLng(new BigDecimal(stationVO.getStationLng()))
.stationLat(new BigDecimal(stationVO.getStationLat()))
// .ownershipOfLand()
// .landProperty()
.construction(Integer.parseInt(stationVO.getConstruction()))
.busineHours("00:0024:00")
.build();
String stationTel = stationVO.getStationTel();
if (StringUtils.isNotBlank(stationTel)) {
stationInfo.setStationTel(stationTel);
stationInfo.setServiceTel(stationTel);
// electricityFee、serviceFee
StringBuilder electricityFee = new StringBuilder();
StringBuilder serviceFee = new StringBuilder();
// 查询计费模板
List<BillingPriceVO> priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(stationVO.getId()));
for (BillingPriceVO billingPriceVO : priceList) {
electricityFee.append(billingPriceVO.getStartTime())
.append("").append(billingPriceVO.getEndTime())
.append(",").append(billingPriceVO.getElectricityPrice())
.append(";");
serviceFee.append(billingPriceVO.getStartTime())
.append("").append(billingPriceVO.getEndTime())
.append(",").append(billingPriceVO.getServicePrice())
.append(";");
}
// // 去除最后一位的分号
// electricityFee.deleteCharAt(electricityFee.length() - 1);
// serviceFee.deleteCharAt(serviceFee.length() - 1);
stationInfo.setElectricityFee(electricityFee.toString());
stationInfo.setServiceFee(serviceFee.toString());
// streetCode
GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(stationVO.getAddress());
if (geoCode == null) {
// String areaCodeCountryside = geoCode.getCounty_code();
stationInfo.setStreetCode("123456789101");
} else {
AreaCodeInfo areaCodeInfo = new AreaCodeInfo();
if (StringUtils.isNotBlank(geoCode.getTownName())) {
String townName = geoCode.getTownName();
areaCodeInfo.setName(townName);
} else {
String countyName = geoCode.getCountyName();
areaCodeInfo.setName(countyName);
}
List<AreaCodeInfo> areaCodeInfoList = areaCodeInfoService.selectAreaCodeInfoList(areaCodeInfo);
stationInfo.setStreetCode(String.valueOf(areaCodeInfoList.get(0).getAreaCode()));
}
if (StringUtils.isNotBlank(stationVO.getPictures())) {
stationInfo.setPictures(Lists.newArrayList(stationVO.getPictures().split(",")));
}
@@ -266,7 +372,9 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
jsonObject.put("ItemSize", resultList.size());
jsonObject.put("StationInfos", resultList);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(jsonObject, shenZhenSecretInfo);
// 加密数据
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(jsonObject, shenZhenSecretInfo.getOurDataSecret(),
shenZhenSecretInfo.getOurDataSecretIv(), shenZhenSecretInfo.getTheirSigSecret());
return resultMap;
}
@@ -277,25 +385,64 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
* @return
*/
@Override
public String notificationStationStatus(PushRealTimeInfoDTO dto) {
String thirdPartyType = dto.getThirdPartyType();
String status = dto.getStatus();
String pileConnectorCode = dto.getPileConnectorCode();
public String notificationStationStatus(String stationId, String pileConnectorCode, String status, ThirdPartySecretInfoVO secretInfoVO) {
List<ConnectorStatusInfo> connectorStatusInfos = new ArrayList<>();
String operatorId = Constants.OPERATORID_LIANLIAN;
String operatorSecret = secretInfoVO.getTheirOperatorSecret();
String signSecret = secretInfoVO.getTheirSigSecret();
String dataSecret = secretInfoVO.getTheirDataSecret();
String dataSecretIv = secretInfoVO.getTheirDataSecretIv();
String urlAddress = secretInfoVO.getTheirUrlPrefix();
ThirdPartySecretInfoVO shenZhenSecretInfo = getShenZhenSecretInfo();
String operatorId = shenZhenSecretInfo.getTheirOperatorId();
String operatorSecret = shenZhenSecretInfo.getTheirOperatorSecret();
String signSecret = shenZhenSecretInfo.getTheirSigSecret();
String dataSecret = shenZhenSecretInfo.getTheirDataSecret();
String dataSecretIv = shenZhenSecretInfo.getTheirDataSecretIv();
String urlAddress = shenZhenSecretInfo.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue();
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
.connectorID(pileConnectorCode)
.status(Integer.parseInt(status))
.build();
StationStatusInfo stationStatusInfo = StationStatusInfo.builder()
.stationId(stationId)
// .connectorStatusInfos()
.build();
int currentA = Constants.zero;
int voltageA = Constants.zero;
int soc = Constants.zero;
BigDecimal chargeElectricity = BigDecimal.ZERO;
if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), status)) {
// 充电中,查出对应的实时数据信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(pileConnectorCode);
if (orderBasicInfo == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
List<RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode());
if (CollectionUtils.isEmpty(chargingRealTimeData)) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0);
currentA = new BigDecimal(realTimeMonitorData.getOutputCurrent()).intValue();
voltageA = new BigDecimal(realTimeMonitorData.getOutputVoltage()).intValue();
soc = new BigDecimal(realTimeMonitorData.getSOC()).intValue();
chargeElectricity = new BigDecimal(realTimeMonitorData.getChargingDegree());
}
info.setCurrentA(currentA);
info.setCurrentB(0);
info.setCurrentC(0);
info.setVoltageA(voltageA);
info.setVoltageB(0);
info.setVoltageC(0);
info.setSoc(soc);
info.setChargeElectricity(chargeElectricity);
info.setDischargeElectricity(BigDecimal.ZERO);
info.setAcquireDateTime(DateUtils.dateTimeNow());
connectorStatusInfos.add(info);
stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
// 调用平台接口
String jsonString = JSON.toJSONString(info);
String jsonString = JSON.toJSONString(stationStatusInfo);
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
@@ -313,7 +460,7 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
List<Object> ConnectorStatusInfos = new ArrayList<>();
ThirdPartySecretInfoVO shenZhenSecretInfo = getShenZhenSecretInfo();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getShenZhenSecretInfo();
ConnectorStatusInfo connectorStatusInfo;
for (String stationId : stationIds) {
@@ -377,7 +524,8 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
map.put("Total", total);
map.put("StationStatusInfos", collect);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(map, shenZhenSecretInfo);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -618,6 +766,7 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}