From a094a866d0537347c688964aa19ba543d72b4bb5 Mon Sep 17 00:00:00 2001 From: Lemon Date: Sat, 11 Jan 2025 16:06:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=96=B0=E8=BF=90?= =?UTF-8?q?=E5=BE=AE=E5=B9=B3=E5=8F=B0Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XinYunWeiPlatformController.java | 191 ++++++++++++++++++ .../thirdparty/ThirdPlatformTypeEnum.java | 2 +- ...java => XinYunWeiPlatformServiceImpl.java} | 20 +- 3 files changed, 202 insertions(+), 11 deletions(-) create mode 100644 jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XinYunWeiPlatformController.java rename jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/{XinYunPlatformServiceImpl.java => XinYunWeiPlatformServiceImpl.java} (98%) diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XinYunWeiPlatformController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XinYunWeiPlatformController.java new file mode 100644 index 000000000..2404fd43e --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/XinYunWeiPlatformController.java @@ -0,0 +1,191 @@ +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.pile.dto.QueryEquipChargeStatusDTO; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * 新运微平台Controller + * + * @author Lemon + * @Date 2025/1/11 15:55:34 + */ +@Anonymous +@RestController +@RequestMapping("/xinyunwei") +public class XinYunWeiPlatformController extends ThirdPartyBaseController{ + private final String platformName = "新运微平台"; + + private final String platformType = ThirdPlatformTypeEnum.XIN_YUN_WEI_PLATFORM.getTypeCode(); + + @Autowired + @Qualifier("xinYunWeiPlatformServiceImpl") + 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("{}-请求令牌, 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); + } + dto.setPlatformType(platformType); + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationsInfo(queryStationInfoDTO); + + 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("查询充电站信息发生异常"); + } + + /** + * 查询充电站状态信息 + * query_station_status + */ + @PostMapping("/v1/query_station_status") + public CommonResult queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询充电站状态信息 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + dto.setPlatformType(platformType); + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationStatus(queryStationInfoDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("{}-查询充电站状态信息 error:", platformName, e); + } + return CommonResult.failed("查询充电站状态信息发生异常"); + } + + /** + * 查询充电站统计信息 + * query_station_stats + */ + @PostMapping("/v1/query_station_stats") + public CommonResult queryStationStats(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询充电站统计信息 params:{}", platformName, JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + dto.setPlatformType(platformType); + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationStats(queryStationInfoDTO); + + return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("{}-查询充电站统计信息 error:", platformName, e); + } + return CommonResult.failed("查询充电站统计信息发生异常"); + } + + /** + * 查询充电状态 + * query_equip_charge_status + */ + @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("查询充电状态发生异常"); + } +} 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 c12f189ca..0c0701a67 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 @@ -30,7 +30,7 @@ public enum ThirdPlatformTypeEnum { NAN_RUI_PLATFORM("19", "南瑞平台", ""), GUANG_XI_PLATFORM("20", "广西平台", "450000000"), - XIN_YUN_PLATFORM("21", "新运平台", ""), + XIN_YUN_WEI_PLATFORM("21", "新运微平台", ""), ; private String typeCode; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunWeiPlatformServiceImpl.java similarity index 98% rename from jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunPlatformServiceImpl.java rename to jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunWeiPlatformServiceImpl.java index 87ca6217e..40b7e8758 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinYunWeiPlatformServiceImpl.java @@ -60,7 +60,7 @@ import java.util.stream.Collectors; * @Date 2025/1/10 8:28:43 */ @Service -public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { +public class XinYunWeiPlatformServiceImpl implements ThirdPartyPlatformService { @Autowired private PileStationInfoService pileStationInfoService; @@ -80,7 +80,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { private RedisCache redisCache; // 平台类型 - private final String thirdPlatformType = ThirdPlatformTypeEnum.XIN_YUN_PLATFORM.getTypeCode(); + private final String thirdPlatformType = ThirdPlatformTypeEnum.XIN_YUN_WEI_PLATFORM.getTypeCode(); @Override public void afterPropertiesSet() throws Exception { @@ -104,7 +104,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { // token缓存key值 String redisKey = operatorId + "_token:"; // 通过operatorId 查出 operatorSecret - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunWeiPlatformSecretInfo(); if (thirdPartySecretInfoVO == null) { failReason = 1; succStat = 1; @@ -164,7 +164,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { return null; } // ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunWeiPlatformSecretInfo(); PageInfo pageInfo = new PageInfo<>(stationInfos); List resultList = new ArrayList<>(); for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { @@ -231,7 +231,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { List stationIds = dto.getStationIds(); List StationStatusInfos = new ArrayList<>(); List ConnectorStatusInfos = new ArrayList<>(); - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunWeiPlatformSecretInfo(); ConnectorStatusInfo connectorStatusInfo; for (String stationId : stationIds) { @@ -299,7 +299,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public Map queryStationStats(QueryStationInfoDTO dto) { - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunWeiPlatformSecretInfo(); // 根据站点id 查出这段时间的充电量 List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); if (CollectionUtils.isEmpty(list)) { @@ -390,7 +390,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { if (orderInfo == null) { return null; } - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunWeiPlatformSecretInfo(); OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); // 通过订单号查询实时数据 List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); @@ -454,7 +454,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public String notificationStationStatus(String stationId, String pileConnectorCode, String status, ThirdPartySecretInfoVO secretInfoVO) { - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunWeiPlatformSecretInfo(); String operatorId = Constants.OPERATORID_JIANG_SU; String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); @@ -512,7 +512,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { BigDecimal voltage = realTimeMonitorData.getOutputVoltage() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputVoltage()); String soc = realTimeMonitorData.getSOC() == null ? Constants.ZERO : realTimeMonitorData.getSOC(); // 查询相关配置信息 - ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunPlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinYunWeiPlatformSecretInfo(); String operatorId = Constants.OPERATORID_JIANG_SU; String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); @@ -621,7 +621,7 @@ public class XinYunPlatformServiceImpl implements ThirdPartyPlatformService { * * @return */ - private ThirdPartySecretInfoVO getXinYunPlatformSecretInfo() { + private ThirdPartySecretInfoVO getXinYunWeiPlatformSecretInfo() { // 通过第三方平台类型查询相关配置信息 ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); if (thirdPartySecretInfoVO == null) {