From a4b002ca509f2fd3cb1afd233caedbf01afa3343 Mon Sep 17 00:00:00 2001 From: "YAS\\29473" <2947326429@qq.com> Date: Sat, 23 Nov 2024 11:46:45 +0800 Subject: [PATCH] update --- .../impl/GuiZhouPlatformServiceImpl.java | 105 +- .../YongChengbochePlatfromServicelmpl.java | 909 ++++++++++++++++++ 2 files changed, 940 insertions(+), 74 deletions(-) create mode 100644 jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServicelmpl.java diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuiZhouPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuiZhouPlatformServiceImpl.java index ceb5b3976..407991493 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuiZhouPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuiZhouPlatformServiceImpl.java @@ -10,15 +10,13 @@ import com.google.common.collect.Maps; import com.jsowell.common.constant.Constants; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.enums.lianlian.StationPaymentEnum; +import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.BillingTimeTypeEnum; 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.DateUtils; -import com.jsowell.common.util.JWTUtils; -import com.jsowell.common.util.PageUtils; -import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.*; import com.jsowell.pile.domain.*; import com.jsowell.pile.dto.PushRealTimeInfoDTO; import com.jsowell.pile.dto.QueryConnectorListDTO; @@ -32,18 +30,18 @@ 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.base.ThirdPartyStationRelationVO; import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO; import com.jsowell.pile.vo.web.PileConnectorInfoVO; import com.jsowell.pile.vo.web.PileMerchantInfoVO; +import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.lianlian.domain.ConnectorChargeStatusInfo; import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo; import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; import com.jsowell.thirdparty.platform.domain.*; import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory; -import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; +import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; import com.jsowell.thirdparty.platform.util.Cryptos; import com.jsowell.thirdparty.platform.util.GBSignUtils; import com.jsowell.thirdparty.platform.util.HttpRequestUtil; @@ -212,11 +210,6 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService { // 未查到数据 return null; } - // ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - // ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); - // if (thirdPartySecretInfoVO == null) { - // return null; - // } ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuiZhouPlatformSecretInfo(); PageInfo pageInfo = new PageInfo<>(stationInfos); @@ -427,8 +420,6 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService { info.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())); info.setEndTime(DateUtils.getDateTime()); // 本次采样时间 info.setTotalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())); // 累计充电量 - // info.setElecMoney(); // 累计电费 - // info.setSeviceMoney(); // 累计服务费 info.setTotalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount())); ConnectorStatusInfos.add(info); @@ -470,51 +461,41 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService { return resultMap; } + /** + * 设备状态变化推送 notification_stationStatus + * 推送充电设备接口状态信息 supervise_notification_station_status + * + * @param dto + * @throws UnsupportedOperationException 未实现异常 + */ @Override public String notificationStationStatus(PushRealTimeInfoDTO dto) { - String pileConnectorCode = dto.getPileConnectorCode(); String status = dto.getStatus(); - ThirdPartySecretInfoVO xiaPlatformSecretInfo = getGuiZhouPlatformSecretInfo(); - // 查询充电枪口状态 - PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); - if (Objects.isNull(connectorInfo)) { - throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); - } + String pileConnectorCode = dto.getPileConnectorCode(); - String merchantId = connectorInfo.getMerchantId(); - MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId); - if (Objects.isNull(merchantInfoVO)) { - throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); - } + // 查出该桩所属哪个站点 + // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + String pileSn = YKCUtils.getPileSn(pileConnectorCode); + PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn); + // 通过站点id查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGuiZhouPlatformSecretInfo(); - SupConnectorStatusInfo info = SupConnectorStatusInfo.builder() - .operatorID(Constants.JSOWELL_OPERATORID) - .equipmentOwnerID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode())) - .stationID(connectorInfo.getStationId()) - .equipmentID(connectorInfo.getPileSn()) + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + 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_STATION_STATUS.getValue(); + ConnectorStatusInfo info = ConnectorStatusInfo.builder() .connectorID(pileConnectorCode) - .equipmentClassification(Constants.ONE) .status(Integer.parseInt(status)) - .statusDesc(PileConnectorDataBaseStatusEnum.getStatusDescription(status)) - .parkStatus(Constants.zero) - .lockStatus(Constants.zero) - .batteryStatus(Constants.ZERO) - .batteryPackID("") - .lastChangeTime(DateUtils.getDateTime()) .build(); - // 调用联联平台接口 - String operatorId = xiaPlatformSecretInfo.getOurOperatorId(); - String operatorSecret = xiaPlatformSecretInfo.getTheirOperatorSecret(); - String signSecret = xiaPlatformSecretInfo.getTheirSigSecret(); - String dataSecret = xiaPlatformSecretInfo.getTheirDataSecret(); - String dataSecretIv = xiaPlatformSecretInfo.getTheirDataSecretIv(); - String urlAddress = xiaPlatformSecretInfo.getTheirUrlPrefix(); - String url = urlAddress + "supervise_notification_station_status"; - - // JSONObject json = new JSONObject(); - // json.put("ConnectorStatusInfo", info); - String jsonString = JSON.toJSONString(info); + JSONObject json = new JSONObject(); + 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); @@ -661,11 +642,6 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService { // 根据订单号查询出信息 OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - // 通过站点id查询相关配置信息 - // ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(orderBasicInfo.getStationId()); - // if (relationInfo == null) { - // return null; - // } ThirdPartySecretInfoVO guiZhouPlatformSecretInfo = getGuiZhouPlatformSecretInfo(); OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); @@ -793,12 +769,6 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService { supStationPowerInfo.setStationRealTimePower(stationPower); } list.add(supStationPowerInfo); - - // 获取推送配置密钥信息 - // ThirdPartyStationRelationVO settingInfo = getGuizhouSettingInfo(); - // if (settingInfo == null) { - // return null; - // } ThirdPartySecretInfoVO guiZhouPlatformSecretInfo = getGuiZhouPlatformSecretInfo(); String operatorId = guiZhouPlatformSecretInfo.getTheirOperatorId(); @@ -823,20 +793,7 @@ public class GuiZhouPlatformServiceImpl implements ThirdPartyPlatformService { } /** - * 获取贵州平台配置密钥信息 - * - * @return - */ - // private ThirdPartyStationRelationVO getGuizhouSettingInfo() { - // // 通过第三方平台类型查询相关配置信息 - // ThirdPartyStationRelation relation = new ThirdPartyStationRelation(); - // relation.setThirdPartyType(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode()); - // ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation); - // return relationInfo; - // } - - /** - * 获取甘肃省平台配置密钥信息 + * 获取贵州省平台配置密钥信息 * @return */ private ThirdPartySecretInfoVO getGuiZhouPlatformSecretInfo() { diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServicelmpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServicelmpl.java new file mode 100644 index 000000000..429764302 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServicelmpl.java @@ -0,0 +1,909 @@ +package com.jsowell.thirdparty.platform.service.impl; + +import cn.hutool.core.util.PageUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; +import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.BillingTimeTypeEnum; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +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.ykcCommond.StartChargingCommand; +import com.jsowell.pile.dto.*; +import com.jsowell.pile.service.*; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.thirdparty.EquipmentInfo; +import com.jsowell.pile.util.MerchantUtils; +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.base.ThirdPartyStationRelationVO; +import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +import com.jsowell.pile.vo.web.PileMerchantInfoVO; +import com.jsowell.pile.vo.web.PileStationVO; +import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO; +import com.jsowell.thirdparty.lianlian.domain.ConnectorChargeStatusInfo; +import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; +import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo; +import com.jsowell.thirdparty.lianlian.vo.*; +import com.jsowell.thirdparty.platform.domain.*; +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 org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 甬城泊车 + */ +@Service +public class YongChengbochePlatfromServicelmpl implements ThirdPartyPlatformService { + private final String thirdPlatformType = ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getTypeCode(); + + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + @Autowired + private PileMerchantInfoService pileMerchantInfoService; + + @Autowired + private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private PileBillingTemplateService pileBillingTemplateService; + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private ThirdPartyStationRelationService thirdPartyStationRelationService; + + @Override + public void afterPropertiesSet() throws Exception { + ThirdPartyPlatformFactory.register(thirdPlatformType, this); + } + + /** + * query_token 获取token,提供给第三方平台使用 + * + * @param dto + * @return + */ + @Override + public Map queryToken(CommonParamsDTO dto) { + AccessTokenVO vo = new AccessTokenVO(); + // 0:成功;1:失败 + int succStat = 0; + // 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义 + int failReason = 0; + + String operatorId = dto.getPlatformID(); + // 通过operatorId 查出 operatorSecret + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId); + if (thirdPartySecretInfoVO == null) { + failReason = 1; + succStat = 1; + } else { + String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + 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("PlatformSecret"); + } + // 对比密钥 + if (!StringUtils.equals(theirOperatorSecret, inputOperatorSecret)) { + failReason = 1; + succStat = 1; + } else { + // 生成token + String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis); + vo.setAccessToken(token); + vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); + } + } + // 组装返回参数 + vo.setPlatformId(operatorId); + vo.setFailReason(failReason); + vo.setSuccStat(succStat); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); + return resultMap; + } + + /** + * 查询充电站信息 query_stations_info + * supervise_query_operator_info + * 此接口用于查询对接平台的充电站的信息 + * + * @param dto 查询站点信息dto + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public Map queryStationsInfo(QueryStationInfoDTO dto) { + int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); + int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); + + PageUtils.startPage(pageNo, pageSize); + List stationInfos = pileStationInfoService.getStationInfosByThirdParty(dto); + if (CollectionUtils.isEmpty(stationInfos)) { + // 未查到数据 + return null; + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); + + PageInfo pageInfo = new PageInfo<>(stationInfos); + List resultList = new ArrayList<>(); + for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { + SupStationInfo stationInfo = new SupStationInfo(); + String stationId = String.valueOf(pileStationInfo.getId()); + stationInfo.setStationID(stationId); + // MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(pileStationInfo.getMerchantId())); + stationInfo.setOperatorID(Constants.OPERATORID_LIANLIAN); // 组织机构代码 + stationInfo.setEquipmentOwnerID(String.valueOf(pileStationInfo.getMerchantId())); + stationInfo.setStationName(pileStationInfo.getStationName()); + stationInfo.setIsAloneApply(Integer.valueOf(pileStationInfo.getAloneApply())); + stationInfo.setIsPublicParkingLot(Integer.valueOf(pileStationInfo.getPublicParking())); + stationInfo.setCountryCode(pileStationInfo.getCountryCode()); + stationInfo.setAreaCode(pileStationInfo.getAreaCode()); + stationInfo.setAddress(pileStationInfo.getAddress()); + stationInfo.setServiceTel(pileStationInfo.getStationTel()); + stationInfo.setStationType(Integer.valueOf(pileStationInfo.getStationType())); + stationInfo.setParkNums(Integer.valueOf(pileStationInfo.getParkNums())); + stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng())); + stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat())); + stationInfo.setConstruction(Integer.valueOf(pileStationInfo.getConstruction())); + stationInfo.setOpenAllDay(Integer.valueOf(pileStationInfo.getOpenAllDay())); + // stationInfo.setMinElectricityPrice(pileStationInfo); // 最低充电电费率 + // stationInfo.setElectricityFee(); // 电费 xx元/度 + // stationInfo.setServiceFee(); // 服务费 xx元/度 + stationInfo.setParkFree(Integer.valueOf(pileStationInfo.getParkFree())); + stationInfo.setPayment(pileStationInfo.getPayment()); + stationInfo.setSupportOrder(Integer.valueOf(pileStationInfo.getSupportOrder())); + // stationInfo.setParkFeeType(pileStationInfo); // 停车收费类型 + stationInfo.setToiletFlag(Integer.valueOf(pileStationInfo.getToiletFlag())); + stationInfo.setStoreFlag(Integer.valueOf(pileStationInfo.getStoreFlag())); + stationInfo.setRestaurantFlag(Integer.valueOf(pileStationInfo.getRestaurantFlag())); + stationInfo.setLoungeFlag(Integer.valueOf(pileStationInfo.getLoungeFlag())); + stationInfo.setCanopyFlag(Integer.valueOf(pileStationInfo.getCanopyFlag())); + stationInfo.setPrinterFlag(Integer.valueOf(pileStationInfo.getPrinterFlag())); + stationInfo.setBarrierFlag(Integer.valueOf(pileStationInfo.getBarrierFlag())); + stationInfo.setParkingLockFlag(Integer.valueOf(pileStationInfo.getParkingLockFlag())); + List pileList = pileBasicInfoService.getPileListForLianLian(stationId); + if (CollectionUtils.isNotEmpty(pileList)) { + stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表 + } + resultList.add(stationInfo); + } + Map map = new LinkedHashMap<>(); + map.put("PageNo", pageInfo.getPageNum()); + map.put("PageCount", pageInfo.getPages()); + map.put("ItemSize", pageInfo.getTotal()); + map.put("StationInfos", resultList); + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + return resultMap; + } + + /** + * 设备接口状态查询 query_station_status + * + * @param dto 查询站点信息dto + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public Map queryStationStatus(QueryStationInfoDTO dto) { + List stationIds = dto.getStationIds(); + List StationStatusInfos = new ArrayList<>(); + List ConnectorStatusInfos = new ArrayList<>(); + ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); + if (configInfo == null) { + return null; + } + ConnectorStatusInfo connectorStatusInfo; + for (String stationId : stationIds) { + StationStatusInfo stationStatusInfo = new StationStatusInfo(); + stationStatusInfo.setStationId(stationId); + // 根据站点id查询 + List list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId)); + for (ConnectorInfoVO connectorInfoVO : list) { + + String connectorStatus = connectorInfoVO.getConnectorStatus(); + if (StringUtils.equals(connectorStatus, PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue())) { + // 充电中 + ConnectorChargeStatusInfo info = new ConnectorChargeStatusInfo(); + OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(connectorInfoVO.getPileConnectorCode()); + if (orderBasicInfo == null) { + continue; + } + List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); + if (CollectionUtils.isNotEmpty(chargingRealTimeData)) { + RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); + + info.setStartChargeSeq(orderBasicInfo.getOrderCode()); + info.setConnectorID(orderBasicInfo.getPileConnectorCode()); + info.setConnectorStatus(Integer.valueOf(connectorInfoVO.getConnectorStatus())); + info.setCurrentA(new BigDecimal(realTimeMonitorData.getOutputCurrent())); + info.setVoltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage())); + info.setSoc(new BigDecimal(realTimeMonitorData.getSOC())); + info.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())); + info.setEndTime(DateUtils.getDateTime()); // 本次采样时间 + info.setTotalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())); // 累计充电量 + // info.setElecMoney(); // 累计电费 + // info.setSeviceMoney(); // 累计服务费 + info.setTotalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount())); + + ConnectorStatusInfos.add(info); + } + } else { + // 其他 + connectorStatusInfo = new ConnectorStatusInfo(); + connectorStatusInfo.setConnectorID(connectorInfoVO.getPileConnectorCode()); + connectorStatusInfo.setStatus(Integer.parseInt(connectorInfoVO.getConnectorStatus())); + + ConnectorStatusInfos.add(connectorStatusInfo); + } + } + stationStatusInfo.setConnectorStatusInfos(ConnectorStatusInfos); + StationStatusInfos.add(stationStatusInfo); + } + // 将 StationStatusInfos 分页 + int pageNum = 1; + int pageSize = 10; + List collect = StationStatusInfos.stream() + .skip((pageNum - 1) * pageSize) + .limit(pageSize) + .collect(Collectors.toList()); + + int total = StationStatusInfos.size(); + int pages = PageUtil.totalPage(total, pageSize); + + Map map = new LinkedHashMap<>(); + map.put("Total", total); + map.put("StationStatusInfos", collect); + + Map resultMap = Maps.newLinkedHashMap(); + // 加密数据 + String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); + resultMap.put("Data", encryptData); + // 生成sig + String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); + resultMap.put("Sig", resultSign); + return resultMap; + } + + /** + * 设备状态变化推送 notification_stationStatus + * 推送充电设备接口状态信息 supervise_notification_station_status + * + * @param dto + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationStationStatus(PushRealTimeInfoDTO dto) { + String status = dto.getStatus(); + String pileConnectorCode = dto.getPileConnectorCode(); + + // 查出该桩所属哪个站点 + // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + String pileSn = YKCUtils.getPileSn(pileConnectorCode); + PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn); + // 通过站点id查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + 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_STATION_STATUS.getValue(); + ConnectorStatusInfo info = ConnectorStatusInfo.builder() + .connectorID(pileConnectorCode) + .status(Integer.parseInt(status)) + .build(); + // 调用联联平台接口 + JSONObject json = new JSONObject(); + 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_equip_business_policy + * + * @param dto 请求启动充电DTO + * @return + */ + @Override + public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { + List policyInfoList = new ArrayList<>(); + String pileConnectorCode = dto.getConnectorID(); + ThirdPartySecretInfoVO yongChengbochePlatformSecretInfo = getYongChengbochePlatformSecretInfo(); + + // 截取桩号 + // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + String pileSn = YKCUtils.getPileSn(pileConnectorCode); + // 查询该桩的站点id + PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); + // 根据桩号查询正在使用的计费模板 + List billingPriceVOList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileBasicInfo.getStationId())); + + if (CollectionUtils.isEmpty(billingPriceVOList)) { + return null; + } + EquipBusinessPolicyVO.PolicyInfo policyInfo = null; + for (BillingPriceVO billingPriceVO : billingPriceVOList) { + // 将时段开始时间、电费、服务费信息进行封装 + policyInfo = new EquipBusinessPolicyVO.PolicyInfo(); + String startTime = billingPriceVO.getStartTime() + ":00"; // 00:00:00 格式 + // 需要将中间的冒号去掉,改为 000000 格式 + String replace = StringUtils.replace(startTime, ":", ""); + policyInfo.setStartTime(replace); + policyInfo.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + policyInfo.setServicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + + policyInfoList.add(policyInfo); + } + + // 拼装所需要的数据格式 + EquipBusinessPolicyVO vo = EquipBusinessPolicyVO.builder() + .equipBizSeq(dto.getEquipBizSeq()) + .connectorId(dto.getConnectorID()) + .succStat(0) + .failReason(0) + .sumPeriod(policyInfoList.size()) + .policyInfos(policyInfoList) + + .build(); + return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfo); + } + + /** + * 请求设备认证 + * + * @param dto + * @return + */ + @Override + public Map queryEquipAuth(QueryEquipmentDTO dto) { + Map resultMap = Maps.newLinkedHashMap(); + EquipmentAuthVO vo = new EquipmentAuthVO(); + + String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732 + String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID()); + // 先查询配置密钥相关信息 + ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); + if (configInfo == null) { + return null; + } + // 根据桩编号查询数据 + // String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); + // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + String pileSn = YKCUtils.getPileSn(pileConnectorCode); + // vo.setSuccStat(1); // 1-失败 0-成功 默认失败 + int succStat = 1; + int failReason = 0; + String failReasonMsg = ""; + PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); + if (pileBasicInfo != null) { + // 查询当前枪口数据 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); + if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), String.valueOf(connectorInfo.getStatus())) + || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), String.valueOf(connectorInfo.getStatus())) + || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_RESERVED_LOCK.getValue(), String.valueOf(connectorInfo.getStatus())) + ) { + succStat = 0; + failReason = 0; + } else { + succStat = 1; + // 1- 此设备尚未插枪; + failReason = 1; + } + vo.setEquipAuthSeq(equipAuthSeq); + vo.setConnectorID(pileConnectorCode); + } else { + // 设备检测失败 + failReason = 2; + failReasonMsg = "未查到该桩的数据"; + } + vo.setSuccStat(succStat); + vo.setFailReason(failReason); // 设备检测失败 + vo.setFailReasonMsg(failReasonMsg); + // 加密数据 + byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).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; + } + + /** + * 请求启动充电 query_start_charge + * + * @param dto 请求启动充电DTO + * @return + */ + @Override + public Map queryStartCharge(QueryStartChargeDTO dto) { + // 通过传过来的订单号和枪口号生成订单 + String pileConnectorCode = dto.getConnectorID(); + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq()); + if (orderInfo != null) { + // 平台已存在订单 + return null; + } + ThirdPartySecretInfoVO yongChengbochePlatformSecretInfoVO = getYongChengbochePlatformSecretInfo(); + // 生成订单 + Map map = orderBasicInfoService.generateOrderForThirdParty(dto); + String orderCode = (String) map.get("orderCode"); + String transactionCode = (String) map.get("transactionCode"); + OrderBasicInfo orderBasicInfo = (OrderBasicInfo) map.get("orderBasicInfo"); + + // 发送启机指令 + StartChargingCommand command = StartChargingCommand.builder() + .pileSn(orderBasicInfo.getPileSn()) + .connectorCode(orderBasicInfo.getConnectorCode()) + .transactionCode(transactionCode) + .chargeAmount(orderBasicInfo.getPayAmount()) + .logicCardNum(null) + .physicsCardNum(null) + .build(); + ykcPushCommandService.pushStartChargingCommand(command); + + // 拼装对应的数据并返回 + QueryStartChargeVO vo = QueryStartChargeVO.builder() + .startChargeSeq(orderCode) + .startChargeSeqStat(2) // 1、启动中 ;2、充电中;3、停止中;4、已结束;5、未知 + .connectorID(pileConnectorCode) + .succStat(0) + .failReason(0) + + .build(); + return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfoVO); + } + + /** + * 推送启动充电结果 notification_start_charge_result + * + * @param orderCode 订单编号 + * @return + */ + @Override + public String notificationStartChargeResult(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return null; + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); + + // 推送启动充电结果(调用接口 notification_start_charge_result) + String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_START_CHARGE_RESULT.getValue(); + // 拼装参数 + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + json.put("ConnectorID", orderInfo.getPileConnectorCode()); + json.put("StartChargeSeqStat", 2); // 一定要给 2-充电中 + json.put("StartTime", DateUtils.getDateTime()); + + 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; + } + + /** + * 查询充电状态 + * + * @param dto 查询充电状态DTO + * @return + */ + @Override + public Map queryEquipChargeStatus(QueryEquipChargeStatusDTO dto) { + String operatorID = dto.getOperatorID(); + // 通过订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq()); + // logger.info(operatorName + "查询订单信息 orderInfo:{}", orderInfo); + if (orderInfo == null) { + return null; + } + ThirdPartySecretInfoVO yongChengbochePlatformSecretInfoVO = getYongChengbochePlatformSecretInfo(); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); + // 通过订单号查询实时数据 + List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); + QueryChargingStatusVO vo; + if (CollectionUtils.isEmpty(realTimeData)) { + vo = new QueryChargingStatusVO(); + } else { + RealTimeMonitorData data = realTimeData.get(0); + String orderStatus = orderInfo.getOrderStatus(); + if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) { + // 充电中 + orderStatus = "2"; + } else if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) { + // 充电完成 + orderStatus = "4"; + } else { + // 直接给 5-未知 + orderStatus = "5"; + } + String status = data.getConnectorStatus(); + int connectorStatus = 0; + if (StringUtils.isBlank(status)) { + // 查询当前枪口状态 + PileConnectorInfoVO connectorInfoVO = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode()); + connectorStatus = connectorInfoVO.getStatus(); + } else { + connectorStatus = Integer.parseInt(status); + } + BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount(); + BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount(); + // 拼装联联平台数据 + vo = QueryChargingStatusVO.builder() + .startChargeSeq(dto.getStartChargeSeq()) // 订单号 + .startChargeSeqStat(Integer.parseInt(orderStatus)) // 订单状态 + .connectorID(orderInfo.getPileConnectorCode()) // 枪口编码 + .connectorStatus(connectorStatus) // 枪口状态 + .currentA(new BigDecimal(data.getOutputCurrent())) // 电流 + .voltageA(new BigDecimal(data.getOutputVoltage())) // 电压 + .soc(new BigDecimal(data.getSOC())) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间 + .endTime(DateUtils.getDateTime()) // 本次采样时间 + .totalPower(new BigDecimal(data.getChargingDegree()).setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计充电量 + .elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费 + .seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费 + .totalMoney(new BigDecimal(data.getChargingAmount())) // 已充金额 + + .build(); + } + return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfoVO); + } + + /** + * 推送充电状态 notification_equip_charge_status + * + * @param orderCode 订单编号 + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationEquipChargeStatus(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + // 查询枪口状态 + PileConnectorInfoVO info = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode()); + BigDecimal current = info.getCurrent() == null ? BigDecimal.ZERO : info.getCurrent(); + BigDecimal voltage = info.getVoltage() == null ? BigDecimal.ZERO : info.getVoltage(); + String soc = info.getSOC() == null ? Constants.ZERO : info.getSOC(); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); + String dateTime = DateUtils.getDateTime(); + SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo.builder() + .operatorID(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerID(Constants.OPERATORID_JIANG_SU) + .stationID(orderInfo.getStationId()) + .equipmentID(orderInfo.getPileSn()) + .connectorID(orderInfo.getPileConnectorCode()) + .orderNo(orderInfo.getOrderCode()) + .orderStatus(2) + .pushTimeStamp(dateTime) + .connectorStatus(info.getStatus()) // 3-充电中 + .currentA(current.setScale(1, BigDecimal.ROUND_HALF_UP)) + .voltageA(voltage.setScale(1, BigDecimal.ROUND_HALF_UP)) + .soc(new BigDecimal(soc)) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) + .endTime(dateTime) + .totalPower(info.getChargingDegree()) + .eventTime(dateTime) + .chargeVoltage(voltage.setScale(1, BigDecimal.ROUND_HALF_UP)) + .chargeCurrent(current.setScale(1, BigDecimal.ROUND_HALF_UP)) + .build(); + + // 查询运营商信息 + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(orderInfo.getStationId()); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) { + String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1); + supEquipChargeStatusInfo.setEquipmentOwnerID(equipmentOwnerId); + } + + String url = urlAddress + "supervise_notification_equip_charge_status"; + // 调用平台接口 + 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; + } + + /** + * 请求停止充电 query_stop_charge + * @param dto + * @return + */ + @Override + public Map queryStopCharge(QueryStartChargeDTO dto) { + QueryStopChargeVO vo = new QueryStopChargeVO(); + String orderCode = dto.getStartChargeSeq(); + + ThirdPartySecretInfoVO yongChengbochePlatformSecretInfo = getYongChengbochePlatformSecretInfo(); + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return null; + } + // 若状态为充电中,则发送停机指令 + if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) { + // 充电中 + pileRemoteService.remoteStopCharging(orderInfo.getPileSn(), orderInfo.getConnectorCode(), orderInfo.getTransactionCode()); + vo.setStartChargeSeq(orderCode); + vo.setStartChargeSeqStat(4); // 1、启动中 ;2、充电中;3、停止中;4、已结束;5、未知 + } + vo.setSuccStat(0); + vo.setFailReason(0); + + return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfo); + } + + /** + * 推送停止充电结果 notification_stop_charge_result + * + * @param orderCode 订单编号 + * @return + */ + @Override + public String notificationStopChargeResult(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return null; + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + 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_STOP_CHARGE_RESULT.getValue(); + + // 拼装联联平台参数 + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + json.put("StartChargeSeqStat", 4); // 只能给 4-已结束 + json.put("ConnectorID", orderInfo.getPileConnectorCode()); + json.put("SuccStat", 0); + json.put("FailReason", 0); + + 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; + } + + /** + * 推送充电站历史充电订单信息 supervise_notification_charge_order_info_history + * + * @param orderCode + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationChargeOrderInfoHistory(String orderCode) { + // 根据订单号查询出信息 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); + + String url = urlAddress + "supervise_notification_charge_order_info_history"; + + ChargeOrderInfo orderInfo = transformChargeOrderInfo(orderBasicInfo, orderDetail); + orderInfo.setOperatorID(operatorId); + String equipmentOwnerID; + if (MerchantUtils.isXiXiaoMerchant(orderBasicInfo.getMerchantId())) { + equipmentOwnerID = Constants.OPERATORID_XI_XIAO; + } else { + equipmentOwnerID = Constants.OPERATORID_LIANLIAN; + } + orderInfo.setEquipmentOwnerID(equipmentOwnerID); + + List billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId()); + // 先将list按照 尖、峰、平、谷 时段排序 + // List collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList()); + // 再循环该list,拼装对应的充电价格、费率 + List chargeDetails = transformSupChargeDetails(orderDetail, billingList); + orderInfo.setChargeDetails(chargeDetails); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } + // 调用联联平台接口 + JSONObject json = new JSONObject(); + json.put("ChargeOrderInfo", orderInfo); + String jsonString = JSON.toJSONString(json); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + + /** + * 获取甬城泊车平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getYongChengbochePlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } + + /** + * 转换充电站充电订单信息 + * + * @param orderBasicInfo + * @param orderDetail + * @return + */ + private ChargeOrderInfo transformChargeOrderInfo(OrderBasicInfo orderBasicInfo, OrderDetail orderDetail) { + ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder() + .stationID(orderBasicInfo.getStationId()) + .equipmentID(orderBasicInfo.getPileSn()) + .orderNo(orderBasicInfo.getOrderCode()) + .connectorID(orderBasicInfo.getPileConnectorCode()) + .licensePlate(orderBasicInfo.getPlateNumber()) + .vin(orderBasicInfo.getVinCode()) + .startSOC(orderBasicInfo.getStartSoc()) + .endSOC(orderBasicInfo.getEndSoc()) + .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()) + .cuspElect(orderDetail.getSharpUsedElectricity()) + .peakElect(orderDetail.getSharpUsedElectricity()) + .flatElect(orderDetail.getFlatUsedElectricity()) + .valleyElect(orderDetail.getValleyUsedElectricity()) + .pushTimeStamp(DateUtils.getDateTime()) + .totalElecMoney(orderDetail.getTotalElectricityAmount()) + .totalSeviceMoney(orderDetail.getTotalServiceAmount()) + .totalMoney(orderDetail.getTotalOrderAmount()) + .stopReason(0) + .stopDesc(orderBasicInfo.getReason()) // TODO 停止原因 + .sumPeriod(0) + .build(); + return chargeOrderInfo; + } + + /** + * 转换时段充电明细 + * + * @param orderDetail + * @param billingList + * @return + */ + private List transformSupChargeDetails(OrderDetail orderDetail, List billingList) { + List resultList = Lists.newArrayList(); + SupChargeDetails detail; + for (BillingPriceVO billingPriceVO : billingList) { + detail = new SupChargeDetails(); + if (StringUtils.equals(billingPriceVO.getTimeType(), BillingTimeTypeEnum.SHARP.getValue())) { + // 尖时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getSharpUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getSharpElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getSharpServicePrice()); + } else if (StringUtils.equals(billingPriceVO.getTimeType(), BillingTimeTypeEnum.PEAK.getValue())) { + // 峰时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getPeakUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getPeakElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getPeakServicePrice()); + } else if (StringUtils.equals(billingPriceVO.getTimeType(), BillingTimeTypeEnum.FLAT.getValue())) { + // 平时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getFlatUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getFlatElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getFlatServicePrice()); + } else if (StringUtils.equals(billingPriceVO.getTimeType(), BillingTimeTypeEnum.VALLEY.getValue())) { + // 谷时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getValleyUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getValleyElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getValleyServicePrice()); + } + resultList.add(detail); + } + return resultList; + } +}