test:(修改车量管理)

dev
zhang xu 2024-06-12 22:07:07 +08:00
parent 9db5a3bbc4
commit df9d6a142c
17 changed files with 342 additions and 236 deletions

7
DirectoryV3.xml 100644
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<trees>
<tree path="/muyu-modules/muyu-enterprise"/>
<tree path="/muyu-modules/muyu-vehicle" title="车辆业务模块"/>
<tree path="/muyu-modules/muyu-vehicle/muyu-vehicle-common" title="业务公共模块"/>
<tree path="/muyu-modules/muyu-networking" title="运营企业平台模块"/>
</trees>

View File

@ -1,92 +0,0 @@
package com.muyu.config.role;
import com.alibaba.druid.pool.DruidDataSource;
import com.muyu.common.core.utils.SpringUtils;
import com.muyu.config.DynamicDataSource;
import com.muyu.config.domain.model.DataSourceInfo;
import com.muyu.config.domain.model.EntInfo;
import com.muyu.config.factory.DruidDataSourceFactory;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @ClassDescription:
* @JdkVersion: 17
* @Author: zhangxu
* @Created: 2024/6/4 9:05
*/
@Log4j2
@Component
@AllArgsConstructor
public class ManyDataSource {
@PostConstruct
public void init(){
new Thread(()-> {
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {}
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
DynamicDataSource dynamicDataSource =SpringUtils.getBean(DynamicDataSource.class);
EntInfo entInfo = EntInfo.builder()
.entCode("ent_4587")
.ip("115.159.67.205")
.port(3307)
.build();
DataSourceInfo dataSourceInfo = DataSourceInfo.getDataSourceInfo(entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort());
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
dynamicDataSource.put(dataSourceInfo.getKey(),druidDataSource);
}).start();
}
private List<EntInfo> dataSourceInfoList(){
List<EntInfo> list = new ArrayList<>();
list.add(
EntInfo.builder()
.entCode("ent_4587")
.ip("115.159.67.205")
.port(3307)
.build()
);
return list;
}
@Bean
@Primary
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
Map<Object, Object> map = new HashMap<>();
dataSourceInfoList().stream()
.map(entInfo -> DataSourceInfo.getDataSourceInfo(entInfo.getEntCode(),entInfo.getIp(),entInfo.getPort()))
.forEach(dataSourceInfo -> {
map.put(dataSourceInfo.getKey(),druidDataSourceFactory.create(dataSourceInfo));
});
//设置动态数据源
DynamicDataSource dynamicDataSource = new DynamicDataSource();
dynamicDataSource.setTargetDataSources(map);
dynamicDataSource.setDefaultTargetDataSource(map);
return dynamicDataSource;
}
}

View File

@ -1,47 +0,0 @@
package com.muyu.networking.interceptor;
import com.muyu.networking.service.DataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @ClassName SaasInterceptor
* @Author GuanTieLin
* @Date 2024/6/3 21:09
*/
@Component
public class SaasInterceptor implements AsyncHandlerInterceptor {
@Autowired
private DataSourceService changeDataSourceService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 解决跨域问题
//1.如果请求不是动态的,handler对象不是HandlerMethod的实例(静态页面).放行
//2.如果请求是跨域请求(请求方法是:OPTIONS),handler对象不是HandlerMethod
if (!(handler instanceof HandlerMethod)) {
return true;
}
String datasourceCode = request.getHeader("datasource-code");
if(datasourceCode==null){
throw new RuntimeException("请求不合法");
}
changeDataSourceService.changeDS(Long.valueOf(datasourceCode));
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// 切换为默认数据源
changeDataSourceService.toDefaultDS();
}
}

View File

@ -1,17 +1,17 @@
package com.muyu.networking.mapper; //package com.muyu.networking.mapper;
//
//
import com.baomidou.mybatisplus.core.mapper.BaseMapper; //import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.domain.datasources.SongInfo; //import com.muyu.domain.datasources.SongInfo;
import org.apache.ibatis.annotations.Mapper; //import org.apache.ibatis.annotations.Mapper;
//
/** ///**
* songMapper // * songMapper接口
* // *
* @author // * @author
* @date // * @date
*/ // */
@Mapper //@Mapper
public interface SongMapper extends BaseMapper<SongInfo> { // song_info对象 //public interface SongMapper extends BaseMapper<SongInfo> { // song_info对象
} //}
//

View File

@ -1,22 +0,0 @@
package com.muyu.networking.opFen;
import com.muyu.common.core.domain.Result;
import com.muyu.common.system.domain.SysUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @ClassDescription:
* @JdkVersion: 17
* @Author: zhangxu
* @Created: 2024/5/27 15:11
*/
@FeignClient("muyu-system")
public interface SysUserNet {
@PostMapping("/system/user")
public Result add (@Validated @RequestBody SysUser user);
}

View File

@ -1,23 +1,23 @@
package com.muyu.networking.service; //package com.muyu.networking.service;
//
import com.baomidou.mybatisplus.extension.service.IService; //import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.domain.datasources.SongInfo; //import com.muyu.domain.datasources.SongInfo;
//
import java.util.List; //import java.util.List;
//
/** ///** 多数据源
* songService // * songService接口
* // *
* @author // * @author
* @date 2024-05-16 // * @date 2024-05-16
*/ // */
public interface SongService extends IService<SongInfo> { // song_info对象 //public interface SongService extends IService<SongInfo> { // song_info对象
/** // /**
* song // * 查询song列表
* // *
* @return song // * @return song集合
*/ // */
public List<SongInfo> list(); // song_info对象 // public List<SongInfo> list(); // song_info对象
//
} //}
//

View File

@ -1,35 +1,35 @@
package com.muyu.networking.service.impl; //package com.muyu.networking.service.impl;
//
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; //import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.domain.datasources.SongInfo; //import com.muyu.domain.datasources.SongInfo;
import com.muyu.networking.mapper.SongMapper; //import com.muyu.networking.mapper.SongMapper;
import com.muyu.networking.service.SongService; //import com.muyu.networking.service.SongService;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import java.util.List; //import java.util.List;
//
/** ///** 多数据源
* songService // * songService业务层处理
* // *
* @author // * @author
* @date 2024-05-16 // * @date 2024-05-16
*/ // */
@Slf4j //@Slf4j
@Service //@Service
public class SongServiceImpl extends ServiceImpl<SongMapper, SongInfo> implements SongService { // song_info对象 | songService接口 //public class SongServiceImpl extends ServiceImpl<SongMapper, SongInfo> implements SongService { // song_info对象 | songService接口
//
/** // /**
* song // * 查询song列表
* // *
* @return song // * @return song
*/ // */
@Override // 查询song列表 // @Override // 查询song列表
public List<SongInfo> list() { // song_info对象 // public List<SongInfo> list() { // song_info对象
return this.list(new LambdaQueryWrapper<>()); // return this.list(new LambdaQueryWrapper<>());
} // }
//
} //}
//

View File

@ -0,0 +1,7 @@
在过去的几年里Java开发者们为了构建一个企业应用常常需要将许多的框架组合起来使用例如Hibernate、SpringMVC和Spring等这样的过程往往会耗费大量时间且复杂。这也就是Spring Boot应运而生的原因。
Spring Boot使用“习惯优于配置”的理念简单来说它提供了一堆依赖打包并已经按照使用习惯解决了依赖问题。使用Spring Boot可以不用或者只需要很少的Spring配置就可以让企业项目快速运行起来。
SpringBoot是一个快速开发的框架能过快速整合第三方框架他是如何快速整合的呢其实他是的基本原来是Maven依赖关系Maven的集成完全采用注解化简化XML配置内嵌HTTP服务器Tomcatejetty默认嵌入Tomcate最终以Java应用程序进行执行

View File

@ -0,0 +1,26 @@
package com.muyu.vehicle;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
import com.muyu.common.security.annotation.EnableCustomConfig;
import com.muyu.common.security.annotation.EnableMyFeignClients;
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* @ClassDescription:
* @JdkVersion: 17
* @Author: zhangxu
* @Created: 2024/6/6 19:39
*/
@EnableCustomConfig
@EnableCustomSwagger2
@EnableMyFeignClients
@SpringBootApplication(exclude = {DynamicDataSourceAutoConfiguration.class, DataSourceAutoConfiguration.class})
public class VehicleApplication {
public static void main(String[] args) {
SpringApplication.run(VehicleApplication.class, args);
}
}

View File

@ -0,0 +1,37 @@
//package com.muyu.vehicle.controller;
//
//
//import com.muyu.common.core.domain.Result;
//import com.muyu.domain.datasources.SongInfo;
//
//import com.muyu.vehicle.service.SongService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.List;
//
///** 多数据源
// * songController
// *
// * @author 张zhangxu
// * @date 2024-05-16
// */
//@RestController
//@RequestMapping("/song")
//public class SongController {
//
// @Autowired
// private SongService songService; // songService接口
//
// /**
// * 查询歌曲列表
// */
// @GetMapping("/list")
// public Result<List<SongInfo>> list() { // song_info对象
// return Result.success(songService.list()); // 查询song列表
// }
//
//}
//

View File

@ -0,0 +1,36 @@
//package com.muyu.vehicle.interceptor;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
///**
// * 拦截器配置
// *
// * @author zhangxu
// */
//@Configuration
//public class WebMvcConfig implements WebMvcConfigurer {
// /**
// * 不需要拦截地址
// */
// public static final String[] excludeUrls = {"/login", "/logout", "/refresh","/enterprise"};
//
// @Override
// public void addInterceptors (InterceptorRegistry registry) {
// registry.addInterceptor(getSaasInterceptor()) // 自定义请求头拦截器
// .addPathPatterns("/networking/**")
// .excludePathPatterns(excludeUrls) // 不需要拦截地址
// .order(-10);
// }
//
// /**
// * 自定义请求头拦截器
// */
// @Bean
// public SaasInterceptor getSaasInterceptor() {
// return new SaasInterceptor();
// }
//}
//

View File

@ -0,0 +1,17 @@
package com.muyu.vehicle.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.domain.datasources.SongInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* songMapper
*
* @author
* @date
*/
@Mapper
public interface SongMapper extends BaseMapper<SongInfo> { // song_info对象
}

View File

@ -0,0 +1,22 @@
package com.muyu.vehicle.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.domain.datasources.SongInfo;
import java.util.List;
/**
* songService
*
* @author
* @date 2024-05-16
*/
public interface SongService extends IService<SongInfo> { // song_info对象
/**
* song
*
* @return song
*/
public List<SongInfo> list(); // song_info对象
}

View File

@ -0,0 +1,40 @@
# Tomcat
server:
port: 9205
# Spring
spring:
rabbitmq:
username: guest
password: guest
virtualHost: /
port: 5672
host: 115.159.67.205
listener:
simple:
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
publisher-returns: true #确认消息已发送到队列(Queue)
application:
# 应用名称
name: muyu-vehicle
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 115.159.67.205:8848
config:
# 配置中心地址
server-addr: 115.159.67.205:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu-vehicle.mapper: DEBUG

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/muyu-vehicle"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>