Files
booschat/internal/services/conversation_assignment_service.go
T
Aibo117 0f40930a41 refactor: rebrand from cs-agent to BossChat
- Rename Go module: cs-agent → bosschat
- Rename all import paths across 200+ Go files
- Rename SDK: cs-ai-agent-sdk → bosschat-sdk
- Rename message protocol: cs-agent:* → bosschat:*
- Rename JS globals: CSAgentConfig → BossChatConfig
- Rename CSS classes: cs-agent-* → bosschat-*
- Update Makefile APP_NAME and ARCHIVE_NAME
- Update logo assets
- Fix display name: BoosChat → BossChat
2026-05-26 13:17:07 +08:00

76 lines
2.8 KiB
Go

package services
import (
"bosschat/internal/models"
"bosschat/internal/pkg/dto"
"bosschat/internal/pkg/enums"
"bosschat/internal/repositories"
"strings"
"time"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web/params"
)
var ConversationAssignmentService = newConversationAssignmentService()
func newConversationAssignmentService() *conversationAssignmentService {
return &conversationAssignmentService{}
}
type conversationAssignmentService struct {
}
func (s *conversationAssignmentService) Get(id int64) *models.ConversationAssignment {
return repositories.ConversationAssignmentRepository.Get(sqls.DB(), id)
}
func (s *conversationAssignmentService) Take(where ...interface{}) *models.ConversationAssignment {
return repositories.ConversationAssignmentRepository.Take(sqls.DB(), where...)
}
func (s *conversationAssignmentService) Find(cnd *sqls.Cnd) []models.ConversationAssignment {
return repositories.ConversationAssignmentRepository.Find(sqls.DB(), cnd)
}
func (s *conversationAssignmentService) FindOne(cnd *sqls.Cnd) *models.ConversationAssignment {
return repositories.ConversationAssignmentRepository.FindOne(sqls.DB(), cnd)
}
func (s *conversationAssignmentService) FindPageByParams(params *params.QueryParams) (list []models.ConversationAssignment, paging *sqls.Paging) {
return repositories.ConversationAssignmentRepository.FindPageByParams(sqls.DB(), params)
}
func (s *conversationAssignmentService) FindPageByCnd(cnd *sqls.Cnd) (list []models.ConversationAssignment, paging *sqls.Paging) {
return repositories.ConversationAssignmentRepository.FindPageByCnd(sqls.DB(), cnd)
}
func (s *conversationAssignmentService) Count(cnd *sqls.Cnd) int64 {
return repositories.ConversationAssignmentRepository.Count(sqls.DB(), cnd)
}
func (s *conversationAssignmentService) FinishActiveAssignments(ctx *sqls.TxContext, conversationID int64, finishedAt time.Time) error {
return ctx.Tx.Model(&models.ConversationAssignment{}).
Where("conversation_id = ? AND status = ?", conversationID, enums.IMAssignmentStatusActive).
Updates(map[string]any{
"status": enums.IMAssignmentStatusInactive,
"finished_at": finishedAt,
}).Error
}
func (s *conversationAssignmentService) CreateAssignment(ctx *sqls.TxContext, conversationID, fromUserID, toUserID int64, assignType enums.IMAssignmentType, reason string, operator *dto.AuthPrincipal, now time.Time) error {
assignment := &models.ConversationAssignment{
ConversationID: conversationID,
FromUserID: fromUserID,
ToUserID: toUserID,
AssignType: strings.TrimSpace(string(assignType)),
Reason: strings.TrimSpace(reason),
Status: enums.IMAssignmentStatusActive,
CreatedAt: now,
}
if operator != nil {
assignment.OperatorID = operator.UserID
}
return ctx.Tx.Create(assignment).Error
}