feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package entity
import (
"github.com/coze-dev/coze-studio/backend/api/model/intelligence/common"
publishAPI "github.com/coze-dev/coze-studio/backend/api/model/publish"
resourceCommon "github.com/coze-dev/coze-studio/backend/api/model/resource/common"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
)
type APP struct {
ID int64
SpaceID int64
IconURI *string
Name *string
Desc *string
OwnerID int64
ConnectorIDs []int64
Version *string
VersionDesc *string
PublishRecordID *int64
PublishStatus *PublishStatus
PublishExtraInfo *PublishRecordExtraInfo
CreatedAtMS int64
UpdatedAtMS int64
PublishedAtMS *int64
}
func (a APP) Published() bool {
return a.PublishStatus != nil && *a.PublishStatus == PublishStatusOfPublishDone
}
func (a APP) GetPublishedAtMS() int64 {
return ptr.FromOrDefault(a.PublishedAtMS, 0)
}
func (a APP) GetVersion() string {
return ptr.FromOrDefault(a.Version, "")
}
func (a APP) GetName() string {
return ptr.FromOrDefault(a.Name, "")
}
func (a APP) GetDesc() string {
return ptr.FromOrDefault(a.Desc, "")
}
func (a APP) GetVersionDesc() string {
return ptr.FromOrDefault(a.VersionDesc, "")
}
func (a APP) GetIconURI() string {
return ptr.FromOrDefault(a.IconURI, "")
}
func (a APP) GetPublishStatus() PublishStatus {
return ptr.FromOrDefault(a.PublishStatus, 0)
}
func (a APP) GetPublishRecordID() int64 {
return ptr.FromOrDefault(a.PublishRecordID, 0)
}
type PublishRecord struct {
APP *APP
ConnectorPublishRecords []*ConnectorPublishRecord
}
type PublishRecordExtraInfo struct {
PackFailedInfo []*PackResourceFailedInfo `json:"pack_failed_info,omitempty"`
}
func (p *PublishRecordExtraInfo) ToVO() *publishAPI.PublishRecordStatusDetail {
if p == nil || len(p.PackFailedInfo) == 0 {
return &publishAPI.PublishRecordStatusDetail{}
}
packFailedDetail := make([]*publishAPI.PackFailedDetail, 0, len(p.PackFailedInfo))
for _, info := range p.PackFailedInfo {
packFailedDetail = append(packFailedDetail, &publishAPI.PackFailedDetail{
EntityID: info.ResID,
EntityType: common.ResourceType(info.ResType),
EntityName: info.ResName,
})
}
return &publishAPI.PublishRecordStatusDetail{
PackFailedDetail: packFailedDetail,
}
}
type PackResourceFailedInfo struct {
ResID int64 `json:"res_id"`
ResType resourceCommon.ResType `json:"res_type"`
ResName string `json:"res_name"`
}
type ResourceCopyResult struct {
ResID int64 `json:"res_id"`
ResType ResourceType `json:"res_type"`
ResName string `json:"res_name"`
CopyStatus ResourceCopyStatus `json:"copy_status"`
CopyScene resourceCommon.ResourceCopyScene `json:"copy_scene"`
FailedReason string `json:"reason"`
}
type Resource struct {
ResID int64
ResType ResourceType
ResName string
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package entity
import (
publishAPI "github.com/coze-dev/coze-studio/backend/api/model/publish"
"github.com/coze-dev/coze-studio/backend/types/consts"
)
var ConnectorIDWhiteList = []int64{
consts.APIConnectorID,
}
type ConnectorPublishRecord struct {
ConnectorID int64 `json:"connector_id"`
PublishStatus ConnectorPublishStatus `json:"publish_status"`
PublishConfig PublishConfig `json:"publish_config"`
}
type PublishConfig struct {
SelectedWorkflows []*SelectedWorkflow `json:"selected_workflows,omitempty"`
}
func (p *PublishConfig) ToVO() *publishAPI.ConnectorPublishConfig {
config := &publishAPI.ConnectorPublishConfig{
SelectedWorkflows: make([]*publishAPI.SelectedWorkflow, 0, len(p.SelectedWorkflows)),
}
if p == nil {
return config
}
for _, w := range p.SelectedWorkflows {
config.SelectedWorkflows = append(config.SelectedWorkflows, &publishAPI.SelectedWorkflow{
WorkflowID: w.WorkflowID,
WorkflowName: w.WorkflowName,
})
}
return config
}
type SelectedWorkflow struct {
WorkflowID int64 `json:"workflow_id"`
WorkflowName string `json:"workflow_name"`
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package entity
type PublishStatus int
const (
PublishStatusOfPacking PublishStatus = 0
PublishStatusOfPackFailed PublishStatus = 1
PublishStatusOfAuditing PublishStatus = 2
PublishStatusOfAuditNotPass PublishStatus = 3
PublishStatusOfConnectorPublishing PublishStatus = 4
PublishStatusOfPublishDone PublishStatus = 5
)
type ConnectorPublishStatus int
const (
ConnectorPublishStatusOfDefault ConnectorPublishStatus = 0
ConnectorPublishStatusOfAuditing ConnectorPublishStatus = 1
ConnectorPublishStatusOfSuccess ConnectorPublishStatus = 2
ConnectorPublishStatusOfFailed ConnectorPublishStatus = 3
ConnectorPublishStatusOfDisable ConnectorPublishStatus = 4
)
type ResourceType string
const (
ResourceTypeOfPlugin ResourceType = "plugin"
ResourceTypeOfWorkflow ResourceType = "workflow"
ResourceTypeOfKnowledge ResourceType = "knowledge"
ResourceTypeOfDatabase ResourceType = "database"
)
type ResourceCopyStatus int
const (
ResourceCopyStatusOfSuccess ResourceCopyStatus = 1
ResourceCopyStatusOfProcessing ResourceCopyStatus = 2
ResourceCopyStatusOfFailed ResourceCopyStatus = 3
)

View File

@@ -0,0 +1,137 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
)
func NewAPPConnectorReleaseRefDAO(db *gorm.DB, idGen idgen.IDGenerator) *APPConnectorReleaseRefDAO {
return &APPConnectorReleaseRefDAO{
idGen: idGen,
query: query.Use(db),
}
}
type APPConnectorReleaseRefDAO struct {
idGen idgen.IDGenerator
query *query.Query
}
type appConnectorReleaseRefPO model.AppConnectorReleaseRef
func (a appConnectorReleaseRefPO) ToDO() *entity.ConnectorPublishRecord {
return &entity.ConnectorPublishRecord{
ConnectorID: a.ConnectorID,
PublishStatus: entity.ConnectorPublishStatus(a.PublishStatus),
PublishConfig: a.PublishConfig,
}
}
func (c *APPConnectorReleaseRefDAO) MGetConnectorPublishRecords(ctx context.Context, recordID int64, connectorIDs []int64) ([]*entity.ConnectorPublishRecord, error) {
table := c.query.AppConnectorReleaseRef
res, err := table.WithContext(ctx).
Where(
table.RecordID.Eq(recordID),
table.ConnectorID.In(connectorIDs...),
).
Find()
if err != nil {
return nil, err
}
publishInfo := make([]*entity.ConnectorPublishRecord, 0, len(res))
for _, r := range res {
publishInfo = append(publishInfo, appConnectorReleaseRefPO(*r).ToDO())
}
return publishInfo, nil
}
func (c *APPConnectorReleaseRefDAO) GetAllConnectorPublishRecords(ctx context.Context, recordID int64) ([]*entity.ConnectorPublishRecord, error) {
table := c.query.AppConnectorReleaseRef
res, err := table.WithContext(ctx).
Where(table.RecordID.Eq(recordID)).
Find()
if err != nil {
return nil, err
}
records := make([]*entity.ConnectorPublishRecord, 0, len(res))
for _, r := range res {
records = append(records, appConnectorReleaseRefPO(*r).ToDO())
}
return records, nil
}
func (c *APPConnectorReleaseRefDAO) GetAllConnectorRecords(ctx context.Context, recordID int64) ([]*entity.ConnectorPublishRecord, error) {
table := c.query.AppConnectorReleaseRef
res, err := table.WithContext(ctx).
Where(table.RecordID.Eq(recordID)).
Find()
if err != nil {
return nil, err
}
publishInfo := make([]*entity.ConnectorPublishRecord, 0, len(res))
for _, r := range res {
publishInfo = append(publishInfo, appConnectorReleaseRefPO(*r).ToDO())
}
return publishInfo, nil
}
func (c *APPConnectorReleaseRefDAO) UpdatePublishStatus(ctx context.Context, recordID int64, status entity.ConnectorPublishStatus) error {
table := c.query.AppConnectorReleaseRef
_, err := table.WithContext(ctx).
Where(table.RecordID.Eq(recordID)).
Update(table.PublishStatus, int32(status))
if err != nil {
return err
}
return nil
}
func (c *APPConnectorReleaseRefDAO) BatchCreateWithTX(ctx context.Context, tx *query.QueryTx, recordID int64, publishRecords []*entity.ConnectorPublishRecord) error {
records := make([]*model.AppConnectorReleaseRef, 0, len(publishRecords))
for _, r := range publishRecords {
id, err := c.idGen.GenID(ctx)
if err != nil {
return err
}
records = append(records, &model.AppConnectorReleaseRef{
ID: id,
RecordID: recordID,
ConnectorID: r.ConnectorID,
PublishConfig: r.PublishConfig,
PublishStatus: int32(r.PublishStatus),
})
}
return tx.AppConnectorReleaseRef.WithContext(ctx).Create(records...)
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"errors"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
)
func NewAPPDraftDAO(db *gorm.DB, idGen idgen.IDGenerator) *APPDraftDAO {
return &APPDraftDAO{
idGen: idGen,
query: query.Use(db),
}
}
type APPDraftDAO struct {
idGen idgen.IDGenerator
query *query.Query
}
type appDraftPO model.AppDraft
func (a appDraftPO) ToDO() *entity.APP {
return &entity.APP{
ID: a.ID,
SpaceID: a.SpaceID,
IconURI: &a.IconURI,
Name: &a.Name,
Desc: &a.Description,
OwnerID: a.OwnerID,
CreatedAtMS: a.CreatedAt,
UpdatedAtMS: a.UpdatedAt,
}
}
func (a *APPDraftDAO) Create(ctx context.Context, app *entity.APP) (appID int64, err error) {
appID, err = a.idGen.GenID(ctx)
if err != nil {
return 0, err
}
m := &model.AppDraft{
ID: appID,
SpaceID: app.SpaceID,
OwnerID: app.OwnerID,
IconURI: app.GetIconURI(),
Name: app.GetName(),
Description: app.GetDesc(),
}
err = a.query.AppDraft.WithContext(ctx).Create(m)
if err != nil {
return 0, err
}
return appID, nil
}
func (a *APPDraftDAO) Get(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error) {
table := a.query.AppDraft
res, err := table.WithContext(ctx).
Where(table.ID.Eq(appID)).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = appDraftPO(*res).ToDO()
return app, true, nil
}
func (a *APPDraftDAO) CheckExist(ctx context.Context, appID int64) (exist bool, err error) {
table := a.query.AppDraft
_, err = table.WithContext(ctx).
Where(table.ID.Eq(appID)).
Select(table.ID).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return false, nil
}
return false, err
}
return true, nil
}
func (a *APPDraftDAO) Delete(ctx context.Context, appID int64) (err error) {
table := a.query.AppDraft
_, err = table.WithContext(ctx).
Where(table.ID.Eq(appID)).
Delete()
if err != nil {
return err
}
return nil
}
func (a *APPDraftDAO) Update(ctx context.Context, app *entity.APP) (err error) {
table := a.query.AppDraft
m := &model.AppDraft{}
if app.Name != nil {
m.Name = *app.Name
}
if app.Desc != nil {
m.Description = *app.Desc
}
if app.IconURI != nil {
m.IconURI = *app.IconURI
}
_, err = table.WithContext(ctx).
Where(table.ID.Eq(app.ID)).
Updates(m)
if err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,256 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"encoding/json"
"errors"
"math"
"gorm.io/gen/field"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
)
func NewAPPReleaseRecordDAO(db *gorm.DB, idGen idgen.IDGenerator) *APPReleaseRecordDAO {
return &APPReleaseRecordDAO{
idGen: idGen,
query: query.Use(db),
}
}
type APPReleaseRecordDAO struct {
idGen idgen.IDGenerator
query *query.Query
}
type releaseRecordPO model.AppReleaseRecord
func (a releaseRecordPO) ToDO() *entity.APP {
return &entity.APP{
ID: a.AppID,
SpaceID: a.SpaceID,
IconURI: &a.IconURI,
Name: &a.Name,
Desc: &a.Description,
OwnerID: a.OwnerID,
CreatedAtMS: a.CreatedAt,
UpdatedAtMS: a.UpdatedAt,
PublishedAtMS: &a.PublishAt,
ConnectorIDs: a.ConnectorIds,
PublishRecordID: &a.ID,
Version: &a.Version,
VersionDesc: &a.VersionDesc,
PublishStatus: ptr.Of(entity.PublishStatus(a.PublishStatus)),
PublishExtraInfo: a.ExtraInfo,
}
}
func (r *APPReleaseRecordDAO) getSelected(opt *APPSelectedOption) (selected []field.Expr) {
if opt == nil {
return selected
}
table := r.query.AppReleaseRecord
if opt.PublishRecordID {
selected = append(selected, table.ID)
}
if opt.APPID {
selected = append(selected, table.AppID)
}
if opt.PublishAtMS {
selected = append(selected, table.PublishAt)
}
if opt.PublishVersion {
selected = append(selected, table.Version)
}
if opt.PublishRecordExtraInfo {
selected = append(selected, table.ExtraInfo)
}
return selected
}
func (r *APPReleaseRecordDAO) GetLatestReleaseRecord(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(table.AppID.Eq(appID)).
Order(table.PublishAt.Desc()).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetOldestReleaseSuccessRecord(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(
table.AppID.Eq(appID),
table.PublishStatus.Eq(int32(entity.PublishStatusOfPublishDone)),
).
Order(table.PublishAt.Asc()).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetReleaseRecordWithID(ctx context.Context, recordID int64) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(table.ID.Eq(recordID)).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetReleaseRecordWithVersion(ctx context.Context, appID int64, version string) (app *entity.APP, exist bool, err error) {
table := r.query.AppReleaseRecord
res, err := table.WithContext(ctx).
Where(
table.AppID.Eq(appID),
table.Version.Eq(version),
).
First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, false, nil
}
return nil, false, err
}
app = releaseRecordPO(*res).ToDO()
return app, true, nil
}
func (r *APPReleaseRecordDAO) GetAPPAllPublishRecords(ctx context.Context, appID int64, opt *APPSelectedOption) (apps []*entity.APP, err error) {
table := r.query.AppReleaseRecord
cursor := int64(math.MaxInt64)
limit := 20
for {
res, err := table.WithContext(ctx).
Select(r.getSelected(opt)...).
Where(
table.AppID.Eq(appID),
table.ID.Lt(cursor),
).
Order(table.ID.Desc()).
Limit(limit).
Find()
if err != nil {
return nil, err
}
for _, v := range res {
apps = append(apps, releaseRecordPO(*v).ToDO())
}
if len(res) < limit {
break
}
cursor = res[len(res)-1].ID
}
return apps, nil
}
func (r *APPReleaseRecordDAO) UpdatePublishStatus(ctx context.Context, recordID int64, status entity.PublishStatus, extraInfo *entity.PublishRecordExtraInfo) (err error) {
table := r.query.AppReleaseRecord
updateMap := map[string]any{
table.PublishStatus.ColumnName().String(): int32(status),
}
if extraInfo != nil {
b, err := json.Marshal(extraInfo)
if err != nil {
return err
}
updateMap[table.ExtraInfo.ColumnName().String()] = b
}
_, err = table.WithContext(ctx).
Where(table.ID.Eq(recordID)).
Updates(updateMap)
if err != nil {
return err
}
return nil
}
func (r *APPReleaseRecordDAO) CreateWithTX(ctx context.Context, tx *query.QueryTx, app *entity.APP) (recordID int64, err error) {
id, err := r.idGen.GenID(ctx)
if err != nil {
return 0, err
}
m := &model.AppReleaseRecord{
ID: id,
AppID: app.ID,
SpaceID: app.SpaceID,
OwnerID: app.OwnerID,
IconURI: app.GetIconURI(),
Name: app.GetName(),
Description: app.GetDesc(),
ConnectorIds: app.ConnectorIDs,
Version: app.GetVersion(),
VersionDesc: app.GetVersionDesc(),
PublishStatus: int32(app.GetPublishStatus()),
PublishAt: app.GetPublishedAtMS(),
}
err = tx.AppReleaseRecord.WithContext(ctx).Create(m)
if err != nil {
return 0, err
}
return id, err
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"errors"
"time"
redisV9 "github.com/redis/go-redis/v9"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
)
type AppCache struct {
cacheCli *redisV9.Client
}
func NewAppCache(cacheCli *redisV9.Client) *AppCache {
return &AppCache{
cacheCli: cacheCli,
}
}
func (a *AppCache) Get(ctx context.Context, key string) (value string, exist bool, err error) {
cmd := a.cacheCli.Get(ctx, key)
if cmd.Err() != nil {
if errors.Is(cmd.Err(), redisV9.Nil) {
return "", false, nil
}
return "", false, cmd.Err()
}
return cmd.Val(), true, nil
}
func (a *AppCache) Set(ctx context.Context, key string, value string, expiration *time.Duration) (err error) {
_expiration := ptr.FromOrDefault(expiration, 0)
cmd := a.cacheCli.Set(ctx, key, value, _expiration)
return cmd.Err()
}

View File

@@ -0,0 +1,25 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import "github.com/coze-dev/coze-studio/backend/domain/app/entity"
const TableNameAppConnectorReleaseRef = "app_connector_release_ref"
// AppConnectorReleaseRef Connector Release Record Reference
type AppConnectorReleaseRef struct {
ID int64 `gorm:"column:id;primaryKey;comment:Primary Key" json:"id"` // Primary Key
RecordID int64 `gorm:"column:record_id;not null;comment:Publish Record ID" json:"record_id"` // Publish Record ID
ConnectorID int64 `gorm:"column:connector_id;comment:Publish Connector ID" json:"connector_id"` // Publish Connector ID
PublishConfig entity.PublishConfig `gorm:"column:publish_config;comment:Publish Configuration;serializer:json" json:"publish_config"` // Publish Configuration
PublishStatus int32 `gorm:"column:publish_status;not null;comment:Publish Status" json:"publish_status"` // Publish Status
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
}
// TableName AppConnectorReleaseRef's table name
func (*AppConnectorReleaseRef) TableName() string {
return TableNameAppConnectorReleaseRef
}

View File

@@ -0,0 +1,29 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"gorm.io/gorm"
)
const TableNameAppDraft = "app_draft"
// AppDraft Draft Application
type AppDraft struct {
ID int64 `gorm:"column:id;primaryKey;comment:APP ID" json:"id"` // APP ID
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
OwnerID int64 `gorm:"column:owner_id;not null;comment:Owner ID" json:"owner_id"` // Owner ID
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
Name string `gorm:"column:name;not null;comment:Application Name" json:"name"` // Application Name
Description string `gorm:"column:description;comment:Application Description" json:"description"` // Application Description
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time
}
// TableName AppDraft's table name
func (*AppDraft) TableName() string {
return TableNameAppDraft
}

View File

@@ -0,0 +1,33 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import "github.com/coze-dev/coze-studio/backend/domain/app/entity"
const TableNameAppReleaseRecord = "app_release_record"
// AppReleaseRecord Application Release Record
type AppReleaseRecord struct {
ID int64 `gorm:"column:id;primaryKey;comment:Publish Record ID" json:"id"` // Publish Record ID
AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
OwnerID int64 `gorm:"column:owner_id;not null;comment:Owner ID" json:"owner_id"` // Owner ID
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
Name string `gorm:"column:name;not null;comment:Application Name" json:"name"` // Application Name
Description string `gorm:"column:description;comment:Application Description" json:"description"` // Application Description
ConnectorIds []int64 `gorm:"column:connector_ids;comment:Publish Connector IDs;serializer:json" json:"connector_ids"` // Publish Connector IDs
ExtraInfo *entity.PublishRecordExtraInfo `gorm:"column:extra_info;comment:Publish Extra Info;serializer:json" json:"extra_info"` // Publish Extra Info
Version string `gorm:"column:version;not null;comment:Release Version" json:"version"` // Release Version
VersionDesc string `gorm:"column:version_desc;comment:Version Description" json:"version_desc"` // Version Description
PublishStatus int32 `gorm:"column:publish_status;not null;comment:Publish Status" json:"publish_status"` // Publish Status
PublishAt int64 `gorm:"column:publish_at;not null;comment:Publish Time in Milliseconds" json:"publish_at"` // Publish Time in Milliseconds
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
}
// TableName AppReleaseRecord's table name
func (*AppReleaseRecord) TableName() string {
return TableNameAppReleaseRecord
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
type APPSelectedOption struct {
APPID bool
PublishRecordID bool
PublishAtMS bool
PublishVersion bool
PublishStatus bool
PublishRecordExtraInfo bool
}

View File

@@ -0,0 +1,405 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
)
func newAppConnectorReleaseRef(db *gorm.DB, opts ...gen.DOOption) appConnectorReleaseRef {
_appConnectorReleaseRef := appConnectorReleaseRef{}
_appConnectorReleaseRef.appConnectorReleaseRefDo.UseDB(db, opts...)
_appConnectorReleaseRef.appConnectorReleaseRefDo.UseModel(&model.AppConnectorReleaseRef{})
tableName := _appConnectorReleaseRef.appConnectorReleaseRefDo.TableName()
_appConnectorReleaseRef.ALL = field.NewAsterisk(tableName)
_appConnectorReleaseRef.ID = field.NewInt64(tableName, "id")
_appConnectorReleaseRef.RecordID = field.NewInt64(tableName, "record_id")
_appConnectorReleaseRef.ConnectorID = field.NewInt64(tableName, "connector_id")
_appConnectorReleaseRef.PublishConfig = field.NewField(tableName, "publish_config")
_appConnectorReleaseRef.PublishStatus = field.NewInt32(tableName, "publish_status")
_appConnectorReleaseRef.CreatedAt = field.NewInt64(tableName, "created_at")
_appConnectorReleaseRef.UpdatedAt = field.NewInt64(tableName, "updated_at")
_appConnectorReleaseRef.fillFieldMap()
return _appConnectorReleaseRef
}
// appConnectorReleaseRef Connector Release Record Reference
type appConnectorReleaseRef struct {
appConnectorReleaseRefDo
ALL field.Asterisk
ID field.Int64 // Primary Key
RecordID field.Int64 // Publish Record ID
ConnectorID field.Int64 // Publish Connector ID
PublishConfig field.Field // Publish Configuration
PublishStatus field.Int32 // Publish Status
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
fieldMap map[string]field.Expr
}
func (a appConnectorReleaseRef) Table(newTableName string) *appConnectorReleaseRef {
a.appConnectorReleaseRefDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a appConnectorReleaseRef) As(alias string) *appConnectorReleaseRef {
a.appConnectorReleaseRefDo.DO = *(a.appConnectorReleaseRefDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *appConnectorReleaseRef) updateTableName(table string) *appConnectorReleaseRef {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt64(table, "id")
a.RecordID = field.NewInt64(table, "record_id")
a.ConnectorID = field.NewInt64(table, "connector_id")
a.PublishConfig = field.NewField(table, "publish_config")
a.PublishStatus = field.NewInt32(table, "publish_status")
a.CreatedAt = field.NewInt64(table, "created_at")
a.UpdatedAt = field.NewInt64(table, "updated_at")
a.fillFieldMap()
return a
}
func (a *appConnectorReleaseRef) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *appConnectorReleaseRef) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 7)
a.fieldMap["id"] = a.ID
a.fieldMap["record_id"] = a.RecordID
a.fieldMap["connector_id"] = a.ConnectorID
a.fieldMap["publish_config"] = a.PublishConfig
a.fieldMap["publish_status"] = a.PublishStatus
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
}
func (a appConnectorReleaseRef) clone(db *gorm.DB) appConnectorReleaseRef {
a.appConnectorReleaseRefDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a appConnectorReleaseRef) replaceDB(db *gorm.DB) appConnectorReleaseRef {
a.appConnectorReleaseRefDo.ReplaceDB(db)
return a
}
type appConnectorReleaseRefDo struct{ gen.DO }
type IAppConnectorReleaseRefDo interface {
gen.SubQuery
Debug() IAppConnectorReleaseRefDo
WithContext(ctx context.Context) IAppConnectorReleaseRefDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppConnectorReleaseRefDo
WriteDB() IAppConnectorReleaseRefDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppConnectorReleaseRefDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppConnectorReleaseRefDo
Not(conds ...gen.Condition) IAppConnectorReleaseRefDo
Or(conds ...gen.Condition) IAppConnectorReleaseRefDo
Select(conds ...field.Expr) IAppConnectorReleaseRefDo
Where(conds ...gen.Condition) IAppConnectorReleaseRefDo
Order(conds ...field.Expr) IAppConnectorReleaseRefDo
Distinct(cols ...field.Expr) IAppConnectorReleaseRefDo
Omit(cols ...field.Expr) IAppConnectorReleaseRefDo
Join(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo
Group(cols ...field.Expr) IAppConnectorReleaseRefDo
Having(conds ...gen.Condition) IAppConnectorReleaseRefDo
Limit(limit int) IAppConnectorReleaseRefDo
Offset(offset int) IAppConnectorReleaseRefDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppConnectorReleaseRefDo
Unscoped() IAppConnectorReleaseRefDo
Create(values ...*model.AppConnectorReleaseRef) error
CreateInBatches(values []*model.AppConnectorReleaseRef, batchSize int) error
Save(values ...*model.AppConnectorReleaseRef) error
First() (*model.AppConnectorReleaseRef, error)
Take() (*model.AppConnectorReleaseRef, error)
Last() (*model.AppConnectorReleaseRef, error)
Find() ([]*model.AppConnectorReleaseRef, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppConnectorReleaseRef, err error)
FindInBatches(result *[]*model.AppConnectorReleaseRef, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppConnectorReleaseRef) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAppConnectorReleaseRefDo
Assign(attrs ...field.AssignExpr) IAppConnectorReleaseRefDo
Joins(fields ...field.RelationField) IAppConnectorReleaseRefDo
Preload(fields ...field.RelationField) IAppConnectorReleaseRefDo
FirstOrInit() (*model.AppConnectorReleaseRef, error)
FirstOrCreate() (*model.AppConnectorReleaseRef, error)
FindByPage(offset int, limit int) (result []*model.AppConnectorReleaseRef, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAppConnectorReleaseRefDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a appConnectorReleaseRefDo) Debug() IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Debug())
}
func (a appConnectorReleaseRefDo) WithContext(ctx context.Context) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appConnectorReleaseRefDo) ReadDB() IAppConnectorReleaseRefDo {
return a.Clauses(dbresolver.Read)
}
func (a appConnectorReleaseRefDo) WriteDB() IAppConnectorReleaseRefDo {
return a.Clauses(dbresolver.Write)
}
func (a appConnectorReleaseRefDo) Session(config *gorm.Session) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Session(config))
}
func (a appConnectorReleaseRefDo) Clauses(conds ...clause.Expression) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appConnectorReleaseRefDo) Returning(value interface{}, columns ...string) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appConnectorReleaseRefDo) Not(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appConnectorReleaseRefDo) Or(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appConnectorReleaseRefDo) Select(conds ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appConnectorReleaseRefDo) Where(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appConnectorReleaseRefDo) Order(conds ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appConnectorReleaseRefDo) Distinct(cols ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appConnectorReleaseRefDo) Omit(cols ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appConnectorReleaseRefDo) Join(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appConnectorReleaseRefDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appConnectorReleaseRefDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appConnectorReleaseRefDo) Group(cols ...field.Expr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appConnectorReleaseRefDo) Having(conds ...gen.Condition) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appConnectorReleaseRefDo) Limit(limit int) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appConnectorReleaseRefDo) Offset(offset int) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appConnectorReleaseRefDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appConnectorReleaseRefDo) Unscoped() IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Unscoped())
}
func (a appConnectorReleaseRefDo) Create(values ...*model.AppConnectorReleaseRef) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a appConnectorReleaseRefDo) CreateInBatches(values []*model.AppConnectorReleaseRef, batchSize int) error {
return a.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a appConnectorReleaseRefDo) Save(values ...*model.AppConnectorReleaseRef) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a appConnectorReleaseRefDo) First() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) Take() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) Last() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) Find() ([]*model.AppConnectorReleaseRef, error) {
result, err := a.DO.Find()
return result.([]*model.AppConnectorReleaseRef), err
}
func (a appConnectorReleaseRefDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppConnectorReleaseRef, err error) {
buf := make([]*model.AppConnectorReleaseRef, 0, batchSize)
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (a appConnectorReleaseRefDo) FindInBatches(result *[]*model.AppConnectorReleaseRef, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appConnectorReleaseRefDo) Attrs(attrs ...field.AssignExpr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appConnectorReleaseRefDo) Assign(attrs ...field.AssignExpr) IAppConnectorReleaseRefDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appConnectorReleaseRefDo) Joins(fields ...field.RelationField) IAppConnectorReleaseRefDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appConnectorReleaseRefDo) Preload(fields ...field.RelationField) IAppConnectorReleaseRefDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a appConnectorReleaseRefDo) FirstOrInit() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) FirstOrCreate() (*model.AppConnectorReleaseRef, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AppConnectorReleaseRef), nil
}
}
func (a appConnectorReleaseRefDo) FindByPage(offset int, limit int) (result []*model.AppConnectorReleaseRef, count int64, err error) {
result, err = a.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = a.Offset(-1).Limit(-1).Count()
return
}
func (a appConnectorReleaseRefDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a appConnectorReleaseRefDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a appConnectorReleaseRefDo) Delete(models ...*model.AppConnectorReleaseRef) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *appConnectorReleaseRefDo) withDO(do gen.Dao) *appConnectorReleaseRefDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@@ -0,0 +1,413 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
)
func newAppDraft(db *gorm.DB, opts ...gen.DOOption) appDraft {
_appDraft := appDraft{}
_appDraft.appDraftDo.UseDB(db, opts...)
_appDraft.appDraftDo.UseModel(&model.AppDraft{})
tableName := _appDraft.appDraftDo.TableName()
_appDraft.ALL = field.NewAsterisk(tableName)
_appDraft.ID = field.NewInt64(tableName, "id")
_appDraft.SpaceID = field.NewInt64(tableName, "space_id")
_appDraft.OwnerID = field.NewInt64(tableName, "owner_id")
_appDraft.IconURI = field.NewString(tableName, "icon_uri")
_appDraft.Name = field.NewString(tableName, "name")
_appDraft.Description = field.NewString(tableName, "description")
_appDraft.CreatedAt = field.NewInt64(tableName, "created_at")
_appDraft.UpdatedAt = field.NewInt64(tableName, "updated_at")
_appDraft.DeletedAt = field.NewField(tableName, "deleted_at")
_appDraft.fillFieldMap()
return _appDraft
}
// appDraft Draft Application
type appDraft struct {
appDraftDo
ALL field.Asterisk
ID field.Int64 // APP ID
SpaceID field.Int64 // Space ID
OwnerID field.Int64 // Owner ID
IconURI field.String // Icon URI
Name field.String // Application Name
Description field.String // Application Description
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
DeletedAt field.Field // Delete Time
fieldMap map[string]field.Expr
}
func (a appDraft) Table(newTableName string) *appDraft {
a.appDraftDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a appDraft) As(alias string) *appDraft {
a.appDraftDo.DO = *(a.appDraftDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *appDraft) updateTableName(table string) *appDraft {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt64(table, "id")
a.SpaceID = field.NewInt64(table, "space_id")
a.OwnerID = field.NewInt64(table, "owner_id")
a.IconURI = field.NewString(table, "icon_uri")
a.Name = field.NewString(table, "name")
a.Description = field.NewString(table, "description")
a.CreatedAt = field.NewInt64(table, "created_at")
a.UpdatedAt = field.NewInt64(table, "updated_at")
a.DeletedAt = field.NewField(table, "deleted_at")
a.fillFieldMap()
return a
}
func (a *appDraft) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *appDraft) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 9)
a.fieldMap["id"] = a.ID
a.fieldMap["space_id"] = a.SpaceID
a.fieldMap["owner_id"] = a.OwnerID
a.fieldMap["icon_uri"] = a.IconURI
a.fieldMap["name"] = a.Name
a.fieldMap["description"] = a.Description
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
a.fieldMap["deleted_at"] = a.DeletedAt
}
func (a appDraft) clone(db *gorm.DB) appDraft {
a.appDraftDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a appDraft) replaceDB(db *gorm.DB) appDraft {
a.appDraftDo.ReplaceDB(db)
return a
}
type appDraftDo struct{ gen.DO }
type IAppDraftDo interface {
gen.SubQuery
Debug() IAppDraftDo
WithContext(ctx context.Context) IAppDraftDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppDraftDo
WriteDB() IAppDraftDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppDraftDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppDraftDo
Not(conds ...gen.Condition) IAppDraftDo
Or(conds ...gen.Condition) IAppDraftDo
Select(conds ...field.Expr) IAppDraftDo
Where(conds ...gen.Condition) IAppDraftDo
Order(conds ...field.Expr) IAppDraftDo
Distinct(cols ...field.Expr) IAppDraftDo
Omit(cols ...field.Expr) IAppDraftDo
Join(table schema.Tabler, on ...field.Expr) IAppDraftDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo
Group(cols ...field.Expr) IAppDraftDo
Having(conds ...gen.Condition) IAppDraftDo
Limit(limit int) IAppDraftDo
Offset(offset int) IAppDraftDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppDraftDo
Unscoped() IAppDraftDo
Create(values ...*model.AppDraft) error
CreateInBatches(values []*model.AppDraft, batchSize int) error
Save(values ...*model.AppDraft) error
First() (*model.AppDraft, error)
Take() (*model.AppDraft, error)
Last() (*model.AppDraft, error)
Find() ([]*model.AppDraft, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppDraft, err error)
FindInBatches(result *[]*model.AppDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppDraft) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAppDraftDo
Assign(attrs ...field.AssignExpr) IAppDraftDo
Joins(fields ...field.RelationField) IAppDraftDo
Preload(fields ...field.RelationField) IAppDraftDo
FirstOrInit() (*model.AppDraft, error)
FirstOrCreate() (*model.AppDraft, error)
FindByPage(offset int, limit int) (result []*model.AppDraft, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAppDraftDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a appDraftDo) Debug() IAppDraftDo {
return a.withDO(a.DO.Debug())
}
func (a appDraftDo) WithContext(ctx context.Context) IAppDraftDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appDraftDo) ReadDB() IAppDraftDo {
return a.Clauses(dbresolver.Read)
}
func (a appDraftDo) WriteDB() IAppDraftDo {
return a.Clauses(dbresolver.Write)
}
func (a appDraftDo) Session(config *gorm.Session) IAppDraftDo {
return a.withDO(a.DO.Session(config))
}
func (a appDraftDo) Clauses(conds ...clause.Expression) IAppDraftDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appDraftDo) Returning(value interface{}, columns ...string) IAppDraftDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appDraftDo) Not(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appDraftDo) Or(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appDraftDo) Select(conds ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appDraftDo) Where(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appDraftDo) Order(conds ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appDraftDo) Distinct(cols ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appDraftDo) Omit(cols ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appDraftDo) Join(table schema.Tabler, on ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appDraftDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appDraftDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appDraftDo) Group(cols ...field.Expr) IAppDraftDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appDraftDo) Having(conds ...gen.Condition) IAppDraftDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appDraftDo) Limit(limit int) IAppDraftDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appDraftDo) Offset(offset int) IAppDraftDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appDraftDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppDraftDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appDraftDo) Unscoped() IAppDraftDo {
return a.withDO(a.DO.Unscoped())
}
func (a appDraftDo) Create(values ...*model.AppDraft) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a appDraftDo) CreateInBatches(values []*model.AppDraft, batchSize int) error {
return a.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a appDraftDo) Save(values ...*model.AppDraft) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a appDraftDo) First() (*model.AppDraft, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) Take() (*model.AppDraft, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) Last() (*model.AppDraft, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) Find() ([]*model.AppDraft, error) {
result, err := a.DO.Find()
return result.([]*model.AppDraft), err
}
func (a appDraftDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppDraft, err error) {
buf := make([]*model.AppDraft, 0, batchSize)
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (a appDraftDo) FindInBatches(result *[]*model.AppDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appDraftDo) Attrs(attrs ...field.AssignExpr) IAppDraftDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appDraftDo) Assign(attrs ...field.AssignExpr) IAppDraftDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appDraftDo) Joins(fields ...field.RelationField) IAppDraftDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appDraftDo) Preload(fields ...field.RelationField) IAppDraftDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a appDraftDo) FirstOrInit() (*model.AppDraft, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) FirstOrCreate() (*model.AppDraft, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AppDraft), nil
}
}
func (a appDraftDo) FindByPage(offset int, limit int) (result []*model.AppDraft, count int64, err error) {
result, err = a.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = a.Offset(-1).Limit(-1).Count()
return
}
func (a appDraftDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a appDraftDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a appDraftDo) Delete(models ...*model.AppDraft) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *appDraftDo) withDO(do gen.Dao) *appDraftDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@@ -0,0 +1,437 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/model"
)
func newAppReleaseRecord(db *gorm.DB, opts ...gen.DOOption) appReleaseRecord {
_appReleaseRecord := appReleaseRecord{}
_appReleaseRecord.appReleaseRecordDo.UseDB(db, opts...)
_appReleaseRecord.appReleaseRecordDo.UseModel(&model.AppReleaseRecord{})
tableName := _appReleaseRecord.appReleaseRecordDo.TableName()
_appReleaseRecord.ALL = field.NewAsterisk(tableName)
_appReleaseRecord.ID = field.NewInt64(tableName, "id")
_appReleaseRecord.AppID = field.NewInt64(tableName, "app_id")
_appReleaseRecord.SpaceID = field.NewInt64(tableName, "space_id")
_appReleaseRecord.OwnerID = field.NewInt64(tableName, "owner_id")
_appReleaseRecord.IconURI = field.NewString(tableName, "icon_uri")
_appReleaseRecord.Name = field.NewString(tableName, "name")
_appReleaseRecord.Description = field.NewString(tableName, "description")
_appReleaseRecord.ConnectorIds = field.NewField(tableName, "connector_ids")
_appReleaseRecord.ExtraInfo = field.NewField(tableName, "extra_info")
_appReleaseRecord.Version = field.NewString(tableName, "version")
_appReleaseRecord.VersionDesc = field.NewString(tableName, "version_desc")
_appReleaseRecord.PublishStatus = field.NewInt32(tableName, "publish_status")
_appReleaseRecord.PublishAt = field.NewInt64(tableName, "publish_at")
_appReleaseRecord.CreatedAt = field.NewInt64(tableName, "created_at")
_appReleaseRecord.UpdatedAt = field.NewInt64(tableName, "updated_at")
_appReleaseRecord.fillFieldMap()
return _appReleaseRecord
}
// appReleaseRecord Application Release Record
type appReleaseRecord struct {
appReleaseRecordDo
ALL field.Asterisk
ID field.Int64 // Publish Record ID
AppID field.Int64 // Application ID
SpaceID field.Int64 // Space ID
OwnerID field.Int64 // Owner ID
IconURI field.String // Icon URI
Name field.String // Application Name
Description field.String // Application Description
ConnectorIds field.Field // Publish Connector IDs
ExtraInfo field.Field // Publish Extra Info
Version field.String // Release Version
VersionDesc field.String // Version Description
PublishStatus field.Int32 // Publish Status
PublishAt field.Int64 // Publish Time in Milliseconds
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
fieldMap map[string]field.Expr
}
func (a appReleaseRecord) Table(newTableName string) *appReleaseRecord {
a.appReleaseRecordDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a appReleaseRecord) As(alias string) *appReleaseRecord {
a.appReleaseRecordDo.DO = *(a.appReleaseRecordDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *appReleaseRecord) updateTableName(table string) *appReleaseRecord {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt64(table, "id")
a.AppID = field.NewInt64(table, "app_id")
a.SpaceID = field.NewInt64(table, "space_id")
a.OwnerID = field.NewInt64(table, "owner_id")
a.IconURI = field.NewString(table, "icon_uri")
a.Name = field.NewString(table, "name")
a.Description = field.NewString(table, "description")
a.ConnectorIds = field.NewField(table, "connector_ids")
a.ExtraInfo = field.NewField(table, "extra_info")
a.Version = field.NewString(table, "version")
a.VersionDesc = field.NewString(table, "version_desc")
a.PublishStatus = field.NewInt32(table, "publish_status")
a.PublishAt = field.NewInt64(table, "publish_at")
a.CreatedAt = field.NewInt64(table, "created_at")
a.UpdatedAt = field.NewInt64(table, "updated_at")
a.fillFieldMap()
return a
}
func (a *appReleaseRecord) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *appReleaseRecord) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 15)
a.fieldMap["id"] = a.ID
a.fieldMap["app_id"] = a.AppID
a.fieldMap["space_id"] = a.SpaceID
a.fieldMap["owner_id"] = a.OwnerID
a.fieldMap["icon_uri"] = a.IconURI
a.fieldMap["name"] = a.Name
a.fieldMap["description"] = a.Description
a.fieldMap["connector_ids"] = a.ConnectorIds
a.fieldMap["extra_info"] = a.ExtraInfo
a.fieldMap["version"] = a.Version
a.fieldMap["version_desc"] = a.VersionDesc
a.fieldMap["publish_status"] = a.PublishStatus
a.fieldMap["publish_at"] = a.PublishAt
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
}
func (a appReleaseRecord) clone(db *gorm.DB) appReleaseRecord {
a.appReleaseRecordDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a appReleaseRecord) replaceDB(db *gorm.DB) appReleaseRecord {
a.appReleaseRecordDo.ReplaceDB(db)
return a
}
type appReleaseRecordDo struct{ gen.DO }
type IAppReleaseRecordDo interface {
gen.SubQuery
Debug() IAppReleaseRecordDo
WithContext(ctx context.Context) IAppReleaseRecordDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppReleaseRecordDo
WriteDB() IAppReleaseRecordDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppReleaseRecordDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppReleaseRecordDo
Not(conds ...gen.Condition) IAppReleaseRecordDo
Or(conds ...gen.Condition) IAppReleaseRecordDo
Select(conds ...field.Expr) IAppReleaseRecordDo
Where(conds ...gen.Condition) IAppReleaseRecordDo
Order(conds ...field.Expr) IAppReleaseRecordDo
Distinct(cols ...field.Expr) IAppReleaseRecordDo
Omit(cols ...field.Expr) IAppReleaseRecordDo
Join(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo
Group(cols ...field.Expr) IAppReleaseRecordDo
Having(conds ...gen.Condition) IAppReleaseRecordDo
Limit(limit int) IAppReleaseRecordDo
Offset(offset int) IAppReleaseRecordDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppReleaseRecordDo
Unscoped() IAppReleaseRecordDo
Create(values ...*model.AppReleaseRecord) error
CreateInBatches(values []*model.AppReleaseRecord, batchSize int) error
Save(values ...*model.AppReleaseRecord) error
First() (*model.AppReleaseRecord, error)
Take() (*model.AppReleaseRecord, error)
Last() (*model.AppReleaseRecord, error)
Find() ([]*model.AppReleaseRecord, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppReleaseRecord, err error)
FindInBatches(result *[]*model.AppReleaseRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppReleaseRecord) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAppReleaseRecordDo
Assign(attrs ...field.AssignExpr) IAppReleaseRecordDo
Joins(fields ...field.RelationField) IAppReleaseRecordDo
Preload(fields ...field.RelationField) IAppReleaseRecordDo
FirstOrInit() (*model.AppReleaseRecord, error)
FirstOrCreate() (*model.AppReleaseRecord, error)
FindByPage(offset int, limit int) (result []*model.AppReleaseRecord, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAppReleaseRecordDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a appReleaseRecordDo) Debug() IAppReleaseRecordDo {
return a.withDO(a.DO.Debug())
}
func (a appReleaseRecordDo) WithContext(ctx context.Context) IAppReleaseRecordDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appReleaseRecordDo) ReadDB() IAppReleaseRecordDo {
return a.Clauses(dbresolver.Read)
}
func (a appReleaseRecordDo) WriteDB() IAppReleaseRecordDo {
return a.Clauses(dbresolver.Write)
}
func (a appReleaseRecordDo) Session(config *gorm.Session) IAppReleaseRecordDo {
return a.withDO(a.DO.Session(config))
}
func (a appReleaseRecordDo) Clauses(conds ...clause.Expression) IAppReleaseRecordDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appReleaseRecordDo) Returning(value interface{}, columns ...string) IAppReleaseRecordDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appReleaseRecordDo) Not(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appReleaseRecordDo) Or(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appReleaseRecordDo) Select(conds ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appReleaseRecordDo) Where(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appReleaseRecordDo) Order(conds ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appReleaseRecordDo) Distinct(cols ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appReleaseRecordDo) Omit(cols ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appReleaseRecordDo) Join(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appReleaseRecordDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appReleaseRecordDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appReleaseRecordDo) Group(cols ...field.Expr) IAppReleaseRecordDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appReleaseRecordDo) Having(conds ...gen.Condition) IAppReleaseRecordDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appReleaseRecordDo) Limit(limit int) IAppReleaseRecordDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appReleaseRecordDo) Offset(offset int) IAppReleaseRecordDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appReleaseRecordDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppReleaseRecordDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appReleaseRecordDo) Unscoped() IAppReleaseRecordDo {
return a.withDO(a.DO.Unscoped())
}
func (a appReleaseRecordDo) Create(values ...*model.AppReleaseRecord) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a appReleaseRecordDo) CreateInBatches(values []*model.AppReleaseRecord, batchSize int) error {
return a.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a appReleaseRecordDo) Save(values ...*model.AppReleaseRecord) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a appReleaseRecordDo) First() (*model.AppReleaseRecord, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) Take() (*model.AppReleaseRecord, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) Last() (*model.AppReleaseRecord, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) Find() ([]*model.AppReleaseRecord, error) {
result, err := a.DO.Find()
return result.([]*model.AppReleaseRecord), err
}
func (a appReleaseRecordDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppReleaseRecord, err error) {
buf := make([]*model.AppReleaseRecord, 0, batchSize)
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (a appReleaseRecordDo) FindInBatches(result *[]*model.AppReleaseRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appReleaseRecordDo) Attrs(attrs ...field.AssignExpr) IAppReleaseRecordDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appReleaseRecordDo) Assign(attrs ...field.AssignExpr) IAppReleaseRecordDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appReleaseRecordDo) Joins(fields ...field.RelationField) IAppReleaseRecordDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appReleaseRecordDo) Preload(fields ...field.RelationField) IAppReleaseRecordDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a appReleaseRecordDo) FirstOrInit() (*model.AppReleaseRecord, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) FirstOrCreate() (*model.AppReleaseRecord, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AppReleaseRecord), nil
}
}
func (a appReleaseRecordDo) FindByPage(offset int, limit int) (result []*model.AppReleaseRecord, count int64, err error) {
result, err = a.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = a.Offset(-1).Limit(-1).Count()
return
}
func (a appReleaseRecordDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a appReleaseRecordDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a appReleaseRecordDo) Delete(models ...*model.AppReleaseRecord) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *appReleaseRecordDo) withDO(do gen.Dao) *appReleaseRecordDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@@ -0,0 +1,119 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
AppConnectorReleaseRef *appConnectorReleaseRef
AppDraft *appDraft
AppReleaseRecord *appReleaseRecord
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
AppConnectorReleaseRef = &Q.AppConnectorReleaseRef
AppDraft = &Q.AppDraft
AppReleaseRecord = &Q.AppReleaseRecord
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
AppConnectorReleaseRef: newAppConnectorReleaseRef(db, opts...),
AppDraft: newAppDraft(db, opts...),
AppReleaseRecord: newAppReleaseRecord(db, opts...),
}
}
type Query struct {
db *gorm.DB
AppConnectorReleaseRef appConnectorReleaseRef
AppDraft appDraft
AppReleaseRecord appReleaseRecord
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
AppConnectorReleaseRef: q.AppConnectorReleaseRef.clone(db),
AppDraft: q.AppDraft.clone(db),
AppReleaseRecord: q.AppReleaseRecord.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
AppConnectorReleaseRef: q.AppConnectorReleaseRef.replaceDB(db),
AppDraft: q.AppDraft.replaceDB(db),
AppReleaseRecord: q.AppReleaseRecord.replaceDB(db),
}
}
type queryCtx struct {
AppConnectorReleaseRef IAppConnectorReleaseRefDo
AppDraft IAppDraftDo
AppReleaseRecord IAppReleaseRecordDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
AppConnectorReleaseRef: q.AppConnectorReleaseRef.WithContext(ctx),
AppDraft: q.AppDraft.WithContext(ctx),
AppReleaseRecord: q.AppReleaseRecord.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
tx := q.db.Begin(opts...)
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}
type QueryTx struct {
*Query
Error error
}
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package repository
import (
"context"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
)
type AppRepository interface {
// draft application
CreateDraftAPP(ctx context.Context, app *entity.APP) (appID int64, err error)
GetDraftAPP(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error)
CheckDraftAPPExist(ctx context.Context, appID int64) (exist bool, err error)
DeleteDraftAPP(ctx context.Context, appID int64) (err error)
UpdateDraftAPP(ctx context.Context, app *entity.APP) (err error)
GetPublishRecord(ctx context.Context, req *GetPublishRecordRequest) (record *entity.PublishRecord, exist bool, err error)
CheckAPPVersionExist(ctx context.Context, appID int64, version string) (exist bool, err error)
CreateAPPPublishRecord(ctx context.Context, record *entity.PublishRecord) (recordID int64, err error)
UpdateAPPPublishStatus(ctx context.Context, req *UpdateAPPPublishStatusRequest) (err error)
UpdateConnectorPublishStatus(ctx context.Context, recordID int64, status entity.ConnectorPublishStatus) (err error)
GetAPPAllPublishRecords(ctx context.Context, appID int64, opts ...APPSelectedOptions) (records []*entity.PublishRecord, err error)
InitResourceCopyTask(ctx context.Context, result *entity.ResourceCopyResult) (taskID string, err error)
SaveResourceCopyTaskResult(ctx context.Context, taskID string, result *entity.ResourceCopyResult) (err error)
GetResourceCopyTaskResult(ctx context.Context, taskID string) (result *entity.ResourceCopyResult, exist bool, err error)
}
type GetPublishRecordRequest struct {
APPID int64
RecordID *int64
OldestSuccess bool // Get the oldest success record if OldestSuccess is true and RecordID is nil; otherwise, get the latest record
}
type UpdateAPPPublishStatusRequest struct {
RecordID int64
PublishStatus entity.PublishStatus
PublishRecordExtraInfo *entity.PublishRecordExtraInfo
}

View File

@@ -0,0 +1,283 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package repository
import (
"context"
"encoding/json"
"fmt"
"runtime/debug"
"strconv"
"sync"
"time"
redisV9 "github.com/redis/go-redis/v9"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal"
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
"github.com/coze-dev/coze-studio/backend/pkg/logs"
"github.com/coze-dev/coze-studio/backend/pkg/taskgroup"
)
type appRepoImpl struct {
idGen idgen.IDGenerator
query *query.Query
appDraftDAO *dal.APPDraftDAO
appReleaseRecordDAO *dal.APPReleaseRecordDAO
appConnectorRefDAO *dal.APPConnectorReleaseRefDAO
cacheCli *dal.AppCache
}
type APPRepoComponents struct {
IDGen idgen.IDGenerator
DB *gorm.DB
CacheCli *redisV9.Client
}
func NewAPPRepo(components *APPRepoComponents) AppRepository {
return &appRepoImpl{
idGen: components.IDGen,
query: query.Use(components.DB),
appDraftDAO: dal.NewAPPDraftDAO(components.DB, components.IDGen),
appReleaseRecordDAO: dal.NewAPPReleaseRecordDAO(components.DB, components.IDGen),
appConnectorRefDAO: dal.NewAPPConnectorReleaseRefDAO(components.DB, components.IDGen),
cacheCli: dal.NewAppCache(components.CacheCli),
}
}
func (a *appRepoImpl) CreateDraftAPP(ctx context.Context, app *entity.APP) (appID int64, err error) {
appID, err = a.appDraftDAO.Create(ctx, app)
if err != nil {
return 0, err
}
return appID, nil
}
func (a *appRepoImpl) GetDraftAPP(ctx context.Context, appID int64) (app *entity.APP, exist bool, err error) {
return a.appDraftDAO.Get(ctx, appID)
}
func (a *appRepoImpl) CheckDraftAPPExist(ctx context.Context, appID int64) (exist bool, err error) {
return a.appDraftDAO.CheckExist(ctx, appID)
}
func (a *appRepoImpl) DeleteDraftAPP(ctx context.Context, appID int64) (err error) {
table := a.query.AppDraft
_, err = table.WithContext(ctx).
Where(table.ID.Eq(appID)).
Delete()
if err != nil {
return err
}
return nil
}
func (a *appRepoImpl) UpdateDraftAPP(ctx context.Context, app *entity.APP) (err error) {
return a.appDraftDAO.Update(ctx, app)
}
func (a *appRepoImpl) GetPublishRecord(ctx context.Context, req *GetPublishRecordRequest) (record *entity.PublishRecord, exist bool, err error) {
var app *entity.APP
if req.RecordID != nil {
app, exist, err = a.appReleaseRecordDAO.GetReleaseRecordWithID(ctx, *req.RecordID)
} else if req.OldestSuccess {
app, exist, err = a.appReleaseRecordDAO.GetOldestReleaseSuccessRecord(ctx, req.APPID)
} else {
app, exist, err = a.appReleaseRecordDAO.GetLatestReleaseRecord(ctx, req.APPID)
}
if err != nil {
return nil, false, err
}
if !exist {
return nil, false, nil
}
publishRecords, err := a.appConnectorRefDAO.GetAllConnectorRecords(ctx, app.GetPublishRecordID())
if err != nil {
return nil, false, err
}
record = &entity.PublishRecord{
APP: app,
ConnectorPublishRecords: publishRecords,
}
return record, true, nil
}
func (a *appRepoImpl) CheckAPPVersionExist(ctx context.Context, appID int64, version string) (exist bool, err error) {
_, exist, err = a.appReleaseRecordDAO.GetReleaseRecordWithVersion(ctx, appID, version)
return exist, err
}
func (a *appRepoImpl) CreateAPPPublishRecord(ctx context.Context, record *entity.PublishRecord) (recordID int64, err error) {
tx := a.query.Begin()
if tx.Error != nil {
return 0, tx.Error
}
defer func() {
if r := recover(); r != nil {
if e := tx.Rollback(); e != nil {
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
}
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
return
}
if err != nil {
if e := tx.Rollback(); e != nil {
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
}
}
}()
recordID, err = a.appReleaseRecordDAO.CreateWithTX(ctx, tx, record.APP)
if err != nil {
return 0, err
}
err = a.appConnectorRefDAO.BatchCreateWithTX(ctx, tx, recordID, record.ConnectorPublishRecords)
if err != nil {
return 0, err
}
err = tx.Commit()
if err != nil {
return 0, err
}
return recordID, nil
}
func (a *appRepoImpl) UpdateAPPPublishStatus(ctx context.Context, req *UpdateAPPPublishStatusRequest) (err error) {
return a.appReleaseRecordDAO.UpdatePublishStatus(ctx, req.RecordID, req.PublishStatus, req.PublishRecordExtraInfo)
}
func (a *appRepoImpl) UpdateConnectorPublishStatus(ctx context.Context, recordID int64, status entity.ConnectorPublishStatus) (err error) {
return a.appConnectorRefDAO.UpdatePublishStatus(ctx, recordID, status)
}
func (a *appRepoImpl) GetAPPAllPublishRecords(ctx context.Context, appID int64, opts ...APPSelectedOptions) (records []*entity.PublishRecord, err error) {
var opt *dal.APPSelectedOption
if len(opts) > 0 {
opt = &dal.APPSelectedOption{}
for _, o := range opts {
o(opt)
}
}
apps, err := a.appReleaseRecordDAO.GetAPPAllPublishRecords(ctx, appID, opt)
if err != nil {
return nil, err
}
tasks := taskgroup.NewTaskGroup(ctx, 5)
lock := sync.Mutex{}
for _, r := range apps {
tasks.Go(func() error {
connectorPublishRecords, err := a.appConnectorRefDAO.GetAllConnectorPublishRecords(ctx, r.GetPublishRecordID())
if err != nil {
return err
}
lock.Lock()
records = append(records, &entity.PublishRecord{
APP: r,
ConnectorPublishRecords: connectorPublishRecords,
})
lock.Unlock()
return nil
})
}
err = tasks.Wait()
if err != nil {
return nil, err
}
return records, nil
}
func (a *appRepoImpl) InitResourceCopyTask(ctx context.Context, result *entity.ResourceCopyResult) (taskID string, err error) {
id, err := a.idGen.GenID(ctx)
if err != nil {
return "", err
}
taskID = strconv.FormatInt(id, 10)
b, err := json.Marshal(result)
if err != nil {
return "", err
}
key := a.makeResourceCopyTaskResultKey(taskID)
err = a.cacheCli.Set(ctx, key, string(b), ptr.Of(time.Hour))
if err != nil {
return "", err
}
return taskID, nil
}
func (a *appRepoImpl) SaveResourceCopyTaskResult(ctx context.Context, taskID string, result *entity.ResourceCopyResult) (err error) {
b, err := json.Marshal(result)
if err != nil {
return err
}
key := a.makeResourceCopyTaskResultKey(taskID)
err = a.cacheCli.Set(ctx, key, string(b), ptr.Of(time.Hour))
if err != nil {
return err
}
return nil
}
func (a *appRepoImpl) GetResourceCopyTaskResult(ctx context.Context, taskID string) (result *entity.ResourceCopyResult, exist bool, err error) {
key := a.makeResourceCopyTaskResultKey(taskID)
b, exist, err := a.cacheCli.Get(ctx, key)
if err != nil {
return nil, false, err
}
if !exist {
return nil, false, nil
}
result = &entity.ResourceCopyResult{}
err = json.Unmarshal([]byte(b), result)
if err != nil {
return nil, false, err
}
return result, true, nil
}
func (a *appRepoImpl) makeResourceCopyTaskResultKey(taskID string) string {
return fmt.Sprintf("resource_copy_task_result_%s", taskID)
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package repository
import (
"github.com/coze-dev/coze-studio/backend/domain/app/internal/dal"
)
type APPSelectedOptions func(*dal.APPSelectedOption)
func WithAPPID() APPSelectedOptions {
return func(opts *dal.APPSelectedOption) {
opts.APPID = true
}
}
func WithAPPPublishAtMS() APPSelectedOptions {
return func(opts *dal.APPSelectedOption) {
opts.PublishAtMS = true
}
}
func WithPublishVersion() APPSelectedOptions {
return func(opts *dal.APPSelectedOption) {
opts.PublishVersion = true
}
}
func WithPublishRecordID() APPSelectedOptions {
return func(opts *dal.APPSelectedOption) {
opts.PublishRecordID = true
}
}
func WithAPPPublishStatus() APPSelectedOptions {
return func(opts *dal.APPSelectedOption) {
opts.PublishStatus = true
}
}
func WithPublishRecordExtraInfo() APPSelectedOptions {
return func(opts *dal.APPSelectedOption) {
opts.PublishRecordExtraInfo = true
}
}

View File

@@ -0,0 +1,262 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package service
import (
"context"
"time"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
resourceCommon "github.com/coze-dev/coze-studio/backend/api/model/resource/common"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossplugin"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossworkflow"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/repository"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
"github.com/coze-dev/coze-studio/backend/pkg/logs"
commonConsts "github.com/coze-dev/coze-studio/backend/types/consts"
"github.com/coze-dev/coze-studio/backend/types/errno"
)
func (a *appServiceImpl) PublishAPP(ctx context.Context, req *PublishAPPRequest) (resp *PublishAPPResponse, err error) {
err = a.checkCanPublishAPP(ctx, req)
if err != nil {
return nil, err
}
recordID, err := a.createPublishVersion(ctx, req)
if err != nil {
return nil, err
}
success, err := a.publishByConnectors(ctx, recordID, req)
if err != nil {
logs.CtxErrorf(ctx, "publish by connectors failed, recordID=%d, err=%v", recordID, err)
}
resp = &PublishAPPResponse{
Success: success,
PublishRecordID: recordID,
}
return resp, nil
}
func (a *appServiceImpl) publishByConnectors(ctx context.Context, recordID int64, req *PublishAPPRequest) (success bool, err error) {
defer func() {
if err != nil {
updateErr := a.APPRepo.UpdateAPPPublishStatus(ctx, &repository.UpdateAPPPublishStatusRequest{
RecordID: recordID,
PublishStatus: entity.PublishStatusOfPackFailed,
})
if updateErr != nil {
logs.CtxErrorf(ctx, "UpdateAPPPublishStatus failed, recordID=%d, err=%v", recordID, updateErr)
}
}
}()
connectorIDs := make([]int64, 0, len(req.ConnectorPublishConfigs))
for cid := range req.ConnectorPublishConfigs {
connectorIDs = append(connectorIDs, cid)
}
failedResources, err := a.packResources(ctx, req.APPID, req.Version, connectorIDs)
if err != nil {
return false, err
}
if len(failedResources) > 0 {
logs.CtxWarnf(ctx, "packResources failed, recordID=%d, len=%d", recordID, len(failedResources))
processErr := a.packResourcesFailedPostProcess(ctx, recordID, failedResources)
if processErr != nil {
logs.CtxErrorf(ctx, "packResourcesFailedPostProcess failed, recordID=%d, err=%v", recordID, processErr)
}
return false, nil
}
for cid := range req.ConnectorPublishConfigs {
switch cid {
case commonConsts.APIConnectorID:
updateSuccessErr := a.APPRepo.UpdateConnectorPublishStatus(ctx, recordID, entity.ConnectorPublishStatusOfSuccess)
if updateSuccessErr == nil {
continue
}
logs.CtxErrorf(ctx, "failed to update connector '%d' publish status to success, err=%v", cid, updateSuccessErr)
updateFailedErr := a.APPRepo.UpdateAPPPublishStatus(ctx, &repository.UpdateAPPPublishStatusRequest{
RecordID: recordID,
PublishStatus: entity.PublishStatusOfPackFailed,
})
if updateFailedErr != nil {
logs.CtxWarnf(ctx, "failed to update connector '%d' publish status to failed, err=%v", cid, updateFailedErr)
}
default:
continue
}
}
err = a.APPRepo.UpdateAPPPublishStatus(ctx, &repository.UpdateAPPPublishStatusRequest{
RecordID: recordID,
PublishStatus: entity.PublishStatusOfPublishDone,
})
if err != nil {
return false, errorx.Wrapf(err, "UpdateAPPPublishStatus failed, recordID=%d", recordID)
}
return true, nil
}
func (a *appServiceImpl) checkCanPublishAPP(ctx context.Context, req *PublishAPPRequest) (err error) {
exist, err := a.APPRepo.CheckAPPVersionExist(ctx, req.APPID, req.Version)
if err != nil {
return errorx.Wrapf(err, "CheckAPPVersionExist failed, appID=%d, version=%s", req.APPID, req.Version)
}
if exist {
return errorx.New(errno.ErrAppRecordNotFound)
}
return nil
}
func (a *appServiceImpl) createPublishVersion(ctx context.Context, req *PublishAPPRequest) (recordID int64, err error) {
draftAPP, exist, err := a.APPRepo.GetDraftAPP(ctx, req.APPID)
if err != nil {
return 0, errorx.Wrapf(err, "GetDraftAPP failed, appID=%d", req.APPID)
}
if !exist {
return 0, errorx.New(errno.ErrAppRecordNotFound)
}
draftAPP.PublishedAtMS = ptr.Of(time.Now().UnixMilli())
draftAPP.Version = &req.Version
draftAPP.VersionDesc = &req.VersionDesc
publishRecords := make([]*entity.ConnectorPublishRecord, 0, len(req.ConnectorPublishConfigs))
for cid, conf := range req.ConnectorPublishConfigs {
publishRecords = append(publishRecords, &entity.ConnectorPublishRecord{
ConnectorID: cid,
PublishStatus: entity.ConnectorPublishStatusOfDefault,
PublishConfig: conf,
})
draftAPP.ConnectorIDs = append(draftAPP.ConnectorIDs, cid)
}
recordID, err = a.APPRepo.CreateAPPPublishRecord(ctx, &entity.PublishRecord{
APP: draftAPP,
ConnectorPublishRecords: publishRecords,
})
if err != nil {
return 0, errorx.Wrapf(err, "CreateAPPPublishRecord failed, appID=%d", req.APPID)
}
return recordID, nil
}
func (a *appServiceImpl) packResources(ctx context.Context, appID int64, version string, connectorIDs []int64) (failedResources []*entity.PackResourceFailedInfo, err error) {
failedPlugins, allDraftPlugins, err := a.packPlugins(ctx, appID, version)
if err != nil {
return nil, err
}
workflowFailedInfoList, err := a.packWorkflows(ctx, appID, version,
slices.Transform(allDraftPlugins, func(a *plugin.PluginInfo) int64 {
return a.ID
}), connectorIDs)
if err != nil {
return nil, err
}
length := len(failedPlugins) + len(workflowFailedInfoList)
if length == 0 {
return nil, nil
}
failedResources = append(failedResources, failedPlugins...)
failedResources = append(failedResources, workflowFailedInfoList...)
return failedResources, nil
}
func (a *appServiceImpl) packPlugins(ctx context.Context, appID int64, version string) (failedInfo []*entity.PackResourceFailedInfo, allDraftPlugins []*plugin.PluginInfo, err error) {
res, err := crossplugin.DefaultSVC().PublishAPPPlugins(ctx, &plugin.PublishAPPPluginsRequest{
APPID: appID,
Version: version,
})
if err != nil {
return nil, nil, errorx.Wrapf(err, "PublishAPPPlugins failed, appID=%d, version=%s", appID, version)
}
failedInfo = make([]*entity.PackResourceFailedInfo, 0, len(res.FailedPlugins))
for _, p := range res.FailedPlugins {
failedInfo = append(failedInfo, &entity.PackResourceFailedInfo{
ResID: p.ID,
ResType: resourceCommon.ResType_Plugin,
ResName: p.GetName(),
})
}
return failedInfo, res.AllDraftPlugins, nil
}
func (a *appServiceImpl) packWorkflows(ctx context.Context, appID int64, version string, allDraftPluginIDs []int64, connectorIDs []int64) (workflowFailedInfoList []*entity.PackResourceFailedInfo, err error) {
issues, err := crossworkflow.DefaultSVC().ReleaseApplicationWorkflows(ctx, appID, &crossworkflow.ReleaseWorkflowConfig{
Version: version,
PluginIDs: allDraftPluginIDs,
ConnectorIDs: connectorIDs,
})
if err != nil {
return nil, errorx.Wrapf(err, "ReleaseApplicationWorkflows failed, appID=%d, version=%s", appID, version)
}
if len(issues) == 0 {
return workflowFailedInfoList, nil
}
workflowFailedInfoList = make([]*entity.PackResourceFailedInfo, 0, len(issues))
for _, issue := range issues {
workflowFailedInfoList = append(workflowFailedInfoList, &entity.PackResourceFailedInfo{
ResID: issue.WorkflowID,
ResType: resourceCommon.ResType_Workflow,
ResName: issue.WorkflowName,
})
}
return workflowFailedInfoList, nil
}
func (a *appServiceImpl) packResourcesFailedPostProcess(ctx context.Context, recordID int64, packFailedInfo []*entity.PackResourceFailedInfo) (err error) {
publishFailedInfo := &entity.PublishRecordExtraInfo{
PackFailedInfo: packFailedInfo,
}
err = a.APPRepo.UpdateAPPPublishStatus(ctx, &repository.UpdateAPPPublishStatusRequest{
RecordID: recordID,
PublishStatus: entity.PublishStatusOfPackFailed,
PublishRecordExtraInfo: publishFailedInfo,
})
if err != nil {
return errorx.Wrapf(err, "UpdateAPPPublishStatus failed, recordID=%d", recordID)
}
return nil
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package service
import (
"context"
connectorModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/connector"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
)
type AppService interface {
CreateDraftAPP(ctx context.Context, req *CreateDraftAPPRequest) (appID int64, err error)
GetDraftAPP(ctx context.Context, appID int64) (app *entity.APP, err error)
DeleteDraftAPP(ctx context.Context, appID int64) (err error)
UpdateDraftAPP(ctx context.Context, req *UpdateDraftAPPRequest) (err error)
GetDraftAPPResources(ctx context.Context, appID int64) (resources []*entity.Resource, err error)
PublishAPP(ctx context.Context, req *PublishAPPRequest) (resp *PublishAPPResponse, err error)
GetAPPPublishRecord(ctx context.Context, req *GetAPPPublishRecordRequest) (record *entity.PublishRecord, published bool, err error)
GetAPPAllPublishRecords(ctx context.Context, appID int64) (records []*entity.PublishRecord, err error)
GetPublishConnectorList(ctx context.Context, req *GetPublishConnectorListRequest) (resp *GetPublishConnectorListResponse, err error)
}
type CreateDraftAPPRequest struct {
SpaceID int64
OwnerID int64
Name string
Desc string
IconURI string
}
type UpdateDraftAPPRequest struct {
APPID int64
Name *string
Desc *string
IconURI *string
}
type DuplicateDraftAPPRequest struct {
APPID int64
Name string
Desc string
IconURI string
}
type PublishAPPRequest struct {
APPID int64
Version string
VersionDesc string
ConnectorPublishConfigs map[int64]entity.PublishConfig
}
type PublishAPPResponse struct {
PublishRecordID int64
Success bool
}
type GetAPPPublishRecordRequest struct {
APPID int64
RecordID *int64
Oldest bool // Get the oldest record if Oldest is true and RecordID is nil; otherwise, get the latest record
}
type GetPublishConnectorListRequest struct {
}
type GetPublishConnectorListResponse struct {
Connectors []*connectorModel.Connector
}

View File

@@ -0,0 +1,214 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package service
import (
"context"
"sort"
"gorm.io/gorm"
connectorModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/connector"
databaseModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
knowledgeModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossconnector"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossdatabase"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossknowledge"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossplugin"
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
"github.com/coze-dev/coze-studio/backend/domain/app/repository"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/types/errno"
)
type Components struct {
IDGen idgen.IDGenerator
DB *gorm.DB
APPRepo repository.AppRepository
}
func NewService(components *Components) AppService {
return &appServiceImpl{
Components: components,
}
}
type appServiceImpl struct {
*Components
}
func (a *appServiceImpl) CreateDraftAPP(ctx context.Context, req *CreateDraftAPPRequest) (appID int64, err error) {
app := &entity.APP{
SpaceID: req.SpaceID,
Name: &req.Name,
Desc: &req.Desc,
IconURI: &req.IconURI,
OwnerID: req.OwnerID,
}
appID, err = a.APPRepo.CreateDraftAPP(ctx, app)
if err != nil {
return 0, errorx.Wrapf(err, "CreateDraftAPP failed, spaceID=%d", req.SpaceID)
}
return appID, nil
}
func (a *appServiceImpl) GetDraftAPP(ctx context.Context, appID int64) (app *entity.APP, err error) {
app, exist, err := a.APPRepo.GetDraftAPP(ctx, appID)
if err != nil {
return nil, err
}
if !exist {
return nil, errorx.New(errno.ErrAppRecordNotFound)
}
return app, nil
}
func (a *appServiceImpl) DeleteDraftAPP(ctx context.Context, appID int64) (err error) {
err = a.APPRepo.DeleteDraftAPP(ctx, appID)
if err != nil {
return errorx.Wrapf(err, "DeleteDraftAPP failed, appID=%d", appID)
}
return nil
}
func (a *appServiceImpl) UpdateDraftAPP(ctx context.Context, req *UpdateDraftAPPRequest) (err error) {
app := &entity.APP{
ID: req.APPID,
Name: req.Name,
Desc: req.Desc,
IconURI: req.IconURI,
}
err = a.APPRepo.UpdateDraftAPP(ctx, app)
if err != nil {
return errorx.Wrapf(err, "UpdateDraftAPP failed, appID=%d", req.APPID)
}
return nil
}
func (a *appServiceImpl) GetAPPPublishRecord(ctx context.Context, req *GetAPPPublishRecordRequest) (record *entity.PublishRecord, exist bool, err error) {
record, exist, err = a.APPRepo.GetPublishRecord(ctx, &repository.GetPublishRecordRequest{
APPID: req.APPID,
RecordID: req.RecordID,
OldestSuccess: req.Oldest,
})
if err != nil {
return nil, false, errorx.Wrapf(err, "GetPublishRecord failed, appID=%d", req.APPID)
}
return record, exist, nil
}
func (a *appServiceImpl) GetAPPAllPublishRecords(ctx context.Context, appID int64) (records []*entity.PublishRecord, err error) {
records, err = a.APPRepo.GetAPPAllPublishRecords(ctx, appID,
repository.WithAPPID(),
repository.WithPublishRecordID(),
repository.WithAPPPublishAtMS(),
repository.WithPublishVersion(),
repository.WithAPPPublishStatus(),
repository.WithPublishRecordExtraInfo(),
)
if err != nil {
return nil, errorx.Wrapf(err, "GetAPPAllPublishRecords failed, appID=%d", appID)
}
sort.Slice(records, func(i, j int) bool {
return records[i].APP.GetPublishedAtMS() > records[j].APP.GetPublishedAtMS()
})
for _, r := range records {
sort.Slice(r.ConnectorPublishRecords, func(i, j int) bool {
return r.ConnectorPublishRecords[i].ConnectorID < r.ConnectorPublishRecords[j].ConnectorID
})
}
return records, nil
}
func (a *appServiceImpl) GetPublishConnectorList(ctx context.Context, _ *GetPublishConnectorListRequest) (resp *GetPublishConnectorListResponse, err error) {
connectorMap, err := crossconnector.DefaultSVC().GetByIDs(ctx, entity.ConnectorIDWhiteList)
if err != nil {
return nil, errorx.Wrapf(err, "GetByIDs failed, ids=%v", entity.ConnectorIDWhiteList)
}
connectorList := make([]*connectorModel.Connector, 0, len(connectorMap))
for _, v := range connectorMap {
connectorList = append(connectorList, v)
}
sort.Slice(connectorList, func(i, j int) bool {
return connectorList[i].ID < connectorList[j].ID
})
resp = &GetPublishConnectorListResponse{
Connectors: connectorList,
}
return resp, nil
}
func (a *appServiceImpl) GetDraftAPPResources(ctx context.Context, appID int64) (resources []*entity.Resource, err error) {
plugins, err := crossplugin.DefaultSVC().GetAPPAllPlugins(ctx, appID)
if err != nil {
return nil, errorx.Wrapf(err, "GetAPPAllPlugins failed, appID=%d", appID)
}
databaseRes, err := crossdatabase.DefaultSVC().GetAllDatabaseByAppID(ctx, &databaseModel.GetAllDatabaseByAppIDRequest{
AppID: appID,
})
if err != nil {
return nil, errorx.Wrapf(err, "GetAllDatabaseByAppID failed, appID=%d", appID)
}
knowledgeRes, err := crossknowledge.DefaultSVC().ListKnowledge(ctx, &knowledgeModel.ListKnowledgeRequest{
AppID: &appID,
})
if err != nil {
return nil, errorx.Wrapf(err, "ListKnowledge failed, appID=%d", appID)
}
resources = make([]*entity.Resource, 0, len(plugins)+len(databaseRes.Databases)+len(knowledgeRes.KnowledgeList))
for _, pl := range plugins {
resources = append(resources, &entity.Resource{
ResID: pl.ID,
ResName: pl.GetName(),
ResType: entity.ResourceTypeOfPlugin,
})
}
for _, db := range databaseRes.Databases {
resources = append(resources, &entity.Resource{
ResID: db.ID,
ResName: db.TableName,
ResType: entity.ResourceTypeOfDatabase,
})
}
for _, kl := range knowledgeRes.KnowledgeList {
resources = append(resources, &entity.Resource{
ResID: kl.ID,
ResName: kl.Name,
ResType: entity.ResourceTypeOfKnowledge,
})
}
return resources, nil
}