From 345d60c227be57bcf9987f59a56bb7f25ee99f6b Mon Sep 17 00:00:00 2001 From: Lemon Date: Thu, 7 Nov 2024 16:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E7=94=98=E8=82=83?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=9B=B8=E5=85=B3Service=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/GanSuPlatformServiceImpl.java | 150 +++++++++++++++++- 1 file changed, 142 insertions(+), 8 deletions(-) diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GanSuPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GanSuPlatformServiceImpl.java index 82a38d115..223a7a0bd 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GanSuPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GanSuPlatformServiceImpl.java @@ -1,40 +1,47 @@ package com.jsowell.thirdparty.platform.service.impl; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.github.pagehelper.PageInfo; import com.jsowell.common.constant.Constants; 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.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.OrderBasicInfo; 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.web.PileConnectorInfoVO; 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.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 org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * 甘肃省平台 @@ -213,21 +220,148 @@ public class GanSuPlatformServiceImpl implements ThirdPartyPlatformService { @Override public Map queryStationStatus(QueryStationInfoDTO dto) { List stationIds = dto.getStationIds(); - List StationStatusInfos = new ArrayList<>(); + List stationStatusInfos = new ArrayList<>(); List connectorStatusInfos = new ArrayList<>(); // 查询密钥信息 ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGanSuSecretInfo(); - ConnectorStatusInfo connectorStatusInfo; - // 根据站点idList查询 + // 根据站点idList查询枪口列表 List list = pileConnectorInfoService.batchSelectConnectorList(stationIds); + // 根据站点id分组 + Map> collect = list.stream() + .collect(Collectors.groupingBy(ConnectorInfoVO::getStationId)); + // 封装参数 + for (Map.Entry> entry : collect.entrySet()) { + String stationId = entry.getKey(); + List voList = entry.getValue(); + StationStatusInfo stationStatusInfo = new StationStatusInfo(); + stationStatusInfo.setStationId(stationId); + 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 map = new LinkedHashMap<>(); + map.put("StationStatusInfos", stationStatusInfos); - return null; + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + 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 = getGanSuSecretInfo(); + + String operatorId = ganSuSecretInfo.getOurOperatorId(); + 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("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; + } + + /** + * 推送设备充电信息 notification_equip_charge_status + * @param orderCode 订单编号 + * @return + */ + @Override + public String notificationEquipChargeStatus(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + ThirdPartySecretInfoVO ganSuSecretInfo = getGanSuSecretInfo(); + + String operatorId = ganSuSecretInfo.getOurOperatorId(); + String operatorSecret = ganSuSecretInfo.getTheirOperatorSecret(); + String signSecret = ganSuSecretInfo.getTheirSigSecret(); + String dataSecret = ganSuSecretInfo.getTheirDataSecret(); + String dataSecretIv = ganSuSecretInfo.getTheirDataSecretIv(); + String urlAddress = ganSuSecretInfo.getTheirUrlPrefix(); + + // 查询充电枪口状态 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode()); + if (Objects.isNull(connectorInfo)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + + String merchantId = connectorInfo.getMerchantId(); + MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId); + if (Objects.isNull(merchantInfoVO)) { + 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"; + } + String dateTimeNow = DateUtils.getDateTime(); + + SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo.builder() + .startChargeSeq(orderCode) + .startChargeSeqStat(Integer.parseInt(orderStatus)) + .connectorID(orderInfo.getPileConnectorCode()) + .connectorStatus(connectorInfo.getStatus()) + .currentA(connectorInfo.getCurrent()) + .voltageA(connectorInfo.getVoltage()) + .soc(new BigDecimal(Constants.ZERO)) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) + .endTime(dateTimeNow) + .totalPower(connectorInfo.getInstantPower()) + .chargeDetails(new ArrayList<>()) + + .build(); + if (StringUtils.isNotBlank(connectorInfo.getSOC())) { + supEquipChargeStatusInfo.setSoc(new BigDecimal(connectorInfo.getSOC())); + } + + + 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