zhibing.pu
2024-09-10 d1c72d1472eea021f595e22c4ca9f40aab245fde
新增加开关道闸接口
4个文件已修改
6个文件已添加
253 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/model/TVehicleRamp.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SwitchwayGateFallbackFactory.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/SwitchwayGateClient.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/vo/SwitchwayGateReq.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-integration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TVehicleRampController.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/controller/SwitchwayGateController.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/model/SwitchwayGate.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/server/SwitchwayGateService.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
}
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SwitchwayGateFallbackFactory.java
New file
@@ -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());
            }
        };
    }
}
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/feignClient/SwitchwayGateClient.java
New file
@@ -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);
}
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/vo/SwitchwayGateReq.java
New file
@@ -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;
}
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
com.ruoyi.integration.api.factory.PlatformStopChargingReplyFallbackFactory
com.ruoyi.integration.api.factory.SwitchwayGateFallbackFactory
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("操作失败");
    }
}
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/controller/SwitchwayGateController.java
New file
@@ -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);
    }
}
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/model/SwitchwayGate.java
New file
@@ -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&timestamp=%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;
    }
}
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/barrierGate/server/SwitchwayGateService.java
New file
@@ -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("调用失败");
//        }
//    }
}
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;
    }