From d1c72d1472eea021f595e22c4ca9f40aab245fde Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期二, 10 九月 2024 11:16:11 +0800 Subject: [PATCH] 新增加开关道闸接口 --- ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/vo/SwitchwayGateReq.java | 19 +++ ruoyi-api/ruoyi-api-integration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports | 3 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TVehicleRampController.java | 17 +++ ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/server/SwitchwayGateService.java | 61 ++++++++++++ ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/model/SwitchwayGate.java | 50 ++++++++++ ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/controller/SwitchwayGateController.java | 36 +++++++ ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/SwitchwayGateClient.java | 25 +++++ ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java | 2 ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SwitchwayGateFallbackFactory.java | 34 ++++++ ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/model/TVehicleRamp.java | 6 10 files changed, 247 insertions(+), 6 deletions(-) diff --git a/ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/model/TVehicleRamp.java b/ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/model/TVehicleRamp.java index e4c5827..6c59b12 100644 --- a/ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/model/TVehicleRamp.java +++ b/ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/model/TVehicleRamp.java @@ -52,6 +52,8 @@ @ApiModelProperty(value = "方向(1=入口,2=出口)") @TableField("direction") private Integer direction; - - + + @ApiModelProperty(value = "开关动作(open:开、close:关)") + @TableField(exist = false) + private String action; } diff --git a/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SwitchwayGateFallbackFactory.java b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SwitchwayGateFallbackFactory.java new file mode 100644 index 0000000..2b75d43 --- /dev/null +++ b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SwitchwayGateFallbackFactory.java @@ -0,0 +1,34 @@ +package com.ruoyi.integration.api.factory; + +import com.ruoyi.common.core.domain.R; +import com.ruoyi.integration.api.feignClient.SendMessageClient; +import com.ruoyi.integration.api.feignClient.SwitchwayGateClient; +import com.ruoyi.integration.api.model.PlatformStartCharging; +import com.ruoyi.integration.api.model.PlatformStopCharging; +import com.ruoyi.integration.api.vo.SwitchwayGateReq; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * 充电桩服务降级处理 + * + * @author ruoyi + */ +@Component +public class SwitchwayGateFallbackFactory implements org.springframework.cloud.openfeign.FallbackFactory<SwitchwayGateClient> { + private static final Logger log = LoggerFactory.getLogger(SwitchwayGateFallbackFactory.class); + + @Override + public SwitchwayGateClient create(Throwable throwable) { + log.error("调用道闸开关失败:{}", throwable.getMessage()); + return new SwitchwayGateClient() { + + + @Override + public R<Boolean> gateService(SwitchwayGateReq req) { + return R.fail("道闸开关失败:" + throwable.getMessage()); + } + }; + } +} diff --git a/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/SwitchwayGateClient.java b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/SwitchwayGateClient.java new file mode 100644 index 0000000..9359fce --- /dev/null +++ b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/SwitchwayGateClient.java @@ -0,0 +1,25 @@ +package com.ruoyi.integration.api.feignClient; + +import com.ruoyi.common.core.constant.ServiceNameConstants; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.integration.api.factory.SwitchwayGateFallbackFactory; +import com.ruoyi.integration.api.vo.SwitchwayGateReq; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @author zhibing.pu + * @Date 2024/9/10 11:08 + */ +@FeignClient(contextId = "SwitchwayGateClient", value = ServiceNameConstants.INTEGRATION_SERVICE, fallbackFactory = SwitchwayGateFallbackFactory.class) +public interface SwitchwayGateClient { + + /** + * 道闸开关 + * @param req + * @return + */ + @PostMapping("/switchwayGate/gateService") + R<Boolean> gateService(@RequestBody SwitchwayGateReq req); +} diff --git a/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/vo/SwitchwayGateReq.java b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/vo/SwitchwayGateReq.java new file mode 100644 index 0000000..18cb103 --- /dev/null +++ b/ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/vo/SwitchwayGateReq.java @@ -0,0 +1,19 @@ +package com.ruoyi.integration.api.vo; + +import lombok.Data; + +/** + * @author zhibing.pu + * @Date 2024/9/10 10:48 + */ +@Data +public class SwitchwayGateReq { + /** + * 开关动作(open:开、close:关) + */ + private String action; + /** + * 通道编号 + */ + private String channel; +} diff --git a/ruoyi-api/ruoyi-api-integration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-api/ruoyi-api-integration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index a17191b..fa602cc 100644 --- a/ruoyi-api/ruoyi-api-integration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/ruoyi-api/ruoyi-api-integration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -3,4 +3,5 @@ com.ruoyi.integration.api.factory.ChargingHandshakeFallbackFactory com.ruoyi.integration.api.factory.SendMessageFallbackFactory com.ruoyi.integration.api.factory.PlatformStartChargingReplyFallbackFactory -com.ruoyi.integration.api.factory.PlatformStopChargingReplyFallbackFactory \ No newline at end of file +com.ruoyi.integration.api.factory.PlatformStopChargingReplyFallbackFactory +com.ruoyi.integration.api.factory.SwitchwayGateFallbackFactory \ No newline at end of file diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TVehicleRampController.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TVehicleRampController.java index f9bd40a..e5e06a5 100644 --- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TVehicleRampController.java +++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TVehicleRampController.java @@ -9,11 +9,14 @@ import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.OperatorType; +import com.ruoyi.integration.api.feignClient.SwitchwayGateClient; +import com.ruoyi.integration.api.vo.SwitchwayGateReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.util.Arrays; import java.util.List; @@ -31,6 +34,13 @@ public class TVehicleRampController { private final TVehicleRampService vehicleRampService; + + @Resource + private SwitchwayGateClient switchwayGateClient; + + + + @Autowired public TVehicleRampController(TVehicleRampService vehicleRampService) { @@ -95,8 +105,11 @@ @ApiOperation(tags = {"后台-车道"},value = "开关闸车道") @PostMapping(value = "/openOrDown") public AjaxResult<String> openOrDown(@RequestBody TVehicleRamp dto) { - // TODO 硬件 开关闸车道 - return AjaxResult.success(); + SwitchwayGateReq req = new SwitchwayGateReq(); + req.setAction(dto.getAction()); + req.setChannel(dto.getCarportNum()); + Boolean data = switchwayGateClient.gateService(req).getData(); + return data ? AjaxResult.success() : AjaxResult.error("操作失败"); } } diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/controller/SwitchwayGateController.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/controller/SwitchwayGateController.java new file mode 100644 index 0000000..3cb179b --- /dev/null +++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/controller/SwitchwayGateController.java @@ -0,0 +1,36 @@ +package com.ruoyi.integration.barrierGate.controller; + +import com.ruoyi.common.core.domain.R; +import com.ruoyi.integration.api.vo.SwitchwayGateReq; +import com.ruoyi.integration.barrierGate.server.SwitchwayGateService; +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.annotation.Resource; + +/** + * 开关道闸 + * @author zhibing.pu + * @Date 2024/9/10 9:43 + */ +@RestController +@RequestMapping("/switchwayGate") +public class SwitchwayGateController { + + @Resource + private SwitchwayGateService switchwayGateService; + + + /** + * 开关道闸 + * @param req + * @return + */ + @PostMapping("/gateService") + public R<Boolean> gateService(@RequestBody SwitchwayGateReq req){ + Boolean aBoolean = switchwayGateService.gateService(req); + return R.ok(aBoolean); + } +} diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/model/SwitchwayGate.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/model/SwitchwayGate.java new file mode 100644 index 0000000..2ab74a0 --- /dev/null +++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/model/SwitchwayGate.java @@ -0,0 +1,50 @@ +package com.ruoyi.integration.barrierGate.model; + +import com.ruoyi.common.core.utils.MD5Util; +import lombok.Data; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; + +/** + * @author zhibing.pu + * @Date 2024/9/10 9:45 + */ +@Slf4j +@Data +@Accessors(chain = true) +public class SwitchwayGate { + /** + * 停车场appkey + */ + private String appkey; + /** + * 开关动作(open:开、close:关) + */ + private String action; + /** + * 通道编号 + */ + private String channel; + /** + * 当前时间戳 + */ + private String timestamp; + /** + * 签名信息:参数升序排序,&拼接所有参数,MD5(参数+&+参数值...+签名密钥)转大写 + */ + private String sign; + + + public SwitchwayGate build(String secretkey){ + String str = String.format("action=%s&appkey=%s&channel=%s×tamp=%s&key=%s", this.getAction(), this.getAppkey(), this.getChannel(), this.getTimestamp(), secretkey); + log.info("待签名串:{}", str); + //MD5加密 + String encoder = MD5Util.getMD5(str); + //将签名结果转大写 + encoder = encoder.toUpperCase(); + log.info("签名结果:{}", encoder); + this.setSign(encoder); + return this; + } + +} diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/server/SwitchwayGateService.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/server/SwitchwayGateService.java new file mode 100644 index 0000000..c20f360 --- /dev/null +++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/server/SwitchwayGateService.java @@ -0,0 +1,61 @@ +package com.ruoyi.integration.barrierGate.server; + +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.integration.api.vo.SwitchwayGateReq; +import com.ruoyi.integration.barrierGate.model.SwitchwayGate; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * @author zhibing.pu + * @Date 2024/9/10 9:44 + */ +@Slf4j +@Service +public class SwitchwayGateService { + + private final String url = "http://8.137.103.127/universal"; + + private final String appkey = "886621e841fc44c1ad63a823d"; + + private final String secretkey = "7d87c2c36bea4749b30f38f4d"; + + + /** + * 开关道闸 + * @param req + * @return + */ + public Boolean gateService(SwitchwayGateReq req){ + SwitchwayGate switchwayGate = new SwitchwayGate() + .setAppkey(appkey) + .setAction(req.getAction()) + .setChannel(req.getChannel()) + .setTimestamp(System.currentTimeMillis() + "") + .build(secretkey); + String body = JSON.toJSONString(switchwayGate); + String result = HttpUtil.post(url + "/gateService", body); + JSONObject jsonObject = JSON.parseObject(result); + Boolean success = jsonObject.getBoolean("success"); + if(!success){ + log.error("调用开关道闸失败:\n请求参数:{}\n返回结果:{}", body, result); + } + return success; + } + + +// public static void main(String[] args) { +// SwitchwayGateService switchwayGateService = new SwitchwayGateService(); +// SwitchwayGateReq req = new SwitchwayGateReq(); +// req.setAction("close"); +// req.setChannel("001"); +// Boolean success = switchwayGateService.gateService(req); +// if(success){ +// log.info("调用成功"); +// }else{ +// log.info("调用失败"); +// } +// } +} diff --git a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java index 8e040ac..3a3d081 100644 --- a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java +++ b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java @@ -69,7 +69,7 @@ */ protected String buildBaseParam(WxPaymentInfoModel requestBody, String notifyUrl) { // 封装基础数据 - requestBody.setNotify_url(notifyUrl); +// requestBody.setNotify_url(notifyUrl); String reqBody = WxJsonUtils.toJsonString(requestBody); return reqBody; } -- Gitblit v1.7.1