update 接口格式

This commit is contained in:
Guoqs
2024-05-10 15:30:20 +08:00
parent 68f4b8c651
commit 09a32ab467
17 changed files with 18 additions and 30 deletions

View File

@@ -0,0 +1,75 @@
package com.jsowell.api.thirdparty;
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.pile.dto.QueryPileDTO;
import com.jsowell.pile.dto.amap.GetStationInfoDTO;
import com.jsowell.thirdparty.amap.common.AMapCommonResult;
import com.jsowell.thirdparty.amap.domain.AMapStationInfo;
import com.jsowell.thirdparty.amap.service.AMapService;
import com.jsowell.thirdparty.amap.util.AMapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* TODO
*
* @author Lemon
* @Date 2023/6/16 13:56
*/
@Anonymous
@RestController
@RequestMapping("/charging")
public class AMapController extends BaseController {
@Autowired
private AMapService aMapService;
@PostMapping("/queryStationInfo")
public AMapCommonResult queryStationInfo(@RequestParam Map<String, String> requestMap) {
AMapCommonResult result = new AMapCommonResult();
String paramString = JSON.toJSONString(requestMap);
logger.info("高德拉取充电站静态数据 params:{}", paramString);
try {
// Map map = JSON.parseObject(paramString, Map.class);
// Map<String, String> paramMap = (Map<String, String>)JSON.parse(paramString);
if (AMapUtils.checkSign(requestMap)) {
// true 验签成功
String bizContent = requestMap.get("biz_content");
GetStationInfoDTO dto = JSON.parseObject(bizContent, GetStationInfoDTO.class);
// List<AMapStationInfo> stationInfos = aMapService.getStationInfos(dto);
List<AMapStationInfo> stationInfos = aMapService.getStationInfosV2(dto);
result = result.successResponse(stationInfos);
// logger.info("高德拉取充电站静态数据 success 业务参数:{}", JSON.toJSONString(stationInfos));
logger.info("高德拉取充电站静态数据 success result:{}", JSON.toJSONString(result));
return result;
}
} catch (Exception e) {
logger.error("高德拉取充电站静态数据 error", e);
return result.failedResponse();
}
logger.error("高德拉取充电站静态数据验签失败");
return result.checkSignFailed();
// logger.info("高德拉取充电站静态数据 result:{}", );
}
@PostMapping("/pushStationStatus")
public AMapCommonResult pushStationStatus(@RequestBody QueryPileDTO dto) {
AMapCommonResult result = new AMapCommonResult();
logger.info("商家推送充电设备动态数据 params:{}", JSON.toJSONString(dto));
try {
String pushResult = aMapService.pushChargingDeviceDynamics(dto.getStationId());
return result.successResponse(pushResult);
} catch (Exception e) {
logger.error("商家推送充电设备动态数据 error", e);
}
return result.failedResponse();
}
}

View File

@@ -0,0 +1,76 @@
package com.jsowell.api.thirdparty;
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.netty.service.camera.CameraBusinessService;
import com.jsowell.pile.dto.camera.CameraHeartBeatDTO;
import com.jsowell.pile.dto.camera.SendMsg2TopicDTO;
import com.jsowell.thirdparty.camera.common.CameraCommonResult;
import com.jsowell.service.CameraService;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* 充电相机 controller
*
* @author Lemon
* @Date 2023/12/5 9:06:53
*/
@Anonymous
@RestController
@RequestMapping("/camera")
public class CameraController extends BaseController {
@Autowired
private CameraService cameraService;
@Autowired
private CameraBusinessService cameraBusinessService;
/**
* 心跳
* @param dto
*/
@PostMapping("/v1/receiveHeartBeat")
public CameraCommonResult receiveHeartBeat(@RequestBody CameraHeartBeatDTO dto) {
logger.info("接收相机系统心跳包 params:{}", JSON.toJSONString(dto));
cameraService.saveHeartBeat2Redis(dto);
CameraCommonResult result = new CameraCommonResult();
logger.info("接收相机系统心跳包 result:{}", JSON.toJSONString(result.successResponse()));
return result.successResponse();
}
/**
* 识别结果
* @param jsonObject
*/
@PostMapping("/v1/receiveIdentifyResults")
public CameraCommonResult receiveIdentifyResults(@RequestBody JSONObject jsonObject) {
logger.info("相机系统接收识别结果 params:{}", jsonObject);
CameraCommonResult result = new CameraCommonResult();
try {
// 调用service方法处理
cameraService.receiveIdentifyResults(jsonObject);
} catch (Exception e) {
logger.error("相机系统接收识别结果 error,", e);
}
return result.successResponse();
}
/**
* 给某个 Topic 发消息
* @param dto
*/
@PostMapping("/sendMsg2Topic")
public void sendMsg2Topic(@RequestBody SendMsg2TopicDTO dto) {
try {
cameraService.sendMsg2Topic(dto.getSn(), dto.getMsgType(), dto.getMsgPrefix(), dto.getTopic(), dto.getMsgData());
} catch (Exception e) {
logger.error("发送消息 error, ", e);
}
}
}

View File

@@ -0,0 +1,47 @@
package com.jsowell.api.thirdparty;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.thirdparty.platform.ThirdPartyPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
/**
* 宁波电刑平台
*
* @author Lemon
* @Date 2024/5/10 9:21:59
*/
@Anonymous
@RestController
@RequestMapping("/dianxing")
public class DianXingPlatformController extends BaseController {
@Autowired
@Qualifier("dianXingPlatformServiceImpl")
private ThirdPartyPlatformService dianXingService;
/**
* 推送充电记录
* @param orderCode
* @return
*/
@GetMapping("/pushChargeRecord/{orderCode}")
public RestApiResponse<?> pushChargeRecordInfo(@PathVariable("orderCode") String orderCode) {
RestApiResponse<?> response = null;
try {
String result = dianXingService.notificationChargeOrderInfo(orderCode);
response = new RestApiResponse<>(result);
} catch (BusinessException e) {
logger.error("点行平台推送充电记录 error:{}, {}", e.getCode(), e.getMessage());
response = new RestApiResponse<>(e);
} catch (Exception e) {
logger.error("点行平台推送充电记录 error", e);
}
logger.info("点行平台推送充电记录 result:{}", response);
return response;
}
}

View File

@@ -0,0 +1,525 @@
package com.jsowell.api.thirdparty;
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.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
import com.jsowell.pile.dto.QueryEquipChargeStatusDTO;
import com.jsowell.pile.dto.QueryEquipmentDTO;
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.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.platform.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.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 海南
*/
@Anonymous
@RestController
@RequestMapping("/hainan")
public class HaiNanPlatformController extends BaseController {
// 使用海南平台处理逻辑
// @Autowired
// private AbsInterfaceWithPlatformLogic platformLogic = new HaiNanPlatformLogic();
@Autowired
@Qualifier("haiNanPlatformServiceImpl")
private ThirdPartyPlatformService platformLogic;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
/**
* 获取token接口
* http://localhost:8080/hainan/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("海南平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = platformLogic.queryToken(dto);
logger.info("海南平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("海南平台 请求令牌接口 异常", e);
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:{}", JSON.toJSONString(dto));
try {
// 校验令牌
// String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
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");
// 查询配置信息
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());
queryStationInfoDTO.setThirdPlatformType(ThirdPlatformTypeEnum.HAI_NAN_1_PLATFORM.getTypeCode());
Map<String, String> map = platformLogic.queryStationsInfo(queryStationInfoDTO);
logger.info("海南平台查询充电站信息 result:{}", JSON.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:{}", JSON.toJSONString(dto));
try {
// 校验令牌
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
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");
// 查询配置信息
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 = platformLogic.queryStationStats(queryStationInfoDTO);
logger.info("海南平台查询统计信息 result:{}", JSON.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:{}", JSON.toJSONString(dto));
try {
// 校验令牌
// String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
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");
// 查询配置信息
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 = platformLogic.queryStationStatus(queryStationInfoDTO);
logger.info("海南平台设备接口状态查询 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "设备接口状态查询成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("海南平台设备接口状态查询 error:", e);
}
return CommonResult.failed("设备接口状态查询发生异常");
}
/**
* 请求设备认证
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_auth")
public CommonResult<?> queryEquipAuth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("请求设备认证 param:{}", JSON.toJSONString(dto));
try {
// 校验令牌
// String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
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");
// 查询配置信息
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);
// 转换成相应对象
QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class);
queryEquipmentDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = platformLogic.queryEquipAuth(queryEquipmentDTO);
logger.info("请求设备认证 result:{}", JSON.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_equip_business_policy
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_business_policy")
public CommonResult<?> queryEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("查询业务策略信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
// String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
// Map<String, String> resultMap = platformLogic.checkoutSign(dto);
// if (resultMap == null) {
// // 签名错误
// 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 = platformLogic.queryEquipBusinessPolicy(queryStartChargeDTO);
logger.info("查询业务策略信息 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "查询业务策略信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("查询业务策略信息 error:", 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 :{}", JSON.toJSONString(dto));
try {
// 校验令牌
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
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");
// 查询配置信息
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 = platformLogic.queryStartCharge(queryStartChargeDTO);
logger.info("海南平台请求启动充电 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求启动充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("海南平台请求启动充电 error", e);
}
return CommonResult.failed("请求启动充电发生异常");
}
/**
* 推送启动充电结果
* http://localhost:8080/hainan/notificationStartChargeResult/{orderCode}
* @param orderCode
* @return
*/
@GetMapping("/notificationStartChargeResult/{orderCode}")
public RestApiResponse<?> notificationStartChargeResult(@PathVariable("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 :{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));
try {
// 校验令牌
// String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
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");
// 查询配置信息
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);
// 转换成相应对象
QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class);
queryEquipChargeStatusDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = platformLogic.queryEquipChargeStatus(queryEquipChargeStatusDTO);
logger.info("【{}】查询充电状态 result:{}", this.getClass().getSimpleName(), JSON.toJSONString(map));
return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("【{}】平台查询充电状态 error", this.getClass().getSimpleName(), 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<?> queryStopCharge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("请求停止充电 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
// String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(request)) {
// 校验失败
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");
// 查询配置信息
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 = platformLogic.queryStopCharge(queryStartChargeDTO);
logger.info("请求停止充电 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("请求停止充电 error", 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;
}
}

View File

@@ -0,0 +1,309 @@
package com.jsowell.api.thirdparty;
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.util.JWTUtils;
import com.jsowell.pile.dto.QueryEquipChargeStatusDTO;
import com.jsowell.pile.dto.QueryEquipmentDTO;
import com.jsowell.pile.dto.QueryStartChargeDTO;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.thirdparty.huawei.HuaWeiService;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import org.springframework.beans.factory.annotation.Autowired;
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.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 华为 Controller
*
* @author Lemon
* @Date 2024/1/15 13:52:05
*/
@Anonymous
@RestController
@RequestMapping("/huawei")
public class HuaWeiController extends BaseController {
@Autowired
private HuaWeiService huaWeiService;
/**
* 获取token接口
* http://localhost:8080/huawei/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("华为平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = huaWeiService.generateToken(dto);
logger.info("华为平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (UnsupportedEncodingException 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("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = huaWeiService.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 = huaWeiService.queryStationsInfo(queryStationInfoDTO);
return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("华为平台查询充电站信息 error", e);
}
return CommonResult.failed("查询充电站信息异常");
}
/**
* 华为平台查询统计信息
* http://localhost:8080/huawei/v1/query_stations_stats
* @param dto
* @return
*/
@PostMapping("/v1/query_station_status")
public CommonResult<?> queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("华为平台查询统计信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = huaWeiService.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 = huaWeiService.queryStationStatus(queryStationInfoDTO);
logger.info("华为平台查询统计信息 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("华为平台查询统计信息 error:", e);
e.printStackTrace();
}
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("华为平台请求设备认证 param:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = huaWeiService.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);
// 转换成相应对象
QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class);
queryEquipmentDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = huaWeiService.queryEquipAuth(queryEquipmentDTO);
logger.info("华为平台请求设备认证 result:{}", JSON.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/huawei/v1/query_equip_business_policy
* @param dto
* @return
*/
@PostMapping("/v1/request_equip_business_policy")
public CommonResult<?> requestEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("华为平台请求计费策略 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = huaWeiService.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);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaWeiService.requestEquipBusinessPolicy(queryStartChargeDTO);
logger.info("华为平台请求计费策略 result:{}", JSON.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/huawei/query_equip_charge_status/{startChargeSeq}
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_charge_status")
public CommonResult<?> query_equip_charge_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("华为平台查询充电状态 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = huaWeiService.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);
// 转换成相应对象
QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class);
queryEquipChargeStatusDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = huaWeiService.queryEquipChargeStatus(queryEquipChargeStatusDTO);
logger.info("华为平台查询充电状态 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("华为平台查询充电状态 error", e);
}
return CommonResult.failed("华为平台查询充电状态发生异常");
}
/**
* 请求停止充电
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_stop_charge")
public CommonResult<?> query_stop_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("华为平台请求停止充电 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = huaWeiService.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);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaWeiService.queryStopCharge(queryStartChargeDTO);
logger.info("华为平台请求停止充电 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("华为平台请求停止充电 error", e);
}
return CommonResult.failed("华为平台请求停止充电发生异常");
}
}

View File

@@ -0,0 +1,399 @@
package com.jsowell.api.thirdparty;
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.dto.ThirdPartyCommonStartChargeDTO;
import com.jsowell.pile.dto.huawei.*;
import com.jsowell.pile.vo.huawei.QueryChargeStatusVO;
import com.jsowell.pile.vo.huawei.QueryEquipAuthVO;
import com.jsowell.pile.vo.huawei.QueryStartChargeVO;
import com.jsowell.thirdparty.common.CommonService;
import com.jsowell.thirdparty.huawei.HuaweiServiceV2;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 华为 Controller V2
*
* @author Lemon
* @Date 2024/2/2 14:34:56
*/
@Anonymous
@RestController
@RequestMapping("/huawei")
public class HuaWeiControllerV2 extends BaseController {
@Autowired
private HuaweiServiceV2 huaweiServiceV2;
@Autowired
private CommonService commonService;
/**
* 获取token接口
* http://localhost:8080/huawei/v1/query_token
*/
@PostMapping("/v2/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("华为平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = huaweiServiceV2.generateToken(dto);
logger.info("华为平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (UnsupportedEncodingException e) {
logger.error("获取token接口 异常");
return CommonResult.failed("获取token发生异常");
}
}
/**
* 华为设备接口状态变化推送
* @param dto
* @return
*/
@PostMapping("/v2/notification_stationStatus")
public CommonResult<?> receiveNotificationStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("华为设备接口状态变化推送 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
ConnectorStatusInfo connectorStatusInfo = JSONObject.parseObject(dataStr, ConnectorStatusInfo.class);
connectorStatusInfo.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaweiServiceV2.receiveNotificationStationStatus(connectorStatusInfo);
logger.info("华为设备接口状态变化推送 result:{}", map);
return CommonResult.success(0, "设备接口状态变化推送成功!", map.get("Data"), map.get("Sig"));
}
/**
* 请求设备计费信息
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/request_equip_business_policy")
public CommonResult<?> requestEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("华为请求设备计费信息 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
RequestEquipBusinessPolicyDTO requestEquipBusinessPolicyDTO = JSONObject.parseObject(dataStr, RequestEquipBusinessPolicyDTO.class);
requestEquipBusinessPolicyDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaweiServiceV2.requestEquipBusinessPolicy(requestEquipBusinessPolicyDTO);
logger.info("华为请求设备计费信息 result:{}", map);
return CommonResult.success(0, "请求设备计费信息成功!", map.get("Data"), map.get("Sig"));
}
/**
* 接收启动充电结果
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/notification_start_charge_result")
public CommonResult<?> receiveStartChargeResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("接收华为启动充电结果 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
ReceiveStartChargeResultDTO receiveStartChargeResultDTO = JSONObject.parseObject(dataStr, ReceiveStartChargeResultDTO.class);
// receiveStartChargeResultDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaweiServiceV2.receiveStartChargeResult(receiveStartChargeResultDTO);
logger.info("接收华为启动充电结果 result:{}", map);
return CommonResult.success(0, "推送启动充电结果成功!", map.get("Data"), map.get("Sig"));
}
/**
* 接收设备充电状态
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/notification_equip_charge_status")
public CommonResult<?> receiveEquipChargeStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("接收华为设备充电状态 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
ReceiveEquipChargeStatusDTO receiveEquipChargeStatusDTO = JSONObject.parseObject(dataStr, ReceiveEquipChargeStatusDTO.class);
// receiveEquipChargeStatusDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaweiServiceV2.receiveEquipChargeStatus(receiveEquipChargeStatusDTO);
logger.info("接收华为设备充电状态 result:{}", map);
return CommonResult.success(0, "接收设备充电状态成功!", map.get("Data"), map.get("Sig"));
}
/**
* 接收华为所推送的停止充电结果
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/notification_stop_charge_result")
public CommonResult<?> receiveStopChargeResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("接收华为停止充电结果 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
ReceiveStopChargeResultVO receiveStopChargeResultVO = JSONObject.parseObject(dataStr, ReceiveStopChargeResultVO.class);
// receiveStopChargeResultVO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaweiServiceV2.receiveStopChargeResult(receiveStopChargeResultVO);
logger.info("接收华为停止充电结果 result:{}", map);
return CommonResult.success(0, "接收停止充电结果成功!", map.get("Data"), map.get("Sig"));
}
/**
* 接收订单信息
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/notification_charge_order_info")
public CommonResult<?> receiveOrderInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("接收华为订单信息 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
ReceiveOrderInfoDTO receiveOrderInfoDTO = JSONObject.parseObject(dataStr, ReceiveOrderInfoDTO.class);
// receiveOrderInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaweiServiceV2.receiveOrderInfo(receiveOrderInfoDTO);
logger.info("接收华为订单信息 result:{}", map);
return CommonResult.success(0, "接收订单信息成功!", map.get("Data"), map.get("Sig"));
}
/**
* vin启动充电
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/insert_start_charge")
public CommonResult<?> vinStartCharge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("华为vin启动充电 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
VinStartChargeDTO vinStartChargeDTO = JSONObject.parseObject(dataStr, VinStartChargeDTO.class);
// receiveOrderInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> resultMap = null;
try {
resultMap = huaweiServiceV2.vinStartCharge(vinStartChargeDTO);
} catch (Exception e) {
logger.error("华为vin启动充电 error", e);
}
logger.info("华为vin启动充电 resultMap:{}", resultMap);
if (resultMap != null) {
return CommonResult.success(0, "vin启动充电结果", resultMap.get("Data"), resultMap.get("Sig"));
}else {
return CommonResult.failed("vin启动充电 error");
}
}
/**
* 下发计费策略响应
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/notification_deliver_equip_business_policy_result")
public CommonResult<?> receiveDeliverEquipBusinessPolicyResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto){
logger.info("华为下发计费策略响应 params:{}", JSON.toJSONString(dto));
String dataStr = checkAuth(request, dto);
// 转换成相应对象
DeliverBusinessPolicyResponseDTO deliverPolicyResponseDTO = JSONObject.parseObject(dataStr, DeliverBusinessPolicyResponseDTO.class);
// receiveOrderInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = huaweiServiceV2.receiveDeliverEquipBusinessPolicyResult(deliverPolicyResponseDTO);
logger.info("华为下发计费策略响应 result:{}", map);
return CommonResult.success(0, "接收下发计费策略响应信息成功!", map.get("Data"), map.get("Sig"));
}
// ======================== 以上为 华为 --> 万车充 ========================
// ======================== 下面为 万车充 --> 华为 ========================
/**
* 平台充电设备编码同步
* @param stationId
* @return
*/
@GetMapping("/v2/notification_operation_system_info/{stationId}")
public RestApiResponse<?> notificationOperationSystemInfo(@PathVariable("stationId") String stationId) {
// logger.info("华为平台充电设备编码同步 stationId:{}", stationId);
RestApiResponse<?> response = null;
String result = null;
try {
result = huaweiServiceV2.notificationOperationSystemInfo(stationId);
response = new RestApiResponse<>(result);
} catch (Exception e) {
logger.error("华为平台充电设备编码同步 error", e);
}
logger.info("华为平台充电设备编码同步 stationId:{}, result:{}", stationId, result);
return response;
}
/**
* 设备接口状态查询
* @param stationIds
* @return
*/
@PostMapping("/v2/query_station_status")
public RestApiResponse<?> queryStationStatus(@RequestBody List<String> stationIds) {
// logger.info("查询华为设备接口状态 stationIds:{}", stationIds);
RestApiResponse<?> response = null;
Map<String, String> map = new LinkedHashMap<>();
try {
map = huaweiServiceV2.queryStationStatus(stationIds);
response = new RestApiResponse<>(map);
} catch (Exception e) {
logger.error("查询华为设备接口状态 error", e);
}
logger.info("查询华为设备接口状态 stationIds:{}, result:{}", stationIds, map);
return response;
}
/**
* 请求设备认证
* @param connectorId
* @return
*/
@PostMapping("/v2/query_equip_auth")
public RestApiResponse<?> queryEquipAuth(@RequestBody String connectorId) {
// logger.info("请求华为设备认证 connectorId:{}", connectorId);
RestApiResponse<?> response = null;
QueryEquipAuthVO vo = null;
try {
vo = huaweiServiceV2.queryEquipAuth(connectorId);
response = new RestApiResponse<>(vo);
} catch (Exception e) {
logger.error("请求华为设备认证 error", e);
}
logger.info("请求华为设备认证 connectorId:{}, result:{}", connectorId, JSON.toJSONString(vo));
return response;
}
/**
* 请求启动充电
* @param dto
* @return
*/
@PostMapping("/v2/query_start_charge")
public RestApiResponse<?> queryStartCharge(@RequestBody HWQueryStartChargeDTO dto) {
// logger.info("请求华为启动充电 param:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
QueryStartChargeVO vo = null;
try {
vo = huaweiServiceV2.queryStartCharge(dto);
response = new RestApiResponse<>(vo);
} catch (Exception e) {
logger.error("请求华为启动充电 error", e);
}
logger.info("请求华为启动充电 param:{}, result:{}", JSON.toJSONString(dto), JSON.toJSONString(vo));
return response;
}
/**
* 查询充电状态
* @param startChargeSeq
* @return
*/
@PostMapping("/v2/query_equip_charge_status")
public RestApiResponse<?> queryChargeStatus(@RequestBody String startChargeSeq) {
// logger.info("查询华为充电状态 startChargeSeq:{}", startChargeSeq);
RestApiResponse<?> response = null;
QueryChargeStatusVO vo = null;
try {
vo = huaweiServiceV2.queryChargeStatus(startChargeSeq);
response = new RestApiResponse<>(vo);
} catch (Exception e) {
logger.error("查询华为充电状态 error", e);
}
logger.info("查询华为充电状态 startChargeSeq:{}, result:{}", startChargeSeq, JSON.toJSONString(vo));
return response;
}
/**
* 请求停止充电
* @param startChargeSeq
* @return
*/
@PostMapping("/v2/query_stop_charge")
public RestApiResponse<?> queryStopCharge(@RequestBody String startChargeSeq) {
// logger.info("请求华为停止充电 startChargeSeq:{}", startChargeSeq);
RestApiResponse<?> response = null;
QueryStartChargeVO vo = null;
try {
vo = huaweiServiceV2.queryStopCharge(startChargeSeq);
response = new RestApiResponse<>(vo);
}catch (Exception e) {
logger.error("请求华为停止充电 error", e);
}
logger.info("请求华为停止充电 startChargeSeq:{}, result:{}", startChargeSeq, JSON.toJSONString(vo));
return response;
}
@PostMapping("/commonStartCharge")
public RestApiResponse<?> commonStartCharge(@RequestBody ThirdPartyCommonStartChargeDTO dto) {
RestApiResponse<?> response = null;
try {
String result = commonService.commonQueryStartCharge(dto);
response = new RestApiResponse<>(result);
} catch (Exception e) {
logger.error("统一启动充电接口 error", e);
}
logger.info("统一启动充电接口 params:{}, result:{}", JSON.toJSONString(dto), response);
return response;
}
/**
* 校验令牌
* @param request
* @param dto
* @return
*/
private String checkAuth(HttpServletRequest request, CommonParamsDTO dto) {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
logger.error("令牌校验错误");
return null;
}
// 校验签名
Map<String, String> resultMap = huaweiServiceV2.checkoutSign(dto);
if (resultMap == null) {
// 签名错误
logger.error("令牌校验错误");
return null;
}
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);
return dataStr;
}
}

View File

@@ -0,0 +1,489 @@
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.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.platform.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
*
* @author JS-ZZA
* @date 2023/4/10 14:58
*/
@Anonymous
@RestController
@RequestMapping("/LianLian")
public class LianLianController extends ThirdPartyBaseController {
@Autowired
@Qualifier("lianLianPlatformServiceImpl")
private ThirdPartyPlatformService lianLianService;
/**
* 获取token接口
* http://localhost:8080/LianLian/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("联联平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = lianLianService.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发生异常");
}
}
/**
* 联联平台查询充电站信息
* http://localhost:8080/LianLian/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:{}", 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 = lianLianService.queryStationsInfo(queryStationInfoDTO);
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/LianLian/v1/query_station_status
* @param dto
* @return
*/
@PostMapping("/v1/query_station_status")
public CommonResult<?> query_station_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("联联平台查询充电站状态信息 params:{}", 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 = lianLianService.queryStationStatus(queryStationInfoDTO);
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/LianLian/v1/query_station_stats
*
* @param dto
* @return
*/
@PostMapping("/v1/query_station_stats")
public CommonResult<?> query_station_stats(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("联联平台查询统计信息 params:{}", 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 = lianLianService.queryStationStats(queryStationInfoDTO);
return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("联联平台查询统计信息 error:", e);
e.printStackTrace();
}
return CommonResult.failed("查询统计信息发生异常");
}
/**
* 充电站信息变化推送 notification_stationInfo
* http://localhost:8080/LianLian/notificationStationInfo
*/
@PostMapping("/notificationStationInfo")
public RestApiResponse<?> notificationStationInfo(@RequestBody PushInfoParamDTO dto) {
logger.info("联联平台充电站信息变化推送 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getStationId()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
String result = lianLianService.notificationStationInfo(dto.getStationId());
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;
}
/**
* 联联平台设备状态变化推送 notification_stationStatus
* http://localhost:8080/LianLian/notificationStationStatus
* @param dto
* @return
*/
@PostMapping("/notificationStationStatus")
public RestApiResponse<?> notificationStationStatus(@RequestBody PushInfoParamDTO dto) {
logger.info("联联平台设备状态变化推送 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getPileConnectorCode())) ||
StringUtils.isBlank(String.valueOf(dto.getStatus()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PushRealTimeInfoDTO pushRealTimeInfoDTO = new PushRealTimeInfoDTO();
pushRealTimeInfoDTO.setStatus(dto.getStatus());
pushRealTimeInfoDTO.setPileConnectorCode(dto.getPileConnectorCode());
pushRealTimeInfoDTO.setThirdPartyType(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getTypeCode());
String result = lianLianService.notificationStationStatus(pushRealTimeInfoDTO);
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;
}
/**
* 站点费率变化推送 notification_stationFee
* http://localhost:8080/LianLian/notificationStationFee
*/
@PostMapping("/notificationStationFee")
public RestApiResponse<?> notificationStationFee(@RequestBody PushInfoParamDTO dto) {
logger.info("联联平台站点费率变化推送 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getStationId()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
String result = lianLianService.notificationStationFee(dto.getStationId());
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;
}
/**
* 设备充电中状态变化推送 notification_connector_charge_status
* http://localhost:8080/LianLian/notificationConnectorChargeStatus
* @return
*/
@GetMapping("/notificationConnectorChargeStatus/{orderCode}")
public RestApiResponse<?> notificationConnectorChargeStatus(@PathVariable("orderCode")String orderCode) {
logger.info("联联平台设备充电中状态变化推送 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// String result = lianLianService.pushPileChargeStatusChange(orderCode);
String result = lianLianService.notificationConnectorChargeStatus(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;
}
/**
* 推送订单信息 notification_orderInfo
* http://localhost:8080/LianLian/notificationOrderInfo/
* @param orderCode
* @return
*/
@GetMapping("/notificationOrderInfo/{orderCode}")
public RestApiResponse<?> notificationOrderInfo(@PathVariable("orderCode")String orderCode) {
logger.info("联联平台推送订单信息 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
String result = lianLianService.notificationChargeOrderInfo(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;
}
/**
* 请求设备认证
* http://localhost:8080/LianLian/v1/query_equip_auth
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_auth")
public CommonResult<?> query_equip_auth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("联联平台请求设备认证 param:{}", JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryEquipmentDTO queryEquipmentDTO = parseParamsDTO(dto, QueryEquipmentDTO.class);
// 执行逻辑
Map<String, String> map = lianLianService.queryEquipAuth(queryEquipmentDTO);
return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("联联平台请求设备认证 error:", 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 :{}", 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 = lianLianService.queryStartCharge(queryStartChargeDTO);
return CommonResult.success(0, "请求启动充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("联联平台请求启动充电 error", e);
}
return CommonResult.failed("请求启动充电发生异常");
}
/**
* 查询充电状态
* http://localhost:8080/LianLian/query_equip_charge_status/{startChargeSeq}
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_charge_status")
public CommonResult<?> query_equip_charge_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("联联平台查询充电状态 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = parseParamsDTO(dto, QueryEquipChargeStatusDTO.class);
// 执行逻辑
Map<String, String> map = lianLianService.queryEquipChargeStatus(queryEquipChargeStatusDTO);
return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("联联平台查询充电状态 error", e);
}
return CommonResult.failed("联联平台查询充电状态发生异常");
}
/**
* 请求停止充电
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_stop_charge")
public CommonResult<?> query_stop_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("联联平台请求停止充电 params :{}", 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 = lianLianService.queryStopCharge(queryStartChargeDTO);
return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("联联平台请求停止充电 error", e);
}
return CommonResult.failed("联联平台请求停止充电发生异常");
}
/**
* 推送订单结算信息 (联联推给我们)
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/notification_order_settlement_info")
public CommonResult<?> notification_order_settlement_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("联联平台推送订单结算信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
PushOrderSettlementDTO pushOrderSettlementDTO = parseParamsDTO(dto, PushOrderSettlementDTO.class);
// 执行逻辑
Map<String, String> map = lianLianService.notificationOrderSettlementInfo(pushOrderSettlementDTO);
return CommonResult.success(0, "推送订单结算信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("联联平台推送订单结算信息 error:", e);
e.printStackTrace();
}
return CommonResult.failed("推送订单结算信息发生异常");
}
@GetMapping("/pushStationFee/{stationId}")
public RestApiResponse<?> pushStationFee(@PathVariable("stationId") String stationId) {
RestApiResponse<?> response = null;
try {
// String result = lianLianService.pushStationFee(stationId);
String result = lianLianService.notificationStationFee(stationId);
response = new RestApiResponse<>(result);
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
}

View File

@@ -0,0 +1,158 @@
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.exception.BusinessException;
import com.jsowell.pile.dto.QueryOperatorInfoDTO;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.platform.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;
/**
* 内蒙古自治区充电设施监测服务平台
*/
@Anonymous
@RestController
@RequestMapping("/evcs")
public class NMGController extends ThirdPartyBaseController {
@Autowired
@Qualifier("neiMengGuPlatformServiceImpl")
private ThirdPartyPlatformService platformLogic;
// @Autowired
// private ThirdpartySecretInfoService thirdpartySecretInfoService;
/**
* 获取token接口
* http://localhost:8080/evcs/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("内蒙古平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = platformLogic.queryToken(dto);
logger.info("内蒙古平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("内蒙古平台 请求令牌接口 异常", e);
return CommonResult.failed("获取token发生异常");
}
}
/**
* 查询运营商信息
* 接口名称supervise_query_operator_info
* 使用方法:由数据提供方实现此接口,数据需求方调用
* 接口频率:每天一次或多次
* 超时时间120秒
*/
@PostMapping("/v1/supervise_query_operator_info")
public CommonResult<?> queryOperatorInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("内蒙古平台查询运营商信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
boolean verifyToken = verifyToken(request.getHeader("Authorization"));
if (!verifyToken) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryOperatorInfoDTO paramDTO = parseParamsDTO(dto, QueryOperatorInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryOperatorInfo(paramDTO);
logger.info("内蒙古平台查询运营商信息 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "操作成功!", map.get("Data"), map.get("Sig"));
} catch (BusinessException e) {
return CommonResult.failed(Integer.parseInt(e.getCode()), e.getMessage());
} catch (Exception e) {
logger.error("内蒙古平台查询运营商信息 异常", e);
return CommonResult.failed("查询运营商信息发生异常");
}
}
/**
* 查询充换电站信息
* 接口名称: supervise_query_stations_info
* 使用方法:由数据提供方实现此接口,数据需求方调用
* 接口频率:每天一次或多次
* 超时时间120秒
*/
@PostMapping("/v1/supervise_query_stations_info")
public CommonResult<?> queryStationsInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("内蒙古平台查询运营商信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
boolean verifyToken = verifyToken(request.getHeader("Authorization"));
if (!verifyToken) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
QueryStationInfoDTO paramDTO = parseParamsDTO(dto, QueryStationInfoDTO.class);
Map<String, String> map = platformLogic.queryStationsInfo(paramDTO);
logger.info("内蒙古平台查询运营商信息 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("内蒙古平台查询运营商信息 异常", e);
return CommonResult.failed("查询运营商信息发生异常");
}
}
/**
* 查询充换电站状态信息
* supervise_query_station_status
*/
@PostMapping("/v1/supervise_query_station_status")
public CommonResult<?> queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("内蒙古平台查询充换电站状态信息 params:{}", 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 paramDTO = parseParamsDTO(dto, QueryStationInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStationStatus(paramDTO);
logger.info("内蒙古平台查询充换电站状态信息 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "查询充换电站状态信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("内蒙古平台查询充换电站状态信息异常", e);
return CommonResult.failed("查询充换电站状态信息发生异常");
}
}
}

View File

@@ -0,0 +1,287 @@
package com.jsowell.api.thirdparty;
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.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.dto.PushStationInfoDTO;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.pile.dto.nanrui.GetTokenDTO;
import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO;
import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.nanrui.service.NRService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 江苏平台 controller
*
* @author Lemon
* @Date 2023/10/11 13:26
*/
@Anonymous
@RestController
@RequestMapping("/jiangsu")
public class NRController extends BaseController {
@Autowired
private NRService nrService;
/**
* 查询充电站信息
* @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("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = nrService.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 = nrService.query_stations_info(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_station_status")
public CommonResult<?> query_station_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("江苏平台查询设备接口状态 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = nrService.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 = nrService.query_station_status(queryStationInfoDTO);
return CommonResult.success(0, "查询设备接口状态成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("江苏平台查询设备接口状态 error", e);
e.printStackTrace();
}
return CommonResult.failed("查询设备接口状态异常");
}
/**
* 查询充电电量信息
* @param dto
*/
@RequestMapping("/v1/query_order_info")
public CommonResult<?> query_order_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("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = nrService.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);
// 转换成相应对象
NRQueryOrderDTO nrQueryOrderDTO = JSONObject.parseObject(dataStr, NRQueryOrderDTO.class);
nrQueryOrderDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = nrService.query_order_info(nrQueryOrderDTO);
return CommonResult.success(0, "查询充电电量信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("江苏平台查询充电电量信息 error", e);
}
return CommonResult.failed("查询充电电量信息异常");
}
/**
* 获取token接口
* http://localhost:8080/nanrui/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("江苏平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = nrService.generateToken(dto);
logger.info("江苏平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (UnsupportedEncodingException e) {
logger.error("获取token接口 异常");
return CommonResult.failed("获取token发生异常");
}
}
@RequestMapping("/v1/getToken")
public String getToken(@RequestBody GetTokenDTO dto) {
String token = nrService.getToken(dto.getUrlAddress(), dto.getOperatorId(), dto.getOperatorSecret(),
dto.getDataSecretIv(), dto.getSignSecret(), dto.getDataSecret());
return token;
}
/**
* 推送充电站信息
* @param dto
* @return
*/
@PostMapping("/v1/pushStationInfo")
public RestApiResponse<?> pushStationInfo(@RequestBody PushStationInfoDTO dto) {
logger.info("推送江苏平台充电站信息 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getStationId()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
String s = nrService.pushStationInfo(dto);
response = new RestApiResponse<>(s);
}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 dto
* @return
*/
@PostMapping("/v1/pushAlarmInfo")
public RestApiResponse<?> pushAlarmInfo(@RequestBody PushAlarmInfoDTO dto) {
logger.info("推送江苏平台告警信息 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getStationId()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
String s = nrService.pushAlarmInfo(dto);
response = new RestApiResponse<>(s);
}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 data
* @return
*/
@PostMapping("/v1/pushPileStatus")
public RestApiResponse<?> pushPileStatus(@RequestBody RealTimeMonitorData data) {
logger.info("推送江苏平台设备状态变化推送 params:{}", JSON.toJSONString(data));
RestApiResponse<?> response = null;
try {
String s = nrService.pushPileStatus(data);
response = new RestApiResponse<>(s);
}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 orderCode
* @return
*/
@GetMapping("/v1/pushOrderInfo/{orderCode}")
public RestApiResponse<?> pushOrderInfo(@PathVariable("orderCode") String orderCode) {
logger.info("江苏平台充电电量信息推送 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String s = nrService.pushOrderInfo(orderCode);
response = new RestApiResponse<>(s);
}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;
}
}

View File

@@ -0,0 +1,230 @@
package com.jsowell.api.thirdparty;
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.util.JWTUtils;
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO;
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.ningxiajiaotou.service.NXJTService;
import org.springframework.beans.factory.annotation.Autowired;
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.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 宁夏交投 Controller
*
* @author Lemon
* @Date 2023/11/15 8:36:42
*/
@Anonymous
@RestController
@RequestMapping("/nxjt")
public class NXJTController extends BaseController {
@Autowired
private NXJTService nxjtService;
@Autowired
private LianLianService lianLianService;
/**
* 获取token接口
* http://localhost:8080/nxjt/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("宁夏交投平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = nxjtService.generateToken(dto);
logger.info("宁夏交投平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (UnsupportedEncodingException e) {
logger.error("获取token接口 异常");
return CommonResult.failed("获取token发生异常");
}
}
/**
* 宁夏交投平台查询充电站信息
* http://localhost:8080/nxjt/v1/query_stations_info
* @param dto
* @return
*/
@PostMapping("/v1/query_stations_info")
public CommonResult<?> queryStationsInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("宁夏交投平台查询充电站信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
NXJTQueryStationInfoDTO nxjtQueryStationInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryStationInfoDTO.class);
nxjtQueryStationInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = nxjtService.queryStationsInfo(nxjtQueryStationInfoDTO);
// return CommonResult.success(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/nxjt/v1/query_free_pile_number
* @param dto
* @return
*/
@PostMapping("/v1/query_free_pile_number")
public CommonResult<?> queryFreePileNumber(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("宁夏交投平台查询充电站中空闲桩数量 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
NXJTQueryStationInfoDTO nxjtQueryStationInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryStationInfoDTO.class);
nxjtQueryStationInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = nxjtService.queryFreePileNumber(nxjtQueryStationInfoDTO);
// return CommonResult.success(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/nxjt/v1/query_free_pile_number
* @param dto
* @return
*/
@PostMapping("/v1/query_orders_info_by_Plate_number")
public CommonResult<?> queryOrdersInfoByPlateNumber(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("宁夏交投平台查询某车牌号消费记录 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
NXJTQueryOrdersInfoDTO nxjtQueryOrdersInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryOrdersInfoDTO.class);
nxjtQueryOrdersInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = nxjtService.queryOrdersInfoByPlateNumber(nxjtQueryOrdersInfoDTO);
// return CommonResult.success(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/nxjt/v1/query_orders_info
* @param dto
* @return
*/
@PostMapping("/v1/query_orders_info")
public CommonResult<?> queryOrdersInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("宁夏交投平台查询某段时间内消费记录 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
NXJTQueryOrdersInfoDTO nxjtQueryOrdersInfoDTO = JSONObject.parseObject(dataStr, NXJTQueryOrdersInfoDTO.class);
nxjtQueryOrdersInfoDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = nxjtService.queryOrdersInfo(nxjtQueryOrdersInfoDTO);
// return CommonResult.success(map);
return CommonResult.success(0, "查询充电站中空闲桩数量信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("宁夏交投平台查询某段时间内消费记录 error:", e);
e.printStackTrace();
}
return CommonResult.failed("查询某段时间内消费记录发生异常");
}
}

View File

@@ -0,0 +1,221 @@
package com.jsowell.api.thirdparty;
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.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
import com.jsowell.pile.dto.PushRealTimeInfoDTO;
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/evcs")
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(Integer.parseInt(map.get("Ret")), map.get("Msg"), 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();
// 校验签名
boolean verifyResult = qingHaiPlatformServiceImpl.verifySignature(dto, platformConfig.getSignSecret());
if (!verifyResult) {
// 验签失败
return CommonResult.failed("签名错误");
}
// 解密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.QING_HAI_PLATFORM.getTypeCode());
Map<String, String> map = qingHaiPlatformServiceImpl.queryStationsInfo(queryStationInfoDTO);
return CommonResult.success(Integer.parseInt(map.get("Ret")), map.get("Msg"), 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();
// 校验签名
boolean verifyResult = qingHaiPlatformServiceImpl.verifySignature(dto, platformConfig.getSignSecret());
if (!verifyResult) {
// 验签失败
return CommonResult.failed("签名错误");
}
// 解密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(Integer.parseInt(map.get("Ret")), map.get("Msg"), map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("青海平台查询业务策略信息 error", e);
}
return CommonResult.failed("查询业务策略信息异常");
}
/**
* 推送站点功率
* @param stationIds
* @return
*/
@PostMapping("/pushStationPower")
public RestApiResponse<?> pushStationPower(@RequestBody 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;
}
/**
* 推送设备状态变化
* @param dto
* @return
*/
@PostMapping("/pushRealTimeInfo")
public RestApiResponse<?> pushStationPower(@RequestBody PushRealTimeInfoDTO dto) {
RestApiResponse<?> response = null;
try {
String result = qingHaiPlatformServiceImpl.notificationStationStatus(dto);
response = new RestApiResponse<>(result);
}catch (Exception e) {
logger.error("青海平台推送设备状态变化 error", e);
}
logger.info("青海平台推送设备状态变化 result:{}", response);
return response;
}
/**
* 推送充电状态
* @param orderCode
* @return
*/
@GetMapping("/notificationEquipChargeStatus/{orderCode}")
public RestApiResponse<?> notificationEquipChargeStatus(@PathVariable("orderCode") String orderCode) {
RestApiResponse<?> response = null;
try {
String result = qingHaiPlatformServiceImpl.notificationEquipChargeStatus(orderCode);
response = new RestApiResponse<>(result);
}catch (Exception e) {
logger.error("青海平台推送充电状态 error", e);
}
logger.info("青海平台推送充电状态 result:{}", response);
return response;
}
/**
* 推送订单
* @param orderCode
* @return
*/
@GetMapping("/pushOrderInfo/{orderCode}")
public RestApiResponse<?> pushOrderInfo(@PathVariable("orderCode") String orderCode) {
RestApiResponse<?> response = null;
try {
String result = qingHaiPlatformServiceImpl.notificationChargeOrderInfo(orderCode);
response = new RestApiResponse<>(result);
}catch (Exception e) {
logger.error("青海平台推送订单信息 error", e);
}
logger.info("青海平台推送订单信息 result:{}", response);
return response;
}
}

View File

@@ -0,0 +1,43 @@
package com.jsowell.api.thirdparty;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.pile.dto.ruanjie.UseCouponDTO;
import com.jsowell.thirdparty.ruanjie.service.RJService;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* 软杰controller
*
* @author Lemon
* @Date 2023/9/22 9:00
*/
@Anonymous
@RestController
@RequestMapping("/ruanjie")
public class RJController extends BaseController {
@Autowired
private RJService rjService;
@PostMapping("/useCoupon")
public RestApiResponse<?> useCoupon(@RequestBody UseCouponDTO dto) {
logger.info("软杰--使用优惠券 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
String result = rjService.useCoupon(dto);
response = new RestApiResponse<>(result);
} catch (Exception e) {
logger.error("软杰--使用优惠券 error, ", e);
response = new RestApiResponse<>(e);
}
logger.info("软杰--使用优惠券 result:{}", response);
return response;
}
}

View File

@@ -0,0 +1,246 @@
package com.jsowell.api.thirdparty;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.GBSignUtils;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
/**
* 内蒙古接口
*/
@Anonymous
@RestController
public class ThirdPartyBaseController extends BaseController {
// @Autowired
// @Qualifier("zhongDianLianPlatformServiceImpl")
// private ThirdPartyPlatformService platformLogic;
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
/**
* 获取token接口
* http://localhost:8080/query_token
*/
// @PostMapping("/query_token")
// public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
// logger.info("平台请求令牌 params:{}", JSON.toJSONString(dto));
// try {
// Map<String, String> map = platformLogic.queryToken(dto);
// logger.info("平台请求令牌 result:{}", JSON.toJSONString(map));
// return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
// } catch (Exception e) {
// logger.error("平台请求令牌接口 异常", e);
// return CommonResult.failed("获取token发生异常");
// }
// }
/**
* 验证token
*/
protected boolean verifyToken(String token) {
if (StringUtils.equals(token, "jsowellTest")) {
// 为了方便测试token为jsowellTest校验通过
return true;
}
boolean result;
try {
result = JWTUtils.checkThirdPartyToken(token);
} catch (Exception e) {
result = false;
}
return result;
}
/**
* 解析DTO
* @param dto
* @param targetClass
* @return
* @param <T>
*/
protected <T> T parseParamsDTO(CommonParamsDTO dto, Class<T> targetClass) throws NoSuchFieldException, IllegalAccessException {
// 解密
String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID();
// 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO secretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId);
if (secretInfoVO == null) {
throw new BusinessException("1", "无此对接平台");
}
String dataSecret = secretInfoVO.getOurDataSecret();
String dataSecretIv = secretInfoVO.getOurDataSecretIv();
// 解密data 获取参数中的OperatorSecret
String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv);
T t = JSONObject.parseObject(decrypt, targetClass);
// 校验是否有operatorId, 没有就set
verifyOperatorId(dto, t);
return t;
}
/**
* 获取OperatorId的值 verify
* @param t
* @return
* @throws NoSuchFieldException
* @throws IllegalAccessException
*/
private <T> void verifyOperatorId(CommonParamsDTO dto, T t) throws NoSuchFieldException, IllegalAccessException {
String targetFieldName = "operatorId";
String operatorId = (String) getFieldValueByObject(t, targetFieldName);
if (StringUtils.isBlank(operatorId)) {
setFieldValueByFieldName(t, targetFieldName, dto.getOperatorID());
}
}
private <T> void setFieldValueByFieldName(T t, String targetFieldName, Object value) {
// 获取该对象的class
Class<? extends Object> tClass = t.getClass();
// 获取所有的属性数组
Field[] fields = tClass.getDeclaredFields();
for (Field field : fields) {
// 属性名称
String currentFieldName = "";
try {
boolean has_JsonProperty = field.isAnnotationPresent(JsonProperty.class);
if (has_JsonProperty) {
currentFieldName = field.getAnnotation(JsonProperty.class).value();
} else {
currentFieldName = field.getName();
}
// 忽略大小写对比
if (currentFieldName.equalsIgnoreCase(targetFieldName)) {
// 取消语言访问检查
field.setAccessible(true);
// 给变量赋值
field.set(t, value);
return;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
/**
* 使用反射获取字段值
*/
private <T> Object getFieldValueByObject(T t, String targetFieldName) throws NoSuchFieldException, IllegalAccessException {
// 获取该对象的class
Class<? extends Object> tClass = t.getClass();
// 获取所有的属性数组
Field[] fields = tClass.getDeclaredFields();
/**
* 这里只需要 id 这个属性,所以直接取 fields[0] 这
* 一个如果id不是排在第一位自己取相应的位置
* 如果有需要可以写成for循环遍历全部属性
*/
for (Field field : fields) {
// 属性名称
String currentFieldName = "";
// 获取属性上面的注解 import com.fasterxml.jackson.annotation.JsonProperty;
/**
* 举例: @JsonProperty("roleIds")
* private String roleIds;
*/
try {
boolean has_JsonProperty = field.isAnnotationPresent(JsonProperty.class);
if (has_JsonProperty) {
currentFieldName = field.getAnnotation(JsonProperty.class).value();
} else {
currentFieldName = field.getName();
}
// 忽略大小写对比
if (currentFieldName.equalsIgnoreCase(targetFieldName)) {
field.setAccessible(true);
currentFieldName = currentFieldName.replaceFirst(currentFieldName.substring(0, 1), currentFieldName.substring(0, 1).toUpperCase());
//整合出 getId() 属性这个方法
Method m = tClass.getMethod("get" + currentFieldName);
return m.invoke(t);
}
} catch (SecurityException e) {
// 安全性异常
e.printStackTrace();
} catch (IllegalArgumentException e) {
// 非法参数
e.printStackTrace();
} catch (IllegalAccessException | NoSuchMethodException e) {
// 无访问权限
e.printStackTrace();
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
return null;
}
/**
* 校验签名
*
* verifySignature
*/
protected boolean verifySignature(CommonParamsDTO dto) {
// 查询密钥
String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID();
ThirdPartySecretInfoVO secretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId);
if (secretInfoVO == null) {
throw new BusinessException("1", "无此对接平台");
}
// 校验签名,使用响应方的密钥
String signSecret = secretInfoVO.getOurSigSecret();
Map<String, String> map = Maps.newLinkedHashMap();
String operatorID = dto.getOperatorID();
if (StringUtils.isNotBlank(operatorID)) {
map.put("OperatorID", operatorID);
}
String platformID = dto.getPlatformID();
if (StringUtils.isNotBlank(platformID)) {
map.put("PlatformID", platformID);
}
String data = dto.getData();
if (StringUtils.isNotBlank(data)) {
map.put("Data", data);
}
String timeStamp = dto.getTimeStamp();
if (StringUtils.isNotBlank(timeStamp)) {
map.put("TimeStamp", timeStamp);
}
String seq = dto.getSeq();
if (StringUtils.isNotBlank(seq)) {
map.put("Seq", seq);
}
// 计算sign
String sign = GBSignUtils.sign(map, signSecret);
return StringUtils.equals(dto.getSig(), sign);
}
}

View File

@@ -0,0 +1,503 @@
package com.jsowell.api.thirdparty;
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.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.dto.*;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.xindiantu.service.XDTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 新电途平台 Controller
*
* @author Lemon
* @Date 2024/1/3 13:41:46
*/
@Anonymous
@RestController
@RequestMapping("/xindiantu")
public class XDTController extends BaseController {
@Autowired
private XDTService xdtService;
/**
* 获取token接口
* http://localhost:8080/xindiantu/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("新电途平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = xdtService.generateToken(dto);
logger.info("新电途平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (UnsupportedEncodingException e) {
logger.error("获取token接口 异常");
return CommonResult.failed("获取token发生异常");
}
}
/**
* 推送充电站信息 notification_stationInfo
* http://localhost:8080/xindiantu/v1/pushStationInfo
* @param dto
* @return
*/
@PostMapping("/pushStationInfo")
public RestApiResponse<?> pushStationInfo(@RequestBody PushStationInfoDTO dto) {
logger.info("推送新电途平台充电站信息 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getStationId()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
xdtService.pushStationInfo(dto);
response = new RestApiResponse<>();
}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 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("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = xdtService.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 = xdtService.queryStationsInfo(queryStationInfoDTO);
return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("新电途平台查询充电站信息 error", e);
}
return CommonResult.failed("查询充电站信息异常");
}
/**
* 新电途平台查询统计信息
* http://localhost:8080/xindiantu/v1/query_stations_stats
* @param dto
* @return
*/
@PostMapping("/v1/query_station_status")
public CommonResult<?> queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("新电途平台查询统计信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = xdtService.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 = xdtService.queryStationStatus(queryStationInfoDTO);
logger.info("新电途平台查询统计信息 result:{}", JSON.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/xindiantu/v1/query_equip_business_policy
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_business_policy")
public CommonResult<?> queryEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("新电途平台查询业务策略信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = xdtService.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);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = xdtService.queryEquipBusinessPolicy(queryStartChargeDTO);
logger.info("新电途平台查询业务策略信息 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "查询业务策略信息成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("新电途平台查询业务策略信息 error:", e);
e.printStackTrace();
}
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("新电途平台请求设备认证 param:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = xdtService.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);
// 转换成相应对象
QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class);
queryEquipmentDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = xdtService.queryEquipAuth(queryEquipmentDTO);
logger.info("新电途平台请求设备认证 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("新电途平台请求设备认证 error:", e);
e.printStackTrace();
}
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 :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = xdtService.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);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = xdtService.queryStartCharge(queryStartChargeDTO);
logger.info("新电途平台请求启动充电 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求启动充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("新电途平台请求启动充电 error", e);
}
return CommonResult.failed("请求启动充电发生异常");
}
/**
* 查询充电状态
* http://localhost:8080/xindiantu/query_equip_charge_status/{startChargeSeq}
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_charge_status")
public CommonResult<?> query_equip_charge_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("新电途平台查询充电状态 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = xdtService.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);
// 转换成相应对象
QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class);
queryEquipChargeStatusDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = xdtService.queryEquipChargeStatus(queryEquipChargeStatusDTO);
logger.info("新电途平台查询充电状态 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("新电途平台查询充电状态 error", e);
}
return CommonResult.failed("新电途平台查询充电状态发生异常");
}
/**
* 请求停止充电
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_stop_charge")
public CommonResult<?> query_stop_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("新电途平台请求停止充电 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = xdtService.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);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = xdtService.queryStopCharge(queryStartChargeDTO);
logger.info("新电途平台请求停止充电 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("新电途平台请求停止充电 error", e);
}
return CommonResult.failed("新电途平台请求停止充电发生异常");
}
/**
* 新电途推送停止充电结果
* http://localhost:8080/xindiantu/pushStartChargeResult
* @param orderCode
* @return
*/
@GetMapping("/pushStopChargeResult/{orderCode}")
public RestApiResponse<?> pushStopChargeResult(@PathVariable("orderCode") String orderCode) {
logger.info("新电途平台推送停止充电结果 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = xdtService.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;
}
/**
* 新电途推送充电订单信息
* http://localhost:8080/xindiantu/pushChargeOrderInfo
* @param orderCode
* @return
*/
@GetMapping("/pushChargeOrderInfo/{orderCode}")
public RestApiResponse<?> pushChargeOrderInfo(@PathVariable("orderCode") String orderCode) {
logger.info("新电途平台推送充电订单信息 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = xdtService.pushChargeOrderInfo(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;
}
/**
* 新电途推送充电状态
* http://localhost:8080/xindiantu/pushStartChargeResult
* @param orderCode
* @return
*/
@GetMapping("/pushChargeStatus/{orderCode}")
public RestApiResponse<?> pushChargeStatus(@PathVariable("orderCode") String orderCode) {
logger.info("新电途平台推送充电状态 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = xdtService.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;
}
/**
* 新电途推送启动充电结果
* http://localhost:8080/xindiantu/pushStartChargeResult
* @param orderCode
* @return
*/
@GetMapping("/pushStartChargeResult/{orderCode}")
public RestApiResponse<?> pushStartChargeResult(@PathVariable("orderCode") String orderCode) {
logger.info("新电途平台推送启动充电结果 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = xdtService.notificationStartChargeResult(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;
}
/**
* 新电途平台设备状态变化推送
* http://localhost:8080/xindiantu/pushStationStatus
* @param dto
* @return
*/
@PostMapping("/pushStationStatus")
public RestApiResponse<?> pushStationStatus(@RequestBody PushInfoParamDTO dto) {
logger.info("新电途平台设备状态变化推送 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getPileConnectorCode())) ||
StringUtils.isBlank(String.valueOf(dto.getStatus()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PushRealTimeInfoDTO pushRealTimeInfoDTO = new PushRealTimeInfoDTO();
pushRealTimeInfoDTO.setStatus(dto.getStatus());
pushRealTimeInfoDTO.setPileConnectorCode(dto.getPileConnectorCode());
pushRealTimeInfoDTO.setThirdPartyType(ThirdPlatformTypeEnum.XIN_DIAN_TU.getTypeCode());
String result = xdtService.notificationStationStatus(pushRealTimeInfoDTO);
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;
}
}

View File

@@ -0,0 +1,462 @@
package com.jsowell.api.thirdparty;
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.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.dto.*;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO;
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 甬城泊车controller
*
* @author Lemon
* @Date 2023/11/3 9:39:21
*/
@Anonymous
@RestController
@RequestMapping("/ycbc")
public class YCBCController extends BaseController {
@Autowired
private YCBCService ycbcService;
@Autowired
private LianLianService lianLianService;
/**
* 获取token接口
* http://localhost:8080/ycbc/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("甬城泊车平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = ycbcService.generateToken(dto);
logger.info("甬城泊车平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (UnsupportedEncodingException e) {
logger.error("甬城泊车平台 请求令牌接口 异常");
return CommonResult.failed("获取token发生异常");
}
}
/**
* 获取token接口
* http://localhost:8080/ycbc/v1/query_token
*/
@PostMapping("/v1/ycbcQuery_token")
public String ycbcQueryToken(@RequestBody YCBCGetTokenDTO dto) {
logger.info("请求甬城泊车平台令牌 params:{}", JSON.toJSONString(dto));
String token = "";
try {
token = ycbcService.YCBCGetToken(dto);
logger.info("请求甬城泊车平台令牌 result:{}", token);
} catch (Exception e) {
logger.error("请求甬城泊车平台令牌接口 异常");
return "";
}
return token;
}
/**
* 甬城泊车平台查询充电站信息
* http://localhost:8080/ycbc/query_stations_info
* @param dto
* @return
*/
@PostMapping("/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("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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 = ycbcService.queryStationsInfo(queryStationInfoDTO);
logger.info("甬城泊车平台查询充电站信息 result:{}", JSON.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/ycbc/query_station_status
* @param dto
* @return
*/
@PostMapping("/v1/query_station_status")
public CommonResult<?> query_station_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("甬城泊车平台查询充电站状态信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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 = ycbcService.queryStationStatus(queryStationInfoDTO);
logger.info("甬城泊车平台查询充电站状态信息 result:{}", JSON.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/ycbc/pushStationStatus
* @param dto
* @return
*/
@PostMapping("/pushStationStatus")
public RestApiResponse<?> pushStationStatus(@RequestBody PushInfoParamDTO dto) {
logger.info("甬城泊车平台设备状态变化推送 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getPileConnectorCode())) ||
StringUtils.isBlank(String.valueOf(dto.getStatus()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PushRealTimeInfoDTO pushRealTimeInfoDTO = new PushRealTimeInfoDTO();
pushRealTimeInfoDTO.setStatus(dto.getStatus());
pushRealTimeInfoDTO.setPileConnectorCode(dto.getPileConnectorCode());
pushRealTimeInfoDTO.setThirdPartyType(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getTypeCode());
String result = ycbcService.notificationStationStatus(pushRealTimeInfoDTO);
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;
}
/**
* 甬城泊车推送启动充电结果
* http://localhost:8080/ycbc/pushStartChargeResult
* @param orderCode
* @return
*/
@GetMapping("/pushStartChargeResult/{orderCode}")
public RestApiResponse<?> pushStartChargeResult(@PathVariable("orderCode") String orderCode) {
logger.info("甬城泊车平台推送启动充电结果 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = ycbcService.pushStartChargeResult(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_equip_auth")
public CommonResult<?> query_equip_auth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("甬城泊车平台请求设备认证 param:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class);
queryEquipmentDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = ycbcService.queryEquipAuth(queryEquipmentDTO);
logger.info("甬城泊车平台请求设备认证 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("甬城泊车平台请求设备认证 error:", e);
e.printStackTrace();
}
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 :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = ycbcService.queryStartCharge(queryStartChargeDTO);
logger.info("甬城泊车平台请求启动充电 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求启动充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("甬城泊车平台请求启动充电 error", e);
}
return CommonResult.failed("请求启动充电发生异常");
}
/**
* 查询充电状态
* http://localhost:8080/LianLian/query_equip_charge_status/{startChargeSeq}
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_charge_status")
public CommonResult<?> query_equip_charge_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("甬城泊车平台查询充电状态 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class);
queryEquipChargeStatusDTO.setOperatorID(dto.getOperatorID());
Map<String, String> map = ycbcService.queryEquipChargeStatus(queryEquipChargeStatusDTO);
logger.info("甬城泊车平台查询充电状态 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("甬城泊车平台查询充电状态 error", e);
}
return CommonResult.failed("甬城泊车平台查询充电状态发生异常");
}
/**
* 甬城泊车推送充电状态
* http://localhost:8080/ycbc/pushStartChargeResult
* @param orderCode
* @return
*/
@GetMapping("/pushChargeStatus/{orderCode}")
public RestApiResponse<?> pushChargeStatus(@PathVariable("orderCode") String orderCode) {
logger.info("甬城泊车平台推送充电状态 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = ycbcService.pushChargeStatus(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 :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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);
// 转换成相应对象
QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class);
queryStartChargeDTO.setOperatorId(dto.getOperatorID());
Map<String, String> map = ycbcService.queryStopCharge(queryStartChargeDTO);
logger.info("甬城泊车平台请求停止充电 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.error("甬城泊车平台请求停止充电 error", e);
}
return CommonResult.failed("甬城泊车平台请求停止充电发生异常");
}
/**
* 甬城泊车推送停止充电结果
* http://localhost:8080/ycbc/pushStartChargeResult
* @param orderCode
* @return
*/
@GetMapping("/pushStopChargeResult/{orderCode}")
public RestApiResponse<?> pushStopChargeResult(@PathVariable("orderCode") String orderCode) {
logger.info("甬城泊车平台推送停止充电结果 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = ycbcService.pushStopChargeResult(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;
}
/**
* 甬城泊车推送充电订单信息
* http://localhost:8080/ycbc/pushChargeOrderInfo
* @param orderCode
* @return
*/
@GetMapping("/pushChargeOrderInfo/{orderCode}")
public RestApiResponse<?> pushChargeOrderInfo(@PathVariable("orderCode") String orderCode) {
logger.info("甬城泊车平台推送充电订单信息 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
String result = ycbcService.pushChargeOrderInfo(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;
}
}

View File

@@ -0,0 +1,284 @@
package com.jsowell.api.thirdparty;
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.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.dto.PushInfoParamDTO;
import com.jsowell.pile.dto.PushRealTimeInfoDTO;
import com.jsowell.pile.dto.PushStationInfoDTO;
import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 中电联 controller
*
* @author Lemon
* @Date 2023/9/14 15:31
*/
@Anonymous
@RestController
@RequestMapping("/zdl")
public class ZDLController extends BaseController {
@Autowired
private ZDLService zdlService;
@Autowired
private LianLianService lianLianService;
/**
* 获取token接口
* http://localhost:8080/zdl/v1/query_token
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("中电联平台请求令牌 params:{}", JSON.toJSONString(dto));
try {
Map<String, String> map = zdlService.generateToken(dto);
logger.info("中电联平台请求令牌 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
} catch (UnsupportedEncodingException e) {
logger.error("中电联平台 请求令牌接口 异常");
return CommonResult.failed("获取token发生异常");
}
}
/**
* 中电联平台查询充电站信息
* http://localhost:8080/zdl/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:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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.NING_BO_PLATFORM.getTypeCode());
Map<String, String> map = zdlService.queryStationsInfo(queryStationInfoDTO);
logger.info("中电联平台查询充电站信息 result:{}", JSON.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/zdl/v1/query_stations_stats
* @param dto
* @return
*/
@PostMapping("/v1/query_station_stats")
public CommonResult<?> queryStationStats(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("中电联平台查询统计信息 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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 = zdlService.queryStationStats(queryStationInfoDTO);
logger.info("中电联平台查询统计信息 result:{}", JSON.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/zdl/v1/query_stations_status
* @param dto
* @return
*/
@PostMapping("/v1/query_station_status")
public CommonResult<?> queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
logger.info("中电联平台设备接口状态查询 params:{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
// 校验失败
return CommonResult.failed("令牌校验错误");
}
// 校验签名
Map<String, String> resultMap = lianLianService.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");
// String dataString = "L31IkD83nw7bm+eWcvfB1U27uIqSBg29+CHyZu6+qlQ=";
// String dataSecret = "vj3RWNsWIxT5MC2K";
// String dataSecretIV = "jjkySnGlM3pbOUki";
// 解密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 = zdlService.queryStationStatus(queryStationInfoDTO);
logger.info("中电联平台设备接口状态查询 result:{}", JSON.toJSONString(map));
return CommonResult.success(0, "设备接口状态查询成功!", map.get("Data"), map.get("Sig"));
} catch (Exception e) {
logger.info("中电联平台设备接口状态查询 error:", e);
e.printStackTrace();
}
return CommonResult.failed("设备接口状态查询发生异常");
}
/**
* 推送充电站信息 notification_stationInfo
* http://localhost:8080/zdl/v1/pushStationInfo
* @param dto
* @return
*/
@PostMapping("/pushStationInfo")
public RestApiResponse<?> pushStationInfo(@RequestBody PushStationInfoDTO dto) {
logger.info("推送中电联平台充电站信息 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getStationId()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
zdlService.pushStationInfo(dto);
response = new RestApiResponse<>();
}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;
}
/**
* 中电联平台设备状态变化推送
* http://localhost:8080/zdl/v1/pushStationStatus
* @param dto
* @return
*/
@PostMapping("/pushStationStatus")
public RestApiResponse<?> pushStationStatus(@RequestBody PushInfoParamDTO dto) {
logger.info("中电联平台设备状态变化推送 params:{}", JSON.toJSONString(dto));
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(String.valueOf(dto.getPileConnectorCode())) ||
StringUtils.isBlank(String.valueOf(dto.getStatus()))) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
PushRealTimeInfoDTO pushRealTimeInfoDTO = new PushRealTimeInfoDTO();
pushRealTimeInfoDTO.setStatus(dto.getStatus());
pushRealTimeInfoDTO.setPileConnectorCode(dto.getPileConnectorCode());
pushRealTimeInfoDTO.setThirdPartyType(ThirdPlatformTypeEnum.NING_BO_PLATFORM.getTypeCode());
String result = zdlService.notificationStationStatus(pushRealTimeInfoDTO);
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 orderCode
* @return
*/
@GetMapping("/pushOrderInfo/{orderCode}")
public RestApiResponse<?> pushOrderInfo(@PathVariable("orderCode")String orderCode) {
logger.info("中电联平台推送订单信息 params:{}", orderCode);
RestApiResponse<?> response = null;
try {
if (StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
String result = zdlService.pushChargeOrderInfo(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;
}
}

View File

@@ -13,8 +13,8 @@ import com.jsowell.pile.dto.QueryStationDTO;
import com.jsowell.pile.dto.RemoteGroundLockDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
import com.jsowell.pile.vo.web.ThirdPartySnRelationVO;
import com.jsowell.web.controller.pile.PileConnectorInfoController;
import com.jsowell.thirdparty.common.CommonService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,7 +23,6 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 充电桩相关接口
@@ -192,7 +191,7 @@ public class PileController extends BaseController {
/**
* 修改第三方平台枪口状态
* @see com.jsowell.web.controller.pile.PileConnectorInfoController#updateThirdPartyConnectorStatus(com.jsowell.pile.dto.QueryConnectorListDTO)
* @see PileConnectorInfoController#updateThirdPartyConnectorStatus(com.jsowell.pile.dto.QueryConnectorListDTO)
* 两个方法完全相同,如有修改需同步修改
*/
private void updateThirdPartyConnectorStatus(QueryConnectorListDTO dto) {