修复bug

This commit is contained in:
Richie 2025-04-24 21:24:50 +08:00
parent bed055fa1d
commit 93c7ff1ed0
11 changed files with 61 additions and 57 deletions

View File

@ -43,6 +43,16 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId> <artifactId>spring-boot-starter-undertow</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>4.0.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>

View File

@ -5,10 +5,15 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient; //import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;
//@EnableDiscoveryClient //@EnableDiscoveryClient
//@MapperScan("cn.qihangerp.oms.mapper") //@MapperScan("cn.qihangerp.oms.mapper")
@EnableFeignClients(basePackages = "cn.qihangerp.oms")
@EnableDiscoveryClient @EnableDiscoveryClient
@ComponentScan(basePackages={"cn.qihangerp"}) @ComponentScan(basePackages={"cn.qihangerp"})
@SpringBootApplication @SpringBootApplication
@ -18,5 +23,9 @@ public class OmsApi {
System.out.println( "Hello oms-api!" ); System.out.println( "Hello oms-api!" );
SpringApplication.run(OmsApi.class, args); SpringApplication.run(OmsApi.class, args);
} }
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
} }

View File

@ -1,17 +1,40 @@
package cn.qihangerp.oms.controller; package cn.qihangerp.oms.controller;
import cn.qihangerp.oms.feign.EchoService;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@AllArgsConstructor @AllArgsConstructor
@RestController @RestController
public class HomeController { public class HomeController {
@Resource
private EchoService echoService;
@Autowired
private RestTemplate restTemplate;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@GetMapping("/") @GetMapping("/")
public String home(){ public String home(){
return "{'code':0,'msg':'oms-api请通过api访问'}"; return "{'code':0,'msg':'oms-api请通过api访问'}";
} }
@GetMapping(value = "/echo-rest")
public String rest() {
return restTemplate.getForObject("http://tao-oms/test/na", String.class);
}
@GetMapping(value = "/echo-feign")
public String feign() {
String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjdkOTBmN2EzLWUwNWQtNDkxNy04NjIzLTU1OGRhNGY3NjE3NiJ9._Oukm9b0P1WvcOywLdhs6_BOt_6mRSF41Q6f4fBm_DGUkPR86Qg1tqyRTM5ouTR2Xz46IRuRAVez8Wcl3NIlwg";
return echoService.echo(token);
}
} }

View File

@ -72,16 +72,16 @@
<version>4.13.2</version> <version>4.13.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <!-- <dependency>-->
<groupId>org.springframework.cloud</groupId> <!-- <groupId>org.springframework.cloud</groupId>-->
<artifactId>spring-cloud-starter</artifactId> <!-- <artifactId>spring-cloud-starter</artifactId>-->
<version>4.0.0</version> <!-- <version>4.0.0</version>-->
</dependency> <!-- </dependency>-->
<dependency> <!-- <dependency>-->
<groupId>org.springframework.cloud</groupId> <!-- <groupId>org.springframework.cloud</groupId>-->
<artifactId>spring-cloud-starter-loadbalancer</artifactId> <!-- <artifactId>spring-cloud-starter-loadbalancer</artifactId>-->
<version>4.0.0</version> <!-- <version>4.0.0</version>-->
</dependency> <!-- </dependency>-->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>--> <!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-gateway</artifactId>--> <!-- <artifactId>spring-cloud-starter-gateway</artifactId>-->

View File

@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -13,7 +13,7 @@ import org.springframework.web.client.RestTemplate;
* Hello world! * Hello world!
* *
*/ */
@EnableFeignClients(basePackages = "cn.qihangerp.sys")
@EnableDiscoveryClient @EnableDiscoveryClient
@ComponentScan(basePackages={"cn.qihangerp"}) @ComponentScan(basePackages={"cn.qihangerp"})
//@MapperScan("com.qihang.sys.api.mapper") //@MapperScan("com.qihang.sys.api.mapper")
@ -26,9 +26,5 @@ public class SysApi
SpringApplication.run(SysApi.class, args); SpringApplication.run(SysApi.class, args);
} }
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
} }

View File

@ -1,34 +0,0 @@
package cn.qihangerp.sys.controller;
import cn.qihangerp.sys.feign.EchoService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class HomeController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Resource
private EchoService echoService;
@GetMapping("/")
public String home(){
return "{'code':0,'msg':'请通过api访问'}";
}
@GetMapping(value = "/echo-rest")
public String rest() {
return restTemplate.getForObject("http://tao-oms/test/na", String.class);
}
@GetMapping(value = "/echo-feign")
public String feign() {
String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjdkOTBmN2EzLWUwNWQtNDkxNy04NjIzLTU1OGRhNGY3NjE3NiJ9._Oukm9b0P1WvcOywLdhs6_BOt_6mRSF41Q6f4fBm_DGUkPR86Qg1tqyRTM5ouTR2Xz46IRuRAVez8Wcl3NIlwg";
return echoService.echo(token);
}
}

View File

@ -242,7 +242,7 @@ export default {
}, },
created() { created() {
this.openWs() this.openWs()
listShop({platform: 6}).then(response => { listShop({type: 400}).then(response => {
this.shopList = response.rows; this.shopList = response.rows;
if (this.shopList && this.shopList.length > 0) { if (this.shopList && this.shopList.length > 0) {
this.queryParams.shopId = this.shopList[0].id this.queryParams.shopId = this.shopList[0].id

View File

@ -233,7 +233,7 @@ export default {
}, },
created() { created() {
this.openWs() this.openWs()
listShop({platform: 3}).then(response => { listShop({type: 200}).then(response => {
this.shopList = response.rows; this.shopList = response.rows;
if (this.shopList && this.shopList.length > 0) { if (this.shopList && this.shopList.length > 0) {
this.queryParams.shopId = this.shopList[0].id this.queryParams.shopId = this.shopList[0].id

View File

@ -239,7 +239,7 @@ export default {
}, },
created() { created() {
this.openWs() this.openWs()
listShop({platform: 5}).then(response => { listShop({type: 300}).then(response => {
this.shopList = response.rows; this.shopList = response.rows;
if (this.shopList && this.shopList.length > 0) { if (this.shopList && this.shopList.length > 0) {
this.queryParams.shopId = this.shopList[0].id this.queryParams.shopId = this.shopList[0].id

View File

@ -249,7 +249,7 @@ export default {
}, },
created() { created() {
this.openWs() this.openWs()
listShop({platform: 4}).then(response => { listShop({type: 100}).then(response => {
this.shopList = response.rows; this.shopList = response.rows;
if (this.shopList && this.shopList.length > 0) { if (this.shopList && this.shopList.length > 0) {
this.queryParams.shopId = this.shopList[0].id this.queryParams.shopId = this.shopList[0].id

View File

@ -221,7 +221,7 @@ export default {
}, },
created() { created() {
this.openWs() this.openWs()
listShop({platform: 2}).then(response => { listShop({type: 500}).then(response => {
this.shopList = response.rows; this.shopList = response.rows;
if (this.shopList && this.shopList.length > 0) { if (this.shopList && this.shopList.length > 0) {
this.queryParams.shopId = this.shopList[0].id this.queryParams.shopId = this.shopList[0].id