启动充电服务调用
This commit is contained in:
parent
7d74ef1817
commit
2ef4b6bd23
@ -0,0 +1,19 @@
|
||||
package com.xhpc.common.api;
|
||||
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xhpc.common.api.factory.PowerPileFallbackFactory;
|
||||
import com.xhpc.common.data.down.StartChargingData;
|
||||
import com.xhpc.common.data.up.OrderData;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(contextId = "powerPileService", value = ServiceNameConstants.PILE_SERVICE, fallbackFactory = PowerPileFallbackFactory.class)
|
||||
public interface PowerPileService {
|
||||
|
||||
@PostMapping(value = "/pile/charging/order")
|
||||
R<OrderData> startCharging(@Validated @RequestBody StartChargingData startChargingData);
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.xhpc.common.api.factory;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xhpc.common.api.PowerPileService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PowerPileFallbackFactory implements FallbackFactory<PowerPileService> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PowerPileFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public PowerPileService create(Throwable cause) {
|
||||
|
||||
logger.error("充电订单服务调用失败:{} //fallback", cause.getMessage());
|
||||
return startChargingData -> R.fail("启动充电失败:" + cause.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,13 +1,79 @@
|
||||
package com.xhpc.common.data.down;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
public class StartChargingData {
|
||||
|
||||
|
||||
@NotBlank(message = "订单流水号不能为空")
|
||||
private String orderNo; //交易流水号
|
||||
@NotBlank(message = "桩号不能为空")
|
||||
private String pileNo; //桩号
|
||||
@NotBlank(message = "枪号不能为空")
|
||||
private String gunId; //枪号
|
||||
@Min(value = 5, message = "账户余额不能小于5")
|
||||
private Double balance; //账户余额
|
||||
private String logicCardNo; //逻辑卡号
|
||||
private String physicCardNo; //物理卡号
|
||||
private double balance; //账户余额
|
||||
|
||||
public String getOrderNo() {
|
||||
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public String getPileNo() {
|
||||
|
||||
return pileNo;
|
||||
}
|
||||
|
||||
public void setPileNo(String pileNo) {
|
||||
|
||||
this.pileNo = pileNo;
|
||||
}
|
||||
|
||||
public String getGunId() {
|
||||
|
||||
return gunId;
|
||||
}
|
||||
|
||||
public void setGunId(String gunId) {
|
||||
|
||||
this.gunId = gunId;
|
||||
}
|
||||
|
||||
public Double getBalance() {
|
||||
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(Double balance) {
|
||||
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public String getLogicCardNo() {
|
||||
|
||||
return logicCardNo;
|
||||
}
|
||||
|
||||
public void setLogicCardNo(String logicCardNo) {
|
||||
|
||||
this.logicCardNo = logicCardNo;
|
||||
}
|
||||
|
||||
public String getPhysicCardNo() {
|
||||
|
||||
return physicCardNo;
|
||||
}
|
||||
|
||||
public void setPhysicCardNo(String physicCardNo) {
|
||||
|
||||
this.physicCardNo = physicCardNo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.xhpc.common.api.factory.PowerPileFallbackFactory
|
||||
@ -63,6 +63,12 @@
|
||||
<artifactId>ruoyi-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Core -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.quickserver</groupId>
|
||||
<artifactId>quickserver</artifactId>
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package com.xhpc.pp;
|
||||
package com.xhpc;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
|
||||
/**
|
||||
@ -10,6 +11,7 @@ import org.springframework.context.annotation.ImportResource;
|
||||
*
|
||||
* @author zz
|
||||
*/
|
||||
@EnableFeignClients
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
@ImportResource(locations = {"classpath:svcmainlogic.xml"})
|
||||
public class XhpcPPApplication {
|
||||
@ -1,30 +1,32 @@
|
||||
package com.xhpc.pp.controller;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.ruoyi.common.core.utils.GetIpAndPort;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xhpc.common.api.PowerPileService;
|
||||
import com.xhpc.common.data.down.StartChargingData;
|
||||
import com.xhpc.common.data.up.OrderData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class ChargingController {
|
||||
|
||||
@PostMapping("test")
|
||||
public String test() throws NacosException {
|
||||
@Autowired
|
||||
private PowerPileService powerPileService;
|
||||
|
||||
String serverIp = "127.0.0.1";
|
||||
int serverPort = 8848;
|
||||
String serverAddr = serverIp + ":" + serverPort;
|
||||
@PostMapping("test/pile/charging/order")
|
||||
public Object test(@Validated @RequestBody StartChargingData startChargingData) {
|
||||
|
||||
NamingService namingService = NacosFactory.createNamingService(serverAddr);
|
||||
List<Instance> ppInstances = namingService.getAllInstances("xhpc-power-pile");
|
||||
// todo clean dead host pile cache
|
||||
String ipAndPort = GetIpAndPort.getIpAndPort();
|
||||
return ipAndPort;
|
||||
R<OrderData> r = powerPileService.startCharging(startChargingData);
|
||||
return r;
|
||||
}
|
||||
|
||||
@PostMapping("pile/charging/order")
|
||||
public Object startCharging(@Validated @RequestBody StartChargingData startChargingData) {
|
||||
|
||||
return new OrderData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ public class RegisterLogic implements ServiceLogic {
|
||||
String hexCode = ServiceResult.HEX_OK;
|
||||
String pileNo = (String) req.get("pileNo");
|
||||
Set<String> pileSnPool = REDIS.getCacheSet("PILE_SN_POOL");
|
||||
// ? = REDIS.getCacheSet(pileNo); todo
|
||||
//todo set rate model to cache
|
||||
if (!pileSnPool.contains(pileNo)) {
|
||||
hexCode = ServiceResult.HEX_FAIL;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user