@@ -3,17 +3,20 @@ package com.jsowell.thirdparty.huawei.impl;
import com.alibaba.fastjson2.JSONObject ;
import com.google.common.collect.Maps ;
import com.jsowell.common.constant.Constants ;
import com.jsowell.common.enums.ykc.ReturnCodeEnum ;
import com.jsowell.common.enums.ykc.StartModeEnum ;
import com.jsowell.common.exception.BusinessException ;
import com.jsowell.common.util.BytesUtil ;
import com.jsowell.common.util.StringUtils ;
import com.jsowell.common.util.YKCUtils ;
import com.jsowell.pile.domain.MemberPlateNumberRelation ;
import com.jsowell.pile.domain.PileBasicInfo ;
import com.jsowell.pile.domain.ThirdPartyPlatformConfig ;
import com.jsowell.pile.domain.ThirdPartyStationRelation ;
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.dto.* ;
import com.jsowell.pile.dto.huawei.DeliverEquipBusinessDTO ;
import com.jsowell.pile.dto.huawei.ReceiveDeliverDTO ;
import com.jsowell.pile.dto.huawei.VinStartChargeDTO ;
import com.jsowell.pile.service.* ;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO ;
import com.jsowell.pile.vo.uniapp.BillingPriceVO ;
@@ -67,6 +70,12 @@ public class HuaWeiServiceImpl implements HuaWeiService {
@Autowired
private PileMerchantInfoService pileMerchantInfoService ;
@Autowired
private MemberPlateNumberRelationService memberPlateNumberRelationService ;
@Autowired
private OrderBasicInfoService orderBasicInfoService ;
/**
* 获取令牌
* @param dto
@@ -270,7 +279,6 @@ public class HuaWeiServiceImpl implements HuaWeiService {
// 为空说明未查到该枪口的计费模板
resultJson . put ( " SuccStat " , 1 ) ;
resultJson . put ( " FailReason " , 1 ) ;
return null ;
} else {
// 延时 500ms, 异步调用 下发计费策略 接口
CompletableFuture . runAsync ( ( ) - > {
@@ -311,15 +319,18 @@ public class HuaWeiServiceImpl implements HuaWeiService {
public String deliverEquipBusinessPolicy ( String equipBizSeq , String pileConnectorCode ) {
DeliverEquipBusinessDTO params = new DeliverEquipBusinessDTO ( ) ;
// 充电业务策略信息
List < DeliverEquipBusinessDTO
. ChargePolicyInfo > chargePolicyInfos = new ArrayList < > ( ) ;
DeliverEquipBusinessDTO . ChargePolicyInfo chargePolicyInfo = new DeliverEquipBusinessDTO . ChargePolicyInfo ( ) ;
// 业务策略信息体
List < DeliverEquipBusinessDTO
. ChargePolicyInfo
. PricePolicyInfo > pricePolicyInfos = new ArrayList < > ( ) ;
DeliverEquipBusinessDTO . ChargePolicyInfo . PricePolicyInfo pricePolicyInfo = new DeliverEquipBusinessDTO . ChargePolicyInfo . PricePolicyInfo ( ) ;
// 计费信息
List < DeliverEquipBusinessDTO
. ChargePolicyInfo
. PricePolicyInfo
@@ -331,9 +342,11 @@ public class HuaWeiServiceImpl implements HuaWeiService {
// 查询该桩的站点id
PileBasicInfo pileBasicInfo = pileBasicInfoService . selectPileBasicInfoBySN ( pileSn ) ;
String stationId = String . valueOf ( pileBasicInfo . getStationId ( ) ) ;
// 获取运营商组织结构代码
// MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(String.valueOf(pileBasicInfo.getMerchantId()));
// String organizationCode = merchantInfoVO.getOrganizationCode();
// 通过站点id查询相关配置信息
ThirdPartyStationRelation relation = new ThirdPartyStationRelation ( ) ;
relation . setStationId ( Long . parseLong ( stationId ) ) ;
@@ -373,7 +386,6 @@ public class HuaWeiServiceImpl implements HuaWeiService {
pricePolicyInfo . setValidStartTime ( billingPriceVO . getPublishTime ( ) ) ; // 生效时间
pricePolicyInfo . setValidEndTime ( " 2099-12-31 23:59:59 " ) ; // 失效时间
pricePolicyInfo . setSumPeriod ( policyInfoList . size ( ) ) ; // 时段数
pricePolicyInfo . setPolicyInfos ( policyInfoList ) ;
pricePolicyInfos . add ( pricePolicyInfo ) ;
@@ -454,4 +466,69 @@ public class HuaWeiServiceImpl implements HuaWeiService {
return resultMap ;
}
/**
* vin启动充电
* 平台 <-- 华为
*
* insert_start_charge
*
* @param dto
* @return
* @throws Exception
*/
@Override
public Map < String , String > vinStartCharge ( VinStartChargeDTO dto ) throws Exception {
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService . getInfoByOperatorId ( dto . getOperatorId ( ) ) ;
if ( configInfo = = null ) {
return null ;
}
Map < String , Object > paramMap = new LinkedHashMap < > ( ) ;
String vinCode = dto . getVin ( ) ;
String pileConnectorCode = dto . getConnectorID ( ) ;
// 截取桩号、枪口号
String pileSn = StringUtils . substring ( pileConnectorCode , 0 , pileConnectorCode . length ( ) - 2 ) ;
String connectorCode = StringUtils . substring ( pileConnectorCode , pileConnectorCode . length ( ) - 2 , pileConnectorCode . length ( ) ) ;
// 根据vin查询小程序平台用户信息
MemberPlateNumberRelation basicInfo = memberPlateNumberRelationService . getMemberPlateInfoByVinCode ( vinCode ) ;
if ( basicInfo = = null ) {
// 该用户未注册
throw new BusinessException ( ReturnCodeEnum . CODE_GENERATE_ORDER_ERROR ) ;
}
// 生成订单,并启动充电
GenerateOrderDTO generateOrderDTO = new GenerateOrderDTO ( ) ;
generateOrderDTO . setMemberPlateNumberRelation ( basicInfo ) ;
generateOrderDTO . setPileSn ( pileSn ) ;
generateOrderDTO . setConnectorCode ( connectorCode ) ;
generateOrderDTO . setStartMode ( StartModeEnum . VIN_CODE . getValue ( ) ) ;
generateOrderDTO . setMemberId ( basicInfo . getMemberId ( ) ) ;
generateOrderDTO . setStartSoc ( String . valueOf ( dto . getSoc ( ) ) ) ;
int succStat = Constants . one ; // 操作结果
int failReason = Constants . one ; // 失败原因
Map < String , Object > map = orderBasicInfoService . generateOrderByCard ( generateOrderDTO ) ;
if ( map ! = null ) {
// 鉴权成功
succStat = Constants . zero ;
failReason = Constants . zero ;
}
paramMap . put ( " SuccStat " , succStat ) ;
paramMap . put ( " FailReason " , failReason ) ;
// 加密
Map < String , String > resultMap = Maps . newLinkedHashMap ( ) ;
// 加密数据
byte [ ] encryptText = Cryptos . aesEncrypt ( JSONObject . toJSONString ( paramMap ) . 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 ;
}
}