update 新电途平台Service

This commit is contained in:
Lemon
2025-03-17 09:01:00 +08:00
parent 5900696d42
commit 8d769352ae
3 changed files with 132 additions and 67 deletions

View File

@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
/**
@@ -46,8 +47,8 @@ public class XDTController extends ThirdPartyBaseController {
@Qualifier("xinDiantuPlatfromServiceImpl")
private ThirdPartyPlatformService platformLogic;
// @Autowired
// private XDTService xdtService;
@Autowired
private XDTService xdtService;
/**
* 获取token接口
@@ -372,23 +373,52 @@ public class XDTController extends ThirdPartyBaseController {
* @param orderCode
* @return
*/
// @GetMapping("/pushChargeOrderInfo/{orderCode}")
// public RestApiResponse<?> pushChargeOrderInfo(@PathVariable("orderCode") String orderCode) {
// logger.info("新电途平台推送充电订单信息 params:{}", orderCode);
// RestApiResponse<?> response = null;
// try {
// String result = xdtService.pushChargeOrderInfo(orderCode);
// response = new RestApiResponse<>(result);
// }catch (BusinessException e) {
// logger.error("新电途平台推送充电订单信息 error",e);
// response = new RestApiResponse<>(e.getCode(), e.getMessage());
// }catch (Exception e) {
// logger.error("新电途平台推送充电订单信息 error", e);
// response = new RestApiResponse<>(e);
// }
// logger.info("新电途平台推送充电订单信息 result:{}", response);
// return response;
// }
@GetMapping("/pushChargeOrderInfo/{orderCode}")
public RestApiResponse<?> pushChargeOrderInfo(@PathVariable("orderCode") String orderCode) {
logger.info("新电途平台推送充电订单信息 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
// String result = xdtService.pushChargeOrderInfo(orderCode);
String result = platformLogic.notificationChargeOrderInfo(orderCode);
response = new RestApiResponse<>(result);
}catch (BusinessException e) {
logger.error("新电途平台推送充电订单信息 error",e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.error("新电途平台推送充电订单信息 error", e);
response = new RestApiResponse<>(e);
}
logger.info("新电途平台推送充电订单信息 result:{}", response);
return response;
}
/**
* 批量推送订单接口
* @param dto
* @return
*/
@PostMapping("/pushChargeOrderInfoList")
public RestApiResponse<?> pushChargeOrderInfoList(@RequestBody PushInfoParamDTO dto) {
logger.info("新电途平台批量推送充电订单信息 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
List<String> orderCodeList = dto.getOrderCodeList();
for (String orderCode : orderCodeList) {
String result = platformLogic.notificationChargeOrderInfo(orderCode);
logger.info("新电途平台批量推送充电订单信息 result:{}", result);
}
response = new RestApiResponse<>();
}catch (BusinessException e) {
logger.error("新电途平台批量推送充电订单信息 error",e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.error("新电途平台批量推送充电订单信息 error", e);
response = new RestApiResponse<>(e);
}
logger.info("新电途平台批量推送充电订单信息 result:{}", response);
return response;
}
/**
* 新电途推送充电状态

View File

@@ -2,8 +2,10 @@ package com.jsowell.pile.dto;
import lombok.Data;
import java.util.List;
/**
* 练练平台推送信息参数DTO
* 平台推送信息参数DTO
*
* @author JS-ZZA
* @date 2023/5/26 9:26
@@ -15,4 +17,6 @@ public class PushInfoParamDTO {
private String status;
private String stationId;
private List<String> orderCodeList;
}

View File

@@ -15,10 +15,7 @@ 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.OrderBasicInfo;
import com.jsowell.pile.domain.OrderDetail;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
@@ -27,6 +24,7 @@ import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.pile.util.MerchantUtils;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
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.customer.BillingPriceVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
@@ -46,15 +44,17 @@ import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.bouncycastle.crypto.CryptoException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -497,15 +497,14 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService {
/**
* 推送充电订单信息
* supervise_notification_charge_order_info
* notification_charge_order_info
*/
@Override
public String notificationChargeOrderInfo(String orderCode, ThirdPartySecretInfoVO secretInfoVO) {
// 根据订单号查询出信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
if (orderBasicInfo == null) {
return null;
}
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = secretInfoVO.getTheirOperatorSecret();
@@ -514,47 +513,79 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService {
String dataSecretIv = secretInfoVO.getTheirDataSecretIv();
String urlAddress = secretInfoVO.getTheirUrlPrefix();
// 根据订单号查询订单详情
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
if (orderDetail == null) {
return null;
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_CHARGE_ORDER_INFO.getValue();
Date chargeStartTime = orderBasicInfo.getChargeStartTime();
if (chargeStartTime == null) {
chargeStartTime = orderBasicInfo.getCreateTime();
}
Date chargeEndTime = orderBasicInfo.getChargeEndTime();
if (chargeEndTime == null) {
chargeEndTime = orderBasicInfo.getCreateTime();
}
// 推送地址
String url = urlAddress + "supervise_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, chargeStartTime));
json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeEndTime));
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); // 2BMS 停止充电
// 拼装成平台所需格式对象
ChargeOrderInfo orderInfo = transformChargeOrderInfo(orderBasicInfo, orderDetail);
orderInfo.setOperatorID(operatorId);
String equipmentOwnerID;
if (MerchantUtils.isXiXiaoMerchant(orderBasicInfo.getMerchantId())) {
equipmentOwnerID = Constants.OPERATORID_XI_XIAO;
} else {
PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(orderInfo.getStationID());
String organizationCode = pileMerchantInfoVO.getOrganizationCode();
if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) {
equipmentOwnerID = ThirdPartyPlatformUtils.extractEquipmentOwnerID(pileMerchantInfoVO.getOrganizationCode());
} else {
equipmentOwnerID = Constants.OPERATORID_JIANG_SU;
}
}
orderInfo.setEquipmentOwnerID(equipmentOwnerID);
List<BillingPriceVO> billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId());
// 先将list按照 尖、峰、平、谷 时段排序
// List<BillingPriceVO> collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList());
// 再循环该list拼装对应的充电价格、费率
List<SupChargeDetails> chargeDetails = transformSupChargeDetails(orderDetail, billingList);
orderInfo.setChargeDetails(chargeDetails);
String jsonString = JSON.toJSONString(json);
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
if (StringUtils.isBlank(token)) {
return null;
}
// 调用联联平台接口
String jsonString = JSON.toJSONString(orderInfo);
// 发送请求
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
@Override
public String notificationChargeOrderInfo(String orderCode) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException, CryptoException {
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU;
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_CHARGE_ORDER_INFO.getValue();
Date chargeStartTime = orderBasicInfo.getChargeStartTime();
if (chargeStartTime == null) {
chargeStartTime = orderBasicInfo.getCreateTime();
}
Date chargeEndTime = orderBasicInfo.getChargeEndTime();
if (chargeEndTime == null) {
chargeEndTime = orderBasicInfo.getCreateTime();
}
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, chargeStartTime));
json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeEndTime));
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); // 2BMS 停止充电
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;
}