Merge branch 'dev' into dev-g

This commit is contained in:
Guoqs
2025-06-19 11:15:00 +08:00
4 changed files with 1329 additions and 12 deletions

View File

@@ -0,0 +1,471 @@
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.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* 常州对接Controller
*/
@Anonymous
@RestController
@RequestMapping("/changzhou")
public class ChangZhouController extends ThirdPartyBaseController {
private final String platformName = "新运常畅充";
private final String platformType = ThirdPlatformTypeEnum.CHANG_ZHOU_PLATFORM.getTypeCode();
@Autowired
@Qualifier("changZhouPlatformServiceImpl")
private ThirdPartyPlatformService platformLogic;
/**
* getToken
*/
@PostMapping("/v1/query_token")
public CommonResult<?> queryToken(@RequestBody CommonParamsDTO dto) {
logger.info("{}-请求令牌 params:{}" , platformName , JSON.toJSONString(dto));
try {
// Map<String, String> map = zdlService.generateToken(dto);
Map<String, String> map = platformLogic.queryToken(dto);
logger.info("{}-请求令牌 result:{}" , platformName , map);
return CommonResult.success(0 , "请求令牌成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.info("{}-请求令牌 error:" , platformName , e);
return CommonResult.failed("获取token发生异常");
}
}
/**
* 查询充电站信息
* query_stations_info
*/
@PostMapping("/v1/query_stations_info")
public CommonResult<?> query_stations_info(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-查询充电站信息 params:{}" , platformName , JSON.toJSONString(dto));
try {
logger.info("{}-携带的token:{}",platformName, request.getHeader("Authorization"));
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStationsInfo(queryStationInfoDTO);
logger.info("{}-查询充电站信息 result:{}" , platformName , JSON.toJSONString(map));
return CommonResult.success(0 , "查询充电站信息成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.info("{}-查询充电站信息 error:" , platformName , e);
}
return CommonResult.failed("查询充电站信息发生异常");
}
/**
* 设备状态推送
* notification_stationStatus
*
* @param request
* @return
*/
@PostMapping("/v1/notification_stationStatus")
public RestApiResponse<?> notification_stationStatus(@RequestBody PushRealTimeInfoDTO pushRealTimeInfoDTO , HttpServletRequest request) {
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationStationStatus(pushRealTimeInfoDTO);
logger.info("【{}】推送设备状态 result:{}" , this.getClass().getSimpleName() , result);
response = new RestApiResponse<>(result);
} catch (BusinessException e) {
logger.error("【{}】推送设备状态 error:{}" , this.getClass().getSimpleName() , e.getMessage());
response = new RestApiResponse<>(e.getCode() , e.getMessage());
} catch (Exception e) {
logger.error("【{}】推送设备状态 error:{}" , this.getClass().getSimpleName() , e);
response = new RestApiResponse<>(e);
}
logger.info("【{}】推送设备状态 response:{}" , this.getClass().getSimpleName() , response);
return response;
}
/**
* 设备接口状态查询 query_station_status
*
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_station_status")
public CommonResult<?> query_stations_status(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-设备接口状态查询 params:{}" , platformName , JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStationStatus(queryStationInfoDTO);
logger.info("{}-设备接口状态查询 result:{}" , platformName , map);
return CommonResult.success(0 , "设备接口状态查询成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.info("{}-设备接口状态查询 error:" , platformName , e);
}
return CommonResult.failed("设备接口状态查询发生异常");
}
/**
* 统计信息查询 query_station_stats
*
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_station_stats")
public CommonResult<?> query_station_stats(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-查询统计信息 params:{}" , platformName , JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStationStats(queryStationInfoDTO);
logger.info("{}-查询统计信息 result:{}" , platformName , map);
return CommonResult.success(0 , "查询统计信息成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.info("{}-查询统计信息 error:" , platformName , e);
}
return CommonResult.failed("查询统计信息发生异常");
}
/**
* 请求设备认证
*
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_equip_auth")
public CommonResult<?> query_equip_auth(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-请求设备认证 params:{}" , platformName , JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
dto.setPlatformType(platformType);
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryEquipmentDTO queryEquipmentDTO = parseParamsDTO(dto , QueryEquipmentDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryEquipAuth(queryEquipmentDTO);
logger.info("{}-请求设备认证 result:{}" , platformName , map);
return CommonResult.success(0 , "请求设备认证成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.error("{}-请求设备认证 error:" , platformName , e);
}
return CommonResult.failed("请求设备认证发生异常");
}
/**
* 查询业务策略信息
*
* @param dto
*/
@RequestMapping("/v1/query_equip_business_policy")
public CommonResult<?> query_equip_business_policy(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-查询业务策略信息 params:{}" , platformName , JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto , QueryStartChargeDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryEquipBusinessPolicy(queryStartChargeDTO);
logger.info("{}-查询业务策略信息 result:{}" , platformName , map);
return CommonResult.success(0 , "查询业务策略信息成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.info("{}-查询业务策略信息 error:" , platformName , e);
}
return CommonResult.failed("查询业务策略信息发生异常");
}
/**
* 请求启动充电
*
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_start_charge")
public CommonResult<?> query_start_charge(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-请求启动充电 params:{}" , platformName , JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
dto.setPlatformType(platformType);
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto , QueryStartChargeDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryStartCharge(queryStartChargeDTO);
logger.info("{}-请求启动充电 result:{}" , platformName , map);
return CommonResult.success(0 , "请求启动充电成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.error("{}-请求启动充电 error:" , platformName , e);
}
return CommonResult.failed("请求启动充电发生异常");
}
/**
* 推送启动充电结果
*
* @param
* @return
*/
@GetMapping("/v1/notification_start_charge_result/{orderCode}")
public RestApiResponse<?> notification_start_charge_result(@PathVariable("orderCode") String orderCode) {
logger.info("【{}】推送启动充电结果 params:{}" , this.getClass().getSimpleName() , orderCode);
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationStartChargeResult(orderCode);
logger.info("【{}】推送启动充电结果 result:{}" , this.getClass().getSimpleName() , result);
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<?> query_equip_charge_status(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-查询充电状态 params:{}" , platformName , JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
dto.setPlatformType(platformType);
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = parseParamsDTO(dto , QueryEquipChargeStatusDTO.class);
// 执行逻辑
Map<String, String> map = platformLogic.queryEquipChargeStatus(queryEquipChargeStatusDTO);
logger.info("{}-查询充电状态 result:{}" , platformName , map);
return CommonResult.success(0 , "查询充电状态成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.error("{}-查询充电状态 error:" , platformName , e);
}
return CommonResult.failed("查询充电状态发生异常");
}
/**
* 推送充电状态
* http://localhost:8080/hainan/notificationEquipChargeStatus
*
* @param orderCode
* @return
*/
@GetMapping("/v1/notification_equip_charge_status/{orderCode}")
public RestApiResponse<?> notification_equip_charge_status(@PathVariable("orderCode") String orderCode) {
logger.info("推送充电状态 params:{}" , orderCode);
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationEquipChargeStatus(orderCode);
logger.info("推送充电状态 result:{}" , result);
response = new RestApiResponse<>(result);
} catch (BusinessException e) {
logger.error("推送充电状态 error" , e);
response = new RestApiResponse<>(e.getCode() , e.getMessage());
} catch (Exception e) {
logger.error("推送充电状态 error" , e);
response = new RestApiResponse<>(e);
}
logger.info("推送充电状态 result:{}" , response);
return response;
}
/**
* 请求停止充电
*
* @param request
* @param dto
* @return
*/
@PostMapping("/v1/query_stop_charge")
public CommonResult<?> query_stop_charge(HttpServletRequest request , @RequestBody CommonParamsDTO dto) {
logger.info("{}-请求停止充电 params :{}" , platformName , JSON.toJSONString(dto));
try {
// 校验令牌
if (!verifyToken(request.getHeader("Authorization"))) {
// 校验失败
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
if (!verifySignature(dto)) {
// 签名错误
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参
QueryStartChargeDTO queryStartChargeDTO = parseParamsDTO(dto , QueryStartChargeDTO.class);
logger.info("{}-请求停止充电 params :{}" , platformName , JSON.toJSONString(queryStartChargeDTO));
// 执行逻辑
Map<String, String> map = platformLogic.queryStopCharge(queryStartChargeDTO);
return CommonResult.success(0 , "请求停止充电成功!" , map.get("Data") , map.get("Sig"));
} catch (Exception e) {
logger.error("{}-请求停止充电 error" , platformName , e);
}
return CommonResult.failed("{}-请求停止充电发生异常");
}
/**
* 推送停止充电结果
* http://localhost:8080/hainan/notificationStopChargeResult
*
* @param orderCode
* @return
*/
@GetMapping("/v1/notification_stop_charge_result/{orderCode}")
public RestApiResponse<?> notification_stop_charge_result(@PathVariable("orderCode") String orderCode) {
logger.info("推送停止充电结果 params:{}" , orderCode);
RestApiResponse<?> response = null;
try {
String result = platformLogic.notificationStopChargeResult(orderCode);
logger.info("推送停止充电结果 result:{}" , result);
response = new RestApiResponse<>(result);
} catch (BusinessException e) {
logger.error("推送停止充电结果 error" , e);
response = new RestApiResponse<>(e.getCode() , e.getMessage());
} catch (Exception e) {
logger.error("推送停止充电结果 error" , e);
response = new RestApiResponse<>(e);
}
logger.info("推送停止充电结果 result:{}" , response);
return response;
}
/**
* 充电订单信息推送
*/
@PostMapping("/v1/notification_charge_order_info")
public RestApiResponse<?> notification_charge_order_info(@RequestBody QueryOrderDTO dto) {
RestApiResponse<?> response = null;
try {
String result = platformLogic.pushOrderInfo(dto);
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

@@ -8,17 +8,17 @@ spring:
# redis 配置
redis:
# 地址
host: r-uf6k0uet7mihr5z78f.redis.rds.aliyuncs.com
# host: 106.14.94.149
# host: r-uf6k0uet7mihr5z78f.redis.rds.aliyuncs.com
host: 106.14.94.149
# 端口默认为6379
port: 6379
# 数据库索引
database: 0
# 账号
username: jsowell
# 密码
password: js@160829
# password: js160829
# username: jsowell
# # 密码
# password: js@160829
password: js160829
# 连接超时时间
timeout: 10s
lettuce:
@@ -38,12 +38,12 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://rm-uf6ra51u33dc3798l.mysql.rds.aliyuncs.com:3306/jsowell_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: jsowell
password: js@160829
# url: jdbc:mysql://106.14.94.149:3306/jsowell_pre?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: jsowell_pre
# password: Js@160829
# url: jdbc:mysql://rm-uf6ra51u33dc3798l.mysql.rds.aliyuncs.com:3306/jsowell_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: jsowell
# password: js@160829
url: jdbc:mysql://106.14.94.149:3306/jsowell_pre?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: jsowell_pre
password: Js@160829
# 从库数据源
slave:
# 从数据源开关/默认关闭

View File

@@ -35,6 +35,7 @@ public enum ThirdPlatformTypeEnum {
HE_NAN_PLATFORM("22", "河南省平台", "050880341"),
WEI_WANG_XIN_DIAN("23", "微网新电", "MA005DBW1"),
HU_ZHOU_PLATFORM("24", "湖州市监管平台", "MA27U00HZ"),
CHANG_ZHOU_PLATFORM("25", "新运常畅充", "0585PCW57"),
;
private String typeCode;

View File

@@ -0,0 +1,845 @@
package com.jsowell.thirdparty.platform.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.thirdparty.ConnectorInfo;
import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
import com.jsowell.pile.vo.web.PileConnectorInfoVO;
import com.jsowell.pile.vo.web.PileModelInfoVO;
import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO;
import com.jsowell.thirdparty.lianlian.domain.ConnectorChargeStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo;
import com.jsowell.thirdparty.lianlian.vo.*;
import com.jsowell.thirdparty.platform.domain.SupStationInfo;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.HttpRequestUtil;
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.bouncycastle.crypto.CryptoException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.*;
@Service
@Slf4j
public class ChangZhouPlatformServiceImpl implements ThirdPartyPlatformService {
private final String thirdPlatformType = ThirdPlatformTypeEnum.CHANG_ZHOU_PLATFORM.getTypeCode();
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private PileBasicInfoService pileBasicInfoService;
@Autowired
private PileModelInfoService pileModelInfoService;
@Autowired
private PileConnectorInfoService pileConnectorInfoService;
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private PileBillingTemplateService pileBillingTemplateService;
@Autowired
private YKCPushCommandService ykcPushCommandService;
@Autowired
private PileRemoteService pileRemoteService;
@Override
public void afterPropertiesSet() throws Exception {
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
}
/**
* query_token 获取token提供给第三方平台使用
*
* @param dto
* @return
*/
@Override
public Map<String, String> queryToken(CommonParamsDTO dto) {
AccessTokenVO vo = new AccessTokenVO();
// 0:成功1:失败
int succStat = 0;
// 0:无1:无此对接平台2:密钥错误; 399:自定义
int failReason = 0;
String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID();
// 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId);
if (thirdPartySecretInfoVO == null) {
failReason = 1;
succStat = 1;
} else {
String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
// 解密data 获取参数中的OperatorSecret
String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv);
String inputOperatorSecret = null;
if (StringUtils.isNotBlank(decrypt)) {
inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret");
if (StringUtils.isBlank(inputOperatorSecret)) {
inputOperatorSecret = JSON.parseObject(decrypt).getString("PlatformSecret");
}
}
// 对比密钥
List<String> operatorSecretList = Lists.newArrayList(theirOperatorSecret, thirdPartySecretInfoVO.getOurOperatorSecret());
if (!operatorSecretList.contains(inputOperatorSecret)) {
failReason = 1;
succStat = 1;
} else {
// 生成token
String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis);
vo.setAccessToken(token);
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
}
}
// 组装返回参数
vo.setPlatformId(operatorId);
vo.setFailReason(failReason);
vo.setSuccStat(succStat);
return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
}
/**
* 查询站点信息
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map<String, String> queryStationsInfo(QueryStationInfoDTO dto) {
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
dto.setThirdPlatformType(thirdPlatformType);
PageUtils.startPage(pageNo, pageSize);
List<ThirdPartyStationInfoVO> stationInfos = pileStationInfoService.selectStationInfosByThirdParty(dto);
if (CollectionUtils.isEmpty(stationInfos)) {
// 未查到数据
return null;
}
// ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
List<SupStationInfo> resultList = new ArrayList<>();
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
SupStationInfo stationInfo = new SupStationInfo();
stationInfo.setStationID(String.valueOf(pileStationInfo.getId()));
stationInfo.setOperatorID(Constants.OPERATORID_JIANG_SU); // 组织机构代码
String organizationCode = pileStationInfo.getOrganizationCode();
if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) {
String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1);
stationInfo.setEquipmentOwnerID(equipmentOwnerId);
}else {
stationInfo.setEquipmentOwnerID(Constants.OPERATORID_JIANG_SU);
}
stationInfo.setStationName(pileStationInfo.getStationName());
stationInfo.setCountryCode(pileStationInfo.getCountryCode());
String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213
// 根据逗号分组
String[] split = StringUtils.split(areaCode, ",");
// 只取最后一部分 330213
String subAreaCode = split[split.length - 1];
stationInfo.setAreaCode(subAreaCode);
stationInfo.setAddress(pileStationInfo.getAddress());
stationInfo.setServiceTel(pileStationInfo.getStationTel());
stationInfo.setStationType(Integer.parseInt(pileStationInfo.getStationType()));
stationInfo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus()));
stationInfo.setParkNums(Integer.parseInt(pileStationInfo.getParkNums()));
stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng()));
stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat()));
stationInfo.setConstruction(Integer.parseInt(pileStationInfo.getConstruction()));
// 停车费率描述
if (StringUtils.isNotBlank(pileStationInfo.getParkFeeDescribe())) {
stationInfo.setParkFee(pileStationInfo.getParkFeeDescribe());
}
// 站点图片
if (StringUtils.isNotBlank(pileStationInfo.getPictures())) {
stationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(",")));
}
List<EquipmentInfo> pileList = getPileList(pileStationInfo);
if (CollectionUtils.isNotEmpty(pileList)) {
stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表
}
resultList.add(stationInfo);
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("ItemSize", resultList.size());
map.put("PageCount", pageInfo.getPages());
map.put("PageNo", pageInfo.getPageNum());
map.put("StationInfos", resultList);
return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO);
}
/**
* 设备状态推送
* @param stationId 站点id
* @param pileConnectorCode 充电桩枪口编号
* @param status
* @param secretInfoVO
* @return
*/
@Override
public String notificationStationStatus(String stationId, String pileConnectorCode, String status, ThirdPartySecretInfoVO secretInfoVO) {
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
// 通过站点id查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
String operatorId = thirdPartySecretInfoVO.getOurOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue();
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
.connectorID(pileConnectorCode)
.status(Integer.parseInt(status))
.build();
JSONObject json = new JSONObject();
json.put("ConnectorStatusInfo", info);
String jsonString = JSON.toJSONString(json);
log.info("参数:{}", jsonString);
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
log.info("token{}", token);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
log.info("返回结果:{}", result);
return result;
}
/**
* 设备接口状态查询 query_station_status
* @param dto 查询站点信息dto
* @return
*/
@Override
public Map<String, String> queryStationStatus(QueryStationInfoDTO dto) {
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
for (String stationId : stationIds) {
StationStatusInfo stationStatusInfo = new StationStatusInfo();
stationStatusInfo.setStationId(stationId);
// 根据站点id查询
List<ConnectorInfoVO> list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId));
List<Object> connectorStatusInfos = new ArrayList<>();
for (ConnectorInfoVO connectorInfoVO : list) {
// 其他
ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo();
connectorStatusInfo.setConnectorID(connectorInfoVO.getPileConnectorCode());
connectorStatusInfo.setStatus(Integer.parseInt(connectorInfoVO.getConnectorStatus()));
connectorStatusInfos.add(connectorStatusInfo);
}
stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
stationStatusInfos.add(stationStatusInfo);
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("StationStatusInfos", stationStatusInfos);
log.info("返回参数:{}", JSON.toJSONString(map));
return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO);
}
/**
* 请求设备认证 query equip auth
* @param dto 请求设备认证
* @return
*/
@Override
public Map<String, String> queryEquipAuth(QueryEquipmentDTO dto) {
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
EquipmentAuthVO vo = new EquipmentAuthVO();
String equipAuthSeq = dto.getEquipAuthSeq();
String pileConnectorCode = dto.getConnectorID();
// 根据桩编号查询数据
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
vo.setSuccStat(1); // 1-失败 0-成功 默认失败
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
if (pileBasicInfo != null) {
// 查询当前枪口数据
PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode);
if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), String.valueOf(connectorInfo.getStatus()))
|| StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), String.valueOf(connectorInfo.getStatus()))
|| StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_RESERVED_LOCK.getValue(), String.valueOf(connectorInfo.getStatus()))
) {
vo.setSuccStat(0);
vo.setFailReason(0);
} else {
vo.setSuccStat(1);
vo.setFailReason(1); // 1- 此设备尚未插枪;
}
vo.setEquipAuthSeq(equipAuthSeq);
vo.setConnectorID(pileConnectorCode);
} else {
vo.setFailReason(2); // 设备检测失败
vo.setFailReasonMsg("未查到该桩的数据");
}
log.info("返回参数:{}", JSON.toJSONString(vo));
return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
}
/**
* 查询业务策略 query_equip_business_policy
* @param dto 请求启动充电DTO
* @return
*/
@Override
public Map<String, String> queryEquipBusinessPolicy(QueryStartChargeDTO dto) {
List<EquipBusinessPolicyVO.PolicyInfo> policyInfoList = new ArrayList<>();
String pileConnectorCode = dto.getConnectorID();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
// 截取桩号
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
// 查询该桩的站点id
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
// 根据桩号查询正在使用的计费模板
List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileBasicInfo.getStationId()));
if (CollectionUtils.isEmpty(billingPriceVOList)) {
return null;
}
EquipBusinessPolicyVO.PolicyInfo policyInfo = null;
for (BillingPriceVO billingPriceVO : billingPriceVOList) {
// 将时段开始时间、电费、服务费信息进行封装
policyInfo = new EquipBusinessPolicyVO.PolicyInfo();
String startTime = billingPriceVO.getStartTime() + ":00"; // 00:00:00 格式
// 需要将中间的冒号去掉,改为 000000 格式
String replace = StringUtils.replace(startTime, ":", "");
policyInfo.setStartTime(replace);
policyInfo.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
policyInfo.setServicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
policyInfoList.add(policyInfo);
}
// 拼装所需要的数据格式
EquipBusinessPolicyVO vo = EquipBusinessPolicyVO.builder()
.equipBizSeq(dto.getEquipBizSeq())
.connectorId(dto.getConnectorID())
.succStat(0)
.failReason(0)
.sumPeriod(policyInfoList.size())
.policyInfos(policyInfoList)
.build();
log.info("返回参数:{}", JSON.toJSONString(vo));
return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
}
/**
* 请求启动充电 query_start_charge
* @param dto 请求启动充电DTO
* @return
*/
@Override
public Map<String, String> queryStartCharge(QueryStartChargeDTO dto) {
// 通过传过来的订单号和枪口号生成订单
String pileConnectorCode = dto.getConnectorID();
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq());
if (orderInfo != null) {
// 平台已存在订单
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
// 生成订单
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(dto);
String orderCode = (String) map.get("orderCode");
String transactionCode = (String) map.get("transactionCode");
OrderBasicInfo orderBasicInfo = (OrderBasicInfo) map.get("orderBasicInfo");
// 发送启机指令
StartChargingCommand command = StartChargingCommand.builder()
.pileSn(orderBasicInfo.getPileSn())
.connectorCode(orderBasicInfo.getConnectorCode())
.transactionCode(transactionCode)
.chargeAmount(orderBasicInfo.getPayAmount())
.logicCardNum(null)
.physicsCardNum(null)
.build();
ykcPushCommandService.pushStartChargingCommand(command);
// 拼装对应的数据并返回
QueryStartChargeVO vo = QueryStartChargeVO.builder()
.startChargeSeq(orderCode)
.startChargeSeqStat(2) // 1、启动中 2、充电中3、停止中4、已结束5、未知
.connectorID(pileConnectorCode)
.succStat(0)
.failReason(0)
.build();
log.info("返回参数:{}", JSON.toJSONString(vo));
return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
}
/**
* 推送启动充电结果 notification_start_charge_result
* @param orderCode 订单编号
* @return
*/
@Override
public String notificationStartChargeResult(String orderCode) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
if (orderInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 推送启动充电结果(调用接口 notification_start_charge_result)
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_START_CHARGE_RESULT.getValue();
// 拼装参数
JSONObject json = new JSONObject();
json.put("StartChargeSeq", orderCode);
json.put("ConnectorID", orderInfo.getPileConnectorCode());
json.put("StartChargeSeqStat", 2); // 一定要给 2-充电中
json.put("StartTime", DateUtils.getDateTime());
String jsonString = JSON.toJSONString(json);
log.info("请求参数:{}", jsonString);
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
/**
* 查询充电状态 query equip charge status
* @param dto 查询充电状态DTO
* @return
*/
@Override
public Map<String, String> queryEquipChargeStatus(QueryEquipChargeStatusDTO dto) {
String operatorID = dto.getOperatorID();
// 通过订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq());
// logger.info(operatorName + "查询订单信息 orderInfo:{}", orderInfo);
if (orderInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
// 通过订单号查询实时数据
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
QueryChargingStatusVO vo;
if (CollectionUtils.isEmpty(realTimeData)) {
vo = new QueryChargingStatusVO();
} else {
RealTimeMonitorData data = realTimeData.get(0);
String orderStatus = orderInfo.getOrderStatus();
if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) {
// 充电中
orderStatus = "2";
}else if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) {
// 充电完成
orderStatus = "4";
} else {
// 直接给 5-未知
orderStatus = "5";
}
String status = data.getConnectorStatus();
int connectorStatus = 0;
if (StringUtils.isBlank(status)) {
// 查询当前枪口状态
PileConnectorInfoVO connectorInfoVO = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode());
connectorStatus = connectorInfoVO.getStatus();
}else {
connectorStatus = Integer.parseInt(status);
}
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount();
// 拼装联联平台数据
vo = QueryChargingStatusVO.builder()
.startChargeSeq(dto.getStartChargeSeq()) // 订单号
.startChargeSeqStat(Integer.parseInt(orderStatus)) // 订单状态
.connectorID(orderInfo.getPileConnectorCode()) // 枪口编码
.connectorStatus(connectorStatus) // 枪口状态
.currentA(new BigDecimal(data.getOutputCurrent())) // 电流
.voltageA(new BigDecimal(data.getOutputVoltage())) // 电压
.soc(new BigDecimal(data.getSOC()))
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间
.endTime(DateUtils.getDateTime()) // 本次采样时间
.totalPower(new BigDecimal(data.getChargingDegree()).setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计充电量
.elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费
.seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费
.totalMoney(new BigDecimal(data.getChargingAmount())) // 已充金额
.build();
}
log.info("返回参数:{}", JSON.toJSONString(vo));
return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
}
/**
* 推送充电状态 notification_equip_charge_status
* @param orderCode 订单编号
* @return
*/
@Override
public String notificationEquipChargeStatus(String orderCode) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
// 查询枪口状态
PileConnectorInfoVO info = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode());
BigDecimal current = info.getCurrent() == null ? BigDecimal.ZERO : info.getCurrent();
BigDecimal voltage = info.getVoltage() == null ? BigDecimal.ZERO : info.getVoltage();
String soc = info.getSOC() == null ? Constants.ZERO : info.getSOC();
// 查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount();
QueryChargingStatusVO vo = QueryChargingStatusVO.builder()
.startChargeSeq(orderInfo.getOrderCode()) // 订单号
.startChargeSeqStat(Integer.parseInt(orderInfo.getOrderStatus())) // 订单状态
.connectorID(orderInfo.getPileConnectorCode()) // 枪口编码
.connectorStatus(info.getStatus()) // 枪口状态
.currentA(info.getCurrent()) // 电流
.voltageA(info.getVoltage()) // 电压
.soc(new BigDecimal(info.getSOC()))
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间
.endTime(DateUtils.getDateTime()) // 本次采样时间
.totalPower(info.getChargingDegree()) // 累计充电量
.elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费
.seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费
.totalMoney(info.getChargingAmount()) // 已充金额
.build();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getValue();
// 调用平台接口
String jsonString = JSON.toJSONString(vo);
log.info("请求参数:{}", jsonString);
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
/**
* 请求停止充电 query_stop_charge
* @param dto
* @return
*/
@Override
public Map<String, String> queryStopCharge(QueryStartChargeDTO dto) {
QueryStopChargeVO vo = new QueryStopChargeVO();
String orderCode = dto.getStartChargeSeq();
ThirdPartySecretInfoVO wangKuaiDianPlatformSecretInfo = getChangZhouSecretInfo();
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
if (orderInfo == null) {
return null;
}
// 若状态为充电中,则发送停机指令
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) {
// 充电中
pileRemoteService.remoteStopCharging(orderInfo.getPileSn(), orderInfo.getConnectorCode(), orderInfo.getTransactionCode());
vo.setStartChargeSeq(orderCode);
vo.setStartChargeSeqStat(4); // 1、启动中 2、充电中3、停止中4、已结束5、未知
}
vo.setSuccStat(0);
vo.setFailReason(0);
vo.setStartChargeSeq(orderCode);
log.info("返回参数:{}", JSON.toJSONString(vo));
return ThirdPartyPlatformUtils.generateResultMap(vo, wangKuaiDianPlatformSecretInfo);
}
/**
* 推送停止充电结果 notification_stop_charge_result
* @param orderCode 订单编号
* @return
*/
@Override
public String notificationStopChargeResult(String orderCode) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
if (orderInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getChangZhouSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STOP_CHARGE_RESULT.getValue();
// 拼装联联平台参数
JSONObject json = new JSONObject();
json.put("StartChargeSeq", orderCode);
json.put("StartChargeSeqStat", 4); // 只能给 4-已结束
json.put("ConnectorID", orderInfo.getPileConnectorCode());
json.put("SuccStat", 0);
json.put("FailReason", 0);
String jsonString = JSON.toJSONString(json);
log.info("请求参数:{}", jsonString);
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
@Override
public String pushOrderInfo(QueryOrderDTO dto) {
ThirdPartySecretInfoVO wangKuaiDianPlatformSecretInfo = getChangZhouSecretInfo();
// 根据站点id 开始时间,结束时间查询出所有的订单信息
// List<OrderListVO> orderListVOS = orderBasicInfoService.selectOrderBasicInfoList(dto);
List<String> orderCodes = orderBasicInfoService.tempGetOrderCodes(dto);
if (CollectionUtils.isEmpty(orderCodes)) {
return "订单信息为空";
}
// List<String> orderCodeList = orderListVOS.stream().map(OrderListVO::getOrderCode).collect(Collectors.toList());
for (String orderCode : orderCodes) {
try {
String result = notificationChargeOrderInfo(orderCode, wangKuaiDianPlatformSecretInfo);
log.info("订单:{} 推送结果:{}", orderCode, result);
}catch (Exception e) {
log.error("订单:{} 推送error, ", orderCode, e);
}
}
return "Success";
}
/**
* 推送订单数据 notificationChargeOrderInfo
* @param orderCode 订单编号
* @return
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws NoSuchProviderException
* @throws CryptoException
*/
@Override
public String notificationChargeOrderInfo(String orderCode, ThirdPartySecretInfoVO thirdPartySecretInfoVO) {
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_CHARGE_ORDER_INFO.getValue();
Date chargeStartTime = orderBasicInfo.getChargeStartTime();
if (chargeStartTime == null) {
chargeStartTime = orderBasicInfo.getCreateTime();
}
Date chargeEndTime = orderBasicInfo.getChargeEndTime();
if (chargeEndTime == null) {
chargeEndTime = orderBasicInfo.getCreateTime();
}
JSONObject json = new JSONObject();
json.put("StartChargeSeq", orderCode);
json.put("ConnectorID", orderBasicInfo.getPileConnectorCode());
json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeStartTime));
json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, chargeEndTime));
json.put("TotalPower", orderDetail.getTotalUsedElectricity().setScale(2, BigDecimal.ROUND_HALF_UP));
json.put("TotalElecMoney", orderDetail.getTotalElectricityAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
json.put("TotalSeviceMoney", orderDetail.getTotalServiceAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
json.put("TotalMoney", orderDetail.getTotalOrderAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
json.put("StopReason", 2); // 2BMS 停止充电
String jsonString = JSON.toJSONString(json);
log.info("请求参数:{}", jsonString);
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
/**
* 获取配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getChangZhouSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
/**
* 获取桩列表信息
*
* @param pileStationInfo
* @return
*/
private List<EquipmentInfo> getPileList(PileStationInfo pileStationInfo) {
List<EquipmentInfo> resultList = new ArrayList<>();
// 通过站点id查询桩基本信息
List<PileBasicInfo> list = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId()));
// 封装成中电联平台对象
for (PileBasicInfo pileBasicInfo : list) {
EquipmentInfo equipmentInfo = new EquipmentInfo();
String pileSn = pileBasicInfo.getSn();
equipmentInfo.setEquipmentID(pileSn);
PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn);
equipmentInfo.setEquipmentType(Integer.parseInt(modelInfo.getSpeedType()));
equipmentInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));
List<ConnectorInfo> connectorList = getConnectorList(pileBasicInfo);
equipmentInfo.setConnectorInfos(connectorList);
resultList.add(equipmentInfo);
}
return resultList;
}
/**
* 获取枪口列表
*
* @param pileBasicInfo
* @return
*/
private List<ConnectorInfo> getConnectorList(PileBasicInfo pileBasicInfo) {
List<ConnectorInfo> resultList = new ArrayList<>();
List<PileConnectorInfo> list = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn());
for (PileConnectorInfo pileConnectorInfo : list) {
ConnectorInfo connectorInfo = new ConnectorInfo();
connectorInfo.setConnectorID(pileConnectorInfo.getPileConnectorCode());
String pileSn = pileConnectorInfo.getPileSn();
PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn);
int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3;
connectorInfo.setConnectorType(connectorType);
// 车位号
if (StringUtils.isNotBlank(pileConnectorInfo.getParkNo())) {
connectorInfo.setParkNo(pileConnectorInfo.getParkNo());
}
connectorInfo.setVoltageUpperLimits(Integer.valueOf(modelInfo.getRatedVoltage()));
connectorInfo.setVoltageLowerLimits(Integer.valueOf(modelInfo.getRatedVoltage()));
connectorInfo.setCurrent(Integer.valueOf(modelInfo.getRatedCurrent()));
connectorInfo.setNationalStandard(2);
// if (!StringUtils.equals(modelInfo.getConnectorNum(), "1")) {
// // 如果不是单枪,则枪口功率需要除以枪口数量
// String ratedPowerStr = modelInfo.getRatedPower();
// BigDecimal ratedPower = new BigDecimal(ratedPowerStr);
// connectorInfo.setPower(ratedPower.divide(new BigDecimal(modelInfo.getConnectorNum()), 1, BigDecimal.ROUND_HALF_UP));
// }else {
// }
connectorInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP));
resultList.add(connectorInfo);
}
return resultList;
}
}