diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XDTController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XDTController.java index b33f3e23d..2b3b3b19f 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XDTController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XDTController.java @@ -55,31 +55,6 @@ public class XDTController extends ThirdPartyBaseController { } } - - /** - * 推送充电站信息 notification_stationInfo - * http://localhost:8080/xindiantu/v1/pushStationInfo - * @param dto - * @return - */ - @PostMapping("/v1/notification_station_detail") - public RestApiResponse pushStationInfo(@RequestBody PushStationInfoDTO dto) { - logger.info("推送新电途平台充电站信息 params:{}", JSON.toJSONString(dto)); - RestApiResponse response = null; - try { - platformLogic.notificationStationInfo(String.valueOf(dto.getStationId())); - response = new RestApiResponse<>(); - }catch (BusinessException e) { - logger.error("推送新电途平台充电站信息 error",e); - response = new RestApiResponse<>(e.getCode(), e.getMessage()); - }catch (Exception e) { - logger.error("推送新电途平台充电站信息 error", e); - response = new RestApiResponse<>(e); - } - logger.info("推送新电途平台充电站信息 result:{}", response); - return response; - } - /** * 查询充电站信息 * @param dto @@ -115,21 +90,46 @@ public class XDTController extends ThirdPartyBaseController { } /** - * 新电途平台查询统计信息 - * http://localhost:8080/xindiantu/v1/query_stations_stats + * 推送充电站信息 notification_stationInfo + * http://localhost:8080/xindiantu/v1/pushStationInfo + * @param dto + * @return + */ + @PostMapping("/v1/notification_station_detail") + public RestApiResponse pushStationInfo(@RequestBody PushStationInfoDTO dto) { + logger.info("推送新电途平台充电站信息 params:{}", JSON.toJSONString(dto)); + RestApiResponse response = null; + try { + platformLogic.notificationStationInfo(String.valueOf(dto.getStationId())); + response = new RestApiResponse<>(); + }catch (BusinessException e) { + logger.error("推送新电途平台充电站信息 error",e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e) { + logger.error("推送新电途平台充电站信息 error", e); + response = new RestApiResponse<>(e); + } + logger.info("推送新电途平台充电站信息 result:{}", response); + return response; + } + + + /** + * 设备接口状态查询 query_station_status + * + * @param request * @param dto * @return */ @PostMapping("/v1/query_station_status") - public CommonResult queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("{}-查询充电站状态信息 params:{}", platformName, JSON.toJSONString(dto)); + public CommonResult query_stations_status(HttpServletRequest request , @RequestBody CommonParamsDTO dto) { + logger.info("{}-设备接口状态查询 params:{}" , platformName , JSON.toJSONString(dto)); try { // 校验令牌 if (!verifyToken(request.getHeader("Authorization"))) { // 校验失败 return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); } - dto.setPlatformType(platformType); // 校验签名 if (!verifySignature(dto)) { @@ -138,27 +138,25 @@ public class XDTController extends ThirdPartyBaseController { } // 解析入参 - QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class); // 执行逻辑 Map map = platformLogic.queryStationStatus(queryStationInfoDTO); - - return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); + logger.info("{}-设备接口状态查询 result:{}" , platformName , map); + return CommonResult.success(0 , "设备接口状态查询成功!" , map.get("Data") , map.get("Sig")); } catch (Exception e) { - logger.error("{}-查询充电站状态信息 error:", platformName, e); + logger.info("{}-设备接口状态查询 error:" , platformName , e); } - return CommonResult.failed("查询充电站状态信息发生异常"); + return CommonResult.failed("设备接口状态查询发生异常"); } + /** - * 新电途平台查询业务策略信息结果 - * http://localhost:8080/xindiantu/v1/query_equip_business_policy - * @param dto - * @return + * 二维码解析接口 query_qrcode_data */ - @PostMapping("/v1/query_equip_business_policy") - public CommonResult queryEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("{}-查询业务策略信息结果 params:{}", platformName, JSON.toJSONString(dto)); + @PostMapping("/v1/query_qrcode_data") + public CommonResult queryQrcodeData(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-二维码解析接口 params:{}", platformName, JSON.toJSONString(dto)); try { // 校验令牌 if (!verifyToken(request.getHeader("Authorization"))) { @@ -174,16 +172,16 @@ public class XDTController extends ThirdPartyBaseController { } // 解析入参 - QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class); + QueryStartChargeDTO queryQrcodeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class); // 执行逻辑 - Map map = platformLogic.queryEquipBusinessPolicy(queryStartChargeDTO); + Map map = platformLogic.queryQrcodeData(queryQrcodeDTO); return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.error("{}-查询业务策略信息结果 error:", platformName, e); + logger.error("{}-二维码解析接口 error:", platformName, e); } - return CommonResult.failed("查询业务策略信息结果发生异常"); + return CommonResult.failed("二维码解析接口发生异常"); } /** @@ -222,15 +220,16 @@ public class XDTController extends ThirdPartyBaseController { return CommonResult.failed("请求设备认证发生异常"); } + /** - * 请求启动充电 - * @param request + * 新电途平台查询业务策略信息结果 + * http://localhost:8080/xindiantu/v1/query_equip_business_policy * @param dto * @return */ - @PostMapping("/v1/query_start_charge") - public CommonResult query_start_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("{}-请求启动充电 params:{}", platformName, JSON.toJSONString(dto)); + @PostMapping("/v1/query_equip_business_policy") + public CommonResult queryEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询业务策略信息结果 params:{}", platformName, JSON.toJSONString(dto)); try { // 校验令牌 if (!verifyToken(request.getHeader("Authorization"))) { @@ -249,15 +248,16 @@ public class XDTController extends ThirdPartyBaseController { QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class); // 执行逻辑 - Map map = platformLogic.queryStartCharge(queryStartChargeDTO); + Map map = platformLogic.queryEquipBusinessPolicy(queryStartChargeDTO); return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.error("{}-请求启动充电 error:", platformName, e); + logger.error("{}-查询业务策略信息结果 error:", platformName, e); } - return CommonResult.failed("请求启动充电发生异常"); + return CommonResult.failed("查询业务策略信息结果发生异常"); } + /** * 查询充电状态 * http://localhost:8080/xindiantu/query_equip_charge_status/{startChargeSeq} @@ -294,6 +294,86 @@ public class XDTController extends ThirdPartyBaseController { return CommonResult.failed("查询充电状态发生异常"); } + + + + /** + * 新电途平台查询统计信息 + * http://localhost:8080/xindiantu/v1/query_stations_stats + * @param dto + * @return + */ + @PostMapping("/v1/query_station_status") + public CommonResult queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询充电站状态信息 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + dto.setPlatformType(platformType); + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationStatus(queryStationInfoDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("{}-查询充电站状态信息 error:", platformName, e); + } + return CommonResult.failed("查询充电站状态信息发生异常"); + } + + + + + /** + * 请求启动充电 + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_start_charge") + public CommonResult query_start_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-请求启动充电 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + dto.setPlatformType(platformType); + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStartCharge(queryStartChargeDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("{}-请求启动充电 error:", platformName, e); + } + return CommonResult.failed("请求启动充电发生异常"); + } + + + /** * 请求停止充电 * @param request diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStartChargeDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStartChargeDTO.java index 1590e464f..1d9bc542d 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStartChargeDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStartChargeDTO.java @@ -105,4 +105,16 @@ public class QueryStartChargeDTO { */ @JsonProperty(value = "OrderNo") private String orderNo; + + /** + * 经度 + */ + @JsonProperty(value = "Latitude") + private BigDecimal longitude; + + /** + * 纬度 + */ + @JsonProperty(value = "Longitude") + private BigDecimal latitude; } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java index fa29abda0..f68f0767a 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java @@ -7,7 +7,6 @@ import com.google.common.collect.Maps; import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.Constants; import com.jsowell.common.core.redis.RedisCache; -import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.StringUtils; @@ -28,7 +27,6 @@ import com.jsowell.thirdparty.platform.util.Encodes; import com.jsowell.thirdparty.platform.util.GBSignUtils; import org.bouncycastle.crypto.CryptoException; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; @@ -297,6 +295,14 @@ public interface ThirdPartyPlatformService extends InitializingBean { throw new UnsupportedOperationException("This method is not yet implemented"); } + /** + * 二维码解析接口 + * query_qrcode_data + */ + default Map queryQrcodeData(QueryStartChargeDTO dto) { + throw new UnsupportedOperationException("This method is not yet implemented"); + } + // =================================================================================== // // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ 由对方平台实现此接口,我方平台调用的通知接口 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ // diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java index e59aba567..3e7403dc0 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java @@ -25,6 +25,7 @@ import com.jsowell.pile.thirdparty.ConnectorInfo; 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; @@ -35,10 +36,7 @@ import com.jsowell.pile.vo.web.PileMerchantInfoVO; import com.jsowell.pile.vo.web.PileModelInfoVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO; -import com.jsowell.thirdparty.lianlian.domain.ConnectorStatsInfo; -import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; -import com.jsowell.thirdparty.lianlian.domain.EquipmentStatsInfo; -import com.jsowell.thirdparty.lianlian.domain.StationStatsInfo; +import com.jsowell.thirdparty.lianlian.domain.*; import com.jsowell.thirdparty.lianlian.vo.*; import com.jsowell.thirdparty.platform.common.StationInfo; import com.jsowell.thirdparty.platform.domain.ChargeOrderInfo; @@ -50,6 +48,7 @@ import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; import com.jsowell.thirdparty.platform.util.*; import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.bouncycastle.crypto.CryptoException; import org.springframework.beans.factory.annotation.Autowired; @@ -62,10 +61,13 @@ import java.security.spec.InvalidKeySpecException; import java.util.*; import java.util.stream.Collectors; +import static com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils.isNeedPushToThirdPartyPlatform; + /** * 新电途 */ @Service +@Slf4j public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService { private final String thirdPlatformType = ThirdPlatformTypeEnum.XIN_DIAN_TU.getTypeCode(); @@ -272,6 +274,579 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService { } + /** + * 设备状态变化推送 notification_stationStatus + * + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationStationStatus(String stationId, String pileConnectorCode, String status, ThirdPartySecretInfoVO secretInfoVO) { + String pileSn = YKCUtils.getPileSn(pileConnectorCode); + // 通过站点id查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); + + if(Objects.equals(status , PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())){ + status =PileConnectorDataBaseStatusEnum.FAULT.getValue() ; // 离网改成255故障 + } + + 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); + log.info("参数:{}", jsonString); + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + log.info("token:{}", token); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + log.info("返回结果:{}", result); + return result; + } + + + /** + * 设备接口状态查询 query_station_status + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStatus(QueryStationInfoDTO dto) { + List stationIds = dto.getStationIds(); + List stationStatusInfos = new ArrayList<>(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo(); + + for (String stationId : stationIds) { + StationStatusInfo stationStatusInfo = new StationStatusInfo(); + stationStatusInfo.setStationId(stationId); + // 根据站点id查询 + List list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId)); + List connectorStatusInfos = new ArrayList<>(); + + for (ConnectorInfoVO connectorInfoVO : list) { + // 其他 + ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo(); + connectorStatusInfo.setConnectorID(connectorInfoVO.getPileConnectorCode()); + String connectorStatus = connectorInfoVO.getConnectorStatus(); + connectorStatusInfo.setStatus(Integer.parseInt(connectorStatus)); + connectorStatusInfos.add(connectorStatusInfo); + } + stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos); + stationStatusInfos.add(stationStatusInfo); + } + + + Map map = new LinkedHashMap<>(); + map.put("StationStatusInfos", stationStatusInfos); + + log.info("返回参数:{}", JSON.toJSONString(map)); + + return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + } + + /** + * 二维码解析 + * @param dto + * @return + */ + @Override + public Map queryQrcodeData(QueryStartChargeDTO dto) { + String qrCode = dto.getQrCode(); + JSONObject json = new JSONObject(); + if (dto.getQrCode() == null) { + json.put("ConnectorID", "解析错误"); + json.put("SuccStat", 0); // 0:成功;1:失败 + json.put("FailReason", 1); // 0:无;1.二维码解析失败 2.运营商未开放 + } + + // https://api.jsowellcloud.com/app-xcx-h5/pile/connectorDetail/8825000001255301 + + String connectorID = null; + if (qrCode != null) { + connectorID = qrCode.substring(qrCode.lastIndexOf("/") + 1); + } + + json.put("ConnectorID", connectorID); + json.put("SuccStat", 0); // 0:成功;1:失败 + json.put("FailReason", 0); // 0:无;1.二维码解析失败 2.运营商未开放 + + return ThirdPartyPlatformUtils.generateResultMap(json, getXinDiantuPlatformSecretInfo()); + } + + /** + * 请求设备认证 + * + * @param dto + * @return + */ + @Override + public Map queryEquipAuth(QueryEquipmentDTO dto) { + EquipmentAuthVO vo = new EquipmentAuthVO(); + + String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732 + String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID()); + // 先查询配置密钥相关信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo(); + + // 根据桩编号查询数据 + // 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); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + + /** + * 查询业务策略 query_equip_business_policy + * + * @param dto 请求启动充电DTO + * @return + */ + @Override + public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { + List policyInfoList = new ArrayList<>(); + String pileConnectorCode = dto.getConnectorID(); + ThirdPartySecretInfoVO xinDiantuPlatformSecretInfo = getXinDiantuPlatformSecretInfo(); + + // 截取桩号 + // 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, xinDiantuPlatformSecretInfo); + } + + + /** + * 请求启动充电 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 xindiantuPlatformSecretInfoVO = getXinDiantuPlatformSecretInfo(); + // 生成订单 + 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, xindiantuPlatformSecretInfoVO); + } + + + /** + * 推送启动充电结果 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 = getXinDiantuPlatformSecretInfo(); + + 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()); + json.put("SuccStat", 0); // 0:成功;1:失败 + 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; + } + + + + /** + * 查询充电状态 + * + * @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 xinDiantuPlatformSecretInfo = getXinDiantuPlatformSecretInfo(); + 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(3, 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, xinDiantuPlatformSecretInfo); + } + + + /** + * 推送充电状态 notification_equip_charge_status + * + * @param orderCode 订单编号 + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationEquipChargeStatus(String orderCode) { + //判断是否是常畅充平台的订单 + boolean flag = isNeedPushToThirdPartyPlatform(orderCode , ThirdPlatformTypeEnum.CHANG_ZHOU_PLATFORM.getOperatorId()); + if (!flag){ + //表示不是常畅充平台的订单 + return null; + } + + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); + // 查询枪口状态 + 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 = getXinDiantuPlatformSecretInfo(); + + 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(); + // 通过订单号查询实时数据 + + + List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); + RealTimeMonitorData data = realTimeData.get(0); + if (CollectionUtils.isEmpty(realTimeData)) { + throw new BusinessException(ReturnCodeEnum.valueOf("没有实时记录")); + } + String chargingAmount = data.getChargingAmount() == null ? Constants.ZERO : data.getChargingAmount(); + String chargingDegree = data.getChargingDegree() == null ? Constants.ZERO : data.getChargingDegree(); + + Integer orderStatus = OrderStatusEnum.convertToNewStatus(orderInfo.getOrderStatus()); + Integer connectorStatus = info.getStatus(); + if(connectorStatus == Integer.parseInt(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())){ + connectorStatus = Integer.parseInt(PileConnectorDataBaseStatusEnum.FAULT.getValue()); + } + QueryChargingStatusVO vo = QueryChargingStatusVO.builder() + .startChargeSeq(orderInfo.getOrderCode()) // 订单号 + .startChargeSeqStat(orderStatus) // 订单状态 + .connectorID(orderInfo.getPileConnectorCode()) // 枪口编码 + .connectorStatus(connectorStatus) // 枪口状态 + .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(chargingDegree).setScale(3, BigDecimal.ROUND_HALF_UP)) // 累计充电量 + .elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费 + .seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费 + .totalMoney(new BigDecimal(chargingAmount).setScale(2, BigDecimal.ROUND_HALF_UP)) // 已充金额 + + .build(); + String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getValue(); + // 调用平台接口 + String jsonString = JSON.toJSONString(vo); + log.info("请求参数:{}", jsonString); + + 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 xinDiantuPlatformSecretInfo = getXinDiantuPlatformSecretInfo(); + // 根据订单号查询订单信息 + 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, xinDiantuPlatformSecretInfo); + } + + + /** + * 推送停止充电结果 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 = getXinDiantuPlatformSecretInfo(); + + 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; + } + + /** + * 推送充电订单信息 + * notification_charge_order_info + */ + @Override + public String notificationChargeOrderInfo(String orderCode, ThirdPartySecretInfoVO secretInfoVO) { + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo(); + + 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(); + Date chargeStartTime = orderBasicInfo.getChargeStartTime(); + if (chargeStartTime == null) { + chargeStartTime = orderBasicInfo.getCreateTime(); + } + Date chargeEndTime = orderBasicInfo.getChargeEndTime(); + if (chargeEndTime == null) { + chargeEndTime = orderBasicInfo.getCreateTime(); + } + + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + json.put("ConnectorID", orderBasicInfo.getPileConnectorCode()); + json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeStartTime)); + json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeEndTime)); + json.put("TotalPower", orderDetail.getTotalUsedElectricity().setScale(3, BigDecimal.ROUND_HALF_UP)); + json.put("TotalElecMoney", orderDetail.getTotalElectricityAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); + json.put("TotalSeviceMoney", orderDetail.getTotalServiceAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); + json.put("TotalMoney", orderDetail.getTotalOrderAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); + json.put("StopReason", 2); // 2:BMS 停止充电 + + 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 * @@ -356,246 +931,13 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService { return ThirdPartyPlatformUtils.generateResultMap(map, ningBoSecretInfoVO); } - /** - * 请求设备认证 - * - * @param dto - * @return - */ - @Override - public Map queryEquipAuth(QueryEquipmentDTO dto) { - EquipmentAuthVO vo = new EquipmentAuthVO(); - String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732 - String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID()); - // 先查询配置密钥相关信息 - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo(); - // 根据桩编号查询数据 - // 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); - Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), - thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); - 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 xindiantuPlatformSecretInfoVO = getXinDiantuPlatformSecretInfo(); - // 生成订单 - 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, xindiantuPlatformSecretInfoVO); - } - - /** - * 查询业务策略 query_equip_business_policy - * - * @param dto 请求启动充电DTO - * @return - */ - @Override - public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { - List policyInfoList = new ArrayList<>(); - String pileConnectorCode = dto.getConnectorID(); - ThirdPartySecretInfoVO xinDiantuPlatformSecretInfo = getXinDiantuPlatformSecretInfo(); - - // 截取桩号 - // 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, xinDiantuPlatformSecretInfo); - } - - /** - * 设备状态变化推送 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 = getXinDiantuPlatformSecretInfo(); - - 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; - } - - /** - * 推送充电订单信息 - * notification_charge_order_info - */ - @Override - public String notificationChargeOrderInfo(String orderCode, ThirdPartySecretInfoVO secretInfoVO) { - OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); - - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo(); - - 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(); - Date chargeStartTime = orderBasicInfo.getChargeStartTime(); - if (chargeStartTime == null) { - chargeStartTime = orderBasicInfo.getCreateTime(); - } - Date chargeEndTime = orderBasicInfo.getChargeEndTime(); - if (chargeEndTime == null) { - chargeEndTime = orderBasicInfo.getCreateTime(); - } - - JSONObject json = new JSONObject(); - json.put("StartChargeSeq", orderCode); - json.put("ConnectorID", orderBasicInfo.getPileConnectorCode()); - json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeStartTime)); - json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeEndTime)); - json.put("TotalPower", orderDetail.getTotalUsedElectricity().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("TotalElecMoney", orderDetail.getTotalElectricityAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("TotalSeviceMoney", orderDetail.getTotalServiceAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("TotalMoney", orderDetail.getTotalOrderAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("StopReason", 2); // 2:BMS 停止充电 - - 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; - } - - @Override + /* @Override public String notificationChargeOrderInfo(String orderCode) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException, CryptoException { OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); @@ -638,247 +980,9 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService { 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 xinDiantuPlatformSecretInfo = getXinDiantuPlatformSecretInfo(); - 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, xinDiantuPlatformSecretInfo); - } - - /** - * 请求停止充电 query_stop_charge - * - * @param dto - * @return - */ - @Override - public Map queryStopCharge(QueryStartChargeDTO dto) { - QueryStopChargeVO vo = new QueryStopChargeVO(); - String orderCode = dto.getStartChargeSeq(); - - ThirdPartySecretInfoVO xinDiantuPlatformSecretInfo = getXinDiantuPlatformSecretInfo(); - // 根据订单号查询订单信息 - 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, xinDiantuPlatformSecretInfo); - } - - /** - * 推送启动充电结果 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 = getXinDiantuPlatformSecretInfo(); - - 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; - } - - /** - * 推送停止充电结果 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 = getXinDiantuPlatformSecretInfo(); - - 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; - } - - /** - * 推送充电状态 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 = getXinDiantuPlatformSecretInfo(); - - 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; - } /** * 获取新电途平台配置密钥信息