update 宁夏平台Service

This commit is contained in:
Lemon
2024-06-11 16:19:18 +08:00
parent 2010fe2b18
commit 0aef83548c
2 changed files with 208 additions and 41 deletions

View File

@@ -0,0 +1,130 @@
package com.jsowell.thirdparty.platform.domain;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 充电状态信息
*
* @author Lemon
* @Date 2024/6/11 14:31:36
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SupEquipChargeStatusInfo {
/**
* 平台运营商ID
*/
@JSONField(name = "OperatorID")
private String operatorID;
/**
* 充换电服务运营商ID
*/
@JSONField(name = "EquipmentOwnerID")
private String equipmentOwnerID;
/**
* 充换电站ID
*/
@JSONField(name = "StationID")
private String stationID;
/**
* 充电设备编码
*/
@JSONField(name = "EquipmentID")
private String equipmentID;
/**
* 充电订单号
*/
@JSONField(name = "OrderNo")
private String orderNo;
/**
* 充电订单状态
* 1、启动中
* 2、充电中
* 3、停止中
* 4、充电完成
* 5、订单挂起
* 6、充电异常结束
* 7、启动失败
*/
@JSONField(name = "OrderStatus")
private Integer orderStatus;
/**
* 充电设备接口编码
*/
@JSONField(name = "ConnectorID")
private String connectorID;
/**
* 设备接口分类
* 1车辆充电设备接口
* 2换电站内的电池箱充电设备接口
*/
@JSONField(name = "EquipmentClassification")
private Integer equipmentClassification;
/**
* 推送时间
*/
@JSONField(name = "PushTimeStamp")
private String pushTimeStamp;
/**
* 充电设备接口状态
* 0离网
* 1空闲
* 2 占用(未充电)
* 3 占用(充电中)
* 4 占用(预约锁定)
* 255故障
*/
@JSONField(name = "ConnectorStatus")
private Integer connectorStatus;
/**
* A相电流
* 小数点后4位
*/
@JSONField(name = "CurrentA")
private BigDecimal currentA;
/**
* 电池剩余电量
* 小数点后1位
*/
@JSONField(name = "SOC")
private BigDecimal soc;
/**
* 开始充电时间
*/
@JSONField(name = "StartTime")
private String startTime;
/**
* 本次采样时间
*/
@JSONField(name = "EndTime")
private String endTime;
/**
* 累计充电量
* 小数点后4位
*/
@JSONField(name = "TotalPower")
private BigDecimal totalPower;
}

View File

@@ -10,9 +10,9 @@ import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.enums.lianlian.StationPaymentEnum;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.BillingTimeTypeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
@@ -22,7 +22,6 @@ import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.PushRealTimeInfoDTO;
import com.jsowell.pile.dto.QueryEquipChargeStatusDTO;
import com.jsowell.pile.dto.QueryOperatorInfoDTO;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.pile.service.*;
@@ -33,21 +32,17 @@ import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
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.uniapp.BillingPriceVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
import com.jsowell.pile.vo.web.PileStationVO;
import com.jsowell.thirdparty.lianlian.domain.ConnectorChargeStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo;
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
import com.jsowell.thirdparty.lianlian.vo.QueryChargingStatusVO;
import com.jsowell.thirdparty.platform.common.StationInfo;
import com.jsowell.thirdparty.platform.domain.*;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.platform.util.HttpRequestUtil;
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
@@ -56,7 +51,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
@@ -356,29 +350,49 @@ public class NinaXiaPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public String notificationStationStatus(PushRealTimeInfoDTO dto) {
String status = dto.getStatus();
String pileConnectorCode = dto.getPileConnectorCode();
String status = dto.getStatus();
ThirdPartySecretInfoVO xiaPlatformSecretInfo = getNingXiaPlatformSecretInfo();
// 查询充电枪口状态
PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode);
if (Objects.isNull(connectorInfo)) {
throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR);
}
// 查出该桩所属哪个站点
String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
ThirdPartySecretInfoVO ningXiaSecretInfo = getNingXiaPlatformSecretInfo();
String merchantId = connectorInfo.getMerchantId();
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId);
if (Objects.isNull(merchantInfoVO)) {
throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR);
}
String operatorId = ningXiaSecretInfo.getOurOperatorId();
String operatorSecret = ningXiaSecretInfo.getTheirOperatorSecret();
String signSecret = ningXiaSecretInfo.getTheirSigSecret();
String dataSecret = ningXiaSecretInfo.getTheirDataSecret();
String dataSecretIv = ningXiaSecretInfo.getTheirDataSecretIv();
String urlAddress = ningXiaSecretInfo.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue();
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
SupConnectorStatusInfo info = SupConnectorStatusInfo.builder()
.operatorID(Constants.JSOWELL_OPERATORID)
.equipmentOwnerID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode()))
.stationID(connectorInfo.getStationId())
.equipmentID(connectorInfo.getPileSn())
.connectorID(pileConnectorCode)
.equipmentClassification(Constants.ONE)
.status(Integer.parseInt(status))
.statusDesc(PileConnectorDataBaseStatusEnum.getStatusDescription(status))
.parkStatus(Constants.ZERO)
.lockStatus(Constants.ZERO)
.batteryStatus(Constants.ZERO)
.batteryPackID("")
.lastChangeTime(DateUtils.getDateTime())
.build();
// 调用联联平台接口
JSONObject json = new JSONObject();
json.put("ConnectorStatusInfo", info);
String jsonString = JSON.toJSONString(json);
String operatorId = xiaPlatformSecretInfo.getOurOperatorId();
String operatorSecret = xiaPlatformSecretInfo.getTheirOperatorSecret();
String signSecret = xiaPlatformSecretInfo.getTheirSigSecret();
String dataSecret = xiaPlatformSecretInfo.getTheirDataSecret();
String dataSecretIv = xiaPlatformSecretInfo.getTheirDataSecretIv();
String urlAddress = xiaPlatformSecretInfo.getTheirUrlPrefix();
String url = urlAddress + "supervise_notification_station_status";
// JSONObject json = new JSONObject();
// json.put("ConnectorStatusInfo", 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);
@@ -577,27 +591,50 @@ public class NinaXiaPlatformServiceImpl implements ThirdPartyPlatformService {
String dataSecretIv = ningXiaSecretInfo.getTheirDataSecretIv();
String urlAddress = ningXiaSecretInfo.getTheirUrlPrefix();
// 调用 查询充电状态方法
QueryEquipChargeStatusDTO dto = new QueryEquipChargeStatusDTO();
dto.setStartChargeSeq(orderCode);
// 根据type获取operatorId
String operatorIdByType = ThirdPlatformTypeEnum.NING_XIA_PLATFORM.getOperatorId();
dto.setOperatorID(operatorIdByType);
Map<String, String> map = queryEquipChargeStatus(dto);
if (map == null) {
return null;
// 查询充电枪口状态
PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode());
if (Objects.isNull(connectorInfo)) {
throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR);
}
String data = map.get("Data");
// 解密data (此处解密需用 thirdparty_platform_config 的密钥配置)
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
ningXiaSecretInfo.getOurDataSecret().getBytes(), ningXiaSecretInfo.getOurDataSecretIv().getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
// 转成对应的对象
QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class);
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getValue();
String merchantId = connectorInfo.getMerchantId();
MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId);
if (Objects.isNull(merchantInfoVO)) {
throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR);
}
String orderStatus = orderInfo.getOrderStatus();
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) {
// 充电中
orderStatus = "2";
}else if (StringUtils.equals(OrderStatusEnum.ORDER_COMPLETE.getValue(), orderStatus)) {
// 充电完成
orderStatus = "4";
}
String dateTimeNow = DateUtils.getDateTime();
SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo.builder()
.operatorID(Constants.JSOWELL_OPERATORID)
.equipmentOwnerID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode()))
.stationID(orderInfo.getStationId())
.equipmentID(orderInfo.getPileSn())
.orderNo(orderCode)
.orderStatus(Integer.parseInt(orderStatus))
.connectorID(orderInfo.getPileConnectorCode())
.equipmentClassification(1)
.pushTimeStamp(dateTimeNow)
.connectorStatus(connectorInfo.getStatus())
.currentA(connectorInfo.getCurrent())
.soc(new BigDecimal(connectorInfo.getSOC()))
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime()))
.endTime(dateTimeNow)
.totalPower(connectorInfo.getInstantPower())
.build();
String url = urlAddress + "supervise_notification_equip_charge_status";
// 调用联联平台接口
String jsonString = JSON.toJSONString(vo);
String jsonString = JSON.toJSONString(supEquipChargeStatusInfo);
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);