init
This commit is contained in:
parent
9914bb5fa2
commit
5831b770f0
34
.gitignore
vendored
Normal file
34
.gitignore
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
/weight-loss-camp-service-api/target/
|
||||
10
readme.md
Normal file
10
readme.md
Normal file
@ -0,0 +1,10 @@
|
||||
## weight-loss-camp-api-base
|
||||
基础功能服务
|
||||
## weight-loss-camp-api-data
|
||||
数据库连接服务
|
||||
|
||||
## weight-loss-camp-service-api
|
||||
基础服务接口
|
||||
|
||||
## weight-loss-camp-work-api
|
||||
工作端api
|
||||
79
weight-loss-camp-service-api/src/test/java/Gen.java
Normal file
79
weight-loss-camp-service-api/src/test/java/Gen.java
Normal file
@ -0,0 +1,79 @@
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import com.wjbl.weightlosscamp.api.base.entity.BaseEntity;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Gen {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> tableNameList = Arrays.asList(
|
||||
"qywx_approve_template_config"
|
||||
);
|
||||
|
||||
gen("jfxly", "root", "123456", tableNameList, "com.wjbl.weightlosscamp.service.api.module.sys");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void gen(String dbName, String userName, String pwd, List<String> tableNameList, String basePackage) {
|
||||
|
||||
String path = System.getProperty("user.dir");
|
||||
|
||||
System.out.println(path);
|
||||
//E:\project\data_process\zhudehao\src\main\java
|
||||
|
||||
String url = "jdbc:mysql://localhost:3307/" + dbName + "?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai";
|
||||
String username = userName;
|
||||
String password = pwd;
|
||||
FastAutoGenerator.create(url, username, password)
|
||||
.globalConfig(builder -> {
|
||||
builder.author("kevin") // 设置作者
|
||||
.commentDate("yyyy-MM-dd")
|
||||
.outputDir(path + File.separator + "weight-loss-camp-service-api" + "\\src\\main\\java")
|
||||
.disableOpenDir()
|
||||
.enableSpringdoc()
|
||||
.dateType(DateType.ONLY_DATE)
|
||||
|
||||
//.enableSpringdoc()
|
||||
; // 指定输出目录
|
||||
}).packageConfig(builder -> {
|
||||
builder.parent(basePackage);
|
||||
}).strategyConfig(builder -> {
|
||||
builder
|
||||
.addTablePrefix("tb_")
|
||||
.addInclude(tableNameList)
|
||||
.entityBuilder()
|
||||
.enableFileOverride()
|
||||
.enableLombok()
|
||||
//enableTableFieldAnnotation()
|
||||
.versionColumnName("revision")
|
||||
.logicDeleteColumnName("deleted")
|
||||
.superClass(BaseEntity.class)
|
||||
.addSuperEntityColumns("id", "tenant_id", "created_by_id", "created_by", "created_time", "updated_by", "updated_by_id", "updated_time", "deleted", "revision")
|
||||
.addIgnoreColumns("dev_remark")
|
||||
//.enableActiveRecord()
|
||||
.idType(IdType.ASSIGN_ID)
|
||||
.controllerBuilder()
|
||||
//.enableFileOverride()
|
||||
.enableRestStyle()
|
||||
.serviceBuilder()
|
||||
.enableFileOverride()
|
||||
.formatServiceFileName("%sService")
|
||||
.formatServiceImplFileName("%sServiceImp")
|
||||
.mapperBuilder()
|
||||
.enableMapperAnnotation()
|
||||
.enableBaseResultMap()
|
||||
.enableBaseColumnList()
|
||||
.enableFileOverride()
|
||||
;
|
||||
})
|
||||
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
||||
.execute();
|
||||
|
||||
}
|
||||
}
|
||||
78
weight-loss-camp-work-api/pom.xml
Normal file
78
weight-loss-camp-work-api/pom.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.wjbl</groupId>
|
||||
<artifactId>weight-loss-camp</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weight-loss-camp-work-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>营地服务应用API</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 内部依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.wjbl</groupId>
|
||||
<artifactId>weight-loss-camp-api-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Cloud OpenFeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Cloud LoadBalancer -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Cloud Alibaba Nacos Discovery -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
||||
<version>1.37.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -0,0 +1,21 @@
|
||||
package com.wjbl.weightlosscamp;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* 营地工作服务API启动类
|
||||
*
|
||||
* @author generated
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class WorkApiApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WorkApiApplication.class, args);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.wjbl.weightlosscamp.service.api.client;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* 服务Feign客户端
|
||||
* 使用OpenFeign调用service-api服务
|
||||
*
|
||||
* @author generated
|
||||
*/
|
||||
@FeignClient(name = "weight-loss-camp-service-api", path = "/service-api")
|
||||
public interface ServiceFeignClient {
|
||||
|
||||
/**
|
||||
* 示例方法:根据ID获取数据
|
||||
*
|
||||
* @param id 数据ID
|
||||
* @return 返回数据字符串
|
||||
*/
|
||||
@GetMapping("/example/{id}")
|
||||
String getExampleDataById(@PathVariable("id") Long id);
|
||||
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
package com.wjbl.weightlosscamp.service.api.config;
|
||||
|
||||
import com.wjbl.weightlosscamp.api.base.constant.WebParamConstant;
|
||||
import feign.Logger;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.Response;
|
||||
import feign.codec.Decoder;
|
||||
import feign.codec.Encoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Feign配置类
|
||||
*
|
||||
* @author generated
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class FeignConfig {
|
||||
|
||||
/**
|
||||
* 配置Feign日志级别
|
||||
*/
|
||||
@Bean
|
||||
public Logger.Level feignLoggerLevel() {
|
||||
return Logger.Level.FULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求拦截器,添加traceId用于链路追踪
|
||||
*/
|
||||
@Bean
|
||||
public RequestInterceptor requestInterceptor() {
|
||||
return requestTemplate -> {
|
||||
// 添加请求唯一标识
|
||||
// 设置序列号
|
||||
|
||||
String seq = MDC.get(WebParamConstant.SEQ);
|
||||
|
||||
if (seq == null || seq.isEmpty()) {
|
||||
seq = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
// 记录请求信息
|
||||
String method = requestTemplate.method();
|
||||
String url = requestTemplate.url();
|
||||
Map<String, Collection<String>> headers = requestTemplate.headers();
|
||||
|
||||
StringBuilder requestLog = new StringBuilder();
|
||||
requestLog.append("\n================================ Feign请求开始 ================================\n");
|
||||
requestLog.append("请求方式: ").append(method).append("\n");
|
||||
requestLog.append("请求地址: ").append(url).append("\n");
|
||||
requestLog.append("请求头: ").append(headers).append("\n");
|
||||
|
||||
// 获取请求体
|
||||
if (requestTemplate.body() != null) {
|
||||
String bodyStr = new String(requestTemplate.body(), StandardCharsets.UTF_8);
|
||||
requestLog.append("请求参数: ").append(bodyStr).append("\n");
|
||||
}
|
||||
|
||||
log.info(requestLog.toString());
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Feign编码器,记录请求参数
|
||||
*/
|
||||
@Bean
|
||||
public Encoder loggingEncoder(Encoder defaultEncoder) {
|
||||
return (object, bodyType, template) -> {
|
||||
defaultEncoder.encode(object, bodyType, template);
|
||||
if (object != null) {
|
||||
log.info("请求参数对象: {}", object);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Feign解码器,记录响应结果
|
||||
*/
|
||||
@Bean
|
||||
public Decoder loggingDecoder(Decoder defaultDecoder) {
|
||||
return (response, type) -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// 克隆响应,因为响应体只能读取一次
|
||||
Response clonedResponse = cloneResponse(response);
|
||||
|
||||
try {
|
||||
// 记录响应信息
|
||||
String responseBody = getResponseBody(clonedResponse);
|
||||
|
||||
StringBuilder responseLog = new StringBuilder();
|
||||
responseLog.append("\n================================ Feign响应结果 ================================\n");
|
||||
responseLog.append("响应状态: ").append(clonedResponse.status()).append("\n");
|
||||
responseLog.append("响应头: ").append(clonedResponse.headers()).append("\n");
|
||||
responseLog.append("响应体: ").append(responseBody).append("\n");
|
||||
responseLog.append("处理时间: ").append(System.currentTimeMillis() - startTime).append("ms\n");
|
||||
responseLog.append("================================ Feign请求结束 ================================\n");
|
||||
|
||||
log.info(responseLog.toString());
|
||||
|
||||
// 使用原始响应解码
|
||||
return defaultDecoder.decode(response, type);
|
||||
} catch (Exception e) {
|
||||
log.error("记录Feign响应日志失败", e);
|
||||
return defaultDecoder.decode(response, type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 克隆响应对象
|
||||
*/
|
||||
private Response cloneResponse(Response response) {
|
||||
return Response.builder()
|
||||
.status(response.status())
|
||||
.reason(response.reason())
|
||||
.headers(response.headers())
|
||||
.body(response.body())
|
||||
.request(response.request())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取响应体内容
|
||||
*/
|
||||
private String getResponseBody(Response response) {
|
||||
if (response.body() == null) {
|
||||
return "(空响应体)";
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] bodyData = feign.Util.toByteArray(response.body().asInputStream());
|
||||
return new String(bodyData, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
log.error("读取响应体失败", e);
|
||||
return "(响应体读取失败)";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.wjbl.weightlosscamp.service.api.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Web配置类
|
||||
*
|
||||
* @author generated
|
||||
*/
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
// Web相关配置,如拦截器、资源处理器等
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package com.wjbl.weightlosscamp.service.api.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.wjbl.weightlosscamp.service.api.client.ServiceFeignClient;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 示例控制器
|
||||
*
|
||||
* @author generated
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/example")
|
||||
public class ExampleController {
|
||||
|
||||
@Autowired
|
||||
private ServiceFeignClient serviceFeignClient;
|
||||
|
||||
/**
|
||||
* 示例方法:通过Feign调用服务API
|
||||
*
|
||||
* @param id 数据ID
|
||||
* @return 返回数据字符串
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public String getExample(@PathVariable Long id) {
|
||||
log.info("接收到获取示例数据请求, id={}", id);
|
||||
return serviceFeignClient.getExampleDataById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 健康检查接口
|
||||
*
|
||||
* @return 返回健康状态
|
||||
*/
|
||||
@GetMapping("/health")
|
||||
public String health() {
|
||||
return "work-api服务运行正常!";
|
||||
}
|
||||
}
|
||||
48
weight-loss-camp-work-api/src/main/resources/application.yml
Normal file
48
weight-loss-camp-work-api/src/main/resources/application.yml
Normal file
@ -0,0 +1,48 @@
|
||||
server:
|
||||
port: 9001
|
||||
servlet:
|
||||
context-path: /work-api
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: weight-loss-camp-work-api
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3307/kevin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: 123456
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 60.205.225.2:8848
|
||||
group: weight-loss-camp
|
||||
# OpenFeign配置
|
||||
openfeign:
|
||||
client:
|
||||
config:
|
||||
default:
|
||||
connectTimeout: 5000
|
||||
readTimeout: 5000
|
||||
loggerLevel: FULL
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
com.wjbl.weight.loss.camp.service.api.apiservice: DEBUG
|
||||
|
||||
# Knife4j配置
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
language: zh-CN
|
||||
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
token-name: Authorization
|
||||
token-prefix: Bearer
|
||||
timeout: 2592000
|
||||
active-timeout: -1
|
||||
is-concurrent: true
|
||||
is-share: false
|
||||
token-style: uuid
|
||||
is-log: true
|
||||
48
weight-loss-camp-work-api/src/main/resources/log4j2.xml
Normal file
48
weight-loss-camp-work-api/src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
<Properties>
|
||||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{TraceId}] %-5level %logger{36} - %msg%n</Property>
|
||||
<Property name="LOG_FILE_PATH">logs/weight-loss-camp-work-api</Property>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}" />
|
||||
</Console>
|
||||
|
||||
<RollingFile name="FileAppender" fileName="${LOG_FILE_PATH}/application.log" filePattern="${LOG_FILE_PATH}/application-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout pattern="${LOG_PATTERN}" />
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" />
|
||||
<SizeBasedTriggeringPolicy size="10MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="10" />
|
||||
</RollingFile>
|
||||
|
||||
<RollingFile name="ErrorFileAppender" fileName="${LOG_FILE_PATH}/error.log" filePattern="${LOG_FILE_PATH}/error-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout pattern="${LOG_PATTERN}" />
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" />
|
||||
<SizeBasedTriggeringPolicy size="10MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="10" />
|
||||
<Filters>
|
||||
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
</Filters>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="FileAppender" />
|
||||
<AppenderRef ref="ErrorFileAppender" />
|
||||
</Root>
|
||||
|
||||
<Logger name="com.wjbl.weight-loss-camp" level="debug" additivity="false">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="FileAppender" />
|
||||
<AppenderRef ref="ErrorFileAppender" />
|
||||
</Logger>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user