diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/BusinessInformationExchangeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/BusinessInformationExchangeEnum.java index 57a5db127..9a9cf44ff 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/BusinessInformationExchangeEnum.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/BusinessInformationExchangeEnum.java @@ -5,6 +5,7 @@ package com.jsowell.common.enums.thirdparty; */ public enum BusinessInformationExchangeEnum { NOTIFICATION_STATION_STATUS("notification_stationStatus", "设备状态变化推送"), + NOTIFICATION_STATION_INFO("notification_stationInfo", "充电站信息变化推送"), NOTIFICATION_CHARGE_ORDER_INFO("notification_charge_order_info", "推送充电订单信息"), NOTIFICATION_START_CHARGE_RESULT("notification_start_charge_result", "推送启动充电结果"), NOTIFICATION_EQUIP_CHARGE_STATUS("notification_equip_charge_status", "推送充电状态"), 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 47a996818..5b4171274 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 @@ -22,6 +22,7 @@ public enum ThirdPlatformTypeEnum { QING_HAI_PLATFORM("11", "青海平台", "630000000"), DIAN_XING_PLATFORM("12", "宁波点行停车平台", ""), NING_XIA_PLATFORM("13", "宁夏平台", ""), + SHEN_ZHEN_PLATFORM("14", "深圳平台", ""), ; private String typeCode; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java index f2911ceae..932b5fe58 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -1049,7 +1049,10 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { equipmentInfo.setEquipmentPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); equipmentInfo.setNewNationalStandard(1); equipmentInfo.setVinFlag(1); + equipmentInfo.setEquipmentName(pileSn); + equipmentInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); + // 枪口列表 List connectorList = getConnectorListForLianLian(pileSn); equipmentInfo.setConnectorInfos(connectorList); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/ConnectorInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/ConnectorInfo.java index 3ad310b00..1d532d1c6 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/ConnectorInfo.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/ConnectorInfo.java @@ -26,7 +26,8 @@ public class ConnectorInfo { /** * 充电设备接口名称 N */ - // private String ConnectorName; + @JSONField(name = "ConnectorName") + private String connectorName; /** * 充电设备接口类型 Y diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java index d40c0a1d9..4509ad0c5 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java @@ -34,12 +34,14 @@ public class EquipmentInfo { * 设备型号 N * 由设备生厂商定义的设备型号 */ - // private String EquipmentModel; + @JSONField(name = "EquipmentModel") + private String equipmentModel; /** * 设备名称 N */ - // private String EquipmentName; + @JSONField(name = "EquipmentName") + private String equipmentName; /** * 设备生产日期 N @@ -109,4 +111,10 @@ public class EquipmentInfo { @JSONField(name = "VinFlag") private Integer vinFlag; + /** + * 设备总功率 + */ + @JSONField(name = "Power") + private BigDecimal power; + } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java index 856cd183c..9de4ed5ee 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java @@ -196,6 +196,11 @@ public class CommonService { insertInfo2DataBase(dto); result = dto.getThirdPartyType() + ":" + "OK"; } + if (StringUtils.equals(ThirdPlatformTypeEnum.DIAN_XING_PLATFORM.getTypeCode(), dto.getThirdPartyType())) { + // 宁波点行平台 + insertInfo2DataBase(dto); + result = ThirdPlatformTypeEnum.DIAN_XING_PLATFORM.getTypeLabel() + ":" + "OK"; + } finalResult.append(result).append("\n"); } return finalResult.toString(); diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/StationInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/StationInfo.java index cd2e34918..58864f9d8 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/StationInfo.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/StationInfo.java @@ -354,4 +354,10 @@ public class StationInfo { @JSONField(name = "ParkingLockFlag") private Integer parkingLockFlag; + /** + * 站点联系电话 + */ + @JSONField(name = "StationTel") + private String stationTel; + } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/ShenZhenPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/ShenZhenPlatformServiceImpl.java new file mode 100644 index 000000000..008b420d6 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/ShenZhenPlatformServiceImpl.java @@ -0,0 +1,197 @@ +package com.jsowell.thirdparty.platform.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.JWTUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.ThirdPartyPlatformConfig; +import com.jsowell.pile.service.PileBasicInfoService; +import com.jsowell.pile.service.PileStationInfoService; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.thirdparty.EquipmentInfo; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; +import com.jsowell.pile.vo.web.PileStationVO; +import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; +import com.jsowell.thirdparty.platform.common.StationInfo; +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.Encodes; +import com.jsowell.thirdparty.platform.util.GBSignUtils; +import com.jsowell.thirdparty.platform.util.HttpRequestUtil; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * 深圳平台 Service + * + * @author Lemon + * @Date 2024/5/14 9:51:12 + */ +@Service +public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService { + + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + Logger logger = LoggerFactory.getLogger(this.getClass()); + + // 平台类型 + private final String thirdPlatformType = ThirdPlatformTypeEnum.SHEN_ZHEN_PLATFORM.getTypeCode(); + + @Override + public void afterPropertiesSet() throws Exception { + ThirdPartyPlatformFactory.register(thirdPlatformType, this); + } + + /** + * 充电站信息变化推送 notification_stationInfo + * @param stationId 充电站id + * @return + */ + @Override + public String notificationStationInfo(String stationId) { + // 根据站点id查询站点资料 + PileStationVO stationVO = pileStationInfoService.getStationInfo(stationId); + if (stationVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + + StationInfo stationInfo = StationInfo.builder() + .stationID(stationVO.getId()) + .operatorID(Constants.OPERATORID_JIANG_SU) + // .equipmentOwnerID() + .stationName(stationVO.getStationName()) + .countryCode(stationVO.getCountryCode()) + .areaCode(stationVO.getAreaCode()) + .address(stationVO.getAddress()) + .stationType(Integer.parseInt(stationVO.getStationType())) + .stationStatus(stationVO.getStationStatus()) + .parkNums(0) // 默认 0:未知 + .stationLng(new BigDecimal(stationVO.getStationLng())) + .stationLat(new BigDecimal(stationVO.getStationLat())) + .construction(Integer.parseInt(stationVO.getConstruction())) + + .build(); + String stationTel = stationVO.getStationTel(); + if (StringUtils.isNotBlank(stationTel)) { + stationInfo.setStationTel(stationTel); + stationInfo.setServiceTel(stationTel); + } + if (StringUtils.isNotBlank(stationVO.getPictures())) { + stationInfo.setPictures(Lists.newArrayList(stationVO.getPictures().split(","))); + } + // 设备信息列表 + List pileList = pileBasicInfoService.getPileListForLianLian(stationId); + stationInfo.setEquipmentInfos(pileList); + + // 获取配置密钥信息 + ThirdPartySecretInfoVO shenZhenSecretInfo = getShenZhenSecretInfo(); + + String operatorId = shenZhenSecretInfo.getTheirOperatorId(); + String operatorSecret = shenZhenSecretInfo.getTheirOperatorSecret(); + String signSecret = shenZhenSecretInfo.getTheirSigSecret(); + String dataSecret = shenZhenSecretInfo.getTheirDataSecret(); + String dataSecretIv = shenZhenSecretInfo.getTheirDataSecretIv(); + String urlAddress = shenZhenSecretInfo.getTheirUrlPrefix(); + String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_INFO.getValue(); + // 发送请求 + String jsonString = JSONObject.toJSONString(stationInfo); + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + /** + * 请求令牌 query_token + * @param dto + * @return + */ + @Override + public Map queryToken(CommonParamsDTO dto) { + String operatorId = dto.getOperatorID(); + // 通过operatorId 查出 相关配置信息 + ThirdPartySecretInfoVO secretInfoVO = getShenZhenSecretInfo(); + if (secretInfoVO == null) { + throw new BusinessException("1", "无此对接平台"); + } + + String operatorSecret = secretInfoVO.getOurOperatorSecret(); + String dataSecret = secretInfoVO.getOurDataSecret(); + String dataSecretIv = secretInfoVO.getOurDataSecretIv(); + String signSecret = secretInfoVO.getOurSigSecret(); + + // 解密data 获取参数中的OperatorSecret + try { + String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); + String inputOperatorSecret = null; + if (StringUtils.isNotBlank(decrypt)) { + inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); + } + if (!StringUtils.equals(operatorSecret, inputOperatorSecret)) { + throw new RuntimeException("密钥不一致"); + } + } catch (RuntimeException e) { + throw new BusinessException("2", "密钥错误"); + } + + // 生成token + String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis); + + // 组装返回参数 + AccessTokenVO vo = new AccessTokenVO(); + vo.setAccessToken(token); + vo.setOperatorID(operatorId); + vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); + vo.setFailReason(0); + vo.setSuccStat(0); + + Map resultMap = Maps.newLinkedHashMap(); + // 加密数据 + byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(), + dataSecret.getBytes(), dataSecretIv.getBytes()); + String encryptData = Encodes.encodeBase64(encryptText); // data + resultMap.put("Ret", "0"); + resultMap.put("Msg", "请求令牌成功!"); + resultMap.put("Data", encryptData); + // 生成sig + String resultSign = GBSignUtils.sign(resultMap, signSecret); + resultMap.put("Sig", resultSign); + + return resultMap; + } + + + /** + * 获取深圳平台相关密钥信息 + * @return + */ + private ThirdPartySecretInfoVO getShenZhenSecretInfo() { + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.SHEN_ZHEN_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + return thirdPartySecretInfoVO; + } +}