初始
This commit is contained in:
188
internal/app/system/logic/qianqiMoxing/qianqi_moxing.go
Normal file
188
internal/app/system/logic/qianqiMoxing/qianqi_moxing.go
Normal file
@ -0,0 +1,188 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-31 11:09:26
|
||||
// 生成路径: internal/app/system/logic/qianqi_moxing.go
|
||||
// 生成人:gfast
|
||||
// desc:倾斜模型
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/coryCommon"
|
||||
"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/mbt"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/common/source/pak"
|
||||
"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"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterQianqiMoxing(New())
|
||||
}
|
||||
|
||||
func New() *sQianqiMoxing {
|
||||
return &sQianqiMoxing{}
|
||||
}
|
||||
|
||||
type sQianqiMoxing struct{}
|
||||
|
||||
func (s *sQianqiMoxing) List(ctx context.Context, req *system.QianqiMoxingSearchReq) (listRes *system.QianqiMoxingSearchRes, err error) {
|
||||
listRes = new(system.QianqiMoxingSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiMoxing.Ctx(ctx).WithAll()
|
||||
if req.ProjectId != "" { //默认带上公共的全国地形
|
||||
m = m.Where(dao.QianqiMoxing.Columns().ProjectId+" = ?", req.ProjectId).
|
||||
WhereOr(dao.QianqiMoxing.Columns().ProjectId+" = ?", 0)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.QianqiMoxing.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.QianqiMoxing.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.QianqiMoxing.Columns().CreatedAt+" >=? AND "+dao.QianqiMoxing.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.QianqiMoxingInfoRes
|
||||
err = m.Fields(system.QianqiMoxingSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.QianqiMoxingListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.QianqiMoxingListRes{
|
||||
Id: v.Id,
|
||||
ProjectId: v.ProjectId,
|
||||
Name: v.Name,
|
||||
SourcePath: v.SourcePath,
|
||||
Detail: v.Detail,
|
||||
SourceId: v.SourceId,
|
||||
CreatedAt: v.CreatedAt,
|
||||
SourceType: "tileset",
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiMoxing) GetById(ctx context.Context, id int) (res *model.QianqiMoxingInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.QianqiMoxing.Ctx(ctx).WithAll().Where(dao.QianqiMoxing.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.QianqiMoxingInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiMoxing) Add(ctx context.Context, req *system.QianqiMoxingAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
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
|
||||
}
|
||||
if strings.HasPrefix(req.SourcePath, "/") {
|
||||
req.SourcePath = strings.Replace(req.SourcePath, "/", "", 1)
|
||||
}
|
||||
sourceId := gmd5.MustEncryptString(req.SourcePath)
|
||||
count, _ := dao.QianqiMoxing.Ctx(ctx).Where(dao.QianqiMoxing.Columns().SourceId, sourceId).Count()
|
||||
if count == 0 {
|
||||
_, err = dao.QianqiMoxing.Ctx(ctx).Insert(&do.QianqiMoxing{
|
||||
ProjectId: req.ProjectId,
|
||||
Name: req.Name,
|
||||
SourceId: sourceId,
|
||||
SourcePath: req.SourcePath,
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
if err == nil {
|
||||
suffix := path.Ext(req.SourcePath)
|
||||
switch suffix {
|
||||
case globe.CLT:
|
||||
clt.OpenClt(req.SourcePath, sourceId)
|
||||
break
|
||||
case globe.MBTILES:
|
||||
mbt.OpenMbt(req.SourcePath, sourceId)
|
||||
break
|
||||
case globe.PAK:
|
||||
pak.OpenPak(req.SourcePath, sourceId)
|
||||
}
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
}
|
||||
//name := ct.New().GetLoginUser(ctx).Id
|
||||
//_, err = dao.QianqiMoxing.Ctx(ctx).Insert(do.QianqiMoxing{
|
||||
// ProjectId: req.ProjectId,
|
||||
// Name: fileName,
|
||||
// SourcePath: FilePath,
|
||||
// SourceId: sourceId,
|
||||
// CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
//})
|
||||
//建立连接
|
||||
//if err == nil {
|
||||
// clt.OpenClt(FilePath, sourceId)
|
||||
//}
|
||||
//liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiMoxing) Edit(ctx context.Context, req *system.QianqiMoxingEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.QianqiMoxing.Ctx(ctx).WherePri(req.Id).Update(do.QianqiMoxing{
|
||||
//ProjectId: req.ProjectId,
|
||||
Name: req.Name,
|
||||
//SourcePath: req.SourcePath,
|
||||
Detail: req.Detail,
|
||||
//SourceId: req.SourceId,
|
||||
CreateBy: "1",
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiMoxing) Delete(ctx context.Context, ids []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiMoxing.Ctx(ctx).Unscoped().Delete(dao.QianqiMoxing.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user