86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
package source
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/tiger1103/gfast/v3/api/v1/common/globe"
|
|
"github.com/tiger1103/gfast/v3/api/v1/common/source/clt"
|
|
"github.com/tiger1103/gfast/v3/api/v1/common/source/pak"
|
|
"github.com/tiger1103/gfast/v3/database"
|
|
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
|
"path"
|
|
)
|
|
|
|
func InitSource(group *ghttp.RouterGroup) {
|
|
ReadAllSourceFromDB()
|
|
group.Group("/data/service", func(group *ghttp.RouterGroup) {
|
|
group.Bind(new(LoadSource))
|
|
})
|
|
}
|
|
|
|
type LoadSource struct {
|
|
}
|
|
type LoadSourceReq struct {
|
|
g.Meta `path:"load-compact-service" summary:"引擎加载资源" method:"post" tags:"资源相关" `
|
|
SourceID string `json:"source_id" v:"required" dc:"资源id"`
|
|
}
|
|
type LoadSourceRes struct {
|
|
Type string `json:"type"`
|
|
Url string `json:"url"`
|
|
database.SourceInfo
|
|
}
|
|
|
|
func (LoadSource) LoadCompactService(ctx context.Context, req *LoadSourceReq) (res *LoadSourceRes, err error) {
|
|
obj := database.GetSourceDB(req.SourceID)
|
|
res = &LoadSourceRes{
|
|
Url: obj.Url,
|
|
Type: obj.Type,
|
|
}
|
|
res.North = obj.Info.North
|
|
res.West = obj.Info.West
|
|
res.East = obj.Info.East
|
|
res.South = obj.Info.South
|
|
res.ProFile = obj.Info.ProFile
|
|
res.TilingScheme = obj.Info.TilingScheme
|
|
res.MaxLevel = obj.Info.MaxLevel
|
|
res.MinLevel = obj.Info.MinLevel
|
|
return
|
|
}
|
|
|
|
func ReadAllSourceFromDB() {
|
|
var sources []database.SOURCE
|
|
var gfb []database.SOURCE
|
|
g.DB().Model(&database.SOURCE{})
|
|
ctx := gctx.New()
|
|
//模型
|
|
dao.QianqiMoxing.Ctx(ctx).Scan(&sources)
|
|
//光伏板
|
|
dao.QianqiGuangfuban.Ctx(ctx).Scan(&gfb)
|
|
sources = append(sources, gfb...)
|
|
for _, v := range sources {
|
|
suffix := path.Ext(v.SourcePath)
|
|
switch suffix {
|
|
case globe.CLT:
|
|
err, obj := clt.OpenClt(v.SourcePath, v.SourceID)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
marshal, _ := json.Marshal(obj)
|
|
fmt.Println(string(marshal), v.SourceID)
|
|
break
|
|
case globe.PAK:
|
|
err, obj := pak.OpenPak(v.SourcePath, v.SourceID)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
marshal, _ := json.Marshal(obj)
|
|
fmt.Println(string(marshal), v.SourceID)
|
|
break
|
|
}
|
|
}
|
|
}
|