This commit is contained in:
Lemon
2024-01-26 16:39:46 +08:00
parent ca036b0646
commit 49e725983e
10 changed files with 454 additions and 17 deletions

View File

@@ -7,17 +7,22 @@ import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.thirdparty.huawei.StartFailedReasonEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.huawei.HWStationInfo;
import com.jsowell.pile.dto.PushStationInfoDTO;
import com.jsowell.pile.dto.QueryStartChargeDTO;
import com.jsowell.pile.dto.huawei.DeliverEquipBusinessDTO;
import com.jsowell.pile.dto.huawei.QueryStartChargeDTO;
import com.jsowell.pile.dto.huawei.requestEquipBusinessPolicyDTO;
import com.jsowell.pile.dto.huawei.HWQueryStartChargeDTO;
import com.jsowell.pile.dto.huawei.ReceiveStartChargeResultDTO;
import com.jsowell.pile.dto.huawei.RequestEquipBusinessPolicyDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
import com.jsowell.pile.vo.huawei.QueryEquipAuthVO;
import com.jsowell.pile.vo.huawei.QueryStartChargeVO;
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
@@ -25,12 +30,10 @@ import com.jsowell.pile.vo.web.PileStationVO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo;
import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO;
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.zhongdianlian.dto.ZDLGetTokenDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -71,6 +74,9 @@ public class HuaweiServiceV2 {
@Autowired
private PileBillingTemplateService pileBillingTemplateService;
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@@ -327,7 +333,7 @@ public class HuaweiServiceV2 {
* @param dto
* @return
*/
public Map<String, String> requestEquipBusinessPolicy(requestEquipBusinessPolicyDTO dto) {
public Map<String, String> requestEquipBusinessPolicy(RequestEquipBusinessPolicyDTO dto) {
String pileConnectorCode = dto.getConnectorID();
String equipBizSeq = dto.getEquipBizSeq();
// 根据枪口号查询计费模板,并返回信息
@@ -498,7 +504,7 @@ public class HuaweiServiceV2 {
* @param dto
* @return QueryStartChargeVO
*/
public QueryStartChargeVO queryStartCharge(QueryStartChargeDTO dto) {
public QueryStartChargeVO queryStartCharge(HWQueryStartChargeDTO dto) {
String pileConnectorCode = dto.getConnectorID();
BigDecimal chargeAmount = dto.getMoneyLimit();
// 获取华为配置参数
@@ -513,12 +519,24 @@ public class HuaweiServiceV2 {
String urlAddress = settingInfo.getUrlAddress();
String requestUrl = urlAddress + "query_start_charge";
// 生成订单号
String orderCode = IdUtils.getOrderCode();
// 生成订单
String orderCode = IdUtils.getOrderCode();
String startChargeSeq = Constants.OPERATORID_JIANG_SU + "_C" + orderCode;
QueryStartChargeDTO startChargeDTO = new QueryStartChargeDTO();
startChargeDTO.setOperatorId(dto.getOperatorId());
startChargeDTO.setStartChargeSeq(startChargeSeq);
startChargeDTO.setConnectorID(dto.getConnectorID());
startChargeDTO.setAccountBalance(dto.getMoneyLimit());
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(startChargeDTO);
if (map == null) {
log.error("华为平台生成订单 error");
throw new BusinessException(ReturnCodeEnum.CODE_GENERATE_ORDER_ERROR);
}
// 拼装参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("StartChargeSeq", Constants.OPERATORID_JIANG_SU + "_C" + orderCode);
jsonObject.put("StartChargeSeq", startChargeSeq);
jsonObject.put("ConnectorID", pileConnectorCode);
jsonObject.put("MoneyLimit", chargeAmount);
@@ -549,7 +567,71 @@ public class HuaweiServiceV2 {
/**
* 接收启动充电结果
*/
public void receiveStartChargeResult() {
public void receiveStartChargeResult(ReceiveStartChargeResultDTO dto) {
String startChargeSeq = dto.getStartChargeSeq();
Integer startChargeSeqStat = dto.getStartChargeSeqStat(); // 充电订单状态
Integer failReason = dto.getFailReason();
String startTime = dto.getStartTime();
// 根据订单号查询订单信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq);
// 判断订单状态
if (startChargeSeqStat == Constants.two) {
// 充电中
orderBasicInfo.setOrderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue());
// 设置开始时间
orderBasicInfo.setChargeStartTime(DateUtils.parseDate(startTime));
orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo);
}
if (failReason != 0) {
// 启动失败, 将失败原因换成中文
String reason = StartFailedReasonEnum.getReasonByCode(failReason);
// 给用户退款(执行0x33中启动失败的操作流程)
orderBasicInfoService.chargingPileFailedToStart(orderBasicInfo.getTransactionCode(), reason);
}
}
/**
* 查询充电状态
* @param startChargeSeq
*/
public void queryChargeStatus(String startChargeSeq) {
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
if (settingInfo == null) {
return;
}
String operatorSecret = settingInfo.getOperatorSecret();
String dataSecret = settingInfo.getDataSecret();
String dataSecretIv = settingInfo.getDataSecretIv();
String signSecret = settingInfo.getSignSecret();
String urlAddress = settingInfo.getUrlAddress();
String requestUrl = urlAddress + "query_equip_auth";
// 拼装参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("StartChargeSeq", startChargeSeq);
// 加密
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8),
dataSecret.getBytes(), dataSecretIv.getBytes());
String strData = Encodes.encodeBase64(encryptText);
// 向华为发送请求
String response = sendRequest2HuaWei(strData, signSecret, requestUrl);
CommonResult<?> commonResult = JSONObject.parseObject(response, CommonResult.class);
if (commonResult.getRet() != 0) {
log.error("解析查询华为充电状态接口result error:{}, ", commonResult.getMsg());
return;
}
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) commonResult.getData()),
dataSecret.getBytes(), dataSecretIv.getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
// 转换成对应的对象
}