refactor: 将客服后端重构为宿主可嵌入模块
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
This commit is contained in:
@@ -24,17 +24,6 @@ func (r *agentRunRepository) Get(db *gorm.DB, id int64) *models.AgentRun {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) TakeByWorkflowRunID(db *gorm.DB, workflowRunID int64) *models.AgentRun {
|
||||
if workflowRunID <= 0 {
|
||||
return nil
|
||||
}
|
||||
ret := &models.AgentRun{}
|
||||
if err := db.Where("workflow_run_id = ?", workflowRunID).Order("id DESC").First(ret).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) Create(db *gorm.DB, item *models.AgentRun) error {
|
||||
return db.Create(item).Error
|
||||
}
|
||||
@@ -66,3 +55,17 @@ func (r *agentRunRepository) FindRecent(db *gorm.DB, aiAgentID int64, limit int)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (r *agentRunRepository) FindRecentByConversationID(db *gorm.DB, conversationID int64, limit int) []models.AgentRun {
|
||||
if conversationID <= 0 {
|
||||
return nil
|
||||
}
|
||||
if limit <= 0 || limit > 20 {
|
||||
limit = 6
|
||||
}
|
||||
var items []models.AgentRun
|
||||
if err := db.Where("conversation_id = ?", conversationID).Order("id DESC").Limit(limit).Find(&items).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -32,3 +34,24 @@ func (r *agentToolInvocationRepository) Create(db *gorm.DB, item *models.AgentTo
|
||||
func (r *agentToolInvocationRepository) Updates(db *gorm.DB, id int64, values map[string]any) error {
|
||||
return db.Model(&models.AgentToolInvocation{}).Where("id = ?", id).Updates(values).Error
|
||||
}
|
||||
|
||||
func (r *agentToolInvocationRepository) TransitionStatus(db *gorm.DB, id int64, fromStatus string, values map[string]any) (bool, error) {
|
||||
result := db.Model(&models.AgentToolInvocation{}).
|
||||
Where("id = ? AND status = ?", id, fromStatus).
|
||||
Updates(values)
|
||||
return result.RowsAffected == 1, result.Error
|
||||
}
|
||||
|
||||
func (r *agentToolInvocationRepository) TransitionLease(db *gorm.DB, id int64, leaseToken string, values map[string]any) (bool, error) {
|
||||
result := db.Model(&models.AgentToolInvocation{}).
|
||||
Where("id = ? AND status = ? AND result_data = ?", id, "running", leaseToken).
|
||||
Updates(values)
|
||||
return result.RowsAffected == 1, result.Error
|
||||
}
|
||||
|
||||
func (r *agentToolInvocationRepository) RecoverStaleRunning(db *gorm.DB, id int64, staleBefore time.Time, values map[string]any) (bool, error) {
|
||||
result := db.Model(&models.AgentToolInvocation{}).
|
||||
Where("id = ? AND status = ? AND updated_at < ?", id, "running", staleBefore).
|
||||
Updates(values)
|
||||
return result.RowsAffected == 1, result.Error
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AIAgentWorkflowBindingRepository = newAIAgentWorkflowBindingRepository()
|
||||
|
||||
func newAIAgentWorkflowBindingRepository() *aiAgentWorkflowBindingRepository {
|
||||
return &aiAgentWorkflowBindingRepository{}
|
||||
}
|
||||
|
||||
type aiAgentWorkflowBindingRepository struct{}
|
||||
|
||||
func (r *aiAgentWorkflowBindingRepository) FindByAgentID(db *gorm.DB, agentID int64) []models.AIAgentWorkflowBinding {
|
||||
ret := make([]models.AIAgentWorkflowBinding, 0)
|
||||
if agentID > 0 {
|
||||
db.Where("ai_agent_id = ?", agentID).Order("priority ASC, id ASC").Find(&ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiAgentWorkflowBindingRepository) FindEnabledByAgentID(db *gorm.DB, agentID int64) []models.AIAgentWorkflowBinding {
|
||||
ret := make([]models.AIAgentWorkflowBinding, 0)
|
||||
if agentID > 0 {
|
||||
db.Where("ai_agent_id = ? AND enabled = ?", agentID, true).Order("priority ASC, id ASC").Find(&ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiAgentWorkflowBindingRepository) FindByWorkflowID(db *gorm.DB, workflowID int64) []models.AIAgentWorkflowBinding {
|
||||
ret := make([]models.AIAgentWorkflowBinding, 0)
|
||||
if workflowID > 0 {
|
||||
db.Where("workflow_id = ?", workflowID).Order("priority ASC, id ASC").Find(&ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiAgentWorkflowBindingRepository) CountByWorkflowID(db *gorm.DB, workflowID int64) int64 {
|
||||
var count int64
|
||||
if workflowID > 0 {
|
||||
db.Model(&models.AIAgentWorkflowBinding{}).Where("workflow_id = ?", workflowID).Count(&count)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (r *aiAgentWorkflowBindingRepository) ReplaceByAgentID(db *gorm.DB, agentID int64, items []models.AIAgentWorkflowBinding) error {
|
||||
if err := db.Where("ai_agent_id = ?", agentID).Delete(&models.AIAgentWorkflowBinding{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
return db.Create(&items).Error
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AIWorkflowNodeRunRepository = newAIWorkflowNodeRunRepository()
|
||||
|
||||
func newAIWorkflowNodeRunRepository() *aiWorkflowNodeRunRepository {
|
||||
return &aiWorkflowNodeRunRepository{}
|
||||
}
|
||||
|
||||
type aiWorkflowNodeRunRepository struct{}
|
||||
|
||||
func (r *aiWorkflowNodeRunRepository) Get(db *gorm.DB, id int64) *models.AIWorkflowNodeRun {
|
||||
ret := &models.AIWorkflowNodeRun{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiWorkflowNodeRunRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIWorkflowNodeRun) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *aiWorkflowNodeRunRepository) Create(db *gorm.DB, t *models.AIWorkflowNodeRun) error {
|
||||
return db.Create(t).Error
|
||||
}
|
||||
|
||||
func (r *aiWorkflowNodeRunRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) error {
|
||||
return db.Model(&models.AIWorkflowNodeRun{}).Where("id = ?", id).Updates(columns).Error
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AIWorkflowRepository = newAIWorkflowRepository()
|
||||
|
||||
func newAIWorkflowRepository() *aiWorkflowRepository {
|
||||
return &aiWorkflowRepository{}
|
||||
}
|
||||
|
||||
type aiWorkflowRepository struct{}
|
||||
|
||||
func (r *aiWorkflowRepository) Get(db *gorm.DB, id int64) *models.AIWorkflow {
|
||||
ret := &models.AIWorkflow{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRepository) Take(db *gorm.DB, where ...interface{}) *models.AIWorkflow {
|
||||
ret := &models.AIWorkflow{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIWorkflow) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AIWorkflow, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIWorkflow, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.AIWorkflow{})
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRepository) Create(db *gorm.DB, t *models.AIWorkflow) error {
|
||||
return db.Create(t).Error
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) error {
|
||||
return db.Model(&models.AIWorkflow{}).Where("id = ?", id).Updates(columns).Error
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AIWorkflowRunRepository = newAIWorkflowRunRepository()
|
||||
|
||||
func newAIWorkflowRunRepository() *aiWorkflowRunRepository {
|
||||
return &aiWorkflowRunRepository{}
|
||||
}
|
||||
|
||||
type aiWorkflowRunRepository struct{}
|
||||
|
||||
func (r *aiWorkflowRunRepository) Get(db *gorm.DB, id int64) *models.AIWorkflowRun {
|
||||
ret := &models.AIWorkflowRun{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRunRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIWorkflowRun) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRunRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AIWorkflowRun, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRunRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIWorkflowRun, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.AIWorkflowRun{})
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRunRepository) Create(db *gorm.DB, t *models.AIWorkflowRun) error {
|
||||
return db.Create(t).Error
|
||||
}
|
||||
|
||||
func (r *aiWorkflowRunRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) error {
|
||||
return db.Model(&models.AIWorkflowRun{}).Where("id = ?", id).Updates(columns).Error
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var AIWorkflowVersionRepository = newAIWorkflowVersionRepository()
|
||||
|
||||
func newAIWorkflowVersionRepository() *aiWorkflowVersionRepository {
|
||||
return &aiWorkflowVersionRepository{}
|
||||
}
|
||||
|
||||
type aiWorkflowVersionRepository struct{}
|
||||
|
||||
func (r *aiWorkflowVersionRepository) Get(db *gorm.DB, id int64) *models.AIWorkflowVersion {
|
||||
ret := &models.AIWorkflowVersion{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *aiWorkflowVersionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIWorkflowVersion) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *aiWorkflowVersionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.AIWorkflowVersion, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *aiWorkflowVersionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.AIWorkflowVersion, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.AIWorkflowVersion{})
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *aiWorkflowVersionRepository) Create(db *gorm.DB, t *models.AIWorkflowVersion) error {
|
||||
return db.Create(t).Error
|
||||
}
|
||||
|
||||
func (r *aiWorkflowVersionRepository) MaxVersionByWorkflowID(db *gorm.DB, workflowID int64) int {
|
||||
var maxVersion int
|
||||
db.Model(&models.AIWorkflowVersion{}).
|
||||
Where("workflow_id = ?", workflowID).
|
||||
Select("COALESCE(MAX(version), 0)").
|
||||
Scan(&maxVersion)
|
||||
return maxVersion
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var CompanyRepository = newCompanyRepository()
|
||||
|
||||
func newCompanyRepository() *companyRepository {
|
||||
return &companyRepository{}
|
||||
}
|
||||
|
||||
type companyRepository struct {
|
||||
}
|
||||
|
||||
func (r *companyRepository) GetByName(db *gorm.DB, name string) *models.Company {
|
||||
ret := &models.Company{}
|
||||
if err := db.First(ret, "name = ?", name).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *companyRepository) Get(db *gorm.DB, id int64) *models.Company {
|
||||
ret := &models.Company{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *companyRepository) Take(db *gorm.DB, where ...interface{}) *models.Company {
|
||||
ret := &models.Company{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *companyRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Company) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Company {
|
||||
ret := &models.Company{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *companyRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Company, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *companyRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Company, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.Company{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Company) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.Company{})
|
||||
}
|
||||
|
||||
func (r *companyRepository) Create(db *gorm.DB, t *models.Company) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) Update(db *gorm.DB, t *models.Company) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.Company{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.Company{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *companyRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.Company{}, "id = ?", id)
|
||||
}
|
||||
@@ -87,8 +87,6 @@ func (r *conversationInterruptRepository) UpsertByCheckPointID(db *gorm.DB, item
|
||||
"agent_step_id": item.AgentStepID,
|
||||
"source_message_id": item.SourceMessageID,
|
||||
"last_resume_message_id": item.LastResumeMessageID,
|
||||
"workflow_run_id": item.WorkflowRunID,
|
||||
"workflow_node_id": item.WorkflowNodeID,
|
||||
"interrupt_id": item.InterruptID,
|
||||
"interrupt_type": item.InterruptType,
|
||||
"status": item.Status,
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var ConversationTagRepository = newConversationTagRepository()
|
||||
|
||||
func newConversationTagRepository() *conversationTagRepository {
|
||||
return &conversationTagRepository{}
|
||||
}
|
||||
|
||||
type conversationTagRepository struct {
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Get(db *gorm.DB, id int64) *models.ConversationTag {
|
||||
ret := &models.ConversationTag{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Take(db *gorm.DB, where ...interface{}) *models.ConversationTag {
|
||||
ret := &models.ConversationTag{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationTag) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.ConversationTag {
|
||||
ret := &models.ConversationTag{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.ConversationTag, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.ConversationTag, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.ConversationTag{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.ConversationTag) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.ConversationTag{})
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Create(db *gorm.DB, t *models.ConversationTag) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Update(db *gorm.DB, t *models.ConversationTag) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.ConversationTag{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.ConversationTag{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *conversationTagRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.ConversationTag{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var CustomerContactRepository = newCustomerContactRepository()
|
||||
|
||||
func newCustomerContactRepository() *customerContactRepository {
|
||||
return &customerContactRepository{}
|
||||
}
|
||||
|
||||
type customerContactRepository struct {
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Get(db *gorm.DB, id int64) *models.CustomerContact {
|
||||
ret := &models.CustomerContact{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Take(db *gorm.DB, where ...interface{}) *models.CustomerContact {
|
||||
ret := &models.CustomerContact{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerContact) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.CustomerContact {
|
||||
ret := &models.CustomerContact{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.CustomerContact, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerContact, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.CustomerContact{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.CustomerContact) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.CustomerContact{})
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Create(db *gorm.DB, t *models.CustomerContact) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Update(db *gorm.DB, t *models.CustomerContact) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.CustomerContact{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.CustomerContact{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerContactRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.CustomerContact{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var CustomerIdentityRepository = newCustomerIdentityRepository()
|
||||
|
||||
func newCustomerIdentityRepository() *customerIdentityRepository {
|
||||
return &customerIdentityRepository{}
|
||||
}
|
||||
|
||||
type customerIdentityRepository struct {
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Get(db *gorm.DB, id int64) *models.CustomerIdentity {
|
||||
ret := &models.CustomerIdentity{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Take(db *gorm.DB, where ...interface{}) *models.CustomerIdentity {
|
||||
ret := &models.CustomerIdentity{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetBy 按外部来源 + 外部用户标识查询身份映射(与 uk_customer_external 一致)。
|
||||
func (r *customerIdentityRepository) GetBy(db *gorm.DB, externalSource enums.ExternalSource, externalID string) *models.CustomerIdentity {
|
||||
if strs.IsAnyBlank(string(externalSource), externalID) {
|
||||
return nil
|
||||
}
|
||||
return r.FindOne(db, sqls.NewCnd().
|
||||
Eq("external_source", externalSource).
|
||||
Eq("external_id", externalID))
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) FindByCustomerID(db *gorm.DB, customerID int64) []models.CustomerIdentity {
|
||||
if customerID <= 0 {
|
||||
return nil
|
||||
}
|
||||
return r.Find(db, sqls.NewCnd().Eq("customer_id", customerID).Eq("status", enums.StatusOk).Desc("id"))
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerIdentity) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.CustomerIdentity {
|
||||
ret := &models.CustomerIdentity{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.CustomerIdentity, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.CustomerIdentity, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.CustomerIdentity{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.CustomerIdentity) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.CustomerIdentity{})
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Create(db *gorm.DB, t *models.CustomerIdentity) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Update(db *gorm.DB, t *models.CustomerIdentity) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.CustomerIdentity{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.CustomerIdentity{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerIdentityRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.CustomerIdentity{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var CustomerRepository = newCustomerRepository()
|
||||
|
||||
func newCustomerRepository() *customerRepository {
|
||||
return &customerRepository{}
|
||||
}
|
||||
|
||||
type customerRepository struct {
|
||||
}
|
||||
|
||||
type CompanyCustomerCount struct {
|
||||
CompanyID int64 `gorm:"column:company_id"`
|
||||
Count int64 `gorm:"column:cnt"`
|
||||
}
|
||||
|
||||
func (r *customerRepository) CountByCompanyIDs(db *gorm.DB, companyIDs []int64, excludeStatus int) map[int64]int64 {
|
||||
ret := make(map[int64]int64)
|
||||
if len(companyIDs) == 0 {
|
||||
return ret
|
||||
}
|
||||
|
||||
rows := make([]CompanyCustomerCount, 0, len(companyIDs))
|
||||
db.Model(&models.Customer{}).
|
||||
Select("company_id, count(1) as cnt").
|
||||
Where("company_id in ?", companyIDs).
|
||||
Where("status <> ?", excludeStatus).
|
||||
Group("company_id").
|
||||
Scan(&rows)
|
||||
|
||||
for _, row := range rows {
|
||||
ret[row.CompanyID] = row.Count
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerRepository) Get(db *gorm.DB, id int64) *models.Customer {
|
||||
ret := &models.Customer{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerRepository) Take(db *gorm.DB, where ...interface{}) *models.Customer {
|
||||
ret := &models.Customer{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Customer) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Customer {
|
||||
ret := &models.Customer{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *customerRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Customer, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *customerRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Customer, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.Customer{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Customer) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.Customer{})
|
||||
}
|
||||
|
||||
func (r *customerRepository) Create(db *gorm.DB, t *models.Customer) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) Update(db *gorm.DB, t *models.Customer) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.Customer{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.Customer{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *customerRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.Customer{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var MigrationRepository = newMigrationRepository()
|
||||
|
||||
func newMigrationRepository() *migrationRepository {
|
||||
return &migrationRepository{}
|
||||
}
|
||||
|
||||
type migrationRepository struct {
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Get(db *gorm.DB, id int64) *models.Migration {
|
||||
ret := &models.Migration{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Take(db *gorm.DB, where ...interface{}) *models.Migration {
|
||||
ret := &models.Migration{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Migration) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Migration {
|
||||
ret := &models.Migration{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *migrationRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Migration, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *migrationRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Migration, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.Migration{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Migration) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.Migration{})
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Create(db *gorm.DB, t *models.Migration) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Update(db *gorm.DB, t *models.Migration) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.Migration{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.Migration{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *migrationRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.Migration{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var SkillDefinitionRepository = newSkillDefinitionRepository()
|
||||
|
||||
func newSkillDefinitionRepository() *skillDefinitionRepository {
|
||||
return &skillDefinitionRepository{}
|
||||
}
|
||||
|
||||
type skillDefinitionRepository struct {
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Get(db *gorm.DB, id int64) *models.SkillDefinition {
|
||||
ret := &models.SkillDefinition{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Take(db *gorm.DB, where ...interface{}) *models.SkillDefinition {
|
||||
ret := &models.SkillDefinition{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.SkillDefinition) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.SkillDefinition {
|
||||
ret := &models.SkillDefinition{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.SkillDefinition, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.SkillDefinition, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.SkillDefinition{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.SkillDefinition) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.SkillDefinition{})
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Create(db *gorm.DB, t *models.SkillDefinition) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Update(db *gorm.DB, t *models.SkillDefinition) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.SkillDefinition{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.SkillDefinition{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.SkillDefinition{}, "id = ?", id)
|
||||
}
|
||||
|
||||
func (r *skillDefinitionRepository) GetByIDs(db *gorm.DB, ids []int64) map[int64]models.SkillDefinition {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
list := r.Find(db, sqls.NewCnd().Where("id IN (?)", ids))
|
||||
if len(list) == 0 {
|
||||
return nil
|
||||
}
|
||||
result := make(map[int64]models.SkillDefinition, len(list))
|
||||
for _, item := range list {
|
||||
result[item.ID] = item
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var SystemConfigRepository = newSystemConfigRepository()
|
||||
|
||||
func newSystemConfigRepository() *systemConfigRepository {
|
||||
return &systemConfigRepository{}
|
||||
}
|
||||
|
||||
type systemConfigRepository struct {
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Get(db *gorm.DB, id int64) *models.SystemConfig {
|
||||
ret := &models.SystemConfig{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Take(db *gorm.DB, where ...interface{}) *models.SystemConfig {
|
||||
ret := &models.SystemConfig{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.SystemConfig) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.SystemConfig {
|
||||
ret := &models.SystemConfig{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.SystemConfig, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.SystemConfig, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.SystemConfig{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.SystemConfig) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.SystemConfig{})
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Create(db *gorm.DB, t *models.SystemConfig) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Update(db *gorm.DB, t *models.SystemConfig) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.SystemConfig{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.SystemConfig{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *systemConfigRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.SystemConfig{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var TagRepository = newTagRepository()
|
||||
|
||||
func newTagRepository() *tagRepository {
|
||||
return &tagRepository{}
|
||||
}
|
||||
|
||||
type tagRepository struct {
|
||||
}
|
||||
|
||||
func (r *tagRepository) Get(db *gorm.DB, id int64) *models.Tag {
|
||||
ret := &models.Tag{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *tagRepository) Take(db *gorm.DB, where ...interface{}) *models.Tag {
|
||||
ret := &models.Tag{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *tagRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Tag) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Tag {
|
||||
ret := &models.Tag{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *tagRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Tag, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *tagRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Tag, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.Tag{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Tag) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.Tag{})
|
||||
}
|
||||
|
||||
func (r *tagRepository) Create(db *gorm.DB, t *models.Tag) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) Update(db *gorm.DB, t *models.Tag) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.Tag{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.Tag{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *tagRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.Tag{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
var TicketNoSequenceRepository = newTicketNoSequenceRepository()
|
||||
|
||||
func newTicketNoSequenceRepository() *ticketNoSequenceRepository {
|
||||
return &ticketNoSequenceRepository{}
|
||||
}
|
||||
|
||||
type ticketNoSequenceRepository struct{}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Get(db *gorm.DB, id int64) *models.TicketNoSequence {
|
||||
ret := &models.TicketNoSequence{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Take(db *gorm.DB, where ...any) *models.TicketNoSequence {
|
||||
ret := &models.TicketNoSequence{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketNoSequence) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketNoSequence {
|
||||
ret := &models.TicketNoSequence{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketNoSequence, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketNoSequence, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.TicketNoSequence{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.TicketNoSequence{})
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) GetByDateKey(db *gorm.DB, dateKey string) *models.TicketNoSequence {
|
||||
ret := &models.TicketNoSequence{}
|
||||
if err := db.Take(ret, "date_key = ?", dateKey).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) GetByDateKeyForUpdate(db *gorm.DB, dateKey string) (*models.TicketNoSequence, error) {
|
||||
ret := &models.TicketNoSequence{}
|
||||
err := db.Clauses(clause.Locking{Strength: "UPDATE"}).Take(ret, "date_key = ?", dateKey).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Create(db *gorm.DB, t *models.TicketNoSequence) error {
|
||||
return db.Create(t).Error
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Update(db *gorm.DB, t *models.TicketNoSequence) error {
|
||||
return db.Save(t).Error
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
|
||||
return db.Model(&models.TicketNoSequence{}).Where("id = ?", id).Updates(columns).Error
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) UpdateColumn(db *gorm.DB, id int64, name string, value any) error {
|
||||
return db.Model(&models.TicketNoSequence{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.TicketNoSequence{}, "id = ?", id)
|
||||
}
|
||||
|
||||
func (r *ticketNoSequenceRepository) UpdateNextSeq(db *gorm.DB, id int64, currentSeq, nextSeq int64, updatedAt time.Time) (bool, error) {
|
||||
result := db.Model(&models.TicketNoSequence{}).
|
||||
Where("id = ? AND next_seq = ?", id, currentSeq).
|
||||
Updates(map[string]any{
|
||||
"next_seq": nextSeq,
|
||||
"updated_at": updatedAt,
|
||||
})
|
||||
return result.RowsAffected == 1, result.Error
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var TicketProgressRepository = newTicketProgressRepository()
|
||||
|
||||
func newTicketProgressRepository() *ticketProgressRepository {
|
||||
return &ticketProgressRepository{}
|
||||
}
|
||||
|
||||
type ticketProgressRepository struct {
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Get(db *gorm.DB, id int64) *models.TicketProgress {
|
||||
ret := &models.TicketProgress{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Take(db *gorm.DB, where ...any) *models.TicketProgress {
|
||||
ret := &models.TicketProgress{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketProgress) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketProgress {
|
||||
ret := &models.TicketProgress{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketProgress, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketProgress, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.TicketProgress{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...any) (list []models.TicketProgress) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...any) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.TicketProgress{})
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Create(db *gorm.DB, t *models.TicketProgress) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Update(db *gorm.DB, t *models.TicketProgress) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Updates(db *gorm.DB, id int64, columns map[string]any) (err error) {
|
||||
err = db.Model(&models.TicketProgress{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) UpdateColumn(db *gorm.DB, id int64, name string, value any) (err error) {
|
||||
err = db.Model(&models.TicketProgress{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketProgressRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.TicketProgress{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var TicketRepository = newTicketRepository()
|
||||
|
||||
func newTicketRepository() *ticketRepository {
|
||||
return &ticketRepository{}
|
||||
}
|
||||
|
||||
type ticketRepository struct {
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Get(db *gorm.DB, id int64) *models.Ticket {
|
||||
ret := &models.Ticket{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Take(db *gorm.DB, where ...interface{}) *models.Ticket {
|
||||
ret := &models.Ticket{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Ticket) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.Ticket {
|
||||
ret := &models.Ticket{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Ticket, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *ticketRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Ticket, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.Ticket{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) FindBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (list []models.Ticket) {
|
||||
db.Raw(sqlStr, paramArr...).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) CountBySql(db *gorm.DB, sqlStr string, paramArr ...interface{}) (count int64) {
|
||||
db.Raw(sqlStr, paramArr...).Count(&count)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.Ticket{})
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Create(db *gorm.DB, t *models.Ticket) (err error) {
|
||||
err = db.Create(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Update(db *gorm.DB, t *models.Ticket) (err error) {
|
||||
err = db.Save(t).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Updates(db *gorm.DB, id int64, columns map[string]interface{}) (err error) {
|
||||
err = db.Model(&models.Ticket{}).Where("id = ?", id).Updates(columns).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) UpdateColumn(db *gorm.DB, id int64, name string, value interface{}) (err error) {
|
||||
err = db.Model(&models.Ticket{}).Where("id = ?", id).UpdateColumn(name, value).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketRepository) Delete(db *gorm.DB, id int64) {
|
||||
db.Delete(&models.Ticket{}, "id = ?", id)
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var TicketTagRepository = newTicketTagRepository()
|
||||
|
||||
func newTicketTagRepository() *ticketTagRepository {
|
||||
return &ticketTagRepository{}
|
||||
}
|
||||
|
||||
type ticketTagRepository struct{}
|
||||
|
||||
func (r *ticketTagRepository) Get(db *gorm.DB, id int64) *models.TicketTag {
|
||||
ret := &models.TicketTag{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) Take(db *gorm.DB, where ...interface{}) *models.TicketTag {
|
||||
ret := &models.TicketTag{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketTag) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketTag {
|
||||
ret := &models.TicketTag{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketTag, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketTag, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.TicketTag{})
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.TicketTag{})
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) Create(db *gorm.DB, t *models.TicketTag) error {
|
||||
return db.Create(t).Error
|
||||
}
|
||||
|
||||
func (r *ticketTagRepository) DeleteByTicketID(db *gorm.DB, ticketID int64) error {
|
||||
return db.Where("ticket_id = ?", ticketID).Delete(&models.TicketTag{}).Error
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var TicketViewRepository = newTicketViewRepository()
|
||||
|
||||
func newTicketViewRepository() *ticketViewRepository {
|
||||
return &ticketViewRepository{}
|
||||
}
|
||||
|
||||
type ticketViewRepository struct {
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Get(db *gorm.DB, id int64) *models.TicketView {
|
||||
ret := &models.TicketView{}
|
||||
if err := db.First(ret, "id = ?", id).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Take(db *gorm.DB, where ...any) *models.TicketView {
|
||||
ret := &models.TicketView{}
|
||||
if err := db.Take(ret, where...).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketView) {
|
||||
cnd.Find(db, &list)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) FindOne(db *gorm.DB, cnd *sqls.Cnd) *models.TicketView {
|
||||
ret := &models.TicketView{}
|
||||
if err := cnd.FindOne(db, &ret); err != nil {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.TicketView, paging *sqls.Paging) {
|
||||
return r.FindPageByCnd(db, ¶ms.Cnd)
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.TicketView, paging *sqls.Paging) {
|
||||
cnd.Find(db, &list)
|
||||
count := cnd.Count(db, &models.TicketView{})
|
||||
|
||||
paging = &sqls.Paging{
|
||||
Page: cnd.Paging.Page,
|
||||
Limit: cnd.Paging.Limit,
|
||||
Total: count,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
|
||||
return cnd.Count(db, &models.TicketView{})
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Create(db *gorm.DB, t *models.TicketView) error {
|
||||
return db.Create(t).Error
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Update(db *gorm.DB, t *models.TicketView) error {
|
||||
return db.Save(t).Error
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
|
||||
return db.Model(&models.TicketView{}).Where("id = ?", id).Updates(columns).Error
|
||||
}
|
||||
|
||||
func (r *ticketViewRepository) Delete(db *gorm.DB, id int64) error {
|
||||
return db.Delete(&models.TicketView{}, "id = ?", id).Error
|
||||
}
|
||||
Reference in New Issue
Block a user