diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java new file mode 100644 index 00000000..c9cc637e --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java @@ -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 startCharging(@Validated @RequestBody StartChargingData startChargingData); + +} diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PowerPileFallbackFactory.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PowerPileFallbackFactory.java new file mode 100644 index 00000000..cd461a13 --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PowerPileFallbackFactory.java @@ -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 { + + 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()); + } + +} diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/down/StartChargingData.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/down/StartChargingData.java index 8f03e03b..5873cc67 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/down/StartChargingData.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/down/StartChargingData.java @@ -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; + } } diff --git a/xhpc-modules/xhpc-common/src/resources/META-INF/spring.factories b/xhpc-modules/xhpc-common/src/resources/META-INF/spring.factories new file mode 100644 index 00000000..b01a60c5 --- /dev/null +++ b/xhpc-modules/xhpc-common/src/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.xhpc.common.api.factory.PowerPileFallbackFactory diff --git a/xhpc-modules/xhpc-power-pile/pom.xml b/xhpc-modules/xhpc-power-pile/pom.xml index 721c542c..cb5c27ec 100644 --- a/xhpc-modules/xhpc-power-pile/pom.xml +++ b/xhpc-modules/xhpc-power-pile/pom.xml @@ -63,6 +63,12 @@ ruoyi-common-datascope + + + com.ruoyi + ruoyi-common-core + + org.quickserver quickserver diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/XhpcPPApplication.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/XhpcPPApplication.java similarity index 92% rename from xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/XhpcPPApplication.java rename to xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/XhpcPPApplication.java index 77cd5320..4d183115 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/XhpcPPApplication.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/XhpcPPApplication.java @@ -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 { diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java index 4ea2fc77..172aad4f 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java @@ -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 ppInstances = namingService.getAllInstances("xhpc-power-pile"); - // todo clean dead host pile cache - String ipAndPort = GetIpAndPort.getIpAndPort(); - return ipAndPort; + R r = powerPileService.startCharging(startChargingData); + return r; + } + + @PostMapping("pile/charging/order") + public Object startCharging(@Validated @RequestBody StartChargingData startChargingData) { + + return new OrderData(); } } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java index 6da4d938..54b774b6 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java @@ -32,6 +32,7 @@ public class RegisterLogic implements ServiceLogic { String hexCode = ServiceResult.HEX_OK; String pileNo = (String) req.get("pileNo"); Set pileSnPool = REDIS.getCacheSet("PILE_SN_POOL"); +// ? = REDIS.getCacheSet(pileNo); todo //todo set rate model to cache if (!pileSnPool.contains(pileNo)) { hexCode = ServiceResult.HEX_FAIL;