新增 青海平台推送站点实时功率接口

This commit is contained in:
Lemon
2024-04-19 11:15:48 +08:00
parent c76cbf3c07
commit 9cf000a2d9
4 changed files with 190 additions and 14 deletions

View File

@@ -0,0 +1,151 @@
package com.jsowell.web.controller.thirdparty.qinghai;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
import com.jsowell.pile.dto.QueryStartChargeDTO;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.pile.service.ThirdPartyPlatformConfigService;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.platform.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
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.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
/**
* 青海平台Controller
*
* @author Lemon
* @Date 2024/4/18 13:46:26
*/
@Anonymous
@RestController
@RequestMapping("/qinghai")
public class QingHaiController extends BaseController {
@Autowired
@Qualifier("qingHaiPlatformServiceImpl")
private ThirdPartyPlatformService qingHaiPlatformServiceImpl;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
/**
* 获取token接口
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("青海平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
// Map<String, String> map = lianLianService.generateToken(dto);
Map<String, String> map = qingHaiPlatformServiceImpl.queryToken(dto);
logger.info("青海平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("获取token接口 异常");
return CommonResult.failed("获取token发生异常");
}
}
/**
* 查询充电站信息
* @param dto
*/
@RequestMapping("/v1/query_stations_info")
public CommonResult<?> query_stations_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("青海平台查询充电站信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 查询配置信息
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
String operatorSecret = platformConfig.getOperatorSecret();
String dataString = dto.getData();
String dataSecret = platformConfig.getDataSecret();
String dataSecretIV = platformConfig.getDataSecretIv();
// 解密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<String, String> map = qingHaiPlatformServiceImpl.queryStationsInfo(queryStationInfoDTO);
return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("青海平台查询充电站信息 error", e);
}
return CommonResult.failed("查询充电站信息异常");
}
/**
* 查询业务策略信息
* @param dto
*/
@RequestMapping("/v1/query_equip_business_policy")
public CommonResult<?> query_equip_business_policy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("青海平台查询业务策略信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 查询配置信息
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
String operatorSecret = platformConfig.getOperatorSecret();
String dataString = dto.getData();
String dataSecret = platformConfig.getDataSecret();
String dataSecretIV = platformConfig.getDataSecretIv();
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = qingHaiPlatformServiceImpl.queryEquipBusinessPolicy(queryStartChargeDTO);
return CommonResult.success(0, "查询业务策略信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("青海平台查询业务策略信息 error", e);
}
return CommonResult.failed("查询业务策略信息异常");
}
/**
* 推送站点功率
* @param stationIds
* @return
*/
@PostMapping("/pushStationPower")
public RestApiResponse<?> pushStationPower(List<String> stationIds) {
RestApiResponse<?> response = null;
try {
String result = qingHaiPlatformServiceImpl.notificationPowerInfo(stationIds);
response = new RestApiResponse<>(result);
}catch (Exception e) {
logger.error("青海平台推送站点功率 error", e);
}
logger.info("青海平台推送站点功率 result:{}", response);
return response;
}
}