diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/WeiWangKuaiDianController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/WeiWangKuaiDianController.java new file mode 100644 index 000000000..181d4735b --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/WeiWangKuaiDianController.java @@ -0,0 +1,494 @@ +package com.jsowell.api.thirdparty; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.annotation.Anonymous; + +import com.jsowell.common.core.domain.AjaxResult; +import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.pile.dto.*; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.thirdparty.common.NotificationDTO; +import com.jsowell.thirdparty.common.NotificationService; +import com.jsowell.thirdparty.lianlian.common.CommonResult; +import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * 微网快电Controller + */ +@Anonymous +@RestController +@RequestMapping("/weiwangkuaidian") +public class WeiWangKuaiDianController extends ThirdPartyBaseController { + private final String platformName = "微网快电"; + + + private final String platformType = ThirdPlatformTypeEnum.WEI_WANG_XIN_DIAN.getTypeCode(); + + + @Autowired + @Qualifier("weiWangKuaiDianPlatformServiceImpl") + private ThirdPartyPlatformService platformLogic; + + @Autowired + private NotificationService notificationService; + + + /** + * getToken + */ + @PostMapping("/v1/query_token") + public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { + logger.info("{}-请求令牌 params:{}", platformName, JSON.toJSONString(dto)); + try { + Map map = platformLogic.queryToken(dto); + logger.info("{}-请求令牌, params:{}, result:{}", platformName, JSON.toJSONString(dto) , JSON.toJSONString(map)); + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("{}-获取token接口, 异常, params:{}", platformName, JSON.toJSONString(dto), e); + return CommonResult.failed("获取token发生异常"); + } + } + + + + /** + * 查询充电站信息 + * query_stations_info + */ + @PostMapping("/v1/query_stations_info") + public CommonResult query_stations_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询充电站信息 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationsInfo(queryStationInfoDTO); + + return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("{}-查询充电站信息 error:", platformName, e); + } + return CommonResult.failed("查询充电站信息发生异常"); + } + + + /** + * 设备状态推送 + * notification_stationStatus + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/notification_stationStatus") + public CommonResult notification_stationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-设备状态推送 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + PushRealTimeInfoDTO pushRealTimeInfoDTO = parseParamsDTO(dto, PushRealTimeInfoDTO.class); + // 执行逻辑 + String result = platformLogic.notificationStationStatus(pushRealTimeInfoDTO); + + return CommonResult.success(Integer.parseInt(result.split(",")[0]), result.split(",")[1], result.split(",")[2], result.split(",")[3]); + } catch (Exception e) { + logger.info("{}-设备状态推送 error:", platformName, e); + } + return CommonResult.failed("设备状态推送发生异常"); + } + + /** + * 设备接口状态查询 query_station_status + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_station_status") + 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); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationStatus(queryStationInfoDTO); + + return CommonResult.success(0, "设备接口状态查询成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("{}-设备接口状态查询 error:", platformName, e); + } + return CommonResult.failed("设备接口状态查询发生异常"); + } + + /** + * 统计信息查询 query_station_stats + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_station_stats") + public CommonResult query_station_stats(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询统计信息 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + // 执行逻辑 + Map map = platformLogic.queryStationStats(queryStationInfoDTO); + + return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("{}-查询统计信息 error:", platformName, e); + } + return CommonResult.failed("查询统计信息发生异常"); + } + + /** + * 请求设备认证 + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_equip_auth") + public CommonResult query_equip_auth(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); + } + + // 解析入参 + QueryEquipmentDTO queryEquipmentDTO = parseParamsDTO(dto, QueryEquipmentDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryEquipAuth(queryEquipmentDTO); + + 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 dto + */ + @RequestMapping("/v1/query_equip_business_policy") + public CommonResult query_equip_business_policy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询业务策略信息 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class); + + // 执行逻辑 + 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.info("{}-查询业务策略信息 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); + logger.info("{}-请求启动充电 result:{}", platformName, map); + + 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 + * @return + */ + @GetMapping("/v1/notification_start_charge_result") + public RestApiResponse notificationStartChargeResult(@RequestParam("orderCode") String orderCode) { + logger.info("【{}】推送启动充电结果 params:{}", this.getClass().getSimpleName(), orderCode); + RestApiResponse response = null; + try { + String result = platformLogic.notificationStartChargeResult(orderCode); + response = new RestApiResponse<>(result); + }catch (BusinessException e) { + logger.error("【{}】推送启动充电结果 error",this.getClass().getSimpleName(), e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e) { + logger.error("【{}】推送启动充电结果 error", this.getClass().getSimpleName(), e); + response = new RestApiResponse<>(e); + } + logger.info("【{}】推送启动充电结果 result:{}", this.getClass().getSimpleName(), response); + return response; + } + + /** + * 查询充电状态 + * http://localhost:8080/xindiantu/query_equip_charge_status/{startChargeSeq} + * @param dto + * @return + */ + @PostMapping("/v1/query_equip_charge_status") + public CommonResult queryEquipChargeStatus(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); + } + + // 解析入参 + QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = parseParamsDTO(dto, QueryEquipChargeStatusDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryEquipChargeStatus(queryEquipChargeStatusDTO); + + 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("查询充电状态发生异常"); + + } + + + /** + * 推送充电状态 + * http://localhost:8080/hainan/notificationEquipChargeStatus + * @param orderCode + * @return + */ + @GetMapping("/notificationEquipChargeStatus/{orderCode}") + public RestApiResponse notificationEquipChargeStatus(@PathVariable("orderCode") String orderCode) { + logger.info("推送充电状态 params:{}", orderCode); + RestApiResponse response = null; + try { + String result = platformLogic.notificationEquipChargeStatus(orderCode); + response = new RestApiResponse<>(result); + }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 request + * @param dto + * @return + */ + @PostMapping("/v1/query_stop_charge") + public CommonResult query_stop_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); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStopCharge(queryStartChargeDTO); + + return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("{}-请求停止充电 error", platformName, e); + } + return CommonResult.failed("{}-请求停止充电发生异常"); + } + + + /** + * 推送停止充电结果 + * http://localhost:8080/hainan/notificationStopChargeResult + * @param orderCode + * @return + */ + @GetMapping("/notificationStopChargeResult/{orderCode}") + public RestApiResponse notificationStopChargeResult(@PathVariable("orderCode") String orderCode) { + logger.info("推送停止充电结果 params:{}", orderCode); + RestApiResponse response = null; + try { + String result = platformLogic.notificationStopChargeResult(orderCode); + response = new RestApiResponse<>(result); + }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; + } + + /** + * 充电订单信息推送 + */ + @PostMapping("/notificationChargeOrderInfo") + public AjaxResult notificationChargeOrderInfo(@RequestBody NotificationDTO dto) { + AjaxResult result; + try { + notificationService.notificationChargeOrderInfo(dto); + result = AjaxResult.success(); + } catch (BusinessException e) { + logger.error("充电订单信息推送失败", e); + result = AjaxResult.error(e.getMessage()); + } catch (Exception e) { + logger.error("充电订单信息推送失败", e); + result = AjaxResult.error(); + } + return result; + } + + //TODO 接口待完善 + @PostMapping("/v1/check_charge_orders/{orderCode}") + public RestApiResponse checkChargeOrders(@PathVariable String orderCode) { + logger.info("{}-检查充电订单 params:{}", platformName, JSON.toJSONString(orderCode)); + RestApiResponse response = null; + try { + String result = platformLogic.checkChargeOrders(orderCode); + response = new RestApiResponse<>(result); + }catch (BusinessException e) { + logger.error("{}-检查充电订单 error", platformName, e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e) { + logger.error("{}-检查充电订单 error", platformName, e); + response = new RestApiResponse<>(e); + } + logger.info("{}-检查充电订单 result:{}", platformName, response); + return response; + } + + + +} 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 a304c6a4c..ce3651842 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 @@ -33,6 +33,7 @@ public enum ThirdPlatformTypeEnum { XIN_YUN_PLATFORM("21", "新运平台", "MADKXL8FX"), HE_NAN_PLATFORM("22", "河南省平台", "050880341"), + WEI_WANG_XIN_DIAN("23", "微网新电", "MA005DBW1") ; private String typeCode; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ChargeOrder.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ChargeOrder.java index f84102c11..7a16a48e9 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ChargeOrder.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ChargeOrder.java @@ -36,4 +36,10 @@ public class ChargeOrder { */ @JSONField(name = "TotalMoney") private BigDecimal totalMoney; + + /** + * 争议原因 1:交易不存在; 2:交易金额错误; 3:交易电量错误; 4~99:自定义 + */ + @JSONField(name = "DisputeReason") + private Integer disputeReason; } 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 09517a058..c419cb232 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 @@ -445,6 +445,10 @@ public interface ThirdPartyPlatformService extends InitializingBean { throw new UnsupportedOperationException("This method is not yet implemented"); } + default String checkChargeOrders(String orderCode) { + throw new UnsupportedOperationException("This method is not yet implemented"); + } + // -------------------------------------- 以下是公用方法 --------------------------------------- // /** * 从联联平台获取令牌 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/weiWangKuaiDianPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/weiWangKuaiDianPlatformServiceImpl.java new file mode 100644 index 000000000..3db654059 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/weiWangKuaiDianPlatformServiceImpl.java @@ -0,0 +1,1056 @@ +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.lianlian.LianLianPileStatusEnum; +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.PileStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.*; +import com.jsowell.pile.domain.*; +import com.jsowell.pile.domain.ykcCommond.StartChargingCommand; +import com.jsowell.pile.dto.*; +import com.jsowell.pile.service.*; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.thirdparty.ConnectorInfo; +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.base.ThirdPartyStationRelationVO; +import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; +import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +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.*; +import com.jsowell.thirdparty.lianlian.vo.*; +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 lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.bouncycastle.crypto.CryptoException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.spec.InvalidKeySpecException; +import java.util.*; +import java.util.stream.Collectors; + + +@Service +@Slf4j +public class weiWangKuaiDianPlatformServiceImpl implements ThirdPartyPlatformService { + private final String thirdPlatformType = ThirdPlatformTypeEnum.WEI_WANG_XIN_DIAN.getTypeCode(); + + @Autowired + private RedisCache redisCache; + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private PileBillingTemplateService pileBillingTemplateService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private PileModelInfoService pileModelInfoService; + + @Autowired + private ThirdPartyStationRelationService thirdPartyStationRelationService; + + + + @Override + public void afterPropertiesSet() throws Exception { + ThirdPartyPlatformFactory.register(thirdPlatformType, this); + } + + /** + * query_token 获取token,提供给第三方平台使用 + * + * @param dto + * @return + */ + @Override + public Map queryToken(CommonParamsDTO dto) { + AccessTokenVO vo = new AccessTokenVO(); + // 0:成功;1:失败 + int succStat = 0; + // 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义 + int failReason = 0; + + String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID(); + // 通过operatorId 查出 operatorSecret + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId); + if (thirdPartySecretInfoVO == null) { + failReason = 1; + succStat = 1; + } else { + String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); + // 解密data 获取参数中的OperatorSecret + String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); + String inputOperatorSecret = null; + if (StringUtils.isNotBlank(decrypt)) { + inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); + if (StringUtils.isBlank(inputOperatorSecret)) { + inputOperatorSecret = JSON.parseObject(decrypt).getString("PlatformSecret"); + } + } + // 对比密钥 + List operatorSecretList = Lists.newArrayList(theirOperatorSecret, thirdPartySecretInfoVO.getOurOperatorSecret()); + if (!operatorSecretList.contains(inputOperatorSecret)) { + failReason = 1; + succStat = 1; + } else { + // 生成token + String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis); + vo.setAccessToken(token); + vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); + } + } + // 组装返回参数 + vo.setPlatformId(operatorId); + vo.setFailReason(failReason); + vo.setSuccStat(succStat); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); + return resultMap; + } + + + // TODO 扩展接口,字段扩展 + /** + * 查询站点信息 + * @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 = getweiWangKuaiDianPlatformSecretInfo(); + + 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 = getPileList(pileStationInfo); + if (CollectionUtils.isNotEmpty(pileList)) { + stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表 + } + + resultList.add(stationInfo); + } + Map map = new LinkedHashMap<>(); + map.put("ItemSize", resultList.size()); + map.put("PageCount", pageInfo.getPages()); + map.put("PageNo", pageInfo.getPageNum()); + map.put("StationInfos", resultList); + + + log.info("query_token 返回参数:{}", JSON.toJSONString(map)); + + return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + } + + /** + * 设备状态变化推送 notification_stationStatus + * @param dto + * @return + */ + @Override + public String notificationStationStatus(PushRealTimeInfoDTO dto) { + String status = dto.getStatus(); + String pileConnectorCode = dto.getPileConnectorCode(); + + + String pileSn = YKCUtils.getPileSn(pileConnectorCode); + PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn); + // 通过站点id查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getweiWangKuaiDianPlatformSecretInfo(); + + 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); + 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 ningBoSecretInfoVO = getweiWangKuaiDianPlatformSecretInfo(); + + 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) { + 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 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); + + log.info("返回参数:{}", JSON.toJSONString(map)); + + return ThirdPartyPlatformUtils.generateResultMap(map, ningBoSecretInfoVO); + } + + + + /** + * 查询统计信息 query_station_stats + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStats(QueryStationInfoDTO dto) { + ThirdPartySecretInfoVO ningBoSecretInfoVO = getweiWangKuaiDianPlatformSecretInfo(); + // 根据站点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); + log.info("返回参数:{}", JSON.toJSONString(map)); + + return ThirdPartyPlatformUtils.generateResultMap(map, ningBoSecretInfoVO); + } + + + + /** + * 请求设备认证 query equip auth + * @param dto 请求设备认证 + * @return + */ + @Override + public Map queryEquipAuth(QueryEquipmentDTO dto) { + ThirdPartySecretInfoVO wangKuaiDianPlatformSecretInfo = getweiWangKuaiDianPlatformSecretInfo(); + EquipmentAuthVO vo = new EquipmentAuthVO(); + + String equipAuthSeq = dto.getEquipAuthSeq(); + String pileConnectorCode = dto.getConnectorID(); + + // 根据桩编号查询数据 + String pileSn = YKCUtils.getPileSn(pileConnectorCode); + vo.setSuccStat(1); // 1-失败 0-成功 默认失败 + 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())) + ) { + vo.setSuccStat(0); + vo.setFailReason(0); + } else { + vo.setSuccStat(1); + vo.setFailReason(1); // 1- 此设备尚未插枪; + } + vo.setEquipAuthSeq(equipAuthSeq); + vo.setConnectorID(pileConnectorCode); + } else { + vo.setFailReason(2); // 设备检测失败 + vo.setFailReasonMsg("未查到该桩的数据"); + } + log.info("返回参数:{}", JSON.toJSONString(vo)); + + return ThirdPartyPlatformUtils.generateResultMapV2(vo, wangKuaiDianPlatformSecretInfo.getTheirDataSecret(), + wangKuaiDianPlatformSecretInfo.getTheirDataSecretIv(), wangKuaiDianPlatformSecretInfo.getTheirSigSecret()); + } + + /** + * 查询业务策略 query_equip_business_policy + * @param dto 请求启动充电DTO + * @return + */ + @Override + public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { + List policyInfoList = new ArrayList<>(); + String pileConnectorCode = dto.getConnectorID(); + ThirdPartySecretInfoVO wangKuaiDianPlatformSecretInfo = getweiWangKuaiDianPlatformSecretInfo(); + + // 截取桩号 + // 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(); + + log.info("返回参数:{}", JSON.toJSONString(vo)); + + return ThirdPartyPlatformUtils.generateResultMapV2(vo, wangKuaiDianPlatformSecretInfo.getTheirDataSecret(), + wangKuaiDianPlatformSecretInfo.getTheirDataSecretIv(), wangKuaiDianPlatformSecretInfo.getTheirSigSecret()); + } + + + //TODO 扩展字段 + /** + * 请求启动充电 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 wangKuaiDianPlatformSecretInfo = getweiWangKuaiDianPlatformSecretInfo(); + // 生成订单 + 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(); + log.info("返回参数:{}", JSON.toJSONString(vo)); + + return ThirdPartyPlatformUtils.generateResultMapV2(vo, wangKuaiDianPlatformSecretInfo.getTheirDataSecret(), + wangKuaiDianPlatformSecretInfo.getTheirDataSecretIv(), wangKuaiDianPlatformSecretInfo.getTheirSigSecret()); + } + + /** + * 推送启动充电结果 notification_start_charge_result + * @param orderCode 订单编号 + * @return + */ + @Override + public String notificationStartChargeResult(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return null; + } + ThirdPartySecretInfoVO ningBoSecretInfoVO = getweiWangKuaiDianPlatformSecretInfo(); + String operatorId = Constants.OPERATORID_JIANG_SU; + String operatorSecret = ningBoSecretInfoVO.getTheirOperatorSecret(); + String signSecret = ningBoSecretInfoVO.getTheirSigSecret(); + String dataSecret = ningBoSecretInfoVO.getTheirDataSecret(); + String dataSecretIv = ningBoSecretInfoVO.getTheirDataSecretIv(); + String urlAddress = ningBoSecretInfoVO.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); + 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; + } + + + + //TODO 扩展字段 车辆识别码vin + /** + * 查询充电状态 query equip charge status + * @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 wangKuaiDianPlatformSecretInfo = getweiWangKuaiDianPlatformSecretInfo(); + 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(); + } + log.info("返回参数:{}", JSON.toJSONString(vo)); + return ThirdPartyPlatformUtils.generateResultMapV2(vo, wangKuaiDianPlatformSecretInfo.getTheirDataSecret(), + wangKuaiDianPlatformSecretInfo.getTheirDataSecretIv(), wangKuaiDianPlatformSecretInfo.getTheirSigSecret()); + } + + + //TODO 扩展字段 vin + /** + * 推送充电状态 notification_equip_charge_status + * @param orderCode 订单编号 + * @return + */ + @Override + public String notificationEquipChargeStatus(String orderCode) { + // 根据订单号查询订单信息 + 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 ningBoSecretInfoVO = getweiWangKuaiDianPlatformSecretInfo(); + + String operatorId = Constants.OPERATORID_JIANG_SU; + String operatorSecret = ningBoSecretInfoVO.getTheirOperatorSecret(); + String signSecret = ningBoSecretInfoVO.getTheirSigSecret(); + String dataSecret = ningBoSecretInfoVO.getTheirDataSecret(); + String dataSecretIv = ningBoSecretInfoVO.getTheirDataSecretIv(); + String urlAddress = ningBoSecretInfoVO.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(info.getStatus()) // 枪口状态 + .currentA(info.getCurrent()) // 电流 + .voltageA(info.getVoltage()) // 电压 + .soc(new BigDecimal(info.getSOC())) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间 + .endTime(DateUtils.getDateTime()) // 本次采样时间 + .totalPower(info.getChargingDegree()) // 累计充电量 + .elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费 + .seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费 + .totalMoney(info.getChargingAmount()) // 已充金额 + + .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 wangKuaiDianPlatformSecretInfo = getweiWangKuaiDianPlatformSecretInfo(); + // 根据订单号查询订单信息 + 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); + vo.setStartChargeSeq(orderCode); + log.info("返回参数:{}", JSON.toJSONString(vo)); + return ThirdPartyPlatformUtils.generateResultMapV2(vo, wangKuaiDianPlatformSecretInfo.getOurDataSecret() + , wangKuaiDianPlatformSecretInfo.getOurDataSecretIv(), wangKuaiDianPlatformSecretInfo.getOurSigSecret()); + } + + + /** + * 推送停止充电结果 notification_stop_charge_result + * @param orderCode 订单编号 + * @return + */ + @Override + public String notificationStopChargeResult(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return null; + } + ThirdPartySecretInfoVO wangKuaiDianPlatformSecretInfo = getweiWangKuaiDianPlatformSecretInfo(); + String operatorId = Constants.OPERATORID_JIANG_SU; + String operatorSecret = wangKuaiDianPlatformSecretInfo.getTheirOperatorSecret(); + String signSecret = wangKuaiDianPlatformSecretInfo.getTheirSigSecret(); + String dataSecret = wangKuaiDianPlatformSecretInfo.getTheirDataSecret(); + String dataSecretIv = wangKuaiDianPlatformSecretInfo.getTheirDataSecretIv(); + String urlAddress = wangKuaiDianPlatformSecretInfo.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); + + 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; + } + + + //TODO 扩展字段 vin + /** + * 推送订单数据 notificationChargeOrderInfo + * @param orderCode 订单编号 + * @return + * @throws NoSuchAlgorithmException + * @throws InvalidKeySpecException + * @throws NoSuchProviderException + * @throws CryptoException + */ + @Override + public String notificationChargeOrderInfo(String orderCode, ThirdPartySecretInfoVO thirdPartySecretInfoVO) { + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + + 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 = 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); + 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; + } + + + /** + * 推送订单对账结果信息 + * + * @param orderCode + * @return + */ + @Override + public String checkChargeOrders(String orderCode) { + + List list = new ArrayList<>(); + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + if (orderInfo == null || orderDetail == null) { + return null; + } + + // 通过站点id查询相关配置信息 + // 通过三方平台类型查询相关配置信息 + ThirdPartyStationRelation relation = new ThirdPartyStationRelation(); + relation.setThirdPartyType(orderInfo.getThirdPartyType()); + ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation); + // ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); + if (relationInfo == null) { + return null; + } + String operatorId = relationInfo.getOperatorId(); + String operatorSecret = relationInfo.getOperatorSecret(); + String signSecret = relationInfo.getSignSecret(); + String dataSecret = relationInfo.getDataSecret(); + String dataSecretIv = relationInfo.getDataSecretIv(); + String urlAddress = relationInfo.getUrlAddress(); + + String url = urlAddress + BusinessInformationExchangeEnum.CHECK_CHARGE_ORDERS.getValue(); + + JSONObject json = new JSONObject(); + json.put("CheckOrderSeq", orderCode); + json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())); + json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeEndTime())); + json.put("TotalDisputeOrder", 1); + json.put("TotalDisputePower", orderDetail.getTotalUsedElectricity()); + json.put("TotalDisputeMoney", orderDetail.getTotalOrderAmount()); + + ChargeOrder chargeOrder = ChargeOrder.builder() + .startChargeSeq(orderCode) + .totalPower(orderDetail.getTotalUsedElectricity()) + .totalMoney(orderDetail.getTotalOrderAmount()) + .build(); + list.add(chargeOrder); + json.put("DisputeOrders", list); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } + String jsonString = JSON.toJSONString(json); + log.info("请求参数:{}", jsonString); + // 发送请求 + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + + //<---------------------------扩展接口--------------------------> + //TODO 站点变更通知 notification_station_change + + //TODO 二维码查询枪号 query_terminal_code + + //TODO 推送充电车牌号 notification_charge_carnum + + //TODO 超时占位费推送 notification_overtime_order_info + + //TODO 账单拉取 query_charge_order_info + + + /** + * 获取微网快电配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getweiWangKuaiDianPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + 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; + } + + + /** + * 获取桩列表信息 + * + * @param pileStationInfo + * @return + */ + private List getPileList(PileStationInfo pileStationInfo) { + List resultList = new ArrayList<>(); + // 通过站点id查询桩基本信息 + List list = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId())); + // MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(pileStationInfo.getMerchantId())); + // 封装成联联平台对象 + for (PileBasicInfo pileBasicInfo : list) { + EquipmentInfo equipmentInfo = new EquipmentInfo(); + String pileSn = pileBasicInfo.getSn(); + + equipmentInfo.setEquipmentID(pileSn); + equipmentInfo.setManufacturerID(Constants.OPERATORID_LIANLIAN); + equipmentInfo.setConstructionTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getCreateTime())); + + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + equipmentInfo.setEquipmentType(Integer.valueOf(modelInfo.getSpeedType())); + + // Map pileStatus = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileBasicInfo.getSn())); + Map pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn)); + String pileStatus = pileStatusMap.get(pileSn); + if (StringUtils.equals(PileStatusEnum.ON_LINE.getValue(), pileStatus)) { + // 1-在线 + pileStatus = LianLianPileStatusEnum.NORMAL.getCode(); + } else if (StringUtils.equals(PileStatusEnum.OFF_LINE.getValue(), pileStatus)) { + // 2-离线 + pileStatus = LianLianPileStatusEnum.CLOSE_OFFLINE.getCode(); + } else if (StringUtils.equals(PileStatusEnum.FAULT.getValue(), pileStatus)) { + // 3-故障 + pileStatus = LianLianPileStatusEnum.UNDER_MAINTENANCE.getCode(); + } + equipmentInfo.setEquipmentStatus(Integer.valueOf(pileStatus)); + equipmentInfo.setEquipmentPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); + equipmentInfo.setNewNationalStandard(1); + equipmentInfo.setVinFlag(1); + + List connectorList = getConnectorList(pileBasicInfo); + equipmentInfo.setConnectorInfos(connectorList); + + resultList.add(equipmentInfo); + } + return resultList; + } + + + /** + * 获取枪口列表 + * + * @param pileBasicInfo + * @return + */ + private List getConnectorList(PileBasicInfo pileBasicInfo) { + List resultList = new ArrayList<>(); + + List list = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn()); + for (PileConnectorInfo pileConnectorInfo : list) { + ConnectorInfo connectorInfo = new ConnectorInfo(); + + connectorInfo.setConnectorID(pileConnectorInfo.getPileConnectorCode()); + String pileSn = pileConnectorInfo.getPileSn(); + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3; + + connectorInfo.setConnectorType(connectorType); + // 车位号 + if (StringUtils.isNotBlank(pileConnectorInfo.getParkNo())) { + connectorInfo.setParkNo(pileConnectorInfo.getParkNo()); + } + connectorInfo.setVoltageUpperLimits(Integer.valueOf(modelInfo.getRatedVoltage())); + connectorInfo.setVoltageLowerLimits(Integer.valueOf(modelInfo.getRatedVoltage())); + + connectorInfo.setCurrent(Integer.valueOf(modelInfo.getRatedCurrent())); + if (!StringUtils.equals(modelInfo.getConnectorNum(), "1")) { + // 如果不是单枪,则枪口功率需要除以枪口数量 + String ratedPowerStr = modelInfo.getRatedPower(); + BigDecimal ratedPower = new BigDecimal(ratedPowerStr); + connectorInfo.setPower(ratedPower.divide(new BigDecimal(modelInfo.getConnectorNum()), 1, BigDecimal.ROUND_HALF_UP)); + }else { + connectorInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); + } + + resultList.add(connectorInfo); + } + + return resultList; + } + + +}