- JWT claims extended with tenantId; login enforces strict tenant verification - AuthorityMiddleware: tenant scope check + Casbin path permission + anti-spoofing - CRM relation API (upstream/downstream one-hop, create/update/history, full graph) - CrmRepo backed by PostgreSQL with $N placeholders - gRPC tenant propagation via UnaryClientInterceptor (x-tenant-id metadata) - All legacy tables (12) gain tenant_id column with indexes - All model queries inject WHERE tenant_id filter - Casbin gorm-adapter downgraded to v3.28.0 for v2 compatibility - GraphSyncWorker (Kafka -> Neo4j) with idempotent MERGE - Full graph API restricted to admin role only - Database migrations for MySQL (CRM tables + tenant columns) and PostgreSQL (CRM init) - Docker Compose: added postgres service to main stack, graph stack with Kafka/Debezium/Neo4j Made-with: Cursor
57 lines
1.7 KiB
Go
Executable File
57 lines
1.7 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ SysConfigModel = (*customSysConfigModel)(nil)
|
|
|
|
type (
|
|
SysConfigModel interface {
|
|
sysConfigModel
|
|
FindByGroup(ctx context.Context, tenantId, group string) ([]*SysConfig, error)
|
|
FindAll(ctx context.Context, tenantId string) ([]*SysConfig, error)
|
|
UpdateByKey(ctx context.Context, tenantId, key, value string) error
|
|
}
|
|
|
|
customSysConfigModel struct {
|
|
*defaultSysConfigModel
|
|
}
|
|
)
|
|
|
|
func NewSysConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) SysConfigModel {
|
|
return &customSysConfigModel{
|
|
defaultSysConfigModel: newSysConfigModel(conn, c, opts...),
|
|
}
|
|
}
|
|
|
|
func (m *customSysConfigModel) FindByGroup(ctx context.Context, tenantId, group string) ([]*SysConfig, error) {
|
|
var list []*SysConfig
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE tenant_id = ? AND `config_group` = ?", sysConfigRows, m.table)
|
|
err := m.QueryRowsNoCacheCtx(ctx, &list, query, tenantId, group)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func (m *customSysConfigModel) FindAll(ctx context.Context, tenantId string) ([]*SysConfig, error) {
|
|
var list []*SysConfig
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE tenant_id = ?", sysConfigRows, m.table)
|
|
err := m.QueryRowsNoCacheCtx(ctx, &list, query, tenantId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func (m *customSysConfigModel) UpdateByKey(ctx context.Context, tenantId, key, value string) error {
|
|
query := fmt.Sprintf("UPDATE %s SET `config_value` = ? WHERE tenant_id = ? AND `config_key` = ?", m.table)
|
|
_, err := m.ExecNoCacheCtx(ctx, query, value, tenantId, key)
|
|
return err
|
|
}
|