From ee733ff8e04410689d5beeae7d5ef13645bded11 Mon Sep 17 00:00:00 2001 From: "YAS\\29473" <2947326429@qq.com> Date: Thu, 26 Jun 2025 15:41:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E5=90=89=E6=9E=97=E5=B9=B3=E5=8F=B0=E6=8E=A5=E5=8F=A3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thirdparty/JiLinPlatformController.java | 266 +++++ .../api/thirdparty/SiChuanController.java | 12 +- .../thirdparty/ThirdPlatformTypeEnum.java | 1 + .../pile/dto/QueryEquipChargeStatusDTO.java | 3 + .../jsowell/pile/dto/QueryStartChargeDTO.java | 6 + .../pile/thirdparty/dto/ConnectorInfoDTO.java | 13 + .../lianlian/vo/QueryStartChargeVO.java | 37 + .../impl/JiLinPlatformServiceImpl.java | 1030 +++++++++++++++++ .../impl/SiChuanPlatformServiceImpl.java | 35 +- 9 files changed, 1379 insertions(+), 24 deletions(-) create mode 100644 jsowell-admin/src/main/java/com/jsowell/api/thirdparty/JiLinPlatformController.java create mode 100644 jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/JiLinPlatformServiceImpl.java diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/JiLinPlatformController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/JiLinPlatformController.java new file mode 100644 index 000000000..c277ec313 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/JiLinPlatformController.java @@ -0,0 +1,266 @@ +package com.jsowell.api.thirdparty; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.annotation.Anonymous; +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.QueryEquipmentDTO; +import com.jsowell.pile.dto.QueryOperatorInfoDTO; +import com.jsowell.pile.dto.QueryStartChargeDTO; +import com.jsowell.pile.dto.QueryStationInfoDTO; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +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 + */ +@RestController +@RequestMapping("/jilin") +@Anonymous +public class JiLinPlatformController extends ThirdPartyBaseController{ + private final String platformName = "吉林省平台"; + + + private final String platformType = ThirdPlatformTypeEnum.JI_LIN_PLATFORM.getTypeCode(); + + + @Autowired + @Qualifier("jiLinPlatformServiceImpl") + private ThirdPartyPlatformService platformLogic; + + + /** + * 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("{}-请求令牌 result:{}" , platformName , map); + return CommonResult.success(0 , "请求令牌成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.info("{}-请求令牌 error:" , platformName , e); + return CommonResult.failed("获取token发生异常"); + } + } + + /** + * 查询运营商信息 + * query_operator_info + */ + @PostMapping("/v1/query_operator_info") + public CommonResult query_operator_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); + } + + // 解析入参 + QueryOperatorInfoDTO queryOperatorInfoDTO = parseParamsDTO(dto , QueryOperatorInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryOperatorInfo(queryOperatorInfoDTO); + logger.info("{}-查询运营商信息 result:{}" , platformName , map); + return CommonResult.success(0 , "查询运营商信息成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.info("{}-查询运营商信息 error:" , platformName , e); + } + return CommonResult.failed("查询运营商信息发生异常"); + } + + + /** + * 查询充电站信息 + * 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 { + logger.info("{}-携带的token:{}",platformName, request.getHeader("Authorization")); + // 校验令牌 + 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); + logger.info("{}-查询充电站信息 result:{}" , platformName , JSON.toJSONString(map)); + return CommonResult.success(0 , "查询充电站信息成功!" , map.get("Data") , map.get("Sig")); + } 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_station_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); + logger.info("{}-设备接口状态查询 result:{}" , platformName , map); + 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); + logger.info("{}-请求设备认证 result:{}" , platformName , map); + return CommonResult.success(0 , "请求设备认证成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.error("{}-请求设备认证 error:" , platformName , e); + } + return CommonResult.failed("请求设备认证发生异常"); + } + + + /** + * 请求启动充电 + * + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/start_charge") + public CommonResult 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(0 , "请求启动充电成功!" , 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/{orderCode}") + public RestApiResponse notification_start_charge_result(@PathVariable("orderCode") String orderCode) { + logger.info("【{}】推送启动充电结果 params:{}" , this.getClass().getSimpleName() , orderCode); + RestApiResponse response = null; + try { + String result = platformLogic.notificationStartChargeResult(orderCode); + logger.info("【{}】推送启动充电结果 result:{}" , this.getClass().getSimpleName() , result); + 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; + } + + +} diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java index 0eff319d2..207dc1f1d 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java @@ -195,9 +195,17 @@ public class SiChuanController extends ThirdPartyBaseController { }*/ + /** + * 推送充电站信息 + */ + @PostMapping("/v1/supervise_push_stations_info/{stationId}") + public CommonResult supervise_push_stations_info(HttpServletRequest request , @PathVariable("stationId") String stationId) { + logger.info("{}-推送充电站信息 params:{}" , platformName , JSON.toJSONString(stationId)); + String s = platformLogic.notificationStationInfo(stationId); + logger.info("{}-推送充电站信息 result:{}" , platformName , s); - - + return CommonResult.success(0 , "推送充电站信息成功!" , s , null); + } } 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 41f649ae4..5432c6d2f 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 @@ -37,6 +37,7 @@ public enum ThirdPlatformTypeEnum { HU_ZHOU_PLATFORM("24", "湖州市监管平台", "MA27U00HZ"), CHANG_ZHOU_PLATFORM("25", "新运常畅充", "0585PCW57"), SI_CHUAN_PLATFORM("26", "四川省平台", ""), + JI_LIN_PLATFORM("27", "吉林省平台", ""), ; private String typeCode; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipChargeStatusDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipChargeStatusDTO.java index e9eca84b2..76f041a16 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipChargeStatusDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipChargeStatusDTO.java @@ -16,4 +16,7 @@ public class QueryEquipChargeStatusDTO { @JsonProperty(value = "OperatorID") private String OperatorID; + + @JsonProperty(value = "orderNo") + private String orderNo; } 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 e883fed3a..b40467aa4 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 @@ -99,4 +99,10 @@ public class QueryStartChargeDTO { */ @JsonProperty(value = "LastQueryEndTime") private String lastQueryEndTime; + + /** + * 充电订单号 格式“运营商ID+唯一编号” + */ + @JsonProperty(value = "OrderNO") + private String orderNO; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/dto/ConnectorInfoDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/dto/ConnectorInfoDTO.java index aac4c3f50..2b2827ad3 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/dto/ConnectorInfoDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/dto/ConnectorInfoDTO.java @@ -167,4 +167,17 @@ public class ConnectorInfoDTO { @JSONField(name = "OpreateHours") private String opreateHours; + + /** + * 有无地锁 + */ + @JSONField(name = "HasLock") + private Integer hasLock; + + /** + * 充电二维码 + */ + @JSONField(name = "ChargingQrCode") + private String chargingQrCode; + } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/QueryStartChargeVO.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/QueryStartChargeVO.java index 1fd132345..8e3ee83b8 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/QueryStartChargeVO.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/QueryStartChargeVO.java @@ -46,4 +46,41 @@ public class QueryStartChargeVO { */ @JSONField(name = "FailReason") private int failReason; + +// 《*** 吉林平台接口返回参数字段 ***》 + + /** + * 充电订单号 + */ + @JSONField(name = "orderNo") + private String orderNo; + + /** + * 充电订单状态 + * 1:启动中; 2:充电中; 3:停止中; 4:充电完成;5:订单挂起;6:充电异常 结束;7:启动失败 + */ + @JSONField(name = "orderStatus") + private Integer orderStatus; + + /** + * 充电启动超时时间 + */ + @JSONField(name = "overTime") + private Integer overTime; + + /** + * 失败码 + * 0:无;1:此设备不存在(设备已下线或站 点非正常使用状态时,认为设备不存在); 2:此设备离线; 3:无此设备使用权限; 4:此设备正忙;50~999:自定义 + */ + @JSONField(name = "FailReasonCode") + private Integer failReasonCode; + + /** + * 失败信息 + */ + @JSONField(name = "FailReasonMsg") + private String failReasonMsg; + + + } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/JiLinPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/JiLinPlatformServiceImpl.java new file mode 100644 index 000000000..af8ddd709 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/JiLinPlatformServiceImpl.java @@ -0,0 +1,1030 @@ +package com.jsowell.thirdparty.platform.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.enums.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.mapper.PileBasicInfoMapper; +import com.jsowell.pile.service.*; +import com.jsowell.pile.thirdparty.*; +import com.jsowell.pile.thirdparty.EquipmentInfoDTO; +import com.jsowell.pile.thirdparty.dto.ConnectorInfoDTO; +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.uniapp.customer.BillingPriceVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +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.ConnectorStatusInfo; +import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo; +import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; +import com.jsowell.thirdparty.lianlian.vo.EquipmentAuthVO; +import com.jsowell.thirdparty.lianlian.vo.QueryChargingStatusVO; +import com.jsowell.thirdparty.lianlian.vo.QueryStartChargeVO; +import com.jsowell.thirdparty.platform.domain.ChargeOrderInfo; +import com.jsowell.thirdparty.platform.domain.SupConnectorStatusInfo; +import com.jsowell.thirdparty.platform.domain.SupOperatorInfo; +import com.jsowell.thirdparty.platform.domain.SupStationInfo; +import com.jsowell.thirdparty.platform.dto.SupStationInfoDTO; +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 com.yi.business.geo.GeoCodeInfo; +import com.yi.business.geo.TermRelationTreeCoordinate; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class JiLinPlatformServiceImpl implements ThirdPartyPlatformService { + private final String thirdPlatformType = ThirdPlatformTypeEnum.JI_LIN_PLATFORM.getTypeCode(); + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + @Autowired + private PileModelInfoService pileModelInfoService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private PileBillingTemplateService pileBillingTemplateService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private ThirdPartyStationRelationService thirdPartyStationRelationService; + + @Autowired + private PileMerchantInfoService pileMerchantInfoService; + + @Autowired + private PileBasicInfoMapper pileBasicInfoMapper; + + + + + @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); + + return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + } + + + /** + * 查询运营商信息 query_operator_info + * supervise_query_operator_info + * + * @param dto 查询运营商信息DTO + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public Map queryOperatorInfo(QueryOperatorInfoDTO dto) { + int pageNo = dto.getPageNo() == 0 ? 1 : dto.getPageNo(); + int pageSize = dto.getPageSize() == 0 ? 50 : dto.getPageSize(); + PageHelper.startPage(pageNo, pageSize); + List merchantList = thirdPartyStationRelationService.selectMerchantList(thirdPlatformType); + PageInfo pageInfo = new PageInfo<>(merchantList); + List operatorInfos = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(pageInfo.getList())) { + SupOperatorInfo supOperatorInfo; + for (MerchantInfoVO merchantInfoVO : pageInfo.getList()) { + supOperatorInfo = new SupOperatorInfo(); + supOperatorInfo.setOperatorID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode())); + supOperatorInfo.setOperatorUSCID(merchantInfoVO.getOrganizationCode()); + supOperatorInfo.setOperatorName(merchantInfoVO.getMerchantName()); + supOperatorInfo.setOperatorTel1(merchantInfoVO.getMerchantTel()); + supOperatorInfo.setOperatorRegAddress(merchantInfoVO.getMerchantAddress()); + operatorInfos.add(supOperatorInfo); + } + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiLinSecretInfo(); + + // 组装结果集 + Map map = Maps.newHashMap(); + map.put("PageNo", pageInfo.getPageNum()); + map.put("PageCount", pageInfo.getPages()); + map.put("ItemSize", pageInfo.getTotal()); + map.put("OperatorInfos", operatorInfos); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + + + /** + * 查询站点信息 + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationsInfo(QueryStationInfoDTO dto) { + int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); + int pageSize = dto.getPageSize() == null ? 50 : dto.getPageSize(); + dto.setThirdPlatformType("25"); + PageUtils.startPage(pageNo, pageSize); + List stationInfos = pileStationInfoService.selectStationInfosByThirdParty(dto); + if (CollectionUtils.isEmpty(stationInfos)) { + // 未查到数据 + return null; + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = null; + + PageInfo pageInfo = new PageInfo<>(stationInfos); + List resultList = new ArrayList<>(); + for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { + SupStationInfoDTO stationInfo = new SupStationInfoDTO(); + stationInfo.setStationID(String.valueOf(pileStationInfo.getId())); + stationInfo.setOperatorID(Constants.OPERATORID_JIANG_SU); // 组织机构代码 + String organizationCode = pileStationInfo.getOrganizationCode(); + // 充电服务运营商 + stationInfo.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)); + 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]; + // 充换电站省市辖区编码 AreaCode + stationInfo.setAreaCode(subAreaCode); + + // 获取地理位置编码 AreaCodeCountryside + GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(pileStationInfo.getAddress()); + if (geoCode != null) { + //充换电站所在县以下行政区划代码 + stationInfo.setAreaCodeCountryside(geoCode.getCounty_code()); + }else{ + stationInfo.setAreaCodeCountryside("12345678901"); + } + + 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()).setScale(6, RoundingMode.HALF_UP)); + stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat()).setScale(6, RoundingMode.HALF_UP)); + stationInfo.setConstruction(Integer.parseInt(pileStationInfo.getConstruction())); + // 站点图片 + if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { + stationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(","))); + } + stationInfo.setRoundTheClock(Constants.one); + //计费信息 + // 根据站点id查询正在使用的计费模板 + List billingPriceVOList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); + + if (CollectionUtils.isEmpty(billingPriceVOList)) { + return null; + } + SupStationInfo.PolicyInfo policyInfo = null; + // 获取计费模板 + List policyInfoList = new ArrayList<>(); + for (BillingPriceVO billingPriceVO : billingPriceVOList) { + // 将时段开始时间、电费、服务费信息进行封装 + policyInfo = new SupStationInfo.PolicyInfo(); + String startTime = billingPriceVO.getStartTime() + ":00"; // 00:00:00 格式 + // 需要将中间的冒号去掉,改为 000000 格式 + String replace = StringUtils.replace(startTime, ":", ""); + policyInfo.setStartTime(replace); + policyInfo.setElecFee(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + policyInfo.setServiceFee(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + + policyInfoList.add(policyInfo); + } + stationInfo.setPolicyInfos(policyInfoList); + + stationInfo.setParkType("255"); + stationInfo.setElectricityType(Constants.one); + stationInfo.setBusinessExpandType(Integer.valueOf(pileStationInfo.getAloneApply())); //是否独立报装 //0,否 1,是 + // 报装电源容量 + if (StringUtils.isNotBlank(String.valueOf(pileStationInfo.getCapacity()))) { + stationInfo.setCapacity(pileStationInfo.getCapacity().setScale(2, RoundingMode.HALF_UP)); + } + + // 获取充电桩设备列表 + List pileList = getPileList(pileStationInfo); + // 站点额定总功率 + BigDecimal stationRatedPower = pileList.stream() + .map(EquipmentInfoDTO::getEquipmentPower) + .reduce(BigDecimal.ZERO, BigDecimal::add); + stationInfo.setRatedPower(stationRatedPower.setScale(1, RoundingMode.HALF_UP)); + + stationInfo.setPeriodFee(Constants.one); + stationInfo.setOfficialRunTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileStationInfo.getCreateTime())); + stationInfo.setVideoMonitor(Constants.zero); + if (CollectionUtils.isNotEmpty(pileList)) { + stationInfo.setEquipmentInfosDTO(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("queryStationsInfo result: {}", JSON.toJSONString(map)); + + return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + } + + + + + /** + * 推送站点信息 + * @param stationId 充电站id + * @return + */ + @Override + public String notificationStationInfo(String stationId) { + List stationInfos = new ArrayList<>(); + // 通过id查询站点相关信息 + PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(Long.parseLong(stationId)); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiLinSecretInfo(); + + 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(); + + + // 组装中电联平台所需要的数据格式 + SupStationInfoDTO info = SupStationInfoDTO.builder() + .stationID(stationId) + .operatorID(Constants.OPERATORID_JIANG_SU) + .stationName(pileStationInfo.getStationName()) + .countryCode(pileStationInfo.getCountryCode()) + .areaCode(pileStationInfo.getAreaCode()) + .address(pileStationInfo.getAddress()) + .serviceTel(pileStationInfo.getStationTel()) + + .stationClassification(Constants.one) + .stationType(Integer.valueOf(pileStationInfo.getStationType())) + .stationStatus(Integer.valueOf(pileStationInfo.getStationStatus())) + .parkNums(Integer.valueOf(pileStationInfo.getParkNums())) + .stationLng(new BigDecimal(pileStationInfo.getStationLng()).setScale(6, RoundingMode.HALF_UP)) + .stationLat(new BigDecimal(pileStationInfo.getStationLat()).setScale(6, RoundingMode.HALF_UP)) + .construction(Integer.valueOf(pileStationInfo.getConstruction())) + .roundTheClock(Constants.one)//7*24小时营业 0:否 1:是 + .parkType("255")//0:免费 1:不免费 2:限时免费停车 3:充电限时减免 255:参考场地实际收费标准 + .electricityType(Constants.one) //1:商业用电 2:普通工业用电 3:大工业用电 4:其他用电 + .businessExpandType(Constants.one) + .videoMonitor(Constants.zero) + .equipmentOwnerName(Constants.Equipment_Owner_Name) + .supplyType(Constants.one) + .build(); + + // 报装电源容量 + if (StringUtils.isNotBlank(String.valueOf(pileStationInfo.getCapacity()))) { + info.setCapacity(pileStationInfo.getCapacity().setScale(2, RoundingMode.HALF_UP)); + } + + //获取充电桩设备列表 + List pileList = getPileList(pileStationInfo); + + // 站点额定总功率 + BigDecimal stationRatedPower = pileList.stream() + .map(EquipmentInfoDTO::getEquipmentPower) + .reduce(BigDecimal.ZERO, BigDecimal::add); + info.setRatedPower(stationRatedPower.setScale(1, RoundingMode.HALF_UP)); + info.setPeriodFee(Constants.one); + info.setOfficialRunTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileStationInfo.getCreateTime())); + + // 根据站点id查询正在使用的计费模板 + List billingPriceVOList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); + + if (CollectionUtils.isEmpty(billingPriceVOList)) { + return null; + } + SupStationInfo.PolicyInfo policyInfo = null; + // 获取计费模板 + List policyInfoList = new ArrayList<>(); + for (BillingPriceVO billingPriceVO : billingPriceVOList) { + // 将时段开始时间、电费、服务费信息进行封装 + policyInfo = new SupStationInfo.PolicyInfo(); + String startTime = billingPriceVO.getStartTime() + ":00"; // 00:00:00 格式 + // 需要将中间的冒号去掉,改为 000000 格式 + String replace = StringUtils.replace(startTime, ":", ""); + policyInfo.setStartTime(replace); + policyInfo.setElecFee(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + policyInfo.setServiceFee(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + + policyInfoList.add(policyInfo); + } + info.setPolicyInfos(policyInfoList); + + + String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213 + // 根据逗号分组 + String[] split = StringUtils.split(areaCode, ","); + // 只取最后一部分 330213 + String subAreaCode = split[split.length - 1]; + info.setAreaCode(subAreaCode); + // 获取地理位置编码 + GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(pileStationInfo.getAddress()); + if (geoCode != null) { + //充换电站所在县以下行政区划代码 + info.setAreaCodeCountryside(geoCode.getCounty_code()); + }else{ + info.setAreaCodeCountryside("12345678901"); + } + // 截取运营商组织机构代码(去除最后一位后的最后九位) + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(String.valueOf(pileStationInfo.getMerchantId())); + String organizationCode = merchantInfo.getOrganizationCode(); + + info.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)); + + + // 站点图片 + if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { + info.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(","))); + } + + if (CollectionUtils.isNotEmpty(pileList)) { + info.setEquipmentInfosDTO(pileList); // 充电设备信息列表 + } + stationInfos.add(info); + + // 调用中电联平台接口 + String url = urlAddress + "notification_station_info"; + + JSONObject data = new JSONObject(); + data.put("SupStationInfos", stationInfos); + + String jsonString = JSON.toJSONString(data); + System.out.println("jsonString : " + jsonString); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + + /** + * 设备接口状态查询 query_station_status + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStatus(QueryStationInfoDTO dto) { + List stationIds = dto.getStationIds(); + + List connectorStatusInfos = new ArrayList<>(); + // 查询密钥信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiLinSecretInfo(); + + // 根据站点idList查询枪口列表 + List list = pileConnectorInfoService.batchSelectConnectorList(stationIds); + // 根据站点id分组 + Map> collect = list.stream() + .collect(Collectors.groupingBy(ConnectorInfoVO::getStationId)); + // 封装参数 + for (Map.Entry> entry : collect.entrySet()) { + String stationId = entry.getKey(); + List voList = entry.getValue(); + + PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId); + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + + ConnectorStatusInfo connectorStatusInfo; + for (ConnectorInfoVO connectorInfoVO : voList) { + connectorStatusInfo = ConnectorStatusInfo.builder() + .operatorId(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerId(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) + .stationId(connectorInfoVO.getStationId()) + .equipmentId(connectorInfoVO.getPileSn()) + .connectorID(connectorInfoVO.getPileConnectorCode()) + .equipmentClassification(Constants.one) + .status(Integer.parseInt(connectorInfoVO.getConnectorStatus())) + .updateTime(DateUtils.getDateTime()) + .build(); + connectorStatusInfos.add(connectorStatusInfo); + } + + } + Map map = new LinkedHashMap<>(); + map.put("StationID", stationIds); + map.put("ConnectorStatusInfos", connectorStatusInfos); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + + + /** + * 设备状态推送 + * @param stationId 站点id + * @param pileConnectorCode 充电桩枪口编号 + * @param status + * @param secretInfoVO + * @return + */ + @Override + public String notificationStationStatus(String stationId, String pileConnectorCode, String status, ThirdPartySecretInfoVO secretInfoVO) { + // 查询充电枪口状态 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); + if (Objects.isNull(connectorInfo)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + + String merchantId = connectorInfo.getMerchantId(); + MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId); + if (Objects.isNull(merchantInfoVO)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + + SupConnectorStatusInfo info = SupConnectorStatusInfo.builder() + .operatorID(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode())) + .stationID(connectorInfo.getStationId()) + .equipmentID(connectorInfo.getPileSn()) + .connectorID(pileConnectorCode) + .status(Integer.parseInt(status)) + .updateTime(DateUtils.getDateTime()) + .equipmentClassification(Constants.ONE) + .build(); + + // 调用联联平台接口 + 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 + "notification_station_status"; + + Map map = new LinkedHashMap<>(); + map.put("StationID", connectorInfo.getStationId()); + map.put("ConnectorStatusInfos", info); + String jsonString = JSON.toJSONString(map); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + + + + /** + * 请求设备认证 query equip auth + * @param dto 请求设备认证 + * @return + */ + @Override + public Map queryEquipAuth(QueryEquipmentDTO dto) { + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiLinSecretInfo(); + 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.generateResultMap(vo, thirdPartySecretInfoVO); + } + + + /** + * 查询业务策略 query_equip_business_policy + * @param dto 请求启动充电DTO + * @return + */ + @Override + public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { + List policyInfoList = new ArrayList<>(); + String pileConnectorCode = dto.getConnectorID(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiLinSecretInfo(); + + // 截取桩号 + // 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)) { + throw new BusinessException(ReturnCodeEnum.valueOf("业务策略查询失败")); + } + 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.generateResultMap(vo, thirdPartySecretInfoVO); + } + + + /** + * 请求启动充电 query_start_charge + * @param dto 请求启动充电DTO + * @return + */ + @Override + public Map queryStartCharge(QueryStartChargeDTO dto) { + // 通过传过来的订单号和枪口号生成订单 + QueryStartChargeVO vo = new QueryStartChargeVO(); + int succStat = 0; // 0-失败 1-成功 + int failReasonCode = 0; //失败码 + String failReasonMsg = ""; //失败原因 + + //吉林平台使用orderNo字段接收订单号 + String orderNO = dto.getOrderNO(); + + //设置到原本的订单号字段 + dto.setStartChargeSeq(orderNO); + + //查询充电桩枪口信息 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderNO); + if (Objects.isNull(connectorInfo) || connectorInfo.getStatus() == 255) { + failReasonCode = 1; //此设备不存在(设备已下线或站 点非正常使用状态时,认为设备不存在) + succStat = 1; + failReasonMsg = "没有此设备或设备故障"; + } + if (connectorInfo.getStatus() == 0){ + failReasonCode = 2; //此设备离线 + succStat = 1; + failReasonMsg = "设备离线"; + } + + String pileConnectorCode = dto.getConnectorID(); + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderNO); + if (orderInfo != null) { + return null; + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiLinSecretInfo(); + // 设置最大充电金额 + dto.setAccountBalance(Constants.LIAN_LIAN_MAX_AMOUNT); + // 生成订单 + 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); + + // 拼装对应的数据并返回 + vo.setOrderNo(orderCode); + vo.setOrderStatus(2);//直接给2充电中 + vo.setConnectorID(pileConnectorCode); + vo.setSuccStat(succStat); + vo.setOverTime(1); //充电启动超时时间 + vo.setFailReasonCode(failReasonCode); + vo.setFailReasonMsg(failReasonMsg); + + log.info("返回参数:{}", JSON.toJSONString(vo)); + + return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); + } + + + + /** + * 推送启动充电结果 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 = getJiLinSecretInfo(); + 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(); + + // 推送启动充电结果(调用接口 notification_start_charge_result) + String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_START_CHARGE_RESULT.getValue(); + // 拼装参数 + JSONObject json = new JSONObject(); + json.put("orderNo", orderCode); + json.put("ConnectorID", orderInfo.getPileConnectorCode()); + json.put("orderStatus", 2); // 一定要给 2-充电中 + json.put("StartTime", DateUtils.getDateTime()); // 充电开始时间 + json.put("PushTimeStamp", 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; + } + + + + /** + * 查询充电状态 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 thirdPartySecretInfoVO = getJiLinSecretInfo(); + 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); + } + if(connectorStatus == Integer.parseInt(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue())){ + connectorStatus = Integer.parseInt(PileConnectorDataBaseStatusEnum.FAULT.getValue()); + } + String soc = data.getSOC() == null ? Constants.ZERO : data.getSOC(); + 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(soc)) + .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.generateResultMap(vo, thirdPartySecretInfoVO); + } + + + + + /** + * 订单推送数据封装 + * @param orderBasicInfo + * @param orderDetail + * @return + */ + private ChargeOrderInfo transformChargeOrderInfo(OrderBasicInfo orderBasicInfo , OrderDetail orderDetail) { + PileStationVO stationInfo = pileStationInfoService.getStationInfo(orderBasicInfo.getStationId()); + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + + ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder() + .operatorID(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) + .stationID(orderBasicInfo.getStationId()) + .equipmentID(orderBasicInfo.getPileSn()) + .orderNo(orderBasicInfo.getOrderCode()) + .connectorID(orderBasicInfo.getPileConnectorCode()) + .equipmentClassification(1) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) + .endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())) + .totalPower(orderDetail.getTotalUsedElectricity().setScale(4, RoundingMode.HALF_UP)) + .pushTimeStamp(DateUtils.getDateTime()) + .totalElecMoney(orderDetail.getTotalElectricityAmount().setScale(4, RoundingMode.HALF_UP)) + .totalServiceMoney(orderDetail.getTotalServiceAmount().setScale(4, RoundingMode.HALF_UP)) + .totalMoney(orderDetail.getTotalOrderAmount()) + .stopReason(2) + .stopDesc(orderBasicInfo.getReason()) + .build(); + if (orderBasicInfo.getPlateNumber() != null) { + chargeOrderInfo.setLicensePlate(orderBasicInfo.getPlateNumber()); + } + if (orderBasicInfo.getVinCode() != null) { + chargeOrderInfo.setVin(orderBasicInfo.getVinCode()); + } + if (orderBasicInfo.getStartSoc() != null) { + chargeOrderInfo.setStartSOC(orderBasicInfo.getStartSoc()); + } + if (orderBasicInfo.getEndSoc() != null) { + chargeOrderInfo.setEndSOC(orderBasicInfo.getEndSoc()); + } + return chargeOrderInfo; + } + + + + /** + * 获取配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getJiLinSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + 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; + } + + + + public List getPileList(PileStationInfo pileStationInfo) { + List resultList = new ArrayList<>(); + // 通过站点id查询桩基本信息 + List list = getPileDetailInfoList(String.valueOf(pileStationInfo.getId())); + // 封装成联联平台对象 + for (PileDetailInfoVO pileDetailInfoVO : list) { + EquipmentInfoDTO equipmentInfo = new EquipmentInfoDTO(); + String pileSn = pileDetailInfoVO.getPileSn(); + + equipmentInfo.setEquipmentID(pileSn); + equipmentInfo.setEquipmentUniqueNumber(Constants.OPERATORID_JIANG_SU + pileSn); //设备生产商组织机构代 码 9 位+设备出厂唯一编码 + equipmentInfo.setManufacturerID(Constants.OPERATORID_JIANG_SU); + equipmentInfo.setManufacturerName(Constants.MANUFACTURER_NAME); + + equipmentInfo.setEquipmentPower(new BigDecimal(pileDetailInfoVO.getRatedPower()).setScale(1, RoundingMode.HALF_UP)); + + + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + equipmentInfo.setEquipmentType(Integer.parseInt(modelInfo.getSpeedType())); + equipmentInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, RoundingMode.HALF_UP)); + + List connectorList = getConnectorList(pileDetailInfoVO,pileStationInfo); + equipmentInfo.setConnectorInfos(connectorList); + + equipmentInfo.setConnectorInfos(connectorList); + + resultList.add(equipmentInfo); + } + + return resultList; + } + + public List getPileDetailInfoList(String stationId) { + List pileDetailInfoList = pileBasicInfoMapper.getPileDetailInfoList(stationId); + if (CollectionUtils.isEmpty(pileDetailInfoList)) { + return new ArrayList<>(); + } + List pileSnList = pileDetailInfoList.stream() + .map(PileDetailInfoVO::getPileSn) + .collect(Collectors.toList()); + Map pileStatusV2 = pileConnectorInfoService.getPileStatus(pileSnList); + pileDetailInfoList.forEach(pileDetailInfoVO -> { + String pileSn = pileDetailInfoVO.getPileSn(); + if (pileStatusV2.containsKey(pileSn)) { + pileDetailInfoVO.setPileStatus(pileStatusV2.get(pileSn)); + } + }); + return pileDetailInfoList; + } + + /** + * 获取枪口信息 + * @param pileDetailInfoVO + * @param pileStationInfo + * @return + */ + private List getConnectorList(PileDetailInfoVO pileDetailInfoVO,PileStationInfo pileStationInfo) { + List resultList = new ArrayList<>(); + + List list = pileConnectorInfoService.selectPileConnectorInfoList(pileDetailInfoVO.getPileSn()); + for (PileConnectorInfo pileConnectorInfo : list) { + ConnectorInfoDTO connectorInfo = new ConnectorInfoDTO(); + + 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); + connectorInfo.setVoltageUpperLimits(new BigDecimal(modelInfo.getRatedVoltage()).setScale(1, RoundingMode.HALF_UP)); + connectorInfo.setVoltageLowerLimits(new BigDecimal(modelInfo.getRatedVoltage()).setScale(1, RoundingMode.HALF_UP)); + connectorInfo.setCurrent(new BigDecimal(modelInfo.getRatedCurrent()).setScale(1, RoundingMode.HALF_UP)); + connectorInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); + connectorInfo.setNationalStandard(2); + connectorInfo.setAuxPower(3); + connectorInfo.setOpreateStatus(Integer.valueOf(pileStationInfo.getStationStatus())); + + String parkingLockFlag = pileStationInfo.getParkingLockFlag() == null ? "0" : pileStationInfo.getParkingLockFlag(); + connectorInfo.setHasLock(Integer.valueOf(parkingLockFlag)); //有无地锁 0 无 1 有 + + //查询站点信息,获取二维码前缀 + PileStationVO stationInfo = pileStationInfoService.getStationInfo(String.valueOf(pileStationInfo.getId())); + String pileConnectorCode = pileConnectorInfo.getPileConnectorCode(); + if (StringUtils.isNotBlank(stationInfo.getQrcodePrefix())) { + connectorInfo.setChargingQrCode(stationInfo.getQrcodePrefix()+pileConnectorCode); + } else { + // 为null时,使用默认生成的 + String pileConnectorQrCodeUrl = pileConnectorInfoService.getPileConnectorQrCodeUrl(connectorInfo.getConnectorID()); + connectorInfo.setChargingQrCode(pileConnectorQrCodeUrl+pileConnectorCode); // https://api.jsowellcloud.com/app-xcx-h5/pile/connectorDetail/8825000001536502 + } + + connectorInfo.setEquipmentClassification(Constants.one); + + resultList.add(connectorInfo); + } + + return resultList; + } + + +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java index f96c257b5..5db114d23 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java @@ -282,20 +282,16 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { stationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(","))); } + List priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); StringBuilder electricityFee = new StringBuilder(); StringBuilder serviceFee = new StringBuilder(); - // 查询计费模板 - List priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); + for (BillingPriceVO billingPriceVO : priceList) { - electricityFee.append(billingPriceVO.getStartTime()) - .append("-").append(billingPriceVO.getEndTime()) - .append(":").append(billingPriceVO.getElectricityPrice()) - .append(","); - serviceFee.append(billingPriceVO.getStartTime()) - .append("-").append(billingPriceVO.getEndTime()) - .append(":").append(billingPriceVO.getServicePrice()) - .append(","); + String timeRange = billingPriceVO.getStartTime() + "-" + billingPriceVO.getEndTime() + ":"; + electricityFee.append(timeRange).append(billingPriceVO.getElectricityPrice()).append(","); + serviceFee.append(timeRange).append(billingPriceVO.getServicePrice()).append(","); } + // 去除最后一位的分号 electricityFee.deleteCharAt(electricityFee.length() - 1); serviceFee.deleteCharAt(serviceFee.length() - 1); @@ -337,7 +333,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public String notificationStationInfo(String stationId) { - List stationInfos = new ArrayList<>(); + List stationInfos = new ArrayList<>(); // 通过id查询站点相关信息 PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(Long.parseLong(stationId)); // 查询相关配置信息 @@ -398,19 +394,14 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { info.setOfficialRunTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileStationInfo.getCreateTime())); + List priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); StringBuilder electricityFee = new StringBuilder(); StringBuilder serviceFee = new StringBuilder(); - // 查询计费模板 - List priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); + for (BillingPriceVO billingPriceVO : priceList) { - electricityFee.append(billingPriceVO.getStartTime()) - .append("-").append(billingPriceVO.getEndTime()) - .append(":").append(billingPriceVO.getElectricityPrice()) - .append(","); - serviceFee.append(billingPriceVO.getStartTime()) - .append("-").append(billingPriceVO.getEndTime()) - .append(":").append(billingPriceVO.getServicePrice()) - .append(","); + String timeRange = billingPriceVO.getStartTime() + "-" + billingPriceVO.getEndTime() + ":"; + electricityFee.append(timeRange).append(billingPriceVO.getElectricityPrice()).append(","); + serviceFee.append(timeRange).append(billingPriceVO.getServicePrice()).append(","); } // 去除最后一位的分号 electricityFee.deleteCharAt(electricityFee.length() - 1); @@ -1188,7 +1179,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { connectorInfo.setVoltageLowerLimits(new BigDecimal(pileDetailInfoVO.getRatedVoltage()).setScale(4, RoundingMode.HALF_UP)); connectorInfo.setCurrent(new BigDecimal(pileDetailInfoVO.getRatedCurrent()).setScale(4, RoundingMode.HALF_UP)); connectorInfo.setPower(new BigDecimal(pileDetailInfoVO.getRatedPower()).setScale(4, RoundingMode.HALF_UP)); - connectorInfo.setNationalStandard(StringUtils.equals("1", pileDetailInfoVO.getSpeedType()) ? 12 : 11); + connectorInfo.setNationalStandard(2); connectorInfo.setAuxPower(3); // 3-兼容12V和24V connectorInfo.setOperateStatus(50); // 50-正常使用