44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
// Package database define database operation functions
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"time"
|
|
|
|
"modelRT/config"
|
|
"modelRT/orm"
|
|
|
|
"github.com/panjf2000/ants/v2"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// LoadCircuitDiagramFromPostgresDB return the result of query circuit diagram info from postgresDB
|
|
func LoadCircuitDiagramFromPostgresDB(ctx context.Context, pool *ants.PoolWithFunc, logger *zap.Logger) error {
|
|
var circuitDiagramOverviews []orm.CircuitDiagramOverview
|
|
// ctx超时判断
|
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
defer cancel()
|
|
result := _globalPostgresClient.WithContext(cancelCtx).Find(&circuitDiagramOverviews)
|
|
if result.Error != nil {
|
|
logger.Error("query circuit diagram overview info failed", zap.Error(result.Error))
|
|
return result.Error
|
|
}
|
|
|
|
for _, overview := range circuitDiagramOverviews {
|
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
defer cancel()
|
|
var circuitDiagramInfos []orm.CircuitDiagram
|
|
tableName := "circuit_diagram_" + strconv.FormatInt(overview.ID, 10)
|
|
result := _globalPostgresClient.Table(tableName).WithContext(cancelCtx).Order("id asc").Find(&circuitDiagramInfos)
|
|
if result.Error != nil {
|
|
logger.Error("query circuit diagram detail infos failed", zap.Error(result.Error))
|
|
return result.Error
|
|
}
|
|
pool.Invoke(config.ModelParseConfig{
|
|
CircuitDiagramInfos: circuitDiagramInfos,
|
|
})
|
|
}
|
|
return nil
|
|
}
|