package com.zsElectric.boot.charging.service.impl; import cn.hutool.core.bean.BeanUtil; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.zsElectric.boot.charging.dto.StartChargingRequestDTO; import com.zsElectric.boot.charging.dto.StartChargingResponseVO; import com.zsElectric.boot.charging.service.ChargingBusinessService; import com.zsElectric.boot.charging.vo.*; import com.zsElectric.boot.common.constant.ConnectivityConstants; import com.zsElectric.boot.common.util.electric.ChargingUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; @Slf4j @Service @RequiredArgsConstructor public class ChargingBusinessServiceImpl implements ChargingBusinessService { private final ChargingUtil chargingUtil; @Override public ChargingPricePolicyVO queryEquipBusinessPolicy(String equipBizSeq, String connectorID){ Map queryTokenParms = new HashMap<>(); queryTokenParms.put("equipBizSeq", equipBizSeq); queryTokenParms.put("connectorID", connectorID); log.info("查询设备价格策略请求参数:{}", queryTokenParms); JsonObject jsonObject = chargingUtil.chargingRequest(ConnectivityConstants.TEST_DOMAIN + ConnectivityConstants.QUERY_EQUIP_BUSINESS_POLICY, queryTokenParms, false); log.info("查询设备价格策略返回结果:{}", jsonObject); JsonObject responseDecode = chargingUtil.responseDecode(jsonObject); log.info("查询设备价格策略返回结果解密后:{}", responseDecode); return new Gson().fromJson(responseDecode, ChargingPricePolicyVO.class); } @Override public EquipmentAuthResponseVO queryEquipAuth(String EquipAuthSeq, String ConnectorID) { Map queryTokenParms = new HashMap<>(); queryTokenParms.put("EquipAuthSeq", EquipAuthSeq); queryTokenParms.put("ConnectorID", ConnectorID); log.info("查询设备认证请求参数:{}", queryTokenParms); JsonObject jsonObject = chargingUtil.chargingRequest(ConnectivityConstants.TEST_DOMAIN + ConnectivityConstants.QUERY_EQUIP_AUTH, queryTokenParms, false); log.info("查询设备认证返回结果:{}", jsonObject); JsonObject responseDecode = chargingUtil.responseDecode(jsonObject); log.info("查询设备认证返回结果解密后:{}", responseDecode); return new Gson().fromJson(responseDecode, EquipmentAuthResponseVO.class); } @Override public QueryStationsInfoVO queryStationsInfo(String LastQueryTime, Integer PageNo, Integer PageSize){ Map queryParms = new HashMap<>(); queryParms.put("LastQueryTime", LastQueryTime); queryParms.put("PageNo", PageNo); queryParms.put("PageSize", PageSize); log.info("查询充电站信息请求参数:{}", queryParms); JsonObject jsonObject = chargingUtil.chargingRequest(ConnectivityConstants.TEST_DOMAIN + ConnectivityConstants.QUERY_STATIONS_INFO, queryParms, true); log.info("查询充电站信息返回结果:{}", jsonObject); JsonObject responseDecode = chargingUtil.responseDecode(jsonObject); log.info("查询充电站信息返回结果解密后:{}", responseDecode); return new Gson().fromJson(responseDecode, QueryStationsInfoVO.class); } @Override public QueryStationStatusVO queryStationStatus(List stationIDs){ Map queryParms = new HashMap<>(); queryParms.put("StationIDs", stationIDs); log.info("设备接口状态查询请求参数:{}", queryParms); JsonObject jsonObject = chargingUtil.chargingRequest(ConnectivityConstants.TEST_DOMAIN + ConnectivityConstants.QUERY_STATION_STATUS, queryParms, true); log.info("设备接口状态查询返回结果:{}", jsonObject); JsonObject responseDecode = chargingUtil.responseDecode(jsonObject); log.info("设备接口状态查询返回结果解密后:{}", responseDecode); return new Gson().fromJson(responseDecode, QueryStationStatusVO.class); } @Override public StartChargingResponseVO startCharging(StartChargingRequestDTO requestDTO){ Map stringObjectMap = BeanUtil.beanToMap(requestDTO); log.info("设备接口状态查询请求参数:{}", stringObjectMap); JsonObject jsonObject = chargingUtil.chargingRequest(ConnectivityConstants.TEST_DOMAIN + ConnectivityConstants.QUERY_START_CHARGE, stringObjectMap, true); log.info("设备接口状态查询返回结果:{}", jsonObject); JsonObject responseDecode = chargingUtil.responseDecode(jsonObject); log.info("设备接口状态查询返回结果解密后:{}", responseDecode); return new Gson().fromJson(responseDecode, StartChargingResponseVO.class); } @Override public ChargingStatusQueryResponseVO queryChargingStatus(String StartChargeSeq) { Map queryParms = new HashMap<>(); queryParms.put("StartChargeSeq", StartChargeSeq); log.info("查询充电订单状态请求参数:{}", queryParms); JsonObject jsonObject = chargingUtil.chargingRequest(ConnectivityConstants.TEST_DOMAIN + ConnectivityConstants.QUERY_EQUIP_CHARGE_STATUS, queryParms, true); log.info("查询充电订单状态返回结果:{}", jsonObject); JsonObject responseDecode = chargingUtil.responseDecode(jsonObject); log.info("查询充电订单状态返回结果解密后:{}", responseDecode); return new Gson().fromJson(responseDecode, ChargingStatusQueryResponseVO.class); } @Override public StopChargingOperationResponseVO stopCharging(String StartChargeSeq, String ConnectorID) { Map queryTokenParms = new HashMap<>(); queryTokenParms.put("StartChargeSeq", StartChargeSeq); queryTokenParms.put("ConnectorID", ConnectorID); log.info("停止充电请求参数:{}", queryTokenParms); JsonObject jsonObject = chargingUtil.chargingRequest(ConnectivityConstants.TEST_DOMAIN + ConnectivityConstants.QUERY_STOP_CHARGE, queryTokenParms, true); log.info("停止充电返回结果:{}", jsonObject); JsonObject responseDecode = chargingUtil.responseDecode(jsonObject); log.info("停止充电返回结果解密后:{}", responseDecode); return new Gson().fromJson(responseDecode, StopChargingOperationResponseVO.class); } }