This commit is contained in:
2024-02-19 15:25:38 +08:00
5 changed files with 376 additions and 47 deletions

View File

@@ -3,24 +3,25 @@ package com.jsowell.web.controller.thirdparty.huawei;
import com.alibaba.fastjson2.JSONObject;
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.pile.dto.QueryStationInfoDTO;
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.huawei.HuaweiServiceV2;
import com.jsowell.thirdparty.lianlian.common.CommonResult;
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo;
import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.util.Cryptos;
import com.jsowell.thirdparty.lianlian.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 org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
/**
@@ -71,24 +72,262 @@ public class HuaWeiControllerV2 extends BaseController {
}
/**
* 请求设备计费信息
* @param request
* @param dto
* @return
*/
@PostMapping("/v2/request_equip_business_policy")
public CommonResult<?> requestEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) {
return null;
logger.info("华为请求设备计费信息 params:{}", JSONObject.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);
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:{}", JSONObject.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);
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:{}", JSONObject.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);
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:{}", JSONObject.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);
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:{}", JSONObject.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);
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:{}", JSONObject.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);
}
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:{}", JSONObject.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);
return CommonResult.success(0, "接收下发计费策略响应信息成功!", map.get("Data"), map.get("Sig"));
}
// ======================== 以上为 华为 --> 万车充 ========================
// ======================== 下面为 万车充 --> 华为 ========================
/**
* 平台充电设备编码同步
* @param stationId
* @return
*/
@GetMapping("/v2/notification_operation_system_info/{stationId}")
public String notificationOperationSystemInfo(@PathVariable("stationId") String stationId) {
logger.info("华为平台充电设备编码同步 stationId:{}", stationId);
String result = null;
try {
result = huaweiServiceV2.notificationOperationSystemInfo(stationId);
} catch (Exception e) {
logger.error("华为平台充电设备编码同步 error", e);
}
logger.info("华为平台充电设备编码同步 result:{}", result);
return result;
}
/**
* 设备接口状态查询
* @param stationIds
* @return
*/
@PostMapping("/v2/query_station_status")
public List<StationStatusInfo> queryStationStatus(@RequestBody List<String> stationIds) {
logger.info("查询华为设备接口状态 stationIds:{}", stationIds);
List<StationStatusInfo> list = null;
try {
list = huaweiServiceV2.queryStationStatus(stationIds);
} catch (Exception e) {
logger.error("查询华为设备接口状态 error", e);
}
logger.info("查询华为设备接口状态 result:{}", list);
return list;
}
/**
* 请求设备认证
* @param connectorId
* @return
*/
@PostMapping("/v2/query_equip_auth")
public QueryEquipAuthVO queryEquipAuth(@RequestBody String connectorId) {
logger.info("请求华为设备认证 connectorId:{}", connectorId);
QueryEquipAuthVO vo = null;
try {
vo = huaweiServiceV2.queryEquipAuth(connectorId);
} catch (Exception e) {
logger.error("请求华为设备认证 error", e);
}
logger.info("请求华为设备认证 result:{}", JSONObject.toJSONString(vo));
return vo;
}
/**
* 请求启动充电
* @param dto
* @return
*/
@PostMapping("/v2/query_start_charge")
public QueryStartChargeVO queryStartCharge(@RequestBody HWQueryStartChargeDTO dto) {
logger.info("请求华为启动充电 param:{}", JSONObject.toJSONString(dto));
QueryStartChargeVO vo = null;
try {
vo = huaweiServiceV2.queryStartCharge(dto);
} catch (Exception e) {
logger.error("请求华为启动充电 error", e);
}
logger.info("请求华为启动充电 result:{}", JSONObject.toJSONString(vo));
return vo;
}
/**
* 查询充电状态
* @param startChargeSeq
* @return
*/
@PostMapping("/v2/query_equip_charge_status")
public QueryChargeStatusVO queryChargeStatus(@RequestBody String startChargeSeq) {
logger.info("查询华为充电状态 startChargeSeq:{}", startChargeSeq);
QueryChargeStatusVO vo = null;
try {
vo = huaweiServiceV2.queryChargeStatus(startChargeSeq);
} catch (Exception e) {
logger.error("查询华为充电状态 error", e);
}
logger.info("查询华为充电状态 result:{}", JSONObject.toJSONString(vo));
return vo;
}
/**
* 请求停止充电
* @param startChargeSeq
* @return
*/
@PostMapping("/v2/query_stop_charge")
public QueryStartChargeVO queryStopCharge(@RequestBody String startChargeSeq) {
logger.info("请求华为停止充电 startChargeSeq:{}", startChargeSeq);
QueryStartChargeVO vo = null;
try {
vo = huaweiServiceV2.queryStopCharge(startChargeSeq);
}catch (Exception e) {
logger.error("请求华为停止充电 error", e);
}
logger.info("请求华为停止充电 result:{}", JSONObject.toJSONString(vo));
return vo;
}
/**
* 校验令牌
* @param request
* @param dto
* @return
*/
private String checkAuth(HttpServletRequest request, CommonParamsDTO dto) {
// 校验令牌
String token = request.getHeader("Authorization");

View File

@@ -0,0 +1,76 @@
package com.jsowell.pile.dto.huawei;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
/**
* 下发计费策略响应DTO
*
* @author Lemon
* @Date 2024/2/19 10:47:06
*/
@Data
public class DeliverBusinessPolicyResponseDTO {
/**
* 策略下发流水号
*
* 格式“运营商ID+唯一编号”,不超过(<=27字符)
* 与 4.11 下发计费策略 接口的值相同
*/
@JsonProperty(value = "EquipBizSeq")
private String equipBizSeq;
/**
* 业务策略结果返回的数量
*
* 一把枪当前下发后,响应业务策略信息执行结果的数量
* 生效结果支持多次返回一次可以返回1个或多个一个主机下某个计费长时间无结果不阻塞其他枪充电
*/
@JsonProperty(value = "SumChargePolicyInfoRets")
private Integer sumChargePolicyInfoRets;
/**
* 充电业务策略返回信息
*
* 批量不超过100把枪每把枪返回对应的信息
*/
@JsonProperty(value = "ChargePolicyInfoRets")
private List<ChargePolicyInfoRet> chargePolicyInfoRets;
@Data
public static class ChargePolicyInfoRet{
/**
* 充电设备接口编码
*/
@JsonProperty(value = "ConnectorID")
private String connectorID;
/**
* 计费策略ID
*/
@JsonProperty(value = "EquipBizID")
private String equipBizID;
/**
* 操作结果
* 0成功
* 1失败
*/
@JsonProperty(value = "SuccStat")
private Integer succStat;
/**
* 失败原因
* 0
* 1设备离线
* 2设备响应超时
* 3策略下发设备失败
* 4服务异常
* 5此充电枪不存在
*/
@JsonProperty(value = "FailReason")
private Integer failReason;
}
}

View File

@@ -158,7 +158,7 @@ public class CommonService {
// result = huaWeiService.notificationOperationSystemInfo(dto);
// }
if(StringUtils.equals(ThirdPlatformTypeEnum.HAI_NAN.getCode(), dto.getThirdPartyType())) {
// 华为
// 海南
result = haiNanChargeService.pushStationInfoV2(dto);
}
finalResult.append(result).append("\n");

View File

@@ -56,6 +56,7 @@ import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 华为Service
@@ -187,26 +188,14 @@ public class HuaweiServiceV2 {
* @param dto
* @return
*/
public String notificationOperationSystemInfo(PushStationInfoDTO dto) {
Long stationId = dto.getStationId();
String type = dto.getThirdPartyType();
// 通过第三方配置类型查询相关配置信息
ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo();
settingInfo.setType(type);
ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo);
String operatorId = thirdPartySettingInfo.getOperatorId();
String operatorSecret = thirdPartySettingInfo.getOperatorSecret();
String signSecret = thirdPartySettingInfo.getSignSecret();
String dataSecret = thirdPartySettingInfo.getDataSecret();
String dataSecretIv = thirdPartySettingInfo.getDataSecretIv();
String urlAddress = thirdPartySettingInfo.getUrlAddress();
public String notificationOperationSystemInfo(String stationId) {
String requestName = "notification_operation_system_info";
List<HWStationInfo
.EquipmentLogicInfo> equipmentLogicInfos = new ArrayList<>();
// 通过站点id查询站点信息
PileStationVO stationInfo = pileStationInfoService.getStationInfo(String.valueOf(stationId));
PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId);
if (stationInfo == null) {
return null;
}
@@ -216,18 +205,18 @@ public class HuaweiServiceV2 {
.build();
// 查询桩列表
equipmentLogicInfos = getPileList(String.valueOf(stationId));
equipmentLogicInfos = getPileList(stationId);
hwStationInfo.setEquipmentInfoNum(equipmentLogicInfos.size());
hwStationInfo.setEquipmentLogicInfos(equipmentLogicInfos);
String jsonString = JSONObject.toJSONString(hwStationInfo);
String url = urlAddress + "notification_operation_system_info";
// 获取令牌
String token = getHuaWeiToken();
// 发送请求
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
// String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
String result = sendMsg2HuaWei(jsonString, token, requestName);
return result;
}
@@ -498,10 +487,10 @@ public class HuaweiServiceV2 {
String orderCode = IdUtils.getOrderCode();
String startChargeSeq = Constants.OPERATORID_JIANG_SU + "_C" + orderCode;
QueryStartChargeDTO startChargeDTO = new QueryStartChargeDTO();
startChargeDTO.setOperatorId(dto.getOperatorId());
startChargeDTO.setOperatorId(ThirdPartyOperatorIdEnum.HUA_WEI.getOperatorId());
startChargeDTO.setStartChargeSeq(startChargeSeq);
startChargeDTO.setConnectorID(dto.getConnectorID());
startChargeDTO.setAccountBalance(dto.getMoneyLimit());
startChargeDTO.setConnectorID(pileConnectorCode);
startChargeDTO.setAccountBalance(chargeAmount);
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(startChargeDTO);
if (map == null) {
@@ -570,7 +559,7 @@ public class HuaweiServiceV2 {
* @param startChargeSeq 订单号
*/
public QueryChargeStatusVO queryChargeStatus(String startChargeSeq) {
String requestName = "query_equip_auth";
String requestName = "query_equip_charge_status";
// 拼装参数
JSONObject jsonObject = new JSONObject();
@@ -821,6 +810,31 @@ public class HuaweiServiceV2 {
}
/**
* 下发计费策略响应
* @param dto
* @return
*/
public Map<String, String> receiveDeliverEquipBusinessPolicyResult(DeliverBusinessPolicyResponseDTO dto) {
List<DeliverBusinessPolicyResponseDTO.ChargePolicyInfoRet> chargePolicyInfoRets = dto.getChargePolicyInfoRets();
// 将下发失败的进行筛选、收集
List<DeliverBusinessPolicyResponseDTO.ChargePolicyInfoRet> failedList = chargePolicyInfoRets.stream()
.filter(x -> x.getSuccStat() == Constants.one) // 1-失败
.collect(Collectors.toList());
for (DeliverBusinessPolicyResponseDTO.ChargePolicyInfoRet chargePolicyInfoRet : failedList) {
log.error("华为下发计费策略响应, 枪口:{} 下发计费策略失败, 失败原因:{}", chargePolicyInfoRet.getConnectorID(), chargePolicyInfoRet.getFailReason());
// TODO 重新下发
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("SuccStat", 0);
jsonObject.put("FailReason", 0);
Map<String, String> resultMap = getResultMap(jsonObject);
return resultMap;
}
/**
* 获取华为配置信息
* @return

View File

@@ -269,56 +269,56 @@ export default {
data() {
// 自定义校验
var validatePassA = (rule, value, callback) => {
if (value >= this.exchangeRate.electricityPriceA) {
if (value > this.exchangeRate.electricityPriceA) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();
}
};
var validatePassB = (rule, value, callback) => {
if (value >= this.exchangeRate.servicePriceA) {
if (value > this.exchangeRate.servicePriceA) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();
}
};
var validatePassC = (rule, value, callback) => {
if (value >= this.exchangeRate.electricityPriceB) {
if (value > this.exchangeRate.electricityPriceB) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();
}
};
var validatePassD = (rule, value, callback) => {
if (value >= this.exchangeRate.servicePriceB) {
if (value > this.exchangeRate.servicePriceB) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();
}
};
var validatePassE = (rule, value, callback) => {
if (value >= this.exchangeRate.electricityPriceC) {
if (value > this.exchangeRate.electricityPriceC) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();
}
};
var validatePassF = (rule, value, callback) => {
if (value >= this.exchangeRate.servicePriceC) {
if (value > this.exchangeRate.servicePriceC) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();
}
};
var validatePassG = (rule, value, callback) => {
if (value >= this.exchangeRate.electricityPriceD) {
if (value > this.exchangeRate.electricityPriceD) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();
}
};
var validatePassH = (rule, value, callback) => {
if (value >= this.exchangeRate.servicePriceD) {
if (value > this.exchangeRate.servicePriceD) {
callback(new Error('输入金额不能大于原金额'));
} else {
callback();