first commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package admin_notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
"hm-server/app/main/model"
|
||||
"hm-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminCreateNotificationLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminCreateNotificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminCreateNotificationLogic {
|
||||
return &AdminCreateNotificationLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminCreateNotificationLogic) AdminCreateNotification(req *types.AdminCreateNotificationReq) (resp *types.AdminCreateNotificationResp, err error) {
|
||||
startDate, _ := time.Parse("2006-01-02", req.StartDate)
|
||||
endDate, _ := time.Parse("2006-01-02", req.EndDate)
|
||||
data := &model.GlobalNotifications{
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
NotificationPage: req.NotificationPage,
|
||||
StartDate: sql.NullTime{Time: startDate, Valid: req.StartDate != ""},
|
||||
EndDate: sql.NullTime{Time: endDate, Valid: req.EndDate != ""},
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
Status: req.Status,
|
||||
}
|
||||
result, err := l.svcCtx.GlobalNotificationsModel.Insert(l.ctx, nil, data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建通知失败, err: %v, req: %+v", err, req)
|
||||
}
|
||||
id, _ := result.LastInsertId()
|
||||
return &types.AdminCreateNotificationResp{Id: id}, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package admin_notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
"hm-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminDeleteNotificationLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminDeleteNotificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminDeleteNotificationLogic {
|
||||
return &AdminDeleteNotificationLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminDeleteNotificationLogic) AdminDeleteNotification(req *types.AdminDeleteNotificationReq) (resp *types.AdminDeleteNotificationResp, err error) {
|
||||
notification, err := l.svcCtx.GlobalNotificationsModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查找通知失败, err: %v, id: %d", err, req.Id)
|
||||
}
|
||||
err = l.svcCtx.GlobalNotificationsModel.DeleteSoft(l.ctx, nil, notification)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "删除通知失败, err: %v, id: %d", err, req.Id)
|
||||
}
|
||||
return &types.AdminDeleteNotificationResp{Success: true}, nil
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package admin_notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
"hm-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetNotificationDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetNotificationDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetNotificationDetailLogic {
|
||||
return &AdminGetNotificationDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetNotificationDetailLogic) AdminGetNotificationDetail(req *types.AdminGetNotificationDetailReq) (resp *types.AdminGetNotificationDetailResp, err error) {
|
||||
notification, err := l.svcCtx.GlobalNotificationsModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查找通知失败, err: %v, id: %d", err, req.Id)
|
||||
}
|
||||
resp = &types.AdminGetNotificationDetailResp{
|
||||
Id: notification.Id,
|
||||
Title: notification.Title,
|
||||
Content: notification.Content,
|
||||
NotificationPage: notification.NotificationPage,
|
||||
StartDate: "",
|
||||
StartTime: notification.StartTime,
|
||||
EndDate: "",
|
||||
EndTime: notification.EndTime,
|
||||
Status: notification.Status,
|
||||
CreateTime: notification.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: notification.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
if notification.StartDate.Valid {
|
||||
resp.StartDate = notification.StartDate.Time.Format("2006-01-02")
|
||||
}
|
||||
if notification.EndDate.Valid {
|
||||
resp.EndDate = notification.EndDate.Time.Format("2006-01-02")
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package admin_notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
"hm-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetNotificationListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetNotificationListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetNotificationListLogic {
|
||||
return &AdminGetNotificationListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetNotificationListLogic) AdminGetNotificationList(req *types.AdminGetNotificationListReq) (resp *types.AdminGetNotificationListResp, err error) {
|
||||
builder := l.svcCtx.GlobalNotificationsModel.SelectBuilder()
|
||||
if req.Title != nil {
|
||||
builder = builder.Where("title LIKE ?", "%"+*req.Title+"%")
|
||||
}
|
||||
if req.NotificationPage != nil {
|
||||
builder = builder.Where("notification_page = ?", *req.NotificationPage)
|
||||
}
|
||||
if req.Status != nil {
|
||||
builder = builder.Where("status = ?", *req.Status)
|
||||
}
|
||||
if req.StartDate != nil {
|
||||
if t, err := time.Parse("2006-01-02", *req.StartDate); err == nil {
|
||||
builder = builder.Where("start_date >= ?", t)
|
||||
}
|
||||
}
|
||||
if req.EndDate != nil {
|
||||
if t, err := time.Parse("2006-01-02", *req.EndDate); err == nil {
|
||||
builder = builder.Where("end_date <= ?", t)
|
||||
}
|
||||
}
|
||||
list, total, err := l.svcCtx.GlobalNotificationsModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询通知列表失败, err: %v, req: %+v", err, req)
|
||||
}
|
||||
items := make([]types.NotificationListItem, 0, len(list))
|
||||
for _, n := range list {
|
||||
item := types.NotificationListItem{
|
||||
Id: n.Id,
|
||||
Title: n.Title,
|
||||
NotificationPage: n.NotificationPage,
|
||||
Content: n.Content,
|
||||
StartDate: "",
|
||||
StartTime: n.StartTime,
|
||||
EndDate: "",
|
||||
EndTime: n.EndTime,
|
||||
Status: n.Status,
|
||||
CreateTime: n.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: n.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
if n.StartDate.Valid {
|
||||
item.StartDate = n.StartDate.Time.Format("2006-01-02")
|
||||
}
|
||||
if n.EndDate.Valid {
|
||||
item.EndDate = n.EndDate.Time.Format("2006-01-02")
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
resp = &types.AdminGetNotificationListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package admin_notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
"hm-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminUpdateNotificationLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminUpdateNotificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateNotificationLogic {
|
||||
return &AdminUpdateNotificationLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminUpdateNotificationLogic) AdminUpdateNotification(req *types.AdminUpdateNotificationReq) (resp *types.AdminUpdateNotificationResp, err error) {
|
||||
notification, err := l.svcCtx.GlobalNotificationsModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查找通知失败, err: %v, id: %d", err, req.Id)
|
||||
}
|
||||
if req.StartDate != nil {
|
||||
startDate, _ := time.Parse("2006-01-02", *req.StartDate)
|
||||
notification.StartDate = sql.NullTime{Time: startDate, Valid: true}
|
||||
}
|
||||
if req.EndDate != nil {
|
||||
endDate, _ := time.Parse("2006-01-02", *req.EndDate)
|
||||
notification.EndDate = sql.NullTime{Time: endDate, Valid: true}
|
||||
}
|
||||
if req.Title != nil {
|
||||
notification.Title = *req.Title
|
||||
}
|
||||
if req.Content != nil {
|
||||
notification.Content = *req.Content
|
||||
}
|
||||
if req.NotificationPage != nil {
|
||||
notification.NotificationPage = *req.NotificationPage
|
||||
}
|
||||
if req.StartTime != nil {
|
||||
notification.StartTime = *req.StartTime
|
||||
}
|
||||
if req.EndTime != nil {
|
||||
notification.EndTime = *req.EndTime
|
||||
}
|
||||
if req.Status != nil {
|
||||
notification.Status = *req.Status
|
||||
}
|
||||
_, err = l.svcCtx.GlobalNotificationsModel.Update(l.ctx, nil, notification)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新通知失败, err: %v, req: %+v", err, req)
|
||||
}
|
||||
return &types.AdminUpdateNotificationResp{Success: true}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user