mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-08 12:00:11 +08:00
update
This commit is contained in:
178
jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanController.java
vendored
Normal file
178
jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanController.java
vendored
Normal file
@@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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("设备接口状态查询发生异常");
|
||||
}
|
||||
}
|
||||
@@ -72,4 +72,6 @@ public class QueryStationInfoDTO {
|
||||
|
||||
|
||||
private String address;
|
||||
|
||||
private String thirdPlatformType;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ public interface ThirdPartyStationRelationService {
|
||||
*/
|
||||
public List<ThirdPartyStationRelation> selectThirdPartyStationRelationList(ThirdPartyStationRelation thirdPartyStationRelation);
|
||||
|
||||
List<ThirdPartyStationRelation> selectThirdPartyStationRelationList(String thirdPlatformType);
|
||||
|
||||
/**
|
||||
* 通过站点id查询相关配置信息
|
||||
* @param stationId 站点id String类型
|
||||
|
||||
@@ -43,6 +43,13 @@ public class ThirdPartyStationRelationServiceImpl implements ThirdPartyStationRe
|
||||
return thirdPartyStationRelationMapper.selectThirdPartyStationRelationList(thirdPartyStationRelation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdPartyStationRelation> selectThirdPartyStationRelationList(String thirdPlatformType) {
|
||||
ThirdPartyStationRelation thirdPartyStationRelation = new ThirdPartyStationRelation();
|
||||
thirdPartyStationRelation.setThirdPartyType(thirdPlatformType);
|
||||
return this.selectThirdPartyStationRelationList(thirdPartyStationRelation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过站点id查询相关配置信息
|
||||
* @param stationId 站点id String类型
|
||||
|
||||
@@ -59,6 +59,17 @@ public class HaiNanChargeService extends AbsInterfaceWithPlatformLogic {
|
||||
* 6.2 查询充电站信息
|
||||
*/
|
||||
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
|
||||
// 查询出要查询的充电站id并set进 dto 的stationIds
|
||||
if (StringUtils.isNotBlank(dto.getThirdPlatformType())) {
|
||||
List<ThirdPartyStationRelation> xdtList = relationService.selectThirdPartyStationRelationList(dto.getThirdPlatformType());
|
||||
if (CollectionUtils.isNotEmpty(xdtList)) {
|
||||
List<String> stationList = xdtList.stream()
|
||||
.map(x -> String.valueOf(x.getStationId()))
|
||||
.collect(Collectors.toList());
|
||||
dto.setStationIds(stationList);
|
||||
}
|
||||
}
|
||||
|
||||
List<ZDLStationInfo> resultList = new ArrayList<>();
|
||||
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
|
||||
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
|
||||
|
||||
@@ -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<String, String> generateToken(CommonParamsDTO dto) {
|
||||
public Map<String, String> 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<String, String> checkoutSign(CommonParamsDTO dto){
|
||||
public Map<String, String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user