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,198 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2023-08-04 16:29:44
// 生成路径: internal/app/system/logic/qianqi_jidianxianlu.go
// 生成人gfast
// desc:集电线路
// company:云南奇讯科技有限公司
// ==========================================================================
package logic
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
"github.com/tiger1103/gfast/v3/api/v1/common/shp"
"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"
"strconv"
"strings"
"time"
)
func init() {
service.RegisterQianqiJidianxianlu(New())
}
func New() *sQianqiJidianxianlu {
return &sQianqiJidianxianlu{}
}
type sQianqiJidianxianlu struct{}
func (s *sQianqiJidianxianlu) List(ctx context.Context, req *system.QianqiJidianxianluSearchReq) (listRes *system.QianqiJidianxianluSearchRes, err error) {
listRes = new(system.QianqiJidianxianluSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.QianqiJidianxianlu.Ctx(ctx).WithAll()
if req.Id != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().Id+" = ?", req.Id)
}
if req.ProjectId != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().ProjectId+" = ?", req.ProjectId)
}
if req.Name != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().Name+" like ?", "%"+req.Name+"%")
}
if req.SourceId != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().SourceId+" = ?", req.SourceId)
}
if req.SourcePath != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().SourcePath+" = ?", req.SourcePath)
}
if req.CreateBy != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().CreateBy+" = ?", req.CreateBy)
}
if req.UpdateBy != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().UpdateBy+" = ?", req.UpdateBy)
}
if len(req.DateRange) != 0 {
m = m.Where(dao.QianqiJidianxianlu.Columns().CreatedAt+" >=? AND "+dao.QianqiJidianxianlu.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
}
if req.SourceType != "" {
m = m.Where(dao.QianqiJidianxianlu.Columns().SourceType+" = ?", req.SourceType)
}
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.QianqiJidianxianluInfoRes
if !req.NotInPlan {
m = m.Fields(system.QianqiJidianxianluSearchRes{}).Page(req.PageNum, req.PageSize)
} else {
m = m.Fields(system.QianqiJidianxianluSearchRes{}).Where(dao.QianqiJidianxianlu.Columns().SourceId+" not in(select source_id from "+dao.PlanWeek.Table()+" where project_id=?)", req.ProjectId)
}
err = m.Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.QianqiJidianxianluListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.QianqiJidianxianluListRes{
Id: v.Id,
ProjectId: v.ProjectId,
Name: v.Name,
SourceId: v.SourceId,
SourcePath: v.SourcePath,
CreateBy: v.CreateBy,
UpdateBy: v.UpdateBy,
CreatedAt: v.CreatedAt,
SourceType: v.SourceType,
Detail: v.Detail,
}
}
})
return
}
func (s *sQianqiJidianxianlu) GetById(ctx context.Context, id int) (res *model.QianqiJidianxianluInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.QianqiJidianxianlu.Ctx(ctx).WithAll().Where(dao.QianqiJidianxianlu.Columns().Id, id).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取信息失败")
})
return
}
func (s *sQianqiJidianxianlu) Add(ctx context.Context, req *system.QianqiJidianxianluAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
var FilePath = ""
res, e := service.SysProject().GetByProjectId(ctx, req.ProjectId)
if e != nil {
liberr.ErrIsNil(ctx, e)
return
}
if res == nil {
liberr.ErrIsNil(ctx, errors.New("项目不存在"))
return
}
file := req.File
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"
FilePath = strings.Join(arr, ".")
//FilePath = strings.Join(split[:len(split)-1], "/") //strings.Replace(, "/resource/public", "/file", -1)
//sourceId, _ = gmd5.EncryptString(FilePath)
}
//需要读取方阵里面的信息
err1, s2 := shp.ReadShp(FilePath)
if err1 != nil {
liberr.ErrIsNil(ctx, err1)
}
fmt.Println(len(s2.Polylines))
CreateBy := ct.New().GetLoginUser(ctx).Id
var arr []do.QianqiJidianxianlu
for i, p := range s2.Polylines {
road := do.QianqiJidianxianlu{}
road.ProjectId = req.ProjectId
road.SourceId = tool.GetUuid()
road.SourcePath = FilePath
road.CreateBy = CreateBy
marshal, err := json.Marshal(p)
if err != nil {
continue
}
road.Detail = string(marshal)
road.Name = "默认线路名称" + strconv.Itoa(i)
time.Sleep(time.Millisecond)
arr = append(arr, road)
}
if len(arr) > 0 {
_, err = dao.QianqiJidianxianlu.Ctx(ctx).Insert(&arr)
liberr.ErrIsNil(ctx, err, "添加失败")
}
})
return
}
func (s *sQianqiJidianxianlu) Edit(ctx context.Context, req *system.QianqiJidianxianluEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.QianqiJidianxianlu.Ctx(ctx).WherePri(req.Id).Update(do.QianqiJidianxianlu{
Name: req.Name,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sQianqiJidianxianlu) Delete(ctx context.Context, ids []int) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.QianqiJidianxianlu.Ctx(ctx).Unscoped().Delete(dao.QianqiJidianxianlu.Columns().Id+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}