Merge remote-tracking branch 'origin/dev' into dev
commit
a9bfdc1670
|
@ -24,48 +24,6 @@ public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V> {
|
|||
redisService.setCacheObject(encode(key),value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存中车辆的数据
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public V getManage(K key) {
|
||||
return redisService.getCacheObject(encode(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据存入缓存
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
@Override
|
||||
public void putManage(K key, V value) {
|
||||
redisService.setCacheObject(encode(key),value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取缓存中故障的数据
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public V getFault(K key) {
|
||||
return redisService.getCacheObject(encode(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据存入故障缓存
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
@Override
|
||||
public void putFault(K key, V value) {
|
||||
redisService.setCacheObject(encode(key),value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return redisService.getCacheObject(encode(key));
|
||||
|
|
|
@ -12,35 +12,6 @@ import java.awt.image.Kernel;
|
|||
|
||||
public interface CacheBasic<K,V> extends PrimaryKeyBasic<K>{
|
||||
|
||||
/**
|
||||
* 将数据存入车辆缓存
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
void putManage(K key,V value);
|
||||
|
||||
/**
|
||||
* 获取缓存中故障的数据
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
V getFault(K key);
|
||||
|
||||
/**
|
||||
* 将数据存入故障缓存
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
void putFault(K key,V value);
|
||||
|
||||
/**
|
||||
* 获取缓存中车辆的数据
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
V getManage(K key);
|
||||
|
||||
|
||||
void put(K key,V value);
|
||||
|
||||
V get(K key);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-common-swagger</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-common-swagger api接口文档
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.common.swagger.annotation;
|
||||
|
||||
import com.muyu.common.swagger.config.SwaggerAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @ClassName EnableCustomSwagger2
|
||||
* @Description EnableCustomSwagger2:类的描述
|
||||
* @Date 2024/10/6 22:16
|
||||
* @author MingWei.Zong
|
||||
*/
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({SwaggerAutoConfiguration.class})
|
||||
public @interface EnableCustomSwagger2 {
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package com.muyu.common.swagger.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName SwaggerAutoConfiguration
|
||||
* @Description SwaggerAutoConfiguration:类的描述
|
||||
* @Date 2024/10/6 22:16
|
||||
* @author MingWei.Zong
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
||||
@Import({SwaggerBeanPostProcessor.class, SwaggerWebConfiguration.class})
|
||||
public class SwaggerAutoConfiguration {
|
||||
/**
|
||||
* 默认的排除路径,排除Spring Boot默认的错误处理路径和端点
|
||||
*/
|
||||
private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error", "/actuator/**");
|
||||
|
||||
private static final String BASE_PATH = "/**";
|
||||
|
||||
@Bean
|
||||
public Docket api (SwaggerProperties swaggerProperties) {
|
||||
// base-path处理
|
||||
if (swaggerProperties.getBasePath().isEmpty()) {
|
||||
swaggerProperties.getBasePath().add(BASE_PATH);
|
||||
}
|
||||
// noinspection unchecked
|
||||
List<Predicate<String>> basePath = new ArrayList<Predicate<String>>();
|
||||
swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path)));
|
||||
|
||||
// exclude-path处理
|
||||
if (swaggerProperties.getExcludePath().isEmpty()) {
|
||||
swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);
|
||||
}
|
||||
|
||||
List<Predicate<String>> excludePath = new ArrayList<>();
|
||||
swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path)));
|
||||
|
||||
ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost())
|
||||
.apiInfo(apiInfo(swaggerProperties)).select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()));
|
||||
|
||||
swaggerProperties.getBasePath().forEach(p -> builder.paths(PathSelectors.ant(p)));
|
||||
swaggerProperties.getExcludePath().forEach(p -> builder.paths(PathSelectors.ant(p).negate()));
|
||||
|
||||
return builder.build().securitySchemes(securitySchemes()).securityContexts(securityContexts()).pathMapping("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全模式,这里指定token通过Authorization头请求头传递
|
||||
*/
|
||||
private List<SecurityScheme> securitySchemes () {
|
||||
List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
||||
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
|
||||
return apiKeyList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全上下文
|
||||
*/
|
||||
private List<SecurityContext> securityContexts () {
|
||||
List<SecurityContext> securityContexts = new ArrayList<>();
|
||||
securityContexts.add(
|
||||
SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
||||
.build());
|
||||
return securityContexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的全局鉴权策略
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<SecurityReference> defaultAuth () {
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
List<SecurityReference> securityReferences = new ArrayList<>();
|
||||
securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
|
||||
return securityReferences;
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo (SwaggerProperties swaggerProperties) {
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerProperties.getTitle())
|
||||
.description(swaggerProperties.getDescription())
|
||||
.license(swaggerProperties.getLicense())
|
||||
.licenseUrl(swaggerProperties.getLicenseUrl())
|
||||
.termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
|
||||
.contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail()))
|
||||
.version(swaggerProperties.getVersion())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.muyu.common.swagger.config;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
|
||||
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName SwaggerBeanPostProcessor
|
||||
* @Description SwaggerBeanPostProcessor:类的描述
|
||||
* @Date 2024/10/6 22:16
|
||||
* @author MingWei.Zong
|
||||
*/
|
||||
public class SwaggerBeanPostProcessor implements BeanPostProcessor {
|
||||
@Override
|
||||
public Object postProcessAfterInitialization (Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
|
||||
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings (List<T> mappings) {
|
||||
List<T> copy = mappings.stream().filter(mapping -> mapping.getPatternParser() == null)
|
||||
.collect(Collectors.toList());
|
||||
mappings.clear();
|
||||
mappings.addAll(copy);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<RequestMappingInfoHandlerMapping> getHandlerMappings (Object bean) {
|
||||
try {
|
||||
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
|
||||
field.setAccessible(true);
|
||||
return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,303 @@
|
|||
package com.muyu.common.swagger.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName SwaggerProperties
|
||||
* @Description SwaggerProperties:类的描述
|
||||
* @Date 2024/10/6 22:16
|
||||
* @author MingWei.Zong
|
||||
*/
|
||||
@ConfigurationProperties("swagger")
|
||||
public class SwaggerProperties {
|
||||
/**
|
||||
* 是否开启swagger
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* swagger会解析的包路径
|
||||
**/
|
||||
private String basePackage = "";
|
||||
|
||||
/**
|
||||
* swagger会解析的url规则
|
||||
**/
|
||||
private List<String> basePath = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 在basePath基础上需要排除的url规则
|
||||
**/
|
||||
private List<String> excludePath = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 标题
|
||||
**/
|
||||
private String title = "";
|
||||
|
||||
/**
|
||||
* 描述
|
||||
**/
|
||||
private String description = "";
|
||||
|
||||
/**
|
||||
* 版本
|
||||
**/
|
||||
private String version = "";
|
||||
|
||||
/**
|
||||
* 许可证
|
||||
**/
|
||||
private String license = "";
|
||||
|
||||
/**
|
||||
* 许可证URL
|
||||
**/
|
||||
private String licenseUrl = "";
|
||||
|
||||
/**
|
||||
* 服务条款URL
|
||||
**/
|
||||
private String termsOfServiceUrl = "";
|
||||
|
||||
/**
|
||||
* host信息
|
||||
**/
|
||||
private String host = "";
|
||||
|
||||
/**
|
||||
* 联系人信息
|
||||
*/
|
||||
private Contact contact = new Contact();
|
||||
|
||||
/**
|
||||
* 全局统一鉴权配置
|
||||
**/
|
||||
private Authorization authorization = new Authorization();
|
||||
|
||||
public Boolean getEnabled () {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled (Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getBasePackage () {
|
||||
return basePackage;
|
||||
}
|
||||
|
||||
public void setBasePackage (String basePackage) {
|
||||
this.basePackage = basePackage;
|
||||
}
|
||||
|
||||
public List<String> getBasePath () {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath (List<String> basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public List<String> getExcludePath () {
|
||||
return excludePath;
|
||||
}
|
||||
|
||||
public void setExcludePath (List<String> excludePath) {
|
||||
this.excludePath = excludePath;
|
||||
}
|
||||
|
||||
public String getTitle () {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle (String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription () {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription (String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion () {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion (String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getLicense () {
|
||||
return license;
|
||||
}
|
||||
|
||||
public void setLicense (String license) {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
public String getLicenseUrl () {
|
||||
return licenseUrl;
|
||||
}
|
||||
|
||||
public void setLicenseUrl (String licenseUrl) {
|
||||
this.licenseUrl = licenseUrl;
|
||||
}
|
||||
|
||||
public String getTermsOfServiceUrl () {
|
||||
return termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public void setTermsOfServiceUrl (String termsOfServiceUrl) {
|
||||
this.termsOfServiceUrl = termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public String getHost () {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost (String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public Contact getContact () {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact (Contact contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public Authorization getAuthorization () {
|
||||
return authorization;
|
||||
}
|
||||
|
||||
public void setAuthorization (Authorization authorization) {
|
||||
this.authorization = authorization;
|
||||
}
|
||||
|
||||
public static class Contact {
|
||||
/**
|
||||
* 联系人
|
||||
**/
|
||||
private String name = "";
|
||||
/**
|
||||
* 联系人url
|
||||
**/
|
||||
private String url = "";
|
||||
/**
|
||||
* 联系人email
|
||||
**/
|
||||
private String email = "";
|
||||
|
||||
public String getName () {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName (String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl () {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl (String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getEmail () {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail (String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Authorization {
|
||||
/**
|
||||
* 鉴权策略ID,需要和SecurityReferences ID保持一致
|
||||
*/
|
||||
private String name = "";
|
||||
|
||||
/**
|
||||
* 需要开启鉴权URL的正则
|
||||
*/
|
||||
private String authRegex = "^.*$";
|
||||
|
||||
/**
|
||||
* 鉴权作用域列表
|
||||
*/
|
||||
private List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
||||
|
||||
private List<String> tokenUrlList = new ArrayList<>();
|
||||
|
||||
public String getName () {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName (String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAuthRegex () {
|
||||
return authRegex;
|
||||
}
|
||||
|
||||
public void setAuthRegex (String authRegex) {
|
||||
this.authRegex = authRegex;
|
||||
}
|
||||
|
||||
public List<AuthorizationScope> getAuthorizationScopeList () {
|
||||
return authorizationScopeList;
|
||||
}
|
||||
|
||||
public void setAuthorizationScopeList (List<AuthorizationScope> authorizationScopeList) {
|
||||
this.authorizationScopeList = authorizationScopeList;
|
||||
}
|
||||
|
||||
public List<String> getTokenUrlList () {
|
||||
return tokenUrlList;
|
||||
}
|
||||
|
||||
public void setTokenUrlList (List<String> tokenUrlList) {
|
||||
this.tokenUrlList = tokenUrlList;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AuthorizationScope {
|
||||
/**
|
||||
* 作用域名称
|
||||
*/
|
||||
private String scope = "";
|
||||
|
||||
/**
|
||||
* 作用域描述
|
||||
*/
|
||||
private String description = "";
|
||||
|
||||
public String getScope () {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope (String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getDescription () {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription (String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.common.swagger.config;
|
||||
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName SwaggerWebConfiguration
|
||||
* @Description SwaggerWebConfiguration:类的描述
|
||||
* @Date 2024/10/6 22:16
|
||||
* @author MingWei.Zong
|
||||
*/
|
||||
public class SwaggerWebConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addResourceHandlers (ResourceHandlerRegistry registry) {
|
||||
/** swagger-ui 地址 */
|
||||
registry.addResourceHandler("/swagger-ui/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-kafka</module>
|
||||
<module>cloud-common-cache</module>
|
||||
<module>cloud-common-swagger</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Gateway -->
|
||||
<!-- SpringCloud Gateway -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.muyu.enterprise.cache;
|
||||
|
||||
import com.muyu.common.cache.config.CacheAbsBasic;
|
||||
import com.muyu.enterprise.domain.CarManage;
|
||||
import com.muyu.enterprise.domain.CarMessage;
|
||||
|
||||
/**
|
||||
|
@ -11,7 +10,6 @@ import com.muyu.enterprise.domain.CarMessage;
|
|||
* @Date 2024/9/30 11:42
|
||||
* @author MingWei.Zong
|
||||
*/
|
||||
|
||||
public class CarMessageCacheService extends CacheAbsBasic<String, CarMessage> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
|
|
|
@ -3,5 +3,5 @@ com.muyu.enterprise.cache.CarFaultCacheService
|
|||
com.muyu.enterprise.cache.CarManageCacheService
|
||||
com.muyu.enterprise.cache.CarMessageCacheService
|
||||
com.muyu.enterprise.cache.CarTemplateCacheService
|
||||
com.muyu.enterprise.cache.CarWarnCacheService
|
||||
com.muyu.enterprise.cache.CarWarnCacheServic
|
||||
com.muyu.enterprise.cache.ElectronicFenceCacheService
|
|
@ -25,8 +25,8 @@ public class CarCompany {
|
|||
/**
|
||||
* 企业表
|
||||
*/
|
||||
@TableId(value = "company_id",type = IdType.AUTO)
|
||||
private Long companyId;
|
||||
@TableId(value = "enterprise_id",type = IdType.AUTO)
|
||||
private Long enterpriseId;
|
||||
/**
|
||||
* 企业名称
|
||||
*/
|
||||
|
|
|
@ -105,7 +105,7 @@ public class CarManage {
|
|||
/**
|
||||
* 汽车所属企业id
|
||||
*/
|
||||
private Long companyId;
|
||||
private Long enterpriseId;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CarDTO {
|
|||
/**
|
||||
* 车辆企业
|
||||
*/
|
||||
private Long companyId;
|
||||
private Long enterpriseId;
|
||||
/**
|
||||
* 车辆配置
|
||||
*/
|
||||
|
|
|
@ -94,7 +94,7 @@ public class CarVO {
|
|||
|
||||
|
||||
/** 所属企业 */
|
||||
private Long companyId;
|
||||
private Long enterpriseId;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -89,6 +89,12 @@
|
|||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 远程调用 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 企业业务平台 - 公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.enterprise.OpenFen;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 企业远调
|
||||
* @ClassName SysEntOpenFen
|
||||
* @Description SysEntOpenFen:类的描述
|
||||
* @Date 2024/10/7 11:52
|
||||
* @author MingWei.Zong(微醺)
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class SysEntFallbackFactory {
|
||||
|
||||
}
|
|
@ -33,15 +33,19 @@ public class CarCompanyController extends BaseController {
|
|||
@PostMapping("selectCompany")
|
||||
public Result<List<CarCompany>> selectCompany(){
|
||||
startPage();
|
||||
return Result.success(sysCarCompanyService.list());
|
||||
List<CarCompany> list = sysCarCompanyService.list();
|
||||
list.forEach(carCompany -> {
|
||||
|
||||
});
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID查询企业
|
||||
*/
|
||||
@PostMapping("selectCompanyByCompanyId")
|
||||
public Result<CarCompany> selectCompanyByCompanyId(@RequestParam("companyId") Long companyId){
|
||||
return Result.success(sysCarCompanyService.selectCompanyByCompanyId(companyId));
|
||||
public Result<CarCompany> selectCompanyByCompanyId(@RequestParam("enterpriseId") Long enterpriseId){
|
||||
return Result.success(sysCarCompanyService.selectCompanyByCompanyId(enterpriseId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ public class CarManageController extends BaseController {
|
|||
@PostMapping("/carListShow2")
|
||||
public Result<List<CarVO>> carListShow2(@RequestBody CarDTO carDTO){
|
||||
startPage();
|
||||
// 存到缓存中去
|
||||
return Result.success(sysCarService.carListShow2(carDTO));
|
||||
}
|
||||
|
||||
|
@ -87,10 +88,8 @@ public class CarManageController extends BaseController {
|
|||
// 随机生成VIN码
|
||||
String key2 = RandomUtil.randomNumbers(17);
|
||||
carVO.setCarVin(key2);
|
||||
sysCarService.save(carVO);
|
||||
// 存到缓存中去
|
||||
carManageCacheService.putManage(carVO.getCarVin(),new CarManage());
|
||||
return Result.success("车辆添加成功");
|
||||
sysCarService.insertCar(carVO);
|
||||
return Result.success("添加成功");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.muyu.enterprise.domain.CarMessage;
|
|||
import com.muyu.enterprise.service.CarMessageService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -11,11 +11,10 @@ import com.muyu.enterprise.domain.CarCompany;
|
|||
*/
|
||||
public interface CarCompanyService extends IService<CarCompany> {
|
||||
/**
|
||||
*
|
||||
* @param companyId
|
||||
* @param enterpriseId
|
||||
* @return
|
||||
*/
|
||||
CarCompany selectCompanyByCompanyId(Long companyId);
|
||||
CarCompany selectCompanyByCompanyId(Long enterpriseId);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -28,8 +28,10 @@ public interface CarManageService extends IService<CarManage> {
|
|||
*/
|
||||
List<CarVO> CarListShow(CarDTO carDTO);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 车辆添加
|
||||
* @param carVO
|
||||
* @return
|
||||
*/
|
||||
void insertCar(CarManage carVO);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,12 @@ public class CarCompanyServiceImpl extends ServiceImpl<CarCompanyMapper, CarComp
|
|||
|
||||
/**
|
||||
*
|
||||
* @param companyId
|
||||
* @param enterpriseId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CarCompany selectCompanyByCompanyId(Long companyId) {
|
||||
return carCompanyMapper.selectById(companyId);
|
||||
public CarCompany selectCompanyByCompanyId(Long enterpriseId) {
|
||||
return carCompanyMapper.selectById(enterpriseId);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.enterprise.cache.CarManageCacheService;
|
||||
import com.muyu.enterprise.controller.CarCompanyController;
|
||||
import com.muyu.enterprise.domain.CarCompany;
|
||||
import com.muyu.enterprise.domain.CarConfig;
|
||||
|
@ -39,6 +40,8 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
|
|||
@Autowired
|
||||
private CarConfigService carConfigService;
|
||||
@Autowired
|
||||
private CarManageCacheService carManageCacheService;
|
||||
@Autowired
|
||||
private CarManageMapper carManageMapper;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +58,7 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
|
|||
.eq(carManage.getCarModel() != null && carManage.getCarModel() != "", CarManage::getCarModel, carManage.getCarModel())
|
||||
.eq(carManage.getCarBrand() != null && carManage.getCarBrand() != "", CarManage::getCarBrand, carManage.getCarBrand())
|
||||
.eq(carManage.getCarStatus() != null && carManage.getCarStatus() > 0, CarManage::getCarStatus, carManage.getCarStatus())
|
||||
.eq(carManage.getCompanyId() != null && carManage.getCompanyId() > 0, CarManage::getCompanyId, carManage.getCompanyId())
|
||||
.eq(carManage.getEnterpriseId() != null && carManage.getEnterpriseId() > 0, CarManage::getEnterpriseId, carManage.getEnterpriseId())
|
||||
.list();
|
||||
// List<CarManage> list = list();
|
||||
|
||||
|
@ -69,9 +72,13 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
|
|||
carVO.setEnergyType(carConfig.getEnergyType());
|
||||
carVO.setGearType(carConfig.getGearType());
|
||||
// 查询出对象,用于赋值
|
||||
CarCompany carCompany = carCompanyService.selectCompanyByCompanyId(carVO.getCompanyId());
|
||||
CarCompany carCompany = carCompanyService.selectCompanyByCompanyId(carVO.getEnterpriseId());
|
||||
carVO.setCompanyName(carCompany.getCompanyName());
|
||||
// 存到 redis
|
||||
carManageCacheService.put(carVO.getCarVin(),new CarManage());
|
||||
});
|
||||
|
||||
|
||||
return carVOS;
|
||||
}
|
||||
@Override
|
||||
|
@ -85,16 +92,23 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
|
|||
.select(CarConfig::getGearType)
|
||||
.select(CarConfig::getEnergyType)
|
||||
.leftJoin(CarConfig.class, CarConfig::getConfigId, CarManage::getConfigId)
|
||||
.leftJoin(CarCompany.class, CarCompany::getCompanyId, CarManage::getCompanyId)
|
||||
.leftJoin(CarCompany.class, CarCompany::getEnterpriseId, CarManage::getEnterpriseId)
|
||||
.eq(carManage.getCarVin() != null && carManage.getCarVin() != "", CarManage::getCarVin, carManage.getCarVin())
|
||||
.eq(carManage.getCarModel() != null && carManage.getCarModel() != "", CarManage::getCarModel, carManage.getCarModel())
|
||||
.eq(carManage.getCarBrand() != null && carManage.getCarBrand() != "", CarManage::getCarBrand, carManage.getCarBrand())
|
||||
.eq(carManage.getCarStatus() != null && carManage.getCarStatus() > 0, CarManage::getCarStatus, carManage.getCarStatus())
|
||||
.eq(carManage.getCompanyId() != null && carManage.getCompanyId() > 0, CarManage::getCompanyId, carManage.getCompanyId())
|
||||
.eq(carManage.getEnterpriseId() != null && carManage.getEnterpriseId() > 0, CarManage::getEnterpriseId, carManage.getEnterpriseId())
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertCar(CarManage carVO) {
|
||||
save(carVO);
|
||||
// 存到缓存中去
|
||||
carManageCacheService.put(carVO.getCarVin(),new CarManage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -298,6 +298,13 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 多数据源 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
|
Loading…
Reference in New Issue