Commit 0896946390f56da90506a05053d6b40d098f6d51
1 parent
642c5f98
chore(mod): bootstrap backend scaffold REQ-MOD-001
Showing
10 changed files
with
260 additions
and
0 deletions
backend/.gitignore
0 → 100644
backend/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + | ||
| 7 | + <parent> | ||
| 8 | + <groupId>org.springframework.boot</groupId> | ||
| 9 | + <artifactId>spring-boot-starter-parent</artifactId> | ||
| 10 | + <version>3.3.5</version> | ||
| 11 | + <relativePath/> | ||
| 12 | + </parent> | ||
| 13 | + | ||
| 14 | + <groupId>com.xly</groupId> | ||
| 15 | + <artifactId>erp-backend</artifactId> | ||
| 16 | + <version>0.0.1-SNAPSHOT</version> | ||
| 17 | + <name>erp-backend</name> | ||
| 18 | + <description>小羚羊 ERP backend</description> | ||
| 19 | + | ||
| 20 | + <properties> | ||
| 21 | + <java.version>17</java.version> | ||
| 22 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 23 | + <mybatis-plus.version>3.5.9</mybatis-plus.version> | ||
| 24 | + <jjwt.version>0.12.6</jjwt.version> | ||
| 25 | + </properties> | ||
| 26 | + | ||
| 27 | + <dependencies> | ||
| 28 | + <dependency> | ||
| 29 | + <groupId>org.springframework.boot</groupId> | ||
| 30 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 31 | + </dependency> | ||
| 32 | + <dependency> | ||
| 33 | + <groupId>org.springframework.boot</groupId> | ||
| 34 | + <artifactId>spring-boot-starter-validation</artifactId> | ||
| 35 | + </dependency> | ||
| 36 | + <dependency> | ||
| 37 | + <groupId>org.springframework.boot</groupId> | ||
| 38 | + <artifactId>spring-boot-starter-security</artifactId> | ||
| 39 | + </dependency> | ||
| 40 | + <dependency> | ||
| 41 | + <groupId>org.springframework.boot</groupId> | ||
| 42 | + <artifactId>spring-boot-starter-jdbc</artifactId> | ||
| 43 | + </dependency> | ||
| 44 | + | ||
| 45 | + <dependency> | ||
| 46 | + <groupId>com.baomidou</groupId> | ||
| 47 | + <artifactId>mybatis-plus-spring-boot3-starter</artifactId> | ||
| 48 | + <version>${mybatis-plus.version}</version> | ||
| 49 | + </dependency> | ||
| 50 | + | ||
| 51 | + <dependency> | ||
| 52 | + <groupId>com.mysql</groupId> | ||
| 53 | + <artifactId>mysql-connector-j</artifactId> | ||
| 54 | + <scope>runtime</scope> | ||
| 55 | + </dependency> | ||
| 56 | + | ||
| 57 | + <dependency> | ||
| 58 | + <groupId>org.flywaydb</groupId> | ||
| 59 | + <artifactId>flyway-core</artifactId> | ||
| 60 | + </dependency> | ||
| 61 | + <dependency> | ||
| 62 | + <groupId>org.flywaydb</groupId> | ||
| 63 | + <artifactId>flyway-mysql</artifactId> | ||
| 64 | + </dependency> | ||
| 65 | + | ||
| 66 | + <dependency> | ||
| 67 | + <groupId>io.jsonwebtoken</groupId> | ||
| 68 | + <artifactId>jjwt-api</artifactId> | ||
| 69 | + <version>${jjwt.version}</version> | ||
| 70 | + </dependency> | ||
| 71 | + <dependency> | ||
| 72 | + <groupId>io.jsonwebtoken</groupId> | ||
| 73 | + <artifactId>jjwt-impl</artifactId> | ||
| 74 | + <version>${jjwt.version}</version> | ||
| 75 | + <scope>runtime</scope> | ||
| 76 | + </dependency> | ||
| 77 | + <dependency> | ||
| 78 | + <groupId>io.jsonwebtoken</groupId> | ||
| 79 | + <artifactId>jjwt-jackson</artifactId> | ||
| 80 | + <version>${jjwt.version}</version> | ||
| 81 | + <scope>runtime</scope> | ||
| 82 | + </dependency> | ||
| 83 | + | ||
| 84 | + <dependency> | ||
| 85 | + <groupId>org.springframework.boot</groupId> | ||
| 86 | + <artifactId>spring-boot-starter-test</artifactId> | ||
| 87 | + <scope>test</scope> | ||
| 88 | + </dependency> | ||
| 89 | + <dependency> | ||
| 90 | + <groupId>org.springframework.security</groupId> | ||
| 91 | + <artifactId>spring-security-test</artifactId> | ||
| 92 | + <scope>test</scope> | ||
| 93 | + </dependency> | ||
| 94 | + </dependencies> | ||
| 95 | + | ||
| 96 | + <build> | ||
| 97 | + <plugins> | ||
| 98 | + <plugin> | ||
| 99 | + <groupId>org.springframework.boot</groupId> | ||
| 100 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 101 | + </plugin> | ||
| 102 | + </plugins> | ||
| 103 | + </build> | ||
| 104 | +</project> |
backend/src/main/java/com/xly/erp/ErpApplication.java
0 → 100644
| 1 | +package com.xly.erp; | ||
| 2 | + | ||
| 3 | +import com.xly.erp.common.config.StubSecurityProperties; | ||
| 4 | +import com.xly.erp.common.config.TenantProperties; | ||
| 5 | +import org.springframework.boot.SpringApplication; | ||
| 6 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 7 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| 8 | + | ||
| 9 | +@SpringBootApplication | ||
| 10 | +@EnableConfigurationProperties({TenantProperties.class, StubSecurityProperties.class}) | ||
| 11 | +public class ErpApplication { | ||
| 12 | + public static void main(String[] args) { | ||
| 13 | + SpringApplication.run(ErpApplication.class, args); | ||
| 14 | + } | ||
| 15 | +} |
backend/src/main/java/com/xly/erp/common/config/MybatisPlusConfig.java
0 → 100644
backend/src/main/java/com/xly/erp/common/config/StubSecurityProperties.java
0 → 100644
| 1 | +package com.xly.erp.common.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 4 | + | ||
| 5 | +@ConfigurationProperties(prefix = "erp.security") | ||
| 6 | +public class StubSecurityProperties { | ||
| 7 | + private String stubUserNo; | ||
| 8 | + private String jwtSecret; | ||
| 9 | + | ||
| 10 | + public String getStubUserNo() { | ||
| 11 | + return stubUserNo; | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + public void setStubUserNo(String stubUserNo) { | ||
| 15 | + this.stubUserNo = stubUserNo; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public String getJwtSecret() { | ||
| 19 | + return jwtSecret; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public void setJwtSecret(String jwtSecret) { | ||
| 23 | + this.jwtSecret = jwtSecret; | ||
| 24 | + } | ||
| 25 | +} |
backend/src/main/java/com/xly/erp/common/config/TenantProperties.java
0 → 100644
| 1 | +package com.xly.erp.common.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 4 | + | ||
| 5 | +@ConfigurationProperties(prefix = "erp.tenant") | ||
| 6 | +public class TenantProperties { | ||
| 7 | + private String brandsId; | ||
| 8 | + private String subsidiaryId; | ||
| 9 | + | ||
| 10 | + public String getBrandsId() { | ||
| 11 | + return brandsId; | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + public void setBrandsId(String brandsId) { | ||
| 15 | + this.brandsId = brandsId; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public String getSubsidiaryId() { | ||
| 19 | + return subsidiaryId; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public void setSubsidiaryId(String subsidiaryId) { | ||
| 23 | + this.subsidiaryId = subsidiaryId; | ||
| 24 | + } | ||
| 25 | +} |
backend/src/main/resources/application-test.yml
0 → 100644
backend/src/main/resources/application.yml
0 → 100644
| 1 | +spring: | ||
| 2 | + application: | ||
| 3 | + name: erp-backend | ||
| 4 | + datasource: | ||
| 5 | + url: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_SCHEMA}?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true | ||
| 6 | + username: ${DB_USER} | ||
| 7 | + password: ${DB_PASSWORD} | ||
| 8 | + driver-class-name: com.mysql.cj.jdbc.Driver | ||
| 9 | + flyway: | ||
| 10 | + enabled: true | ||
| 11 | + locations: filesystem:../sql/migrations | ||
| 12 | + baseline-on-migrate: true | ||
| 13 | + | ||
| 14 | +server: | ||
| 15 | + port: 8080 | ||
| 16 | + servlet: | ||
| 17 | + context-path: / | ||
| 18 | + | ||
| 19 | +mybatis-plus: | ||
| 20 | + mapper-locations: classpath:mapper/**/*.xml | ||
| 21 | + configuration: | ||
| 22 | + map-underscore-to-camel-case: false | ||
| 23 | + | ||
| 24 | +erp: | ||
| 25 | + tenant: | ||
| 26 | + brands-id: XLY | ||
| 27 | + subsidiary-id: XLY | ||
| 28 | + security: | ||
| 29 | + stub-user-no: STUB_ADMIN | ||
| 30 | + jwt-secret: ${JWT_SECRET} | ||
| 31 | + | ||
| 32 | +logging: | ||
| 33 | + level: | ||
| 34 | + root: INFO | ||
| 35 | + com.xly.erp: DEBUG |
backend/src/main/resources/logback-spring.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<configuration> | ||
| 3 | + <include resource="org/springframework/boot/logging/logback/defaults.xml"/> | ||
| 4 | + <include resource="org/springframework/boot/logging/logback/console-appender.xml"/> | ||
| 5 | + | ||
| 6 | + <root level="INFO"> | ||
| 7 | + <appender-ref ref="CONSOLE"/> | ||
| 8 | + </root> | ||
| 9 | +</configuration> |
backend/src/test/java/com/xly/erp/SmokeTest.java
0 → 100644
| 1 | +package com.xly.erp; | ||
| 2 | + | ||
| 3 | +import org.junit.jupiter.api.Test; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 6 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 7 | +import org.springframework.test.context.ActiveProfiles; | ||
| 8 | + | ||
| 9 | +import static org.assertj.core.api.Assertions.assertThat; | ||
| 10 | + | ||
| 11 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
| 12 | +@ActiveProfiles("test") | ||
| 13 | +class SmokeTest { | ||
| 14 | + | ||
| 15 | + @Autowired | ||
| 16 | + private JdbcTemplate jdbcTemplate; | ||
| 17 | + | ||
| 18 | + @Test | ||
| 19 | + void contextLoads_andFlywayApplied() { | ||
| 20 | + Integer count = jdbcTemplate.queryForObject( | ||
| 21 | + "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'tModule'", | ||
| 22 | + Integer.class); | ||
| 23 | + assertThat(count).isEqualTo(1); | ||
| 24 | + } | ||
| 25 | +} |