514 lines
19 KiB
Go
514 lines
19 KiB
Go
// Package model 定义后端服务、SQLite 仓储和 Wails 前端之间共享的数据结构。
|
||
// 该包只描述数据,不包含数据库或系统命令逻辑,因此可被各层安全复用。
|
||
package model
|
||
|
||
type Project struct {
|
||
ID int64 `json:"id"`
|
||
Name string `json:"name"`
|
||
Path string `json:"path"`
|
||
Description string `json:"description"`
|
||
GroupID int64 `json:"groupId"`
|
||
GroupName string `json:"groupName"`
|
||
Icon string `json:"icon"` // 本地 dataURL,不同步
|
||
CreatedAt string `json:"createdAt"`
|
||
UpdatedAt string `json:"updatedAt"`
|
||
Stats ProjectStats `json:"stats"`
|
||
Languages []LanguageStat `json:"languages"`
|
||
}
|
||
type ProjectInput struct {
|
||
Name string `json:"name"`
|
||
Path string `json:"path"`
|
||
Description string `json:"description"`
|
||
GroupID int64 `json:"groupId"`
|
||
}
|
||
type ProjectGroup struct {
|
||
ID int64 `json:"id"`
|
||
Name string `json:"name"`
|
||
CreatedAt string `json:"createdAt"`
|
||
UpdatedAt string `json:"updatedAt"`
|
||
}
|
||
type ProjectStats struct {
|
||
TotalLines int64 `json:"totalLines"`
|
||
CodeLines int64 `json:"codeLines"`
|
||
CommentLines int64 `json:"commentLines"`
|
||
BlankLines int64 `json:"blankLines"`
|
||
FileCount int64 `json:"fileCount"`
|
||
CommitCount int64 `json:"commitCount"`
|
||
AddedLines int64 `json:"addedLines"`
|
||
DeletedLines int64 `json:"deletedLines"`
|
||
ContributorCount int64 `json:"contributorCount"`
|
||
LastAnalyzed string `json:"lastAnalyzed"`
|
||
}
|
||
type LanguageStat struct {
|
||
Name string `json:"name"`
|
||
Files int64 `json:"files"`
|
||
Code int64 `json:"code"`
|
||
Comments int64 `json:"comments"`
|
||
Blanks int64 `json:"blanks"`
|
||
}
|
||
type FileEntry struct {
|
||
Path string `json:"path"`
|
||
Name string `json:"name"`
|
||
Extension string `json:"extension"`
|
||
Size int64 `json:"size"`
|
||
IsDir bool `json:"isDir"`
|
||
Parent string `json:"parent"`
|
||
}
|
||
type StructureStats struct {
|
||
Files []FileEntry `json:"files"`
|
||
TotalFiles int64 `json:"totalFiles"`
|
||
TotalDirs int64 `json:"totalDirs"`
|
||
TotalSize int64 `json:"totalSize"`
|
||
LargeFiles []FileEntry `json:"largeFiles"`
|
||
Folders []FolderStat `json:"folders"`
|
||
Extensions []ExtensionStat `json:"extensions"`
|
||
}
|
||
type FolderStat struct {
|
||
Name string `json:"name"`
|
||
Files int64 `json:"files"`
|
||
Size int64 `json:"size"`
|
||
}
|
||
type ExtensionStat struct {
|
||
Extension string `json:"extension"`
|
||
Files int64 `json:"files"`
|
||
Size int64 `json:"size"`
|
||
}
|
||
|
||
type GitCommit struct {
|
||
Hash string `json:"hash"`
|
||
Author string `json:"author"`
|
||
Email string `json:"email"`
|
||
Message string `json:"message"`
|
||
Date string `json:"date"`
|
||
Added int64 `json:"added"`
|
||
Deleted int64 `json:"deleted"`
|
||
}
|
||
type GitRef struct {
|
||
Name string `json:"name"`
|
||
Hash string `json:"hash"`
|
||
Kind string `json:"kind"`
|
||
Current bool `json:"current"`
|
||
}
|
||
type Contributor struct {
|
||
Name string `json:"name"`
|
||
Email string `json:"email"`
|
||
Commits int64 `json:"commits"`
|
||
Added int64 `json:"added"`
|
||
Deleted int64 `json:"deleted"`
|
||
}
|
||
type HeatDay struct {
|
||
Date string `json:"date"`
|
||
Count int64 `json:"count"`
|
||
Added int64 `json:"added"`
|
||
Deleted int64 `json:"deleted"`
|
||
}
|
||
|
||
// GitFileHotspot 记录变更最频繁的文件,用于识别高风险热点。
|
||
type GitFileHotspot struct {
|
||
Path string `json:"path"`
|
||
Changes int64 `json:"changes"`
|
||
Added int64 `json:"added"`
|
||
Deleted int64 `json:"deleted"`
|
||
}
|
||
type GitStats struct {
|
||
Available bool `json:"available"`
|
||
Error string `json:"error,omitempty"`
|
||
CurrentBranch string `json:"currentBranch"`
|
||
WorkspaceBranch string `json:"workspaceBranch"`
|
||
ViewRef string `json:"viewRef"`
|
||
CommitCount int64 `json:"commitCount"`
|
||
Added int64 `json:"added"`
|
||
Deleted int64 `json:"deleted"`
|
||
ContributorCount int64 `json:"contributorCount"`
|
||
Commits []GitCommit `json:"commits"`
|
||
Refs []GitRef `json:"refs"`
|
||
Contributors []Contributor `json:"contributors"`
|
||
Heatmap []HeatDay `json:"heatmap"`
|
||
Hotspots []GitFileHotspot `json:"hotspots"`
|
||
}
|
||
type GitDiagnostics struct {
|
||
Available bool `json:"available"`
|
||
ErrorCode string `json:"errorCode,omitempty"`
|
||
Detail string `json:"detail,omitempty"`
|
||
IsWSL bool `json:"isWsl"`
|
||
Distro string `json:"distro,omitempty"`
|
||
LinuxPath string `json:"linuxPath,omitempty"`
|
||
WorkspaceBranch string `json:"workspaceBranch,omitempty"`
|
||
ViewRef string `json:"viewRef,omitempty"`
|
||
RefCount int `json:"refCount"`
|
||
}
|
||
type ProjectInsights struct {
|
||
ProjectID int64 `json:"projectId"`
|
||
HealthScore int `json:"healthScore"`
|
||
GeneratedAt string `json:"generatedAt"`
|
||
Summary InsightSummary `json:"summary"`
|
||
Issues []InsightIssue `json:"issues"`
|
||
}
|
||
type InsightSummary struct {
|
||
High int `json:"high"`
|
||
Medium int `json:"medium"`
|
||
Low int `json:"low"`
|
||
TodoCount int `json:"todoCount"`
|
||
LongFiles int `json:"longFiles"`
|
||
LargeFiles int `json:"largeFiles"`
|
||
}
|
||
type InsightIssue struct {
|
||
Severity string `json:"severity"`
|
||
Type string `json:"type"`
|
||
Title string `json:"title"`
|
||
Detail string `json:"detail"`
|
||
Path string `json:"path,omitempty"`
|
||
Line int `json:"line,omitempty"`
|
||
Suggestion string `json:"suggestion"`
|
||
Evidence string `json:"evidence,omitempty"`
|
||
}
|
||
type GitFileChange struct {
|
||
Path string `json:"path"`
|
||
Status string `json:"status"`
|
||
Added int64 `json:"added"`
|
||
Deleted int64 `json:"deleted"`
|
||
}
|
||
type GitCommitDetail struct {
|
||
GitCommit
|
||
Files []GitFileChange `json:"files"`
|
||
}
|
||
type CheckoutResult struct {
|
||
Branch string `json:"branch"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
type ExclusionRule struct {
|
||
ID int64 `json:"id"`
|
||
Pattern string `json:"pattern"`
|
||
Category string `json:"category"`
|
||
Builtin bool `json:"builtin"`
|
||
}
|
||
type LogEntry struct {
|
||
ID int64 `json:"id"`
|
||
Level string `json:"level"`
|
||
Category string `json:"category"`
|
||
Message string `json:"message"`
|
||
Detail string `json:"detail"`
|
||
CreatedAt string `json:"createdAt"`
|
||
}
|
||
type Todo struct {
|
||
ID int64 `json:"id"`
|
||
UUID string `json:"uuid"`
|
||
Title string `json:"title"`
|
||
Content string `json:"content"`
|
||
ProjectID int64 `json:"projectId"`
|
||
ProjectName string `json:"projectName"`
|
||
DueAt string `json:"dueAt"`
|
||
Priority string `json:"priority"` // low | medium | high
|
||
Status string `json:"status"` // open | doing | done
|
||
CreatedAt string `json:"createdAt"`
|
||
UpdatedAt string `json:"updatedAt"`
|
||
History string `json:"history"` // JSON 数组:[{"status","at"}],记录每次进入某状态的时间
|
||
TeamID int64 `json:"teamId"` // >0 表示已共享给该团队
|
||
}
|
||
type Ticket struct {
|
||
ID int64 `json:"id"`
|
||
UUID string `json:"uuid"`
|
||
Title string `json:"title"`
|
||
Description string `json:"description"`
|
||
Type string `json:"type"` // feature | bug | task | improvement
|
||
ProjectID int64 `json:"projectId"`
|
||
ProjectName string `json:"projectName"`
|
||
StartAt string `json:"startAt"`
|
||
DueAt string `json:"dueAt"`
|
||
Status string `json:"status"` // open | in_progress | resolved | closed
|
||
Priority string `json:"priority"` // low | medium | high
|
||
CreatedAt string `json:"createdAt"`
|
||
UpdatedAt string `json:"updatedAt"`
|
||
History string `json:"history"` // JSON 数组:[{"status","at"}],记录每次进入某状态的时间
|
||
TeamID int64 `json:"teamId"` // >0 表示已共享给该团队
|
||
}
|
||
type Note struct {
|
||
ID int64 `json:"id"`
|
||
UUID string `json:"uuid"`
|
||
Content string `json:"content"`
|
||
UpdatedAt string `json:"updatedAt"`
|
||
}
|
||
type Message struct {
|
||
ID int64 `json:"id"`
|
||
Kind string `json:"kind"` // todo_due | ticket_due | analysis | sync | system
|
||
Title string `json:"title"`
|
||
Body string `json:"body"`
|
||
SourceType string `json:"sourceType"` // todo | ticket | project | ""
|
||
SourceID int64 `json:"sourceId"`
|
||
Read bool `json:"read"`
|
||
CreatedAt string `json:"createdAt"`
|
||
}
|
||
type AppSettings struct {
|
||
Theme string `json:"theme"`
|
||
Locale string `json:"locale"`
|
||
GitScope string `json:"gitScope"`
|
||
DatabasePath string `json:"databasePath"`
|
||
AutoRefresh bool `json:"autoRefresh"`
|
||
GlassOpacity int `json:"glassOpacity"`
|
||
LoadingStyle string `json:"loadingStyle"`
|
||
// 托盘与定时更新(Phase 2)
|
||
MinimizeToTray bool `json:"minimizeToTray"`
|
||
AutoUpdateEnabled bool `json:"autoUpdateEnabled"`
|
||
AutoUpdateMode string `json:"autoUpdateMode"` // daily | everyNDays | everyNHours
|
||
AutoUpdateInterval int `json:"autoUpdateInterval"` // everyNDays/everyNHours 的 N
|
||
AutoUpdateTime string `json:"autoUpdateTime"` // daily/everyNDays 的触发时刻 HH:MM
|
||
// AI 分析(Phase 5)
|
||
AIProvider string `json:"aiProvider"` // spark | deepseek
|
||
SparkKey string `json:"sparkKey"`
|
||
DeepSeekKey string `json:"deepSeekKey"`
|
||
// SyncAPIKeys 开启后 AI API Key 会加密同步到云端(密钥由登录密码派生,服务器不可解密)。
|
||
SyncAPIKeys bool `json:"syncApiKeys"`
|
||
// 用户头像:AvatarMode 为 ""(未设置) | base64 | url | path,AvatarValue 依模式存 dataURL / 图片 URL / 本地文件路径。
|
||
AvatarMode string `json:"avatarMode"`
|
||
AvatarValue string `json:"avatarValue"`
|
||
// 内容图片存储:待办/工单 Markdown 里粘贴或插入的图片如何保存。
|
||
// base64(内嵌 dataURL,随内容同步到云端)| path(写入数据目录,仅本机可见)。
|
||
ImageMode string `json:"imageMode"`
|
||
}
|
||
|
||
// AvatarPick 是选择头像图片的结果:Value 为要保存的值,Preview 为可直接显示的图片源。
|
||
// SearchHit 全局搜索(Ctrl+K 命令面板)的一条结果。
|
||
type SearchHit struct {
|
||
Kind string `json:"kind"` // project | todo | ticket | conversation
|
||
ID int64 `json:"id"`
|
||
Title string `json:"title"`
|
||
Sub string `json:"sub"` // 路径 / 状态 / 供应商等辅助信息
|
||
Extra string `json:"extra"` // 次级状态(如优先级)
|
||
}
|
||
|
||
type AvatarPick struct {
|
||
// Mode 是选图后实际采用的存储模式(base64 | url),auto 选图时由全局配置决定。
|
||
Mode string `json:"mode"`
|
||
Value string `json:"value"`
|
||
Preview string `json:"preview"`
|
||
}
|
||
|
||
// AIConversation 是一次 AI 分析会话(可绑定项目)。
|
||
type AIConversation struct {
|
||
ID int64 `json:"id"`
|
||
ProjectID int64 `json:"projectId"`
|
||
ProjectName string `json:"projectName"`
|
||
Provider string `json:"provider"`
|
||
Title string `json:"title"`
|
||
CreatedAt string `json:"createdAt"`
|
||
UpdatedAt string `json:"updatedAt"`
|
||
}
|
||
|
||
// AIMessage 是会话中的一条消息。
|
||
type AIMessage struct {
|
||
ID int64 `json:"id"`
|
||
ConversationID int64 `json:"conversationId"`
|
||
Role string `json:"role"` // user | assistant
|
||
Content string `json:"content"`
|
||
CreatedAt string `json:"createdAt"`
|
||
}
|
||
|
||
// AISummary 是分析完成后 AI 生成的模块介绍(按项目+模块各存最新一份)。
|
||
type AISummary struct {
|
||
ProjectID int64 `json:"projectId"`
|
||
Kind string `json:"kind"` // project | git
|
||
Content string `json:"content"`
|
||
Provider string `json:"provider"`
|
||
GeneratedAt string `json:"generatedAt"`
|
||
}
|
||
type Dashboard struct {
|
||
Projects int64 `json:"projects"`
|
||
TotalLines int64 `json:"totalLines"`
|
||
CodeLines int64 `json:"codeLines"`
|
||
CommentLines int64 `json:"commentLines"`
|
||
BlankLines int64 `json:"blankLines"`
|
||
FileCount int64 `json:"fileCount"`
|
||
Commits int64 `json:"commits"`
|
||
Contributors int64 `json:"contributors"`
|
||
Languages []LanguageStat `json:"languages"`
|
||
}
|
||
|
||
// FileStorageConfig 是全局「文件存储方式」配置:由管理员(云端账号 id=1)设置,
|
||
// 云端存 sync_settings 的 file_storage 行(挂在 id=1 名下),随同步分发给所有账号。
|
||
// mode=local 时图片维持本地行为;mode=server 时内容图(imageMode=server)与
|
||
// 头像选图上传到 nl-pms-api 换取 http URL,远程/跨设备场景直接引用。
|
||
type FileStorageConfig struct {
|
||
Mode string `json:"mode"` // local | server
|
||
BaseURL string `json:"baseUrl"` // nl-pms-api 地址,如 http://192.168.1.10:8788
|
||
APIKey string `json:"apiKey"` // 已废弃;上传改用登录 JWT
|
||
}
|
||
|
||
// ServerFile 是 nl-pms-api 素材库中的一条文件记录(含上传者用户名与公开访问 URL)。
|
||
type ServerFile struct {
|
||
ID int64 `json:"id"`
|
||
Name string `json:"name"`
|
||
URL string `json:"url"`
|
||
Mime string `json:"mime"`
|
||
Size int64 `json:"size"`
|
||
UserID int64 `json:"userId"`
|
||
TeamID int64 `json:"teamId"`
|
||
Kind string `json:"kind"` // avatar | content
|
||
Username string `json:"username"`
|
||
CreatedAt string `json:"createdAt"`
|
||
}
|
||
|
||
// ServerFileList 是素材库的一页结果。
|
||
type ServerFileList struct {
|
||
Total int64 `json:"total"`
|
||
Items []ServerFile `json:"items"`
|
||
}
|
||
|
||
// SyncConfig 是 nl-pms-api 的 HTTP 基址配置(保存在本地 SQLite meta)。
|
||
type SyncConfig struct {
|
||
BaseURL string `json:"baseUrl"`
|
||
}
|
||
|
||
// SyncStatus 描述当前登录与同步状态,供设置页展示。
|
||
type SyncStatus struct {
|
||
Configured bool `json:"configured"`
|
||
LoggedIn bool `json:"loggedIn"`
|
||
// UserID 为云端账号 id;id=1 视为管理员(可配置节日背景图等全局资源)。
|
||
UserID int64 `json:"userId"`
|
||
Username string `json:"username"`
|
||
LastSyncAt string `json:"lastSyncAt"`
|
||
Syncing bool `json:"syncing"`
|
||
Online bool `json:"online"`
|
||
LastError string `json:"lastError"`
|
||
Pushed int `json:"pushed"`
|
||
Pulled int `json:"pulled"`
|
||
// Pending 为本地待推送(dirty)行数,用于界面徽标。
|
||
Pending int `json:"pending"`
|
||
}
|
||
|
||
// FestivalImage 是一个节日的背景配置:mode 决定日历格显示自定义照片还是动态插画。
|
||
// image 在 mode=art 时仍保留,方便管理员切回图片模式无需重新上传。
|
||
type FestivalImage struct {
|
||
Mode string `json:"mode"` // photo | art
|
||
Image string `json:"image"`
|
||
}
|
||
|
||
// LogPage 是日志分页搜索的结果,counts 基于当前搜索条件(忽略级别筛选)。
|
||
type LogPage struct {
|
||
Items []LogEntry `json:"items"`
|
||
Total int64 `json:"total"`
|
||
Info int64 `json:"info"`
|
||
Warning int64 `json:"warning"`
|
||
Error int64 `json:"error"`
|
||
}
|
||
|
||
// BatchSummary 是批量统计完成后的汇总事件载荷。
|
||
type BatchSummary struct {
|
||
Total int `json:"total"`
|
||
Completed int `json:"completed"`
|
||
Failed int `json:"failed"`
|
||
Cancelled int `json:"cancelled"`
|
||
Failures []string `json:"failures"`
|
||
}
|
||
|
||
// FilePreview 是文件预览接口的返回载荷。
|
||
type FilePreview struct {
|
||
Path string `json:"path"`
|
||
Name string `json:"name"`
|
||
Extension string `json:"extension"`
|
||
Size int64 `json:"size"`
|
||
Content string `json:"content"`
|
||
Lines int `json:"lines"`
|
||
Truncated bool `json:"truncated"`
|
||
Binary bool `json:"binary"`
|
||
}
|
||
|
||
// TaskEvent 只传递稳定消息键,具体中文或英文由前端根据当前语言即时翻译。
|
||
type TaskEvent struct {
|
||
TaskID string `json:"taskId"`
|
||
ProjectID int64 `json:"projectId"`
|
||
Stage string `json:"stage"`
|
||
Progress int `json:"progress"`
|
||
MessageKey string `json:"messageKey"`
|
||
Params map[string]any `json:"params,omitempty"`
|
||
}
|
||
|
||
// CloneInput 是「从 Git 克隆并添加项目」的入参。
|
||
type CloneInput struct {
|
||
URL string `json:"url"`
|
||
ParentDir string `json:"parentDir"`
|
||
Name string `json:"name"`
|
||
GroupID int64 `json:"groupId"`
|
||
Description string `json:"description"`
|
||
}
|
||
|
||
// LaunchCategory 是启动台一级分类(用户自定义,仅本地)。
|
||
type LaunchCategory struct {
|
||
ID int64 `json:"id"`
|
||
Name string `json:"name"`
|
||
Sort int `json:"sort"`
|
||
CreatedAt string `json:"createdAt"`
|
||
}
|
||
|
||
// LaunchApp 是启动台保存的应用(含启停命令)。
|
||
type LaunchApp struct {
|
||
ID int64 `json:"id"`
|
||
Name string `json:"name"`
|
||
Kind string `json:"kind"`
|
||
Port int `json:"port"`
|
||
Dir string `json:"dir"`
|
||
StartCmd string `json:"startCmd"`
|
||
StopCmd string `json:"stopCmd"`
|
||
LastPID int64 `json:"lastPid"`
|
||
Icon string `json:"icon"` // dataURL,本地抓取或用户选图
|
||
CategoryID int64 `json:"categoryId"` // 一级分类 id,0=未归类
|
||
Category string `json:"category"` // 二级分类(自由文本)
|
||
CreatedAt string `json:"createdAt"`
|
||
UpdatedAt string `json:"updatedAt"`
|
||
}
|
||
|
||
// LaunchEntry 是启动台卡片条目:保存的应用与实时扫描到的监听进程合并后的视图。
|
||
type LaunchEntry struct {
|
||
ID int64 `json:"id"` // launch_apps id;0 表示未保存的扫描条目
|
||
Name string `json:"name"`
|
||
Kind string `json:"kind"`
|
||
Port int `json:"port"`
|
||
Dir string `json:"dir"`
|
||
StartCmd string `json:"startCmd"`
|
||
StopCmd string `json:"stopCmd"`
|
||
Running bool `json:"running"`
|
||
PID int32 `json:"pid"`
|
||
Exe string `json:"exe"`
|
||
Cmdline string `json:"cmdline"`
|
||
Ports []int `json:"ports"`
|
||
CPU float64 `json:"cpu"` // 占全机 CPU 百分比
|
||
MemMB float64 `json:"memMB"` // 常驻内存
|
||
IOKBs float64 `json:"ioKBs"` // 磁盘读写吞吐
|
||
ProjectID int64 `json:"projectId"` // 若目录匹配到「我的项目」则带上
|
||
Icon string `json:"icon"` // dataURL
|
||
CategoryID int64 `json:"categoryId"` // 一级分类
|
||
Category string `json:"category"` // 二级分类
|
||
// Status: starting | running | stopped | failed(内存态,失败会标红)
|
||
Status string `json:"status"`
|
||
LastError string `json:"lastError"`
|
||
LastLog string `json:"lastLog"`
|
||
}
|
||
|
||
// LaunchLogLine 启动台本地进程日志行(不同步)。
|
||
type LaunchLogLine struct {
|
||
ID int64 `json:"id"`
|
||
AppID int64 `json:"appId"`
|
||
Level string `json:"level"`
|
||
Line string `json:"line"`
|
||
CreatedAt string `json:"createdAt"`
|
||
}
|
||
|
||
// LaunchSuggest 是按项目种类推荐的启停命令。
|
||
type LaunchSuggest struct {
|
||
Start []string `json:"start"`
|
||
Stop []string `json:"stop"`
|
||
}
|
||
|
||
// LaunchProfile 根据目录/项目探测出的启动草稿(种类、推荐命令、默认端口)。
|
||
type LaunchProfile struct {
|
||
Name string `json:"name"`
|
||
Kind string `json:"kind"`
|
||
Port int `json:"port"`
|
||
Dir string `json:"dir"`
|
||
StartCmd string `json:"startCmd"`
|
||
StopCmd string `json:"stopCmd"`
|
||
Start []string `json:"start"`
|
||
Stop []string `json:"stop"`
|
||
ProjectID int64 `json:"projectId"`
|
||
}
|