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,176 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2023-07-31 11:45:12
// 生成路径: internal/app/system/logic/qianqi_redline.go
// 生成人gfast
// desc:红线
// company:云南奇讯科技有限公司
// ==========================================================================
package logic
import (
"context"
"errors"
"fmt"
"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/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"
"strings"
)
func init() {
service.RegisterQianqiRedline(New())
}
func New() *sQianqiRedline {
return &sQianqiRedline{}
}
type sQianqiRedline struct{}
func (s *sQianqiRedline) List(ctx context.Context, req *system.QianqiRedlineSearchReq) (listRes *system.QianqiRedlineSearchRes, err error) {
listRes = new(system.QianqiRedlineSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.QianqiRedline.Ctx(ctx).WithAll()
if req.ProjectId != "" {
m = m.Where(dao.QianqiRedline.Columns().ProjectId+" = ?", req.ProjectId)
}
if req.Name != "" {
m = m.Where(dao.QianqiRedline.Columns().Name+" like ?", "%"+req.Name+"%")
}
//创建时间模糊查询
if req.CreatedAt != "" {
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
m = m.Where(dao.QianqiRedline.Columns().CreatedAt+" like ?", "%"+date+"%")
}
if len(req.DateRange) != 0 {
m = m.Where(dao.QianqiRedline.Columns().CreatedAt+" >=? AND "+dao.QianqiRedline.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.QianqiRedlineInfoRes
if !req.NotInPlan {
m = m.Fields(system.QianqiRedlineSearchRes{}).Page(req.PageNum, req.PageSize)
} else {
m = m.Fields(system.QianqiRedlineSearchRes{}).
Where(dao.QianqiRedline.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.QianqiRedlineListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.QianqiRedlineListRes{
Id: v.Id,
ProjectId: v.ProjectId,
Name: v.Name,
SourceId: v.SourceId,
SourcePath: v.SourcePath,
SourceType: v.SourceType,
CreatedAt: v.CreatedAt,
}
}
})
return
}
func (s *sQianqiRedline) GetById(ctx context.Context, id int) (res *model.QianqiRedlineInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.QianqiRedline.Ctx(ctx).WithAll().Where(dao.QianqiRedline.Columns().Id, id).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取信息失败")
//获取创建人 更新人
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
infoRes := by.(model.QianqiRedlineInfoRes)
res = &infoRes
})
return
}
func (s *sQianqiRedline) Add(ctx context.Context, req *system.QianqiRedlineAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
var fileName = ""
var FilePath = ""
var sourceId = ""
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, "上传失败!")
}
fmt.Println(str)
//fmt.Println(file[i].Filename)
fileName = file[i].Filename
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)
}
count, _ := dao.QianqiRedline.Ctx(ctx).Where(dao.QianqiRedline.Columns().SourceId, sourceId).Count()
if count == 0 {
_, err = dao.QianqiRedline.Ctx(ctx).Insert(&do.QianqiRedline{
ProjectId: req.ProjectId,
Name: strings.Split(fileName, ".")[0],
SourceId: sourceId,
SourcePath: FilePath,
CreateBy: ct.New().GetLoginUser(ctx).Id,
})
liberr.ErrIsNil(ctx, err, "添加失败")
}
})
return
}
func (s *sQianqiRedline) Edit(ctx context.Context, req *system.QianqiRedlineEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
name := ct.New().GetLoginUser(ctx).Id
_, err = dao.QianqiRedline.Ctx(ctx).WherePri(req.Id).Update(do.QianqiRedline{
//ProjectId: req.ProjectId,
Name: req.Name,
//SourceId: req.SourceId,
//SourcePath: req.SourcePath,
UpdateBy: name,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sQianqiRedline) Delete(ctx context.Context, ids []int) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.QianqiRedline.Ctx(ctx).Unscoped().Delete(dao.QianqiRedline.Columns().Id+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}