diff --git a/src/service/project.ts b/src/service/project.ts index 8ec2ae1..8e4b888 100644 --- a/src/service/project.ts +++ b/src/service/project.ts @@ -5,19 +5,21 @@ const TABLE = 'project' export const projectTableSql = `CREATE TABLE IF NOT EXISTS project ( id INTEGER PRIMARY KEY AUTOINCREMENT, project_name TEXT NOT NULL, - project_type TEXT, - status TEXT DEFAULT 'offline', + stake_range TEXT, + total_area REAL, + status INTEGER DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP )` export interface Project { - id?: number - project_name: string - project_type?: string - status?: string - created_at?: string - updated_at?: string + id?: number // 主键,自增 + project_name: string // 项目名称,必填 + stake_range: string // 项目范围,可选 + total_area: number // 项目总面积,可选 + status: 0 | 1 // 项目状态,0:未完成,1:已完成,默认0 + created_at?: string // 创建时间,默认当前时间 + updated_at?: string // 更新时间,默认当前时间 } /** 查询全部项目 */ @@ -30,19 +32,19 @@ export async function selectById(id: number): Promise { return DB.selectById(TABLE, id) } -/** 按状态查询 */ -export async function selectByStatus(status: string): Promise { +/** 按状态查询(0=进行中, 1=结束) */ +export async function selectByStatus(status: 0 | 1): Promise { return DB.selectByField(TABLE, 'status', status) } /** 新增项目 */ -export async function insert(data: Project): Promise { +export async function insert(data: Omit): Promise { return DB.insert(TABLE, data) } /** 更新项目 */ export async function update(id: number, data: Partial): Promise { - return DB.update(TABLE, data, `id = ${id}`) + return DB.update(TABLE, { ...data, updated_at: new Date().toISOString() }, `id = ${id}`) } /** 删除项目 */