初始
This commit is contained in:
197
internal/app/system/logic/busFolder/bus_folder.go
Normal file
197
internal/app/system/logic/busFolder/bus_folder.go
Normal file
@ -0,0 +1,197 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-09-15 17:15:59
|
||||
// 生成路径: internal/app/system/logic/bus_folder.go
|
||||
// 生成人:gfast
|
||||
// desc:文件夹
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"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.RegisterBusFolder(New())
|
||||
}
|
||||
|
||||
func New() *sBusFolder {
|
||||
return &sBusFolder{}
|
||||
}
|
||||
|
||||
type sBusFolder struct{}
|
||||
|
||||
type minOrMax struct {
|
||||
Min string `json:"min"`
|
||||
Max string `json:"max"`
|
||||
}
|
||||
|
||||
func (s *sBusFolder) TreeFormListFunc(ctx context.Context, req *system.TreeFormListFuncReq) (listRes *system.TreeFormListFuncRes, err error) {
|
||||
listRes = new(system.TreeFormListFuncRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusFolder.Ctx(ctx).WithAll()
|
||||
//if req.Name != "" {
|
||||
// m = m.Where(dao.BusFolder.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
//}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where("(project_id = ? or folder_type = '0')", req.ProjectId)
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusFolder.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
order := "sort desc,id desc"
|
||||
var res []*model.BusFolderInfoRes
|
||||
err = m.Fields(system.BusFolderSearchRes{}).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusFolderListRes, len(res))
|
||||
for k, v := range res {
|
||||
var qp []string
|
||||
if v.FolderType == "0" {
|
||||
//生成虚拟日期树形结构文件夹;获取到当前文件夹下面最小和最大的时间日期
|
||||
var mm *minOrMax
|
||||
err = dao.BusFolderFile.Ctx(ctx).Where("folder_id", v.Id).Fields("min(DATE_FORMAT(created_at,'%Y-%m')) as min,max(DATE_FORMAT(created_at,'%Y-%m')) as max").Scan(&mm)
|
||||
if mm != nil {
|
||||
qp = tool.RangeTime(mm.Min, mm.Max)
|
||||
}
|
||||
}
|
||||
|
||||
listRes.List[k] = &model.BusFolderListRes{
|
||||
Id: v.Id,
|
||||
FolderType: v.FolderType,
|
||||
Icon: v.Icon,
|
||||
Name: v.Name,
|
||||
Remark: v.Remark,
|
||||
CreatedAt: v.CreatedAt,
|
||||
QiePian: qp,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolder) List(ctx context.Context, req *system.BusFolderSearchReq) (listRes *system.BusFolderSearchRes, err error) {
|
||||
listRes = new(system.BusFolderSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusFolder.Ctx(ctx).WithAll()
|
||||
if req.TypeNum == 1 {
|
||||
m = m.Where(dao.BusFolder.Columns().Father, 0)
|
||||
}
|
||||
if req.TypeNum == 2 {
|
||||
m = m.Where(dao.BusFolder.Columns().Father, req.FatherId)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.BusFolder.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where("(project_id = ? or folder_type = '0')", req.ProjectId)
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusFolder.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusFolder.Columns().CreatedAt+" >=? AND "+dao.BusFolder.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 := "sort desc,id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusFolderInfoRes
|
||||
err = m.Fields(system.BusFolderSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusFolderListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusFolderListRes{
|
||||
Id: v.Id,
|
||||
FolderType: v.FolderType,
|
||||
Icon: v.Icon,
|
||||
Name: v.Name,
|
||||
Remark: v.Remark,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolder) GetById(ctx context.Context, id int64) (res *model.BusFolderInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusFolder.Ctx(ctx).WithAll().Where(dao.BusFolder.Columns().Id, id).Scan(&res)
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusFolderInfoRes)
|
||||
res = &infoRes
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolder) Add(ctx context.Context, req *system.BusFolderAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusFolder.Ctx(ctx).Insert(do.BusFolder{
|
||||
Icon: req.Icon,
|
||||
Name: req.Name,
|
||||
Remark: req.Remark,
|
||||
ProjectId: req.ProjectId,
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolder) Edit(ctx context.Context, req *system.BusFolderEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusFolder.Ctx(ctx).WherePri(req.Id).Update(do.BusFolder{
|
||||
Icon: req.Icon,
|
||||
Name: req.Name,
|
||||
Remark: req.Remark,
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolder) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
for _, id := range ids {
|
||||
num, _ := dao.BusFolder.Ctx(ctx).WherePri(id).Fields("folder_type").Value()
|
||||
if num.String() == "0" {
|
||||
err = errors.New("系统文件不可删除!")
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
_, err = dao.BusFolder.Ctx(ctx).Delete(dao.BusFolder.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user