微网快电第三方接口

This commit is contained in:
YAS\29473
2025-04-22 16:00:47 +08:00
parent ca9d990139
commit 9ec21ab817
5 changed files with 1561 additions and 0 deletions

View File

@@ -0,0 +1,494 @@
package com.jsowell.api.thirdparty;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.common.NotificationDTO;
import com.jsowell.thirdparty.common.NotificationService;
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.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* 微网快电Controller
*/
@Anonymous
@RestController
@RequestMapping("/weiwangkuaidian")
public class WeiWangKuaiDianController extends ThirdPartyBaseController {
private final String platformName = "微网快电";
private final String platformType = ThirdPlatformTypeEnum.WEI_WANG_XIN_DIAN.getTypeCode();
@Autowired
@Qualifier("weiWangKuaiDianPlatformServiceImpl")
private ThirdPartyPlatformService platformLogic;
@Autowired
private NotificationService notificationService;
/**
* getToken
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("{}-请求令牌 params:{}", platformName, JSON.toJSONString(dto));
try {
Map<String, String> 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);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStationsInfo(queryStationInfoDTO);
return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("{}-查询充电站信息 error:", platformName, e);
}
return CommonResult.failed("查询充电站信息发生异常");
}
/**
* 设备状态推送
* notification_stationStatus
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/notification_stationStatus")
public CommonResult<?> notification_stationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("{}-设备状态推送 params:{}", platformName, JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
PushRealTimeInfoDTO pushRealTimeInfoDTO = parseParamsDTO(dto, PushRealTimeInfoDTO.class);
// 执行逻辑
String result = platformLogic.notificationStationStatus(pushRealTimeInfoDTO);
return CommonResult.success(Integer.parseInt(result.split(",")[0]), result.split(",")[1], result.split(",")[2], result.split(",")[3]);
} catch (Exception e) {
logger.info("{}-设备状态推送 error:", platformName, e);
}
return CommonResult.failed("设备状态推送发生异常");
}
/**
* 设备接口状态查询 query_station_status
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_station_status")
public CommonResult<?> query_stations_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("{}-设备接口状态查询 params:{}", platformName, JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStationStatus(queryStationInfoDTO);
return CommonResult.success(0, "设备接口状态查询成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("{}-设备接口状态查询 error:", platformName, e);
}
return CommonResult.failed("设备接口状态查询发生异常");
}
/**
* 统计信息查询 query_station_stats
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_station_stats")
public CommonResult<?> query_station_stats(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("{}-查询统计信息 params:{}", platformName, JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto, QueryStationInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStationStats(queryStationInfoDTO);
return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("{}-查询统计信息 error:", platformName, e);
}
return CommonResult.failed("查询统计信息发生异常");
}
/**
* 请求设备认证
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_auth")
public CommonResult<?> query_equip_auth(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);
}
// 解析入参
QueryEquipmentDTO queryEquipmentDTO = parseParamsDTO(dto, QueryEquipmentDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryEquipAuth(queryEquipmentDTO);
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("请求设备认证发生异常");
}
/**
* 查询业务策略信息
* @param dto
*/
@RequestMapping("/v1/query_equip_business_policy")
public CommonResult<?> query_equip_business_policy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("{}-查询业务策略信息 params:{}", platformName, JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryEquipBusinessPolicy(queryStartChargeDTO);
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("查询业务策略信息发生异常");
}
/**
* 请求启动充电
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_start_charge")
public CommonResult<?> query_start_charge(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);
}
// 解析入参
QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStartCharge(queryStartChargeDTO);
logger.info("{}-请求启动充电 result:{}", platformName, map);
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("请求启动充电发生异常");
}
/**
* 推送启动充电结果
* @param
* @return
*/
@GetMapping("/v1/notification_start_charge_result")
public RestApiResponse<?> notificationStartChargeResult(@RequestParam("orderCode") String orderCode) {
logger.info("【{}】推送启动充电结果 params:{}", this.getClass().getSimpleName(), orderCode);
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationStartChargeResult(orderCode);
response = new RestApiResponse<>(result);
}catch (BusinessException e) {
logger.error("【{}】推送启动充电结果 error",this.getClass().getSimpleName(), e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.error("【{}】推送启动充电结果 error", this.getClass().getSimpleName(), e);
response = new RestApiResponse<>(e);
}
logger.info("【{}】推送启动充电结果 result:{}", this.getClass().getSimpleName(), response);
return response;
}
/**
* 查询充电状态
* http://localhost:8080/xindiantu/query_equip_charge_status/{startChargeSeq}
* @param dto
* @return
*/
@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<String, String> 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("查询充电状态发生异常");
}
/**
* 推送充电状态
* http://localhost:8080/hainan/notificationEquipChargeStatus
* @param orderCode
* @return
*/
@GetMapping("/notificationEquipChargeStatus/{orderCode}")
public RestApiResponse<?> notificationEquipChargeStatus(@PathVariable("orderCode") String orderCode) {
logger.info("推送充电状态 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationEquipChargeStatus(orderCode);
response = new RestApiResponse<>(result);
}catch (BusinessException e) {
logger.error("推送充电状态 error",e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.error("推送充电状态 error", e);
response = new RestApiResponse<>(e);
}
logger.info("推送充电状态 result:{}", response);
return response;
}
/**
* 请求停止充电
*
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_stop_charge")
public CommonResult<?> query_stop_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("{}-请求停止充电 params :{}", platformName, JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto, QueryStartChargeDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStopCharge(queryStartChargeDTO);
return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("{}-请求停止充电 error", platformName, e);
}
return CommonResult.failed("{}-请求停止充电发生异常");
}
/**
* 推送停止充电结果
* http://localhost:8080/hainan/notificationStopChargeResult
* @param orderCode
* @return
*/
@GetMapping("/notificationStopChargeResult/{orderCode}")
public RestApiResponse<?> notificationStopChargeResult(@PathVariable("orderCode") String orderCode) {
logger.info("推送停止充电结果 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationStopChargeResult(orderCode);
response = new RestApiResponse<>(result);
}catch (BusinessException e) {
logger.error("推送停止充电结果 error",e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.error("推送停止充电结果 error", e);
response = new RestApiResponse<>(e);
}
logger.info("推送停止充电结果 result:{}", response);
return response;
}
/**
* 充电订单信息推送
*/
@PostMapping("/notificationChargeOrderInfo")
public AjaxResult notificationChargeOrderInfo(@RequestBody NotificationDTO dto) {
AjaxResult result;
try {
notificationService.notificationChargeOrderInfo(dto);
result = AjaxResult.success();
} catch (BusinessException e) {
logger.error("充电订单信息推送失败", e);
result = AjaxResult.error(e.getMessage());
} catch (Exception e) {
logger.error("充电订单信息推送失败", e);
result = AjaxResult.error();
}
return result;
}
//TODO 接口待完善
@PostMapping("/v1/check_charge_orders/{orderCode}")
public RestApiResponse<?> checkChargeOrders(@PathVariable String orderCode) {
logger.info("{}-检查充电订单 params:{}", platformName, JSON.toJSONString(orderCode));
RestApiResponse<?> response = null;
try {
String result = platformLogic.checkChargeOrders(orderCode);
response = new RestApiResponse<>(result);
}catch (BusinessException e) {
logger.error("{}-检查充电订单 error", platformName, e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.error("{}-检查充电订单 error", platformName, e);
response = new RestApiResponse<>(e);
}
logger.info("{}-检查充电订单 result:{}", platformName, response);
return response;
}
}