fmode пре 2 недеља
родитељ
комит
0b8bdf024a
3 измењених фајлова са 280 додато и 0 уклоњено
  1. 3 0
      .vscode/settings.json
  2. 71 0
      docs/info-map.md
  3. 206 0
      docs/schema.md

+ 3 - 0
.vscode/settings.json

@@ -0,0 +1,3 @@
+{
+     "plantuml.server":"http://www.plantuml.com/plantuml"
+}

+ 71 - 0
docs/info-map.md

@@ -0,0 +1,71 @@
+# 智慧农田数据模型
+
+## _User (Parse内置类)
+- **字段**
+  - username: String
+  - password: String
+  - email: String
+  - mobilePhone: String
+  - ...其他内置字段
+
+## Farmland
+- **基础字段**
+  - objectId
+  - createdAt
+  - updatedAt
+- **业务字段**
+  - farmlandName: String
+  - area: Number
+  - cropType: String
+  - geoLocation: GeoPoint
+    - latitude
+    - longitude
+  - owner: Pointer<_User>
+  - status: String
+    - 播种期
+    - 生长期
+    - 成熟期
+  - irrigationSystem: String
+- **关系**
+  - 1 → n FarmingReminder
+  - 1 → n GrowthRecord
+
+## FarmingReminder
+- **基础字段**
+  - objectId
+  - createdAt
+  - updatedAt
+- **业务字段**
+  - reminderType: String
+    - 灌溉
+    - 施肥
+    - 除虫
+  - content: String
+  - dueDate: Date
+  - isCompleted: bool
+  - priority: Number
+- **关系**
+  - farmland: Pointer<Farmland>
+
+## GrowthRecord
+- **基础字段**
+  - objectId
+  - createdAt
+  - updatedAt
+- **业务字段**
+  - recordType: String
+    - 文字记录
+    - 图片记录
+  - description: String
+  - recordDate: Date
+  - images: Array<Parse.File>
+  - growthStage: String
+  - temperature: Number
+  - humidity: Number
+- **关系**
+  - farmland: Pointer<Farmland>
+
+## 关系图谱
+- _User 1 → n Farmland (owns)
+- Farmland 1 → n FarmingReminder (has)
+- Farmland 1 → n GrowthRecord (contains)

+ 206 - 0
docs/schema.md

@@ -0,0 +1,206 @@
+# AI智慧农业项目
+
+# 数据范式设计
+> 设定要求
+您是一名专业的数据库工程师,熟悉PostgreSQL和ParseServer。
+请注意表名用大驼峰,字段小驼峰。
+有预留字段:objectId、updatedAt、createdAt。
+关于ParseServer中数据类的描述,字段的主要类型有:
+String => String
+Number => Number
+Bool => bool
+Array => JSON Array
+Object => JSON Object
+Date => Date
+File => Parse.File
+Pointer => other Parse.Object
+Relation => Parse.Relation
+Null => null
+GeoPoint => {latitude: 40.0, longitude: -30.0}
+
+> 项目需求
+智慧农田的辅助AI应用,农民(_User)、农田、农事提醒、生长记录,请您根据农业种植的行业经验,设计以上四张表,农民直接用预留的_User表即可。
+
+> 输出结果(UML类图)
+请您帮我用plantuml的类图描述设计好的几张表及其关系
+
+> 输出结果(信息结构图)
+请您帮我用markmap格式表示上面的信息结构图
+
+> 输出结果(SQL语句)
+请您帮我用sql格式给我建表语句和测试数据插入语句,注意字段请使用小驼峰用""引起来。
+
+# UML类图
+```plantuml
+@startuml
+class _User {
+  <<Parse内置类>>
+  + username: String
+  + password: String
+  + email: String
+  + mobilePhone: String
+  + ...其他内置字段
+}
+
+class Farmland {
+  + objectId: String
+  + createdAt: Date
+  + updatedAt: Date
+  + farmlandName: String
+  + area: Number
+  + cropType: String
+  + geoLocation: {latitude: Number, longitude: Number}
+  + owner: Pointer<_User>
+  + status: String  // 如"播种期","生长期","成熟期"
+  + irrigationSystem: String
+}
+
+class FarmingReminder {
+  + objectId: String
+  + createdAt: Date
+  + updatedAt: Date
+  + reminderType: String  // 如"灌溉","施肥","除虫"
+  + content: String
+  + dueDate: Date
+  + isCompleted: bool
+  + farmland: Pointer<Farmland>
+  + priority: Number
+}
+
+class GrowthRecord {
+  + objectId: String
+  + createdAt: Date
+  + updatedAt: Date
+  + recordType: String  // 如"文字记录","图片记录"
+  + description: String
+  + recordDate: Date
+  + images: Array<Parse.File>
+  + farmland: Pointer<Farmland>
+  + growthStage: String
+  + temperature: Number
+  + humidity: Number
+}
+
+_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的命名规范完全一致。如需在其它数据库中使用,可能需要根据数据库特性调整引号的使用方式。