更新redis的使用和数据汇总性能优化

This commit is contained in:
2026-06-24 13:49:57 +08:00
parent 0b4860f46e
commit 4105b901f1
16 changed files with 662 additions and 119 deletions
+147 -61
View File
@@ -2,53 +2,58 @@
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
> **See also** `AGENTS.md` for module breakdown, framework choices, conventions, and gotchas. This file supplements it with build commands and architectural patterns.
> **See also** `AGENTS.md` for module breakdown, framework choices, conventions, and gotchas.
## Build & Run
---
```bash
# Full build (tests skipped by default per pom.xml <skipTests>true</skipTests>)
mvn clean install -DskipTests
## Project overview
# Build with tests
mvn clean install -DskipTests=false
**weather-data** is a full-stack meteorological data analysis platform: Java 17 / Spring Boot 3.5 multi-module backend + Vue 3 / Vite 5 / TypeScript frontend.
# Run single test class
mvn -pl system-admin -DskipTests=false -Dtest=YourTestClass test
```
**Run applications** from IntelliJ:
- **Admin backend**: `com.weather.AdminApplication` (`system-admin/`) — port 8080, context path `/system-admin`
- **API service**: `com.weather.ApiApplication` (`system-api/`) — port 8081
- **Code generator**: `com.weather.GeneratorApplication` (`renren-generator/`)
weather-data/
├── system-common/ → shared Java lib
├── system-admin/ → admin backend (port 8080, /system-admin)
├── system-api/ → external API service (port 8081)
├── system-dynamic-datasource → multi-DS support (placeholder)
├── renren-generator/ → code generator
└── weather-data-ui/ → Vue 3 SPA frontend
```
**Database**: `weather_data_system` (MySQL). Init from `system-admin/db/mysql.sql`. Default admin: `admin` / `admin`.
## Architecture
---
### Multi-module Maven project (Java 17, Spring Boot 3.5.x)
## Backend
### Build & Run
```bash
mvn clean install -DskipTests # full build (tests skipped by default)
mvn clean install -DskipTests=false # build with tests
mvn -pl system-admin -DskipTests=false -Dtest=YourTestClass test # single test
```
weather-data (pom)
├── system-common → shared lib (all modules depend on this)
├── system-admin → main admin backend
├── system-api → external API service
├── system-dynamic-datasource → multi-DS support (placeholder)
└── renren-generator → code generator
```
Launch from IntelliJ:
- `AdminApplication` (`system-admin/`) → port 8080, context `/system-admin`
- `ApiApplication` (`system-api/`) → port 8081
- `GeneratorApplication` (`renren-generator/`)
### Service layer pattern
All services extend one of two base classes from `system-common`:
- **`CrudService<Dao, Entity, DTO>`** — generic CRUD with `page()`, `get()`, `save()`, `update()`, `delete()`. The DTO type param is used for query criteria wrapping.
- **`BaseService<Dao>`** — lighter base without DTO generic.
Two base classes in `system-common`:
New modules follow this convention:
| Base | Purpose |
|---|---|
| `CrudService<Dao, Entity, DTO>` | Generic CRUD: `page()`, `get()`, `save()`, `update()`, `delete()` |
| `BaseService<Dao>` | Lighter base without DTO generic |
Module convention:
```
modules/<name>/
├── controller/ → @RestController, returns Result
├── dao/ → extends BaseMapper<Entity> (MyBatis-Plus)
├── dto/ → request/query DTOs (often extends BaseEntity for auto-fill)
├── dto/ → request/query DTOs (often extends BaseEntity)
├── entity/ → @TableName JPA entity
├── service/ → interface extends CrudService/BaseService
│ └── impl/ → @Service implementation
@@ -60,48 +65,129 @@ Mapper XMLs: `src/main/resources/mapper/<domain>/**/*.xml`
### Key cross-cutting mechanisms
| Mechanism | How it works |
| Mechanism | How |
|---|---|
| **Data permissions** | `@DataFilter` annotation on controller → `DataFilterAspect``DataFilterInterceptor` injects dept-based SQL filtering into MyBatis |
| **Auto-fill** | `FieldMetaObjectHandler` fills `creator`/`createDate`/`updater`/`updateDate` via MyBatis-Plus meta-object handler |
| **Scheduled jobs** | Quartz. Jobs in `schedule_job` table, implement `ITask`, annotated `@Component("beanName")`. `JobCommandLineRunner` auto-registers at startup |
| **File scanning** | Three-part weather module: `WatchService` (primary, `FileWatchServiceManager`) + Quartz fallback (`FileScanTask`) + startup scan (`FileScanStartupRunner`). Files served via `FileDownloadController` |
| **Excel import** | EasyExcel with async progress tracking via `WeatherDataImportManager` |
| **API responses** | Always wrapped in `Result` class (`system-common`) |
| **Validation** | Hibernate Validator on DTOs. XSS filter via `XssFilter` |
| **Data permissions** | `@DataFilter` on controller → `DataFilterAspect`MyBatis interceptor injects dept-based SQL |
| **Auto-fill** | `FieldMetaObjectHandler` fills creator/date via MyBatis-Plus |
| **Scheduled jobs** | Quartz. `schedule_job` table, implements `ITask`, `@Component("beanName")` |
| **File scanning** | `WatchService` (primary) + Quartz fallback (`FileScanTask`) + startup runner |
| **Excel import** | EasyExcel + async progress via `WeatherDataImportManager` |
| **API responses** | Always wrapped in `Result` |
| **Validation** | Hibernate Validator. XSS filter via `XssFilter` |
### PK strategy
### PK & Auth
`ASSIGN_ID` (Snowflake via `IdUtil.getSnowflakeNextId()`), set globally in MyBatis-Plus config. All entities extend `BaseEntity` which declares the `id` field.
- PK: `ASSIGN_ID` (Snowflake). All entities extend `BaseEntity`.
- Auth: Apache Shiro 1.12 (Jakarta) + OAuth2 token. Login → `token` header.
- API module: `@Login` annotation + `AuthorizationInterceptor`.
### Auth flow
### Redis & Docs
- Apache Shiro 1.12 (Jakarta classifier) with OAuth2 token auth
- Login → get token → pass `token` header on subsequent requests
- API module (`system-api`) uses `@Login` annotation + `AuthorizationInterceptor`
- Redis: optional, `project-options.redis.open` (default `false` in dev). `RedisAspect`.
- API docs: Knife4j at `/doc.html`, **disabled by default** (`knife4j.enable: false`).
### Redis
Optional, controlled by `project-options.redis.open` (default `false` in dev). Cache aspect: `RedisAspect`.
### API docs
Knife4j (Swagger UI) at `/doc.html`. **Disabled by default** (`knife4j.enable: false`). Enable only in dev profile.
## Custom Weather Domain
### Weather domain (backend)
Three sub-modules under `system-admin/.../modules/weather/`:
| Sub-module | Purpose | Key detail |
|---|---|---|
| `dailydata/` | Daily weather observations | Excel batch import (async), EasyExcel listener pattern |
| `station/` | Weather station CRUD | Linked to dept via `dept_id`, data-permission aware |
| `filescan/` | File monitoring & serving | WatchService → record → serve via `FileDownloadController` |
| Module | Purpose |
|---|---|
| `dailydata/` | Daily observations, Excel batch import (async), EasyExcel listener |
| `station/` | Weather station CRUD, linked to dept via `dept_id` |
| `filescan/` | File monitoring + serving. Format: `<地区>地区-<指标>.png` / `<地区>地区631信息.txt` |
File format convention (from `需求文档.md`): `<地区>地区-<指标>.png` for charts, `<地区>地区631信息.txt` for text data. `FileNameParser` extracts region/indicator keywords.
Parameter `scan_root_path` in `sys_params` controls file-scan base directory.
## Database
---
Custom tables: `weather_daily_data`, `weather_station`, `weather_file_scan_record`.
Seed scripts in `system-admin/db/` (mysql.sql + Oracle/SQLServer/PostgreSQL/Dameng variants).
Parameter `scan_root_path` in `sys_params` controls the file-scan base directory.
## Frontend (`weather-data-ui/`)
### Commands
```bash
npm install # install dependencies
npm run dev # Vite dev server
npm run build / npm run build:prod # production build
npm run serve # preview production build
npm run lint # lint with autofix
npx vue-tsc --noEmit # type-check
```
### Stack
- Vite 5 + Vue 3 + TypeScript SPA
- Element Plus + Element Plus Icons for UI
- `vue-router` with hash history
- Pinia for state management
- Axios via `src/utils/http.ts` + `src/service/baseService.ts`
- API base URL: `VITE_APP_API` env var, overridable at runtime by `window.SITE_CONFIG.apiURL`
### Routing & state
- `src/router/base.ts`: base routes (`/`, `/home`, `/login`, etc.)
- `src/router/index.ts`: `beforeEach` guard — auth check, dynamic route registration from backend menus, tab management
- `src/store/index.ts` (`useAppStore`): user, permissions, dicts, dynamic routes, tabs
- `src/store/importTasks.ts`: long-running import task state for header indicator
- `src/utils/router.ts`: converts backend menu records → Vue router records, flattens nested routes for keep-alive
Layout is event-driven: `src/layout/` shell + `mitt` event bus (`src/utils/emits.ts`). Trace both the Pinia store and `mitt` events when changing navigation/sidebar/tabs/theme.
### Weather frontend module
The home dashboard (`src/views/home.vue`) uses a **composable-based architecture**. All domain logic is extracted from the SFC into `src/composables/`:
| Composable | Responsibility |
|---|---|
| `useWeatherConstants.ts` | Rain levels, temperature thresholds, filter field definitions, `fmtVal()`, level/class helpers |
| `useWeatherFilter.ts` | Filter state, toggle/reset/match logic, `matchOp()` |
| `useWeatherStats.ts` | `computeStats()`, `buildStatCards()`, `buildSummary()`, `rainLevelDistribution`, `WeatherDataRow` type |
| `useWeatherChart.ts` | ECharts dynamic import, `buildChartOption()`, `ResizeObserver`, precise trigger key (not deep watch) |
| `useWeatherExport.ts` | PNG/PDF export with dynamic `html2canvas`/`jspdf` imports, loading indicator |
Supporting utils:
- `src/utils/chartBuilder.ts` — chart option builders
- `src/utils/exportReport.ts` — shared `exportPNG()`/`exportPDF()`
### Critical rules learned (must follow)
#### 1. Null ≠ zero — missing data MUST be preserved as null
When mapping backend API responses to frontend models, **never** default missing numeric values to `0`. Rainfall of `0mm` means "no rain that day" (valid measurement); `null` means "no data available" (missing record). Use `: null` not `: 0` in data mapping, and display `"—"` for null values via `fmtVal()`.
```typescript
// ✅ Correct
rainfall: row.rain2020 != null ? +row.rain2020 : null,
// ❌ Wrong — confuses "no data" with "measured zero"
rainfall: row.rain2020 != null ? +row.rain2020 : 0,
```
All helper functions (`rainLevelLabel`, `tmaxValClass`, `tminValClass`, `rainValClass`) must accept `number | null` and return `"—"` or `""` for null. Stats computations (`computeStats`, `fStats`, `filterExtremes`) must skip null values in sums and extreme comparisons. ECharts will naturally render null as gaps in line/bar series.
#### 2. Heavy libraries must use dynamic imports
`html2canvas`, `jspdf`, and `echarts` are NOT imported at module level. They are loaded via `await import()` only when the user triggers export or chart rendering. This keeps them out of the initial bundle (~600KB saved).
#### 3. Google Fonts go in index.html, not scoped styles
Never use `@import url("https://fonts.googleapis.com/...")` inside Vue scoped styles — it blocks rendering. Instead, add `<link rel="preconnect">` + `<link rel="stylesheet">` in `index.html`.
#### 4. Export must show user feedback
When exporting images/PDFs, always show a loading indicator (`ElLoading.service` fullscreen) and a success/failure message (`ElMessage`). Disable the export button during rendering to prevent double-clicks.
#### 5. Deep watchers on filter objects are banned
Never use `watch(filters, callback, { deep: true })`. Instead, derive a precise computed trigger key that only includes fields actually affecting the output (e.g., `dataHash`, `filteredHash`, `extremesVersion`) and watch that.
### Common page pattern
Admin CRUD pages use `src/hooks/useView.ts` for shared list-page workflow: query, paging, sorting, delete, export, permission checks, dictionary lookup. Check whether behavior comes from `useView` before refactoring these screens.
### Other conventions
- Reusable selector/tree controls: `src/components/sys-*`, registered globally in `main.ts`
- SVG icons: `vite-plugin-svg-icons` from `src/assets/icons/svg/`
- Tests: no test runner configured yet
---
## Repository notes
- `README.md` does not contain substantive guidance; operational context lives in this file and `AGENTS.md`.
- `weather-data-ui/CLAUDE.md` is superseded by this merged file — the root `CLAUDE.md` covers both frontend and backend.