zhanghua
2022-09-28 038ab5f05825d7f49872ae61bd25bad9e80193aa
屏蔽Feign代码
5个文件已修改
5个文件已添加
272 ■■■■ 已修改文件
pom.xml 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/utils/StringUtils.java 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/PlatformApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/config/feign/MessageConverter.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/controller/caseHandler/BaseCaseController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/remote/service/CityPlatformService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
ycl-common/src/main/java/com/ycl/utils/StringUtils.java
New file
@@ -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();
    }
}
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 {
ycl-platform/src/main/java/com/ycl/config/feign/FeignConfiguration.java
New file
@@ -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);
//    }
}
ycl-platform/src/main/java/com/ycl/config/feign/FeignGlobalConfiguration.java
New file
@@ -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);
//    }
}
ycl-platform/src/main/java/com/ycl/config/feign/MessageConverter.java
New file
@@ -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);
    }
}
ycl-platform/src/main/java/com/ycl/config/feign/UnderlineQueryEncoder.java
New file
@@ -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);
//        }
//    }
}
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);
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 {
    /**
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