This commit is contained in:
2026-04-18 12:05:21 +08:00
parent 55fcaf62dc
commit 957976db31
21 changed files with 331 additions and 140 deletions

View File

@@ -2,6 +2,7 @@ package admin_notification
import (
"context"
"strings"
"time"
"bdrp-server/app/main/api/internal/svc"
@@ -32,7 +33,10 @@ func (l *AdminGetNotificationListLogic) AdminGetNotificationList(req *types.Admi
builder = builder.Where("title LIKE ?", "%"+*req.Title+"%")
}
if req.NotificationPage != nil {
builder = builder.Where("notification_page = ?", *req.NotificationPage)
s := strings.TrimSpace(*req.NotificationPage)
if s != "" {
builder = builder.Where("notification_page LIKE ?", "%"+s+"%")
}
}
if req.Status != nil {
builder = builder.Where("status = ?", *req.Status)

View File

@@ -3,6 +3,7 @@ package admin_notification
import (
"context"
"database/sql"
"strings"
"time"
"bdrp-server/app/main/api/internal/svc"
@@ -32,13 +33,30 @@ func (l *AdminUpdateNotificationLogic) AdminUpdateNotification(req *types.AdminU
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查找通知失败, err: %v, id: %d", err, req.Id)
}
// 空字符串表示「无日期」(如每天展示),须写 NULL不能写零时间否则 MySQL 会报 Incorrect date value
if req.StartDate != nil {
startDate, _ := time.Parse("2006-01-02", *req.StartDate)
notification.StartDate = sql.NullTime{Time: startDate, Valid: true}
s := strings.TrimSpace(*req.StartDate)
if s == "" {
notification.StartDate = sql.NullTime{Valid: false}
} else {
startDate, err := time.Parse("2006-01-02", s)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.REUQEST_PARAM_ERROR), "start_date 格式错误: %v", err)
}
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}
s := strings.TrimSpace(*req.EndDate)
if s == "" {
notification.EndDate = sql.NullTime{Valid: false}
} else {
endDate, err := time.Parse("2006-01-02", s)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.REUQEST_PARAM_ERROR), "end_date 格式错误: %v", err)
}
notification.EndDate = sql.NullTime{Time: endDate, Valid: true}
}
}
if req.Title != nil {
notification.Title = *req.Title