@@ -1,8 +1,63 @@
package com.jsowell.thirdparty.platform.service.impl ;
import com.alibaba.fastjson2.JSON ;
import com.alibaba.fastjson2.JSONObject ;
import com.github.pagehelper.PageInfo ;
import com.google.common.collect.Lists ;
import com.jsowell.common.constant.Constants ;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData ;
import com.jsowell.common.core.redis.RedisCache ;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum ;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum ;
import com.jsowell.common.enums.ykc.OrderStatusEnum ;
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.DateUtils ;
import com.jsowell.common.util.JWTUtils ;
import com.jsowell.common.util.PageUtils ;
import com.jsowell.common.util.StringUtils ;
import com.jsowell.pile.domain.AreaCodeInfo ;
import com.jsowell.pile.domain.OrderBasicInfo ;
import com.jsowell.pile.domain.OrderDetail ;
import com.jsowell.pile.dto.QueryStartChargeDTO ;
import com.jsowell.pile.dto.QueryStationInfoDTO ;
import com.jsowell.pile.service.* ;
import com.jsowell.pile.thirdparty.CommonParamsDTO ;
import com.jsowell.pile.thirdparty.EquipmentInfo ;
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.lianlian.AccumulativeInfoVO ;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO ;
import com.jsowell.pile.vo.uniapp.customer.OrderVO ;
import com.jsowell.pile.vo.web.PileConnectorInfoVO ;
import com.jsowell.pile.vo.web.PileStationVO ;
import com.jsowell.thirdparty.lianlian.domain.* ;
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO ;
import com.jsowell.thirdparty.platform.common.ChargeOrderInfo ;
import com.jsowell.thirdparty.platform.domain.SupChargeDetails ;
import com.jsowell.thirdparty.platform.domain.SupEquipChargeStatusInfo ;
import com.jsowell.thirdparty.platform.domain.SupStationInfo ;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory ;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService ;
import com.jsowell.thirdparty.platform.util.Cryptos ;
import com.jsowell.thirdparty.platform.util.HttpRequestUtil ;
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils ;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService ;
import com.yi.business.geo.GeoCodeInfo ;
import com.yi.business.geo.TermRelationTreeCoordinate ;
import org.apache.commons.collections4.CollectionUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.util.* ;
import java.util.concurrent.TimeUnit ;
import java.util.stream.Collectors ;
/**
* 广西省平台Service
*
@@ -11,9 +66,609 @@ import org.springframework.stereotype.Service;
*/
@Service
public class GuangXiPlatformServiceImpl implements ThirdPartyPlatformService {
// 平台类型
private final String thirdPlatformType = ThirdPlatformTypeEnum . GUANG_XI_PLATFORM . getTypeCode ( ) ;
@Autowired
private RedisCache redisCache ;
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService ;
@Autowired
private PileStationInfoService pileStationInfoService ;
@Autowired
private PileBasicInfoService pileBasicInfoService ;
@Autowired
private PileBillingTemplateService pileBillingTemplateService ;
@Autowired
private PileConnectorInfoService pileConnectorInfoService ;
@Autowired
private OrderBasicInfoService orderBasicInfoService ;
@Autowired
private IAreaCodeInfoService areaCodeInfoService ;
@Override
public void afterPropertiesSet ( ) throws Exception {
ThirdPartyPlatformFactory . register ( thirdPlatformType , this ) ;
}
/**
* 查询令牌 query_token
*
* @param dto
* @return
*/
@Override
public Map < String , String > queryToken ( CommonParamsDTO dto ) {
AccessTokenVO vo = new AccessTokenVO ( ) ;
// 0:成功; 1:失败
int succStat = 0 ;
// 0:无; 1:无此对接平台; 2:密钥错误; 3~ 99:自定义
int failReason = 0 ;
String operatorId = dto . getOperatorID ( ) ;
// token缓存key值
String redisKey = operatorId + " _token: " ;
// 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuangXiSecretInfo ( ) ;
if ( thirdPartySecretInfoVO = = null ) {
failReason = 1 ;
succStat = 1 ;
} else {
String ourOperatorSecret = thirdPartySecretInfoVO . getOurOperatorSecret ( ) ;
String dataSecret = thirdPartySecretInfoVO . getOurDataSecret ( ) ;
String dataSecretIv = thirdPartySecretInfoVO . getOurDataSecretIv ( ) ;
// 解密data 获取参数中的OperatorSecret
String decrypt = Cryptos . decrypt ( dto . getData ( ) , dataSecret , dataSecretIv ) ;
String inputOperatorSecret = null ;
if ( StringUtils . isNotBlank ( decrypt ) ) {
inputOperatorSecret = JSON . parseObject ( decrypt ) . getString ( " OperatorSecret " ) ;
}
// 对比密钥
if ( ! StringUtils . equals ( ourOperatorSecret , inputOperatorSecret ) ) {
failReason = 1 ;
succStat = 1 ;
} else {
// 先查缓存中是否有已生成的token
String token = redisCache . getCacheObject ( redisKey ) ;
int expiredTime = ( int ) redisCache . getExpire ( redisKey ) ;
if ( StringUtils . isBlank ( token ) ) {
// 生成token
token = JWTUtils . createToken ( operatorId , ourOperatorSecret , JWTUtils . ttlMillis ) ;
expiredTime = ( int ) ( JWTUtils . ttlMillis / 1000 ) ;
}
vo . setAccessToken ( token ) ;
vo . setTokenAvailableTime ( expiredTime ) ;
// 设置缓存
redisCache . setCacheObject ( redisKey , token , expiredTime , TimeUnit . SECONDS ) ;
}
}
// 组装返回参数
vo . setOperatorID ( operatorId ) ;
vo . setFailReason ( failReason ) ;
vo . setSuccStat ( succStat ) ;
Map < String , String > resultMap = ThirdPartyPlatformUtils . generateResultMapV2 ( vo , thirdPartySecretInfoVO . getOurDataSecret ( )
, thirdPartySecretInfoVO . getOurDataSecretIv ( ) , thirdPartySecretInfoVO . getOurSigSecret ( ) ) ;
return resultMap ;
}
/**
* 查询充电站信息 query_stations_info
*
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map < String , String > queryStationsInfo ( QueryStationInfoDTO dto ) {
int pageNo = dto . getPageNo ( ) = = null ? 1 : dto . getPageNo ( ) ;
int pageSize = dto . getPageSize ( ) = = null ? 50 : dto . getPageSize ( ) ;
dto . setThirdPlatformType ( thirdPlatformType ) ;
PageUtils . startPage ( pageNo , pageSize ) ;
List < ThirdPartyStationInfoVO > stationInfos = pileStationInfoService . selectStationInfosByThirdParty ( dto ) ;
if ( CollectionUtils . isEmpty ( stationInfos ) ) {
// 未查到数据
return null ;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuangXiSecretInfo ( ) ;
PageInfo < ThirdPartyStationInfoVO > pageInfo = new PageInfo < > ( stationInfos ) ;
List < SupStationInfo > resultList = new ArrayList < > ( ) ;
for ( ThirdPartyStationInfoVO pileStationInfo : pageInfo . getList ( ) ) {
SupStationInfo info = SupStationInfo . builder ( )
. stationID ( String . valueOf ( pileStationInfo . getId ( ) ) )
. operatorID ( Constants . OPERATORID_JIANG_SU )
. equipmentOwnerID ( ThirdPartyPlatformUtils . extractEquipmentOwnerID ( pileStationInfo . getOrganizationCode ( ) ) )
. stationName ( pileStationInfo . getStationName ( ) )
. countryCode ( pileStationInfo . getCountryCode ( ) )
// .areaCode()
// .streetCode()
. address ( pileStationInfo . getAddress ( ) )
. serviceTel ( pileStationInfo . getServiceTel ( ) )
. stationType ( Integer . parseInt ( pileStationInfo . getStationType ( ) ) )
. stationStatus ( Integer . parseInt ( pileStationInfo . getStationStatus ( ) ) )
. parkNums ( Integer . parseInt ( pileStationInfo . getParkNums ( ) ) )
. stationLng ( new BigDecimal ( pileStationInfo . getStationLng ( ) ) )
. stationLat ( new BigDecimal ( pileStationInfo . getStationLat ( ) ) )
. construction ( Integer . parseInt ( pileStationInfo . getConstruction ( ) ) )
// .electricityFee()
// .serviceFee()
// .equipmentInfos()
. runDate ( DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD , pileStationInfo . getCreateTime ( ) ) )
. buildDate ( DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD , pileStationInfo . getCreateTime ( ) ) )
. build ( ) ;
JSONObject electricityFee = new JSONObject ( ) ;
JSONObject serviceFee = new JSONObject ( ) ;
// 查询计费模板
List < BillingPriceVO > priceList = pileBillingTemplateService . queryBillingPrice ( String . valueOf ( pileStationInfo . getId ( ) ) ) ;
for ( BillingPriceVO billingPriceVO : priceList ) {
electricityFee . put ( billingPriceVO . getStartTime ( ) + " :00- " + billingPriceVO . getEndTime ( ) + " :00 " , billingPriceVO . getElectricityPrice ( ) ) ;
serviceFee . put ( billingPriceVO . getStartTime ( ) + " :00- " + billingPriceVO . getEndTime ( ) + " :00 " , billingPriceVO . getServicePrice ( ) ) ;
}
info . setElectricityFee ( electricityFee . toJSONString ( ) ) ;
info . setServiceFee ( serviceFee . toJSONString ( ) ) ;
// AreaCode
String areaCode = pileStationInfo . getAreaCode ( ) ; // 330000,330200,330213
// 根据逗号分组
String [ ] split = StringUtils . split ( areaCode , " , " ) ;
// 只取最后一部分 330213
String subAreaCode = split [ split . length - 1 ] ;
info . setAreaCode ( subAreaCode ) ;
List < EquipmentInfo > pileList = pileBasicInfoService . getPileListForLianLian ( String . valueOf ( pileStationInfo . getId ( ) ) ) ;
if ( CollectionUtils . isNotEmpty ( pileList ) ) {
info . setEquipmentInfos ( pileList ) ; // 充电设备信息列表
}
// areaCodeCountryside
GeoCodeInfo geoCode = TermRelationTreeCoordinate . completeGeoCode ( pileStationInfo . getAddress ( ) ) ;
if ( geoCode = = null ) {
// String areaCodeCountryside = geoCode.getCounty_code();
info . setStreetCode ( " 123456789101 " ) ;
} else {
AreaCodeInfo areaCodeInfo = new AreaCodeInfo ( ) ;
if ( StringUtils . isNotBlank ( geoCode . getTownName ( ) ) ) {
String townName = geoCode . getTownName ( ) ;
areaCodeInfo . setName ( townName ) ;
} else {
String countyName = geoCode . getCountyName ( ) ;
areaCodeInfo . setName ( countyName ) ;
}
List < AreaCodeInfo > areaCodeInfoList = areaCodeInfoService . selectAreaCodeInfoList ( areaCodeInfo ) ;
info . setStreetCode ( String . valueOf ( areaCodeInfoList . get ( 0 ) . getAreaCode ( ) ) ) ;
}
resultList . add ( info ) ;
}
Map < String , Object > map = new LinkedHashMap < > ( ) ;
map . put ( " PageNo " , pageInfo . getPageNum ( ) ) ;
map . put ( " PageCount " , pageInfo . getPages ( ) ) ;
map . put ( " ItemSize " , pageInfo . getTotal ( ) ) ;
map . put ( " StationInfos " , resultList ) ;
Map < String , String > resultMap = ThirdPartyPlatformUtils . generateResultMapV2 ( map , thirdPartySecretInfoVO . getOurDataSecret ( ) ,
thirdPartySecretInfoVO . getOurDataSecretIv ( ) , thirdPartySecretInfoVO . getTheirSigSecret ( ) ) ;
return resultMap ;
}
/**
* 设备接口状态查询接口 query_station_status
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map < String , String > queryStationStatus ( QueryStationInfoDTO dto ) {
List < String > stationIds = dto . getStationIds ( ) ;
List < StationStatusInfo > stationStatusInfos = new ArrayList < > ( ) ;
List < Object > connectorStatusInfos = new ArrayList < > ( ) ;
// 查询密钥信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuangXiSecretInfo ( ) ;
// 根据站点idList查询枪口列表
List < ConnectorInfoVO > list = pileConnectorInfoService . batchSelectConnectorList ( stationIds ) ;
// 根据站点id分组
Map < String , List < ConnectorInfoVO > > collect = list . stream ( )
. collect ( Collectors . groupingBy ( ConnectorInfoVO : : getStationId ) ) ;
// 封装参数
for ( Map . Entry < String , List < ConnectorInfoVO > > entry : collect . entrySet ( ) ) {
String stationId = entry . getKey ( ) ;
List < ConnectorInfoVO > voList = entry . getValue ( ) ;
StationStatusInfo stationStatusInfo = new StationStatusInfo ( ) ;
stationStatusInfo . setStationId ( stationId ) ;
stationStatusInfo . setStationStatus ( 50 ) ; // 50-正常使用
ConnectorStatusInfo connectorStatusInfo ;
for ( ConnectorInfoVO connectorInfoVO : voList ) {
connectorStatusInfo = ConnectorStatusInfo . builder ( )
. connectorID ( connectorInfoVO . getPileConnectorCode ( ) )
. status ( Integer . parseInt ( connectorInfoVO . getConnectorStatus ( ) ) )
. build ( ) ;
connectorStatusInfos . add ( connectorStatusInfo ) ;
}
stationStatusInfo . setConnectorStatusInfos ( connectorStatusInfos ) ;
stationStatusInfos . add ( stationStatusInfo ) ;
}
Map < String , Object > map = new LinkedHashMap < > ( ) ;
map . put ( " StationStatusInfos " , stationStatusInfos ) ;
Map < String , String > resultMap = ThirdPartyPlatformUtils . generateResultMapV2 ( map , thirdPartySecretInfoVO . getOurDataSecret ( ) ,
thirdPartySecretInfoVO . getOurDataSecretIv ( ) , thirdPartySecretInfoVO . getTheirSigSecret ( ) ) ;
return resultMap ;
}
/**
* 推送设备状态变化接口 notification_stationStatus
* @param stationId 站点id
* @param pileConnectorCode 充电桩枪口编号
* @param status
* @param secretInfoVO
* @return
*/
@Override
public String notificationStationStatus ( String stationId , String pileConnectorCode , String status , ThirdPartySecretInfoVO secretInfoVO ) {
// 查询相关配置信息
ThirdPartySecretInfoVO ganSuSecretInfo = getGuangXiSecretInfo ( ) ;
String operatorId = Constants . OPERATORID_JIANG_SU ;
String operatorSecret = ganSuSecretInfo . getTheirOperatorSecret ( ) ;
String signSecret = ganSuSecretInfo . getTheirSigSecret ( ) ;
String dataSecret = ganSuSecretInfo . getTheirDataSecret ( ) ;
String dataSecretIv = ganSuSecretInfo . getTheirDataSecretIv ( ) ;
String urlAddress = ganSuSecretInfo . getTheirUrlPrefix ( ) ;
String url = urlAddress + BusinessInformationExchangeEnum . NOTIFICATION_STATION_STATUS . getValue ( ) ;
ConnectorStatusInfo info = ConnectorStatusInfo . builder ( )
. connectorID ( pileConnectorCode )
. status ( Integer . parseInt ( status ) )
. build ( ) ;
// 调用联联平台接口
JSONObject json = new JSONObject ( ) ;
json . put ( " DataType " , Constants . ZERO ) ;
json . put ( " ConnectorStatusInfo " , info ) ;
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 ;
}
/**
* 查询统计信息接口 query_station_stats
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map < String , String > queryStationStats ( QueryStationInfoDTO dto ) {
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuangXiSecretInfo ( ) ;
// 根据站点id 查出这段时间的充电量
List < AccumulativeInfoVO > list = orderBasicInfoService . getAccumulativeInfoForLianLian ( dto ) ;
if ( CollectionUtils . isEmpty ( list ) ) {
return null ;
}
// 根据充电桩编号分组 key=充电桩编号
Map < String , List < AccumulativeInfoVO > > pileMap = list . stream ( )
. collect ( Collectors . groupingBy ( AccumulativeInfoVO : : getPileSn ) ) ;
// 存放所有充电桩设备
List < EquipmentStatsInfo > equipmentStatsInfoList = Lists . newArrayList ( ) ;
// 站点用电量
BigDecimal stationElectricity = BigDecimal . ZERO ;
int stationChargingTime = Constants . zero ;
// 用于记录桩充电量 在循环每个枪口的时候初始化
BigDecimal pileElec ;
// 桩充电次数
int pileChargingNum ;
// 桩充电时长
int pileChargingTime ;
for ( String pileSn : pileMap . keySet ( ) ) {
// 该充电桩下 所有枪口的用电数据
List < AccumulativeInfoVO > accumulativeInfoVOS = pileMap . get ( pileSn ) ;
if ( CollectionUtils . isEmpty ( accumulativeInfoVOS ) ) {
continue ;
}
// 存放充电桩用电量
pileElec = BigDecimal . ZERO ;
// 充电桩充电次数
pileChargingNum = Constants . zero ;
// 充电桩充电时长
pileChargingTime = Constants . zero ;
// key=枪口编号 value 该枪口的用电数据
Map < String , List < AccumulativeInfoVO > > collect = accumulativeInfoVOS . stream ( )
. collect ( Collectors . groupingBy ( AccumulativeInfoVO : : getPileConnectorCode ) ) ;
List < ConnectorStatsInfo > connectorStatsInfos = Lists . newArrayList ( ) ;
for ( Map . Entry < String , List < AccumulativeInfoVO > > entry : collect . entrySet ( ) ) {
String pileConnectorCode = entry . getKey ( ) ;
List < AccumulativeInfoVO > value = entry . getValue ( ) ;
// 枪口用电量求和
BigDecimal connectorElec = value . stream ( )
. map ( AccumulativeInfoVO : : getConnectorElectricity )
. map ( BigDecimal : : new )
. reduce ( BigDecimal . ZERO , BigDecimal : : add ) ;
// 充电时长求和
BigDecimal chargingTime = value . stream ( )
. map ( AccumulativeInfoVO : : getChargingTime )
. map ( BigDecimal : : new )
. reduce ( BigDecimal . ZERO , BigDecimal : : add ) ;
// 充电次数
long chargingNumLong = accumulativeInfoVOS . stream ( )
. map ( x - > x . getPileConnectorCode ( ) . equals ( pileConnectorCode ) )
. count ( ) ;
int chargingNum = Integer . parseInt ( String . valueOf ( chargingNumLong ) ) ;
connectorStatsInfos . add (
ConnectorStatsInfo . builder ( )
. connectorID ( pileConnectorCode )
. connectorElectricity ( connectorElec )
. connectorDuration ( chargingTime . intValue ( ) )
. connectorNum ( chargingNum )
. build ( )
) ;
// 充电桩电量为枪口用电量累计
pileElec = pileElec . add ( connectorElec ) ;
// 充电桩充电次数为枪口充电次数累计
pileChargingNum + = chargingNum ;
// 充电时长
pileChargingTime + = chargingTime . intValue ( ) ;
}
EquipmentStatsInfo build = EquipmentStatsInfo . builder ( )
. equipmentID ( pileSn )
. equipmentElectricity ( pileElec )
. connectorDuration ( pileChargingTime )
. connectorNum ( pileChargingNum )
. connectorStatsInfos ( connectorStatsInfos )
. build ( ) ;
equipmentStatsInfoList . add ( build ) ;
// 所有充电桩用电量之和
stationElectricity = stationElectricity . add ( pileElec ) ;
// 充电时长
stationChargingTime + = pileChargingTime ;
}
StationStatsInfo stationStatsInfo = StationStatsInfo . builder ( )
. stationID ( dto . getStationID ( ) )
. startTime ( dto . getStartTime ( ) )
. endTime ( dto . getEndTime ( ) )
. stationElectricity ( stationElectricity )
. connectorDuration ( stationChargingTime )
. connectorNum ( list . size ( ) )
. equipmentStatsInfos ( equipmentStatsInfoList ) // 设备列表
. build ( ) ;
Map < String , Object > map = new LinkedHashMap < > ( ) ;
map . put ( " StationStats " , stationStatsInfo ) ;
Map < String , String > resultMap = ThirdPartyPlatformUtils . generateResultMapV2 ( map , thirdPartySecretInfoVO . getOurDataSecret ( ) ,
thirdPartySecretInfoVO . getOurDataSecretIv ( ) , thirdPartySecretInfoVO . getTheirSigSecret ( ) ) ;
return resultMap ;
}
/**
* 推送已完成订单信息接口 notification_charge_order_info
* @param orderCode
* @param secretInfoVO
* @return
*/
@Override
public String notificationChargeOrderInfo ( String orderCode , ThirdPartySecretInfoVO secretInfoVO ) {
// 根据订单号查询出信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService . getOrderInfoByOrderCode ( orderCode ) ;
if ( orderBasicInfo = = null ) {
return null ;
}
String operatorId = Constants . OPERATORID_JIANG_SU ;
String operatorSecret = secretInfoVO . getTheirOperatorSecret ( ) ;
String signSecret = secretInfoVO . getTheirSigSecret ( ) ;
String dataSecret = secretInfoVO . getTheirDataSecret ( ) ;
String dataSecretIv = secretInfoVO . getTheirDataSecretIv ( ) ;
String urlAddress = secretInfoVO . getTheirUrlPrefix ( ) ;
// 推送地址
String url = urlAddress + BusinessInformationExchangeEnum . NOTIFICATION_CHARGE_ORDER_INFO . getValue ( ) ;
// 根据订单号查询订单详情
OrderDetail orderDetail = orderBasicInfoService . getOrderDetailByOrderCode ( orderCode ) ;
if ( orderDetail = = null ) {
return null ;
}
ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo . builder ( )
. startChargeSeq ( orderCode )
// .startChargeType()
. connectorId ( orderBasicInfo . getPileConnectorCode ( ) )
. startTime ( DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , orderBasicInfo . getChargeStartTime ( ) ) )
. endTime ( DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , orderBasicInfo . getChargeEndTime ( ) ) )
. totalPower ( orderDetail . getTotalUsedElectricity ( ) )
// .totalElecMoney(orderDetail.getTotalElectricityAmount())
// .totalSeviceMoney(orderDetail.getTotalServiceAmount())
. elecMoney ( orderDetail . getTotalElectricityAmount ( ) )
. seviceMoney ( orderDetail . getTotalServiceAmount ( ) )
. totalMoney ( orderDetail . getTotalOrderAmount ( ) )
. build ( ) ;
// startChargeType
String startMode = orderBasicInfo . getStartMode ( ) ;
if ( StringUtils . equals ( StartModeEnum . AUTH_CARD . getValue ( ) , startMode )
| | StringUtils . equals ( StartModeEnum . OFFLINE_CARD . getValue ( ) , startMode ) ) {
chargeOrderInfo . setStartChargeType ( 3 ) ; // 3-卡启动
} else {
chargeOrderInfo . setStartChargeType ( Constants . one ) ;
}
// 获取令牌
String token = getToken ( urlAddress , operatorId , operatorSecret , dataSecretIv , signSecret , dataSecret ) ;
if ( StringUtils . isBlank ( token ) ) {
return null ;
}
// 调用平台接口
String jsonString = JSON . toJSONString ( chargeOrderInfo ) ;
String result = HttpRequestUtil . sendPost ( token , jsonString , url , dataSecret , dataSecretIv , operatorId , signSecret ) ;
return result ;
}
/**
* 查询已完成订单列表信息接口 query_finish_orders
* @param dto
* @return
*/
@Override
public Map < String , String > queryFinishOrders ( QueryStartChargeDTO dto ) {
int pageNo = dto . getPageNo ( ) = = null ? 1 : dto . getPageNo ( ) ;
int pageSize = dto . getPageSize ( ) = = null ? 10 : dto . getPageSize ( ) ;
List < ChargeOrderInfo > orderInfos = new ArrayList < > ( ) ;
PageUtils . startPage ( pageNo , pageSize ) ;
List < OrderVO > orderVOS = orderBasicInfoService . selectThirdPartyOrderList ( dto ) ;
PageInfo < OrderVO > pageInfo = new PageInfo < > ( orderVOS ) ;
for ( OrderVO orderVO : pageInfo . getList ( ) ) {
ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo . builder ( )
. startChargeSeq ( orderVO . getOrderCode ( ) )
// .startChargeType()
. connectorId ( orderVO . getPileConnectorCode ( ) )
. startTime ( orderVO . getStartTime ( ) )
. endTime ( orderVO . getStartTime ( ) )
. totalPower ( new BigDecimal ( orderVO . getTotalPower ( ) ) )
. elecMoney ( orderVO . getTotalElectricityAmount ( ) )
. seviceMoney ( orderVO . getTotalServiceAmount ( ) )
. totalMoney ( orderVO . getOrderAmount ( ) )
. build ( ) ;
// startChargeType
String startMode = orderVO . getStartMode ( ) ;
if ( StringUtils . equals ( StartModeEnum . AUTH_CARD . getValue ( ) , startMode )
| | StringUtils . equals ( StartModeEnum . OFFLINE_CARD . getValue ( ) , startMode ) ) {
chargeOrderInfo . setStartChargeType ( 3 ) ; // 3-卡启动
} else {
chargeOrderInfo . setStartChargeType ( Constants . one ) ;
}
orderInfos . add ( chargeOrderInfo ) ;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuangXiSecretInfo ( ) ;
Map < String , Object > map = new LinkedHashMap < > ( ) ;
map . put ( " PageNo " , pageInfo . getPageNum ( ) ) ;
map . put ( " PageCount " , pageInfo . getPages ( ) ) ;
map . put ( " ItemSize " , pageInfo . getTotal ( ) ) ;
map . put ( " ChargeOrders " , orderInfos ) ;
map . put ( " LastQueryTime " , dto . getLastQueryTime ( ) ) ;
map . put ( " LastQueryEndTime " , dto . getLastQueryEndTime ( ) ) ;
Map < String , String > resultMap = ThirdPartyPlatformUtils . generateResultMapV2 ( map , thirdPartySecretInfoVO . getOurDataSecret ( ) ,
thirdPartySecretInfoVO . getOurDataSecretIv ( ) , thirdPartySecretInfoVO . getTheirSigSecret ( ) ) ;
return resultMap ;
}
}
/**
* 推送充电状态接口 notification_equip_charge_status
* @param orderCode 订单编号
* @return
*/
@Override
public String notificationEquipChargeStatus ( String orderCode ) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService . getOrderInfoByOrderCode ( orderCode ) ;
// 查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuangXiSecretInfo ( ) ;
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 ( ) ;
// 查询枪口实时状态
List < RealTimeMonitorData > chargingRealTimeData = orderBasicInfoService . getChargingRealTimeData ( orderInfo . getTransactionCode ( ) ) ;
RealTimeMonitorData realTimeMonitorData ;
if ( CollectionUtils . isEmpty ( chargingRealTimeData ) ) {
realTimeMonitorData = RealTimeMonitorData . builder ( )
. chargingDegree ( Constants . ZERO )
. connectorStatus ( " 3 " )
. build ( ) ;
chargingRealTimeData . add ( realTimeMonitorData ) ;
} else {
realTimeMonitorData = chargingRealTimeData . get ( 0 ) ;
}
// 查询枪口状态
PileConnectorInfoVO info = pileConnectorInfoService . getPileConnectorInfoByConnectorCode ( orderInfo . getPileConnectorCode ( ) ) ;
if ( Objects . isNull ( info ) ) {
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 " ;
}
BigDecimal current = realTimeMonitorData . getOutputCurrent ( ) = = null ? BigDecimal . ZERO : info . getCurrent ( ) ;
BigDecimal voltage = realTimeMonitorData . getOutputVoltage ( ) = = null ? BigDecimal . ZERO : info . getVoltage ( ) ;
String soc = realTimeMonitorData . getSOC ( ) = = null ? Constants . ZERO : info . getSOC ( ) ;
String dateTime = DateUtils . getDateTime ( ) ;
SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo . builder ( )
. startChargeSeq ( orderInfo . getOrderCode ( ) )
. startChargeSeqStat ( Integer . parseInt ( orderStatus ) )
. connectorID ( orderInfo . getPileConnectorCode ( ) )
. connectorStatus ( Integer . parseInt ( realTimeMonitorData . getConnectorStatus ( ) ) ) // 3-充电中
. currentA ( current . setScale ( 1 , RoundingMode . HALF_UP ) )
. voltageA ( voltage . setScale ( 1 , RoundingMode . HALF_UP ) )
. soc ( new BigDecimal ( soc ) )
. startTime ( DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , orderInfo . getChargeStartTime ( ) ) )
. endTime ( dateTime )
. totalPower ( new BigDecimal ( realTimeMonitorData . getChargingDegree ( ) ) )
. build ( ) ;
String url = urlAddress + BusinessInformationExchangeEnum . NOTIFICATION_EQUIP_CHARGE_STATUS . getValue ( ) ;
// 调用平台接口
String jsonString = JSON . toJSONString ( supEquipChargeStatusInfo ) ;
// 获取令牌
String token = getToken ( urlAddress , operatorId , operatorSecret , dataSecretIv , signSecret , dataSecret ) ;
String result = HttpRequestUtil . sendPost ( token , jsonString , url , dataSecret , dataSecretIv , operatorId , signSecret ) ;
return result ;
}
/**
* 获取广西平台密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getGuangXiSecretInfo ( ) {
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService . queryByThirdPlatformType ( thirdPlatformType ) ;
if ( thirdPartySecretInfoVO = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_SELECT_INFO_IS_NULL ) ;
}
thirdPartySecretInfoVO . setOurOperatorId ( Constants . OPERATORID_JIANG_SU ) ;
return thirdPartySecretInfoVO ;
}
}