mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
update
This commit is contained in:
@@ -405,6 +405,16 @@ public interface ThirdPartyPlatformService extends InitializingBean {
|
||||
throw new UnsupportedOperationException("This method is not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* 充电电量信息推送
|
||||
* 当运营商平台完成一次充电时,将充电电量信息推送至省、市两级监管平台
|
||||
* @param orderCode
|
||||
* @return
|
||||
*/
|
||||
default String pushOrderInfo(String orderCode) {
|
||||
throw new UnsupportedOperationException("This method is not yet implemented");
|
||||
}
|
||||
|
||||
// -------------------------------------- 以下是公用方法 --------------------------------------- //
|
||||
/**
|
||||
* 从联联平台获取令牌
|
||||
|
||||
@@ -0,0 +1,738 @@
|
||||
package com.jsowell.thirdparty.platform.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.enums.lianlian.StationPaymentEnum;
|
||||
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||
import com.jsowell.common.enums.ykc.PileStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.*;
|
||||
import com.jsowell.pile.domain.*;
|
||||
import com.jsowell.pile.domain.nanrui.JiangSuOrderInfo;
|
||||
import com.jsowell.pile.dto.PushRealTimeInfoDTO;
|
||||
import com.jsowell.pile.dto.QueryConnectorListDTO;
|
||||
import com.jsowell.pile.dto.QueryStationInfoDTO;
|
||||
import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO;
|
||||
import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.thirdparty.CommonParamsDTO;
|
||||
import com.jsowell.pile.thirdparty.EquipmentInfo;
|
||||
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
|
||||
import com.jsowell.pile.vo.base.MerchantInfoVO;
|
||||
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
|
||||
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
|
||||
import com.jsowell.pile.vo.nanrui.JiangSuOrderInfoVO;
|
||||
import com.jsowell.pile.vo.uniapp.customer.CurrentTimePriceDetails;
|
||||
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
|
||||
import com.jsowell.pile.vo.web.PileModelInfoVO;
|
||||
import com.jsowell.pile.vo.web.PileStationVO;
|
||||
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
|
||||
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
|
||||
import com.jsowell.thirdparty.nanrui.domain.*;
|
||||
import com.jsowell.thirdparty.platform.domain.SupStationInfo;
|
||||
import com.jsowell.thirdparty.platform.dto.QueryOrderDTO;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 南瑞
|
||||
*/
|
||||
@Service
|
||||
public class NanRuiPlatfromServicelmp implements ThirdPartyPlatformService {
|
||||
|
||||
private final String thirdPlatformType = ThirdPlatformTypeEnum.NAN_RUI_PLATFORM.getTypeCode();
|
||||
|
||||
@Autowired
|
||||
private ThirdpartySecretInfoService thirdpartySecretInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileBasicInfoService pileBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileStationInfoService pileStationInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileMerchantInfoService pileMerchantInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileBillingTemplateService pileBillingTemplateService;
|
||||
|
||||
@Autowired
|
||||
private PileConnectorInfoService pileConnectorInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileModelInfoService pileModelInfoService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private OrderBasicInfoService orderBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private ThirdPartyStationRelationService thirdPartyStationRelationService;
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* query_token 获取token,提供给第三方平台使用
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryToken(CommonParamsDTO dto) {
|
||||
AccessTokenVO vo = new AccessTokenVO();
|
||||
// 0:成功;1:失败
|
||||
int succStat = 0;
|
||||
// 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义
|
||||
int failReason = 0;
|
||||
|
||||
String operatorId = dto.getPlatformID();
|
||||
// 通过operatorId 查出 operatorSecret
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId);
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
failReason = 1;
|
||||
succStat = 1;
|
||||
} else {
|
||||
String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
|
||||
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("PlatformSecret");
|
||||
}
|
||||
// 对比密钥
|
||||
if (!StringUtils.equals(theirOperatorSecret, inputOperatorSecret)) {
|
||||
failReason = 1;
|
||||
succStat = 1;
|
||||
} else {
|
||||
// 生成token
|
||||
String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis);
|
||||
vo.setAccessToken(token);
|
||||
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
|
||||
}
|
||||
}
|
||||
// 组装返回参数
|
||||
vo.setPlatformId(operatorId);
|
||||
vo.setFailReason(failReason);
|
||||
vo.setSuccStat(succStat);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送充电站信息
|
||||
* supervise_notification_station_info
|
||||
*/
|
||||
@Override
|
||||
public String notificationStationInfo(String stationId) {
|
||||
// 通过id查询站点相关信息
|
||||
PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(Long.parseLong(stationId));
|
||||
|
||||
// 查询第三方平台配置信息
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNanRuiPlatformSecretInfo();
|
||||
|
||||
String operatorId = thirdPartySecretInfoVO.getOurOperatorId();
|
||||
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
|
||||
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
|
||||
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
|
||||
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
|
||||
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
|
||||
|
||||
// 组装所需要的数据格式
|
||||
SupStationInfo info = SupStationInfo.builder()
|
||||
.stationID(stationId)
|
||||
.operatorID(operatorId)
|
||||
.stationName(pileStationInfo.getStationName())
|
||||
.isAloneApply(Integer.valueOf(pileStationInfo.getAloneApply()))
|
||||
.isPublicParkingLot(Integer.valueOf(pileStationInfo.getPublicParking()))
|
||||
.countryCode(pileStationInfo.getCountryCode())
|
||||
.address(pileStationInfo.getAddress())
|
||||
.serviceTel(pileStationInfo.getStationTel())
|
||||
.stationType(Integer.valueOf(pileStationInfo.getStationType()))
|
||||
.stationStatus(Integer.valueOf(pileStationInfo.getStationStatus()))
|
||||
.parkNums(Integer.valueOf(pileStationInfo.getParkNums()))
|
||||
.stationLng(new BigDecimal(pileStationInfo.getStationLng()))
|
||||
.stationLat(new BigDecimal(pileStationInfo.getStationLat()))
|
||||
.construction(Integer.valueOf(pileStationInfo.getConstruction()))
|
||||
.openAllDay(Integer.valueOf(pileStationInfo.getOpenAllDay()))
|
||||
.minElectricityPrice(new BigDecimal(Constants.ZERO))
|
||||
.electricityFee(Constants.ZERO)
|
||||
.serviceFee(Constants.ZERO)
|
||||
.parkFree(Integer.valueOf(pileStationInfo.getParkFree()))
|
||||
.supportOrder(Integer.valueOf(pileStationInfo.getSupportOrder()))
|
||||
.parkFeeType(0)
|
||||
.toiletFlag(Integer.valueOf(pileStationInfo.getToiletFlag()))
|
||||
.storeFlag(Integer.valueOf(pileStationInfo.getStoreFlag()))
|
||||
.restaurantFlag(Integer.valueOf(pileStationInfo.getRestaurantFlag()))
|
||||
.loungeFlag(Integer.valueOf(pileStationInfo.getLoungeFlag()))
|
||||
.canopyFlag(Integer.valueOf(pileStationInfo.getCanopyFlag()))
|
||||
.printerFlag(Integer.valueOf(pileStationInfo.getPrinterFlag()))
|
||||
.barrierFlag(Integer.valueOf(pileStationInfo.getBarrierFlag()))
|
||||
.parkingLockFlag(Integer.valueOf(pileStationInfo.getParkingLockFlag()))
|
||||
.build();
|
||||
String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213
|
||||
// 根据逗号分组
|
||||
String[] split = StringUtils.split(areaCode, ",");
|
||||
// 只取最后一部分 330213
|
||||
String subAreaCode = split[split.length - 1];
|
||||
info.setAreaCode(subAreaCode);
|
||||
// 截取运营商组织机构代码(去除最后一位后的最后九位)
|
||||
String organizationCode = "";
|
||||
if (StringUtils.equals(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getTypeCode(), thirdPlatformType)) {
|
||||
// 联联平台先使用自己运营商的组织机构代码
|
||||
organizationCode = Constants.OPERATORID_LIANLIAN;
|
||||
info.setEquipmentOwnerID(organizationCode);
|
||||
} else {
|
||||
MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(String.valueOf(pileStationInfo.getMerchantId()));
|
||||
organizationCode = merchantInfo.getOrganizationCode();
|
||||
if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) {
|
||||
String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1);
|
||||
info.setEquipmentOwnerID(equipmentOwnerId);
|
||||
}
|
||||
}
|
||||
|
||||
info.setPayment(StationPaymentEnum.getPaymentByCode(pileStationInfo.getPayment()));
|
||||
if (StringUtils.isNotBlank(pileStationInfo.getParkingNumber())) {
|
||||
info.setIsPublicParkingLot(1);
|
||||
info.setParkingLotNumber(pileStationInfo.getParkingNumber());
|
||||
}
|
||||
// 户号
|
||||
if (StringUtils.isNotBlank(pileStationInfo.getAccountNumber())) {
|
||||
info.setAccountNumber(pileStationInfo.getAccountNumber());
|
||||
}
|
||||
|
||||
// 容量
|
||||
if (StringUtils.isNotBlank(String.valueOf(pileStationInfo.getCapacity()))) {
|
||||
info.setCapacity(pileStationInfo.getCapacity().setScale(4, RoundingMode.HALF_UP));
|
||||
}
|
||||
List<EquipmentInfo> pileList = pileBasicInfoService.getPileListForLianLian(stationId);
|
||||
if (CollectionUtils.isNotEmpty(pileList)) {
|
||||
info.setEquipmentInfos(pileList); // 充电设备信息列表
|
||||
}
|
||||
|
||||
// areaCodeCountryside
|
||||
GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(pileStationInfo.getAddress());
|
||||
if (geoCode != null) {
|
||||
String areaCodeCountryside = geoCode.getCounty_code();
|
||||
info.setAreaCodeCountryside(areaCodeCountryside);
|
||||
}
|
||||
|
||||
// 调用联联平台接口
|
||||
String url = urlAddress + "supervise_notification_station_info";
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("SupStationInfo", info);
|
||||
|
||||
String jsonString = JSON.toJSONString(info);
|
||||
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取充电站信息
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
|
||||
List<NRStationInfo> resultList = new ArrayList<>();
|
||||
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
|
||||
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
|
||||
|
||||
PageUtils.startPage(pageNo, pageSize);
|
||||
List<ThirdPartyStationInfoVO> stationInfos = pileStationInfoService.getStationInfosByThirdParty(dto);
|
||||
if (CollectionUtils.isEmpty(stationInfos)) {
|
||||
// 未查到数据
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO NanRuiSecretInfo = getNanRuiPlatformSecretInfo();
|
||||
|
||||
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
|
||||
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
|
||||
// 拼装参数
|
||||
NRStationInfo nrStationInfo = NRStationInfo.builder()
|
||||
.stationId(String.valueOf(pileStationInfo.getId()))
|
||||
.operatorID(Constants.OPERATORID_JIANG_SU)
|
||||
.equipmentOwnerID(Constants.OPERATORID_JIANG_SU)
|
||||
.stationName(pileStationInfo.getStationName())
|
||||
.countryCode(pileStationInfo.getCountryCode())
|
||||
.areaCode(pileStationInfo.getAreaCode())
|
||||
.address(pileStationInfo.getAddress())
|
||||
.serviceTel(pileStationInfo.getStationTel())
|
||||
.stationStatus(Integer.parseInt(pileStationInfo.getStationStatus()))
|
||||
.parkNums(0)
|
||||
.stationLng(new BigDecimal(pileStationInfo.getStationLng()).setScale(6, BigDecimal.ROUND_HALF_UP))
|
||||
.stationLat(new BigDecimal(pileStationInfo.getStationLat()).setScale(6, BigDecimal.ROUND_HALF_UP))
|
||||
.openForBusinessDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileStationInfo.getCreateTime()))
|
||||
.openAllDay(Integer.parseInt(pileStationInfo.getOpenAllDay()))
|
||||
.busineHours(pileStationInfo.getBusinessHours())
|
||||
.build();
|
||||
// 站点费率
|
||||
// 查计费模板
|
||||
CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(String.valueOf(pileStationInfo.getId()));
|
||||
if (currentTimePriceDetails == null) {
|
||||
// 未设置计费模板
|
||||
continue;
|
||||
}
|
||||
String electricityPrice = currentTimePriceDetails.getElectricityPrice();
|
||||
electricityPrice = StringUtils.isBlank(electricityPrice) ? "0" : electricityPrice;
|
||||
|
||||
String servicePrice = currentTimePriceDetails.getServicePrice();
|
||||
servicePrice = StringUtils.isBlank(servicePrice) ? "0" : servicePrice;
|
||||
|
||||
BigDecimal price = new BigDecimal(electricityPrice).add(new BigDecimal(servicePrice));
|
||||
nrStationInfo.setMinElectricityPrice(price);
|
||||
|
||||
// 站点图片
|
||||
if (StringUtils.isNotBlank(pileStationInfo.getPictures())) {
|
||||
nrStationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(",")));
|
||||
}
|
||||
// 站点类型
|
||||
String stationType = pileStationInfo.getStationType();
|
||||
if (!StringUtils.equals("1", stationType) && !StringUtils.equals("255", stationType)) {
|
||||
// 不为1-公共并且不为255-其他,都为专用
|
||||
stationType = "2";
|
||||
}
|
||||
nrStationInfo.setStationType(Integer.parseInt(stationType));
|
||||
nrStationInfo.setConstruction(255);
|
||||
|
||||
List<NREquipmentInfo> nrEquipmentInfos = getEquipmentInfo(String.valueOf(pileStationInfo.getId()));
|
||||
nrStationInfo.setEquipmentInfos(nrEquipmentInfos);
|
||||
|
||||
resultList.add(nrStationInfo);
|
||||
}
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("PageNo", pageInfo.getPageNum());
|
||||
map.put("PageCount", pageInfo.getPages());
|
||||
map.put("ItemSize", resultList.size());
|
||||
map.put("StationInfos", resultList);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(map, getNanRuiPlatformSecretInfo());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送告警信息
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String notificationAlarmInfo(PushAlarmInfoDTO dto) {
|
||||
List<NRAlarmInfo> nrAlarmInfos = new ArrayList<>();
|
||||
|
||||
ThirdPartySecretInfoVO jiangSuSecretInfo = getNanRuiPlatformSecretInfo();
|
||||
|
||||
String operatorId = jiangSuSecretInfo.getOurOperatorId();
|
||||
String operatorSecret = jiangSuSecretInfo.getTheirOperatorSecret();
|
||||
String signSecret = jiangSuSecretInfo.getTheirSigSecret();
|
||||
String dataSecret = jiangSuSecretInfo.getTheirDataSecret();
|
||||
String dataSecretIv = jiangSuSecretInfo.getTheirDataSecretIv();
|
||||
String urlAddress = jiangSuSecretInfo.getTheirUrlPrefix();
|
||||
|
||||
// 从缓存中获取故障原因
|
||||
String redisKey = CacheConstants.PILE_HARDWARE_FAULT + dto.getPileConnectorCode();
|
||||
String faultReason = redisCache.getCacheObject(redisKey);
|
||||
int status = 0;
|
||||
if (StringUtils.equals(dto.getConnectorStatus(), "01")) {
|
||||
// 故障
|
||||
status = 1;
|
||||
}
|
||||
// 封装对象
|
||||
NRAlarmInfo alarmInfo = NRAlarmInfo.builder()
|
||||
.connectorId(dto.getPileConnectorCode())
|
||||
.alertTime(DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS))
|
||||
.alertCode(120) // 120-预留
|
||||
.describe(faultReason)
|
||||
.status(status)
|
||||
|
||||
.build();
|
||||
nrAlarmInfos.add(alarmInfo);
|
||||
|
||||
// 发送请求
|
||||
String url = urlAddress + "notification_alarmInfo";
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("AlarmInfos", nrAlarmInfos);
|
||||
|
||||
String jsonString = JSON.toJSONString(data);
|
||||
System.out.println("jsonString : " + jsonString);
|
||||
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备状态变化推送 notification_stationStatus
|
||||
* 推送充电设备接口状态信息 supervise_notification_station_status
|
||||
*
|
||||
* @param dto
|
||||
* @throws UnsupportedOperationException 未实现异常
|
||||
*/
|
||||
@Override
|
||||
public String notificationStationStatus(PushRealTimeInfoDTO dto) {
|
||||
String status = dto.getStatus();
|
||||
String pileConnectorCode = dto.getPileConnectorCode();
|
||||
|
||||
// 查出该桩所属哪个站点
|
||||
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
|
||||
PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn);
|
||||
// 通过站点id查询相关配置信息
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNanRuiPlatformSecretInfo();
|
||||
|
||||
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()
|
||||
.connectorID(pileConnectorCode)
|
||||
.status(Integer.parseInt(status))
|
||||
.build();
|
||||
// 调用联联平台接口
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("ConnectorStatusInfo", info);
|
||||
String jsonString = JSON.toJSONString(json);
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备接口状态
|
||||
* 此接口用于批量查询设备实时状态
|
||||
* 由充电运营商方实现此接口,省、市两级监管平台调用。
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryStationStatus(QueryStationInfoDTO dto) {
|
||||
List<String> stationIds = dto.getStationIds();
|
||||
List<NRStationStatusInfo> resultList = new ArrayList<>();
|
||||
|
||||
ThirdPartySecretInfoVO NanRuiSecretInfo = getNanRuiPlatformSecretInfo();
|
||||
|
||||
// 将 stationIdList 转换成 List<Long>
|
||||
List<Long> stationLongList = stationIds.stream()
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
QueryConnectorListDTO queryConnectorListDTO = QueryConnectorListDTO.builder()
|
||||
.stationIdList(stationLongList)
|
||||
.build();
|
||||
List<PileConnectorInfoVO> connectorInfoVOS = pileConnectorInfoService.getConnectorInfoListByParams(queryConnectorListDTO);
|
||||
if (CollectionUtils.isEmpty(connectorInfoVOS)) {
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
// 根据stationId分组
|
||||
Map<String, List<PileConnectorInfoVO>> collect = connectorInfoVOS.stream()
|
||||
.collect(Collectors.groupingBy(PileConnectorInfoVO::getStationId));
|
||||
// 遍历 map
|
||||
for (Map.Entry<String, List<PileConnectorInfoVO>> entry : collect.entrySet()) {
|
||||
String stationId = entry.getKey();
|
||||
List<PileConnectorInfoVO> connectorList = entry.getValue();
|
||||
List<NRConnectorStatusInfo> connectorStatusInfoList = new ArrayList<>();
|
||||
|
||||
for (PileConnectorInfoVO connectorInfoVO : connectorList) {
|
||||
NRConnectorStatusInfo nrConnectorStatusInfo = NRConnectorStatusInfo.builder()
|
||||
.connectorID(connectorInfoVO.getPileConnectorCode())
|
||||
.status(connectorInfoVO.getStatus())
|
||||
.currentA(0)
|
||||
.voltageA(0)
|
||||
.soc(BigDecimal.ZERO)
|
||||
.beginTime(null)
|
||||
.currentKwh(BigDecimal.ZERO)
|
||||
.timeStamp((int) (System.currentTimeMillis() / 1000))
|
||||
|
||||
.build();
|
||||
if (StringUtils.equals(String.valueOf(connectorInfoVO.getStatus()), "3")) {
|
||||
// 充电中
|
||||
nrConnectorStatusInfo.setCurrentA(connectorInfoVO.getCurrent().intValue());
|
||||
nrConnectorStatusInfo.setVoltageA(connectorInfoVO.getVoltage().intValue());
|
||||
nrConnectorStatusInfo.setSoc(new BigDecimal(connectorInfoVO.getSOC()));
|
||||
String chargingTime = connectorInfoVO.getChargingTime();
|
||||
Date beginTime = DateUtils.addMinute(new Date(), -Integer.parseInt(chargingTime));
|
||||
nrConnectorStatusInfo.setBeginTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, beginTime));
|
||||
}
|
||||
if (StringUtils.equals(String.valueOf(connectorInfoVO.getStatus()), "255")) {
|
||||
// 故障
|
||||
nrConnectorStatusInfo.setStatus(255);
|
||||
}
|
||||
connectorStatusInfoList.add(nrConnectorStatusInfo);
|
||||
}
|
||||
// 封装参数
|
||||
NRStationStatusInfo stationStatusInfo = NRStationStatusInfo.builder()
|
||||
.stationId(stationId)
|
||||
.connectorStatusInfos(connectorStatusInfoList)
|
||||
.build();
|
||||
resultList.add(stationStatusInfo);
|
||||
}
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("StationStatusInfos", resultList);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(map,NanRuiSecretInfo);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 充电电量信息推送
|
||||
* 当运营商平台完成一次充电时,将充电电量信息推送至省、市两级监管平台
|
||||
* @param orderCode
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String pushOrderInfo(String orderCode) {
|
||||
// 根据订单号查询订单信息
|
||||
JiangSuOrderInfoVO nrOrderInfoVO = orderBasicInfoService.getNROrderInfoByOrderCode(orderCode);
|
||||
JiangSuOrderInfo jiangSuOrderInfo = formatNROrderInfo((nrOrderInfoVO));
|
||||
|
||||
// 通过三方平台类型查询相关配置信息
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNanRuiPlatformSecretInfo();
|
||||
|
||||
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 + "notification_orderInfo";
|
||||
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("OrderInfo", jiangSuOrderInfo);
|
||||
|
||||
String jsonString = JSON.toJSONString(jsonObject);
|
||||
|
||||
String result = HttpRequestUtil.nrSendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询充电电量信息
|
||||
* 此接口用于批量查询时间区段内交易记录
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryOrderInfo(QueryOrderDTO dto) {
|
||||
List<JiangSuOrderInfo> resultList = new ArrayList<>();
|
||||
ThirdPartySecretInfoVO jiangSuSecretInfo = getNanRuiPlatformSecretInfo();
|
||||
NRQueryOrderDTO queryOrderDTO = new NRQueryOrderDTO();
|
||||
queryOrderDTO.setOrderCode(dto.getOrderCode());
|
||||
queryOrderDTO.setQueryStartTime(dto.getQueryStartTime());
|
||||
queryOrderDTO.setQueryEndTime(dto.getQueryEndTime());
|
||||
List<JiangSuOrderInfoVO> nrOrderInfos = orderBasicInfoService.getNROrderInfos(queryOrderDTO);
|
||||
if (CollectionUtils.isEmpty(nrOrderInfos)) {
|
||||
return Maps.newLinkedHashMap();
|
||||
}
|
||||
for (JiangSuOrderInfoVO nrOrderInfoVO : nrOrderInfos) {
|
||||
JiangSuOrderInfo jiangSuOrderInfo = formatJiangSuOrderInfo(nrOrderInfoVO);
|
||||
resultList.add(jiangSuOrderInfo);
|
||||
}
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(JSONObject.toJSONString(resultList), jiangSuSecretInfo);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备信息
|
||||
* @param stationId
|
||||
* @return
|
||||
*/
|
||||
private List<NREquipmentInfo> getEquipmentInfo(String stationId) {
|
||||
List<NREquipmentInfo> resultList = new ArrayList<>();
|
||||
List<PileBasicInfo> list = pileBasicInfoService.getPileListByStationId(stationId);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return resultList;
|
||||
}
|
||||
for (PileBasicInfo pileBasicInfo : list) {
|
||||
String pileSn = pileBasicInfo.getSn();
|
||||
// 获取桩状态
|
||||
Map<String, String> pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn));
|
||||
String pileStatus = pileStatusMap.get(pileSn);
|
||||
if (StringUtils.equals(PileStatusEnum.ON_LINE.getValue(), pileStatus)) {
|
||||
pileStatus = "50"; // 50-正常使用
|
||||
} else if (StringUtils.equals(PileStatusEnum.OFF_LINE.getValue(), pileStatus)
|
||||
|| StringUtils.equals(PileStatusEnum.FAULT.getValue(), pileStatus)) {
|
||||
pileStatus = "6"; // 6-维护中
|
||||
}
|
||||
// 获取桩型号信息
|
||||
PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn);
|
||||
if (modelInfo == null) {
|
||||
continue;
|
||||
}
|
||||
NREquipmentInfo equipmentInfo = NREquipmentInfo.builder()
|
||||
.equipmentID(pileSn)
|
||||
.equipmentName(pileSn)
|
||||
.openForBusinessDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getCreateTime()))
|
||||
.equipmentType(Integer.parseInt(modelInfo.getSpeedType()))
|
||||
.equipmentStatus(Integer.parseInt(pileStatus))
|
||||
.power(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP))
|
||||
|
||||
.vinFlag(1)
|
||||
.equipmentPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP))
|
||||
.newNationalStandard(1)
|
||||
.constructionTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getProductionDate()))
|
||||
.manufacturerID("014406554")
|
||||
.build();
|
||||
// 获取枪口信息
|
||||
List<NRConnectorInfo> connectorInfos = getConnectorInfo(pileSn);
|
||||
equipmentInfo.setConnectorInfos(connectorInfos);
|
||||
|
||||
resultList.add(equipmentInfo);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枪口信息
|
||||
* @param pileSn
|
||||
* @return
|
||||
*/
|
||||
private List<NRConnectorInfo> getConnectorInfo(String pileSn) {
|
||||
List<NRConnectorInfo> resultList = new ArrayList<>();
|
||||
List<PileConnectorInfo> list = pileConnectorInfoService.selectPileConnectorInfoList(pileSn);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return resultList;
|
||||
}
|
||||
PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn);
|
||||
int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3;
|
||||
// 封装成江苏平台对象
|
||||
for (PileConnectorInfo pileConnectorInfo : list) {
|
||||
NRConnectorInfo connectorInfo = NRConnectorInfo.builder()
|
||||
.connectorId(pileConnectorInfo.getPileConnectorCode())
|
||||
.connectorName(pileConnectorInfo.getPileConnectorCode())
|
||||
.connectorType(connectorType)
|
||||
.voltageUpperLimits(Integer.parseInt(modelInfo.getRatedVoltage()))
|
||||
.voltageLowerLimits(Integer.parseInt(modelInfo.getRatedVoltage()))
|
||||
.current(Integer.parseInt(modelInfo.getRatedCurrent()))
|
||||
.power(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP))
|
||||
.nationalStandard(2)
|
||||
|
||||
.build();
|
||||
resultList.add(connectorInfo);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取南瑞平台配置密钥信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ThirdPartySecretInfoVO getNanRuiPlatformSecretInfo() {
|
||||
// 通过第三方平台类型查询相关配置信息
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getTypeCode());
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
|
||||
}
|
||||
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
|
||||
return thirdPartySecretInfoVO;
|
||||
}
|
||||
|
||||
|
||||
private JiangSuOrderInfo formatJiangSuOrderInfo(JiangSuOrderInfoVO nrOrderInfoVO) {
|
||||
JiangSuOrderInfo jiangSuOrderInfo = JiangSuOrderInfo.builder()
|
||||
.operatorId(Constants.OPERATORID_JIANG_SU)
|
||||
.connectorId(nrOrderInfoVO.getConnectorId())
|
||||
.startChargeSeq(nrOrderInfoVO.getStartChargeSeq())
|
||||
.userChargeType(1)
|
||||
.elect(nrOrderInfoVO.getElect())
|
||||
.cuspElect(nrOrderInfoVO.getCuspElect())
|
||||
.peakElect(nrOrderInfoVO.getPeakElect())
|
||||
.flatElect(nrOrderInfoVO.getFlatElect())
|
||||
.valleyElect(nrOrderInfoVO.getValleyElect())
|
||||
.startTime(nrOrderInfoVO.getStartTime())
|
||||
.endTime(nrOrderInfoVO.getEndTime())
|
||||
|
||||
.build();
|
||||
// TODO 获取电表总起、止值
|
||||
// pileMsgRecordService.getPileFeedList()
|
||||
|
||||
jiangSuOrderInfo.setMeterValueStart(BigDecimal.ZERO);
|
||||
jiangSuOrderInfo.setMeterValueEnd(BigDecimal.ZERO);
|
||||
return jiangSuOrderInfo;
|
||||
}
|
||||
/**
|
||||
* 格式化南瑞平台订单对象
|
||||
* @param nrOrderInfoVO
|
||||
* @return
|
||||
*/
|
||||
private JiangSuOrderInfo formatNROrderInfo(JiangSuOrderInfoVO nrOrderInfoVO) {
|
||||
// 将组织机构代码截取后九位
|
||||
// String organizationCode = nrOrderInfoVO.getOperatorId();
|
||||
// if (StringUtils.isBlank(organizationCode)) {
|
||||
// return null;
|
||||
// }
|
||||
// String operatorId = StringUtils.substring(organizationCode, organizationCode.length() - 9);
|
||||
|
||||
JiangSuOrderInfo jiangSuOrderInfo = JiangSuOrderInfo.builder()
|
||||
.operatorId(Constants.OPERATORID_JIANG_SU)
|
||||
.connectorId(nrOrderInfoVO.getConnectorId())
|
||||
.startChargeSeq(nrOrderInfoVO.getStartChargeSeq())
|
||||
.userChargeType(1)
|
||||
.elect(nrOrderInfoVO.getElect())
|
||||
.cuspElect(nrOrderInfoVO.getCuspElect())
|
||||
.peakElect(nrOrderInfoVO.getPeakElect())
|
||||
.flatElect(nrOrderInfoVO.getFlatElect())
|
||||
.valleyElect(nrOrderInfoVO.getValleyElect())
|
||||
.startTime(nrOrderInfoVO.getStartTime())
|
||||
.endTime(nrOrderInfoVO.getEndTime())
|
||||
|
||||
.build();
|
||||
// TODO 获取电表总起、止值
|
||||
// pileMsgRecordService.getPileFeedList()
|
||||
|
||||
jiangSuOrderInfo.setMeterValueStart(BigDecimal.ZERO);
|
||||
jiangSuOrderInfo.setMeterValueEnd(BigDecimal.ZERO);
|
||||
return jiangSuOrderInfo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user