|
@@ -34,173 +34,54 @@ GeoPoint => {latitude: 40.0, longitude: -30.0}
|
|
|
```plantuml
|
|
|
@startuml
|
|
|
class _User {
|
|
|
- <<Parse内置类>>
|
|
|
+ + objectId: String [PK]
|
|
|
+ username: String
|
|
|
- + password: String
|
|
|
- + email: String
|
|
|
- + mobilePhone: String
|
|
|
- + ...其他内置字段
|
|
|
+ + phone: String
|
|
|
+ + farmLevel: Number
|
|
|
+ + createdAt: Date
|
|
|
+ + updatedAt: Date
|
|
|
}
|
|
|
|
|
|
class Farmland {
|
|
|
- + objectId: String
|
|
|
- + createdAt: Date
|
|
|
- + updatedAt: Date
|
|
|
- + farmlandName: String
|
|
|
+ + objectId: String [PK]
|
|
|
+ + farmName: String
|
|
|
+ area: Number
|
|
|
- + cropType: String
|
|
|
- + geoLocation: {latitude: Number, longitude: Number}
|
|
|
+ + soilType: String
|
|
|
+ + location: GeoPoint
|
|
|
+ + currentCrop: Pointer<Crop>
|
|
|
+ owner: Pointer<_User>
|
|
|
- + status: String // 如"播种期","生长期","成熟期"
|
|
|
- + irrigationSystem: String
|
|
|
+ + createdAt: Date
|
|
|
+ + updatedAt: Date
|
|
|
}
|
|
|
|
|
|
class FarmingReminder {
|
|
|
- + objectId: String
|
|
|
- + createdAt: Date
|
|
|
- + updatedAt: Date
|
|
|
- + reminderType: String // 如"灌溉","施肥","除虫"
|
|
|
- + content: String
|
|
|
+ + objectId: String [PK]
|
|
|
+ + reminderType: String
|
|
|
+ dueDate: Date
|
|
|
+ isCompleted: bool
|
|
|
+ farmland: Pointer<Farmland>
|
|
|
- + priority: Number
|
|
|
+ + createdBy: Pointer<_User>
|
|
|
+ + details: Object
|
|
|
+ + createdAt: Date
|
|
|
+ + updatedAt: Date
|
|
|
}
|
|
|
|
|
|
class GrowthRecord {
|
|
|
- + objectId: String
|
|
|
- + createdAt: Date
|
|
|
- + updatedAt: Date
|
|
|
- + recordType: String // 如"文字记录","图片记录"
|
|
|
- + description: String
|
|
|
+ + objectId: String [PK]
|
|
|
+ recordDate: Date
|
|
|
- + images: Array<Parse.File>
|
|
|
- + farmland: Pointer<Farmland>
|
|
|
+ growthStage: String
|
|
|
- + temperature: Number
|
|
|
- + humidity: Number
|
|
|
+ + healthStatus: String
|
|
|
+ + images: Array<File>
|
|
|
+ + farmland: Pointer<Farmland>
|
|
|
+ + notes: String
|
|
|
+ + weatherData: Object
|
|
|
+ + createdAt: Date
|
|
|
+ + updatedAt: Date
|
|
|
}
|
|
|
|
|
|
+' 关系定义
|
|
|
_User "1" -- "n" Farmland : owns
|
|
|
Farmland "1" -- "n" FarmingReminder : has
|
|
|
Farmland "1" -- "n" GrowthRecord : contains
|
|
|
@enduml
|
|
|
-```
|
|
|
-
|
|
|
-# SQL语句
|
|
|
-
|
|
|
-以下是使用小驼峰命名并用双引号包裹字段名的PostgreSQL建表语句和测试数据插入语句:
|
|
|
-
|
|
|
-### 1. 建表语句
|
|
|
-
|
|
|
-```sql
|
|
|
--- 用户表(使用Parse内置的_User表,此处仅创建扩展表)
|
|
|
-CREATE TABLE "User" (
|
|
|
- "objectId" VARCHAR(36) PRIMARY KEY,
|
|
|
- "username" VARCHAR(50) NOT NULL UNIQUE,
|
|
|
- "email" VARCHAR(100),
|
|
|
- "mobilePhone" VARCHAR(20),
|
|
|
- "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
- "updatedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
|
-);
|
|
|
-
|
|
|
--- 农田表
|
|
|
-CREATE TABLE "Farmland" (
|
|
|
- "objectId" VARCHAR(36) PRIMARY KEY,
|
|
|
- "farmlandName" VARCHAR(100) NOT NULL,
|
|
|
- "area" NUMERIC(10, 2),
|
|
|
- "cropType" VARCHAR(50),
|
|
|
- "latitude" NUMERIC(9, 6),
|
|
|
- "longitude" NUMERIC(9, 6),
|
|
|
- "ownerId" VARCHAR(36) REFERENCES "User"("objectId"),
|
|
|
- "status" VARCHAR(20) CHECK ("status" IN ('播种期', '生长期', '成熟期')),
|
|
|
- "irrigationSystem" VARCHAR(50),
|
|
|
- "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
- "updatedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
|
-);
|
|
|
-
|
|
|
--- 农事提醒表
|
|
|
-CREATE TABLE "FarmingReminder" (
|
|
|
- "objectId" VARCHAR(36) PRIMARY KEY,
|
|
|
- "reminderType" VARCHAR(20) CHECK ("reminderType" IN ('灌溉', '施肥', '除虫')),
|
|
|
- "content" TEXT,
|
|
|
- "dueDate" TIMESTAMP NOT NULL,
|
|
|
- "isCompleted" BOOLEAN DEFAULT false,
|
|
|
- "farmlandId" VARCHAR(36) REFERENCES "Farmland"("objectId"),
|
|
|
- "priority" INTEGER DEFAULT 1,
|
|
|
- "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
- "updatedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
|
-);
|
|
|
-
|
|
|
--- 生长记录表
|
|
|
-CREATE TABLE "GrowthRecord" (
|
|
|
- "objectId" VARCHAR(36) PRIMARY KEY,
|
|
|
- "recordType" VARCHAR(20) CHECK ("recordType" IN ('文字记录', '图片记录')),
|
|
|
- "description" TEXT,
|
|
|
- "recordDate" TIMESTAMP NOT NULL,
|
|
|
- "growthStage" VARCHAR(50),
|
|
|
- "temperature" NUMERIC(5, 2),
|
|
|
- "humidity" NUMERIC(5, 2),
|
|
|
- "farmlandId" VARCHAR(36) REFERENCES "Farmland"("objectId"),
|
|
|
- "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
- "updatedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
|
-);
|
|
|
-
|
|
|
--- 图片存储关联表
|
|
|
-CREATE TABLE "GrowthRecordImages" (
|
|
|
- "recordId" VARCHAR(36) REFERENCES "GrowthRecord"("objectId"),
|
|
|
- "fileUrl" VARCHAR(255) NOT NULL,
|
|
|
- "uploadTime" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
- PRIMARY KEY ("recordId", "fileUrl")
|
|
|
-);
|
|
|
-```
|
|
|
-
|
|
|
-### 2. 测试数据插入语句
|
|
|
-
|
|
|
-```sql
|
|
|
--- 插入测试用户
|
|
|
-INSERT INTO "User" ("objectId", "username", "email", "mobilePhone") VALUES
|
|
|
-('usr001', 'farmer_wang', 'wang@example.com', '13800138001'),
|
|
|
-('usr002', 'farmer_li', 'li@example.com', '13900139001');
|
|
|
-
|
|
|
--- 插入测试农田
|
|
|
-INSERT INTO "Farmland" ("objectId", "farmlandName", "area", "cropType", "latitude", "longitude", "ownerId", "status", "irrigationSystem") VALUES
|
|
|
-('fld001', '王家的麦田', 5.2, '小麦', 39.9042, 116.4074, 'usr001', '生长期', '滴灌系统'),
|
|
|
-('fld002', '李家的玉米地', 8.5, '玉米', 34.3416, 108.9398, 'usr002', '播种期', '喷灌系统');
|
|
|
-
|
|
|
--- 插入农事提醒
|
|
|
-INSERT INTO "FarmingReminder" ("objectId", "reminderType", "content", "dueDate", "isCompleted", "farmlandId", "priority") VALUES
|
|
|
-('rem001', '灌溉', '麦田需要浇水', CURRENT_TIMESTAMP + INTERVAL '2 days', false, 'fld001', 1),
|
|
|
-('rem002', '施肥', '玉米地需要追肥', CURRENT_TIMESTAMP + INTERVAL '5 days', false, 'fld002', 2);
|
|
|
-
|
|
|
--- 插入生长记录
|
|
|
-INSERT INTO "GrowthRecord" ("objectId", "recordType", "description", "recordDate", "growthStage", "temperature", "humidity", "farmlandId") VALUES
|
|
|
-('rec001', '文字记录', '小麦抽穗期开始', CURRENT_TIMESTAMP - INTERVAL '3 days', '抽穗期', 22.5, 65.0, 'fld001'),
|
|
|
-('rec002', '图片记录', '玉米幼苗生长情况', CURRENT_TIMESTAMP - INTERVAL '1 day', '幼苗期', 25.0, 70.0, 'fld002');
|
|
|
-
|
|
|
--- 插入生长记录图片
|
|
|
-INSERT INTO "GrowthRecordImages" ("recordId", "fileUrl") VALUES
|
|
|
-('rec002', 'https://example.com/images/corn_seedling_1.jpg'),
|
|
|
-('rec002', 'https://example.com/images/corn_seedling_2.jpg');
|
|
|
-```
|
|
|
-
|
|
|
-### 修改说明:
|
|
|
-
|
|
|
-1. **命名规范**:
|
|
|
- - 所有字段名使用小驼峰命名并用双引号包裹
|
|
|
- - 表名使用大驼峰命名并用双引号包裹
|
|
|
- - 保留Parse Server原始字段名(如objectId/createdAt/updatedAt)
|
|
|
-
|
|
|
-2. **修正问题**:
|
|
|
- - 修正了农事提醒表中的字段名拼写错误(reminderType)
|
|
|
- - 确保所有引用字段名都使用小驼峰格式
|
|
|
-
|
|
|
-3. **兼容性**:
|
|
|
- - 完全兼容PostgreSQL的标识符引用规则
|
|
|
- - 保留所有原始设计的约束和关系
|
|
|
-
|
|
|
-4. **测试数据**:
|
|
|
- - 保持与之前相同的测试场景
|
|
|
- - 所有字段引用都使用新的命名格式
|
|
|
-
|
|
|
-这种格式可以直接在PostgreSQL中执行,且与Parse Server的命名规范完全一致。如需在其它数据库中使用,可能需要根据数据库特性调整引号的使用方式。
|
|
|
+```
|