初始
This commit is contained in:
139
internal/app/system/logic/sysFile/sys_file.go
Normal file
139
internal/app/system/logic/sysFile/sys_file.go
Normal file
@ -0,0 +1,139 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-29 15:32:09
|
||||
// 生成路径: internal/app/system/logic/sys_file.go
|
||||
// 生成人:gfast
|
||||
// desc:文件
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterSysFile(New())
|
||||
}
|
||||
|
||||
func New() *sSysFile {
|
||||
return &sSysFile{}
|
||||
}
|
||||
|
||||
type sSysFile struct{}
|
||||
|
||||
func (s *sSysFile) List(ctx context.Context, req *system.SysFileSearchReq) (listRes *system.SysFileSearchRes, err error) {
|
||||
listRes = new(system.SysFileSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.SysFile.Ctx(ctx).WithAll()
|
||||
if req.FileName != "" {
|
||||
m = m.Where(dao.SysFile.Columns().FileName+" like ?", "%"+req.FileName+"%")
|
||||
}
|
||||
if req.Status != "" {
|
||||
m = m.Where(dao.SysFile.Columns().Status+" = ?", req.Status)
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.SysFile.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.SysFile.Columns().CreatedAt+" >=? AND "+dao.SysFile.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 := "file_id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.SysFileInfoRes
|
||||
err = m.Fields(system.SysFileSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.SysFileListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.SysFileListRes{
|
||||
FileId: v.FileId,
|
||||
ParentId: v.ParentId,
|
||||
Ancestors: v.Ancestors,
|
||||
FileName: v.FileName,
|
||||
OrderNum: v.OrderNum,
|
||||
ProjectId: v.ProjectId,
|
||||
FileTypeId: v.FileTypeId,
|
||||
Leader: v.Leader,
|
||||
Status: v.Status,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysFile) GetByFileId(ctx context.Context, fileId int) (res *model.SysFileInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.SysFile.Ctx(ctx).WithAll().Where(dao.SysFile.Columns().FileId, fileId).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.SysFileInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysFile) Add(ctx context.Context, req *system.SysFileAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.SysFile.Ctx(ctx).Insert(do.SysFile{
|
||||
ParentId: req.ParentId,
|
||||
FileName: req.FileName,
|
||||
ProjectId: req.ProjectId,
|
||||
FileTypeId: req.FileTypeId,
|
||||
CreateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysFile) Edit(ctx context.Context, req *system.SysFileEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
_, err = dao.SysFile.Ctx(ctx).WherePri(req.FileId).Update(do.SysFile{
|
||||
ParentId: req.ParentId,
|
||||
FileName: req.FileName,
|
||||
ProjectId: req.ProjectId,
|
||||
FileTypeId: req.FileTypeId,
|
||||
UpdateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysFile) Delete(ctx context.Context, fileIds []int) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.SysFile.Ctx(ctx).Delete(dao.SysFile.Columns().FileId+" in (?)", fileIds)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user