初始
This commit is contained in:
246
internal/app/system/logic/busFolderFile/bus_folder_file.go
Normal file
246
internal/app/system/logic/busFolderFile/bus_folder_file.go
Normal file
@ -0,0 +1,246 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-09-15 17:16:00
|
||||
// 生成路径: internal/app/system/logic/bus_folder_file.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"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
controllerModel "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"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusFolderFile(New())
|
||||
}
|
||||
|
||||
func New() *sBusFolderFile {
|
||||
return &sBusFolderFile{}
|
||||
}
|
||||
|
||||
type sBusFolderFile struct{}
|
||||
|
||||
func (s *sBusFolderFile) List(ctx context.Context, req *system.BusFolderFileSearchReq) (listRes *system.BusFolderFileSearchRes, err error) {
|
||||
listRes = new(system.BusFolderFileSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusFolderFile.Ctx(ctx).WithAll()
|
||||
if req.FolderId != "" {
|
||||
m = m.Where(dao.BusFolderFile.Columns().FolderId, req.FolderId)
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.BusFolderFile.Columns().ProjectId, req.ProjectId)
|
||||
}
|
||||
if req.Name != "" {
|
||||
m = m.Where(dao.BusFolderFile.Columns().Name+" like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.Size != "" {
|
||||
m = m.Where(dao.BusFolderFile.Columns().Size+" = ?", req.Size)
|
||||
}
|
||||
if req.Suffix != "" {
|
||||
m = m.Where(dao.BusFolderFile.Columns().Suffix+" = ?", req.Suffix)
|
||||
}
|
||||
//创建时间模糊查询 年月日
|
||||
if req.CreateAt != "" {
|
||||
m = m.Where(dao.BusEquipmentEquipmentUnpacking.Columns().CreatedAt+" like ?", "%"+req.CreateAt+"%")
|
||||
}
|
||||
//创建时间模糊查询 年月日时分秒
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusEquipmentEquipmentUnpacking.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusFolderFile.Columns().CreatedAt+" >=? AND "+dao.BusFolderFile.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 := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusFolderFileInfoRes
|
||||
err = m.Fields(system.BusFolderFileSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusFolderFileListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusFolderFileListRes{
|
||||
Id: v.Id,
|
||||
FolderId: v.FolderId,
|
||||
LinkedFolderId: v.LinkedFolderId,
|
||||
FileType: v.FileType,
|
||||
Name: v.Name,
|
||||
Size: v.Size,
|
||||
Suffix: v.Suffix,
|
||||
Remark: v.Remark,
|
||||
Path: v.Path,
|
||||
TableName: v.TableName,
|
||||
TableId: v.TableId,
|
||||
UserType: v.UserType,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolderFile) GetById(ctx context.Context, id int64) (res *model.BusFolderFileInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusFolderFile.Ctx(ctx).WithAll().Where(dao.BusFolderFile.Columns().Id, id).Scan(&res)
|
||||
if res.UserType == "1" {
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusFolderFileInfoRes)
|
||||
res = &infoRes
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolderFile) Add(ctx context.Context, req *system.BusFolderFileAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusFolderFile.Ctx(ctx).Insert(do.BusFolderFile{
|
||||
ProjectId: req.ProjectId,
|
||||
FolderId: req.FolderId,
|
||||
FileType: "2",
|
||||
Name: req.Name,
|
||||
Size: req.Size,
|
||||
Suffix: req.Suffix,
|
||||
Path: req.Path,
|
||||
UserType: "1",
|
||||
Remark: req.Remark,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolderFile) Edit(ctx context.Context, req *system.BusFolderFileEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusFolderFile.Ctx(ctx).WherePri(req.Id).Update(do.BusFolderFile{
|
||||
FolderId: req.FolderId,
|
||||
FileType: req.FileType,
|
||||
Name: req.Name,
|
||||
Remark: req.Remark,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusFolderFile) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusFolderFile.Ctx(ctx).Delete(dao.BusFolderFile.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
AllPicture 通用图库上传
|
||||
picture:图片-数组
|
||||
folderId:当前图片的文件夹是谁
|
||||
tableName:哪张表的数据?表名
|
||||
tableId:哪张表的数据?表ID
|
||||
userType:pc端上传还是小程序上传(1后台管理系统 2小程序)
|
||||
idOrOpenId:后台传递id 小程序传递openid
|
||||
*/
|
||||
func (s *sBusFolderFile) AllPicture(
|
||||
ctx context.Context,
|
||||
picture []string,
|
||||
folderId int64,
|
||||
tableName string,
|
||||
tableId int64,
|
||||
userType string,
|
||||
idOrOpenId string,
|
||||
remark string,
|
||||
projectId int64,
|
||||
) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
if !(userType == "1" || userType == "2") {
|
||||
err = errors.New("用户类型错误!")
|
||||
return
|
||||
}
|
||||
flag := false
|
||||
var bffr []*controllerModel.BusFolderFileListRes
|
||||
for _, path := range picture {
|
||||
if path != "" {
|
||||
//1、如果当前表,当前id有数据,就将当前数据给删除
|
||||
var bff *model.BusFolderFileInfoRes
|
||||
err = dao.BusFolderFile.Ctx(ctx).Where("table_name", tableName).Where("table_id", tableId).OrderDesc("id").Limit(1).Scan(&bff)
|
||||
if err != nil && bff != nil {
|
||||
dao.BusFolderFile.Ctx(ctx).Where("table_name", bff.TableName).Where("table_id", bff.TableId).Delete()
|
||||
}
|
||||
flag = true
|
||||
//根据文件路径获取到文件的名称,大小,后缀
|
||||
name, ext, size := coryCommon.FileInfo(path)
|
||||
var bffrTwo = new(controllerModel.BusFolderFileListRes)
|
||||
bffrTwo.FolderId = folderId
|
||||
bffrTwo.FileType = "2" //2表示图片-固定
|
||||
bffrTwo.Name = name
|
||||
bffrTwo.Suffix = ext
|
||||
bffrTwo.ProjectId = projectId
|
||||
bffrTwo.Size = strconv.FormatInt(size, 10)
|
||||
bffrTwo.Path = path
|
||||
if tableName != "" {
|
||||
bffrTwo.TableName = tableName
|
||||
}
|
||||
if tableId > 0 {
|
||||
bffrTwo.TableId = tableId
|
||||
}
|
||||
if remark != "" {
|
||||
bffrTwo.Remark = remark
|
||||
}
|
||||
bffrTwo.UserType = userType
|
||||
bffrTwo.CreateBy = idOrOpenId
|
||||
bffr = append(bffr, bffrTwo)
|
||||
}
|
||||
|
||||
}
|
||||
if flag {
|
||||
dao.BusFolderFile.Ctx(ctx).Insert(bffr)
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, "操作失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
AllDelete 通用图库删除上传
|
||||
tableName:哪张表的数据?表名
|
||||
tableId:哪张表的数据?表ID
|
||||
*/
|
||||
func (s *sBusFolderFile) AllDelete(ctx context.Context, tableName string, tableId []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//只删除了数据库存储数据,并没有删除实际图片(原因是小程序与pc端各自存放了图片,目前没有去研究如何在一个服务器去删除另外一个服务器的资源)
|
||||
_, err = dao.BusFolderFile.Ctx(ctx).
|
||||
Where("table_name", tableName).
|
||||
Where("table_id in (?)", tableId).
|
||||
Delete()
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user