From 2f82b1eca4a812378041f01cffce0a0f0a431dff Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期三, 28 九月 2022 20:28:50 +0800
Subject: [PATCH] bug处理

---
 ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java    |    4 
 ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java |   20 ++--
 ycl-platform/src/main/java/com/ycl/PlatformApplication.java                   |    4 
 ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java    |  117 ++++++++++++++--------------
 ycl-platform/src/main/resources/logback.xml                                   |   19 ----
 pom.xml                                                                       |   10 +-
 ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java       |   28 +++---
 7 files changed, 91 insertions(+), 111 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7eb1820..e9621fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -181,11 +181,11 @@
             <version>1.2.73</version>
         </dependency>
 
-<!--        <dependency>-->
-<!--            <groupId>org.springframework.cloud</groupId>-->
-<!--            <artifactId>spring-cloud-starter-openfeign</artifactId>-->
-<!--            <version>2.2.7.RELEASE</version>-->
-<!--        </dependency>-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
+            <version>3.1.3</version>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/ycl-platform/src/main/java/com/ycl/PlatformApplication.java b/ycl-platform/src/main/java/com/ycl/PlatformApplication.java
index fc23227..5f2d978 100644
--- a/ycl-platform/src/main/java/com/ycl/PlatformApplication.java
+++ b/ycl-platform/src/main/java/com/ycl/PlatformApplication.java
@@ -3,7 +3,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-//import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
@@ -20,7 +20,7 @@
 @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
 @EnableAsync(proxyTargetClass = true)
 @EnableScheduling
-//@EnableFeignClients
+@EnableFeignClients
 @EnableTransactionManagement(proxyTargetClass = true)
 @SpringBootApplication
 public class PlatformApplication {
diff --git a/ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java b/ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java
index cdcfa36..d1c5f1b 100644
--- a/ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java
+++ b/ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java
@@ -1,22 +1,22 @@
 package com.ycl.config.feign;
 
-//import feign.Feign;
-//import feign.Logger;
-//import feign.Retryer;
+import feign.Feign;
+import feign.Logger;
+import feign.Retryer;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 @Configuration
 public class FeignConfiguration {
-//    @Bean
-//    Logger.Level feignLoggerLevel() {
-//        return Logger.Level.FULL;
-//    }
-//
-//    @Bean
-//    public Feign.Builder feignBuilder() {
-//        return Feign.builder()
-//                .queryMapEncoder(new UnderlineQueryEncoder())
-//                .retryer(Retryer.NEVER_RETRY);
-//    }
+    @Bean
+    Logger.Level feignLoggerLevel() {
+        return Logger.Level.FULL;
+    }
+
+    @Bean
+    public Feign.Builder feignBuilder() {
+        return Feign.builder()
+                .queryMapEncoder(new UnderlineQueryEncoder())
+                .retryer(Retryer.NEVER_RETRY);
+    }
 }
\ No newline at end of file
diff --git a/ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java b/ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java
index 89abd9a..aa8e305 100644
--- a/ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java
+++ b/ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java
@@ -1,9 +1,9 @@
 package com.ycl.config.feign;
 
-//import feign.codec.Decoder;
-//import org.springframework.beans.factory.ObjectFactory;
-//import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
-//import org.springframework.cloud.openfeign.support.SpringDecoder;
+import feign.codec.Decoder;
+import org.springframework.beans.factory.ObjectFactory;
+import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
+import org.springframework.cloud.openfeign.support.SpringDecoder;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -11,10 +11,10 @@
 public class FeignGlobalConfiguration {
 
 
-//    @Bean
-//    public Decoder feignDecoder(){
-//        MessageConverter converter = new MessageConverter();
-//        ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(converter);
-//        return new SpringDecoder(objectFactory);
-//    }
+    @Bean
+    public Decoder feignDecoder(){
+        MessageConverter converter = new MessageConverter();
+        ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(converter);
+        return new SpringDecoder(objectFactory);
+    }
 }
diff --git a/ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java b/ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java
index 2a17195..bc55c2e 100644
--- a/ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java
+++ b/ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java
@@ -1,9 +1,9 @@
 package com.ycl.config.feign;
 
 import com.ycl.utils.StringUtils;
-//import feign.Param;
-//import feign.QueryMapEncoder;
-//import feign.codec.EncodeException;
+import feign.Param;
+import feign.QueryMapEncoder;
+import feign.codec.EncodeException;
 
 import java.beans.IntrospectionException;
 import java.beans.Introspector;
@@ -12,60 +12,59 @@
 import java.lang.reflect.Method;
 import java.util.*;
 
-public class UnderlineQueryEncoder{
-//        implements QueryMapEncoder {
-//    private final Map<Class<?>, ObjectParamMetadata> classToMetadata =
-//            new HashMap();
-//
-//    @Override
-//    public Map<String, Object> encode(Object object) throws EncodeException {
-//        try {
-//            ObjectParamMetadata metadata = getMetadata(object.getClass());
-//            Map<String, Object> propertyNameToValue = new HashMap<String, Object>();
-//            for (PropertyDescriptor pd : metadata.objectProperties) {
-//                Method method = pd.getReadMethod();
-//                Object value = method.invoke(object);
-//                if (value != null && value != object) {
-//                    Param alias = method.getAnnotation(Param.class);
-//                    String name = alias != null ? alias.value() : pd.getName();
-//                    propertyNameToValue.put(StringUtils.camelToUnderlineLowerCase(name), value);
-//                }
-//            }
-//            return propertyNameToValue;
-//        } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) {
-//            throw new EncodeException("Failure encoding object into query map", e);
-//        }
-//    }
-//
-//    private ObjectParamMetadata getMetadata(Class<?> objectType) throws IntrospectionException {
-//        ObjectParamMetadata metadata = classToMetadata.get(objectType);
-//        if (metadata == null) {
-//            metadata = ObjectParamMetadata.parseObjectType(objectType);
-//            classToMetadata.put(objectType, metadata);
-//        }
-//        return metadata;
-//    }
-//
-//    private static class ObjectParamMetadata {
-//
-//        private final List<PropertyDescriptor> objectProperties;
-//
-//        private ObjectParamMetadata(List<PropertyDescriptor> objectProperties) {
-//            this.objectProperties = Collections.unmodifiableList(objectProperties);
-//        }
-//
-//        private static ObjectParamMetadata parseObjectType(Class<?> type)
-//                throws IntrospectionException {
-//            List<PropertyDescriptor> properties = new ArrayList<PropertyDescriptor>();
-//
-//            for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
-//                boolean isGetterMethod = pd.getReadMethod() != null && !"class".equals(pd.getName());
-//                if (isGetterMethod) {
-//                    properties.add(pd);
-//                }
-//            }
-//
-//            return new ObjectParamMetadata(properties);
-//        }
-//    }
+public class UnderlineQueryEncoder implements QueryMapEncoder {
+    private final Map<Class<?>, ObjectParamMetadata> classToMetadata =
+            new HashMap();
+
+    @Override
+    public Map<String, Object> encode(Object object) throws EncodeException {
+        try {
+            ObjectParamMetadata metadata = getMetadata(object.getClass());
+            Map<String, Object> propertyNameToValue = new HashMap<String, Object>();
+            for (PropertyDescriptor pd : metadata.objectProperties) {
+                Method method = pd.getReadMethod();
+                Object value = method.invoke(object);
+                if (value != null && value != object) {
+                    Param alias = method.getAnnotation(Param.class);
+                    String name = alias != null ? alias.value() : pd.getName();
+                    propertyNameToValue.put(StringUtils.camelToUnderlineLowerCase(name), value);
+                }
+            }
+            return propertyNameToValue;
+        } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) {
+            throw new EncodeException("Failure encoding object into query map", e);
+        }
+    }
+
+    private ObjectParamMetadata getMetadata(Class<?> objectType) throws IntrospectionException {
+        ObjectParamMetadata metadata = classToMetadata.get(objectType);
+        if (metadata == null) {
+            metadata = ObjectParamMetadata.parseObjectType(objectType);
+            classToMetadata.put(objectType, metadata);
+        }
+        return metadata;
+    }
+
+    private static class ObjectParamMetadata {
+
+        private final List<PropertyDescriptor> objectProperties;
+
+        private ObjectParamMetadata(List<PropertyDescriptor> objectProperties) {
+            this.objectProperties = Collections.unmodifiableList(objectProperties);
+        }
+
+        private static ObjectParamMetadata parseObjectType(Class<?> type)
+                throws IntrospectionException {
+            List<PropertyDescriptor> properties = new ArrayList<PropertyDescriptor>();
+
+            for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
+                boolean isGetterMethod = pd.getReadMethod() != null && !"class".equals(pd.getName());
+                if (isGetterMethod) {
+                    properties.add(pd);
+                }
+            }
+
+            return new ObjectParamMetadata(properties);
+        }
+    }
 }
\ No newline at end of file
diff --git a/ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java b/ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java
index d9d9409..3923a42 100644
--- a/ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java
+++ b/ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java
@@ -1,7 +1,7 @@
 package com.ycl.remote.service;
 
 import com.ycl.remote.dto.*;
-//import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
@@ -12,7 +12,7 @@
  * @author: AI
  * @date: 2022-09-28 15:40
  **/
-//@FeignClient(url = "http://10.53.139.176:81/api", name = "cityApi")
+@FeignClient(url = "http://10.53.139.176:81/api", name = "cityApi")
 public interface CityPlatformService {
 
     /**
diff --git a/ycl-platform/src/main/resources/logback.xml b/ycl-platform/src/main/resources/logback.xml
index 711cef3..4331451 100644
--- a/ycl-platform/src/main/resources/logback.xml
+++ b/ycl-platform/src/main/resources/logback.xml
@@ -107,25 +107,6 @@
 			<appender-ref ref="errorLog" />
 		</root>
 	</springProfile>
-	<springProfile name="test">
-		<!--鎵撳嵃SQL-->
-		<logger name="java.sql.Connection" level="DEBUG" />
-		<logger name="java.sql.Statement" level="DEBUG" />
-		<logger name="java.sql.PreparedStatement" level="DEBUG" />
-
-		<logger name="com.ycl.component" level="error" />
-
-		<logger name="com.ycl" level="debug" >
-			<appender-ref ref="normalLog" />
-			<appender-ref ref="errorLog" />
-		</logger>
-
-		<root level="info">
-			<appender-ref ref="Console" />
-			<appender-ref ref="normalLog" />
-			<appender-ref ref="errorLog" />
-		</root>
-	</springProfile>
 
 	<springProfile name="pro">
 		<!--鎵撳嵃SQL-->

--
Gitblit v1.8.0