This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,29 @@
function start_parse(s) {
try {
let scenes = JSON.parse(s) || []
let nodes = []
scenes.scenes.forEach(scene => {
let arr = []
getNode(scene, arr)
nodes.push(...arr)
})
return JSON.stringify(nodes)
} catch (e) {
return e
}
}
function getNode(node, arr = [], parent_name = "") {
if (node.hasOwnProperty("children")) {//存在子节点
node.children.forEach(it => {
getNode(it, arr, node.name)
})
} else {
if (node.type === "element") {//在地球上会渲染的
let namearr = parent_name.split("_")
namearr.pop()
node.name = namearr.join(".")
arr.push(node)
}
}
}

View File

@ -0,0 +1,421 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2023-07-31 11:31:49
// 生成路径: internal/app/system/logic/qianqi_guangfuban.go
// 生成人gfast
// desc:光伏板模型
// company:云南奇讯科技有限公司
// ==========================================================================
package logic
import (
"context"
_ "embed"
"encoding/json"
"errors"
"fmt"
"github.com/dop251/goja"
"github.com/gogf/gf/v2/crypto/gmd5"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
shp2 "github.com/tiger1103/gfast/v3/api/v1/common/shp"
"github.com/tiger1103/gfast/v3/api/v1/common/source/clt"
tool2 "github.com/tiger1103/gfast/v3/api/v1/common/tool"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
"github.com/tomchavakis/geojson/geometry"
"github.com/tomchavakis/turf-go"
"github.com/tomchavakis/turf-go/constants"
"github.com/tomchavakis/turf-go/measurement"
"strconv"
"strings"
)
//go:embed parse_ids.js
var parse_ids string
func init() {
service.RegisterQianqiGuangfuban(New())
}
func New() *sQianqiGuangfuban {
return &sQianqiGuangfuban{}
}
type sQianqiGuangfuban struct{}
func (s *sQianqiGuangfuban) CorrectQueryFunc(ctx context.Context, req *system.CorrectQueryFuncReq) (res *system.CorrectQueryFuncRes, err error) {
res = new(system.CorrectQueryFuncRes)
err = g.DB().Model("qianqi_guangfuban_data").Where("").Where("guangfuban_source_id", req.GuangfubanSourceId).Scan(&res)
if err != nil {
err = errors.New("查询失败!")
return
} else {
return
}
}
func (s *sQianqiGuangfuban) CorrectFunc(ctx context.Context, req *system.CorrectFuncReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = g.DB().Model("qianqi_guangfuban_data").Ctx(ctx).
Where("guangfuban_source_id", req.GuangfubanSourceId).
Update(g.Map{"guangfuban_data": req.GuangfubanData})
liberr.ErrIsNil(ctx, err, "原始坐标信息反序列化失败")
})
return err
}
func (s *sQianqiGuangfuban) CaculateZuchuan(ctx context.Context, req *system.QianqiGuangfubanCalZuchuanReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
var list []model.QianqiGuangfubanListRes
err = dao.QianqiGuangfuban.Ctx(ctx).WithAll().Where(dao.QianqiGuangfuban.Columns().SourceId, req.SourceId).Fields(dao.QianqiGuangfuban.Columns()).Scan(&list)
liberr.ErrIsNil(ctx, err, "获取数据失败")
if len(list) == 0 {
liberr.ErrIsNil(ctx, err, "资源不存在")
}
if len(list[0].Detail) == 0 {
liberr.ErrIsNil(ctx, err, "请将模型平移到准确位置后再试")
}
if len(list[0].Src_point) == 0 {
liberr.ErrIsNil(ctx, err, "请将模型无原始参考点坐标,请添加原始参考点后再试")
}
type Detail struct {
Position shp2.Point
}
//得到模型最新中心坐标
dt := Detail{}
err = json.Unmarshal([]byte(list[0].Detail), &dt)
if err != nil {
liberr.ErrIsNil(ctx, err, "新坐标信息反序列化失败")
}
srcPoint := shp2.Point{}
err = json.Unmarshal([]byte(list[0].Src_point), &srcPoint)
if err != nil {
liberr.ErrIsNil(ctx, err, "原始坐标信息反序列化失败")
}
//得到原始中心点和新中心点的距离 以米未单位
distance, err := measurement.Distance(dt.Position.Lng, dt.Position.Lat, srcPoint.Lng, srcPoint.Lat, constants.UnitMeters)
if err != nil {
liberr.ErrIsNil(ctx, err, "参考点间距离计算失败")
}
//将科学计数法的转换成正常的数字
normal := fmt.Sprintf("%f", distance)
//measurement.RhumbDestination()
//从shp读取到组串数据
err, s2 := shp2.ReadShp(list[0].Zuchuan_path)
if err != nil {
liberr.ErrIsNil(ctx, err, "组串shp数据不存在")
}
for _, polyline := range s2.Polylines {
if polyline.Name == "G03.07.09" {
fmt.Println(polyline)
}
}
var gfbids []model.QianqiGuangfubanIdsListRes
err = dao.QianqiGuangfubanIds.Ctx(ctx).WithAll().Where(dao.QianqiGuangfubanIds.Columns().DevId, req.SourceId).
Fields(dao.QianqiGuangfubanIds.Columns()).Scan(&gfbids)
if len(gfbids) == 0 {
liberr.ErrIsNil(ctx, err, "组串id不存在")
}
var start, end geometry.Point
start.Lng = srcPoint.Lng
start.Lat = srcPoint.Lat
end.Lng = dt.Position.Lng
end.Lat = dt.Position.Lat
bearing, err := measurement.RhumbBearing(start, end, false)
if err != nil {
return
}
fmt.Println(normal, *bearing)
normalbearing := fmt.Sprintf("%f", *bearing)
_, _ = strconv.ParseFloat(normalbearing, 64)
for _, gfbid := range gfbids {
var sphere []float64
err = json.Unmarshal([]byte(gfbid.Sphere), &sphere)
if err != nil {
continue
}
//将xyz的坐标转换成wgs84
lng, lat, _ := tool2.Xyz2Wgs84(sphere[0], sphere[1], sphere[2])
var point geometry.Point
point.Lng = lng
point.Lat = lat
destination, err := measurement.RhumbDestination(point, distance, *bearing, constants.UnitMeters, map[string]interface{}{})
//destination, err := measurement.RhumbDestination(point, 2048200.953185, -153.13771370235122, constants.UnitMeters, map[string]interface{}{})
if err != nil {
return
}
if arr, ok := destination.Geometry.Coordinates.([]float64); ok {
final_point := geometry.Point{Lng: arr[0], Lat: arr[1]}
fmt.Println("平移前", point)
//fmt.Println("平移参数", normal, normalNumber, gfbid)
fmt.Println("平移后", arr, gfbid.Name)
for _, polyline := range s2.Polylines {
var polygon geometry.Polygon
var line geometry.LineString
for _, p1 := range polyline.Positions {
gp := geometry.Point{Lng: p1.Lng, Lat: p1.Lat}
line.Coordinates = append(line.Coordinates, gp)
}
polygon.Coordinates = append(polygon.Coordinates, line)
pointInPolygon, err := turf.PointInPolygon(final_point, polygon)
if err != nil {
continue
}
if pointInPolygon {
fmt.Println("找到了", gfbid.SourceId, polyline.Name)
break
}
}
}
//s2 := ref.Kind().String()
}
})
return
}
func (s *sQianqiGuangfuban) ImportZuchuan(ctx context.Context, req *system.QianqiGuangfubanImportZuchuanReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
file := req.File
str := ""
for i := range file {
str, err = coryCommon.UploadFile(ctx, file[i], coryCommon.LargeFileShp)
if err != nil {
liberr.ErrIsNil(ctx, err, "上传失败!")
}
}
arr := strings.Split(str, ".")
arr[len(arr)-1] = "shp"
pa := strings.Join(arr, ".")
_, err = dao.QianqiGuangfuban.Ctx(ctx).Where(dao.QianqiGuangfuban.Columns().SourceId, req.SourceId).Update(do.QianqiGuangfuban{
Zuchuan_path: strings.Join(arr, "."),
UpdateBy: ct.New().GetLoginUser(ctx).Id,
})
arr2 := strings.Split(str, "/")
//将组串 当作布板图
_, err = dao.QianqiBubantu.Ctx(ctx).Insert(&do.QianqiBubantu{
ProjectId: req.ProjectId,
Name: strings.Split(arr2[len(arr2)-1], ".")[0],
SourceId: gmd5.MustEncryptString(pa),
SourcePath: strings.Join(arr, "."),
CreateBy: ct.New().GetLoginUser(ctx).Id,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sQianqiGuangfuban) List(ctx context.Context, req *system.QianqiGuangfubanSearchReq) (listRes *system.QianqiGuangfubanSearchRes, err error) {
listRes = new(system.QianqiGuangfubanSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.QianqiGuangfuban.Ctx(ctx).WithAll()
if req.ProjectId != "" {
m = m.Where(dao.QianqiGuangfuban.Columns().ProjectId+" = ?", req.ProjectId)
}
if req.Name != "" {
m = m.Where(dao.QianqiGuangfuban.Columns().Name+" like ?", "%"+req.Name+"%")
}
//创建时间模糊查询
if req.CreatedAt != "" {
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
m = m.Where(dao.QianqiGuangfuban.Columns().CreatedAt+" like ?", "%"+date+"%")
}
if len(req.DateRange) != 0 {
m = m.Where(dao.QianqiGuangfuban.Columns().CreatedAt+" >=? AND "+dao.QianqiGuangfuban.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
}
listRes.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "name asc,id desc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.QianqiGuangfubanInfoRes
err = m.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.QianqiGuangfubanListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.QianqiGuangfubanListRes{
Id: v.Id,
ProjectId: v.ProjectId,
Name: v.Name,
SourcePath: v.SourcePath,
Detail: v.Detail,
SourceId: v.SourceId,
CreatedAt: v.CreatedAt,
SourceType: v.SourceType,
}
}
})
return
}
func (s *sQianqiGuangfuban) GetById(ctx context.Context, id int) (res *model.QianqiGuangfubanInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.QianqiGuangfuban.Ctx(ctx).WithAll().Where(dao.QianqiGuangfuban.Columns().Id, id).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取信息失败")
//获取创建人 更新人
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
infoRes := by.(model.QianqiGuangfubanInfoRes)
res = &infoRes
})
return
}
func (s *sQianqiGuangfuban) Add(ctx context.Context, req *system.QianqiGuangfubanAddReq) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
var fileName = ""
var FilePath = ""
var sourceId = ""
file := req.File
str, err := coryCommon.UploadFile(ctx, file, coryCommon.LargeFileClt)
if err != nil {
liberr.ErrIsNil(ctx, err, "上传失败!")
}
fileName = file.Filename
FilePath = str
encrypt, _ := gmd5.EncryptString(file.Filename)
sourceId = encrypt
count, err := dao.QianqiGuangfuban.Ctx(ctx).Where(dao.QianqiGuangfuban.Columns().SourceId, sourceId).Count()
if err != nil {
return
}
if count > 0 {
liberr.ErrIsNil(ctx, errors.New("资源已存在"))
return
} else {
CreateBy := ct.New().GetLoginUser(ctx).Id
_, err = dao.QianqiGuangfuban.Ctx(ctx).Insert(do.QianqiGuangfuban{
ProjectId: req.ProjectId,
Name: fileName,
SourcePath: FilePath,
Detail: req.Detail,
SourceId: sourceId,
CreateBy: CreateBy,
})
//建立连接
if err == nil {
clt.OpenClt(FilePath, sourceId)
//初始化光伏板纠正
//id, _ := qg.LastInsertId()
_, err = g.DB().Model("qianqi_guangfuban_data").Ctx(ctx).Insert(g.Map{"guangfuban_source_id": sourceId, "guangfuban_data": ""})
if err != nil {
liberr.ErrIsNil(ctx, errors.New("初始化数据失败!"))
return
}
}
tile := clt.GetTile(sourceId, "scenetree.json")
vm := goja.New()
vm.RunString(parse_ids)
var start_parse func(scenetree string) string
vm.ExportTo(vm.Get("start_parse"), &start_parse)
fmt.Println("开始转换", gtime.Datetime())
res := start_parse(string(tile))
var elements []model.Element
json.Unmarshal([]byte(res), &elements)
var eles []do.QianqiGuangfubanIds
for _, element := range elements {
if !strings.HasPrefix(element.Name, "G") {
continue
}
ele := do.QianqiGuangfubanIds{}
ele.DevId = sourceId
ele.Name = element.Name
ele.SourceId = element.Id
marshal, err := json.Marshal(element.Sphere)
if err != nil {
continue
}
ele.Sphere = string(marshal)
ele.CreateBy = CreateBy
ele.ProjectId = req.ProjectId
eles = append(eles, ele)
if len(eles) > 500 {
dao.QianqiGuangfubanIds.Ctx(ctx).Insert(eles)
eles = []do.QianqiGuangfubanIds{}
}
}
if len(eles) > 0 {
dao.QianqiGuangfubanIds.Ctx(ctx).Insert(eles)
}
fmt.Println("转换完成", gtime.Datetime())
liberr.ErrIsNil(ctx, err, "添加失败")
}
//name := ct.New().GetLoginUser(ctx).Id
})
return err
})
return
}
func (s *sQianqiGuangfuban) Edit(ctx context.Context, req *system.QianqiGuangfubanEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
//name := ct.New().GetLoginUser(ctx).Id
_, err = dao.QianqiGuangfuban.Ctx(ctx).WherePri(req.Id).Update(do.QianqiGuangfuban{
Name: req.Name,
Detail: req.Detail,
UpdateBy: ct.New().GetLoginUser(ctx).Id,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sQianqiGuangfuban) Delete(ctx context.Context, ids []string) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.QianqiGuangfuban.Ctx(ctx).Unscoped().Delete(dao.QianqiGuangfuban.Columns().SourceId+" in (?)", ids)
_, err = dao.QianqiGuangfubanIds.Ctx(ctx).Unscoped().Delete(dao.QianqiGuangfubanIds.Columns().DevId+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}
//func (c *sQianqiGuangfuban) gfbUpload(ctx context.Context, req *system.UploadFileBimReq) (res *system.UploadFileBimRes, err error) {
// // 初始化 res 变量
// res = &system.UploadFileBimRes{}
// file := req.File
// str, err := coryCommon.UploadFile(ctx, file, coryCommon.LargeFileBim)
// res.FileName = file.Filename
// res.FilePath = str
// return
//}