diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanController.java new file mode 100644 index 000000000..af21b504e --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanController.java @@ -0,0 +1,178 @@ +package com.jsowell.web.controller.thirdparty.hainan; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.util.JWTUtils; +import com.jsowell.pile.dto.QueryStationInfoDTO; +import com.jsowell.thirdparty.hainan.service.HaiNanChargeService; +import com.jsowell.thirdparty.lianlian.common.CommonResult; +import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO; +import com.jsowell.thirdparty.lianlian.util.Cryptos; +import com.jsowell.thirdparty.lianlian.util.Encodes; +import com.jsowell.thirdparty.platform.AbsInterfaceWithPlatformLogic; +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.nio.charset.StandardCharsets; +import java.util.Map; + +/** + * 海南 + */ +@Anonymous +@RestController +@RequestMapping("/hainan") +public class HaiNanController extends BaseController { + AbsInterfaceWithPlatformLogic platformLogic = new HaiNanChargeService(); + + /** + * 获取token接口 + * http://localhost:8080/hainan/v1/query_token + */ + @PostMapping("/v1/query_token") + public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { + logger.info("海南平台请求令牌 params:{}", JSONObject.toJSONString(dto)); + try { + Map map = platformLogic.generateToken(dto); + logger.info("海南平台请求令牌 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("海南平台 请求令牌接口 异常"); + return CommonResult.failed("获取token发生异常"); + } + } + + /** + * 海南平台查询充电站信息 + * http://localhost:8080/hainan/v1/query_stations_info + * @param dto + * @return + */ + @PostMapping("/v1/query_stations_info") + public CommonResult query_stations_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("海南平台查询充电站信息 params:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); + queryStationInfoDTO.setOperatorId(dto.getOperatorID()); + queryStationInfoDTO.setThirdPlatformType(ThirdPlatformTypeEnum.HAI_NAN.getCode()); + Map map = platformLogic.queryStationsInfo(queryStationInfoDTO); + logger.info("海南平台查询充电站信息 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("海南平台查询充电站信息 error:", e); + } + return CommonResult.failed("查询充电站信息发生异常"); + } + + /** + * 海南平台查询统计信息 + * http://localhost:8080/hainan/v1/query_stations_stats + * @param dto + * @return + */ + @PostMapping("/v1/query_station_stats") + public CommonResult queryStationStats(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("海南平台查询统计信息 params:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); + queryStationInfoDTO.setOperatorId(dto.getOperatorID()); + Map map = platformLogic.queryStationStats(queryStationInfoDTO); + logger.info("海南平台查询统计信息 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("海南平台查询统计信息 error:", e); + // e.printStackTrace(); + } + return CommonResult.failed("查询统计信息发生异常"); + } + + /** + * 海南平台设备接口状态查询 + * http://localhost:8080/hainan/v1/query_stations_status + * @param dto + * @return + */ + @PostMapping("/v1/query_station_status") + public CommonResult queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("海南平台设备接口状态查询 params:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); + queryStationInfoDTO.setOperatorId(dto.getOperatorID()); + Map map = platformLogic.queryStationStatus(queryStationInfoDTO); + logger.info("海南平台设备接口状态查询 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "设备接口状态查询成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("海南平台设备接口状态查询 error:", e); + // e.printStackTrace(); + } + return CommonResult.failed("设备接口状态查询发生异常"); + } +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStationInfoDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStationInfoDTO.java index 036c2a9ad..3f2819529 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStationInfoDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryStationInfoDTO.java @@ -72,4 +72,6 @@ public class QueryStationInfoDTO { private String address; + + private String thirdPlatformType; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyStationRelationService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyStationRelationService.java index 20f4cd284..d4afd8826 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyStationRelationService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyStationRelationService.java @@ -28,6 +28,8 @@ public interface ThirdPartyStationRelationService { */ public List selectThirdPartyStationRelationList(ThirdPartyStationRelation thirdPartyStationRelation); + List selectThirdPartyStationRelationList(String thirdPlatformType); + /** * 通过站点id查询相关配置信息 * @param stationId 站点id String类型 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyStationRelationServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyStationRelationServiceImpl.java index 00fa5311d..88088f74d 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyStationRelationServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyStationRelationServiceImpl.java @@ -43,6 +43,13 @@ public class ThirdPartyStationRelationServiceImpl implements ThirdPartyStationRe return thirdPartyStationRelationMapper.selectThirdPartyStationRelationList(thirdPartyStationRelation); } + @Override + public List selectThirdPartyStationRelationList(String thirdPlatformType) { + ThirdPartyStationRelation thirdPartyStationRelation = new ThirdPartyStationRelation(); + thirdPartyStationRelation.setThirdPartyType(thirdPlatformType); + return this.selectThirdPartyStationRelationList(thirdPartyStationRelation); + } + /** * 通过站点id查询相关配置信息 * @param stationId 站点id String类型 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/hainan/service/HaiNanChargeService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/hainan/service/HaiNanChargeService.java index b13db9724..edef36d6c 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/hainan/service/HaiNanChargeService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/hainan/service/HaiNanChargeService.java @@ -59,6 +59,17 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic { * 6.2 查询充电站信息 */ public Map queryStationsInfo(QueryStationInfoDTO dto) { + // 查询出要查询的充电站id并set进 dto 的stationIds + if (StringUtils.isNotBlank(dto.getThirdPlatformType())) { + List xdtList = relationService.selectThirdPartyStationRelationList(dto.getThirdPlatformType()); + if (CollectionUtils.isNotEmpty(xdtList)) { + List stationList = xdtList.stream() + .map(x -> String.valueOf(x.getStationId())) + .collect(Collectors.toList()); + dto.setStationIds(stationList); + } + } + List resultList = new ArrayList<>(); int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/AbsInterfaceWithPlatformLogic.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/AbsInterfaceWithPlatformLogic.java index e9bee8214..dd7fda568 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/AbsInterfaceWithPlatformLogic.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/AbsInterfaceWithPlatformLogic.java @@ -54,6 +54,9 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean @Autowired protected PileConnectorInfoService pileConnectorInfoService; + @Autowired + protected ThirdPartyStationRelationService relationService; + @Autowired protected PileModelInfoService pileModelInfoService; @@ -154,7 +157,7 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean /** * 身份认证 */ - protected Map generateToken(CommonParamsDTO dto) { + public Map generateToken(CommonParamsDTO dto) { String operatorID = dto.getOperatorID(); // 通过operatorID 查出 operatorSecret ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID); @@ -188,7 +191,6 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean // 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w long ttlMillis = 60 * 60 * 24 * 1000; String token = JWTUtils.createToken(operatorID, operatorSecret, ttlMillis); - // System.out.println("生成的token:" + token); // 组装返回参数 AccessTokenVO vo = new AccessTokenVO(); @@ -212,7 +214,7 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean return resultMap; } - protected Map checkoutSign(CommonParamsDTO dto){ + public Map checkoutSign(CommonParamsDTO dto){ String operatorID = dto.getOperatorID(); // 通过operatorID 查出 operatorSecret ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID); @@ -317,7 +319,6 @@ public abstract class AbsInterfaceWithPlatformLogic implements InitializingBean resultList.add(connectorInfo); } - return resultList; } }