初始
This commit is contained in:
@ -0,0 +1,155 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-07-29 16:04:06
|
||||
// 生成路径: internal/app/system/logic/bus_research_document.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/libUtils"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
tool "github.com/tiger1103/gfast/v3/utility/coryUtils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusResearchDocument(New())
|
||||
}
|
||||
|
||||
func New() *sBusResearchDocument {
|
||||
return &sBusResearchDocument{}
|
||||
}
|
||||
|
||||
type sBusResearchDocument struct{}
|
||||
|
||||
func (s *sBusResearchDocument) List(ctx context.Context, req *system.BusResearchDocumentSearchReq) (listRes *system.BusResearchDocumentSearchRes, err error) {
|
||||
listRes = new(system.BusResearchDocumentSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusResearchDocument.Ctx(ctx).WithAll()
|
||||
if req.FileId != "" {
|
||||
m = m.Where(dao.BusResearchDocument.Columns().FileId+" = ?", req.FileId)
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.BusResearchDocument.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.DocumenName != "" {
|
||||
m = m.Where(dao.BusResearchDocument.Columns().DocumenName+" like ?", "%"+req.DocumenName+"%")
|
||||
}
|
||||
//创建时间模糊查询
|
||||
if req.CreatedAt != "" {
|
||||
date := tool.New().GetFormattedDate(gconv.Time(req.CreatedAt))
|
||||
m = m.Where(dao.BusResearchDocument.Columns().CreatedAt+" like ?", "%"+date+"%")
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where(dao.BusResearchDocument.Columns().CreatedAt+" >=? AND "+dao.BusResearchDocument.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.BusResearchDocumentInfoRes
|
||||
err = m.Fields(system.BusResearchDocumentSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusResearchDocumentListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusResearchDocumentListRes{
|
||||
Id: v.Id,
|
||||
DocumenName: v.DocumenName,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusResearchDocument) GetById(ctx context.Context, id int64) (res *model.BusResearchDocumentInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusResearchDocument.Ctx(ctx).WithAll().Where(dao.BusResearchDocument.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
//获取创建人 更新人
|
||||
by := coryCommon.New().CreateByOrUpdateBy(ctx, res)
|
||||
infoRes := by.(model.BusResearchDocumentInfoRes)
|
||||
res = &infoRes
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusResearchDocument) Add(ctx context.Context, req *system.BusResearchDocumentAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
for _, obj := range req.FileUrl {
|
||||
obj.Url, err = libUtils.GetFilesPath(ctx, obj.Url)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
if len(req.FileUrl) > 0 {
|
||||
file := req.FileUrl[0]
|
||||
_, err = dao.BusResearchDocument.Ctx(ctx).Insert(do.BusResearchDocument{
|
||||
DocumenName: file.Name,
|
||||
DocumentUrl: file.Url,
|
||||
FileId: req.FileId,
|
||||
ProjectId: req.ProjectId,
|
||||
CreateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
return
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, coryCommon.ImportFile)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusResearchDocument) Edit(ctx context.Context, req *system.BusResearchDocumentEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
name := ct.New().GetLoginUser(ctx).Id
|
||||
for _, obj := range req.FileUrl {
|
||||
obj.Url, err = libUtils.GetFilesPath(ctx, obj.Url)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
}
|
||||
if len(req.FileUrl) > 0 {
|
||||
file := req.FileUrl[0]
|
||||
_, err = dao.BusResearchDocument.Ctx(ctx).WherePri(req.Id).Update(do.BusResearchDocument{
|
||||
DocumenName: file.Name,
|
||||
DocumentUrl: file.Url,
|
||||
Remark: req.Remark,
|
||||
FileId: req.FileId,
|
||||
ProjectId: req.ProjectId,
|
||||
UpdateBy: name,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
return
|
||||
}
|
||||
liberr.ErrIsNil(ctx, err, coryCommon.ImportFile)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusResearchDocument) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusResearchDocument.Ctx(ctx).Delete(dao.BusResearchDocument.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user