mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
update 海南平台对接
This commit is contained in:
@@ -7,26 +7,37 @@ 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.enums.thirdparty.ThirdPartyOperatorIdEnum;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.PageUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.OrderBasicInfo;
|
||||
import com.jsowell.pile.domain.OrderDetail;
|
||||
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
|
||||
import com.jsowell.pile.domain.ThirdPartyStationRelation;
|
||||
import com.jsowell.pile.domain.*;
|
||||
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
|
||||
import com.jsowell.pile.domain.ykcCommond.StopChargingCommand;
|
||||
import com.jsowell.pile.dto.QueryEquipChargeStatusDTO;
|
||||
import com.jsowell.pile.dto.QueryEquipmentDTO;
|
||||
import com.jsowell.pile.dto.QueryStartChargeDTO;
|
||||
import com.jsowell.pile.dto.QueryStationInfoDTO;
|
||||
import com.jsowell.pile.vo.base.ConnectorInfoVO;
|
||||
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
|
||||
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
|
||||
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
|
||||
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
|
||||
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
|
||||
import com.jsowell.pile.vo.web.PileStationVO;
|
||||
import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO;
|
||||
import com.jsowell.thirdparty.lianlian.domain.*;
|
||||
import com.jsowell.thirdparty.lianlian.util.Cryptos;
|
||||
import com.jsowell.thirdparty.lianlian.util.Encodes;
|
||||
import com.jsowell.thirdparty.lianlian.util.GBSignUtils;
|
||||
import com.jsowell.thirdparty.lianlian.util.HttpRequestUtil;
|
||||
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.platform.AbsInterfaceWithPlatformLogic;
|
||||
import com.jsowell.thirdparty.platform.InterfaceWithPlatformLogicFactory;
|
||||
import com.jsowell.thirdparty.zhongdianlian.domain.ZDLEquipmentInfo;
|
||||
@@ -36,6 +47,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -421,4 +433,534 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
resultMap.put("Sig", resultSign);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求设备认证
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryEquipAuth(QueryEquipmentDTO dto) {
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
EquipmentAuthVO vo = new EquipmentAuthVO();
|
||||
|
||||
String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732
|
||||
String pileConnectorCode = dto.getConnectorID();
|
||||
// 先查询配置密钥相关信息
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 根据桩编号查询数据
|
||||
// String merchantId = StringUtils.substring(equipAuthSeq, 0, 9);
|
||||
String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
vo.setSuccStat(1); // 1-失败 0-成功 默认失败
|
||||
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
|
||||
if (pileBasicInfo != null) {
|
||||
// 查询当前枪口数据
|
||||
PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode);
|
||||
if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), String.valueOf(connectorInfo.getStatus()))
|
||||
|| StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), String.valueOf(connectorInfo.getStatus()))
|
||||
|| StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_APPOINTMENT_LOCK.getValue(), String.valueOf(connectorInfo.getStatus()))
|
||||
) {
|
||||
vo.setSuccStat(0);
|
||||
vo.setFailReason(0);
|
||||
} else {
|
||||
vo.setSuccStat(1);
|
||||
vo.setFailReason(1); // 1- 此设备尚未插枪;
|
||||
}
|
||||
vo.setFailReasonMsg("");
|
||||
vo.setEquipAuthSeq(equipAuthSeq);
|
||||
vo.setConnectorID(pileConnectorCode);
|
||||
} else {
|
||||
vo.setFailReason(2); // 设备检测失败
|
||||
vo.setFailReasonMsg("未查到该桩的数据");
|
||||
}
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询业务策略信息结果
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryEquipBusinessPolicy(QueryStartChargeDTO dto) {
|
||||
List<EquipBusinessPolicyVO.PolicyInfo> policyInfoList = new ArrayList<>();
|
||||
String pileConnectorCode = dto.getConnectorID();
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 截取桩号
|
||||
String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
// 查询该桩的站点id
|
||||
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
|
||||
// 根据桩号查询正在使用的计费模板
|
||||
List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileBasicInfo.getStationId()));
|
||||
|
||||
if (CollectionUtils.isEmpty(billingPriceVOList)) {
|
||||
return null;
|
||||
}
|
||||
EquipBusinessPolicyVO.PolicyInfo policyInfo = null;
|
||||
for (BillingPriceVO billingPriceVO : billingPriceVOList) {
|
||||
// 将时段开始时间、电费、服务费信息进行封装
|
||||
policyInfo = new EquipBusinessPolicyVO.PolicyInfo();
|
||||
String startTime = billingPriceVO.getStartTime() + ":00"; // 00:00:00 格式
|
||||
// 需要将中间的冒号去掉,改为 000000 格式
|
||||
String replace = StringUtils.replace(startTime, ":", "");
|
||||
policyInfo.setStartTime(replace);
|
||||
policyInfo.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
|
||||
policyInfo.setServicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
|
||||
|
||||
policyInfoList.add(policyInfo);
|
||||
}
|
||||
|
||||
// 拼装所需要的数据格式
|
||||
EquipBusinessPolicyVO vo = EquipBusinessPolicyVO.builder()
|
||||
.equipBizSeq(dto.getEquipBizSeq())
|
||||
.connectorId(dto.getConnectorID())
|
||||
.succStat(0)
|
||||
.failReason(0)
|
||||
.sumPeriod(policyInfoList.size())
|
||||
.policyInfos(policyInfoList)
|
||||
|
||||
.build();
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送启动充电结果
|
||||
*
|
||||
* @param orderCode
|
||||
*/
|
||||
@Override
|
||||
public String notificationStartChargeResult(String orderCode) {
|
||||
// 根据订单号查询订单信息
|
||||
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||
if (orderInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 通过站点id查询相关配置信息
|
||||
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
|
||||
relation.setStationId(Long.parseLong(orderInfo.getStationId()));
|
||||
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();
|
||||
|
||||
// 推送启动充电结果(调用接口 notification_start_charge_result)
|
||||
String url = urlAddress + "notification_start_charge_result";
|
||||
|
||||
// String orderStatus = orderInfo.getOrderStatus();
|
||||
// // 订单状态统一
|
||||
// if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) {
|
||||
// // 充电中
|
||||
// orderStatus = "2";
|
||||
// } else if (StringUtils.equals(OrderStatusEnum.NOT_START.getValue(), orderStatus)) {
|
||||
// // 未启动
|
||||
// orderStatus = "1";
|
||||
// } else {
|
||||
// // 其他状态都为 未知
|
||||
// orderStatus = "5";
|
||||
// }
|
||||
// 拼装参数
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("StartChargeSeq", orderCode);
|
||||
json.put("ConnectorID", orderInfo.getPileConnectorCode());
|
||||
json.put("StartChargeSeqStat", 2); // 一定要给 2-充电中
|
||||
json.put("StartTime", DateUtils.getDateTime());
|
||||
|
||||
String jsonString = JSONObject.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> queryStartCharge(QueryStartChargeDTO dto) {
|
||||
// 通过传过来的订单号和枪口号生成订单
|
||||
String pileConnectorCode = dto.getConnectorID();
|
||||
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq());
|
||||
if (orderInfo != null) {
|
||||
// 平台已存在订单
|
||||
return null;
|
||||
}
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 生成订单
|
||||
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(dto);
|
||||
String orderCode = (String) map.get("orderCode");
|
||||
String transactionCode = (String) map.get("transactionCode");
|
||||
OrderBasicInfo orderBasicInfo = (OrderBasicInfo) map.get("orderBasicInfo");
|
||||
|
||||
// 发送启机指令
|
||||
StartChargingCommand command = StartChargingCommand.builder()
|
||||
.pileSn(orderBasicInfo.getPileSn())
|
||||
.connectorCode(orderBasicInfo.getConnectorCode())
|
||||
.transactionCode(transactionCode)
|
||||
.chargeAmount(orderBasicInfo.getPayAmount())
|
||||
.logicCardNum(null)
|
||||
.physicsCardNum(null)
|
||||
.build();
|
||||
ykcPushCommandService.pushStartChargingCommand(command);
|
||||
|
||||
// 拼装对应的数据并返回
|
||||
QueryStartChargeVO vo = QueryStartChargeVO.builder()
|
||||
.startChargeSeq(orderCode)
|
||||
.startChargeSeqStat(2) // 1、启动中 ;2、充电中;3、停止中;4、已结束;5、未知
|
||||
.connectorID(pileConnectorCode)
|
||||
.succStat(0)
|
||||
.failReason(0)
|
||||
|
||||
.build();
|
||||
String type = ThirdPartyOperatorIdEnum.getTypeByOperatorId(dto.getOperatorId());
|
||||
if (StringUtils.equals(ThirdPlatformTypeEnum.XIN_DIAN_TU.getCode(), type)) {
|
||||
// 如果是新电途平台,则将 startChargeSeqStat 改为 1-启动中
|
||||
vo.setStartChargeSeqStat(1);
|
||||
}
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询充电状态
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryEquipChargeStatus(QueryEquipChargeStatusDTO dto) {
|
||||
String operatorID = dto.getOperatorID();
|
||||
String type = ThirdPartyOperatorIdEnum.getTypeByOperatorId(operatorID);
|
||||
String operatorName = ThirdPlatformTypeEnum.getLabelByCode(type);
|
||||
// 通过订单号查询订单信息
|
||||
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq());
|
||||
// logger.info(operatorName + "查询订单信息 orderInfo:{}", orderInfo);
|
||||
if (orderInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
|
||||
// logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo);
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
|
||||
// 通过订单号查询实时数据
|
||||
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
|
||||
QueryChargingStatusVO vo;
|
||||
if (CollectionUtils.isEmpty(realTimeData)) {
|
||||
vo = new QueryChargingStatusVO();
|
||||
} else {
|
||||
RealTimeMonitorData data = realTimeData.get(0);
|
||||
String orderStatus = orderInfo.getOrderStatus();
|
||||
if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) {
|
||||
// 充电中
|
||||
orderStatus = "2";
|
||||
}else if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) {
|
||||
// 充电完成
|
||||
orderStatus = "4";
|
||||
} else {
|
||||
// 直接给 5-未知
|
||||
orderStatus = "5";
|
||||
}
|
||||
String status = data.getConnectorStatus();
|
||||
int connectorStatus = 0;
|
||||
if (StringUtils.isBlank(status)) {
|
||||
// 查询当前枪口状态
|
||||
PileConnectorInfoVO connectorInfoVO = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode());
|
||||
connectorStatus = connectorInfoVO.getStatus();
|
||||
}else {
|
||||
connectorStatus = Integer.parseInt(status);
|
||||
}
|
||||
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
|
||||
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount();
|
||||
// 拼装联联平台数据
|
||||
vo = QueryChargingStatusVO.builder()
|
||||
.startChargeSeq(dto.getStartChargeSeq()) // 订单号
|
||||
.startChargeSeqStat(Integer.parseInt(orderStatus)) // 订单状态
|
||||
.connectorID(orderInfo.getPileConnectorCode()) // 枪口编码
|
||||
.connectorStatus(connectorStatus) // 枪口状态
|
||||
.currentA(new BigDecimal(data.getOutputCurrent())) // 电流
|
||||
.voltageA(new BigDecimal(data.getOutputVoltage())) // 电压
|
||||
.soc(new BigDecimal(data.getSOC()))
|
||||
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间
|
||||
.endTime(DateUtils.getDateTime()) // 本次采样时间
|
||||
.totalPower(new BigDecimal(data.getChargingDegree()).setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计充电量
|
||||
.elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费
|
||||
.seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费
|
||||
.totalMoney(new BigDecimal(data.getChargingAmount())) // 已充金额
|
||||
.build();
|
||||
}
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送充电状态
|
||||
*
|
||||
* @param orderCode
|
||||
*/
|
||||
@Override
|
||||
public String notificationEquipChargeStatus(String orderCode) {
|
||||
// 根据订单号查询订单信息
|
||||
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||
// 通过站点id查询相关配置信息
|
||||
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
|
||||
relation.setStationId(Long.parseLong(orderInfo.getStationId()));
|
||||
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();
|
||||
|
||||
// 调用 查询充电状态方法
|
||||
QueryEquipChargeStatusDTO dto = new QueryEquipChargeStatusDTO();
|
||||
dto.setStartChargeSeq(orderCode);
|
||||
// 根据type获取operatorId
|
||||
String operatorIdByType = ThirdPartyOperatorIdEnum.getOperatorIdByType(thirdPartyType);
|
||||
dto.setOperatorID(operatorIdByType);
|
||||
Map<String, String> map = queryEquipChargeStatus(dto);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
String data = map.get("Data");
|
||||
// 解密data (此处解密需用 thirdparty_platform_config 的密钥配置)
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType);
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
// 转成对应的对象
|
||||
QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class);
|
||||
|
||||
String url = urlAddress + "notification_equip_charge_status";
|
||||
// 调用联联平台接口
|
||||
String jsonString = JSONObject.toJSONString(vo);
|
||||
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求停止充电
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryStopCharge(QueryStartChargeDTO dto) {
|
||||
QueryStopChargeVO vo = new QueryStopChargeVO();
|
||||
String orderCode = dto.getStartChargeSeq();
|
||||
// 根据订单号查询订单信息
|
||||
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||
if (orderInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 若状态为充电中,则发送停机指令
|
||||
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) {
|
||||
// 充电中
|
||||
StopChargingCommand command = StopChargingCommand.builder()
|
||||
.pileSn(orderInfo.getPileSn())
|
||||
.connectorCode(orderInfo.getConnectorCode())
|
||||
.build();
|
||||
ykcPushCommandService.pushStopChargingCommand(command);
|
||||
vo.setStartChargeSeq(orderCode);
|
||||
vo.setStartChargeSeqStat(4); // 1、启动中 ;2、充电中;3、停止中;4、已结束;5、未知
|
||||
}
|
||||
vo.setSuccStat(0);
|
||||
vo.setFailReason(0);
|
||||
|
||||
String type = ThirdPartyOperatorIdEnum.getTypeByOperatorId(dto.getOperatorId());
|
||||
if (StringUtils.equals(ThirdPlatformTypeEnum.XIN_DIAN_TU.getCode(), type)) {
|
||||
// 如果是新电途平台,则将 startChargeSeqStat 改为 3-停止中
|
||||
vo.setStartChargeSeqStat(3);
|
||||
}
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送停止充电结果
|
||||
*
|
||||
* @param orderCode
|
||||
*/
|
||||
@Override
|
||||
public String notificationStopChargeResult(String orderCode) {
|
||||
// 根据订单号查询订单信息
|
||||
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||
if (orderInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 通过站点id查询相关配置信息
|
||||
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
|
||||
relation.setStationId(Long.parseLong(orderInfo.getStationId()));
|
||||
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();
|
||||
|
||||
String url = urlAddress + "notification_stop_charge_result";
|
||||
|
||||
// 拼装联联平台参数
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("StartChargeSeq", orderCode);
|
||||
json.put("StartChargeSeqStat", 4); // 只能给 4-已结束
|
||||
json.put("ConnectorID", orderInfo.getPileConnectorCode());
|
||||
json.put("SuccStat", 0);
|
||||
json.put("FailReason", 0);
|
||||
|
||||
String jsonString = JSONObject.toJSONString(json);
|
||||
|
||||
// 获取token
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送充电订单信息
|
||||
*
|
||||
* @param orderCode
|
||||
*/
|
||||
@Override
|
||||
public String notificationChargeOrderInfo(String orderCode) {
|
||||
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
|
||||
|
||||
// 通过站点id查询相关配置信息
|
||||
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
|
||||
relation.setStationId(Long.parseLong(orderBasicInfo.getStationId()));
|
||||
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();
|
||||
|
||||
String url = urlAddress + "notification_charge_order_info";
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("StartChargeSeq", orderCode);
|
||||
json.put("ConnectorID", orderBasicInfo.getPileConnectorCode());
|
||||
json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime()));
|
||||
json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime()));
|
||||
json.put("TotalPower", orderDetail.getTotalUsedElectricity().setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
json.put("TotalElecMoney", orderDetail.getTotalElectricityAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
json.put("TotalSeviceMoney", orderDetail.getTotalServiceAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
json.put("TotalMoney", orderDetail.getTotalOrderAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
json.put("StopReason", 2); // 2:BMS 停止充电
|
||||
|
||||
String jsonString = JSONObject.toJSONString(json);
|
||||
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送充电订单对账信息
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> checkChargeOrders() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ import com.jsowell.pile.domain.PileBasicInfo;
|
||||
import com.jsowell.pile.domain.PileConnectorInfo;
|
||||
import com.jsowell.pile.domain.PileStationInfo;
|
||||
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
|
||||
import com.jsowell.pile.dto.QueryEquipChargeStatusDTO;
|
||||
import com.jsowell.pile.dto.QueryEquipmentDTO;
|
||||
import com.jsowell.pile.dto.QueryStartChargeDTO;
|
||||
import com.jsowell.pile.dto.QueryStationInfoDTO;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.vo.web.PileModelInfoVO;
|
||||
@@ -66,6 +69,9 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean
|
||||
@Autowired
|
||||
protected ThirdPartyStationRelationService thirdPartyStationRelationService;
|
||||
|
||||
@Autowired
|
||||
protected YKCPushCommandService ykcPushCommandService;
|
||||
|
||||
@Autowired
|
||||
protected ZDLService zdlService;
|
||||
|
||||
@@ -94,8 +100,64 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean
|
||||
*/
|
||||
public abstract Map<String, String> queryStationStats(QueryStationInfoDTO dto);
|
||||
|
||||
////////////////////////////////////// 以下是公用方法 ////////////////////////////////////////////
|
||||
/////////////////////////////////
|
||||
/// 业务信息交换 10 个接口 Start ///
|
||||
/////////////////////////////////
|
||||
/**
|
||||
* 请求设备认证
|
||||
*/
|
||||
public abstract Map<String, String> queryEquipAuth(QueryEquipmentDTO dto);
|
||||
|
||||
/**
|
||||
* 查询业务策略信息结果
|
||||
*/
|
||||
public abstract Map<String, String> queryEquipBusinessPolicy(QueryStartChargeDTO dto);
|
||||
|
||||
/**
|
||||
* 请求启动充电
|
||||
*/
|
||||
public abstract Map<String, String> queryStartCharge(QueryStartChargeDTO dto);
|
||||
|
||||
/**
|
||||
* 推送启动充电结果
|
||||
*/
|
||||
public abstract String notificationStartChargeResult(String orderCode);
|
||||
|
||||
/**
|
||||
* 查询充电状态
|
||||
*/
|
||||
public abstract Map<String, String> queryEquipChargeStatus(QueryEquipChargeStatusDTO dto);
|
||||
|
||||
/**
|
||||
* 推送充电状态
|
||||
*/
|
||||
public abstract String notificationEquipChargeStatus(String orderCode);
|
||||
|
||||
/**
|
||||
* 请求停止充电
|
||||
*/
|
||||
public abstract Map<String, String> queryStopCharge(QueryStartChargeDTO dto);
|
||||
|
||||
/**
|
||||
* 推送停止充电结果
|
||||
*/
|
||||
public abstract String notificationStopChargeResult(String orderCode);
|
||||
|
||||
/**
|
||||
* 推送充电订单信息
|
||||
*/
|
||||
public abstract String notificationChargeOrderInfo(String orderCode);
|
||||
|
||||
/**
|
||||
* 推送充电订单对账信息
|
||||
*/
|
||||
public abstract Map<String, String> checkChargeOrders();
|
||||
|
||||
///////////////////////////////
|
||||
/// 业务信息交换 10 个接口 end ///
|
||||
///////////////////////////////
|
||||
|
||||
// -------------------------------------- 以下是公用方法 --------------------------------------- //
|
||||
/**
|
||||
* 从联联平台获取令牌
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user