Commit 7b98b08b57b2e071a795a96081814ed467ca51e8
1 parent
3b22285e
chore(usr): 初始化 backend Maven 骨架与启动类
Showing
6 changed files
with
257 additions
and
0 deletions
backend/checkstyle.xml
0 → 100644
| 1 | +<?xml version="1.0"?> | ||
| 2 | +<!DOCTYPE module PUBLIC | ||
| 3 | + "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" | ||
| 4 | + "https://checkstyle.org/dtds/configuration_1_3.dtd"> | ||
| 5 | +<!-- | ||
| 6 | + 小羚羊 ERP 后端 Checkstyle 规则(轻量级)。 | ||
| 7 | + 仅做基础卫生检查:禁止 import *、禁止 tab、保留必要规约; | ||
| 8 | + 不引入会阻塞合法业务代码的严格风格规则。 | ||
| 9 | +--> | ||
| 10 | +<module name="Checker"> | ||
| 11 | + <property name="charset" value="UTF-8"/> | ||
| 12 | + <property name="severity" value="error"/> | ||
| 13 | + <property name="fileExtensions" value="java"/> | ||
| 14 | + | ||
| 15 | + <!-- 禁止行尾空白以外的硬性风格,这里只查基本项 --> | ||
| 16 | + <module name="FileTabCharacter"> | ||
| 17 | + <property name="eachLine" value="true"/> | ||
| 18 | + </module> | ||
| 19 | + | ||
| 20 | + <module name="TreeWalker"> | ||
| 21 | + <!-- 禁止通配符 import --> | ||
| 22 | + <module name="AvoidStarImport"/> | ||
| 23 | + <!-- 禁止未使用 import --> | ||
| 24 | + <module name="UnusedImports"/> | ||
| 25 | + <!-- 禁止冗余 import --> | ||
| 26 | + <module name="RedundantImport"/> | ||
| 27 | + <!-- 左大括号风格 --> | ||
| 28 | + <module name="LeftCurly"/> | ||
| 29 | + <!-- 每条语句必须有大括号 --> | ||
| 30 | + <module name="NeedBraces"/> | ||
| 31 | + </module> | ||
| 32 | +</module> |
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.2.5</version> | ||
| 11 | + <relativePath/> | ||
| 12 | + </parent> | ||
| 13 | + | ||
| 14 | + <groupId>com.xly</groupId> | ||
| 15 | + <artifactId>erp-backend</artifactId> | ||
| 16 | + <version>1.0.0</version> | ||
| 17 | + <packaging>jar</packaging> | ||
| 18 | + <name>xly-erp-backend</name> | ||
| 19 | + <description>小羚羊 ERP 后端服务</description> | ||
| 20 | + | ||
| 21 | + <properties> | ||
| 22 | + <java.version>17</java.version> | ||
| 23 | + <maven.compiler.release>17</maven.compiler.release> | ||
| 24 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 25 | + <mybatis-plus.version>3.5.7</mybatis-plus.version> | ||
| 26 | + <flyway.version>10.10.0</flyway.version> | ||
| 27 | + <jjwt.version>0.12.5</jjwt.version> | ||
| 28 | + <hutool.version>5.8.27</hutool.version> | ||
| 29 | + <checkstyle.plugin.version>3.3.1</checkstyle.plugin.version> | ||
| 30 | + </properties> | ||
| 31 | + | ||
| 32 | + <dependencies> | ||
| 33 | + <dependency> | ||
| 34 | + <groupId>org.springframework.boot</groupId> | ||
| 35 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 36 | + </dependency> | ||
| 37 | + <dependency> | ||
| 38 | + <groupId>org.springframework.boot</groupId> | ||
| 39 | + <artifactId>spring-boot-starter-validation</artifactId> | ||
| 40 | + </dependency> | ||
| 41 | + <dependency> | ||
| 42 | + <groupId>org.springframework.boot</groupId> | ||
| 43 | + <artifactId>spring-boot-starter-security</artifactId> | ||
| 44 | + </dependency> | ||
| 45 | + | ||
| 46 | + <!-- MyBatis-Plus (Spring Boot 3 starter) --> | ||
| 47 | + <dependency> | ||
| 48 | + <groupId>com.baomidou</groupId> | ||
| 49 | + <artifactId>mybatis-plus-spring-boot3-starter</artifactId> | ||
| 50 | + <version>${mybatis-plus.version}</version> | ||
| 51 | + </dependency> | ||
| 52 | + | ||
| 53 | + <!-- MySQL driver --> | ||
| 54 | + <dependency> | ||
| 55 | + <groupId>com.mysql</groupId> | ||
| 56 | + <artifactId>mysql-connector-j</artifactId> | ||
| 57 | + <scope>runtime</scope> | ||
| 58 | + </dependency> | ||
| 59 | + | ||
| 60 | + <!-- Flyway --> | ||
| 61 | + <dependency> | ||
| 62 | + <groupId>org.flywaydb</groupId> | ||
| 63 | + <artifactId>flyway-core</artifactId> | ||
| 64 | + <version>${flyway.version}</version> | ||
| 65 | + </dependency> | ||
| 66 | + <dependency> | ||
| 67 | + <groupId>org.flywaydb</groupId> | ||
| 68 | + <artifactId>flyway-mysql</artifactId> | ||
| 69 | + <version>${flyway.version}</version> | ||
| 70 | + </dependency> | ||
| 71 | + | ||
| 72 | + <!-- JWT (jjwt) --> | ||
| 73 | + <dependency> | ||
| 74 | + <groupId>io.jsonwebtoken</groupId> | ||
| 75 | + <artifactId>jjwt-api</artifactId> | ||
| 76 | + <version>${jjwt.version}</version> | ||
| 77 | + </dependency> | ||
| 78 | + <dependency> | ||
| 79 | + <groupId>io.jsonwebtoken</groupId> | ||
| 80 | + <artifactId>jjwt-impl</artifactId> | ||
| 81 | + <version>${jjwt.version}</version> | ||
| 82 | + <scope>runtime</scope> | ||
| 83 | + </dependency> | ||
| 84 | + <dependency> | ||
| 85 | + <groupId>io.jsonwebtoken</groupId> | ||
| 86 | + <artifactId>jjwt-jackson</artifactId> | ||
| 87 | + <version>${jjwt.version}</version> | ||
| 88 | + <scope>runtime</scope> | ||
| 89 | + </dependency> | ||
| 90 | + | ||
| 91 | + <!-- Hutool --> | ||
| 92 | + <dependency> | ||
| 93 | + <groupId>cn.hutool</groupId> | ||
| 94 | + <artifactId>hutool-core</artifactId> | ||
| 95 | + <version>${hutool.version}</version> | ||
| 96 | + </dependency> | ||
| 97 | + | ||
| 98 | + <!-- Test --> | ||
| 99 | + <dependency> | ||
| 100 | + <groupId>org.springframework.boot</groupId> | ||
| 101 | + <artifactId>spring-boot-starter-test</artifactId> | ||
| 102 | + <scope>test</scope> | ||
| 103 | + </dependency> | ||
| 104 | + <dependency> | ||
| 105 | + <groupId>org.springframework.security</groupId> | ||
| 106 | + <artifactId>spring-security-test</artifactId> | ||
| 107 | + <scope>test</scope> | ||
| 108 | + </dependency> | ||
| 109 | + </dependencies> | ||
| 110 | + | ||
| 111 | + <build> | ||
| 112 | + <finalName>erp-backend</finalName> | ||
| 113 | + <plugins> | ||
| 114 | + <plugin> | ||
| 115 | + <groupId>org.springframework.boot</groupId> | ||
| 116 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 117 | + </plugin> | ||
| 118 | + <plugin> | ||
| 119 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 120 | + <artifactId>maven-checkstyle-plugin</artifactId> | ||
| 121 | + <version>${checkstyle.plugin.version}</version> | ||
| 122 | + <configuration> | ||
| 123 | + <configLocation>checkstyle.xml</configLocation> | ||
| 124 | + <consoleOutput>true</consoleOutput> | ||
| 125 | + <failsOnError>true</failsOnError> | ||
| 126 | + <includeTestSourceDirectory>false</includeTestSourceDirectory> | ||
| 127 | + </configuration> | ||
| 128 | + </plugin> | ||
| 129 | + </plugins> | ||
| 130 | + </build> | ||
| 131 | +</project> |
backend/src/main/java/com/xly/erp/ErpApplication.java
0 → 100644
| 1 | +package com.xly.erp; | ||
| 2 | + | ||
| 3 | +import org.mybatis.spring.annotation.MapperScan; | ||
| 4 | +import org.springframework.boot.SpringApplication; | ||
| 5 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 小羚羊 ERP 后端启动类。 | ||
| 9 | + * | ||
| 10 | + * <p>REQ-USR-001: 项目首个后端 REQ,初始化 Maven 骨架与公共基础设施。</p> | ||
| 11 | + */ | ||
| 12 | +@SpringBootApplication | ||
| 13 | +@MapperScan("com.xly.erp.**.mapper") | ||
| 14 | +public class ErpApplication { | ||
| 15 | + | ||
| 16 | + public static void main(String[] args) { | ||
| 17 | + SpringApplication.run(ErpApplication.class, args); | ||
| 18 | + } | ||
| 19 | +} |
backend/src/main/resources/application-test.yml
0 → 100644
| 1 | +# application-test.yml — 测试 profile。 | ||
| 2 | +# 连同一测试库(xlyweberp_vibe_erp_test,由 setup-test-db.mjs DROP+CREATE 后由 Flyway apply V1)。 | ||
| 3 | +# 测试期间 Flyway 自动 apply sql/migrations/ 下的 V1+;DB 凭据沿用主配置默认(来自 config-vars.yaml)。 | ||
| 4 | +spring: | ||
| 5 | + datasource: | ||
| 6 | + driver-class-name: com.mysql.cj.jdbc.Driver | ||
| 7 | + url: jdbc:mysql://${DB_HOST:118.178.19.35}:${DB_PORT:3318}/${DB_SCHEMA:xlyweberp_vibe_erp_test}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true | ||
| 8 | + username: ${DB_USER:xlyprint} | ||
| 9 | + password: ${DB_PASSWORD:xlyXLYprint2016} | ||
| 10 | + flyway: | ||
| 11 | + enabled: true | ||
| 12 | + locations: filesystem:../sql/migrations | ||
| 13 | + baseline-on-migrate: true | ||
| 14 | + | ||
| 15 | +jwt: | ||
| 16 | + secret: ${JWT_SECRET:a3b7e8f1c4d6029e5b8f37a1c9d2e4068b5f1d3a7c0e9b2f48d6a1c5e7f9b3d2} | ||
| 17 | + expire-millis: 43200000 |
backend/src/main/resources/application.yml
0 → 100644
| 1 | +# application.yml — 小羚羊 ERP 后端主配置。 | ||
| 2 | +# 端口 / 数据源 / MyBatis-Plus / Flyway / JWT。 | ||
| 3 | +# 敏感值(DB 凭据 / JWT 密钥)通过环境变量注入,单一来源为仓库根 config-vars.yaml, | ||
| 4 | +# 由工具脚本 / 部署环境导出为下列 env,禁止硬编码进源码。 | ||
| 5 | +server: | ||
| 6 | + port: ${BACKEND_HTTP_PORT:5172} | ||
| 7 | + | ||
| 8 | +spring: | ||
| 9 | + application: | ||
| 10 | + name: xly-erp-backend | ||
| 11 | + datasource: | ||
| 12 | + driver-class-name: com.mysql.cj.jdbc.Driver | ||
| 13 | + url: jdbc:mysql://${DB_HOST:118.178.19.35}:${DB_PORT:3318}/${DB_SCHEMA:xlyweberp_vibe_erp_test}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true | ||
| 14 | + username: ${DB_USER:xlyprint} | ||
| 15 | + password: ${DB_PASSWORD:xlyXLYprint2016} | ||
| 16 | + flyway: | ||
| 17 | + enabled: true | ||
| 18 | + locations: filesystem:../sql/migrations | ||
| 19 | + baseline-on-migrate: true | ||
| 20 | + table: flyway_schema_history | ||
| 21 | + | ||
| 22 | +mybatis-plus: | ||
| 23 | + configuration: | ||
| 24 | + map-underscore-to-camel-case: false | ||
| 25 | + global-config: | ||
| 26 | + db-config: | ||
| 27 | + id-type: auto | ||
| 28 | + | ||
| 29 | +# JWT 配置:密钥单一来源 config-vars.yaml secrets.jwt_secret,通过 env 注入。 | ||
| 30 | +jwt: | ||
| 31 | + secret: ${JWT_SECRET:a3b7e8f1c4d6029e5b8f37a1c9d2e4068b5f1d3a7c0e9b2f48d6a1c5e7f9b3d2} | ||
| 32 | + # 过期时间(毫秒),默认 12 小时 | ||
| 33 | + expire-millis: ${JWT_EXPIRE_MILLIS:43200000} | ||
| 34 | + | ||
| 35 | +logging: | ||
| 36 | + level: | ||
| 37 | + com.xly.erp: INFO |
backend/src/test/java/com/xly/erp/ErpApplicationTests.java
0 → 100644
| 1 | +package com.xly.erp; | ||
| 2 | + | ||
| 3 | +import org.junit.jupiter.api.Test; | ||
| 4 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 5 | +import org.springframework.test.context.ActiveProfiles; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 骨架健康自检:证明 pom 依赖 / 启动类 / application.yml 自洽, | ||
| 9 | + * Flyway 能对测试库 apply V1,MyBatis-Plus 装配成功。 | ||
| 10 | + * | ||
| 11 | + * <p>REQ-USR-001 T1。</p> | ||
| 12 | + */ | ||
| 13 | +@SpringBootTest | ||
| 14 | +@ActiveProfiles("test") | ||
| 15 | +class ErpApplicationTests { | ||
| 16 | + | ||
| 17 | + @Test | ||
| 18 | + void contextLoads() { | ||
| 19 | + // Spring 上下文成功加载即通过。 | ||
| 20 | + } | ||
| 21 | +} |