diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileStationInfoController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileStationInfoController.java index 8995fb872..613295126 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileStationInfoController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/pile/PileStationInfoController.java @@ -31,6 +31,7 @@ import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.service.PileService; import com.jsowell.thirdparty.lianlian.service.LianLianService; import com.jsowell.thirdparty.nanrui.service.NRService; +import com.jsowell.thirdparty.xindiantu.service.XDTService; import com.jsowell.thirdparty.yongchengboche.service.YCBCService; import com.jsowell.thirdparty.zhongdianlian.service.ZDLService; import org.springframework.beans.factory.annotation.Autowired; @@ -70,6 +71,9 @@ public class PileStationInfoController extends BaseController { @Autowired private YCBCService ycbcService; + @Autowired + private XDTService xdtService; + @Autowired private ThirdPartyStationRelationService thirdPartyStationRelationService; @@ -307,6 +311,10 @@ public class PileStationInfoController extends BaseController { // 甬城泊车平台 result = ycbcService.pushStationInfo(dto); } + if (StringUtils.equals(ThirdPlatformTypeEnum.XIN_DIAN_TU.getCode(), dto.getThirdPartyType())) { + // 新电途平台 + result = xdtService.pushStationInfo(dto); + } response = new RestApiResponse<>(result); }catch (BusinessException e) { logger.error("推送第三方平台充电站信息 error",e); diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/huawei/HuaWeiController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/huawei/HuaWeiController.java index a4e374129..8f2a64817 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/huawei/HuaWeiController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/huawei/HuaWeiController.java @@ -1,9 +1,30 @@ package com.jsowell.web.controller.thirdparty.huawei; +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.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 javax.servlet.http.HttpServletRequest; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.Map; + /** * 华为 Controller * @@ -12,6 +33,277 @@ import org.springframework.web.bind.annotation.RestController; */ @Anonymous @RestController -@RequestMapping("/xindiantu") -public class HuaWeiController { +@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:{}", JSONObject.toJSONString(dto)); + try { + Map map = huaWeiService.generateToken(dto); + logger.info("华为平台请求令牌 result:{}", JSONObject.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 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 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:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map 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 map = huaWeiService.queryStationStatus(queryStationInfoDTO); + logger.info("华为平台查询统计信息 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("华为平台查询统计信息 error:", e); + e.printStackTrace(); + } + return CommonResult.failed("查询统计信息发生异常"); + } + + + /** + * 请求设备认证 + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_equip_auth") + public CommonResult query_equip_auth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("华为平台请求设备认证 param:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map 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 map = huaWeiService.queryEquipAuth(queryEquipmentDTO); + logger.info("华为平台请求设备认证 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("华为平台请求设备认证 error:", e); + e.printStackTrace(); + } + return CommonResult.failed("请求设备认证发生异常"); + } + + /** + * 华为平台请求计费策略 + * http://localhost:8080/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:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map 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 map = huaWeiService.requestEquipBusinessPolicy(queryStartChargeDTO); + logger.info("华为平台请求计费策略 result:{}", JSONObject.toJSONString(map)); + + return CommonResult.success(0, "请求计费策略成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("华为平台请求计费策略 error:", e); + e.printStackTrace(); + } + return CommonResult.failed("请求计费策略发生异常"); + } + + /** + * 查询充电状态 + * http://localhost:8080/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 :{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map 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 map = huaWeiService.queryEquipChargeStatus(queryEquipChargeStatusDTO); + logger.info("华为平台查询充电状态 result:{}", JSONObject.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 :{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map 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 map = huaWeiService.queryStopCharge(queryStartChargeDTO); + logger.info("华为平台请求停止充电 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("华为平台请求停止充电 error", e); + } + return CommonResult.failed("华为平台请求停止充电发生异常"); + } } diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/xindiantu/XDTController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/xindiantu/XDTController.java index a9288c19f..4d7e2659e 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/xindiantu/XDTController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/xindiantu/XDTController.java @@ -54,6 +54,33 @@ public class XDTController extends BaseController { } } + /** + * 推送充电站信息 notification_stationInfo + * http://localhost:8080/xindiantu/v1/pushStationInfo + * @param dto + * @return + */ + @PostMapping("/pushStationInfo") + public RestApiResponse pushStationInfo(@RequestBody PushStationInfoDTO dto) { + logger.info("推送新电途平台充电站信息 params:{}", JSONObject.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 diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java index 5338fe206..b5a2aef3f 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java @@ -15,6 +15,7 @@ public enum ThirdPlatformTypeEnum { YONG_CHENG_BO_CHE("4", "甬城泊车平台"), NING_XIA_JIAO_TOU("5", "宁夏交投"), XIN_DIAN_TU("6", "新电途平台"), + HUA_WEI("7", "华为平台"), ; private String code; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/util/HttpRequestUtil.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/util/HttpRequestUtil.java index 169e3ea69..a059ff93e 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/util/HttpRequestUtil.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/util/HttpRequestUtil.java @@ -130,7 +130,7 @@ public class HttpRequestUtil { String hutoolRequest = HttpRequest.post(url).header("Authorization", "Bearer " + token).body(postData).execute().body(); - // log.info("联联平台发送请求 接收到返回数据:{}", hutoolRequest); + log.info("发送请求 接收到返回数据:{}", hutoolRequest); if (StringUtils.isBlank(hutoolRequest)) { return "返回数据为空"; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java index b8d09deb1..71c033ca1 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java @@ -1,9 +1,6 @@ package com.jsowell.thirdparty.xindiantu.service; -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.dto.*; import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO; import com.jsowell.thirdparty.zhongdianlian.dto.ZDLGetTokenDTO; @@ -119,4 +116,7 @@ public interface XDTService { * @return */ String notificationEquipChargeStatus(String orderCode) throws UnsupportedEncodingException; + + + String pushStationInfo(PushStationInfoDTO dto); } \ No newline at end of file diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java index 9ea93913b..130927bce 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java @@ -4,10 +4,7 @@ import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.domain.ThirdPartyStationRelation; -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.dto.*; import com.jsowell.pile.service.ThirdPartyStationRelationService; import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO; import com.jsowell.thirdparty.xindiantu.service.XDTService; @@ -190,4 +187,10 @@ public class XDTServiceImpl implements XDTService { public String notificationEquipChargeStatus(String orderCode) throws UnsupportedEncodingException { return zdlService.notificationEquipChargeStatus(orderCode); } + + + @Override + public String pushStationInfo(PushStationInfoDTO dto) { + return zdlService.pushStationInfo(dto); + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java index 40907a631..29e065dbc 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java @@ -105,7 +105,6 @@ public class ZDLServiceImpl implements ZDLService { ThirdPartyStationRelation relation = new ThirdPartyStationRelation(); relation.setStationId(dto.getStationId()); ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation); - // ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(dto.getStationId()); if (relationInfo == null) { // 新增 relation.setThirdPartyType(dto.getThirdPartyType());