From 038ab5f05825d7f49872ae61bd25bad9e80193aa Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期三, 28 九月 2022 20:15:49 +0800
Subject: [PATCH] 屏蔽Feign代码

---
 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-common/src/main/java/com/ycl/utils/StringUtils.java                              |   78 +++++++++++++++
 ycl-platform/src/main/java/com/ycl/controller/caseHandler/BaseCaseController.java    |    2 
 ycl-platform/src/main/java/com/ycl/PlatformApplication.java                          |    4 
 ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java           |   71 ++++++++++++++
 ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java |   46 ++++----
 pom.xml                                                                              |   10 +-
 ycl-platform/src/main/java/com/ycl/config/feign/MessageConverter.java                |   15 +++
 ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java              |   22 ++++
 10 files changed, 240 insertions(+), 32 deletions(-)

diff --git a/pom.xml b/pom.xml
index f31d0f4..7eb1820 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>2.2.7.RELEASE</version>-->
+<!--        </dependency>-->
     </dependencies>
 
 </project>
diff --git a/ycl-common/src/main/java/com/ycl/utils/StringUtils.java b/ycl-common/src/main/java/com/ycl/utils/StringUtils.java
new file mode 100644
index 0000000..4fa7c6c
--- /dev/null
+++ b/ycl-common/src/main/java/com/ycl/utils/StringUtils.java
@@ -0,0 +1,78 @@
+package com.ycl.utils;
+
+public class StringUtils {
+
+    /**
+     * 涓嶅鐞嗗ぇ灏忓啓
+     * helloWorld=>hello_World
+     * HelloWorld=>Hello_World
+     *
+     * @param content
+     * @return
+     */
+    private static String camelToUnderlineIgnoreCase(String content) {
+        return new StringBuilder(16)
+                .append(content.substring(0, 1))
+                .append(content.substring(1).replaceAll("([A-Z])", "_$1"))
+                .toString();
+    }
+
+
+    /**
+     * 椹煎嘲杞叏灏忎笅鍒掔嚎
+     * helloWorld=>hello_world
+     * HelloWorld=>hello_world
+     *
+     * @return
+     */
+    public static String camelToUnderlineLowerCase(String content) {
+        return camelToUnderlineIgnoreCase(content).toLowerCase();
+    }
+
+
+    /**
+     * 椹煎嘲杞叏澶у啓涓嬪垝绾�
+     * helloWorld=>HELLO_WORLD
+     * HelloWorld=>HELLO_WORLD
+     *
+     * @return
+     */
+    public static String camelToUnderlineUpperCase(String content) {
+        return camelToUnderlineIgnoreCase(content)
+                .toLowerCase();
+    }
+
+
+    /**
+     * 涓嬪垝绾胯浆灏忛┘宄�
+     * hello_world=>helloWorld
+     * HELLO_WORLD=>helloWorld
+     * Hello_World=>helloWorld
+     * @param content
+     * @return
+     */
+    public static String underlineToLowerCamelCase(String content) {
+        return new StringBuilder(16)
+                .append(content.substring(0,1).toLowerCase())
+                .append(content.substring(1).replaceAll("_([a-zA-Z])","$1".toUpperCase()))
+                .toString();
+    }
+
+
+    /**
+     * 涓嬪垝绾胯浆澶ч┘宄�
+     * hello_world=>HelloWorld
+     * HELLO_WORLD=>HelloWorld
+     * Hello_World=>HelloWorld
+     * @param content
+     * @return
+     */
+    public static String underlineToCamelUpperCase(String content) {
+        return new StringBuilder(16)
+                .append(content.substring(0, 1).toUpperCase())
+                .append(content.substring(1).replaceAll("_([a-zA-Z])", "$1".toUpperCase()))
+                .toString();
+    }
+
+
+}
\ No newline at end of file
diff --git a/ycl-platform/src/main/java/com/ycl/PlatformApplication.java b/ycl-platform/src/main/java/com/ycl/PlatformApplication.java
index 5f2d978..fc23227 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
new file mode 100644
index 0000000..cdcfa36
--- /dev/null
+++ b/ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java
@@ -0,0 +1,22 @@
+package com.ycl.config.feign;
+
+//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);
+//    }
+}
\ 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
new file mode 100644
index 0000000..89abd9a
--- /dev/null
+++ b/ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java
@@ -0,0 +1,20 @@
+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 org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class FeignGlobalConfiguration {
+
+
+//    @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/MessageConverter.java b/ycl-platform/src/main/java/com/ycl/config/feign/MessageConverter.java
new file mode 100644
index 0000000..d78f77e
--- /dev/null
+++ b/ycl-platform/src/main/java/com/ycl/config/feign/MessageConverter.java
@@ -0,0 +1,15 @@
+package com.ycl.config.feign;
+
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MessageConverter extends MappingJackson2HttpMessageConverter {
+    public MessageConverter(){
+        List<MediaType> mediaTypes = new ArrayList<>();
+        mediaTypes.add(MediaType.TEXT_PLAIN);
+        setSupportedMediaTypes(mediaTypes);
+    }
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..2a17195
--- /dev/null
+++ b/ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java
@@ -0,0 +1,71 @@
+package com.ycl.config.feign;
+
+import com.ycl.utils.StringUtils;
+//import feign.Param;
+//import feign.QueryMapEncoder;
+//import feign.codec.EncodeException;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+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);
+//        }
+//    }
+}
\ No newline at end of file
diff --git a/ycl-platform/src/main/java/com/ycl/controller/caseHandler/BaseCaseController.java b/ycl-platform/src/main/java/com/ycl/controller/caseHandler/BaseCaseController.java
index 13eb69e..fd638a9 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/caseHandler/BaseCaseController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/caseHandler/BaseCaseController.java
@@ -165,7 +165,7 @@
      * @Param [violationParam]
      **/
     @ApiOperation(value = "娣诲姞杩濆缓妗堜欢")
-    @PostMapping("/addition_violation")
+    @PostMapping("/addition_illegal_building")
     public CommonResult addIllegalBuildingCase(@RequestBody @Validated IllegalBuildingParam illegalBuildingParam) {
         BaseCase baseCase = new BaseCase();
         BeanUtils.copyProperties(illegalBuildingParam, baseCase);
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 3923a42..d9d9409 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/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
index a4b3cd8..a4cd580 100644
--- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
+++ b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
@@ -44,17 +44,17 @@
 @Service
 public class BaseCaseServiceImpl extends ServiceImpl<BaseCaseMapper, BaseCase> implements IBaseCaseService {
 
-    private CityPlatformService cityPlatformService;
+    //    private CityPlatformService cityPlatformService;
     private IViolationsService violationsService;
     private IVideoAlarmReportService videoAlarmReportService;
 
     @Value("${fdfs.fileUrl}")
     private String fileUrl;
 
-    @Autowired
-    public void setCityPlatformService(CityPlatformService cityPlatformService) {
-        this.cityPlatformService = cityPlatformService;
-    }
+//    @Autowired
+//    public void setCityPlatformService(CityPlatformService cityPlatformService) {
+//        this.cityPlatformService = cityPlatformService;
+//    }
 
     @Autowired
     public void setViolationsService(IViolationsService violationsService) {
@@ -91,29 +91,31 @@
         }
         EventAddParamDto dto = EventAddParamDto.builder().y84(baseCase.getLatitude().toString()).x84(baseCase.getLongitude().toString())
                 .source(11).address(baseCase.getSite()).eventDesc(eventDesc).eventSign(baseCase.getCode()).medias(medias).build();
-        ResultResponseDto<EventAddResponseDto> result = cityPlatformService.addEvent(dto);
-        if (result.getCode() == 0) {
-            EventAddResponseDto responseDto = result.getResult();
-            baseCase.setTaskCode(responseDto.getTaskcode());
-            this.updateById(baseCase);
-            return null;
-        } else {
-            return result.getMsg();
-        }
+//        ResultResponseDto<EventAddResponseDto> result = cityPlatformService.addEvent(dto);
+//        if (result.getCode() == 0) {
+//            EventAddResponseDto responseDto = result.getResult();
+//            baseCase.setTaskCode(responseDto.getTaskcode());
+//            this.updateById(baseCase);
+//            return null;
+//        } else {
+//            return result.getMsg();
+//        }
+        return null;
     }
 
     @Override
     public String processEvent(Integer caseId) {
         BaseCase baseCase = this.getById(caseId);
         EventProcessParamDto paramDto = EventProcessParamDto.builder().eventSign(baseCase.getCode()).taskcode(baseCase.getTaskCode()).build();
-        ResultResponseDto<EventProcessResponseDto> responseDto = cityPlatformService.getEventProcess(paramDto);
-        if (responseDto.getCode() == 0) {
-            EventProcessResponseDto eventProcessResponseDto = responseDto.getResult();
-            /*********** 鏈鐞嗗競骞冲彴杩斿洖鏁版嵁 ***************/
-            return null;
-        } else {
-            return responseDto.getMsg();
-        }
+//        ResultResponseDto<EventProcessResponseDto> responseDto = cityPlatformService.getEventProcess(paramDto);
+//        if (responseDto.getCode() == 0) {
+//            EventProcessResponseDto eventProcessResponseDto = responseDto.getResult();
+//            /*********** 鏈鐞嗗競骞冲彴杩斿洖鏁版嵁 ***************/
+//            return null;
+//        } else {
+//            return responseDto.getMsg();
+//        }
+        return null;
     }
 
     @Override

--
Gitblit v1.8.0