- 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
47 lines
1.4 KiB
Go
Executable File
47 lines
1.4 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 _ InvStockImportLogModel = (*customInvStockImportLogModel)(nil)
|
|
|
|
type (
|
|
InvStockImportLogModel interface {
|
|
invStockImportLogModel
|
|
FindList(ctx context.Context, tenantId string, page, pageSize int64) ([]*InvStockImportLog, int64, error)
|
|
}
|
|
|
|
customInvStockImportLogModel struct {
|
|
*defaultInvStockImportLogModel
|
|
}
|
|
)
|
|
|
|
func NewInvStockImportLogModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) InvStockImportLogModel {
|
|
return &customInvStockImportLogModel{
|
|
defaultInvStockImportLogModel: newInvStockImportLogModel(conn, c, opts...),
|
|
}
|
|
}
|
|
|
|
func (m *customInvStockImportLogModel) FindList(ctx context.Context, tenantId string, page, pageSize int64) ([]*InvStockImportLog, int64, error) {
|
|
var total int64
|
|
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE tenant_id = ?", m.table)
|
|
err := m.QueryRowNoCacheCtx(ctx, &total, countQuery, tenantId)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
var list []*InvStockImportLog
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE tenant_id = ? ORDER BY created_at DESC LIMIT ? OFFSET ?", invStockImportLogRows, m.table)
|
|
err = m.QueryRowsNoCacheCtx(ctx, &list, query, tenantId, pageSize, (page-1)*pageSize)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
return list, total, nil
|
|
}
|