124 lines
3.9 KiB
Go
124 lines
3.9 KiB
Go
|
// ==========================================================================
|
|||
|
// GFast自动生成logic操作代码。
|
|||
|
// 生成日期:2024-04-23 14:47:24
|
|||
|
// 生成路径: internal/app/system/logic/comments.go
|
|||
|
// 生成人:gfast
|
|||
|
// desc:App通知公告评论
|
|||
|
// 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/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"
|
|||
|
"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"
|
|||
|
)
|
|||
|
|
|||
|
func init() {
|
|||
|
service.RegisterComments(New())
|
|||
|
}
|
|||
|
|
|||
|
func New() *sComments {
|
|||
|
return &sComments{}
|
|||
|
}
|
|||
|
|
|||
|
type sComments struct{}
|
|||
|
|
|||
|
func (s *sComments) List(ctx context.Context, req *system.CommentsSearchReq) (listRes *system.CommentsSearchRes, err error) {
|
|||
|
listRes = new(system.CommentsSearchRes)
|
|||
|
err = g.Try(ctx, func(ctx context.Context) {
|
|||
|
m := dao.Comments.Ctx(ctx).WithAll()
|
|||
|
if req.Id != "" {
|
|||
|
m = m.Where(dao.Comments.Columns().Id+" = ?", req.Id)
|
|||
|
}
|
|||
|
if req.NotificationId != "" {
|
|||
|
m = m.Where(dao.Comments.Columns().NotificationId+" = ?", gconv.Int(req.NotificationId))
|
|||
|
}
|
|||
|
if req.CommentText != "" {
|
|||
|
m = m.Where(dao.Comments.Columns().CommentText+" = ?", req.CommentText)
|
|||
|
}
|
|||
|
if req.CommentId != "" {
|
|||
|
m = m.Where(dao.Comments.Columns().CommentId+" = ?", req.CommentId)
|
|||
|
}
|
|||
|
if len(req.DateRange) != 0 {
|
|||
|
m = m.Where(dao.Comments.Columns().CreatedAt+" >=? AND "+dao.Comments.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 asc"
|
|||
|
if req.OrderBy != "" {
|
|||
|
order = req.OrderBy
|
|||
|
}
|
|||
|
var res []*model.CommentsInfoRes
|
|||
|
err = m.Fields(system.CommentsSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
|||
|
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
|||
|
listRes.List = make([]*model.CommentsInfoRes, len(res))
|
|||
|
for k, v := range res {
|
|||
|
listRes.List[k] = &model.CommentsInfoRes{
|
|||
|
Id: v.Id,
|
|||
|
NotificationId: v.NotificationId,
|
|||
|
CommentText: v.CommentText,
|
|||
|
CommentId: v.CommentId,
|
|||
|
CreatedAt: v.CreatedAt,
|
|||
|
}
|
|||
|
}
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
func (s *sComments) GetById(ctx context.Context, id uint) (res *model.CommentsInfoRes, err error) {
|
|||
|
err = g.Try(ctx, func(ctx context.Context) {
|
|||
|
err = dao.Comments.Ctx(ctx).WithAll().Where(dao.Comments.Columns().Id, id).Scan(&res)
|
|||
|
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
func (s *sComments) Add(ctx context.Context, req *system.CommentsAddReq) (err error) {
|
|||
|
err = g.Try(ctx, func(ctx context.Context) {
|
|||
|
_, err = dao.Comments.Ctx(ctx).Insert(do.Comments{
|
|||
|
NotificationId: req.NotificationId,
|
|||
|
CommentText: req.CommentText,
|
|||
|
CommentId: req.CommentId,
|
|||
|
})
|
|||
|
liberr.ErrIsNil(ctx, err, "添加失败")
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
func (s *sComments) Edit(ctx context.Context, req *system.CommentsEditReq) (err error) {
|
|||
|
err = g.Try(ctx, func(ctx context.Context) {
|
|||
|
_, err = dao.Comments.Ctx(ctx).WherePri(req.Id).Update(do.Comments{
|
|||
|
NotificationId: req.NotificationId,
|
|||
|
CommentText: req.CommentText,
|
|||
|
CommentId: req.CommentId,
|
|||
|
})
|
|||
|
liberr.ErrIsNil(ctx, err, "修改失败")
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
func (s *sComments) Delete(ctx context.Context, ids []uint) (err error) {
|
|||
|
err = g.Try(ctx, func(ctx context.Context) {
|
|||
|
_, err = dao.Comments.Ctx(ctx).Delete(dao.Comments.Columns().Id+" in (?)", ids)
|
|||
|
liberr.ErrIsNil(ctx, err, "删除失败")
|
|||
|
})
|
|||
|
return
|
|||
|
}
|