初始
This commit is contained in:
214
internal/app/system/logic/qianqiRoad/qianqi_road.go
Normal file
214
internal/app/system/logic/qianqiRoad/qianqi_road.go
Normal file
@ -0,0 +1,214 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-08-04 16:24:38
|
||||
// 生成路径: internal/app/system/logic/qianqi_road.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.RegisterQianqiRoad(New())
|
||||
}
|
||||
|
||||
func New() *sQianqiRoad {
|
||||
return &sQianqiRoad{}
|
||||
}
|
||||
|
||||
type sQianqiRoad struct{}
|
||||
|
||||
func (s *sQianqiRoad) List(ctx context.Context, req *system.QianqiRoadSearchReq) (listRes *system.QianqiRoadSearchRes, err error) {
|
||||
listRes = new(system.QianqiRoadSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.QianqiRoad.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.QianqiRoad.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.QianqiRoad.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.QianqiRoad.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.SourceId != "" {
|
||||
m = m.Where(dao.QianqiRoad.Columns().SourceId+" = ?", req.SourceId)
|
||||
}
|
||||
if req.SourcePath != "" {
|
||||
m = m.Where(dao.QianqiRoad.Columns().SourcePath+" = ?", req.SourcePath)
|
||||
}
|
||||
if req.CreateBy != "" {
|
||||
m = m.Where(dao.QianqiRoad.Columns().CreateBy+" = ?", req.CreateBy)
|
||||
}
|
||||
if req.UpdateBy != "" {
|
||||
m = m.Where(dao.QianqiRoad.Columns().UpdateBy+" = ?", req.UpdateBy)
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.QianqiRoad.Columns().CreatedAt+" >=? AND "+dao.QianqiRoad.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
if req.SourceType != "" {
|
||||
m = m.Where(dao.QianqiRoad.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.QianqiRoadInfoRes
|
||||
//err = m.Fields(system.QianqiRoadSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
if !req.NotInPlan {
|
||||
m = m.Fields(system.QianqiRoadSearchRes{}).Page(req.PageNum, req.PageSize)
|
||||
} else {
|
||||
m = m.Fields(system.QianqiRoadSearchRes{}).Where(dao.QianqiRoad.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.QianqiRoadListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.QianqiRoadListRes{
|
||||
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 *sQianqiRoad) GetById(ctx context.Context, id int) (res *model.QianqiRoadInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.QianqiRoad.Ctx(ctx).WithAll().Where(dao.QianqiRoad.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiRoad) Add(ctx context.Context, req *system.QianqiRoadAddReq) (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.QianqiRoad
|
||||
for i, p := range s2.Polylines {
|
||||
//将方阵的名称 作为方阵的id
|
||||
//sourceId := gmd5.MustEncryptString(p.Name)
|
||||
road := do.QianqiRoad{}
|
||||
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)
|
||||
|
||||
//判断是否已经存在了该方阵,存在了就不再添加
|
||||
//count, _ := dao.QianqiFangzhen.Ctx(ctx).Where(dao.QianqiFangzhen.Columns().SourceId, sourceId).Count()
|
||||
//if count == 0 {
|
||||
// marshal, err := json.Marshal(p)
|
||||
// if err != nil {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
//}
|
||||
}
|
||||
if len(arr) > 0 {
|
||||
_, err = dao.QianqiRoad.Ctx(ctx).Insert(&arr)
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
}
|
||||
//_, err = dao.QianqiRoad.Ctx(ctx).Insert(do.QianqiRoad{
|
||||
// ProjectId: req.ProjectId,
|
||||
//})
|
||||
//liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiRoad) Edit(ctx context.Context, req *system.QianqiRoadEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiRoad.Ctx(ctx).WherePri(req.Id).Update(do.QianqiRoad{
|
||||
Name: req.Name,
|
||||
SourceType: req.SourceType,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sQianqiRoad) Delete(ctx context.Context, ids []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.QianqiRoad.Ctx(ctx).Unscoped().Delete(dao.QianqiRoad.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user