🎨 新增公告通知模块
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"git.echol.cn/loser/lckt/service/bot"
|
||||
"git.echol.cn/loser/lckt/service/category"
|
||||
"git.echol.cn/loser/lckt/service/example"
|
||||
"git.echol.cn/loser/lckt/service/notice"
|
||||
"git.echol.cn/loser/lckt/service/system"
|
||||
"git.echol.cn/loser/lckt/service/user"
|
||||
"git.echol.cn/loser/lckt/service/vip"
|
||||
@@ -20,4 +21,5 @@ type ServiceGroup struct {
|
||||
ArticleGroup article.ServiceGroup
|
||||
UserServiceGroup user.ServiceGroup
|
||||
VipServiceGroup vip.ServiceGroup
|
||||
NoticeServiceGroup notice.ServiceGroup
|
||||
}
|
||||
|
3
service/notice/enter.go
Normal file
3
service/notice/enter.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package notice
|
||||
|
||||
type ServiceGroup struct{ NoticeService }
|
84
service/notice/notice.go
Normal file
84
service/notice/notice.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package notice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/model/notice"
|
||||
noticeReq "git.echol.cn/loser/lckt/model/notice/request"
|
||||
)
|
||||
|
||||
type NoticeService struct{}
|
||||
|
||||
// CreateNotice 创建通知记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (notService *NoticeService) CreateNotice(ctx context.Context, not *notice.Notice) (err error) {
|
||||
err = global.GVA_DB.Create(not).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteNotice 删除通知记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (notService *NoticeService) DeleteNotice(ctx context.Context, ID string) (err error) {
|
||||
err = global.GVA_DB.Delete(¬ice.Notice{}, "id = ?", ID).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteNoticeByIds 批量删除通知记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (notService *NoticeService) DeleteNoticeByIds(ctx context.Context, IDs []string) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]notice.Notice{}, "id in ?", IDs).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateNotice 更新通知记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (notService *NoticeService) UpdateNotice(ctx context.Context, not notice.Notice) (err error) {
|
||||
err = global.GVA_DB.Model(¬ice.Notice{}).Where("id = ?", not.ID).Updates(¬).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// GetNotice 根据ID获取通知记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (notService *NoticeService) GetNotice(ctx context.Context, ID string) (not notice.Notice, err error) {
|
||||
err = global.GVA_DB.Where("id = ?", ID).First(¬).Error
|
||||
return
|
||||
}
|
||||
|
||||
// GetNoticeInfoList 分页获取通知记录
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (notService *NoticeService) GetNoticeInfoList(ctx context.Context, info noticeReq.NoticeSearch) (list []notice.Notice, total int64, err error) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
db := global.GVA_DB.Model(¬ice.Notice{})
|
||||
var nots []notice.Notice
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
|
||||
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var OrderStr string
|
||||
orderMap := make(map[string]bool)
|
||||
orderMap["title"] = true
|
||||
if orderMap[info.Sort] {
|
||||
OrderStr = info.Sort
|
||||
if info.Order == "descending" {
|
||||
OrderStr = OrderStr + " desc"
|
||||
}
|
||||
db = db.Order(OrderStr)
|
||||
}
|
||||
|
||||
if limit != 0 {
|
||||
db = db.Limit(limit).Offset(offset)
|
||||
}
|
||||
|
||||
err = db.Find(¬s).Error
|
||||
return nots, total, err
|
||||
}
|
||||
func (notService *NoticeService) GetNoticePublic(ctx context.Context) {
|
||||
// 此方法为获取数据源定义的数据
|
||||
// 请自行实现
|
||||
}
|
Reference in New Issue
Block a user