diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java index 6766f7aa9..c12f189ca 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java @@ -28,8 +28,9 @@ public enum ThirdPlatformTypeEnum { GAN_SU_PLATFORM("17", "甘肃省平台", "MA01H3BQ9"), GUI_ZHOU_PLATFORM("18", "贵州省平台", "009390404"), NAN_RUI_PLATFORM("19", "南瑞平台", ""), - GUANG_XI_PLATFORM("20", "广西平台", "450000000"), + + XIN_YUN_PLATFORM("21", "新运平台", ""), ; private String typeCode; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java index e41ee3fba..3f091a7df 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GuangXiPlatformServiceImpl.java @@ -636,12 +636,6 @@ public class GuangXiPlatformServiceImpl implements ThirdPartyPlatformService { 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)) { // 充电中 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunPlatformServiceImpl.java new file mode 100644 index 000000000..ee856d964 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunPlatformServiceImpl.java @@ -0,0 +1,628 @@ +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.PileConnectorDataBaseStatusEnum; +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.OrderBasicInfo; +import com.jsowell.pile.domain.OrderDetail; +import com.jsowell.pile.dto.QueryEquipChargeStatusDTO; +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.ThirdPartyStationInfoVO; +import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +import com.jsowell.thirdparty.lianlian.domain.*; +import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; +import com.jsowell.thirdparty.lianlian.vo.QueryChargingStatusVO; +import com.jsowell.thirdparty.platform.common.ChargeOrderInfo; +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 org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 新运平台Service + * + * @author Lemon + * @Date 2025/1/10 8:28:43 + */ +@Service +public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private RedisCache redisCache; + + // 平台类型 + private final String thirdPlatformType = ThirdPlatformTypeEnum.XIN_YUN_PLATFORM.getTypeCode(); + + @Override + public void afterPropertiesSet() throws Exception { + ThirdPartyPlatformFactory.register(thirdPlatformType, this); + } + + @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.getOperatorID(); + // token缓存key值 + String redisKey = operatorId + "_token:"; + // 通过operatorId 查出 operatorSecret + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + 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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + /** + * 查询充电站信息 query_stations_info + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationsInfo(QueryStationInfoDTO dto) { + int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); + int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); + dto.setThirdPlatformType(thirdPlatformType); + PageUtils.startPage(pageNo, pageSize); + List stationInfos = pileStationInfoService.selectStationInfosByThirdParty(dto); + if (CollectionUtils.isEmpty(stationInfos)) { + // 未查到数据 + return null; + } + // ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); + List resultList = new ArrayList<>(); + for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { + SupStationInfo stationInfo = new SupStationInfo(); + stationInfo.setStationID(String.valueOf(pileStationInfo.getId())); + stationInfo.setOperatorID(Constants.OPERATORID_JIANG_SU); // 组织机构代码 + String organizationCode = pileStationInfo.getOrganizationCode(); + if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) { + String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1); + stationInfo.setEquipmentOwnerID(equipmentOwnerId); + }else { + stationInfo.setEquipmentOwnerID(Constants.OPERATORID_JIANG_SU); + } + stationInfo.setStationName(pileStationInfo.getStationName()); + stationInfo.setCountryCode(pileStationInfo.getCountryCode()); + String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213 + // 根据逗号分组 + String[] split = StringUtils.split(areaCode, ","); + // 只取最后一部分 330213 + String subAreaCode = split[split.length - 1]; + stationInfo.setAreaCode(subAreaCode); + stationInfo.setAddress(pileStationInfo.getAddress()); + stationInfo.setServiceTel(pileStationInfo.getStationTel()); + stationInfo.setStationType(Integer.parseInt(pileStationInfo.getStationType())); + stationInfo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus())); + stationInfo.setParkNums(Integer.parseInt(pileStationInfo.getParkNums())); + stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng())); + stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat())); + stationInfo.setConstruction(Integer.parseInt(pileStationInfo.getConstruction())); + // 停车费率描述 + if (StringUtils.isNotBlank(pileStationInfo.getParkFeeDescribe())) { + stationInfo.setParkFee(pileStationInfo.getParkFeeDescribe()); + } + // 站点图片 + if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { + stationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(","))); + } + + List pileList = pileBasicInfoService.getPileListForLianLian(String.valueOf(pileStationInfo.getId())); + 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", resultList.size()); + map.put("StationInfos", resultList); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + /** + * 设备接口状态查询 query_station_status + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStatus(QueryStationInfoDTO dto) { + List stationIds = dto.getStationIds(); + List StationStatusInfos = new ArrayList<>(); + List ConnectorStatusInfos = new ArrayList<>(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + + 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); + } + + int total = StationStatusInfos.size(); + + Map map = new LinkedHashMap<>(); + map.put("Total", total); + map.put("StationStatusInfos", StationStatusInfos); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + /** + * 查询统计信息 query_station_stats + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStats(QueryStationInfoDTO dto) { + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + // 根据站点id 查出这段时间的充电量 + List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); + if (CollectionUtils.isEmpty(list)) { + return null; + } + + // 根据充电桩编号分组 key=充电桩编号 + Map> pileMap = list.stream() + .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileSn)); + + // 存放所有充电桩设备 + List equipmentStatsInfoList = Lists.newArrayList(); + // 站点用电量 + BigDecimal stationElectricity = BigDecimal.ZERO; + // 用于记录枪口用电量 在循环每个枪口的时候初始化 + BigDecimal pileElec; + for (String pileSn : pileMap.keySet()) { + // 该充电桩下 所有枪口的用电数据 + List accumulativeInfoVOS = pileMap.get(pileSn); + if (CollectionUtils.isEmpty(accumulativeInfoVOS)) { + continue; + } + + // 存放充电桩用电量 + pileElec = BigDecimal.ZERO; + + // key=枪口编号 value 该枪口的用电数据 + Map> collect = accumulativeInfoVOS.stream() + .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileConnectorCode)); + + List connectorStatsInfos = Lists.newArrayList(); + for (Map.Entry> entry : collect.entrySet()) { + String pileConnectorCode = entry.getKey(); + List value = entry.getValue(); + // 枪口用电量求和 + BigDecimal connectorElec = value.stream() + .map(AccumulativeInfoVO::getConnectorElectricity) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + connectorStatsInfos.add( + ConnectorStatsInfo.builder() + .connectorID(pileConnectorCode) + .connectorElectricity(connectorElec) + .build() + ); + // 充电桩电量为枪口用电量累计 + pileElec = pileElec.add(connectorElec); + } + + EquipmentStatsInfo build = EquipmentStatsInfo.builder() + .equipmentID(pileSn) + .equipmentElectricity(pileElec) + .connectorStatsInfos(connectorStatsInfos) + .build(); + equipmentStatsInfoList.add(build); + + // 所有充电桩用电量之和 + stationElectricity = stationElectricity.add(pileElec); + } + + StationStatsInfo stationStatsInfo = StationStatsInfo.builder() + .stationID(dto.getStationID()) + .startTime(dto.getStartTime()) + .endTime(dto.getEndTime()) + .stationElectricity(stationElectricity) + .equipmentStatsInfos(equipmentStatsInfoList) // 设备列表 + .build(); + + Map map = new LinkedHashMap<>(); + map.put("StationStats", stationStatsInfo); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + /** + * 查询充电状态 query_equip_charge_status + * @param dto 查询充电状态DTO + * @return + */ + @Override + public Map queryEquipChargeStatus(QueryEquipChargeStatusDTO dto) { + // 通过订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq()); + // logger.info(operatorName + "查询订单信息 orderInfo:{}", orderInfo); + if (orderInfo == null) { + return null; + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + 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(); + } + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, 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 thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + 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(); + + String url = thirdPartySecretInfoVO.getTheirUrlPrefix() + 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_charge_status + * @param orderCode 订单编号 + * @return + */ + @Override + public String notificationEquipChargeStatus(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); + // 查询枪口实时状态 + List 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); + } + + // 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 : new BigDecimal(realTimeMonitorData.getOutputCurrent()); + BigDecimal voltage = realTimeMonitorData.getOutputVoltage() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputVoltage()); + String soc = realTimeMonitorData.getSOC() == null ? Constants.ZERO : realTimeMonitorData.getSOC(); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + + 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(); + + BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount(); + BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount(); + + QueryChargingStatusVO vo = QueryChargingStatusVO.builder() + .startChargeSeq(orderInfo.getOrderCode()) // 订单号 + .startChargeSeqStat(Integer.parseInt(orderInfo.getOrderStatus())) // 订单状态 + .connectorID(orderInfo.getPileConnectorCode()) // 枪口编码 + .connectorStatus(Integer.parseInt(realTimeMonitorData.getConnectorStatus())) // 枪口状态 + .currentA(current) // 电流 + .voltageA(voltage) // 电压 + .soc(new BigDecimal(soc)) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间 + .endTime(DateUtils.getDateTime()) // 本次采样时间 + .totalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())) // 累计充电量 + .elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费 + .seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费 + .totalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount())) // 已充金额 + + .build(); + String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getValue(); + // 调用平台接口 + String jsonString = JSON.toJSONString(vo); + + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送充电订单信息 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; + } + // 拼装订单编号 + String startChargeSeq = Constants.OPERATORID_JIANG_SU + orderCode + DateUtils.dateTimeNow(DateUtils.YYMMDD); + ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder() + .startChargeSeq(startChargeSeq) + // .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()) + .totalMoney(orderDetail.getTotalOrderAmount()) + .stopReason(2) + + .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; + } + + /** + * 获取新运平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getXinYunPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + 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; + } +}