| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package model
-
- import (
- "time"
-
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
-
- // SessionStatus 会话状态枚举
- const (
- StatusRequirementDocument = "requirement_document" // 需求文档
- StatusTechnicalDocument = "technical_document" // 技术文档
- StatusCode = "code" // 代码
- StatusTest = "test" // 测试
- StatusRelease = "release" // 发布
- )
-
- // IsValidStatus 验证状态是否有效
- func IsValidStatus(status string) bool {
- validStatuses := []string{
- StatusRequirementDocument,
- StatusTechnicalDocument,
- StatusCode,
- StatusTest,
- StatusRelease,
- }
- for _, s := range validStatuses {
- if s == status {
- return true
- }
- }
- return false
- }
-
- // Agent 智能体枚举
- const (
- AgentReplenish = "replenish" // 补货
- AgentTransfer = "transfer" // 调拨
- AgentAllocation = "allocation" // 配货
- AgentReport = "report" // 报表
- )
-
- // AgentDisplayName 智能体显示名称映射
- var AgentDisplayName = map[string]string{
- AgentReplenish: "补货",
- AgentTransfer: "调拨",
- AgentAllocation: "配货",
- AgentReport: "报表",
- }
-
- // GetAllAgents 获取所有智能体列表
- func GetAllAgents() []map[string]string {
- agents := []map[string]string{}
- for id, name := range AgentDisplayName {
- agents = append(agents, map[string]string{
- "id": id,
- "name": name,
- })
- }
- return agents
- }
-
- // IsValidAgent 验证智能体名称是否有效
- func IsValidAgent(agentName string) bool {
- _, exists := AgentDisplayName[agentName]
- return exists
- }
-
- // Session 主会话文档
- type Session struct {
- ID string `bson:"_id" json:"id"` // opencode会话ID,作为主键
- ProjectID string `bson:"project_id" json:"project_id"` // 项目ID(新增)
- Title string `bson:"title" json:"title"` // 标题
- AgentName string `bson:"agent_name" json:"agent_name"` // 智能体名称
- Description string `bson:"description" json:"description"` // 项目描述(新增)
- Status string `bson:"status" json:"status"` // 状态
- UserID string `bson:"user_id" json:"user_id"` // 用户ID
- TenantID string `bson:"tenant_id" json:"tenant_id"` // 租户ID
- CreatedAt time.Time `bson:"created_at" json:"created_at"` // 创建时间
- UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` // 更新时间
- }
-
- // CodeItem 代码项
- type CodeItem struct {
- Order int `bson:"order" json:"order"` // 执行次序
- Title string `bson:"title" json:"title"` // 步骤标题(新增)
- SelectPart string `bson:"select_part" json:"select_part"` // select 部分SQL代码
- FromPart string `bson:"from_part" json:"from_part"` // from 部分代码
- WherePart string `bson:"where_part" json:"where_part"` // where 部分
- GroupByPart string `bson:"group_by_part" json:"group_by_part"` // group by 部分
- OrderByPart string `bson:"order_by_part" json:"order_by_part"` // order by 部分
- TempTableName string `bson:"temp_table_name" json:"temp_table_name"` // 临时表名称
- Parameters map[string]interface{} `bson:"parameters" json:"parameters"` // 参数集合
- ReturnColumns map[string]string `bson:"return_columns" json:"return_columns"` // 返回的列名称和对应的中文名称(映射)
- }
-
- // SessionDetail 明细文档
- type SessionDetail struct {
- ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // MongoDB自动生成的ID
- SessionID string `bson:"session_id" json:"session_id"` // 关联的会话ID
- RequirementDoc string `bson:"requirement_doc" json:"requirement_doc"` // 需求文档
- TechnicalDoc string `bson:"technical_doc" json:"technical_doc"` // 技术文档
- CodeItems []CodeItem `bson:"code_items" json:"code_items"` // 代码数组
- HistorySessions []string `bson:"history_sessions" json:"history_sessions"` // 历史会话ID数组(新增)
- CreatedAt time.Time `bson:"created_at" json:"created_at"` // 创建时间
- UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` // 更新时间
- }
-
- // SessionWithDetail 包含主会话和明细的完整响应
- type SessionWithDetail struct {
- Session *Session `json:"session"`
- Detail *SessionDetail `json:"detail,omitempty"`
- HistoryCount int `json:"history_count,omitempty"` // 历史消息数量
- }
-
- // SessionCollectionName 返回会话集合名称
- func (Session) CollectionName() string {
- return "code_sessions"
- }
-
- // SessionDetailCollectionName 返回会话明细集合名称
- func (SessionDetail) CollectionName() string {
- return "code_session_details"
- }
|